Skip to content

Instantly share code, notes, and snippets.

View startling's full-sized avatar

Lizzie Dixon startling

View GitHub Profile
class Looper(object):
def __init__(self, function):
function(self)
@Looper
def my_looper(self):
self.height = 130
self.width = 120
@startling
startling / program.py
Created April 25, 2012 22:31 — forked from els-pnw/error
program.py
products = {
"sam": "Subscription Asset Manager - Subscription Management",
"headpin": "Headpin - Open Source Subscription Management",
"katello", "Katello - Open Source Systems Management"
}
class Page(object):
"Base class for all Pages"
def __init__(self, testsetup):
"Initializer."

Embedded in a string, a la Pymeta

parser = Parser("""
integer ::= \d+
atom ::= integer | s_expression
atoms ::= (atom,?\s*)*
s_expression ::= "(" atoms ")"
""")
@startling
startling / gist:2598169
Created May 4, 2012 22:43
metaclasses explained
class FalseClass(type):
def __int__(self):
return 13
class C(object):
__metaclass__ = FalseClass
print int(C)
@startling
startling / gist:2651192
Created May 10, 2012 05:20
automatic currying in python
from functools import wraps
def curried(fn, args=None):
args = args or ()
@wraps(fn)
def curried_wrapper(*new_args):
if len(args + new_args) < fn.func_code.co_argcount:
return curried(fn, args + new_args)
else:
@startling
startling / das.rb
Created May 12, 2012 06:10
Homebrew formula for das
require 'formula'
# Homebrew formula for das.
# das: http://github.com/jonpovey/das
# install with:
# `brew install https://gist.github.com/raw/2664491/das.rb`
# or save this file somewhere and "brew install das.rb"
class Das < Formula
#include <sdl.h>
void event_loop(void (*on_keydown)(char), void (*on_loop)()) {
/* Given a function pointer to call on each new keypress, catch keypresses
* and pass them to it.
*
* TODO: a callback on quit. */
SDL_Event event;
int cont = 1;
@startling
startling / gist:2786341
Created May 25, 2012 07:15
object literals in python ?
inside object() as o:
a = 12
b = 13
o.a # -> 12
o.b # -> 13
@startling
startling / data.py
Created July 28, 2012 04:24
dictionary
topics = { "Spell" : ["Love", "Revenge", "Etc"],
"Prayer" : ["Zeus", "Legba", "Circe"] }
choice = raw_input().rstrip()
print topics[choice]
import Data.Monoid
-- Repeat an element every n times.
every :: Monoid a => Int -> a -> [a]
every n x = cycle $ replicate (n - 1) mempty ++ [x]
-- Pick either a number or a string. Always pick the number
-- over the empty string.
choose :: Show a => a -> String -> String
choose n s = if null s then show n else s