This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data DoubleList a = DoubleList { prev :: DoubleList a | |
, item :: a | |
, next :: DoubleList a | |
} | EmptyDoubleList | |
doublyLink :: [a] -> DoubleList a | |
doublyLink [] = EmptyDoubleList | |
doublyLink xs = link EmptyDoubleList xs | |
where link :: DoubleList a -> [a] -> DoubleList a | |
link prev [] = EmptyDoubleList |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby-1.9.3-p0 :001 > a = lambda { |&b| b.call } | |
=> #<Proc:0x000000028c9180@(irb):1 (lambda)> | |
ruby-1.9.3-p0 :002 > b = lambda { yield } | |
=> #<Proc:0x000000028d4eb8@(irb):2 (lambda)> | |
ruby-1.9.3-p0 :003 > a.call { puts 'hi' } | |
hi | |
=> nil | |
ruby-1.9.3-p0 :004 > b.call { puts 'hi' } | |
LocalJumpError: no block given (yield) | |
from (irb):2:in `block in irb_binding' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[teepark@spaceghost ~]$ uname -a | |
Linux spaceghost 3.1.5-1-ARCH #1 SMP PREEMPT Sat Dec 10 14:43:09 CET 2011 x86_64 Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz GenuineIntel GNU/Linux | |
[teepark@spaceghost ~]$ scanimage --version | |
scanimage (sane-backends) 1.0.22; backend version 1.0.22 | |
[teepark@spaceghost ~]$ lsusb | |
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub | |
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub | |
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub | |
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub | |
Bus 001 Device 003: ID 04f2:b217 Chicony Electronics Co., Ltd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SQLite version 3.7.10 2012-01-16 13:28:40 | |
Enter ".help" for instructions | |
Enter SQL statements terminated with a ";" | |
sqlite> create table a(id integer primary key); | |
sqlite> create table b(aid integer references a(id) on delete cascade); | |
sqlite> insert into a default values; | |
sqlite> insert into a default values; | |
sqlite> insert into a default values; | |
sqlite> select * from a; | |
1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def with_retry(attempts=3, sleep_time=1.0, &bl) | |
so_far = 2 | |
df = EM::DefaultDeferrable.new | |
result = nil | |
begin | |
result = bl.call | |
rescue | |
timer = EM::PeriodicTimer.new(sleep_time) do | |
begin | |
result = bl.call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.get(r'^/$') | |
def index(http): | |
return 'homepage' | |
@app.get(r'^/phail$') | |
def phailure(http): | |
raise Exception("I have no idea what I'm doing") | |
@app.handle_500 | |
def on_failure(http): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: fileencoding=utf8:et:sta:ai:sw=4:ts=4:sts=4 | |
import json | |
import Queue | |
import os | |
import socket | |
import sys | |
import threading | |
import urllib2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from greenhouse import pool | |
def async_pool(size): | |
def handler(func, args=(), kwargs=None, callback=None): | |
result = func(*args, **(kwargs or {})) | |
if callback is not None: | |
callback(result) | |
return pool.OneWayPool(handler, size) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from greenhouse import emulation | |
mp_pool = emulation.patched("multiprocessing.pool") | |
def cb(x): | |
print 'callback:', x | |
tp = mp_pool.ThreadPool() | |
tp.apply_async(lambda a, b: a * b, (4, 5), {}, cb) | |
greenhouse.pause_for(0.1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import greenhouse | |
_count = 0 | |
_local = greenhouse.Local() | |
def current_name(): | |
global _count | |
if not hasattr(_local, "glet_id"): | |
_count += 1 | |
_local.glet_id = _count |