Skip to content

Instantly share code, notes, and snippets.

View jadudm's full-sized avatar

Matthew Jadud jadudm

View GitHub Profile
@jadudm
jadudm / explore.rkt
Created July 5, 2012 02:27
Exploration of the PLT web server...
#lang racket
(require web-server/dispatch
web-server/http
web-server/dispatchers/dispatch
)
(define-values (dispatch blog-url)
(dispatch-rules
[("") serve-static]
[("go" (string-arg)) go]
@jadudm
jadudm / whispers.occ
Created August 10, 2012 17:23
"Chinese Whispers" in occam-pi
-- As described in this blog post:
-- http://cxwangyi.wordpress.com/2012/07/29/chinese-whispers-in-racket-and-go/
--
-- This version was run and tested on the Transterpreter Virtual Machine, a
-- bytecode interpreter for occam-pi programs. Compiled natively, it will
-- be faster; with modification, it could be run on an Arduino (and be slower).
--
-- For more info, see:
-- http://concurrency.cc/
@jadudm
jadudm / whispers-no-timing.occ
Created August 10, 2012 17:27
"Chinese Whispers" in occam-pi (no timing)
#INCLUDE "useful.module"
VAL INT N IS 100000:
PROC whisper (CHAN INT left?, right!)
INT v:
SEQ
left ? v
right ! (v + 1)
:
@jadudm
jadudm / create-pages.py
Created December 4, 2012 02:24
Generate Jekyll Pages for Class Days in a Semester
import datetime, calendar
def generate_dates(start_date, end_date):
alldates = []
td = datetime.timedelta(hours=24)
current_date = start_date
while current_date <= end_date:
alldates.append(current_date)
current_date += td
return alldates
@jadudm
jadudm / mangle.py
Last active December 12, 2015 04:39
For a demo in class.
import sys
import re
# Note: In a language without types, it is good practice to
# annotate your functions with a type contract. For example,
# "find_matches" takes two strings and has no return value.
# Writing a purpose statement indicates you know what you are trying
# to do, and makes it easier for other people to read your code.
# CONTRACT
@jadudm
jadudm / regexp-example-1.py
Last active December 12, 2015 05:38
A quick example regarding regexps.
import re
filecontents = ["Matt Purple 4", "Jan Green", "Gary Orange 7"]
regex = re.compile("\d+")
for line in filecontents:
r = regex.search(line)
if r:
print "Groups: " + str(r.groups())
import re
filecontents = ["Matt Purple 4", "Jan Green", "Gary Orange 7"]
regex = re.compile("(\w+)\s+\w+\s+\d+")
for line in filecontents:
r = regex.search(line)
if r:
print "Groups: " + str(r.groups())
@jadudm
jadudm / picovm.c
Created February 22, 2013 11:41
A demo from class; a "pico" fetch/execute virtual machine written in just over 5 minutes.
#include <stdio.h>
int code[] = {0x73, 0x75, 0x1A, 0x00};
int stack[] = {0, 0, 0};
#define A 0
#define B 1
#define C 2
void printStack () {
@jadudm
jadudm / comporg-assembler.py
Last active December 14, 2015 06:18
comporg-assembler
# A Hack assembler in 5 Minutes
import re
# Set up hash tables (dictionaries, in Python) to capture all of
# the instruction transformations. This is a "lookup table," of sorts.
# When we encounter an "A", it will always be transformed to
# "110000", which we will get by looking up the key "A" in the dictionary
# called "comp".
#
# I like my hash tables to line up all pretty-like when I can pull it off.
@jadudm
jadudm / variables.ino
Created March 3, 2013 17:16
Introducing variables on the Arduino.
// Turn two LEDs on then off.
// Declare variables for later use.
int greenLED;
int redLED;
void setup () {
// Assign values to our variables.
greenLED = 2;
redLED = 4;