Skip to content

Instantly share code, notes, and snippets.

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<10000;$i++){
// 処理
}
$t->setMarker('m2');
$t->stop();
awk '{print $1}' access_log | sort | uniq -c | sort -n | tail -5
@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 ''
@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 / image magick fill resize
Created April 18, 2011 13:13
ImageMagickで指定サイズで空白を埋める。
convert input.jpg -resize 1024x1024\> -size 1024x1024 xc:white +swap -gravity center -composite output.jpg
@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}'