Skip to content

Instantly share code, notes, and snippets.

@u1tnk
u1tnk / retire_hosts.rb
Last active August 29, 2015 14:03
working以外のサーバを一括retire
# -*- coding: utf-8 -*-
# mackrel-client-ruby 0.0.2 使用
require 'mackerel'
client = Mackerel::Client.new(:mackerel_api_key => ENV['MACKEREL_APIKEY'])
client.get_hosts(service: 'service_name').each do |host|
# working以外で初期登録から一週間以上経過している
if host.status != "working" && host.createdAt < Time.now.to_i - (60 * 60 * 24 * 7)
p "retire host id:#{host.id}"
p client.retire_host(host.id)
echo 'stats' |nc localhost 11211
echo 'flush_all' |nc localhost 11211
watch -n0.5 "mysql -hhost -umang -ppass -A db -e'show processlist;'"
require_once 'Benchmark/Timer.php';
$t = new Benchmark_Timer();
$t->start ();
$t->setMarker( 't1' );
for($i=0;$i&lt;10000;$i++){
// 処理
}
$t->setMarker('m2');
$t->stop();
@u1tnk
u1tnk / replace many file on Mac
Created February 8, 2011 05:46
linuxでは -e command -i '' の代わりに -iだけで良い
find . -name "*.html" | xargs sed -e 's/hoge/fuga/g' -i ''
awk '{print $1}' access_log | sort | uniq -c | sort -n | tail -5
@u1tnk
u1tnk / apache log count
Created March 8, 2011 04:57
apacheのログを時間単位でカウント。ログフォーマットにもよるけど。
cat hoge.log | awk '{print $5}' | cut -c 14-15 | sort | uniq -c
#awkは無条件で5番目を出力
#cut は14から15文字目
#sortはuniqueが前後しかunique化しないから必要。
@u1tnk
u1tnk / baseball.rb
Created November 5, 2011 06:40
tddbc
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
module BaseBall
class Batter
include Comparable
attr_accessor :box, :at_box, :hit, :name
def initialize arg
@box = arg[:box]
@at_box = arg[:at_box]
@u1tnk
u1tnk / gist:1440879
Created December 7, 2011 00:59
mysql safe-updatesを一時的に解除
SET SQL_SAFE_UPDATES=0;
@u1tnk
u1tnk / gist:1851642
Created February 17, 2012 07:47
ruby grep replace one-liner
find . -name *.txt -print0 | xargs -0 ruby -i -p -e '$_.gsub! %r{(foo|bar)}, %q{\1baz}'