Skip to content

Instantly share code, notes, and snippets.

View ojimac's full-sized avatar

Keita Ojima ojimac

View GitHub Profile
@ojimac
ojimac / gist:2844158
Created May 31, 2012 15:28
mysqlsnifferのインストール @ CentOS5.5
<参考URL>
http://nippondanji.blogspot.jp/2010/04/mysqlsniffermysql.html
<インストール>
$ sudo yum install libpcap-devel
$ mkdir mysqlsniffer
$ cd mysqlsniffer
$ wget http://hackmysql.com/code/mysqlsniffer.tgz
$ tar xf mysqlsniffer.tgz
$ gcc -m64 -g -O3 -lpcap -o mysqlsniffer *.c
@ojimac
ojimac / gist:2856423
Created June 2, 2012 03:38
はてブAPI 複数のASINに対する被コレクション数を出力するサンプルスクリプト(python版)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xmlrpclib
proxy = xmlrpclib.ServerProxy('http://b.hatena.ne.jp/xmlrpc')
print proxy.bookmark.getAsinCount('4774124966','4886487319')
@ojimac
ojimac / gist:2861865
Created June 3, 2012 04:19
ディスク使用量調査(ファイルサイズ毎にソート)するコマンド
# Linux
$ du -x --max-depth=1 / | sort -n
# Mac OS X
$ du -x -d 1 / | sort -n
@ojimac
ojimac / gist:2866333
Created June 4, 2012 04:21
HTTPリクエストした先がBasic認証かかっていたときの対処@TitaniumMobile
// 参考 : http://boydlee.com/appcelerator-titanium/basic-authentication-with-titanium-httpclient-and-json.html
xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
// snip
};
xhr.onerror = function() {
// snip
};
xhr.open('POST', 'http://example.com');
@ojimac
ojimac / gist:2868985
Created June 4, 2012 15:12
あるカラムの値が重複しているレコードを抽出するSQL
SELECT {COLUMN_NAME}
FROM {TABLE_NAME}
GROUP BY {COLUMN_NAME}
HAVING COUNT({COLUMN_NAME}) <> 1
@ojimac
ojimac / gist:2881010
Created June 6, 2012 09:52
EUC-JP -> UTF-8変換時の旧漢字文字化け対応...
<?php
mb_convert_encoding(mb_convert_encoding($str, 'sjis-win', 'eucjp'), 'UTF-8', 'sjis-win');
@ojimac
ojimac / gist:2881287
Created June 6, 2012 11:03
How to install App::Ack
$ sudo cpan install App::Ack
@ojimac
ojimac / gist:2892964
Created June 8, 2012 01:51
自己結合
select *
from users as t1
inner join users as t2 on t1.id = t2.id
where 1 = 1
// sql-benchのインストール方法と、インストール先、使い方 @ CentOS5.5
<install>
# yum install mysql-bench
<path>
# /usr/share/sql-bench
<usage>
$ ./run-all-tests --server=mysql --user=root --password={PASSWORD} --log --fast
@ojimac
ojimac / gist:2915987
Created June 12, 2012 07:55
MySQLで大きめのテーブルにorder by rand()を適用する場合の対策
// sqlを2回に分ける
// order by rand() は全件走査になるので、まずid(主キー)だけのリストを作り
select users.id # idだけ取得
from users
where {CONDITIONS}
order by rand()
// その後インデックスが効くようにid縛りのクエリを発行
select {COLUMN}