#author("2021-09-02T11:42:27+09:00","default:nobuoki","nobuoki") #author("2021-09-02T11:44:16+09:00","default:nobuoki","nobuoki") * Description / これは何? [#b422f6d7] Makes feces (FUN, 糞 as Japanese) that overlap as many as you receive from /dev/stdin. 標準入力から受け取った数だけ重なった、糞を作ります。 #prism(bash){{{ $ echo 3 | makefun ( (_) (___) $ echo 5 | makefun ( (_) (___) (_____) (_______) }}} * Usage / 使い方 [#xd130c62] Install / インストール #prism(bash){{{ $ (cd /tmp; wget https://gist.githubusercontent.com/kemasoft-oss/edb86fde900c0cb4c572ce39a2f0e50e/raw/a1b4f91afebd60ca4bc3a422e8457937802632 5e/makefun; chmod a+x makefun; sudo install makefun /usr/local/bin/) or $ wget -O /tmp/makefun https://bit.ly/3zFmITB; chmod a+x /tmp/makefun; sudo install /tmp/makefun /usr/local/bin/ -- snip -- 2021-09-02 10:35:34 (11.4 MB/s) - ‘makefun’ saved [183/183] }}} Draw / 描画する #prism(bash){{{ $ echo 3 | makefun ( (_) (___) }}} Uninstall / アンインストール #prism(bash){{{ $ sudo rm /usr/local/bin/makefun; hash -r $ makefun makefun: command not found }}} * server化 [#a3c2109c] ** start server / サーバ起動 [#i3c94484] #prism(bash){{{ socat tcp-l:19876,reuseaddr,fork exec:/usr/local/bin/makefun & }}} ** test / 動作確認 [#yb7dd612] #prism(bash){{{ $ echo 5 | socat - tcp:localhost:19876 ( (_) (___) (_____) (_______) }}} ** Call from another host / 他のホストから呼び出し [#b9e98b67] #prism(batch){{{ C:\> echo 3 | wsl socat - tcp:172.27.195.99:19876 ( (_) (___) }}} ** stop server / サーバ停止 [#taa525d1] #prism(bash){{{ kill %$(jobs | awk -F'[][]' '/19876/{print $2}') 2>/dev/null }}} * Implimentation / 解説 [#pef04db4] Goal / 肝となる部分 #prism(bash){{{ $ echo 5 | perl -nE 'for(; $_>0; $_--){say $s."_" x ($_*2-1); $s.=" "}' | sed 's/_/(/;s/_$/)/' | tac ( (_) (___) (_____) (_______) }}} ** n から 1 まで、2n-1 個の下線を引く [#j19da82c] Underline (2 * n - 1) from 'n' to 1 #prism(bash){{{ $ echo 5 | perl -nE 'for(; $_>0; $_--){say "_" x ($_*2-1)}' _________ _______ _____ ___ _ }}} ** N行目の先頭に N-1 個のスペースを入れる [#ye280a17] Insert (N - 1) spaces at the beginning of the Nth line #prism(bash){{{ $ echo 5 | perl -nE 'for(; $_>0; $_--){say $s."_" x ($_*2-1); $s.=" "}' _________ _______ _____ ___ _ }}} ** 前後を括弧に置き換える [#wf3ae003] Replace before and after with parentheses #prism(bash){{{ $ echo 5 | perl -nE 'for(; $_>0; $_--){say $s."_" x ($_*2-1); $s.=" "}' | sed 's/_/(/;s/_$/)/' (_______) (_____) (___) (_) ( }}} ** ひっくり返す [#ka7aacef] turn over Turn over #prism(bash){{{ $ echo 5 | perl -nE 'for(; $_>0; $_--){say $s."_" x ($_*2-1); $s.=" "}' | sed 's/_/(/;s/_$/)/' | tac ( (_) (___) (_____) (_______) }}} ** 申し訳程度のサニタイジングやパラメータ制限を入れておく [#g0726bf6] Put in minimum sanitizing and parameter restrictions - tr -dc 0-9 - exit if ($_ > 100); #prism(bash){{{ #!/bin/sh tr -dc 0-9 | perl -nE ' exit if ($_ > 100); for($i=$_; $i>0; $i--){ say $s."_" x ($i*2-1); $s.=" "; }' | sed 's/_/(/;s/_$/)/' | tac }}}