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 / ecldemo.c
Created November 4, 2010 03:49
Example of ECL in a C program.
/*
Example of a C program embedding ECL with callbacks to C functions.
Compiled via: gcc ecldemo.c -lecl
*/
#include <stdio.h>
#include <stdlib.h>
#include "ecl/ecl.h"
#define DEFUN(name,fun,args) \
cl_def_c_function(c_string_to_object(name), \
@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 / 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 / gist:1725650
Created February 2, 2012 20:44
Pythonic Java
import java.net.* ;
import java.io.* ;
import java.util.* ;
public class Server {
public static void main( String[] args) {
try {
ServerSocket sock = new ServerSocket(4712,100) ;
while(true) new Handler(sock.accept()).start() ;}
catch(IOException e) {
System.err.println(e) ;};}}
@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 / schelling.py
Created February 16, 2012 04:12
Schelling Model
#!/usr/bin/python
import Tkinter as Tk
import random
class Schelling():
"""A Schelling model.
This is a model of a city undergoing dynamic racial segregation."""
race_colors = ["#F9C", "#000", "#FF0", "#F00", "#533"]
@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