Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / main.js
Created December 12, 2014 12:50
firefox addon adding a button which shows whether the current url has been added into Delicious.com
var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var prefs = require('sdk/simple-prefs');
var Request = require("sdk/request").Request;
var button = buttons.ActionButton({
id: "delicious-check",
label: "delicious-check",
icon: "./tagOff.png",
onClick: check
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@scturtle
scturtle / 0hh1.py
Last active August 29, 2015 14:12
play 0hh1.com with pyautogui
import pyautogui
# constants
O, R, B = -1, 1, 0
width = 50
# global variables
topy, topx = None, None
mat = []
@scturtle
scturtle / flight_mon.py
Created January 3, 2015 06:57
show flight price on OS X system status bar
# coding: utf8
from Foundation import *
from AppKit import *
from PyObjCTools import AppHelper
import os
import re
start_time = NSDate.date()
@scturtle
scturtle / output.txt
Last active August 29, 2015 14:12
Trampolined-style (workaround of tail recursion) http://lifegoo.pluskid.org/?p=327
calling tramp_fac(n=5, k=1)
bouncer: ('bounce', 'tramp_fac', (4, 5))
calling tramp_fac(n=4, k=5)
bouncer: ('bounce', 'tramp_fac', (3, 20))
calling tramp_fac(n=3, k=20)
bouncer: ('bounce', 'tramp_fac', (2, 60))
calling tramp_fac(n=2, k=60)
bouncer: ('bounce', 'tramp_fac', (1, 120))
calling tramp_fac(n=1, k=120)
bouncer: ('bounce', 'tramp_fac', (0, 120))
@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' }