Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

View GitHub Profile
@methane
methane / profile_sample.py
Created April 17, 2012 12:02
プロファイラを使って関数のプロファイルをとるサンプル
from cProfile import Profile
from functools import wraps
import atexit
_prof = Profile(builtins=False)
def with_profile(func):
@wraps(func)
def wrapped(*args, **kw):
return _prof.runcall(func, *args, **kw)
return wrapped
@methane
methane / fluent.conf
Created April 30, 2012 06:51
fluentd で殴り合い
<source>
type forward
port 12345
</source>
<match **>
type forward
buffer_type memory
buffer_chunk_limit 4m
buffer_queue_limit 128
flush_interval 1s
@methane
methane / crontab.py
Created May 4, 2012 10:29
crontab の自動バックアップ
#!/usr/bin/env python
# coding: utf-8
import os
import subprocess
import sys
def escape(x):
return x.replace("'", "\\'").replace('"', '\\"')
@methane
methane / mp_test.rb
Created May 17, 2012 18:48
testing MessagePack memory usage.
require 'msgpack'
msg = MessagePack::pack("a" * 1024)
while true do MessagePack::unpack(msg) end
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
@methane
methane / mylite.py
Created June 22, 2012 12:27
Copy table from mysql to sqlite
#! /usr/bin/python
# coding: utf-8
"""Copy table from mysql to sqlite.
Require:
* SQLAlchemy
* MySQLdb or PyMySQL
Usage:
@methane
methane / serial.py
Created June 29, 2012 05:35
シリアルコード発行用スクリプト
#!/usr/bin/env python
import random
import sys
from glob import glob
import os
BASE = os.path.dirname(__file__)
CHARS = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789'
N = int(sys.argv[1])
import bz2
import re
import sys
R = re.compile('opensocial_viewer_id=(\w+)')
def count_uu(fn):
f = bz2.BZ2File(fn)
acc = set()
for L in f:
@methane
methane / gist:3031447
Created July 2, 2012 06:30
Python 3本構成案
##############
詳説 Python 3
##############
タイトル未定
Python 3.3 ベースの、 Python を使って何かをするのではなく、 Python を使いこなすための本。
みんPyとの違い => プログラミング自体の入門者向けではない
def reopen_stdio_with_encoding(encoding='utf-8'):
import io
import sys
def reopen(file):
file.__init__(file.detach(),
line_buffering=file.line_buffering,
encoding=encoding)
reopen(sys.stdout)
reopen(sys.stderr)
reopen(sys.stdin)