小工具集合

Reference https://ffmpeg.org/documentation.html Usage flac to mp3 ffmpeg -i input.flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3 ffplay https://www.jianshu.com/p/c7c6871a8b7c https://www.jianshu.com/p/fd3c6d02a625 VLC VLC 命令行播放音乐 参考 https://wiki.videolan.org/Console/ ✗ vlc -I rc VLC media player 3.0.16 Vetinari (revision 3.0.16-0-g5e70837d8d) [00007fe29244ebe0] main playlist: playlist is empty [00007fe292712650] [cli] lua interface: Listening on host "*console". VLC media player 3.0.16 Vetinari Command Line Interface initialized. Type `help' for help. > help +----[ CLI commands ] | add XYZ . . . . . . . . . . . . . . . . . . . . add XYZ to playlist | enqueue XYZ . . . . . . . . . . . . . . . . . queue XYZ to playlist | playlist . . . . . . . . . . . . . show items currently in playlist | search [string] . . search for items in playlist (or reset search) | delete [X] . . . . . . . . . . . . . . . . delete item X in playlist | move [X][Y] . . . . . . . . . . . . move item X in playlist after Y | sort key . . . . . . . . . . . . . . . . . . . . . sort the playlist | sd [sd] . . . . . . . . . . . . . show services discovery or toggle | play . . . . . . . . . . . . . . . . . . . . . . . . . . play stream | stop . . . . . . . . . . . . . . . . . . . . . . . . . . stop stream | next . . . . . . . . . . . . . . . . . . . . . . next playlist item | prev . . . . . . . . . . . . . . . . . . . . previous playlist item | goto, gotoitem . . . . . . . . . . . . . . . . . goto item at index | repeat [on|off] . . . . . . . . . . . . . . toggle playlist repeat | loop [on|off] . . . . . . . . . . . . . . . . toggle playlist loop | random [on|off] . . . . . . . . . . . . . . toggle playlist random | clear . . . . . . . . . . . . . . . . . . . . . clear the playlist | status . . . . . . . . . . . . . . . . . . . current playlist status | title [X] . . . . . . . . . . . . . . set/get title in current item | title_n . . . . . . . . . . . . . . . . next title in current item | title_p . . . . . . . . . . . . . . previous title in current item | chapter [X] . . . . . . . . . . . . set/get chapter in current item | chapter_n . . . . . . . . . . . . . . next chapter in current item | chapter_p . . . . . . . . . . . . previous chapter in current item | | seek X . . . . . . . . . . . seek in seconds, for instance `seek 12' | pause . . . . . . . . . . . . . . . . . . . . . . . . toggle pause | fastforward . . . . . . . . . . . . . . . . . . set to maximum rate | rewind . . . . . . . . . . . . . . . . . . . . . set to minimum rate | faster . . . . . . . . . . . . . . . . . . faster playing of stream | slower . . . . . . . . . . . . . . . . . . slower playing of stream | normal . . . . . . . . . . . . . . . . . . normal playing of stream | rate [playback rate] . . . . . . . . . . set playback rate to value | frame . . . . . . . . . . . . . . . . . . . . . play frame by frame | fullscreen, f, F [on|off] . . . . . . . . . . . . toggle fullscreen | info [X] . . information about the current stream (or specified id) | stats . . . . . . . . . . . . . . . . show statistical information | get_time . . . . . . . . . seconds elapsed since stream's beginning | is_playing . . . . . . . . . . . . 1 if a stream plays, 0 otherwise | get_title . . . . . . . . . . . . . the title of the current stream | get_length . . . . . . . . . . . . the length of the current stream | | volume [X] . . . . . . . . . . . . . . . . . . set/get audio volume | volup [X] . . . . . . . . . . . . . . . raise audio volume X steps | voldown [X] . . . . . . . . . . . . . . lower audio volume X steps | achan [X] . . . . . . . . . . . . set/get stereo audio output mode | atrack [X] . . . . . . . . . . . . . . . . . . . set/get audio track | vtrack [X] . . . . . . . . . . . . . . . . . . . set/get video track | vratio [X] . . . . . . . . . . . . . . . set/get video aspect ratio | vcrop, crop [X] . . . . . . . . . . . . . . . . set/get video crop | vzoom, zoom [X] . . . . . . . . . . . . . . . . set/get video zoom | vdeinterlace [X] . . . . . . . . . . . . . set/get video deinterlace | vdeinterlace_mode [X] . . . . . . . set/get video deinterlace mode | snapshot . . . . . . . . . . . . . . . . . . . . take video snapshot | strack [X] . . . . . . . . . . . . . . . . . set/get subtitle track | | vlm . . . . . . . . . . . . . . . . . . . . . . . . . load the VLM | description . . . . . . . . . . . . . . . . . describe this module | help, ? [pattern] . . . . . . . . . . . . . . . . . a help message | longhelp [pattern] . . . . . . . . . . . . . . a longer help message | lock . . . . . . . . . . . . . . . . . . . . lock the telnet prompt | logout . . . . . . . . . . . . . . exit (if in a socket connection) | quit . . . . . . . . quit VLC (or logout if in a socket connection) | shutdown . . . . . . . . . . . . . . . . . . . . . . . shutdown VLC +----[ end of help ] > https://github.com/pemako/beancount ...

April 9, 2026 · 8 min · Theme PaperMod

终端原理

Go 终端编程原理详解 基于 golang.org/x/term 和 github.com/creack/pty 的完整技术文档 目录 终端基础概念 文件描述符 termios:终端 I/O 控制 Cooked 模式 vs Raw 模式 golang.org/x/term API 详解 PTY(伪终端)原理 完整示例解析 常见问题与最佳实践 参考资料 1. 终端基础概念 什么是终端(Terminal) 终端最初是物理设备(电传打字机、CRT 显示器),通过串口连接到主机,用于输入命令和查看输出。现代操作系统中的"终端"是对这一概念的软件模拟,称为终端模拟器(Terminal Emulator),如 macOS 的 Terminal.app、iTerm2,Linux 上的 GNOME Terminal 等。 用户键盘输入 │ ▼ ┌─────────────┐ ┌──────────────┐ ┌─────────┐ │ 终端模拟器 │─────▶│ TTY 驱动层 │─────▶│ 进程 │ │ (Terminal) │◀─────│ (内核) │◀─────│ (Shell) │ └─────────────┘ └──────────────┘ └─────────┘ │ ▼ 屏幕显示输出 TTY 与终端设备文件 在 Linux/macOS 中,终端通过特殊的设备文件暴露给进程: ...

April 9, 2026 · 13 min · Theme PaperMod

自动化爬虫

docker-selenium 启动 docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chromium:latest 暴露 4444 和 7900 端口 4444 是 Selenium WebDriver HTTP API 7900 vpc 端口 默认的密码是 secret 启动浏览器 使用下面的浏览器就可以直接启动一个 chrome 在 VNC 中显示 from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument("--start-maximized") driver = webdriver.Remote( command_executor="http://localhost:4444", options=options ) driver.get("https://www.google.com") chromedp AdsPowser Profiles 无GUI的服务器如何启动 chrome 登录 机器上安装如下 最后主要是通过 noVNC 访问 #!/usr/bin/env bash set -e sudo apt update sudo apt install -y \ xvfb \ x11vnc \ xauth \ x11-utils \ chromium-browser \ dbus-x11 \ git \ python3 \ python3-websockify \ fonts-liberation \ libnss3 \ libgbm1 \ libgtk-3-0 \ libxrandr2 \ libxdamage1 \ libdrm2 \ psmisc \ procps \ net-tools \ curl \ wget if [ ! -d /opt/noVNC ]; then sudo git clone https://github.com/novnc/noVNC.git /opt/noVNC fi sudo mkdir -p /data/chrome/profile1 sudo chown -R "$USER:$USER" /data/chrome 控制启停脚本 #!/usr/bin/env bash set -e ######################## # ENV ######################## BASE_DIR=$(cd "$(dirname "$0")" && pwd) # === 基础路径 === PID_DIR="$BASE_DIR/pids" LOG_DIR="$BASE_DIR/logs" mkdir -p "$PID_DIR" "$LOG_DIR" # === 显示 & 网络 === export DISPLAY=:99 SCREEN_RESOLUTION="1280x800x24" VNC_PORT=5900 NOVNC_PORT=6080 # === Chrome === CHROME_BIN=/usr/bin/chromium-browser CHROME_PROFILE_DIR=$HOME/Work/chrome/profiles/pemako # === noVNC === NOVNC_DIR=$HOME/Work/noVNC ######################## # 工具函数 ######################## is_running() { local pidfile=$1 [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null } start_bg() { local name=$1 local pidfile=$2 shift 2 if is_running "$pidfile"; then echo "[$name] already running" return fi echo "[$name] starting..." "$@" & echo $! >"$pidfile" } stop_bg() { local name=$1 local pidfile=$2 if is_running "$pidfile"; then kill "$(cat "$pidfile")" && rm -f "$pidfile" echo "[$name] stopped" else echo "[$name] not running" fi } status_bg() { local name=$1 local pidfile=$2 if is_running "$pidfile"; then echo "[$name] running (pid $(cat "$pidfile"))" else echo "[$name] stopped" fi } ######################## # Xvfb ######################## xvfb_start() { start_bg "xvfb" "$PID_DIR/xvfb.pid" \ Xvfb "$DISPLAY" -screen 0 "$SCREEN_RESOLUTION" \ >"$LOG_DIR/xvfb.log" 2>&1 } xvfb_stop() { stop_bg "xvfb" "$PID_DIR/xvfb.pid" } xvfb_status() { status_bg "xvfb" "$PID_DIR/xvfb.pid" } ######################## # Chrome ######################## chrome_start() { mkdir -p "$CHROME_PROFILE_DIR" start_bg "chrome" "$PID_DIR/chrome.pid" \ env DISPLAY="$DISPLAY" \ "$CHROME_BIN" \ --user-data-dir="$CHROME_PROFILE_DIR" \ --no-sandbox \ --disable-dev-shm-usage \ >"$LOG_DIR/chrome.log" 2>&1 } chrome_stop() { stop_bg "chrome" "$PID_DIR/chrome.pid" } chrome_status() { status_bg "chrome" "$PID_DIR/chrome.pid" } ######################## # x11vnc ######################## x11vnc_start() { start_bg "x11vnc" "$PID_DIR/x11vnc.pid" \ x11vnc \ -display "$DISPLAY" \ -rfbport "$VNC_PORT" \ -forever \ -shared \ -nopw \ >"$LOG_DIR/x11vnc.log" 2>&1 } x11vnc_stop() { stop_bg "x11vnc" "$PID_DIR/x11vnc.pid" } x11vnc_status() { status_bg "x11vnc" "$PID_DIR/x11vnc.pid" } ######################## # noVNC ######################## novnc_start() { start_bg "novnc" "$PID_DIR/novnc.pid" \ "$NOVNC_DIR/utils/novnc_proxy" \ --vnc "localhost:$VNC_PORT" \ --listen "$NOVNC_PORT" \ >"$LOG_DIR/novnc.log" 2>&1 } novnc_stop() { stop_bg "novnc" "$PID_DIR/novnc.pid" } novnc_status() { status_bg "novnc" "$PID_DIR/novnc.pid" } ######################## # 总控 ######################## start_all() { xvfb_start sleep 1 chrome_start sleep 1 x11vnc_start sleep 1 novnc_start } stop_all() { novnc_stop x11vnc_stop chrome_stop xvfb_stop } status_all() { xvfb_status chrome_status x11vnc_status novnc_status } ######################## # CLI ######################## case "$1" in start) start_all ;; stop) stop_all ;; status) status_all ;; *) echo "Usage: $0 {start|stop|status}" exit 1 esac

April 9, 2026 · 3 min · Theme PaperMod

虚拟机安装

系统下载安装 说明该版本的系统主要是作为学习 《程序员的自我修养》这本书的环境 下载对应的 iso 镜像版本 https://old-releases.ubuntu.com/releases/7.04/ 配置 ubuntu 提供的老的 apt 镜像源 问题1 问题2 # 先备份 cp /etc/apt/sources.list /etc/apt/sources.list.bak # 替换 sudo sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list # then update with sudo apt-get update && sudo apt-get dist-upgrade # 删除 cdrom 的行 sed -i '/cdrom/d' /etc/apt/sources.list 网络配置 这里主要是想固定虚拟机的ip地址,开启 ssh 服务,这样可以通过终端登录。故这里选择的网络模式为 Nat + Host-only 模式。 在 Tools->Network->Create 选择 Host-only Networks 添加一个网络配置 在虚拟机的 Settings->Network->Adapter 1 中选择 NAT (这里默认选择) 配置 Adapter 2 网络在 图一添加的 host only network 的名字 ...

April 9, 2026 · 1 min · Theme PaperMod