Hello 2024

Hello 2024, goodby 2023. In 2024, I wish I’ll write more blog posts, at least one pre week. Last year, I finally got a basement to do some woodworking, and recently I bought a some wood and a lot of woodworking tools, every weekend I will go there and do some woodworking, I only finished a horse bench, three shelfs, wish I will finish one or two tables in 2024.

January 2, 2024 · notsobad

Zsh eat my curl Output

I got a strange problem today, a URL is supposed to return something in it’s body, but when use curl to get that url, it outputs nothing. curl 'http://localhost:9527/static/a.js' At first, I think it might be server problems, but when using wireshark to see the traffic, there is nothing wrong, http header followed by \r\n then http response body. I have also noticed that this happens when the response body is short. Testing with browser or python-requests is fine. So it’s not the server error, could it be curl’s problem? Let’s strace it. >> strace -vv curl 'http://localhost:9527/static/a.js' ...... recvfrom(5, "HTTP/1.1 200 OK\r\nServer: YNM3K-9"..., 102400, 0, NULL, NULL) = 443 newfstatat(1, "", {st_dev=makedev(0, 0x1d), st_ino=6, st_mode=S_IFCHR|0620, st_nlink=1, st_uid=1000, st_gid=5, st_blksize=1024, st_blocks=0, st_rdev=makedev(0x88, 0x3), st_atime=1703671640 /* 2023-12-27T18:07:20.893334033+0800 */, st_atime_nsec=893334033, st_mtime=1703671640 /* 2023-12-27T18:07:20.893334033+0800 */, st_mtime_nsec=893334033, st_ctime=1703662393 /* 2023-12-27T15:33:13.893334033+0800 */, st_ctime_nsec=893334033}, AT_EMPTY_PATH) = 0 brk(0x560907e02000) = 0x560907e02000 rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f68b677f710}, NULL, 8) = 0 rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f68b677f710}, NULL, 8) = 0 write(1, "a.js", 4a.js) = 4 rt_sigaction(SIGPIPE, NULL, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f68b677f710}, 8) = 0 ...... From strace output, I can see it write a.js to fd 1, which is stdout, so it get the response body, and write to stdout, maybe it’s the terminal? ...

December 27, 2023 · notsobad

Auto open apps on Mac

I poweroff my laptop every night. So I have to open some app I use everyday when I started the laptop. I use a script by Justin Hileman, to open news tabs in terminal. Save this script as init.sh, run sh init.sh in the terminal, and it will do several things: run wg.sh, setup wireguard tunnal open new tab, start a tmux session open new tab, using mosh to ssh a server open new tab, open a txt file using vim open github in chrome start vs code show a popup message #!/bin/bash # # Open new Terminal tabs from the command line # # Author: Justin Hileman (http://justinhileman.com) # # Installation: # Add the following function to your `.bashrc` or `.bash_profile`, # or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc` # # Usage: # tab Opens the current directory in a new tab # tab [PATH] Open PATH in a new tab # tab [CMD] Open a new tab and execute CMD # tab [PATH] [CMD] ... You can prob'ly guess function tab () { local cmd="" local cdto="$PWD" local args="$@" if [ -d "$1" ]; then cdto=`cd "$1"; pwd` args="${@:2}" fi if [ -n "$args" ]; then cmd="; $args" fi osascript &>/dev/null <<EOF tell application "iTerm" tell current window set newTab to (create tab with default profile) tell newTab tell current session write text "cd \"$cdto\"$cmd" end tell end tell end tell end tell EOF } function alert(){ title="$1" msg="$2" osascript &>/dev/null <<EOF display notification "$msg" with title "$title" EOF } ~/wg.sh || exit tab "tmux new -s x" tab "mosh root@xxxx" tab "vi notes.txt" open -a "Google Chrome" https://github.com/ code alert "have a nice day"

December 21, 2023 · notsobad

Using Windows

最近开始用一台旧的XPS 13笔记本,之前被自动升级到了win 11,于是就开始了windows的体验,目前可以使用WSL2,里面安装了ubuntu 22.04, 然后发现了另外一个比较有意思的软件,就是winget, 这个之前一直没有用过,这次就体验了一下。 winget是一个windows的命令行的软件管理器,运行winget update, 它会自动探测系统中已安装的软件版本,然后和数据库中对比,之后就可以选择性的升级。命令行安装或者升级软件还是很方便的,除了部分软件会弹出一个权限确认的窗口外,基本不需要人工交互。这个解决了windows没有软件库的问题,也解决了升级问题。不是所有软件都自身带有自动升级和新版本检测的,比如kicad,不用winget的话,想更新就要自己去官网检查、下载、安装才可以。 ...

December 1, 2023 · notsobad

vscode Tips

不同步某些配置项 参考:https://code.visualstudio.com/docs/editor/settings-sync#_configuring-synced-data 可以设置settingsSync.ignoredSettings, 或者直接在gui上,将“同步此配置”的勾选去掉。比如我可能希望在不同的设备上有不同的主题,就可以配置为 ...

November 20, 2023 · notsobad

Gitlab Ci Tips

调试ci 参考这篇文章: https://www.lullabot.com/articles/debugging-jobs-gitlab-ci 本地配置gitlab runner环境 在本地代码中操作,修改ci脚本使其在适当的位置sleep 本地提交改动过的代码,注意ci只会执行在git仓库中的代码 运行runner docker exec进入运行中的容器 本地运行runner,注意增加超时时间,避免被杀掉 ...

October 8, 2023 · notsobad

Clickhouse Tips

投影projection 官方文档https://clickhouse.com/docs/en/sql-reference/statements/alter/projection 创建这个特性时的讨论:https://github.com/ClickHouse/ClickHouse/issues/14730 ...

September 14, 2023 · notsobad

ffmpeg Tips

安装 brew install ffmpeg --with-libvpx --with-libvorbis --with-ffplay ffmpeg -codecs ffmpeg -f avfoundation -list_devices true -i "" 查看文件信息 ffmpeg -i screen.mp4 录屏 ffmpeg -r 30 -f avfoundation -i 1 -vcodec vp8 -quality realtime screen2.webm ffmpeg -r 30 -f avfoundation -i 1 -vcodec h264 screen.mp4 视频转换为gif ffmpeg -ss 2 -t 4 -i screen.mp4 -s 240x180 screen.gif 视频转为图片 ffmpeg -i video.mp4 image%d.jpg 视频文件的前十秒,每一秒生成一张图片 ffmpeg -i Downloads/硅谷第5季第一集.mp4 -r 1 -frames 10 -f image2 xx-%3d.jpeg 直播 docker run -it --rm -p 9080:80 -p 1935:1935 -v ~/tmp:/usr/local/nginx/html chakkritte/docker-nginx-rtmp ffmpeg -y -loglevel warning -f avfoundation -i 1 -r 30 -s 480x320 -threads 2 -vcodec libx264 -f flv rtmp://test-serv:1935/live/test ffmpeg -y -loglevel warning -f avfoundation -i 0 -s 480x320 -threads 2 -vcodec libx264 -f flv rtmp://test-serv:1935/live/test ffmpeg -f avfoundation -framerate 30 -i "2:0" -f avfoundation -framerate 30 -video_size 640x480 -i "0" -c:v libx264 -preset ultrafast -filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://test-serv:1935/live/test 摄像头录制 ffmpeg -f avfoundation -framerate 30 -i "0" -target pal-vcd ./test.mpg 提取文件长度 ffprobe -i $i -show_entries format=duration -v quiet -of csv="p=0" ffmpeg -i ~/新录音\ 9.m4a random.wav 拆分文件 ffmpeg -i random.wav -f segment -segment_time 9 -c copy random-%03d.wav 局域网内多播 https://news.ycombinator.com/item?id=34912300 ...

August 31, 2023 · notsobad

Archlinux Tips

使用archinstall进行安装,注意终端只有一个tty,错误输出会打印到这个tty里,可以临时禁用错误输出。 dmesg -n 1 另外archinstall中输入密码时如果发现无法回车确认,可以用ctrl + j来代替回车。 安装gnome pacman -S gnome systemctl enable gdm systemctl start gdm 安装KDE ...

August 29, 2023 · notsobad

Golang Tips

快速的单个文件测试 # run without build go run main.go # 如果 main.go依赖test.go, 那就需要指定好依赖文件,或者用go build go run main.go test.go # or build it go build -o xxx main.go ./xxx godoc 文档: go install golang.org/x/tools/cmd/godoc@latest godoc -http :6060 # visit http://localhost:6060/ 使用protobuf,需要安装protoc-gen-go, 同时~/go/bin要在 PATH 里 ...

August 21, 2023 · notsobad