画像のフォーマットを判別する
<?php $filename = 'path/to/image'; $handle = fopen($filename, 'rb'); $header = fread($handle, 8); fclose($handle); if ($header === "\x89PNG\x0d\x0a\x1a\x0a") { echo 'PNG'; } elseif (substr($header, 0, 2) === "\xff\xd8") { echo 'JPEG'; } elseif (preg_match('/\AGIF8[79]a/', $header)) { echo 'GIF'; } else { echo 'something else' }
[git] git サブモジュールについて
$ git clone https://yourname@github.com/yourproject/yourrepo
$ git submodule init
$ git submodule update
もしくは
$ git clone --recursive https://yourname@github.com/yourproject/yourrepo
監視系コマンドまとめ
サーバーの接続数を表示する
$ sudo watch -d -n 3 "netstat -alpn | grep -E ':(80|443) ' | awk '{print \$5}' | sed -e 's/\:[^.]*$//' | sort | uniq -c | sort -nk1 -r | head -n 20"
サーバーの接続状態を表示する
$ sudo watch -d -n 2 "netstat -tan | grep -E ':(80|443) ' | grep -E '(ESTABLISHED|LISTEN|TIME_WAIT)' | awk '{print \$6}' | sort | uniq -c"
WEB サーバーから MySQL への接続数を表示する
$ sudo watch -d -n 2 "netstat -tan | grep ':3306 ' | grep -E '(ESTABLISHED|LISTEN|TIME_WAIT)' | awk '{print \$6}' | sort | uniq -c"
MySQL への接続で TIME_WAIT が 30秒以上のものを表示する
$ sudo watch -d -n 2 "netstat -tano | grep ':3306 ' | grep -E ' \([3-5][0-9]' | awk '{print \$1}' | sort | uniq -c"
Googlebot の接続数を表示する
$ sudo watch -d -n 3 "netstat -alpn | grep -E '66.249.(6[469]|7[1379])' | awk '{print \$5}' | sed -e 's/\:[^.]*$//' | sort | uniq -c | sort -nk1 -r" $ sudo watch -d -n 3 "netstat -alpn | grep -E '66.249.(6[469]|7[1379])' | awk '{print \$5}' | sed -e 's/\:[^.]*$//' | sort | uniq -c | sort -nk1 -r | awk '{sum+=\$1}END{print \"Goooglebot: \" sum}'"
サーバーのデータ転送量をみる
$ awk '$1=="eth0:" {printf "rx: %fMB tx: %fMB\n", $2/1024/1024, $10/1024/1024}' < /proc/net/dev $ watch -d -n 3 "awk '\$1==\"eth0:\" {printf \"rx: %f MB tx: %f MB\n\", \$2/1024/1024, \$10/1024/1024}' < /proc/net/dev"
新規に記事を作成する
$ hugo new post/welcome.md
HUGO で theme を自作する
$ ls archetypes/ config.toml content/ data/ layouts/ README.md static/ themes/ $ hugo new theme my-theme $ ls themes/ my-theme
HUGO で WEB サイトの初期データを作成する
$ hugo new site ~/path/to/your/site
$ cd ~/path/to/your/site
$ ls
archetypes/ config.toml content/ data/ layouts/ README.md static/ themes/