Skip to content

Instantly share code, notes, and snippets.

View skydark's full-sized avatar

Skydark Chen skydark

View GitHub Profile
from threading import Thread
import hashlib
def async(gen):
def func(*args, **kwargs):
it = gen(*args, **kwargs)
result = it.next()
Thread(target=lambda: list(it)).start()
return result
return func
@skydark
skydark / patternmatch.py
Created December 5, 2012 05:42
A simple pattern matcher #python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import unittest
GREATER, LESSER, EQUAL, NOT_COMPARABLE = 1, -1, 0, None
def compare(e1, e2):
order = e1.compare(e2)
@skydark
skydark / raskell.rb
Created May 24, 2013 13:11 — forked from andkerosine/raskell.rb
list comprehension in ruby, see also: https://gist.github.com/freakhill/5564328 #ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@