Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

  • KLab Inc,
  • Japan
  • 00:51 (UTC +09:00)
  • X @methane
View GitHub Profile
@methane
methane / KL11.java
Created November 16, 2011 07:14
ICPC 2011 FUKUOKA / Java Challenge AI
import java.util.LinkedList;
import jp.ac.kyushu_u.icpc2011.game.*;
import jp.ac.kyushu_u.icpc2011.game.GameInfo.Direction;
import jp.ac.kyushu_u.icpc2011.game.GameInfo.Handle;
import jp.ac.kyushu_u.icpc2011.game.GameInfo.Speed;
import jp.ac.kyushu_u.icpc2011.game.model.*;
import jp.ac.kyushu_u.icpc2011.gameAPI.*;
import jp.ac.kyushu_u.icpc2011.gameAPI.PlayerAction.*;
@methane
methane / codevs.py
Created December 3, 2011 17:58
Skeleton code of codevs.jp
#!/usr/bin/python
# coding: utf-8
import sys
import fileinput
def read_ints(f):
return map(int, f.readline().strip().split())
def read_line(f):
@methane
methane / myprofiler.py
Created December 5, 2011 08:54
Casual MySQL profiler using "SHOW FULL PROCESSLIST"
#!/usr/bin/env python
# coding: utf-8
"""myprofiler - Casual MySQL Profiler
https://github.com/methane/myprofiler
"""
import os
import sys
00s000
110000
100000
g0000g
敵の移動力を10とした時、左のゴールへ移動するのにかかる時間は44、
右のゴールへ移動するのにかかる時間は42なので、右のゴールに進むはず。
だが、履歴を確認すると敵は左のゴールへ移動していた。
@methane
methane / gist:1599820
Created January 12, 2012 10:46
Flask request context
import flask
app = flask.Flask(__name__)
@app.before_request
def setup():
http://developer.mixi.co.jp/appli/spec/mob/validate-oauth-signature/ を Python で検証してみる。
In [85]: key
Out[85]: '79e0a55cde43e7dc86fd1e1366d6bd6ac7771db8&'
In [86]: raw
Out[86]: 'GET&http%3A%2F%2Fexample.com%2Ffoo%2F&oauth_consumer_key%3Dbc906fac81f581c3c96a%26oauth_nonce%3D9dc8fbca0e51842e7449%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1254282755%26oauth_version%3D1.0%26opensocial_app_id%3D123%26opensocial_owner_id%3Dxxxxxxxx'
In [87]: import hmac
In [88]: from hashlib import sha1
In [89]: hmac.new(key, raw, sha1).digest().encode('base64')
Out[89]: 'cv87UdLBj/Jlt0hkqvQ6m2d9XxY=\n'
#!/usr/bin/env python
# coding: utf-8
"""mystatus - Casual MySQL status check
"""
import os
import sys
import re
from time import sleep, strftime
@methane
methane / flask_memcache.py
Created January 31, 2012 12:00
Sample using python-memcached in threaded Flask application.
"""Flask extension utility."""
from flask.sessions import SessionInterface, SessionMixin
from werkzeug.contrib.cache import MemcachedCache
import memcache # Use https://code.launchpad.net/~songofacandy/python-memcached/mixin-threading
def setup_cache(app):
"""
Setup ``app.cache``.
In [1]: class C(object):
...: def m(self):
...: pass
...:
In [2]: c=C()
In [3]: f=c.m
In [4]: f()
In [1]: def loop():
...: for i in xrange(10**5 * 30):
...: pass
...:
In [2]: %timeit loop()
10 loops, best of 3: 56.8 ms per loop