Skip to content

Instantly share code, notes, and snippets.

module Main where
import UI.NCurses
import Control.Monad.State
main :: IO ()
main = runCurses $ void (runStateT top [])
top = do
lift $ setEcho False
@skatenerd
skatenerd / statecurses.hs
Last active October 30, 2015 19:27
run ncurses in state monad?
module Main where
import UI.NCurses
import Data.Maybe
import Control.Monad
import Control.Monad.State
main :: IO ()
main = runCurses $ void (runStateT top [])
@skatenerd
skatenerd / interpolate.py
Created July 17, 2015 07:54
pyparsing is pretty cool
import pyparsing
class Word(object):
def __init__(self, body):
self.body = body
def __repr__(self):
return self.body[0]
class Tag(object):
@skatenerd
skatenerd / yield.py
Created July 17, 2015 03:40
continuations?
def thing(n):
if n < 10:
thing(n+1)
yield(n)
for x in thing(0):
print x
>>> z=01
>>> z=02
>>> z=03
>>> z=1
>>> z=0000000000001
>>> z=0000000000002
>>> z=0000000000006
>>> z=8
>>> z=08
File "<stdin>", line 1
example_transformations = [
["colin, why dont you get it", "mark, why dont you get it"],
["I eat lots of bananas", "I eat lots of apples"],
["colin eats lots of bananas", "mark eats lots of apples"],
["milk tea is the best", "coffee is the best"],
["milk and tea are both great", "milk and tea are both great"]
["foo(1, 2)", "foo(1, 2, user=colin)"],
["foo(9)", "foo(9)"],
]
@skatenerd
skatenerd / optimize.py
Last active August 29, 2015 14:20
optimize
# Old implementation. Can you spot the optimization?
predicates = [lambda x: x.is_rad(), lambda x: x.is_cool(), lambda x: x.is_baller()]
all_products = Product.objects.all()
products = reduce(
lambda filtered_so_far, predicate: filter(predicate, filtered_so_far),
predicates,
all_products
)
# New implementation
@skatenerd
skatenerd / jsoint.py
Created April 22, 2015 21:56
i guess this could help you inscrutably cram arbitrary data into a GET request...
import binascii
import json
def to_int(data):
return int(binascii.hexlify(json.dumps(data)), 16)
def from_int(i):
return json.loads(binascii.unhexlify('%x' % i))
print to_int({1: 2, 'hello': 'world'})
@skatenerd
skatenerd / gotcha.py
Created April 16, 2015 11:42
django orm gotcha
In [10]: SomeModel.objects.create(name='foo')
Out[10]: <SomeModel: SomeModel object>
In [11]: SomeModel.objects.create(name='bar')
Out[11]: <SomeModel: SomeModel object>
In [12]: SomeModel.objects.create(name='foo')
Out[12]: <SomeModel: SomeModel object>
In [13]: SomeModel.objects.distinct()
var rave = setInterval(
function () {
index = Math.floor(Math.random() * 1000) % colors.length;
$(rave_selector).css('border-color', colors[index]);
$(rave_selector).css('background-color', colors[index]);
}, 100);