Skip to content

Home

Journal-2025

4.1

fcitx5-rime配色主题

rime的Windows和MacOS版本都有相应的主题配置文件:weasel.yamlsquirrel.yaml。但Linux下rime时挂在输入法框架ibus或fcitx下的,UI界面并不由rime实现。因此,自定义主题需要在fcitx中配置,可参考ref

不错的rime配置+词库

雾凇拼音

rime覆写配置

可以通过*.custom.yaml的方式给原先的配置打补丁,避免修改原配置导致同步上游不便。

例如,原本的default.yaml中存在:

menu:
  page_size: 5

可以在default.yaml同级目录创建default.custom.yaml

patch:
  "menu/page_size": 3

完整patch:

patch:
  "menu/page_size": 3
  "key_binder/bindings/+":
    - { when: has_menu, accept: bracketleft, send: Page_Up }
    - { when: has_menu, accept: bracketright, send: Page_Down }
  "key_binder/select_first_character": null
  "key_binder/select_last_character": null

3.28

监控Python进程状态

有时运行一个Python程序后无法获知其运行进展(因其日志输出过于简略或阻塞于未知原因),我们希望能在不修改代码/干涉其运行的条件下了解其当前调用栈。可以使用非侵入式profiler工具py-spy

yay -S py-spy
# or: cargo install py-spy

echo 0| sudo tee /proc/sys/kernel/yama/ptrace_scope # ensure the ptrace permission
# suppose the target program is `app.py`
py-spy dump --pid `pgrep -f app.py` # dump the call stack
py-spy top --pid `pgrep -f app.py` # show a top-like live view of functions

镜像源滚包缓慢

无论什么镜像源都不到3MB/s,经排查发现是默认解析到了ipv6,而校园网对ipv6存在限速。目前可以使用仅解析ipv4的地址。

3.12

共用同一个Linux user时简单隔离

有时没有创建新用户的权限,需要多人共用同一用户,可以在home下创建子目录作为隔离的home,并使用RemoteCommand指定:

/home/user
├── user1
│   └── init.sh
├── user2
│   └── init.sh
└── user3
    └── init.sh

init.sh:

#!/bin/bash
export HOME=/home/user/user1
export SHELL=zsh # can be customized

cd $HOME
exec $SHELL -l

SSH Config:

Host ...
  HostName ...
  User user
  RemoteCommand /home/user/user1/init.sh
  RequestTTY yes

curl&git证书问题

某些配置有问题的服务器上,CA根证书不存在或没有读权限,导致curl报错:

$ curl https://baidu.com
curl: (77) error setting certificate verify locations:
  CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
$ ls -al /etc/pki/tls/certs/ca-bundle.crt
lrwxrwxrwx 1 root root 49 Jun  1  2024 /etc/pki/tls/certs/ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
$ ls -al /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
-rw------- 1 root root 209650 Nov 15 10:20 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

这种情况可以从curl官方下载CA Bundle证书到有权限的目录,并使用环境变量指定curl使用:

cd /path/to/save/certs
curl --etag-compare etag.txt --etag-save etag.txt --remote-name https://curl.se/ca/cacert.pem
export CURL_CA_BUNDLE=/path/to/save/certs/cacert.pem

同理,git出现相同证书问题也可以指定环境变量解决

export GIT_SSL_CAINFO=/path/to/save/certs/cacert.pem

对于其他程序(如rustup-init使用的reqwest库,SSL_CERT_FILE基本能相对通用地解决问题,这个环境变量对curl有效但对git无效)

export SSL_CERT_FILE=/path/to/save/certs/cacert.pem

3.7

对某目录递归字符串

grep -r "target" /path/to/grep/
grep -r "target" /path/to/grep/ --exclude="*.file.pattern.to.ignore"

2.25

重启docker daemon而不重启容器

首先添加live-restore配置:

/etc/docker/daemon.json:

{
    "live-restore": true,
    ...
}

使用SIGHUP信号触发dockerd重载配置:

sudo kill -SIGHUP $(pidof dockerd)
docker info | grep Live # 检查配置已载入,预期 Live Restore Enabled: true

重启daemon:

sudo systemctl restart docker

docker覆盖entrypoint

当Dockerfile为镜像指定了entrypoint时,docker run命令中指定的命令名会作为参数传递给entrypoint程序,可以使用--entrypoint new_cmd覆盖。

2.11

Ubuntu安装deb版firefox(非snap版)

source

1.8

uv安装有特殊要求的包

uv add flash-attn --no-build-isolation
uv add --editable ./path/to/package

切换CUDA版本

首选使用update-alternatives,如果不能使用,则可以通过指定环境变量的方式:

cuda_path="/usr/local/cuda-11.7" # or other

export CUDA_HOME="${cuda_path}"
export CUDA_ROOT="${cuda_path}"
export LD_LIBRARY_PATH="${cuda_path}/lib64:${cuda_path}/lib:${LD_LIBRARY_PATH}"
export PATH="${cuda_path}/bin:${PATH}"

uv安装PyTorch最佳实践

  1. 在系统中安装所需CUDA版本

  2. 根据PyTorch和CUDA版本需求,在PyTorch官网确定要使用的index

  3. pyproject.toml中添加相应源,并指定explicit = true使得仅torch相关包使用该源。 例如:

```toml [tool.uv.sources] torch = [{ index = "pytorch-index" }] torchvision = [{ index = "pytorch-index" }]

[[tool.uv.index]] url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple" default = true

[[tool.uv.index]] name = "pytorch-index" url = "https://download.pytorch.org/whl/cu121" explicit = true ```

  1. 执行uv sync同步环境

ref

1.7

git打包文件

git可以将工作区打包为压缩包,只包含被跟踪的文件

git archive --output "./output.tar.gz" master # 文件类型通过--output自动推断

对Gradio应用进行反向代理

反代gradio应用时(例如example.com/gradio-demo -> localhost:7860),由于gradio无法感知到外部url路径,会给出错误的资源url,可以通过设置GRADIO_ROOT_PATH环境变量解决。ref

server {
    listen 80;
    server_name example.com www.example.com;  # Change this to your domain name

    location /gradio-demo/ {  # Change this if you'd like to server your Gradio app on a different path
        proxy_pass http://127.0.0.1:7860/; # Change this if your Gradio app will be running on a different port
        proxy_buffering off;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

1.6

Shell在管道中间复制一份到错误流

command1 | command2 # original
command1 | tee /dev/stderr | command2 # for debug

1.1

\(\text{The Best Year Ever!}\)