Skip to content

Instantly share code, notes, and snippets.

@reusee
reusee / py2php.py
Created June 20, 2011 16:49
Python to php translator, compile python script to php
import ast
from cStringIO import StringIO
import sys
INFSTR = '1e308'
def interleave(inter, f, seq):
seq = iter(seq)
try:
f(next(seq))
require 'weakref'
$debug = false
SPACE = [' ', "\t"]
NEWLINE = ["\r", "\n"]
QUOTE = {
'"' => '"',
"'" => "'",
'{' => '}',
'(' => ')',
@reusee
reusee / gist:1323259
Created October 28, 2011 19:35
graph-like structure in redis
class Isred(Redis):
def node(self, serial = None):
return Node(self, serial)
class Node(dict):
def __init__(self, r, serial = None):
self.redis = r
self.serial = str(serial) if serial else r.incr('serial')
def __getitem__(self, key):
@reusee
reusee / gist:1325724
Created October 30, 2011 09:05
reus vimrc reusee@gmail.com
colo evening
syntax on
filetype plugin on
set autochdir
set autoindent
set cursorline
set dir=~/.vimdir
set expandtab
set fileencoding=utf-8
@reusee
reusee / gist:1348701
Created November 8, 2011 18:47
lua object emulator
local yield = coroutine.yield
local create = coroutine.create
local status = coroutine.status
local resume = coroutine.resume
local setmetatable = setmetatable
local next = next
local pop = table.remove
local insert = table.insert
local type = type
local pairs = pairs
@reusee
reusee / gist:1384816
Created November 22, 2011 03:33
collins cobuild 6th xml file formatter
# coding: utf8
import re
class Formatter(dict):
def __init__(self, input_file):
dict.__init__(self)
xml_source = open(input_file, 'r')
for line in xml_source.xreadlines():
line = line.strip()
@reusee
reusee / kindle.cls.tex
Created November 23, 2011 04:23
documentclass for kindle 3
\ProvidesClass{kindle}
\LoadClass{book}
\usepackage[margin=0mm,top=1mm,bottom=1mm,papersize={90mm,120mm}]{geometry}
\usepackage{xltxtra}
\usepackage{fontspec}
\setmainfont{LiHei Pro}
\pagestyle{empty}
\sloppy
\XeTeXlinebreaklocale "zh"
@reusee
reusee / gist:1397703
Created November 27, 2011 15:34
timer wheel
#include <iostream>
#include <list>
using std::list;
using std::string;
using std::cout;
using std::endl;
#define ROOT_BITS 8
#define REST_BITS 8
#define REST_NUM 3
@reusee
reusee / gist:1554159
Created January 3, 2012 08:58
a coroutine-based parallel library for Python
# coding: utf8
from types import *
import thread
import time
import multiprocessing
import ctypes
import traceback
class ProcessRegistry:
@reusee
reusee / gist:2290202
Created April 3, 2012 07:39
my xmonad configuration file
import XMonad
import Data.Monoid
import qualified Data.Map as M
import qualified XMonad.StackSet as W
import System.Exit
import XMonad.Actions.CycleWS
import XMonad.Actions.GridSelect
import XMonad.Util.Cursor
import XMonad.Util.SpawnOnce
import XMonad.Util.EZConfig