Skip to content

Instantly share code, notes, and snippets.

@teepark
teepark / DoubleList.hs
Created August 22, 2011 22:26
A non-cyclic doubly-linked list in haskell
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
@teepark
teepark / wtf.rb
Created December 9, 2011 18:54
what the hell guys?
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'
[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
@teepark
teepark / gist:1667874
Created January 24, 2012 04:48
ON DELETE CASCADE
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
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
@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):
@teepark
teepark / level08-exploit.py
Created August 31, 2012 21:40
level 8 of the stripe CTF
#!/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
@teepark
teepark / gist:3616634
Created September 4, 2012 04:33
a greenhouse-based workalike to multiprocessing.pool.Pool.apply_async
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)
@teepark
teepark / gist:3616725
Created September 4, 2012 04:53
multiprocessing's threadpool on greenhouse emulation
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)
import greenhouse
_count = 0
_local = greenhouse.Local()
def current_name():
global _count
if not hasattr(_local, "glet_id"):
_count += 1
_local.glet_id = _count