Bash Script

References 手册 - Bash Reference Manual 检查工具 - shellcheck Shebang #!/bin/bash # 在 shebang 行中使用 env 命令 #!/usr/bin/env python Variables # 定义变量 var="a string" #等号两边不能有空格 #调用变量 echo $var echo ${var} # `""` suppress expansions except parameter expansion, arithmetic expansion, and command substitution echo "$var" # 双引号会渲染变量,输出`a string` # `''` suppress all expansions echo '$var' # 单引号不会渲染变量,输出`$var` # Arithmetic Expansion echo $((1+1)) # 输出`2` echo $((1.0/2)) # 输出`0.5` # Command Substitution # 执行命令并将输出替换原来内容 `cat some.txt` $( cat some.txt ) # Process Substitution # 执行命令并将输出写到一个临时文件中,并用临时文件名替换原来内容 # 在我们希望返回值通过文件而不是STDIN传递时很有用 diff <(ls foo) <(ls bar) #显示文件夹`foo`和`bar`中文件的区别 # Globbing 通配符 # `?`匹配一个字符,`*`匹配任意个字符 rm foo* # Brace Expansion # 花括号展开 echo Number_{1..5} echo Front-{A,B,C}-Back Positional Paramaters $0:路径 dirname $0:路径名 basename $0:文件名 $1~$9:输入参数 $@: 所有参数,$*:区别是会展开双引号中的参数 $#: 参数个数 $?:上一次退出状态,0为正常,其他为错误 $$: 当前脚本的进程识别码 Logit Expression Logit [[ exp1 && exp2 ]] and [[ exp1 || exp2 ]] or [[ ! exp1 ]] not # do command2 if command1 is sucessful command1 && command2 # do command2 if command1 is unsucessful command1 || command2 Function function func { commands return } # or func () { commands return } # local variable function func { local var var=2 return } # function arguments func () { echo "Parameter #1 is $1" # arguments are refered by position } func "$arg1" "$arg2" # call function with arguments Branching and Looping If x=5 if [[ $x -eq 5 ]]; then echo "x equals 5." elif [[ $x -eq 4 ]]; then echo "x equals 4." else echo "x does not equal 5 or 4." fi Case read -p case $REPLY in 0) echo "zero" ;; 1) echo "one" ;; 2) echo "two" ;; *) echo "other" ;; esac While count=1 while [[ $count -le 5 ]]; do echo $count count=$((count + 1)) done while true; do echo 1 sleep 1 done For for (( i=0; i<5; i=i+1 )); do echo $i done for i in {1..100}; do echo $i done # iterate arguments from the 3rd for i in "${@:3}"; do echo $i done Test test 手册 ...

January 1, 2000

Blender

Blender 帮助 帮助文档(F1) 界面 菜单栏:视图、选择、添加、网格、顶点、边、面、UV 侧边栏(N):条目、工具、视图、编辑 视图操作 右上角视图导航器 鼠标操作 放大/缩小视角(滚轮) 旋转视角(中键) 拖动视角(SHIFT + 中键) 快捷切换(~ + 数字键) 打开透视(Alt + Z) 四格视图(菜单 => 视图 => 区域 => 切换四格视图) 游标 游标回原点(SHIFT + C) 吸附游标 手动吸附(右键 => 吸附) 自动吸附(磁体 => 顶点吸附模式) 设置原点(右键 => 设置原点) 物体 选择 全选(A) 加/减选(SHIFT + 左键) 反选(CTRL + I) 物体操作 添加(SHIFT + A) 原位复制:(CTRL + C/CTRL + V) 复制并抓取(SHIFT + D) 删除(X) 合并(右键 => 合并):将多个物体合并为一个 拆分(右键 => 拆分):在一个物体中拆分为不同部分 分离(右键 => 分离):拆分为不同物体 BoolTool(侧边栏 => 编辑 => BoolTool) 变换 平移 (G) 例子:沿x轴平移10 m(G + X + 10) 缩放(S) 例子:沿x轴放大到两倍(S + X + 2) 法向缩放(ALT + S) 旋转(R) 例子:沿x轴旋转10度(R + X + 10) 编辑模式 切换编辑模式(TAB) 切换点/线/面选择(1/2/3) 选择 选择:框选、刷选、套索 间隔式弃选 面操作 细分(右键 => 细分) 挤出(E,工具栏 => 挤出选区) 沿各面挤出(ALT+ E) 挤出流形:相当于勾选了融并正交面 内插面(I) 尖分面(右键 => 尖分面):各个顶点到中心点连线 面三角化(右键 => 面三角化):各个顶点连线形成三角形 融并面(右键 => 融并面):将多个面合并成一个面 切割(K,工具栏 => 切割) 切割过程中按SHIFT键吸附中点 切分:整体切分 环切(CTRL + R,工具栏 => 环切) 居中切割(右键) 添加切割数(滚轮) 塌陷(X => 塌陷边线&面):塌陷成一个点 线操作 选择 选择循环边(ALT + 左键,菜单栏 => 选择 => 选择循环 => 循环边) 选择并排边(CTRL + ALT + 左键,菜单栏 => 选择 => 选择循环 => 并排边) 选择循环面(ALT + 左键) 填充面 从边创建面(F,右键 => 从边创建面) 三角填充(ALT + F,右键 => 填充) 栅格填充(菜单栏 => 面 => 栅格填充) 细分(右键 => 细分) 滑移(右键 => 滑移边线):沿着临边滑移 偏移边线并滑移(菜单栏 => 边 => 偏移边线并滑移):用于卡线 桥接循环边(菜单栏 => 边 => 桥接循环边) 两组循环边边数要相等 可以用于打洞 溶并边(右键 => 融并边):将边两侧的面融合 倒角(CTRL + B,工具栏 => 倒角) 鼠标滚轮切换段数 如果倒角不均匀,是因为物体缩放过,需要CTRL + A选"全部变换" 点操作 滑移(SHIFT + V,右键 => 滑移顶点,菜单栏 => 顶点 => 滑移顶点,工具栏 => 滑移顶点):沿临边移动 连接顶点 从顶点创建边(F,菜单栏 => 顶点 => 从顶点创建边):不会分割面 连接顶点路径(J,菜单栏 => 顶点 => 连接顶点路径):会分割面 点合并(M,右键 => 合并顶点) 自动合并(全选 => 右键 => 合并顶点 => 按距离) 溶并顶点(右键 => 融并顶点):将顶点相邻的面融合 点倒角(CTRL + B,工具栏 => 倒角) 平面内点的倒角:结合LoopTools创建圆环(右键 => LoopTools) 衰减编辑:操作会影响周边一定衰减半径内的邻居 修改衰减半径(滚轮) 曲线 贝塞尔曲线 控制柄(V) 自由:自由调节 对齐:左右同步 矢量:直线连接 自动:自动平滑 自由绘制(工具栏 => 自由线) Nurbs路径 曲线倒角 倒角(右侧工作区 => 物体数据属性 => 几何数据 => 倒角) 修改器 倒角修改器 阵列修改器 镜像修改器 布尔修改器 线框修改器 将面收缩成线框 反细分(菜单栏 => 边 => 反细分):菱形细分边 表面细分修改器 卡线:用环切、内插面、倒角来卡线 边线折痕(右键 => 边线折痕):设置边不会被细分 实体化修改器 可以设置厚度转换为实体 曲线修改器 让物体按照曲线的走向变形 晶格修改器 给物体添加一个扭曲空间 形变修改器 几何节点修改器 材质 实用操作 选择点 -> 球形化

January 1, 2000

Boards

Boards Arduino Nano Pinout 代码为外侧紫色数字 built-in led: 13 ESP8266 Install https://arduino.esp8266.com/stable/package_esp8266com_index.json Pinout 1 2 3 4 5 6 7 8 9 开发板管脚 D0 D1 D2 D3 D4 D5 D6 D7 D8 芯片管脚 16 5 4 0 2 14 12 13 15 电机驱动板:esp8266 motor shield 电机电源(VM):4.5V~36V,可单独供电 控制电源(VIN):4.5V~9V,可单独供电 可以短路 VM 和VIN,使用一个电源(4.5V~9V)同时给电机与控制供电 Board pin NodeMCU GPIO Arduino IDE A power 1 5 or D1 A direction 3 0 or D3 B power 2 4 or D2 B direction 4 2 or D4 definition: pins.h ...

January 1, 2000

Browser

Firefox Shortcuts Keyboard shortcuts - Perform common Firefox tasks quickly Navigation Back/Forward: cmd-left/right Down/Up a screen: space/shift-space Go to bottom/top of a page: cmd-down/up Reload: cmd-R Zoom in/out/reset: cmd++/-/0 Find: cmd-F or / Find next/previous: cmd-G/cmd-shift-G Find link: ' Search Focus search bar: cmd-K Focus address bar: cmd-L Auto complete address: ctrl-enter Open Result in New Tab: Cmd-Return Open Result in Background Tab: Cmd-Shift-Return Tabs and Windows Close Tab: cmd-W New Tab: cmd-T Close Windows: cmd-shift-W New Window: cmd-N Go to Tab: cmd-1 to 8 Go to Last Tab: cmd-9 Next Tab: Cmd-Option-Right or Ctrl-Tab Previous Tab: Cmd-Option-Left or Ctrl-Shift-Tab Move Tab Left: ctrl-shift-PageUp Move Tab Right: ctrl-shift-PageDown Misc Open History: Cmd-Shift-H Clear History: Cmd-Shift-Del Open Bookmarks Sidebar: Cmd-B Add to Bookmarks: Cmd-D Add All Tabs to Bookmarks: Cmd-Shift-D Open Downloads: Cmd-J Open Add-ons: Cmd-Shift-A Developer Tools: F12 Reader Mode: Cmd-Shift-R Chrome Extention Install crx file ...

January 1, 2000

C Language

C Language Hello World #include <stdio.h> int main() { printf("hello, world\n"); return 0; } With arguments #include <stdio.h> int main(int argc, char* argv[]) { printf("arg count: %i\n", argc); for (int i=1; i<argc; i++) { printf("argv: %s\n", argv[i]); } return 0; } 编译与运行 gcc hello.c ./a.out comments // comment /* multiline comments */ Command-line arguments #include <stdio.h> int main(int argc, char *argv[]) { int i; for (i=1; i<argc; i++) { printf("%s%s", argv[i], (i < argc-1) ? " ": ""); } printf("\n"); return 0; } argc: argument count argv: argument vector Includes #include <xxx.h>: search in standard places, ex: /usr/include #include "yyy.h": search in working dir Variables Data Types Data Type Size Value Range Format boolean 1 byte 1 char 1 -128 ~ 127 %d unsigned char 1 0 ~ 255 %u short 2+(dependent on complier) -32768 ~ 32767 %d unsigned short 2+ 0 ~ 65535 %u int short to long(dependent on complier) -2147483648 ~ 2147483647 %d unsigned int short to long 0 ~ 2^32 %u long 4+(dependent on complier) %ld unsigned long 4+ %lu float 4 3.4e-38 to 3.4e+38 %f double 4 1.7e-308 to 1.7e+308 Type Cast int x = 1; // signed与unsigned互转,保持二进制表示不变,值可能改变 unsigned int ux = (unsigned int) x; // 短类型转长类型 // 对于signed类型(Two's Complement编码)在左侧补最高位bit的值(sign extension) // 对于unsigned类型,在左侧补0(zero extension) long lx = (long) x; // 长类型转短类型,截断高位,然后根据编码类型(signed or unsigned)解释数值 short sx = (short) lx; Declaring and Instantiating Variables // declarating int year; // instantiating year = 2022; // Declaring and instantiating simultaneously int year = 2022 // Constant const float pi = 3.14; Symbolic Constants #define LOWER 0 #define UPPER 300 #define STEP 20 Enum Constants // starts at 0, next 1, etc... enum boolean { NO, YES }; // values are specified enum escapes { BELL = '\a', BACKSPACE = '\b', TAB = '\t', NEWLINE = '\n', VTAB = '\v', RETURN = '\r' }; /* FEB = 2, MAR = 3, etc. */ enum months { JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; Array int ndigit[10]; for (i = 0; i < 10; ++i) { ndigit[i] = 0; } // assigns values to first 5 data int myarray[10] = {20, 30, 40, 50, 100}; int myarray[] = {20, 30, 40, 50, 100}; // size size = sizeof(myArray) / sizeof(int) 2-D Array // definition char daytab[2][13] = { {0, 31, 28, ..., 31}, {0, 31, 29, ..., 31} }; // get value daytab[i][j]; // passed to function f(int daytab[2][13]) { ... } f(int daytab[][13]) { ... } /* the number of row is irrelevant */ f(int (*daytab)[13]) { ... } /* a pointer to an array of 13 integers */ sizeof size_t:unsigned interger, defined in <stddef.h> #define NKEYS (sizeof keytab / sizeof(struct key)) #define NKEYS (sizeof keytab / sizeof(keytab[0])) Character string every character string has a ’\0’ at the end ...

January 1, 2000

C++ Language

C++ Language Install # MacOS xcode-select --install Hello World #include <iostream> int main() { std::cout << "Hello world!" << std::endl; return 0; } 编译与运行 g++ main.cpp -o main.out ./main.out 输入输出 iosteam #include <iostream> int main() { int v1 = 0, v2 = 0; std::cin >> v1 >> v2; std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1+v2 << std::endl; return 0; } 不知道有多少个输入时 int main() { string word; while (cin >> word) cout << word << endl; return 0; } 读取整行 int main() { string line; while (getline(cin, line)) cout << line << endl; return 0; } fstream #include <fstream> // open file ofstream outfile("file.txt"); // append file ofstream outfile("file.txt", ios_base::app); // write data to file if (! outfile) cerr << "failed to open file.\n"; else outfile << "content" << endl; // read data from file ifstream infile("file.txt"); if (! infile) cerr << "failed to open file.\n"; else { while (infile >> word) { cout << word << endl; } } 注释 /* * multi-line * comment */ int main() { // single line comment return 0; } 流程控制 while ...

January 1, 2000

Caddy

References Github - caddy 安装 Binary Keep Caddy Running 下载 binary:https://caddyserver.com/download 运行命令 sudo mv caddy /usr/bin/ sudo mkdir /etc/caddy sudo cp Caddyfile /etc/caddy/Caddyfile sudo groupadd --system caddy sudo useradd --system \ --gid caddy \ --create-home \ --home-dir /var/lib/caddy \ --shell /usr/sbin/nologin \ --comment "Caddy web server" \ caddy 将以下内容写入 /etc/systemd/system/caddy.service 文件 [Unit] Description=Caddy Documentation=https://caddyserver.com/docs/ After=network.target network-online.target Requires=network-online.target [Service] Type=notify User=caddy Group=caddy ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force TimeoutStopSec=5s LimitNOFILE=1048576 PrivateTmp=true ProtectSystem=full AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE [Install] WantedBy=multi-user.target 启动 sudo systemctl daemon-reload sudo systemctl enable --now caddy sudo systemctl status caddy 注意:centos 7 的 systemd 版本太低(219),需要先升级 ...

January 1, 2000

Censors

加速度传感器 MPU6050 References How to use MPU6050 6-axis (gyro + accelerometer) MEMS motion tracking sensor with Arduino Libraries Arduino-MPU6050 接线 VCC:2.0 ~ 5.0V I2C通信:SCL/SDA接Arduino对应接口 人体感应 AM312 接线 红外传感器 树莓派安装(系统为Raspbian Stretch) sudo apt update sudo apt install lirc 编辑/boot/config.txt dtoverlay=gpio-ir,gpio_out_pin=17,gpio_in_pin=18,gpio_in_pull=up 编辑 /etc/lirc/lirc_options.conf driver = default device = /dev/lirc0 重启sudo reboot后,查看是否有lirc0 ls -l /dev/lirc0 lsmod | grep lirc systemctl status lircd.service systemctl status lircd.socket References https://raspberrypi.stackexchange.com/questions/81876/raspberry-pi-3-not-lirc-not-running-working Remotes Database 音频 DFPlayer Mini References DFRobot - DFR0299 DFPlayer Mini Libraries DFRobotDFPlayerMini 接线 VCC:3.2 ~ 5.0V 通过UART接口与Arduino通信,注意Rx接口需要接1kΩ的电阻 似乎只能识别FAT16格式的SD卡,无法识别FAT32格式的 ...

January 1, 2000

CLI Apps

References Github - awesome-cli-apps Shell chezmoi chezmoi - Quick Start dotfiles dotfiles example # install sh -c "$(curl -fsLS get.chezmoi.io)" sudo mv bin/chezmoi /usr/local/bin # init chezmoi init # add dotfile chezmoi add {dotfile} # goto git dir chezmoi cd # init chezmoi and pull repo chezmoi init {git_url} # apply changes chezmoi apply -v # pull and apply chezmoi update -v tmux 可以通过修改配置 .tmux.conf 修改 prefix 键 ...

January 1, 2000

Coding

Tools Install pnpm install -g @anthropic-ai/claude-code pnpm install -g @openai/codex@latest pnpm install -g @google/gemini-cli pnpm install -g @qwen-code/qwen-code@latest Update pnpm update -g @anthropic-ai/claude-code # update all pnpm update -g Claude Code Doc Claude Code Usage: ctrl + v: paste image from clipboard shift + tab: plan mode/edit mode Qwen Coder Github - Qwen Code Codex Doc: Github - Codex Codex Gemini-CLI gemini-cli.dev Google AI Studio Google AI Studio MCP Github - Model Context Protocol servers MCP Market Higress ModelScope - MCP Plaza Github - Awesome MCP Servers Zen MCP Server Github - MCP Chrome MCPs Git Context7 MCP Chrome Spec Engineering Github - OpenSpec Github - spec-kit Github - BMAD-METHOD AGENTS.md Agents.md Github - Agents.md Github - Agent.md Github - awesome-copilot Spec Driven Workflow v1 Outline Project overview Build and test commands Code style guidelines Testing instructions Security considerations Template <Project Description> ## Architecture Frontend: Next.js with TypeScript Styling: Tailwind CSS Package manager: pnpm Database: MySQL ## Development Environment - Python: - use `uv run` to run python scripts, use `uv add --script <script.py> <package>` to solve dependcies, use `uv run --with <package> -- python -c ` to run ad-hoc python code - Data Warehouse: - use `mysql -h fe-c-ca4b4d642153fa7e-internal.starrocks.aliyuncs.com -P 9030 -ureadonly -p'V@!KG0fG' -Dpaimon.default` to inspect table and data - Object Storage: - use `rclone lsd oss:<bucket_name>/path/to/data` to inspect data in object storage

January 1, 2000