This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#INCLUDE "useful.module" | |
VAL INT N IS 100000: | |
PROC whisper (CHAN INT left?, right!) | |
INT v: | |
SEQ | |
left ? v | |
right ! (v + 1) | |
: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
OlderNewer