Skip to content

Instantly share code, notes, and snippets.

Avatar
😉
Nanchatte

Yasuhiro Yamada greymd

😉
Nanchatte
  • Dublin, Ireland
View GitHub Profile
@greymd
greymd / equalized_partition_nums.sh
Last active Aug 12, 2018
Divide integer num much equally with bash
View equalized_partition_nums.sh
#!/bin/bash
ceiling () {
local divide="$1";shift
local by="$1"
printf "%s\\n" $(( ( divide + by - 1 ) / by ))
}
equalized_partition_nums () {
local number="$1";shift
local count="$1"
@greymd
greymd / fifo.sh
Last active Jul 31, 2018
Docker + fifo + tmux bug ?
View fifo.sh
#!/bin/bash
# Try this script on the docker container.
# Tested on macoOS High Sierra + Ubuntu 18.04 docker container.
rm -f "$HOME"/work/*
tmux -S "$HOME"/work/sess new-session -d
printf "%s\\n" A B C D | while read -r f;do
View gist:42c1c245e2a6c0e10db176d314081f62
--------------------
bash 3.2.0
--------------------
~$ bash --version
GNU bash, version 3.2.0(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
~$ [[ "hoge" =~ ho.. ]] && echo "${BASH_REMATCH[0]}"
hoge
@greymd
greymd / gist:6edbff59405fcf5d4802cdb910587db0
Last active Jul 7, 2018
めも:【問題のみ】jus共催 第36回七夕・・・7は素数じゃないですか(しかも2つ)シェル芸勉強会
View gist:6edbff59405fcf5d4802cdb910587db0
Q1:
<welcome.txt tr '\0' '*' | fold -w 70
初っ端からひどい
Q2:
ls | perl -C -Mutf8 -nle 'printf "mv $_ ";$_ =~ tr/0-9/0-9/ ;$_ =~ tr/A-Z/A-Z/;$_ =~ m/([0-9]).*([A-Z])/; print " $1年$2組.doc"'
Q3:
echo 2018{01..12}{01..31}$'\n' | date -f- +'%Y%m%d' 2>/dev/null | grep -P '([2357].*){4}'
@greymd
greymd / app.log
Last active May 25, 2018
app.log
View app.log
2017-05-09 20:53:26 INFO --- [thread-1] myapp.logic : Register records
2017-05-09 20:53:26 INFO --- [thread-1] myapp.logic : --> POST https://api.example/v2/records http/1.1
2017-05-09 20:53:27 INFO --- [thread-1] myapp.logic : response: <?xml version="1.0" encoding="UTF-8"?>
<root>
<records>
<record>
<id>A001</id>
<date>1990-01-04</date>
<status>0</status>
</record>
@greymd
greymd / script.sh
Last active May 16, 2018
Convert app.log to csv
View script.sh
sed '/response:/{:loop;N;/<\/root>/!b loop;s/\n//g}' app.log | \
# 特定の時間帯のログだけをgrep
grep '^2017-05-09 20:5[0-9]' | \
# あとはgrepなりsedなりawkなりで自由に抽出
grep -oP '<record> *\K.*?(?= *</record>)' | sed 's/<\/[^>]*> *<[^>]*>/,/g;s/<[^>]*>//g'
# 同じディレクトリにapp.logを置いて実行
# $ bash script.sh
# 出力結果:
# A001,1990-01-04,0
View gist:9527645a73662b641a34d6c07e459ae5
$ dc -e'0[1+ddn10P10>r]srlrx'
1
2
3
4
5
6
7
8
View gist:079c4964f04ab03003f35c7e5a9c8dc1
# https://unix.stackexchange.com/questions/205936/how-can-i-quickly-sum-all-numbers-in-a-file/205939
perl -pe 's/\d*/$s+=$&/ge}{$_=$s' file
perl -F= -pe '$s+=$F[1]}{print $s' file
awk -F= '{sum+=$2};END{print sum}'
@greymd
greymd / hibike.dc
Last active Apr 12, 2018
響け!ユーフォニアムをdcのみで
View hibike.dc
[響] 0:a [け] 1:a [!] 2:a [ユ] 3:a [ー] 4:a [フ] 5:a [ォ] 6:a [ニ] 7:a [ア] 8:a [ム] 9:a
0sc
[
lc
lC+
10%;an
lC
1+
d
sC
View gist:efc0f69d76925e599c32844a767f653a
## From: https://en.wikipedia.org/wiki/Dc_(computer_program)
## prime number
2p # A = 2; print A
3p # A = 3; print A
## スタックの先頭にある数とsqrt(処理中の数)を計算
[ # func f-# (int n) int {
d # A = n(試す数)
l! # B = ! -- nと試し割りの割る数を用意
You can’t perform that action at this time.