Skip to content

Instantly share code, notes, and snippets.

View greymd's full-sized avatar
😉
Nanchatte

Yasuhiro Yamada greymd

😉
Nanchatte
View GitHub Profile
cat number | sed 's/./ &/g' | \
egison -F1c -m '(match-all-lambda (list integer) [<join _ <join $a _ <join ,a _>>> [a]])' |\
grep -oP '{.*?}' | sort | uniq -c | sort -n | awk 'NF>=4' | grep '^ *2'
@greymd
greymd / gist:cc4a957f45f3cc598c6a
Last active August 29, 2015 14:03
DICOMO2014 attendees list
curl -so- www2.infonets.hiroshima-u.ac.jp/dicomo/program/program.html | nkf -w | grep green | grep 著者 | sed 's/).*//' | sed 's/.*(//' | sort | uniq -c | sort -nr
set cdpath=%~1
set escapedPath=%cdpath:\=\\%
start C:\cygwin64\bin\mintty.exe /bin/bash -lc "cd '%escapedPath%'; exec bash"
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\CygwinOpen]
"NoWorkingDirectory"=""
@="CygwinOpen"
[HKEY_CLASSES_ROOT\Directory\Background\shell\CygwinOpen\command]
@="C:\\cygwin64\\CygwinOpen.bat \"%V\""
@greymd
greymd / apt-cyg_install.sh
Created September 15, 2014 09:39
apt-cyg install oneliner
wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg -P /usr/bin && chmod 755 /usr/bin/apt-cyg
@greymd
greymd / gist:a6933f2472b888a75014
Last active August 29, 2015 14:13
南武線の駅の中で、快速→各停→快速 となっている不憫な並びの3駅を抽出するegisonシェル芸。
# 南武線の駅の中で、快速→各停→快速 となっている不憫な並びの3駅を抽出するegisonシェル芸。
curl -so- -L goo.gl/4Gl1BL | tr ',\n' '\t' | egison -F 1cs -m '(match-all-lambda (list something) [ <join _ <cons $x <cons ,"快速" <cons $y <cons ,"各停" <cons $z <cons ,"快速" >>>>>>> [x y z]] )'
# [Result]
# {["鹿島田" "平間" "向河原"] ["登戸" "中野島" "稲田堤"] ["稲田堤" "矢野口" "稲城長沼"]}
#
# 既存のgrep等による単純な文字列マッチでは難しいオーバーラップしたパターンをループなしで検出できる。
# curlで習得する文字列には「稲田堤」はひとつしか含まれていないが、
# 例では稲田堤がオーバーラップしている。
@greymd
greymd / gist:26892f933d21dd84c2ac
Last active August 29, 2015 14:13
ジャンケンの結果が「グー パー グー パー」のように4話のうち2回ずつ同じパターンがでたサザエさんの話数
w3m -dump http://www.asahi-net.or.jp/~tk7m-ari/sazae_ichiran.html | \
sed 's/(.*//g' | awk NF | awk '$0=$1" "$3' | sed -n '4,$p' | tr ' ' '\t' | \
egison -T -F1s -s '(match-all-lambda
(list [string string])[
<join _ <cons [$a $te1]
<cons [$b $te2]
<cons [$c ,te1]
<cons [$d ,te2]>>>> _>
[a b c d "=>" te1 te2 te1 te2]
])' | column -t
@greymd
greymd / gist:352f9a6ec70d2a5f607f
Created January 20, 2015 14:30
「メロスは激怒した」と同じような語感を持つ文を「走れメロス」から抜き出す
# 形態素解析器を使うのでmecabを事前にインストールされたし
# % brew install mecab
# 青空文庫から「走れメロス」を取得
$ w3m -dump http://www.aozora.gr.jp/cards/000035/files/1567_14913.html | \
mecab | awk -F',' '$0=$1' | awk 'NF==2' | \
egison -F1s -s '(match-all-lambda (list [string string])[<join _ <cons [$a ,"名詞"] <cons [$b ,"助詞"] <cons [$c ,"名詞"] <cons [$d ,"動詞"] <cons [$e ,"助動詞"]>>>>>> [a b c d e]])'
# Result
# ["メロス" "は" "激怒" "し" "た"]
@greymd
greymd / gist:db0ec53d0221d1d76b49
Last active August 29, 2015 14:13
ポーカーのストレートフラッシュ製造機
# Macの場合shufではなくgshufをつかってください。
yes | xargs bash -c "echo {'♦','♥','♣','♠'}' '{1..13} | xargs -n 2 | tr ' ' '\t' | shuf" | \
egison -F1,1s -s '(match-all-lambda
(multiset [string integer])[
<cons [$s $n]
<cons [,s ,(- n 1)]
<cons [,s ,(- n 2)]
<cons [,s ,(- n 3)]
<cons [,s ,(- n 4)]
@greymd
greymd / gist:93d495bd3cca88e31dae
Last active August 29, 2015 14:14
円周率を求めるシェル芸
#/bin/bash
#NUMが大きいほど精度がよくなる
NUM=50; paste <(seq 1 2 $NUM) <(seq $NUM) | \
awk 'NF==2' | awk '{print $1"+ "$2"^2/"}' | \
xargs | awk '$0="4/ "$0" 1"' | xargs -n 1 | \
sed 's/^/(/g'| perl -anle '{print $_}END{print ")" x $.}' | \
xargs | awk '$0="scale=20;"$0' | bc