Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
tkuchiki / _usage
Last active August 29, 2015 14:01
webサーバから proxy した http request ヘッダを出力する SimpleHTTPServer
$ ./httpserver.py
$ ./httpserver.py PORT
$ ./httpserver.py IPADDR
$ ./httpserver.py IPADDR:PORT
@tkuchiki
tkuchiki / result.md
Created May 25, 2014 14:46
bonnie++(program to test hard drive performance)
# CentOS
## epel
$ yum install onnie++

# Ubuntu
$ apt-get install 
@tkuchiki
tkuchiki / parse_json.md
Created May 27, 2014 11:26
json 文字列を受けとって、任意のキーの値を出力する
$ echo '{"hosts":[{"name":"host1"},{"name":"host2"}]}' | python -c "exec(\"import json,sys\\nj=json.load(sys.stdin)\\nfor attr in j.get('hosts'):\\n    print attr.get('name')\")"
host1
host2
@tkuchiki
tkuchiki / _env
Last active August 29, 2015 14:01
User Data で instance 起動時に ephemeral を mount する(RAID0)
- Amazon Linux AMI release 2014.03
- cloud-init-0.7.2-7.20.amzn1.noarch
(
- Amazon Linux AMI release 2013.09
- cloud-init-0.5.15-77.amzn1.noarch
)
@tkuchiki
tkuchiki / json-checker
Last active August 29, 2015 14:01
jsonlint で json の syntax check を行う
#!/bin/bash
if [ $# -eq 0 ]; then
echo -e "\nUsage: $(basename $0) DIR [DIR ...]\n"
echo -e " json syntax checker(require jsonlint)\n"
exit 1
fi
if type jsonlint > /dev/null 2>&1 && [ $? -ne 0 ]; then
echo "jsonlint is required. [npm install -g jsonlint]"
@tkuchiki
tkuchiki / add-ip-and-hostname.py
Last active August 29, 2015 14:02
aws ec2 describe-instances を叩いて [local ip] [hostname] を /etc/hosts に追記する
#!/usr/bin/env python
# coding: utf-8
import sys
import json
import subprocess
p = subprocess.Popen(['aws', 'ec2', 'describe-instances'], shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
@tkuchiki
tkuchiki / error.md
Created June 2, 2014 10:02
rpm trouble shooting

error: %preun(PACKAGE.el6.x86_64) scriptlet failed, exit status 1

rpm -e --noscripts PACKAGE
@tkuchiki
tkuchiki / default.rb
Created June 2, 2014 10:18
ruby_block の中で、template resource を実行する
ruby_block "create template" do
block do
template = Chef::Resource::Template.new("/path/to/file", run_context)
template.owner "root"
template.cookbook "COOKBOOK_NAME"
template.mode 0644
template.source "conffile.erb"
template.variables({
:foo => "bar",
})
@tkuchiki
tkuchiki / link_to_daemontools.sh
Last active August 29, 2015 14:02
daemontools で service を起動できていなかったら、service を停止して symlink を消す
@tkuchiki
tkuchiki / term-ui
Created June 5, 2014 09:15
Term::UI for bash (未完成)
#!/bin/bash
CHOICES=$(echo "hoge foobar piyo")
CHOICES="${CHOICES} nothing"
NUM=$(echo $CHOICES | wc -w)
echo "question?"
for i in $(seq 1 $NUM); do
echo "${i}) $(echo $CHOICES | cut -d ' ' -f $i)"