Skip to content

Instantly share code, notes, and snippets.

@vwood
vwood / cell.py
Created October 27, 2010 11:30
Simple Reactive programming.
from types import FunctionType
class cell:
def __init__(self, *args):
self.i_depend_on = []
self.depends_on_me = []
self.set(*args)
def get(self):
return self.value
@vwood
vwood / channel.c
Created November 2, 2010 15:00
Channel library.
#include <semaphore.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "channel.h"
struct channel_s {
sem_t empty_semaphore;
sem_t fill_semaphore;
@vwood
vwood / channel.c
Created November 17, 2010 03:33 — forked from vwood/channel.c
Channels with asynchronous support.
#include <semaphore.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "channel.h"
struct channel_s {
sem_t empty_semaphore;
sem_t fill_semaphore;
@vwood
vwood / disjoint_set.c
Created February 8, 2012 09:32
Disjoint Sets
#include "disjoint_set.h"
void disjoint_set_new(disjoint_set_t *set) {
set->parent = set;
set->rank = 0;
}
disjoint_set_t *disjoint_set_find(disjoint_set_t *set) {
disjoint_set_t *root = set->parent;
@vwood
vwood / willpower.py
Created February 29, 2012 10:03
Willpower Game
#!/usr/bin/env python
#
# Willpower trainer
#
# It's a really bad, ad hoc state machine
#
import random
import pygame
@vwood
vwood / random_imgur.py
Created August 1, 2012 03:58
random imgur downloader
import os
import sys
import random
import time
import string
import Queue
import threading
from urllib2 import Request, urlopen, URLError, HTTPError
import hashlib
@vwood
vwood / count_min.py
Created August 16, 2012 05:39
count min
#!/usr/bin/env python2
from math import log
from random import randint
def log2(n):
return log(n) / log(2)
#
# Simple count min
@vwood
vwood / censor.el
Created August 28, 2012 02:18
Censorship in emacs
;;
;; Censor text temporarily in emacs
;;
;; (Using this for screen shots mostly)
(defvar censor-face
'(:foreground "black" :background "black")
"Face to use for censoring")
(defun censor ()
@vwood
vwood / compact-search-engine.py
Created December 9, 2011 05:02
Short Python3 Search Engine
#!/usr/bin/env python
# Short indexer and search engine, 2011 Vaughn Wood
# Written in python 3
# Assumes the collection is a newline separated file called index on the current path
# Only uses TF (so perform queries accordingly)
from functools import *
def dict_join_add_values(d, e):
"""Given two dictionaries, add the items in the second to the first.
@vwood
vwood / eav.sql
Created October 2, 2012 00:34
EAV in postgres
-- Entity Attribute Value Model in Postgres
CREATE TABLE public.entity (
id serial NOT NULL,
type varchar(25) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.defined_attributes (
key varchar(25) NOT NULL,