《Disney +》 迪士尼、Marvel、彼思、星球大戰…  《Hunter’s Arena: Legends》封閉測試即將登上PS5   荒野行動 × 七大罪聯名活動第2彈開跑!新年服裝與全新載具皮膚隆重登場!   手心大小玩偶「Pokémon fit」系列確定推出神奧地區的寶可夢!   《God of War Ragnarök》首度亮相   《NBA 2K22》為PlayStation帶來新賽季和新發現   hololive旗下VTuber湊阿庫婭&獅白牡丹加入電競大賽「Red Bull 5G」官方應援團   【開箱實測】JBL 最新款便攜式藍芽音箱「JBL CHARGE 5」!   《House of Ashes》– 將恐怖音效變得栩栩如生 

cheat.sh:Cheatsheet 的線上、CLI 查詢工具

商業

程式撰寫常常需要線上查資料、查 Library 或者查詢寫法(ex: foreach 的參數) 等等,有個線上服務出現,將這些種種問題一次解決。

各種程式語言、各種寫法範例、Cheatsheet 等等,在這個網站都可以直接查到,而且還有提供 CLI (crt.sh) 直接透過 CURL 存取查詢。

使用方式

  • curl https://cheat.sh/ # 即可開始使用
  • curl https://cht.sh/ # 即可開始使用

註:此篇最下面有將 cht.sh 與 vim 快速鍵結合,方便查詢

cheat.sh:Cheatsheet 的線上、CLI 查詢工具

cheat.sh / cht.sh 都是一樣的,在這邊將操作的一些技巧做點紀錄

註:cht.sh 和 cheat.sh 都一樣,以下都用 cht.sh 來操作

使用 CURL 就可以存取操作的範例:

  • curl cht.sh/go/Pointers
  • curl cht.sh/scala/Functions
  • curl cht.sh/python/lambda
  • curl cht.sh/tar
  • curl cht.sh/go/reverse+a+list
  • curl cht.sh/python/random+list+elements
  • curl cht.sh/js/parse+json
  • curl cht.sh/go/reverse+a+list
  • curl cht.sh/python/random+list+elements
  • curl cht.sh/js/parse+json
  • curl cht.sh/lua/merge+tables
  • curl cht.sh/clojure/variadic+function
  • curl cht.sh/python/random+string
  • curl cht.sh/python/random+string/1 # 需要另外給參數,可於 / 後面另外加上
  • curl cht.sh/python/random+string/2 # 另外加上參數
  • curl cht.sh/lua/table+keys
  • curl cht.sh/lua/table+keys?Q # 不需要 comment,只要答案
  • curl cht.sh/go/reverse+a+list?Q
  • curl cht.sh/python/random+list+elements?Q
  • curl cht.sh/js/parse+json?Q
  • curl cht.sh/lua/merge+tables?QT # 不需要 syntax highlight
  • curl cht.sh/clojure/variadic+function?QT

將 cht.sh 安裝於 CLI

雖然可以使用 curl 直接存取,不過有點麻煩,這邊有更方便的工具:(可安裝於 CLI)

  1. curl https://cht.sh/:cht.sh >/tmp/cht.sh
  2. sudo mv /tmp/cht.sh /usr/bin/cht.sh
  3. chmod +x /usr/bin/cht.sh # 到此即安裝完成
  4. 下述是執行範例
    • cht.sh /php/ file_exist
    • cht.sh /go/isset
    • cht.sh /php/ explode

cht.sh 想要 CLI 更進階的操作介面

  1. sudo apt install rlwrap xsel # xsel for copy
  2. cht.sh --shell
  3. cht.sh> help
    help - show this help
    hush - do not show the 'help' string at start anymore
    cd LANG - change the language context
    copy - copy the last answer in the clipboard (aliases: yank, y, c)
    ccopy - copy the last answer w/o comments (cut comments; aliases: cc, Y, C)
    exit - exit the cheat shell (aliases: quit, ^D)
    id [ID] - set/show an unique session id ("reset" to reset, "remove" to remove)
    stealth - stealth mode (automatic queries for selected text)
    update - self update (only if the scriptfile is writeable)
    version - show current cht.sh version
    /:help - service help
    QUERY - space ceparated query staring (examples are below)
                cht.sh> python zip list
                cht.sh/python> zip list
                cht.sh/go> /python zip list
  4. cht.sh> cd php
  5. cht.sh/php> file_exists

將 cht.sh 與 Vim 結合 (游標的字自動丟給 cht.sh)

使用 F4 的快速鍵,將 vim 目前的 file-type + 存取到的字,丟進 cht.sh 來查詢

  1. vim ~/.vimrc
  2. 以下找隨意的地方寫入即可,在此用 為快速鍵 (使用一行的寫法,暫時不知道該怎麼將 file-type 自動帶入,所以寫成 Function 來處理)
    " 查詢此字的 cheatsheet (crt.sh)
    "nmap  :!/usr/bin/cht.sh /php/ =expand("")
    "nmap F :!/usr/bin/cht.sh /php/ =expand("")
    function! QueryFunctionCheatsheet()
        let my_filetype = &filetype
        let current_word = expand("")
        execute ":!/usr/bin/cht.sh /".my_filetype."/ ".current_word
    endfunction
    map  :call QueryFunctionCheatsheet()
  3. 再來隨便進入 *.php 或 *.py 之類的,移動到 function 的名字,直接按 F4 就可以查詢囉~
Tsung

隨機商業新聞

NordVPN