xud6的笔记本

徐岱青

apt限制同时下载数量

 •  Filed under linux, debian

Queue-Mode 设置选项

默认值为 host 对每个host发起一个连接。当设为access时,对每个URI类型发起一个连接。由于大部分为http,因此也大致满足要求

永久设置

echo 'Acquire::Queue-Mode "access";' >/etc/apt/apt.conf.d/75download

临时设置

apt -o Acquire::Queue-mode=access upgrade

STM32 HAL UART循环发送缓存

 •  Filed under Embedded
#define UART_SEND_BUFF_SIZE		100
uint8_t UARTSendBuff[UART_SEND_BUFF_SIZE + 2] = {0};
uint16_t UARTSendBuffDataPos = 0;
uint16_t UARTSendBuffUsedPos = 0;
uint8_t UARTSendBuff_FlagSendBusy = 0;
void UARTSendBuff_putData(uint8_t * data,uint16_t len){
    while(len){
        UARTSendBuffDataPos++;
        if(UARTSendBuffDataPos > UART_SEND_BUFF_SIZE){
            UARTSendBuffDataPos = 1;
        }
        UARTSendBuff[UARTSendBuffDataPos] = *data;

        len --;
        data++;
    }
}

void UARTSendBuff_StartSend(){
    if(UARTSendBuff_FlagSendBusy == 0){
        if(UARTSendBuffDataPos == UARTSendBuffUsedPos){
            return;
        }else if(UARTSendBuffDataPos > UARTSendBuffUsedPos){
            UARTSendBuff_FlagSendBusy = 1;
            HAL_UART_Transmit_IT(&huart2,&UARTSendBuff[UARTSendBuffUsedPos + 1],(UARTSendBuffDataPos-UARTSendBuffUsedPos));
            UARTSendBuffUsedPos = UARTSendBuffDataPos;
        }else if(UARTSendBuffDataPos < UARTSendBuffUsedPos){
            if(UARTSendBuffUsedPos == UART_SEND_BUFF_SIZE){
                UARTSendBuffUsedPos = 0;
                UARTSendBuff_FlagSendBusy = 1;
                HAL_UART_Transmit_IT(&huart2,&UARTSendBuff[UARTSendBuffUsedPos + 1],(UARTSendBuffDataPos-UARTSendBuffUsedPos));
                UARTSendBuffUsedPos = UARTSendBuffDataPos;
            }else{
                UARTSendBuff_FlagSendBusy = 1;
                HAL_UART_Transmit_IT(&huart2,&UARTSendBuff[UARTSendBuffUsedPos + 1],(UART_SEND_BUFF_SIZE-UARTSendBuffUsedPos));
                UARTSendBuffUsedPos = 0;
            }
        }
    }
}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
    UARTSendBuff_FlagSendBusy = 0;
    UARTSendBuff_StartSend();
}

void UARTSEndBuff_Send(uint8_t * data,uint16_t len){
    UARTSendBuff_putData(data,len);
    UARTSendBuff_StartSend();
}

Powershell 卸载程序

 •  Filed under windows, powershell
function Uninstall-Application {
    $appName = $($args[0])
    Write "application to uninstall: $appName"
    $uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -Match $appName }
    $uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match $appName }

    if($uninstall32){
        if($uninstall32.QuietUninstallString){
            Write ("uninstall32 Quiet: " + $uninstall32.QuietUninstallString)
            Start-Process -FilePath cmd.exe -ArgumentList '/c', $uninstall32.QuietUninstallString  -Wait
        }else{
            Write ("uninstall32 Normal: " + $uninstall32.UninstallString)
            Start-Process -FilePath cmd.exe -ArgumentList '/c', $uninstall32.UninstallString  -Wait
        }
    }
    if($uninstall64){
        if($uninstall64.QuietUninstallString){
            Write ("uninstall64 Quiet: " + $uninstall64.QuietUninstallString)
            Start-Process -FilePath cmd.exe -ArgumentList '/c', $uninstall64.QuietUninstallString  -Wait
        }else{
            Write ("uninstall64 Normal: " + $uninstall64.UninstallString)
            Start-Process -FilePath cmd.exe -ArgumentList '/c', $uninstall64.UninstallString  -Wait
        }
    }
}

Uninstall-Application("application name*")

PowerShell 自动提权

 • 

添加至脚本头

param([switch]$Elevated)

function Test-Admin {
    $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
    $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

if ((Test-Admin) -eq $false)  {
    if ($elevated) {
        # tried to elevate, did not work, aborting
    } else {
        Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
    }
    exit
}

'running with full privileges'

Centos 开启 dns缓存

 •  Filed under centos, centos7

安装nscd

yum install nscd

在有IPA Client(或SSSD)的情况下修改/etc/nscd.conf中enable-cache为如下

enable-cache hosts yes
enable-cache passwd no
enable-cache group no
enable-cache netgroup no
enable-cache services no

启动

systemctl enable nscd
systemctl restart nscd

验证已经开启

time getent hosts www.bing.com

结果中

real    0m0.002s
user    0m0.001s
sys     0m0.000s

real 几乎等于 user + sys

centos 8 自动更新

 •  Filed under centos, centos8, linux

安装dnf-automatic

dnf install dnf-automatic

编辑/etc/dnf/automatic.conf

apply_updates = yes

启动定时器

systemctl enable --now dnf-automatic.timer