Skip to content

Instantly share code, notes, and snippets.

View mjg123's full-sized avatar
😅

Matthew Gilliard mjg123

😅
View GitHub Profile
@mjg123
mjg123 / core.cljs
Created August 8, 2011 19:41
core clojurescript
(ns game.core
(:require [goog.graphics :as gfx]
[goog.events :as events]
[goog.events.KeyCodes :as key-codes]
[goog.events.KeyHandler :as key-handler]
[game.ui :as ui])
; core game logic
(ui/foo)
@mjg123
mjg123 / truth-table.clj
Created September 11, 2011 21:27
Truth-table macro in clojure
(defn bool-combinations [vs]
(loop [vs vs
a '({})]
(if (empty? vs)
a
(recur
(rest vs)
(flatten
(map
#(list
(defn bool-combinations [vs]
(loop [vs vs
a '({})]
(if (empty? vs)
a
(recur
(rest vs)
(flatten
(map
@mjg123
mjg123 / worker-queue.clj
Created October 21, 2011 22:12
Worker Queues in Clojure
(defn new-q [] (java.util.concurrent.LinkedBlockingDeque.))
(defn offer!
"adds x to the back of queue q"
[q x] (.offer q x) q)
(defn take!
"takes from the front of queue q. if q is empty, block until something is offer!ed into it"
[q] (.take q))
@mjg123
mjg123 / confused.clj
Created October 24, 2011 21:24
confusion in overtone
(def my-bus (audio-bus))
;; produce a signal & put it into the bus
(defsynth sig-gen [out-bus 0 cps 440 dur 1]
(let [env (env-gen (envelope [1 0.00001] [dur] :exponential))
sig (* env (saw cps))]
(out out-bus sig)))
;; something to read the bus & make it audible
@mjg123
mjg123 / latinsq.clj
Created October 26, 2011 08:37
Latin square solver in clojure
(ns latinsq.core
(:use [clojure.set :only (difference)]))
(defn replace-at
"in string s, replaces character at index p with c"
[s p c]
(str
(.substring s 0 p)
c
@mjg123
mjg123 / dijkstra-core.clj
Created May 29, 2012 22:34 — forked from tcoupland/dijkstra-core.clj
Brisfunctional dojo code implementing dijkstra's algorithm 29-05-2012
(ns dijkstra.core)
(def initial-node {:score Integer/MAX_VALUE :route [] :dead? false})
(defn make-initial-state [edges start-node]
(-> (zipmap (keys edges) (repeat initial-node))
(assoc-in [start-node :score] 0)
(assoc-in [start-node :route] [start-node])))
(defn live-nodes [state]
@mjg123
mjg123 / WordCounter.java
Created June 14, 2012 05:31
Word count hadoop job notes
package net.mjg123;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
@mjg123
mjg123 / after.clj
Created June 26, 2012 05:08
Clojure macro for delayed executino
(defmacro after
"Sleeps for t miliseconds then executes body. Immediately
returns a future from which the result of executing body
can (eventually) be obtained by `deref`"
{:author "Matthew Gilliard"}
[t & body]
`(future
(java.lang.Thread/sleep ~t)
~@body))
@mjg123
mjg123 / gogogo.clj
Created June 27, 2012 15:04
go-go-go
(defn empty-board [s]
{:size s :stones {} :next :black :status :ok})
(def other {:black :white :white :black})
(defn play-stone [brd pos]
(-> brd
(assoc-in [:stones pos] (brd :next))
(assoc :next (other (brd :next)))))