Hero Image
How to Delete Files With Names That Contain Non-printable Characters

How to Delete Files With Names That Contain Non-printable Characters ls -l total 13 -rw-r--r-- 1 ZZ 197121 4 Nov 6 07:08 ' ' -rw-r--r-- 1 ZZ 197121 162 Apr 16 2022 '~$iscord.docx' -rw-r--r-- 1 ZZ 197121 6 Nov 6 06:03 ''$'\302\226' -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:01 ''$'\302\226''Λ---ω' -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:13 '␴?␴??␴??::␴?␴' -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:12 ␴__␴ -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:14 ␴␴␴␴␴␴␴␴␴␴␴␴␴␴␴␴␴ -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:18 '␴ω␴␴␣␦'$'\342\220\264' -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:16 ␣␣␣␣␣␣␣␣ -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:26 ␣ μ μ Ω Ω -rw-r--r-- 1 ZZ 197121 14 Nov 6 06:23 '␣ μ ␴'$'\342\220\264''Ξ' -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:27 -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:27 Using ANSI-C Quoting # Using ANSI-C Quoting rm ''$'\302\226' # We can also use the $ special character before enclosing the filename in single quotes rm $'\356\200\215' # pass an item's name to rm without using the ANSI-C quoting rm '\026\033' rm: cannot remove '\026\033': No such file or directory Using Inode Numbers ls -li total 11 ... 6517085 -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:18 '␴ω␴␴␣␦'$'\342\220\264' 7826050 -rw-r--r-- 1 ZZ 197121 3 Nov 9 04:23 ''$'\356\200\215\356\200\215\356\200\215' 4685554 -rw-r--r-- 1 ZZ 197121 4 Nov 6 06:27 we can delete the desired file by passing its inode number to the -inum switch of the find command

Hero Image
善用 Go Fuzzing,幫助你寫出更完整的單元測試

善用 Go Fuzzing,幫助你寫出更完整的單元測試 func Pow(base uint, exponent uint) uint { if exponent == 0 { return 1 } return base * Pow(base, exponent-1) } func FuzzPow(f *testing.F) { f.Fuzz(func(t *testing.T, x, y uint) { assert := assert.New(t) assert.Equal(Pow(x, 0), uint(1)) assert.Equal(Pow(x, 1), x) assert.Equal(Pow(x, 2), x*x) if x > 0 && y > 0 { assert.Equal(Pow(x, y)/x, Pow(x, y-1)) } }) } go test -fuzz=Fuzz -fuzztime 20s 在做 Fuzzing Test 的時候如果跑一跑 FAIL 了,Go 會幫忙把那組 input 記在 testcase/ 裡面 看了之後會發現在 x=6、y=30 時 assert 會失敗,也就是說 pow(6, 30)/6 不會等於 pow(6, 29)。但這也太奇怪了吧?仔細實驗之後才發現是因為在計算 pow(6, 30) 的時候會發生 overflow。 因為 Go 定義的 max.MaxUint 大約是 18 * 10¹⁸,但 6²⁹ 大概是 7 * 10¹⁸。如果把 6²⁹ 再乘上 6,就會發生 overflow 得到 8 * 10¹⁸,很像繞了操場兩圈結果在跟原本差不多的位置。 var ErrOverflow = fmt.Errorf("overflow") func Pow(base uint, exponent uint) (uint, error) { if exponent == 0 { return 1 } prevResult, err := Pow(base, exponent-1) if math.MaxUint/base < prevResult { return 0, ErrOverflow } return base * prevResult, nil } func FuzzPow(f *testing.F) { f.Fuzz(func(t *testing.T, x, y uint) { assert := assert.New(t) if result, err := Pow(x, 1); err != ErrOverflow { assert.Equal(result, x) } if result, err := Pow(x, y); x > 0 && y > 0 && err != ErrOverflow { resultDivX, _ := Pow(x, y-1) assert.Equal(result/x, resultDivX) } }) }

Hero Image
一張圖學會【拼音輸入法】

一張圖學會【拼音輸入法】 聲母(Initials) 聲母 拼音 例字 ㄅ b 爸 ba、別 bie、奔 ben ㄆ p 撇 pie、平 ping、鵬 peng ㄇ m 媽 ma、莫 mo、某 mou ㄈ f 發 fa、飯 fan、風 feng ㄉ d 的 d、但 dan、段 duan ㄊ t 他 ta、貼 tie、團 tuan ㄋ n 你 ni、農 nong、暖 nuan ㄌ l 李 li、亂 luan、亮 liang ㄍ g 跟 gen、怪 guai、灌 guan ㄎ k 快 kuai、考 kao、狂 kuang ㄏ h 哈 ha、漢 han、橫 heng ㄐ j 叫 jiao、雞 ji、京 jing ㄑ q 七 qi、琴 qin、巧 qiao ㄒ x 西 xi、寫 xie、小 xiao ㄓ zh 知 zhi、戰 zhan、正 zheng ㄔ ch 吃 chi、船 chuan、重 chong ㄕ sh 是 shi、山 shan、刷 shuan ㄖ r 日 ri、讓 rang、人 ren ㄗ z 字 zi、讚 zan、昨 zuo ㄘ c 次 ci、菜 cai、餐 can ㄙ s 三 san、四 si、算 suan 介音 / 特殊聲母 類型 拼音 例字 y yi / i 以 yi、依 yi、修 xiu w wu / u 無 wu、溫 wen、船 chuan v yu / ü 律 lü、雨 yu、院 yuan 單韻母(Finals) 韻母 拼音 例字 ㄚ a 沙 sha、撒 sa、奧 ao ㄛ o 哦 o、偶 ou、歐 ou ㄜ e 餓 e、樂 le、設 she ㄝ ê / ye 也 ye、學 xue、切 qie ㄞ ai 愛 ai、篩 shai、崖 yai ㄟ ei 雷 lei、最 zui、脆 cui ㄠ ao 凹 ao、老 lao、笑 xiao ㄡ ou 歐 ou、樓 lou、手 shou ㄢ an 安 an、蘭 lan、算 suan ㄣ en 恩 en、林 lin、冷 leng ㄤ ang 昂 ang、浪 lang、讓 rang ㄥ eng 成 cheng、冷 leng、令 ling ㄦ er 二 er、兒 er、而 er 複韻母 / 組合韻 拼音 例字 ye 也 ye、結 jie、血 xie iu 六 liu、有 you、謬 miu in 音 yin、新 xin、林 lin ing 英 ying、靈 ling、醒 xing uan 元 yuan、卷 juan、團 tuan ue 略 lue、學 xue yun 雲 yun、巡 xun、群 qun ong 用 yong、兇 xiong、同 tong ui 鬼 gui、為 wei、虧 kui un 文 wen、混 hun、準 zhun ua 華 hua、抓 zhua、蛙 wa uai 壞 huai、快 kuai、踹 chuai

Hero Image
How to Make Output Overwrite the Same Line in a Terminal

How to Make Output Overwrite the Same Line in a Terminal Introduction to the Problem $ cat print_status.sh !/bin/bash echo "[INFO] Processing file: readme.txt" sleep 2 To simulate the file processing echo "[INFO] Processing file: veryPowerfulService.service" sleep 2 echo "[INFO] Processing file: log.txt" echo "DONE" $ ./print_status.sh [INFO] Processing file: readme.txt [INFO] Processing file: veryPowerfulService.service [INFO] Processing file: log.txt DONE The “Magic Code”: \033[0K\r -n option asks the echo command to stop outputting the trailing newline character -e option allows the echo command to interpret backslash escapes such as \n (newline) and \r (carriage return) \033 - It’s the escape sequence. In other words, it’s ESC. \033[ - Then this becomes “ESC [”, which is the control sequence introducer (CSI). \033[0k - So it’s “CSI 0 K”. Further, “CSI 0 K” erases the text from the cursor to the end of the line. \r - This is the carriage return. It brings the cursor to the beginning of the line. $ cat print_status.sh #!/bin/bash echo -ne "[INFO] Processing file: readme.txt\033[0K\r" sleep 2 echo -ne "[INFO] Processing file: veryPowerfulService.service\033[0K\r" sleep 2 echo -e "[INFO] Processing file: log.txt\033[0K\r" echo "DONE" !/bin/bash printf "[INFO] Processing file: readme.txt\033[0K\r" sleep 2 printf "[INFO] Processing file: veryPowerfulService.service\033[0K\r" sleep 2 printf "[INFO] Processing file: log.txt\033[0K\r\n" echo "DONE"