Skip to content

Instantly share code, notes, and snippets.

😉
Nanchatte

Yasuhiro Yamada greymd

😉
Nanchatte
  • Dublin, Ireland
Block or report user

Report or block greymd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@greymd
greymd / gist:4548a30365cea2d44f33
Last active Aug 29, 2015
因数分解→因数を全て足し算の速度比較 while vs awk
View gist:4548a30365cea2d44f33
#bashのwhile readを利用。
$ time seq 1000 | factor | while read a b; do echo $b | tr ' ' '+' | bc ;done > /dev/null
real 0m2.150s
user 0m1.370s
sys 0m3.259s
#awkのfor文を利用
$ time seq 1000 | factor | awk '{s=0;for(i=2;i<=NF;i++){s+=$i}print s;}' > /dev/null
@greymd
greymd / gist:425136954ade49ec39ad
Last active Aug 29, 2015
任意の整数(NUM)を2つの自然数の積で算出するために必要な数の組み合わせを求める。
View gist:425136954ade49ec39ad
#NUMには任意の整数を入れる
NUM=1000; \
egison -e '(p-f '$NUM')' | egison -T -m '(match-all-lambda (multiset integer) [<join $x $xs> [x xs ":"]])' | \
sed 's/":"/\n/g' | tr -s '\t' | sed -r 's/(^\t|\t$)//g' | sed 's/{}/{1}/' | grep -vP '^{.*}$' | awk 'NF' | \
egison -F 2c -m 'id' | egison -m '2#[(foldr * 1 %1) (foldr * 1 %2)]' | tr -d '[]' | \
awk '{if($1>$2){print $2" "$1}else{print}}' | sort -k1,1n -k2,2n | uniq
#Example
# [NUM=100]
@greymd
greymd / gist:fa3ba0788075a1ce2955
Last active Aug 29, 2015
常用漢字とその画数
View gist:fa3ba0788075a1ce2955
一 1
乙 1
九 2
七 2
十 2
人 2
二 2
入 2
八 2
力 2
@greymd
greymd / gist:fb45abc82971eec318d6
Last active Aug 29, 2015
任意の自然数の体積を持つ直方体の持ち得る自然数x, y, zの組み合わせを求めるEgisonシェル芸
View gist:fb45abc82971eec318d6
$ echo 64 | \
egison -T -m '1#(match-all (p-f %1) (multiset integer) [ <join $xs <join $ys $zs>> [(foldl * 1 xs) (foldl * 1 ys) (foldl * 1 zs)]])' | \
xargs -n 3 | \
egison -T -f '3#(and (lte? %1 %2) (lte? %2 %3))' | \
sort | uniq
# 結果 (体積64の直方体)
# 1 1 64
# 1 2 32
# 1 4 16
@greymd
greymd / smsis.sh
Last active Aug 29, 2015
SMクラブから、同じOPPAIのカップ数を持ち、身長が小中大になっている女王様三姉妹の組み合わせを抽出する
View smsis.sh
#!/bin/sh
curl -L urx.nu/ibQd | nkf -wZ | \
sed -n -r '/<p>/{s/\(([0-9]*)\)</\t\1\t</;h;n;y@\(\)@\t\t@;x;G;s@</?p>@@g;y@/@\t@;s/\n//;p}' | \
tr -s '\t' | awk -F'\t' 'NF==7' | cut -f1,3,5 | \
cat list | egison -T -F1,1s -F3s -s '(match-all-lambda
(multiset [string integer string])
[ <cons [$n1 $tal1 $cup]
<cons [$n2 (& ?(gt? $ tal1) $tal2),cup]
<cons [$n3 (& ?(gt? $ tal2) $tal3) ,cup]
_>>>
@greymd
greymd / gist:9f9d68f5aee96553d8f9
Created Jun 12, 2015
関東圏の路線の遅延情報取得シェル芸
View gist:9f9d68f5aee96553d8f9
curl -sLo- goo.gl/xEZPhi| grep info/deta -A1 | xargs | sed 's/ -- /\n/g' | grep -v 平常運転 | awk -F'[=><]' '{print $6,$5}' | while read a b; do echo -n $a":"; curl -so- $b | grep 'og:description' | grep -oP '(?<=content=").*(?=")' ;done
View gist:99f86ba2b93d5c4bf012
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'
View vib.ino
int VIB = 2;
int state = LOW;
void setup(){
Serial.begin(9600);
pinMode(VIB,OUTPUT);
}
void loop(){
if (Serial.available()) {
char c = Serial.read();
if (c == '1') {
View squares.sh
# 参考: https://twitter.com/ryuichiueda/status/637570756138823680
W=9; H=9 ;printf $(printf "+%%0${W}d\\\n%0${H}s\n" | sed "s/ /|%${W}s\\\n+%0${W}d\\\n/g") | sed 's/0/---+/g' | sed 's/ / |/g'
# 結果
# +---+---+---+---+---+---+---+---+---+
# | | | | | | | | | |
# +---+---+---+---+---+---+---+---+---+
# | | | | | | | | | |
# +---+---+---+---+---+---+---+---+---+
# | | | | | | | | | |
View shell_gei_18_ans.md

第18回シェル芸勉強会個人的回答

https://blog.ueda.asia/?p=6836

Q4

$ cat cross | sed 's/./& /g' | \
perl -anlE 'printf chr($_+ord(a)-1)."-".$F[0]."=".$F[$_]." " for (1..$#F); say ""' | \
grep -oP '.{3}(?=\=x)'
You can’t perform that action at this time.