2012年10月30日火曜日

sudo で GUIアプリケーションを起動したら GTKwarning で落ちる時

sudo じゃなくて gksu を使うといけることがある。

example
sudo ntfs-config --> fail
gksu ntfs-config --> success

2012年10月25日木曜日

Find duplicated file with python

linux用. md5sum コマンド でmd5sum のファイルリストを作成し
同じ md5sum を持つファイルをぶわーっと書きだす。 
 
 
import sys
import re
import itertools


#utility functions
def error():
    print "usage: python finddup.py rootpath extension"
def splitline(line):
   return re.match("([a-z0-9]+)[ ]+(.*)", line).groups()


#command line argument check
if len(sys.argv) == 3:
    os.system(r'find %s -name "*.%s" -exec md5sum {} \; > dup.md5'
              % (sys.argv[1], sys.argv[2]))
else:
    print "reading existing dup.md5..."
    error()

# open file
try:
    files = map(splitline, open("dup.md5"))
except:
    error()
    sys.exit(1)

# find duplicates and print them
for f1, f2 in itertools.product(files, files):
    md5sum1, path1 = f1
    md5sum2, path2 = f2
    if path1 == path2: continue
    if md5sum1 == md5sum2:
        print "duplicated:"
        print "    ", path1
        print "    ", path2


2012年10月20日土曜日

今期アニメ

K
絶園のテンペスト
リトルバスターズ
中二病でも恋がしたい
リトルバスターズ
BTOOM
好きっていいなよ
さくら荘のペットな彼女
CODE:BREAKER
ヨルムンガンド
武装神姫
PSYCHO-
ロボティクスノーツ

--つづき
ソードアートオンライン

2012年9月9日日曜日

最新 nodejs npm を apt-get でいれる

https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

websocket-server で Chrome からアクセス出来ない問題の解決策


Sec-WebSocket-Accept が無いために Chrome だとエラーがおこる。

(npm -i websocket-server したパス)/nodejs/node_modules/websocket-server/connection.js  を編集

console.log(connection);
var key = require('crypto')
            .createHash('sha1')
            .update(connection._req.headers['sec-websocket-key']
                    + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')
            .digest('base64');
res += '\r\nSec-WebSocket-Accept: ' + key;

377行目の直前に書く。

377  connection._socket.write(res + '\r\n\r\n', 'ascii');


2012年9月4日火曜日

python で関数に大量の引数をまとめて与える。

たとえば、 struct.pack で 200個の長さのlist をバイナリにしたいとする。
でも、 struct.pack は

    struct.pack(format, p1, p2, ...)

なので、単純には p1, ..., p200 の引数を書かないといけない。つまり
    values = range(100)
    packed = struct.pack("<" + "L" * 100, values[0], values[1], ..., values[199])

でもこれはあまりにしんどい。そんなときは, * を使えば展開可能
    packed = struct.pack("<" + "L" * 100, *(values))


2012年8月22日水曜日

trac+svn でコミットログを書き換える

* subversion サーバ設定
リポジトリのディレクトリ以下の
hooks/pre-revprop-change.tmpl
の .tmpl を消して実行権限をつける

* ログ編集
TortoiseSVN でチェックアウトし、
Show Log でログ表示、右クリックして

* trac のログを更新
trac のプロジェクトのディレクトリに cd して、
trac-admin . resync <リビジョン番号>

とすれば更新完了