Skip to content

Instantly share code, notes, and snippets.

View KGZM's full-sized avatar

KGZM

  • We Have The Web LLC
  • Brooklyn
View GitHub Profile
@KGZM
KGZM / sicp.js
Created January 23, 2013 06:45
Examples From Structure and Interpretation of Computer Programs.. I decided to go through and make some of my previously private gists into public ones.
inc = function(x) {
return x + 1;
};
square = function(x) {
return x * x;
};
cube = function(x) {
return x * x * x;
@KGZM
KGZM / textgame.py
Created January 24, 2013 22:25
A friend of mine is learning to program with Python and started making a simple text game. He hit on the novel, if impractical solution, of using a function for each room... but was writing them all explicitly. I decided to show him about first class functions and closures with this example here. It's very rough and based on his architecture for…
commands = ["look", "smell"]
def make_room(description, exits):
def room(skip = False, command = ""):
if not skip or command == "look":
print description
print "You can go: " + ",".join(exits.keys())
if command in exits.keys():
return rooms[exits[command]]
if command and command not in commands:
print "I don't understand that."
@KGZM
KGZM / message.py
Last active December 11, 2015 20:19
Sequel to textgame.py: Intrigued by python I decided to take the text game idea a little further. Added server things and multiuser mode. Just experimenting. (I have no idea how to rename a multifile gist or reorder it, so the files are in alphabetical order not in a semantic order.)
class Message(object):
def __init__(self, string):
self.breakdown = []
self.tokens = {}
for part in string.split('{'):
self.breakdown.extend(part.split('}'))
for i, part in enumerate(self.breakdown):
if i % 2 == 1:
@KGZM
KGZM / ast.rs
Created October 2, 2013 03:08
Just experimenting a bit.
enum Operation {
Add,
Sub,
Mul,
Div,
Exp
}
impl Operation {
fn apply(self, a : int, b : int) -> int {
@KGZM
KGZM / monosynth1.sc
Created November 26, 2013 20:16
Experimenting with SuperCollider.
(
var notes, on, off;
MIDIClient.init;
MIDIIn.connect();
SynthDef.new(\MonoSaw, {
|freq = 440, amp = 0.2,
dur = 1, gate = 0,
/*
* robotNav.js
*
* The green key is located in a slightly more
* complicated room. You'll need to get the robot
* past these obstacles.
*/
function startLevel(map) {
// Hint: you can press R or 5 to "rest" and not move the
{
"Alabama":{
"name":"Alabama",
"borders":[
"Mississippi",
"Tennessee",
"Georgia",
"Florida"
]
},
@KGZM
KGZM / 0-rps.hs
Last active August 29, 2015 14:11
Simple Comparison Between Haskell and OCaml
{- rps.hs Simple Rock Paper Scissors written in Haskell
- for translation to Ocaml as a learning exercise.
-}
data Move = Rock | Paper | Scissors deriving (Show, Eq)
data Player = Player String deriving (Show, Eq)
data Outcome = Winner Player | Tie deriving (Show, Eq)
@KGZM
KGZM / markov.clj
Last active August 29, 2015 14:23
Simple markov chain implementation
(ns markov.experiment
(:require [clojure.string :as string]))
(defn wrand [m]
(let [total (reduce + (vals m))
r (rand total)]
(loop [ks (keys m) sum 0]
(if (< r (+ (get m (first ks))
sum))
(first ks)
@KGZM
KGZM / print.js
Last active December 5, 2015 03:06 — forked from anonymous/print.js
var PDFDocument = require('pdfkit');
var fs=require('fs');
var process = require('process')
var captureText = function(cb) {
var text = ""
process.stdin.on('readable', () => {
chunk = process.stdin.read();
if(chunk) text = text + chunk;
});