Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / fac_cps.py
Last active August 29, 2015 14:12
factorial function in CPS
def bounce(func, *args):
return ('bounce', func, args)
def land(value):
return ('land', value)
def pogo(bouncer):
''' Keep bouncing until landing. '''
@scturtle
scturtle / cps.hs
Last active August 29, 2015 14:12
CPS transformer (EOPL ch. 6)
-- import Text.Parsec
-- import Text.Parsec.String (Parser)
import Data.List (findIndex)
import Prelude hiding (exp)
import Data.IORef
import System.IO.Unsafe
{-# NOINLINE varCnt #-}
varCnt :: IORef Int
varCnt = unsafePerformIO (newIORef 0)
@scturtle
scturtle / horspool.hs
Created March 10, 2015 09:24
horspool algorithm
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Map as M (findWithDefault, fromList)
import qualified Data.ByteString as BS
horspool :: BS.ByteString -> BS.ByteString -> Maybe Int
horspool s p = f (lenp - 1) (lenp - 1) (lenp - 1)
where lenp = BS.length p
lens = BS.length s
jmptbl = M.fromList $ zip (BS.unpack p) [lenp - 1, lenp - 2 .. 1]
jmp c = M.findWithDefault lenp c jmptbl
@scturtle
scturtle / search.py
Created April 6, 2015 13:35
search for item in 《The Binding of Isaac 》
import os
from PIL import Image
import glob
# icons downloaded from http://bindingofisaacrebirth.gamepedia.com/
IMGS_PATH = "./img/*"
# clipboard to image file
if os.system('pngpaste isaac_clip.png'):
exit()
@scturtle
scturtle / twlogin.py
Created April 30, 2015 12:54
get key and secret via tweetdeck
import sys
import requests
from pprint import pprint
from base64 import encodestring
from rauth import OAuth1Session
assert len(sys.argv) == 3, "Useage: python twlogin.py USERNAME PASSWORD"
headers = { 'authorization': 'x-td-basic ' + encodestring(sys.argv[1] + ':' + sys.argv[2]),
'X-TD-Authtype': 'twitter' }
@scturtle
scturtle / zipcomic.py
Created April 22, 2011 10:16
zip downloaded comics
# coding: utf-8
import os,sys,zipfile
def walkdir(d):
l=os.listdir(d)
nodir=True
for t in l:
p=os.path.join(d,t)
if os.path.isdir(p):
nodir=False
@scturtle
scturtle / doubanfav.py
Created April 22, 2011 10:02
show all doubanFM favorite songs
# coding: utf-8
import cookielib,urllib2
from cStringIO import StringIO
from pysqlite2 import dbapi2 as sqlite
from BeautifulSoup import BeautifulSoup
# a useful function from others
def sqlite2cookie(filename,host):
con = sqlite.connect(filename)
@scturtle
scturtle / firstpinyin.py
Created April 22, 2011 10:13
return first pinyin letter of chinese word
# coding: utf-8
a=[ i.decode('utf8').encode('gbk') for i in
['澳', '怖', '错', '堕', '贰', '咐', '过',
'祸', '祸', '骏', '阔', '络', '穆', '诺',
'沤', '瀑', '群', '弱', '所', '唾',
'唾', '唾', '误', '褕', '孕', '座',] ]
def firstpy(s,code='utf8'):
s=s.decode(code).encode('gbk')
@scturtle
scturtle / ptcheater.py
Created April 22, 2011 10:14
a proxy cheating the upload of BT/PT
# -*- coding: utf-8 -*-
import re, time, sys
import socket
import threading
from time import time
from random import random
PORT = 8080
mbps=10
@scturtle
scturtle / gist:959240
Last active September 25, 2015 17:38
vimperatorrc
" vim: set ft=vim:
" Vimperator 3.5
source! /Users/scturtle/.vimperatorrc.local
source ~/.vimperator/plugin/pinyin-hints.js
let mapleader=","
" quick jump
noremap <leader>1 :b 1<cr>