Luke 发布的文章

背景

在VSCode中使用Roo Code时,遇到终端集成问题,Roo Code无法在终端中执行各种操作,也无法获取输出,非常不方便。

解决步骤

1、检查powershell版本。
按下 Win + R,输入 pwsh,如果报找不到文件pswh,则版本不对,需要升级。
2、在powershell命令行中输入以下命令,安装新版本。

winget search Microsoft.PowerShell
winget install --id Microsoft.PowerShell --source winget

3、用pswh方式打开新的powershell,执行以下命令。

New-Item -Path $PROFILE -ItemType File -Force

在创建的文件中写入以下内容:

if ($env:TERM_PROGRAM -eq "vscode") {
  . "$(code --locate-shell-integration-path pwsh)"
}

4、以管理员方式启动powershell,执行以下命令。

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

5、在VSCode中按下Ctrl + Shift + P,输入Preferences: Open User Settings (JSON),填入以下内容。

    "terminal.integrated.defaultProfile.windows": "PowerShell 7",
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ]
        },
        "PowerShell 7": {
            "path": "你的pwsh.exe路径",
            "args": []
        }
    },

6、在VScode终端中输入以下命令:

$PSVersionTable.PSVersion

看是否有正确输出。

参考资料

https://zhuanlan.zhihu.com/p/25724740375

背景

每次AirPods连接MAC都会被音量吓一跳。

步骤

1、安装Hammerspoon。

brew install hammerspoon --cask

2、创建默认配置。

mkdir -p ~/.hammerspoon
touch ~/.hammerspoon/init.lua

3、在init.lua中写入配置

-- 存储上一次默认音频输出设备的名称
local lastOutputDeviceName = hs.audiodevice.defaultOutputDevice():name()

-- 处理设备变更的回调函数
local function handleDeviceChanges()
-- 获取当前默认音频输出设备的名称
local currentOutputDeviceName = hs.audiodevice.defaultOutputDevice():name()
-- 判断设备名称是否发生了变化
if lastOutputDeviceName ~= currentOutputDeviceName then
-- 判断当前设备是否为蓝牙耳机
if string.find(currentOutputDeviceName, "AirPods") then
-- 连接蓝牙耳机时将音量设置为 20
hs.audiodevice.defaultOutputDevice():setVolume(20)
hs.alert.show("音量已设为 20")
-- 判断上一个设备是否为蓝牙耳机
elseif string.find(lastOutputDeviceName, "AirPods") then
-- 断开蓝牙耳机时将音量设置为 0
hs.audiodevice.defaultOutputDevice():setVolume(0)
hs.alert.show("音量已设为 0")
end
end
-- 更新 lastOutputDeviceName 为当前设备名称
lastOutputDeviceName = currentOutputDeviceName
end

-- 为音频设备变动设置回调函数
hs.audiodevice.watcher.setCallback(handleDeviceChanges)
-- 启动音频设备监听器
hs.audiodevice.watcher.start()

4、重新加载配置。
在启动台搜索Hammerspoon,启动应用。然后在标题栏点击他的图标,然后选择Reload Config。

参考资料

https://www.v2ex.com/t/1011644

1 模型常驻显存

curl http://localhost:11434/api/generate -d '{"model": "gemma3:27b", "keep_alive": -1}' 

示例输出:

{"model":"gemma3:27b","created_at":"2025-11-26T00:50:25.894745547Z","response":"","done":true,"done_reason":"load"}%  

2 从魔搭加载GGUF文件

ollama run modelscope.cn/Qwen/Qwen2.5-3B-Instruct-GGUF
ollama run modelscope.cn/Qwen/Qwen2.5-3B-Instruct-GGUF:Q3_K_M
ollama run modelscope.cn/Qwen/Qwen2.5-3B-Instruct-GGUF:qwen2.5-3b-instruct-q3_k_m.gguf

3 删除本地模型

1 背景

实验室服务器经常有人提交大量任务,导致内存占满后系统卡死,不得不重启。通过使用earlyoom在内存耗尽前查杀大内存进程,避免系统崩溃。

2 做法

1、安装earlyoom

sudo apt install earlyoom

2、编辑配置文件

sudo vim /etc/default/earlyoom

将其中Available minimum memory部分修改为EARLYOOM_ARGS="-m 6,5 -s 100,100",表示内存余量低于5%就查杀大内存进程,同时忽略swap的占用情况。

# Default settings for earlyoom. This file is sourced by /bin/sh from
# /etc/init.d/earlyoom or by systemd from earlyoom.service.

# Options to pass to earlyoom
EARLYOOM_ARGS="-r 3600"

# Examples:

# Print memory report every second instead of every minute
# EARLYOOM_ARGS="-r 1"

# Available minimum memory 5%
# EARLYOOM_ARGS="-m 5"
EARLYOOM_ARGS="-m 6,5 -s 100,100"
# Available minimum memory 15% and free minimum swap 5%
# EARLYOOM_ARGS="-m 15 -s 5"

# Avoid killing processes whose name matches this regexp
# EARLYOOM_ARGS="--avoid '(^|/)(init|X|sshd|firefox)$'"

# See more at `earlyoom -h'
3、重启服务

sudo systemctl restart earlyoom

## 注意

1 背景

服务器经常遇到恶意爆破。使用fail2ban自动封禁多次密码输入错误的IP,降低服务器被攻破的风险。

2 做法

1、安装fail2ban。

sudo apt update
sudo apt install fail2ban

2、配置fail2ban

sudo vim /etc/fail2ban/jail.local

然后输入以下内容:

[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 10  # findtime时间内最大尝试次数
bantime = 86400  # 超过最大尝试次数后封禁时间,以秒为单位
findtime = 600  # 设置监测时间,以秒为单位。600表示统计连续10分钟内密码输入错误的次数

3、重启fail2ban

sudo systemctl restart fail2ban

4、查看状态

sudo fail2ban-client status sshd

注意

如果不正正常运行,执行以下命令

sudo apt-get update && sudo apt-get install -y rsyslog  # Debian/Ubuntu
sudo systemctl enable --now rsyslog
# 等 1~2 分钟让日志开始写入,再继续

然后再次重启fail2ban即可恢复正常。