elixirインストール
# cd /usr/local/src/
# wget http://erlang.org/download/otp_src_20.0.tar.gz
# tar xfzv otp_src_20.0.tar.gz
# cd otp_src_20.0
# ./configure
# make
# make install# cd /usr/local/lib
# git clone https://github.com/elixir-lang/elixir.git
# cd elixir
# make clean test
VIM バイナリ編集
$ vim -b :%!xxd 元に戻す :%!xxd -r
GOで二分探索木
GOで二分探索木を書いてみた。
GOのリストとパフォーマンス比較。
RANDOMSが対象のデータ構造(二分探索木、リスト)
SEARCHSが検索する値のリスト
ランダムにRANDOMSに値を入れて
SEARCHSの値でRANDOMSを検索する。
1回目 RAMDOMS len is 50 SEARCHS len is 100 BINARI SEARCH start: insert. end : insert time: 6.375µs. start: search. end : search result num: 50, time: 25.241µs. GOLIST start: insert. end : insert time: 184ns. start: search. end : search result num: 50, time: 8.266µs. 2回目 RAMDOMS len is 122 SEARCHS len is 244 BINARI SEARCH start: insert. end : insert time: 18.031µs. start: search. end : search result num: 122, time: 37.397µs. GOLIST start: insert. end : insert time: 522ns. start: search. end : search result num: 122, time: 63.044µs 3回目 RAMDOMS len is 500 SEARCHS len is 1000 BINARI SEARCH start: insert. end : insert time: 124.748µs. start: search. end : search result num: 500, time: 140.488µs. GOLIST start: insert. end : insert time: 7.284µs. start: search. end : search result num: 500, time: 578.013µs.
値の個数が少ない場合はリストの方がパフォーマンスがよいが
値の個数が120個あたりで処理速度が逆転する。
pythonでtsvからsqlを作る
タブ区切りのデーターファイルからsqlを生成する。
id¥tname¥tmsg
から
insert into table ( id,name,msg ) values (%s,%s,%s),(%s,%s,%s),(%s,%s,%s)
psycopg2のプレースホルダーの形式でバルクinsert文へ
引数にファイル名を渡す
python hoge.py data.tsv
import sys cols = ['id', 'name', 'msg'] def main(): try: for d in parse_line(): print make_str(d) except IOError as e: print 'IOError!!!' print e except Exception as e: print 'Exeption' print "Unexpected error:", sys.exc_info()[0] print e def make_str(data): f = [] for x in cols: f.append('%s') fs = "(" + ",".join(f) + ")" fss = [] cond = [] for td in data: fss.append(fs) for d in td: cond.append(d) sql = "insert into table ( {0} ) values {1} ".format(",".join(cols), ",".join(fss)) print cond return sql def parse_line(): nums = 0 nmax = 3 ds = [] for line in open(sys.argv[-1]): d = line[:-1] if nums == nmax: yield ds ds = [] nums = 0 ds.append(d.split("\t")) nums += 1 yield ds if __name__ == '__main__': main()
FuelPHP
FuelPHPの設定
$ curl get.fuelphp.com/oil | sh sudo: $ cd /var/web/ $ mkdir lib $ cd lib $ oid create api nginxのroot $ cd /var/web/html/ $ ln -s /var/web/lib/api/public api # service php-fpm restart # service nginx restart ブラウザから http://{domain}/api/ rewriteの設定 # nginx.conf location /api/ { try_files $uri $uri/ /api/index.php$is_args$args;