Skip to content

Instantly share code, notes, and snippets.

@nekonaq
nekonaq / format-epoch.awk
Last active February 20, 2022 23:11
prints a epoch time in human friendly format
# cat /proc/uptime
{
insec = $1;
# insec = 20 # 20s
# insec = 2400; # 40min
# insec = 3600 * 2; # 2h
# insec = 4300; # 1h 12min <- 1h 11m 40s
# insec = 86400; # 1day
# insec = 86400 + 2400; # 1day <- 1d 40min
# insec = 86400 + 3600 * 2; # 1day 2h
@nekonaq
nekonaq / tstamp60.py
Last active January 28, 2021 23:00
uuid の 60bit タイムスタンプ
# - https://stackoverflow.com/questions/3795554/extract-the-time-from-a-uuid-v1-in-python
'''
import time
import datetime
import uuid
>>> uu = uuid.uuid1()
>>> uu
UUID('ca7f909e-6197-11eb-b755-fe8e2a52ce52')
@nekonaq
nekonaq / output
Created August 29, 2019 02:50 — forked from Cinderhaze/output
How to pretty-print hashes and arrays for puppet debugging
ubuntu@ubuntu:~$ puppet apply pretty.pp [12/46]
Notice: Scope(Class[main]): {one => 1, two => [dos, 2]}
Notice: Scope(Class[main]):
{
"one": "1",
"two": [
"dos",
"2"
]
}

awk で単一の空白文字をフィールド区切りとして扱う

次のようなデータがあるとする。

$ cat data
@nekonaq
nekonaq / README-sparse-files.org
Last active April 8, 2019 07:25
スパースファイルの基本操作

スパースファイルの操作

スパースな 10M のファイルを作成する

#// 通常のファイルを作成
@nekonaq
nekonaq / README-float-calc-in-shell-script.org
Last active April 6, 2019 13:38
シェルスクリプトで小数点以下の演算

シェルスクリプトで小数点以下の演算を行う

  • bc コマンドを使う
        
@nekonaq
nekonaq / README-firstboot-setup.org
Last active April 8, 2019 07:23
インストール直後のシステム起動で一度だけ実行するスクリプト

インストール直後のシステム起動で一度だけ実行するスクリプトを仕掛ける

@nekonaq
nekonaq / dockerhub-tags
Last active February 12, 2019 06:44
DockerHub にあるイメージのタグとハッシュの一覧を表示する
#!/bin/bash
set -e
main() {
local repo="$1" # e.g. 'fluentd/fluentd'
if [ -z "$repo" ]; then
echo "$0: invalid parameter" >&2
return 1
fi
@nekonaq
nekonaq / git-revision
Last active February 12, 2019 06:35
git のタグから現在のバージョン文字列を生成する
#!/bin/sh
set -e
main() {
local git_toplevel="$( git rev-parse --show-toplevel 2>/dev/null ||: )"
if [ -z "$git_toplevel" ]; then
echo "$0: not a git repository" >&2
exit 1
fi
git describe --tags HEAD 2>/dev/null |