Skip to content

Instantly share code, notes, and snippets.

View YuukiToriyama's full-sized avatar
🚲
On Cycling

ToriChan YuukiToriyama

🚲
On Cycling
  • Kyoto, Japan
View GitHub Profile
@YuukiToriyama
YuukiToriyama / scala_regexp.md
Created August 28, 2019 08:07
Scala 正規表現を使って文字列を切り出したい

部分文字列を取り出したい

こんなことがしたい。

echo "aiueo700" | sed 's/\([a-z]*\)\([0-9]*\)/\1 and \2/g'
# => aiueo and 700

正規表現オブジェクトのつくりかた

@YuukiToriyama
YuukiToriyama / circle_animation.bash
Created June 29, 2019 13:53
ImageMagickで円グラフアニメーションを描く【シェル芸】
mkdir im
for i in {01..51}; do
seq 1 $i | awk '{r = 8*atan2(1,1)/50 * $1; printf "%f,%f ", 200*cos(r) + 250, 200*sin(r) + 250}' | xargs -I@ convert -size 500x500 xc:Yellow -fill Red -stroke Black -draw 'path "M 250,250 @ z"' im/$i.png
done
convert im/*.png -delay 10 circle_graph.gif
rm -r im
seq 1 230 | awk '{r = 8*atan2(1,1)/47 * $1; printf "%f,%f ", sin($1)*$1*cos(r) + 250, sin($1)*$1*sin(r) + 250}' | xargs -I@ convert -size 500x500 xc:yellow -fill red -stroke Black -draw 'path "M @ z"' a_flower.png
@YuukiToriyama
YuukiToriyama / koch_curves.md
Created June 22, 2019 22:42
Some Arrangements of Koch Curve【Bash,ImageMagick,シェル芸】

koch island

eval echo "fbfbfbf" "| sed 's/f/faffbffbfbfafaffbfbfafaffaffbf/g'"{,} | grep -o [ab]*f | awk 'BEGIN{x=250;y=250;rx=0;ry=13} {tmp=rx; printf "%s,%s ", x,y; x=x+rx; y=y+ry; if($1=="af"){rx=-ry; ry=tmp}else if($1=="bf"){rx=ry; ry=-tmp}} END{printf "%s,%s", x,y}' | xargs -I@ convert -size 1000x1000 xc:DarkRed -fill none -stroke Yellow -strokewidth 4 -draw "path 'M @'" koch_island.png

koch flower

eval echo "fbfbfbf" "| sed 's/f/ffbfbfbfbfbfaf/g'"{,,} | grep -o [ab]*f | awk 'BEGIN{x=50;y=550;rx=0;ry=20} {tmp=rx; printf "%s,%s ", x,y; x=x+rx; y=y+ry; if($1=="af"){rx=-ry; ry=tmp}else if($1=="bf"){rx=ry; ry=-tmp}} END{printf "%s,%s", x,y}' | xargs -I@ convert -size 1000x1000 xc:DarkRed -fill none -stroke Yellow -strokewidth 4 -draw "path 'M @'" flower.png
@YuukiToriyama
YuukiToriyama / national_anthem.bash
Last active November 24, 2024 21:26
bashでオルゴール【Sox】
# National Anthem of USSR
# Execute this ShellScript, Soviet Anthem Plays You.
# Before execute this, you have to install Sox(Sound eXchange) by apt-get / brew.
mkdir notes
cat << EOS | grep -v "-" | awk '{if ($1=="z") {print "sox -n -c 2 notes/"NR".wav trim 0.0", $2/4} else {{print "sox -n -c 2 notes/" NR ".wav synth", $2/4, "pluck", $1, "\\"} if ($3!="") {print "pluck", $3, "\\"} if ($5!="") {print "pluck", $5, "\\"} print ";"}}END{print "sox notes/{1.."NR-1"}.wav song_new.wav"}' | bash
E4 4 G4 4 C5 4
-
D4 1 G4 1 D5 1
C4 1 G4 1 C5 1
@YuukiToriyama
YuukiToriyama / imagemagick_cube.bash
Created May 27, 2019 19:35
またつまらないシェル芸を作ってしまった
#!/bin/bash
convert -size 1500x500 pattern:checkerboard -fill Black -pointsize 400 -font "Symbola" -draw 'text 30,350 "Sh ell 💩"' -write mpr:L -crop 500x500+0+0! -virtual-pixel none -distort Perspective '0,0 100,350 500,0 100,150 0,500 250,400' -write mpr:tmp +delete mpr:L -crop 500x500+500+0! -virtual-pixel none -distort Perspective '0,0 100,150 500,0 250,100 0,500 250,200' mpr:tmp -composite -write mpr:tmp +delete mpr:L -crop 500x500+1000+0! -virtual-pixel none -distort Perspective '0,0 250,200 500,0 400,150 0,500 250,400' mpr:tmp -composite unko.png
@YuukiToriyama
YuukiToriyama / bionomical_coefficient.bash
Created May 20, 2019 13:49
二項係数を計算するawkだけのゴリ押しワンライナー
#!/bin/bash
# Usage
# 先頭のecho ""にパスカルの三角形の何段目まで二項係数を計算したいか入力します。
# 8行目行中にある「{print $0}」の部分を削除すれば、パスカルの三角形は表示せずに求めたい段の二項係数のみが表示されるようになります。
# Copyright 2019 YUUKIToriyama All Rights Reserved
echo "10" | awk '{for (n=1; n<=$1; n++){ for (m=1; m<=n; m++){printf "$"m"+$"m+1","} printf "\n" }}' \
| awk 'BEGIN{printf "echo 1 1"}{printf " | awk \047{print $0}END{print 1," $0 "1}\047"}' \
| bash
@YuukiToriyama
YuukiToriyama / 格子線を描く方法.md
Created May 20, 2019 08:27
Create vertical lines on canvas【ImageMagick】

ImageMagickで鉄格子を描く方法

convert -size 90x1 pattern:gray50 -scale 500x500! show:

画像の高さを1ピクセルにしてパターンを適用すると、ちょうと等間隔に黒い点が打たれるようになります。まずそのような細長の画像を作って、それを-scaleオプションを使って縦に引き伸ばします。

格子線の例

完全にエクセル函数を頭に入れた人用の「セルの入力からグラフの作成まですべてをコマンド入力だけで済ませるプラグイン」みたいなのをつくろうかと思っている。

@YuukiToriyama
YuukiToriyama / communists_shellgei.sh
Created May 16, 2019 10:39
hard political shellgei
convert -size 700x300 xc:black -font Symbola -pointsize 300 -gravity center -fill white -draw 'text 0,0 "🗺"' -write mpr:A +delete -size 100x100 xc:red -font Symbola -pointsize 100 -fill yellow -gravity center -draw 'text 0,0 "★"' -write mpr:star +delete -size 700x300 tile:mpr:star mpr:A -compose multiply -composite redstars.png