Just another Ruby porter,

〜2015年12月上旬〜


<Older(,) | Newer(.)> | Recent(/)>> | RDF


2015-12-01 (Tue)

Docker小ネタ



% docker ps -l
% docker rm `docker ps -lq`



% docker ps -l
% docker ps -lq|xargs docker rm



docker images --tree--viz便使
deprecate
--tree
Deprecate 'docker images --tree' and 'docker images --viz' by shykes · Pull Request #5001 · docker/docker


2015-12-02 (Wed)

dockviz


--treedockviz使
dockerdockvizstaticlink

% docker run nate/dockviz images
Unable to find image 'nate/dockviz:latest' locally
latest: Pulling from nate/dockviz
8bd831364921: Pull complete
3dfb5e1486b5: Pull complete
607d274e6daa: Pull complete
Digest: sha256:9afe152b794ae8480b230545ec75bc81f5e11a0b9d28158bb609479de5a95a72
Status: Downloaded newer image for nate/dockviz:latest
Unable to access Docker socket, please run like this:
  docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz images <args>
For more help, run 'dockviz help'
% docker ps -lq | xargs docker export | tar x dockviz
% file dockviz
dockviz: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
% ./dockviz images -t
├─8bd831364921 Virtual Size: 5.9 MB
│ └─3dfb5e1486b5 Virtual Size: 5.9 MB
│   └─607d274e6daa Virtual Size: 5.9 MB Tags: nate/dockviz:latest
├─039b63dd2cba Virtual Size: 1.1 MB
│ └─c51f86c28340 Virtual Size: 1.1 MB Tags: busybox:latest
└─0c5a95b92fbb Virtual Size: 87.0 MB
  └─c59aaaa35c20 Virtual Size: 87.0 MB
    └─40f9f9531e43 Virtual Size: 820.7 MB
      └─560151ab7b6b Virtual Size: 882.4 MB
        └─dec1400ab1bd Virtual Size: 882.4 MB
          └─a0d99d01b2a3 Virtual Size: 905.5 MB
            └─232ed8986774 Virtual Size: 1.0 GB
              └─3859c9a9c729 Virtual Size: 1.8 GB
                └─86cceda0c83a Virtual Size: 1.8 GB
                  └─ca77a6cff892 Virtual Size: 1.8 GB
                    └─be540060a179 Virtual Size: 1.8 GB
                      └─fc9a7b5c096a Virtual Size: 1.8 GB
                        └─7db11899a300 Virtual Size: 1.8 GB Tags: hone/mruby-cli:latest



2015-12-03 (Thu)

factor


factorfactor

% factor 10 20
10: 2 5
20: 2 2 5
% echo 10 20 | factor
10: 2 5
20: 2 2 5
% echo "10\n20"         
10
20
% echo "10\n20" | factor
10: 2 5
20: 2 2 5

使

2015-12-04 (Fri)

BASHでCSVを扱う #シェル芸


Bash -  TipsGolf/ - Qiita

cat data.csv | while read line
do
  cols=(`echo $line | tr ',' ' '`)
  for ((i=0; i < ${#cols[@]}; i++)) {
    echo "Column $((i+1)): ${cols[$i]}"
  }
done

BASHread -a
cat data.csv | while read line
do
  cols=(`echo $line | tr ',' ' '`)


cat data.csv | while IFS=, read -a cols
do


% bash -c 'echo "a,b c,d" | while IFS=, read -a f;do for i in "${f[@]}";do echo "$i";done;done'
a
b c
d

2015-12-05 (Sat)

csvtool


LinuxCSVcsvtool
debiancsvtool

% seq 9 | xargs -n3 | tr ' ' , # テスト用のCSVを用意
1,2,3
4,5,6
7,8,9
% seq 9 | xargs -n3 | tr ' ' , | csvtool col 2 - # 2番目のフィールドだけ
2
5
8
% seq 9 | xargs -n3 | tr ' ' , | csvtool col 2- - # 先頭のフィールドを削除
2,3
5,6
8,9
% seq 9 | xargs -n3 | tr ' ' , | csvtool setcolumns 2 - # 2番目まで
1,2
4,5
7,8
% seq 9 | xargs -n3 | tr ' ' , | csvtool width - # フィールド数
3
% seq 9 | xargs -n3 | tr ' ' , | csvtool height - # レコード数
3
% seq 9 | xargs -n3 | tr ' ' , | csvtool head 2 - # 先頭の2レコード
1,2,3
4,5,6
% seq 9 | xargs -n3 | tr ' ' , | csvtool drop 2 - # 先頭の2レコードを削除
7,8,9
% echo 'a,"b\nc",d' | bash -c 'x(){ for i in "$@";{ echo $i;};}; export -f x; csvtool call x -'
a
b c
d

"b\nc"""ok
call使callback

2015-12-06 (Sun)

gawk 4以降でCSVを扱う


FPAT-F,""
% echo 'a,"b,c",d' | gawk '{OFS="|"; $1=$1; print}' FPAT='[^,]+|\"[^\"]+\"'
a|"b,c"|d

RubyString#scan

gawkinfo FPAT
FPAT = "([^,]+)|(\"[^\"]+\")"

()

2015-12-07 (Mon)

ExcelでCSV形式で保存

改行を含むフィールドがあると

"a\r\nb"

ではなく

"a\nb"

のようになぜかCRがつかない形式になる。
行末はCR+LFなのでawk的にはRS="\r\n"にすれば普通に扱えてしまうのであった。


2015-12-08 (Tue)

  CygwinGNU awk


CygwinGNU awk
CR+LFLF
Cygwin
BEGINBINMODE="r"
-r BINMODE=r
% printf '\r\n' | gawk '{print length()}'
0
% printf '\r\n' | gawk -v BINMODE=r '{print length()}'
1

2015-12-09 (Wed)

busybox --install


busyboxsymlink
busybox--install
使hardlink-ssymlink
% mkdir bin
% busybox --install -s bin
% ls bin
[   cp   egrep       httpd lsmod   passwd      seq   taskset      unlzop
[[   cpio   env       hwclock lzcat   patch       setkeycodes  tee       unxz
acpid   crond   expand       id lzma   pidof       setsid   telnet       unzip
adjtimex  crontab  expr       ifconfig lzop   ping       sh   telnetd      uptime
ar   cttyhack  false       ifdown lzopcat   ping6       sha1sum   test       usleep
arp   cut   fdisk       ifup md5sum   pivot_root  sha256sum   tftp       uudecode
arping   date   fgrep       init mdev   poweroff    sha512sum   time       uuencode
ash   dc   find       insmod microcom  printf      sleep   timeout      vconfig
awk   dd   fold       ionice mkdir   ps       sort   top       vi
basename  deallocvt  free       ip mkfifo   pwd       start-stop-daemon  touch       watch
blockdev  depmod  freeramdisk  ipcalc mknod   rdate       stat   tr       watchdog
brctl   devmem  fstrim       kill mkswap   readlink    static-sh   traceroute   wc
bunzip2   df   ftpget       killall mktemp   realpath    strings   traceroute6  wget
bzcat   diff   ftpput       klogd modinfo   reboot      stty   true       which
bzip2   dirname  getopt       last modprobe  renice      su   tty       who
cal   dmesg   getty       less more   reset       sulogin   tunctl       whoami
cat   dnsdomainname  grep       ln mount   rev       swapoff   udhcpc       xargs
chgrp   dos2unix  groups       loadfont mt   rm       swapon   udhcpd       xz
chmod   dpkg   gunzip       loadkmap mv   rmdir       switch_root  umount       xzcat
chown   dpkg-deb  gzip       logger nameif   rmmod       sync   uname       yes
chpasswd  du   halt       login nc   route       sysctl   uncompress   zcat
chroot   dumpkmap  head       logname netstat   rpm       syslogd   unexpand
chvt   dumpleases  hexdump      logread nslookup  rpm2cpio    tac   uniq
clear   echo   hostid       losetup od   run-parts   tail   unix2dos
cmp   ed   hostname     ls openvt   sed       tar   unlzma
% ls -l bin/cp
lrwxrwxrwx 1 eban eban 12 2015-12-10 02:47:26 bin/cp -> /bin/busybox

Dockerfile

2015-12-10 (Thu)

ツイッター人望指数



% curl -Ls twitter.com/nhk_news  | grep -o '[0-9]\+人'| awk '$0=($2*++$2/++$1)^.5' RS=

commify
% curl -Ls twitter.com/nhk_news  | grep -o '[0-9,]\+人'
14人
1,588,067人


curl -Ls twitter.com/nhk_news  | grep -o '[0-9,]\+人' | tr -d , | awk '$0=($2*++$2/++$1)^.5' RS=

<Older(,) | Newer(.)> | Recent(/)>> | RDF



WWW を検索 jarp.does.notwork.org を検索

わたなべひろふみ
Key fingerprint = C456 1350 085F A320 C6C8 8A36 0F15 9B2E EB12 3885
Valid HTML 4.01!