Skip to content

Instantly share code, notes, and snippets.

View rjwebb's full-sized avatar

Bob Webb rjwebb

View GitHub Profile
@rjwebb
rjwebb / brainfuck.py
Last active February 26, 2019 08:12
A toy Brainfuck implementation in Python
"""
A toy Brainfuck implementation in Python.
In this implementation, the length of tape is infinite in both directions (I used two stacks for the left and right
sides of the tape) and the values on the tape are 0 <= x < 256.
"""
def jump_to_closing_bracket(start_i, program):
"""
@rjwebb
rjwebb / gradient_descent.hs
Last active December 18, 2018 23:08
Gradient descent implementation in Haskell
import Control.Monad (liftM)
import Data.List (find)
-- Given a list it returns the consecutive pairs of items in the list
pairs :: [a] -> [(a, a)]
pairs values = zip values (tail values)
-- Given a list, this function returns the first item whose difference
-- between it and the previous item is less than `threshold`

Keybase proof

I hereby claim:

  • I am rjwebb on github.
  • I am rjwebb (https://keybase.io/rjwebb) on keybase.
  • I have a public key ASCv0-ae5IB77dqQ1VbY6tdmVD-Ow0Mb2SFWcKn9ZPPbggo

To claim this, I am signing this object:

@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
@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 / 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 / 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 / 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 / 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 / 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