Skip to content

Instantly share code, notes, and snippets.

View 10nin's full-sized avatar
🔥
真空に火を点ける

10nin 10nin

🔥
真空に火を点ける
View GitHub Profile
@10nin
10nin / csvquote.awk
Created January 18, 2013 09:47
| で区切られた各フィールドを二重引用符でくくって標準出力に出すawkスクリプト。 ExcelでCSV出力するときに二重引用符で囲めなかったので即興。
BEGIN {
FS="|"
}
{
for( i=1; i<=NF; i++ ) {
printf( "\"" $i "\"" ",")
}
printf("\n")
}
@10nin
10nin / Crypto.ex
Created June 5, 2013 11:52
Get MD5 message digest by elixir-lang.
defmodule Crypto do
def md5(s) do
list_to_binary(Enum.map(bitstring_to_list(:crypto.md5(s)), fn(x) -> integer_to_binary(x, 16) end))
end
end
@10nin
10nin / Crypto.ex
Created June 5, 2013 12:00
Get message digest generally by elixir-lang.
defmodule Crypto do
def gethash(typ, s) do
list_to_binary(Enum.map(bitstring_to_list(:crypto.hash(typ, s)), fn(x) -> integer_to_binary(x, 16) end))
end
def sha1(s), do: gethash(:sha, s)
def md5(s), do: gethash(:md5, s)
def sha256(s), do: gethash(:sha256, s)
def sha512(s), do: gethash(:sha512, s)
end
@10nin
10nin / thumb.sh
Created June 10, 2013 13:14
Create jpeg thumbnail fast.
#! /bin/sh
QUALITY=50
SIZE=120
OUTPUT='thumbnail/'${1%.*}'thumb.jpg'
convert -define jpeg:size=${SIZE} -quality ${QUALITY} -thumbnail ${SIZE} ${1} ${OUTPUT}
@10nin
10nin / joint_text.py
Created November 21, 2014 12:50
二つの文字列を水平方向にpretty printな感じで接続するスクリプト
def _justify_list(list1, list2):
"""短いほうのリストに空要素を追加して、リストの長さをそろえる"""
short_list = min(list1, list2, key=len)
c = max(len(list1), len(list2)) - len(short_list)
for i in range(0, c):
short_list.append('')
return list1, list2
def _join_str_list(parent_list, child_list, margin):
eto = ['申', '酉', '戌', '亥', '子', '丑', '寅', '卯', '辰', '巳', '午', '未']
print('年を入力')
y = int(input())
print('干支は{eto}'.format(eto[y%len(eto)]))
@10nin
10nin / md5_digest.py
Created February 17, 2015 14:00
Get md5 digest.
def get_digest(s):
import hashlib
m = hashlib.md5()
m.update(s.encode())
return m.hexdigest()
@10nin
10nin / get_timestamp.py
Created February 17, 2015 14:02
Get time stamp string formatted '%Y-%m-%d %H:%M'.
def get_timestamp():
from datetime import datetime
return datetime.now().strftime('%Y-%m-%d %H:%M')
#-*-coding:utf-8-*-
from datetime import datetime as dt
def make_time_table(raw_time_table):
"""入力された文字から、時間のリストを使って返します"""
ret = list()
# 1文字目は無意味なので読み捨てます
lst = raw_time_table.split(' ')[1:]
# 2要素ずつ取り出して、時間データとして確保します
@10nin
10nin / dm.lisp
Created July 26, 2017 13:44
Convert Decimal minutes (DM) and SI minuts & second
;; Convert DM->second
(defun dm-to-sec (x)
(* (/ x 100.0) 60.0))
;; Convert DM->minutes
(defun dm-to-min (x)
(/ x 100.0))
;; Convert second->minutes
(defun sec-to-min (x)
(/ x 60.0))
;; second->minutes convert with m:s.# style format