Skip to content

Instantly share code, notes, and snippets.

View startling's full-sized avatar

Lizzie Dixon startling

View GitHub Profile
@startling
startling / gist:2322193
Created April 6, 2012 19:20
dcpu-16 debugger output!
$ sixteen-debug examples/quick_example.bin
SET A 0x0030
>> registers
A: 0030 C: 0000 B: 0000 I: 0000 J: 0000 O: 0000 PC: 0002 SP: ffff Y: 0000 X: 0000 Z: 0000
>>>>
SET [0x1000] 0x0020
>>
SUB A [0x1000]
>>
IFN A 0x0010
#!/usr/bin/env python
from wsgiref.handlers import CGIHandler
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
# This is the API everything inherits from
class GenericApplicationConfigurationClass(object):
def __init__(self):
self.looper = Looper()
# And the small, configuration-only script I intend to write for each specific case
class MyClass(object):
def __init__(self, c):
c.width = self.calculate_width()
c.height = self.calculate_height()
def calculate_width(self):
return 10
def calculate_height(self):
return 20
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