Skip to content

Instantly share code, notes, and snippets.

View rjwebb's full-sized avatar

Bob Webb rjwebb

View GitHub Profile
@rjwebb
rjwebb / mandelbrotGenerator.py
Created June 5, 2012 12:50
Mandelbrot Set generator and fractal viewer
#/bin/python
# Mandelbrot pattern generator by Bob Webb, 2012.
# Generates a Mandelbrot pattern as a 2D array of numerical values (number of iterations) that's then pickled.
# I need to get round to pickling metadata as well but not now. Har har.
import sys
import numpy
import pickle
import math
@rjwebb
rjwebb / unification.hs
Created November 23, 2013 13:11
An implementation of the type unification algorithm [1], using simple types. Used the explanation in this week's Comparative Programming lecture as reference.
import qualified Data.Maybe as M
import Debug.Trace
-- Type type
data Type = Val Char | Arrow Type Type deriving Eq
instance Show Type where
show (Val c) = [c]
show (Arrow t1 t2) = "(" ++ (show t1) ++ " -> " ++ (show t2) ++ ")"
-- Substitution type
betweenTimes :: Integral b => b -> Time -> Time -> Time -> Bool
betweenTimes n s e t = and [normT >= s, normT < e] where normT = fromIntegral (mod (floor t) n)
playForLoop :: Integral b => b -> Time -> Time -> Pattern a -> Pattern a
playForLoop n s e = playWhen (betweenTimes n s e)
seqPLoop :: Integral b => b -> [(Time, Time, Pattern a)] -> Pattern a
seqPLoop n = stack . (map (\(s, e, p) -> playForLoop n s e ((sam s) ~> p)))
@rjwebb
rjwebb / coolserv.py
Created October 22, 2016 23:38
WHO NEEDS TEMPLATING RIGHT??? JUST MAKE UR OWN DSL
# this code might not be correct
# but i thought the idea was kinda funny
# templating engines are still much better
# the pallets team are doing god's work
# i'm so sorry
@rjwebb
rjwebb / dependency_injection.py
Last active April 11, 2017 23:06
(not serious)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Python dependency injection experiment!!
# Provides a DependencyScope object which lets you declare
# dependencies and inject them in functions à la AngularJS
class DependencyScope:
def __init__(self):
self.dependencies = {}
@rjwebb
rjwebb / reuben.py
Created January 10, 2017 14:32
this is an in-joke
import random
import nltk
from nltk.tokenize import TreebankWordTokenizer
"""
INSTALLATION INSTRUCTIONS:
Install nltk
Use the nltk downloader to install the Penn Treebank corpus
and averaged_perception_tagger
@rjwebb
rjwebb / linked_list.rs
Created April 11, 2017 22:41
Very basic linked list in Rust
use std::fmt;
/*
Made this to experiment with making abstract data structures in Rust.
I'm not entirely convinced that it's necessary to use Box here...
*/
fn flip(p: &Point) -> Point {
Point{ x: p.y, y: p.x }
@rjwebb
rjwebb / closedbraces.c
Created May 9, 2017 21:58
A little C program (script!) that checks if the braces are closed on stdin.
#include <stdio.h>
int main(void)
{
FILE *fp;
fp = stdin;
int depth = 0;
int c;
@rjwebb
rjwebb / stack.c
Last active May 16, 2017 19:15
Stack / Linked List implementation.
#include <stdio.h>
#include <stdlib.h>
/**
Very simple stack / linked list data structure for
holding integers.
**/
typedef struct Cell {
@rjwebb
rjwebb / kellycriterion.py
Created December 12, 2017 00:53
experiment generating coin flips to test kelly criterion
import decimal
import math
import random
from matplotlib import pyplot as plt
def bet(p):
return random.random() < p