Skip to content

Instantly share code, notes, and snippets.

View startling's full-sized avatar

Lizzie Dixon startling

View GitHub Profile
#include <glib.h>
typedef struct {
GSList *stack;
} MachineState;
static void machine_push (MachineState *state, int v);
static int machine_pop (MachineState *state);
/* pushes an operand onto the operand stack */
@startling
startling / stacks.py
Created March 16, 2012 06:45
stack machines
import operator
def stack_operations(stack, operands):
assert len(stack) == len(operands) + 1
def binary_operation(fn):
a = stack.pop()
b = stack.pop()
@startling
startling / goat.md
Created March 20, 2012 23:01
monty hall truth table

If you always switch prizes, you have a 2/3 chance to get the car:

|---------------------------|
| picked | revealed | prize |
|---------------------------|
| goat a | goat b   | car   |
| goat b | goat a   | car   |
| car    | goat     | goat  |
|---------------------------|
@startling
startling / gist:2165518
Created March 22, 2012 23:42
udhcpc config script
#!/bin/sh
# udhcpc config script
# $interface is the name of the device udhcpc is using
# $router is the (space_separated) list of gateways
# $broadcast is the broadcast address
# $ip is the ip address that we get from the dhcp server
# $dns is the list of dns servers we get from the dhcp server
# $domain is the domain of the network
@startling
startling / venv.fish
Created April 1, 2012 06:40
venv.fish -- manage virtualenvs with fish
# venv.fish -- virtualenv management with fish
# https://gist.github.com/2272033
# So the `activate.fish` script that comes in a virtualenv is unsatisfactory
# for a number of reasons: it's broken under os x and it's rigid with regards
# to prompts. virtualenvwrapper, as far as I can tell, doesn't support fish at
# all.
# this is a little nicer, i think; it saves the name of the current venv in an
# environment variable, so you can choose what you want to do with it, and it's
@startling
startling / naive_sets.py
Created April 3, 2012 05:14
russell's paradox in python
class Set(object):
"""Sets can contain anything, including themselves. This leads to
paradoxical behavior: given R, the set of all sets that don't contain
themselves, does R contain R? Here this becomes an infinite recursion.
"""
def __init__(self, predicate):
self.predicate = predicate
def __contains__(self, obj):
return self.predicate(obj)
@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!'
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
# 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