Skip to content

Instantly share code, notes, and snippets.

View startling's full-sized avatar

Lizzie Dixon startling

View GitHub Profile
def test():
for x in range(10):
def func():
print x
yield func
for f in test():
f()
@startling
startling / gist:1841257
Created February 16, 2012 02:57
toy lispy parser
#!/usr/bin/env ruby
require 'parslet'
class Lispy < Parslet::Parser
rule(:integer) { match('[0-9]').repeat(1) }
rule(:literal) { integer }
rule(:identifier) { match('[^0-9\'"]') >> match('.').repeat(0)}
rule(:atom) { identifier | literal }
rule(:spaces) { match('\s').repeat(1) }
@startling
startling / gist:1858281
Created February 18, 2012 08:44
constructing linked lists iteratively!
# the list so far; `tail` because we're starting at the end.
# None represents the empty list for now
tail = None
items = range(4)
# iterate through `items` backwards
for item in items[::-1]:
tail = (item, tail)
; ModuleID = 'plusequals.c'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.6.8"
define i32 @main(i32 %argc, i8** %argv) nounwind uwtable ssp {
%1 = alloca i32, align 4
%2 = alloca i32, align 4
%3 = alloca i8**, align 8
store i32 0, i32* %1
store i32 %argc, i32* %2, align 4
@startling
startling / colors.py
Created March 11, 2012 06:08
Display 256 colors in your terminal, if it supports it.
import sys
for i, n in enumerate(xrange(232)):
# for each color, print two spaces with that background
sys.stdout.write("\x1b[48;5;%dm " % n)
# and then back to the default color
sys.stdout.write("\x1b[49m")
# every 6 numbers after the first three,
@startling
startling / scoping.io
Created March 14, 2012 02:59
playing with io's do()
# so, because of scoping inside of do(...) I have to do:
Color greyscale := method(
i := intensity
grey := Color clone
grey red := i
grey blue := i
grey green := i
return grey
)
#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 / 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