Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

  • KLab Inc,
  • Japan
  • 03:38 (UTC +09:00)
  • X @methane
View GitHub Profile
import sys
lines = words = bytes = 0
for L in sys.stdin:
bytes += len(L)
words += len(L.split())
lines += 1
print 'bytes', bytes
print 'words', words
print 'lines', lines
@methane
methane / gist:743228
Created December 16, 2010 09:33
Player implemented by KLab for JavaChallenge 2010.
package jp.ac.nii.icpc2010.players;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.PriorityQueue;
import jp.ac.nii.icpc2010.players.BasePlayer;
import jp.ac.nii.icpc2010.playfield.FieldDirection;
import jp.ac.nii.icpc2010.playfield.IPlayField;
@methane
methane / ばーか
Created April 26, 2011 00:31
てすと
あーほ
X = 233
Y = 456
Z = 787
TARGET = 10000000000
def gcd(x, y): # x >= y
mod = x%y
if mod == 0: return y
return gcd(y, x%y)
#http://googledevjp.blogspot.com/2011/04/google-code-jam-2011.html
def solve(rest, boards, counts):
if boards == []:
return rest == 0
board = boards[-1]
count = rest / board
rest = rest % board
while count >= 0:
if solve(rest, boards[0:-1], counts):
inada-n@sag15:~$ cat send_magic.py
import socket
s = socket.socket()
s.connect(('127.0.0.1', 8000))
s.sendall("fff4fffd06".decode('hex'))
s.shutdown(socket.SHUT_WR)
dat = s.recv(1024)
try:
dat.decode('ascii')
print dat
@methane
methane / zlib_thread.py
Created August 20, 2011 17:32
zlib and gil
from zlib import compress, decompress
from time import time
import threading
import random
import string
#DAT = ''.join(random.choice(string.letters) for _ in xrange(8*1024))
DAT = 'hello'
#DAT = compress(DAT)
def check_route(board, route):
w = board.w
h = board.h
state = bytearray(board.state)
pos = board.state.index(b'0')
try:
for c in route:
if c == 'D':
npos = pos+w
@methane
methane / echo_server_tobikko.py
Created September 12, 2011 11:47
Echo server with tobikko
#!/usr/bin/env python
import tobikko
import tobikko.socket as socket
def handler(sock):
try:
print "start handler"
recv=sock.recv
send=sock.send
while 1:
2011-10-02 13:38:58 +0900: adding match pattern="debug.**" type="stdout"
2011-10-02 13:38:58 +0900: running fluent-0.9.14
2011-10-02 13:39:16 +0900 debug.hoge: {"foo":"bar"}