Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / bengou.go
Last active December 16, 2015 23:59
bengou comic downloader
package main
import (
"io"
"os"
"fmt"
"flag"
"time"
"errors"
"regexp"
@scturtle
scturtle / pq.py
Last active December 17, 2015 05:38
Priority queue (allow priority changes)
''' 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 = {}
@scturtle
scturtle / ttt.py
Last active December 17, 2015 06:08
tic tac toe AI
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] == '_']
@scturtle
scturtle / style.css
Created May 15, 2013 02:54
stylish for theoldreader
@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 {
@scturtle
scturtle / snake.py
Last active April 29, 2018 02:27
snake AI demo with pygame
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
@scturtle
scturtle / simplex.py
Created July 6, 2013 12:01
simplex algorithm
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, [], []
@scturtle
scturtle / addlrc.py
Last active March 4, 2023 10:10
download from music.163.com
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:
@scturtle
scturtle / fib.hs
Last active December 19, 2015 17:09
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
@scturtle
scturtle / fft.py
Created August 31, 2013 09:06
FFT
# 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]
@scturtle
scturtle / dns.py
Last active December 22, 2015 12:29
dns proxy server using 0bad.com and ip
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'):