This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"os" | |
"fmt" | |
"flag" | |
"time" | |
"errors" | |
"regexp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' Priority queue implemented by heap. | |
Some codes are copied from the official library heapq. | |
Priority changes for queue item is possible and fast. ''' | |
class PQ: | |
def __init__(self): | |
self.heap = [] | |
self.priority = {} | |
self.position = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
opmv = {'O': 'X', 'X': 'O'} | |
def print_grid(grid): | |
print '\n' + '\n'.join(' '.join(line) for line in zip(*[iter(grid)]*3)) | |
def possible(grid): | |
return [i for i in xrange(9) if grid[i] == '_'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@namespace url(http://www.w3.org/1999/xhtml); | |
@-moz-document domain("theoldreader.com") { | |
.list-post { | |
width: 60% !important; | |
} | |
.list-post > h3 { | |
margin: 15px !important; | |
} | |
.list-post h3 + .clearfix { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import random | |
from Queue import Queue, deque | |
from pygame.color import Color | |
d = 20 | |
WIDTH = 15 | |
HEIGHT = 10 | |
LEFT, RIGHT, UP, DOWN = -1, 1, -WIDTH, WIDTH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
try: | |
from numpypy import * | |
except ImportError: | |
from numpy import * | |
class Tableau: | |
def __init__(self, obj): | |
self.obj, self.rows, self.cons = obj, [], [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import eyed3 | |
import re | |
import glob | |
def get_lyric(lrc): | |
text = open(lrc).read() | |
text = re.sub(r'(?:\[.*\])+', '', text).strip() | |
text = map(lambda l: l.strip(), text.split('\n')) | |
ans = [] | |
for l in text: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib' 1 = (0, 1, 1) | |
fib' n = let (a, b, c) = fib' (n `div` 2) | |
a' = a*a + b*b | |
b' = a*b + b*c | |
c' = b*b + c*c | |
in if n `rem` 2 == 1 then (b', c', b' + c') | |
else (a', b', c') | |
fib 0 = 0 | |
fib n = let (_, v, _) = fib' n in v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
# ref: | |
# http://jakevdp.github.io/blog/2013/08/28/understanding-the-fft/ | |
# http://zh.wikipedia.org/zh-cn/库利-图基快速傅里叶变换算法#.E6.99.82.E5.9F.9F.E6.8A.BD.E5.8F.96.E6.B3.95 | |
import numpy as np | |
def FFT(x): | |
x = np.asarray(x, dtype=float) | |
n = x.shape[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SocketServer | |
from gevent import monkey | |
monkey.patch_socket(dns=False) | |
import requests | |
from dnslib import * | |
cache = {'0bad.com': ['69.163.160.212'], 'bitstress.com': ['127.0.0.1']} | |
def redirect_ip(data, ip='144.214.121.220'): |