Skip to content

Instantly share code, notes, and snippets.

View dcolish's full-sized avatar

Dan dcolish

View GitHub Profile
@dcolish
dcolish / provision.sh
Created March 4, 2012 06:58
Bootstrap a development minion
#!/bin/bash
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Use this with something like
# Vagrant::Config.run do |config|
# config.vm.box = "lucid32"
# config.vm.forward_port 22, 2223
# config.vm.forward_port 80, 8080
@dcolish
dcolish / pytree.py
Created April 12, 2012 05:57
Trees in python
import random
class tt(tuple):
def __str__(self):
pass
empty = None
red, black = range(2)
color, left, root, right = range(4)
data Tree' a = E' | Tree' (Tree' a) a (Tree' a)
foo' = Tree' E' 0 E'
foo = Tree' (Tree' E' 1 E' ) 0 (Tree' E' 1 (Tree' E' 0 E'))
foo'' = Tree' E' 0 (Tree' E' 1 E')
height t = case t of
E' -> 0
Tree' s1 x s2 -> if h1 > h2 then h1 + 1 else h2 + 1
where
data Tree' a = E' | Tree' (Tree' a) a (Tree' a)
foo' = Tree' E' 0 E'
foo = Tree' (Tree' E' 1 E' ) 0 (Tree' E' 1 (Tree' E' 0 E'))
foo'' = Tree' E' 0 (Tree' E' 1 E')
height t = case t of
E' -> 0
Tree' s1 x s2 -> if h1 > h2 then h1 + 1 else h2 + 1
where
data Tree' a = E' | Tree' (Tree' a) a (Tree' a)
foo' = Tree' E' 0 E'
foo = Tree' (Tree' E' 1 E' ) 0 (Tree' E' 1 (Tree' E' 0 E'))
foo'' = Tree' E' 0 (Tree' E' 1 E')
height t = case t of
E' -> 0
Tree' s1 x s2 -> if h1 > h2 then h1 + 1 else h2 + 1
where
import random
empty = None
color, left, root, right, red, black = range(6)
rbnode = lambda c, l, t, r: {color: c, left: l, root: t, right: r}
def member(x, tree):
if tree == empty:
# Inplace quicksort in python
from functools import partial
import operator
import random
import time
def partition(list_, l, r, p):
pVal = list_[p]
list_[p], list_[r] = list_[r], list_[p]
/* Takes a list of int args to sort */
#include <stdio.h>
void swap(int array[], int n, int m) {
int tmp = 0;
tmp = array[n];
array[n] = array[m];
array[m] = tmp;
from itertools import islice
import random
def merge_sort(l):
if len(l) <= 1:
return l
left = []
right = []
middle = len(l) / 2
import random
def insert_sort(l):
for i, item in enumerate(l):
while i > 0 and l[i - 1] > item:
l[i] = l[i - 1]
i -= 1
l[i] = item