Skip to content

Instantly share code, notes, and snippets.

View greymd's full-sized avatar
๐Ÿ˜‰
Nanchatte

Yasuhiro Yamada greymd

๐Ÿ˜‰
Nanchatte
View GitHub Profile
@greymd
greymd / arr_ifs.md
Last active May 4, 2017 06:44
bash: IFSใจ้…ๅˆ—ใฎ[*]ใฎๆŒ™ๅ‹•
$ bash --version
GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
@greymd
greymd / setu.bash
Last active May 1, 2017 05:15
difference between "${1+$@}" and ${1+"$@"}
#!/bin/bash
set -u
argtest() {
printf '$@: '
echo "$@"
printf '$# '
echo $#
printf '$1 '
echo $1 ;shift
@greymd
greymd / dir_permission.md
Last active April 26, 2017 11:48
ๆ›ธใ่พผใฟใจ่ชญใฟ่พผใฟๆจฉ้™ใฎใฟใ‚’ๆŒใฃใŸใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒช(rw-)ใฃใฆใฉใ‚“ใชๅ‹•ไฝœใ™ใ‚“ใฎ๏ผŸ

่ชญใฟ่พผใฟใ€ๆ›ธใ่พผใฟๆจฉ้™ใฎใฟใงใ€ๅฎŸ่กŒๆจฉ้™ใŒใชใ„็Šถๆ…‹ใฎใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒช(drw-)ใฎๅ‹•ไฝœใŒๆฐ—ใซใชใฃใŸใฎใงใƒกใƒขใ€‚่‰ฒใ€…ๆคœ็ดขใ—ใฆใ‚‚ใ“ใฎใ‚ฑใƒผใ‚นใฏ็„กใ‹ใฃใŸใฎใงใ€‚ ใใ‚‚ใใ‚‚ใ€wใŒใคใ„ใฆใฆxใŒใคใ„ใฆใชใ„ใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒชใฃใฆใฟใชใ„ใชใจๆ€ใฃใŸใฎใงใ€‚

็’ฐๅขƒ

Dockerใ‚ณใƒณใƒ†ใƒŠใงๆคœ่จผ ใ‚คใƒกใƒผใ‚ธใฏubuntu:16.04

ๅ…ˆใซ็ต่ซ–

@greymd
greymd / gist:873a66a45a42858706452fb81227da2c
Last active April 24, 2017 10:42
ๆœ€ๅˆใซ่ฆ‹ใคใ‘ใŸ๏ผ“ใคใฎ่จ€่‘‰ใŒใ€Œใ‚ใชใŸใŒไบบ็”Ÿใงๆ‰‹ใซๅ…ฅใ‚ŒใŸใ„ใ‚‚ใฎใ€(https://goo.gl/SVT1Cs)
ใฆ ใŸ ใŽ ใ† ใช ใ— ใ‚€ ใž ใ‚ ใต ใ“ ใ† ใ˜ ใท ใฉ
ใ ใด ใฉ ใ‹ ใฎ ใ” ใ† ใฑ ใ” ใซ ใค ใ‚‚ ใ• ใŒ ใ‚
ใž ใ‚“ ใ ใผ ใ† ใต ใ“ ใจ ใŠ ใ ใ‚ ใ‚† ใ„ ใ‚’ ใ„
ใŒ ใ– ใ‹ ใญ ใ‚ˆ ใฝ ใ† ใถ ใ— ใ‚„ ใ‚“ ใ† ใ‚Š ใ ใ‚ˆ
ใŸ ใจ ใต ใ™ ใ‚ ใ ใด ใ• ใช ใพ ใณ ใˆ ใ‚“ ใต ใš
ใฅ ใ‚“ ใก ใ‚ˆ ใ› ใ„ ใ“ ใ† ใŽ ใ‚† ใญ ใค ใช ใ‚“ ใŠ
ใ› ใ ใ• ใ‚† ใถ ใฏ ใ ใค ใ™ ใ‚ ใ‹ ใ• ใ˜ ใ— ใ
ใฌ ใ„ ใ ใ† ใ„ ใ‚ ใค ใฏ ใพ ใ‚Š ใก ใ„ ใ“ ใญ ใ‚ˆ
ใŠ ใท ใ˜ ใต ใ† ใ‚ ใ“ ใ‘ ใ† ใ‚‹ ใ› ใฉ ใ— ใ‚ ใ†
ใธ ใ„ ใ‚ ใค ใ ใฉ ใก ใ‚ˆ ใ‚“ ใ„ ใ‚ ใ† ใท ใ‚“ ใ‚Š
@greymd
greymd / shifts.md
Created April 20, 2017 12:09
shift within multiple functions with bash
parse1() {
    echo "$1"
    shift
    parse2 "$@"
    echo "$1"
}

parse2() {
 echo "$1"
@greymd
greymd / cure.glue
Created March 27, 2017 13:37
cure.glue
import /usr/bin/ as ub
proc cure = /usr/local/bin/docker 'run' '-i' 'greymd/cureutils' 'cure' argv[1]
proc cure_date_stdin = /usr/local/bin/docker 'run' '-i' 'greymd/cureutils' 'cure' 'date' '-f' '-' argv[1]
ub.seq '1' '365' >>=
ub.sed 's/$/ days ago/' >>=
this.cure_date_stdin '+%F @P' >>=
this.cure 'grep' >>=
ub.sed 's|/.*$||' >>= ub.head
@greymd
greymd / tree_full_path.md
Last active March 13, 2017 07:42
convert tree result to have full path.

tree -f ใงใ„ใ„ใ˜ใ‚ƒใ‚“ใจใ„ใ†่ฉฑใ€‚

$ tree test | awk 'NF{depth=gsub("[โ”‚โ”œโ””]","&",$0); if(last_depth < depth){dirs[depth]=last_dir;}else if(last_depth > depth){dirs[last_depth]="";} last_dir=$NF;last_depth=depth;pdir=".";for (i in dirs){pdir=pdir"/"dirs[i];} gsub("/$","",pdir);$NF=pdir"/"$NF;print}' | sed '$d'

Preparation

$ mkdir test/{aaa,bbb}
$ touch test/aaa/{aaa1,aaa2,aaa3}
@greymd
greymd / versions.sh
Last active March 8, 2017 11:17
bash & zsh versions
$ curl -so- https://ftp.gnu.org/gnu/bash/ | perl -nle '/(bash-.*?tar.gz)/ and print $1' | grep -v doc | uniq
bash-1.14.7.tar.gz
bash-2.0.tar.gz
bash-2.01.1.tar.gz
bash-2.01.tar.gz
bash-2.02.1.tar.gz
bash-2.02.tar.gz
bash-2.03.tar.gz
bash-2.04.tar.gz
bash-2.05.tar.gz
$ git tag | grep -E 'curl-[0-9]+_[0-9]+_[0-9]$' | awk -F'_' '{if(!a[$1_$2]){print} a[$1_$2]++}' | tr '_' ' ' | sort -k1,1n -k2,2n -k3,3n | tr ' ' '_'
curl-7_1_1
curl-7_4_1
curl-6_5_1
curl-7_5_2
curl-7_6_1
curl-7_7_1
curl-7_8_1
curl-7_9_1
curl-7_10_1
@greymd
greymd / gist:4483de16fe563d8ee8c2b57c1a247fc7
Last active February 28, 2017 15:48
Build curl on Linux
# CentOS
$ yum install autoconf automake libtool libtool-ltdl openssl-devel tar
$ curl -sL https://github.com/curl/curl/archive/curl-7_20_0.tar.gz | tar zxv
$ cd curl-curl-7_20_0/
$ ./buildconf
$ ./configure --enable-libcurl-option
$ make && make install
# Ubuntu
$ apt-get update