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 / 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 / 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 / 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
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 / 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
@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 / fizzbuzz.rb
Last active September 12, 2019 18:53
ruby -e '(1..100).map{|n| case n % 15; when 0 then "FizzBuzz"; when 5,10 then "Buzz"; when 3,6,9,12 then "Fizz"; else n; end}.display'
#!/usr/bin/ruby
# 15で割った余りに注目してFizzBuzz
class Integer
def fizzbuzz
case self % 15
when 0 then "FizzBuzz"
when 5,10 then "Buzz"
when 3,6,9,12 then "Fizz"
else self
@YuukiToriyama
YuukiToriyama / miopon.bash
Created September 17, 2019 14:01
mioponAPIをシェルから叩く
# .develoer_idにはデベロッパIDを.access_tokenにはアクセストークンをそれぞれ改行なしで入れるものとする
curl -H "X-IIJmio-Developer:$(cat .developer_id)" -H "X-IIJmio-Authorization:$(cat .access_token)" https://api.iijmio.jp/mobile/d/v2/coupon/ > test
@YuukiToriyama
YuukiToriyama / nhk_api.md
Created September 20, 2019 08:50
NHK番組表APIにアクセスできるようになるまで

NHK番組表APIにアクセスできるようになるまで

  1. api-portal.nhk.or.jpにアクセス api-portal.nhk.or.jpにアクセスし、アカウントを作成。「ユーザ登録がお済みでない方はこちら」をクリックしアカウントを作成する。

  2. アプリを作成 ログイン後、マイページを開きアプリを作成する。「アプリのURL」は任意のため、「アプリ名」を入力するだけでOK。アプリが作成できたら「登録済みアプリ」ページからそのアプリのページを開くと、APIにアクセスするのに必要なAPIキーを確認することができる。コピー&ペーストしてファイルに保存しておく。

  3. 使用できるAPIは4種類

@YuukiToriyama
YuukiToriyama / nhk_area
Created September 20, 2019 08:52
NHK放送局リスト
010 札幌 sapporo
011 函館 hakodate
012 旭川 asahikawa
013 帯広 obihiro
014 釧路 kushiro
015 北見 kitami
016 室蘭 muroran
020 青森 aomori
030 盛岡 morioka
040 仙台 sendai