Skip to content

Instantly share code, notes, and snippets.

View suzuki-shunsuke's full-sized avatar

Shunsuke Suzuki suzuki-shunsuke

View GitHub Profile
@suzuki-shunsuke
suzuki-shunsuke / datetime_example.py
Created January 11, 2016 11:47
datetimeのロケールの操作
import datetime
import pytz
# ロケールのないdatetimeにロケール情報を与える
d = datetime.datetime.now() # naiveなローカルな時刻を取得
d2 = pytz.timezone("Asia/Tokyo").localize(d)
# ロケールを変更する
d3 = d2.astimezone(pytz.utc)
from functools import reduce
def concate(*args):
return reduce(
lambda func1, func2: lambda value: func2(func1(value)),
args
)
{
"presets": ["es2015"],
"plugins": ["transform-runtime"]
}
@suzuki-shunsuke
suzuki-shunsuke / upgrade-node
Created August 2, 2017 03:57
nodebrew の nodeのバージョンアップするスクリプト
#!/usr/bin/env zsh
set -e
NODE_VERSION=$1
nodebrew install-binary $NODE_VERSION
nodebrew use $NODE_VERSION
PACKAGES=(
@suzuki-shunsuke
suzuki-shunsuke / upgrade-node
Last active August 14, 2017 02:24
nodebrew の nodeのバージョンアップするスクリプト
#!/usr/bin/env zsh
set -e
NODE_VERSION=$1
nodebrew install-binary $NODE_VERSION
nodebrew use $NODE_VERSION
PACKAGES=(
@suzuki-shunsuke
suzuki-shunsuke / error.go
Created September 15, 2017 14:28
runtimeエラーを処理する汎用的なコード。
package models
type RuntimeError interface {
Param() interface{} // runtimeエラーが起こった祭のpanic()の引数を取得
Error() string
}
type runtimeErrorImpl struct {
data struct {
param interface{}
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/ghodss/yaml"
)
@suzuki-shunsuke
suzuki-shunsuke / playbook.yml
Created January 5, 2018 12:58
ansibleのshell(command)モジュールで標準出力によってchangedを判定する方法
---
- hosts: localhost
tasks:
- shell: "echo '{\"changed\": true}'"
register: result
changed_when: (result.stdout|from_json)["changed"]
- shell: "echo '{\"changed\": false}'"
register: result
changed_when: (result.stdout|from_json)["changed"]
{
"permissions" : {
"outputs" : [ "create", "edit", "terminate", "read" ],
"sources" : [ "read" ],
"indexranges" : [ "read", "rebuild" ],
"deflector" : [ "read", "cycle" ],
"loggers" : [ "readsubsystem", "edit", "editsubsystem", "read" ],
"inputs" : [ "terminate", "read", "create", "changestate", "edit" ],
"lbstatus" : [ "change" ],
"roles" : [ "edit", "create", "read", "delete" ],
@suzuki-shunsuke
suzuki-shunsuke / decode_hook.go
Last active March 29, 2018 05:16
sample code of mapstructure's DecodeHook
package main
import (
"fmt"
"log"
"reflect"
"github.com/mitchellh/mapstructure"
"github.com/suzuki-shunsuke/go-set"
)