Skip to content

Instantly share code, notes, and snippets.

View morimori's full-sized avatar

Takatoshi MORIYAMA morimori

View GitHub Profile

Keybase proof

I hereby claim:

  • I am morimori on github.
  • I am morimori (https://keybase.io/morimori) on keybase.
  • I have a public key ASAYIj_UuyAOKC9lqp7HpTanc3pGS_Oy1SwQBE54QRPyOAo

To claim this, I am signing this object:

@morimori
morimori / url_error_check.sh
Created May 30, 2014 07:28
ファイルに書かれた URL をチェックして、cURL の exit コードと HTTP ステータスコードを表示する
#! /bin/sh
echo "curl exit code\thttp status code\turl"
while read url ; do
http_status=$(curl -L -f -s -A 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:29.0) Gecko/20100101 Firefox/29.0' "${url}" -o /dev/null -w '%{http_code}\n')
echo "${?}\t${http_status}\t${url}"
sleep 1
done < $1
@morimori
morimori / ebs-snapshot.rb
Created April 8, 2013 06:13
実行中のインスタンスにアタッチされている EBS ボリュームのスナップショットを取って、古いスナップショットを削除する
ACCESS_KEY = 'YOUR ACCESS KEY'
SECRET_KEY = 'YOUR SECRET KEY'
MAX_SNAPSHOTS = 5
require 'rubygems'
require 'aws-sdk'
require 'json'
require 'open-uri'
config = JSON.parse open('http://169.254.169.254/latest/dynamic/instance-identity/document').read
@morimori
morimori / retry_vs_recursive.rb
Last active December 12, 2015 01:18
再帰と retry の比較
def a(i = 0)
print 0x08.chr * i.to_s.size; print i
raise if i < 100000
rescue
i += 1
retry
end
def b(i = 0)
print 0x08.chr * i.to_s.size; print i
require 'benchmark'
c = 100000
sa = 'abc'
sb = 'def'
sc = 'ghi'
Benchmark.bmbm do |x|
x.report('<<') do
c.times{ s = ''; s << sa << sb << sc }
end
@morimori
morimori / gist:3688802
Created September 10, 2012 03:59
focus タグや save_and_open_page が残っていたらコミットさせない pre-commit フック
# Block commit include focus tag for test
git stash --keep-index -q
FOCUS_TAGS=$(grep -rn ':focus => true' spec/*/**)
result=$?
git stash pop -q
if [ $result -eq 0 ]; then
echo "### PLEASE REMOVE FOCUS TAGS ###"
echo "$FOCUS_TAGS"
exit 1
fi
@morimori
morimori / a.rb
Created August 6, 2012 03:30
クラス変数とモジュール
class A
@@a = 1
end
@morimori
morimori / sqlite_optimizer.sh
Created April 9, 2012 04:25
optimize sqlite database
find -type f -print0 | xargs -0 file | grep SQLite | awk -F : '{print $1}' | xargs -n1 -d "\n" sqlite_optimizer.sh
@morimori
morimori / build-centos6-32bit-s3backed-ami.sh
Created January 17, 2012 03:59
CentOS6 (32bit, S3-Backed) の AMI をゼロから作って登録する
#! /bin/sh
# 0. 設定
RELEASE=1.kray
ARCH=i386
EC2_PRIVATE_KEY=/path/to/private_key.pem
EC2_CERT=/path/to/certificate.pem
S3_BUCKET=bucket-name
AWS_ACCOUNT_NUMBER=012345678910
AWS_ACCESS_KEY=youraccesskey
@morimori
morimori / pre-commit
Created December 14, 2011 08:28
Jasmine と RSpec を実行する git pre-commit hook
#! /bin/sh
# Run all specs
git stash --keep-index
RAILS_ENV=test bundle exec rake assets:precompile jasmine:headless assets:clean spec
result=$?
git stash pop
[ $result -ne 0 ] && exit $result