Skip to content

Instantly share code, notes, and snippets.

View mjg123's full-sized avatar
😅

Matthew Gilliard mjg123

😅
View GitHub Profile
@mjg123
mjg123 / overtone-midi.clj
Created June 30, 2012 05:23
overtone-midi
(ns overmidi.core
(:use [overtone.live]))
(definst foo [note 60 vel 0.8]
(let [freq (midicps note)]
(* vel
(env-gen (perc 0.01 0.2) 1 1 0 1 :action FREE)
(+ (sin-osc (/ freq 2))
(rlpf (saw freq) (* 1.1 freq) 0.4))))) ; => from overtone's wiki
@mjg123
mjg123 / solved-cube.clj
Created October 25, 2012 11:28
The representation of the solved 2x2x2 Rubik's Cube
;; f1
;; f2 f3 f4
;; f5
;; f6
(def solved-cube
{:f1 [:w :w
:w :w]
:f2 [:o :o
:o :o]
@mjg123
mjg123 / get-assoc.clj
Created October 25, 2012 11:44
getting and "setting" in the cube
(get-in solved-cube [:f3 0])
;; => :g
(assoc-in solved-cube [:f3 0] :w)
;; => a value identical to solved-cube except one sticker
;; changed from green to white (it's not a valid cube
;; layout any more). solved-cube is unaltered.
;; using the -> macro to 'thread' these together
(-> solved-cube
@mjg123
mjg123 / move.clj
Created October 25, 2012 12:19
A move function
(defn face-cycle [c [q1 q2 q3 q4]]
(-> c
(assoc-in q2 (get-in c q1))
(assoc-in q3 (get-in c q2))
(assoc-in q4 (get-in c q3))
(assoc-in q1 (get-in c q4))))
(defn r [c]
(-> c
(face-cycle [[:f1 1] [:f6 1] [:f5 1] [:f3 1]])
@mjg123
mjg123 / comp.clj
Created October 25, 2012 12:23
composed moves
(def r' (comp r r r))
(def r2 (comp r r))
@mjg123
mjg123 / moves.clj
Created October 25, 2012 12:37
Scrambles and applying moves
(def moves {:r r :r' r' :r2 r2
:l l :l' l' :l2 l2
:u u :u' u' :u2 u2
:d d :d' d' :d2 d2
:f f :f' f' :f2 f2
:b b :b' b' :b2 b2})
(def move-names (keys moves))
(defn create-scramble [n]
@mjg123
mjg123 / core.clj
Created October 25, 2012 12:42
create a scrambled cube
(let [moves (create-scramble 14)
scrambled-cube (reduce apply-named-move solved-cube moves)]
;; do something with the scrambled cube
)
@mjg123
mjg123 / gol.clj
Created November 10, 2012 00:27
BY GOLLY!
(def size 6)
(def rules {:be-born? #(contains? #{3} %) ;; high-life has this as #{3 6}
:stay-alive? #(contains? #{2 3} %)})
(def glider #{[2 0] [0 1] [2 1] [1 2] [2 2]})
(defn live? [xy gen]
(contains? gen xy))
@mjg123
mjg123 / notes
Last active December 11, 2015 21:39
Lazy approach to approximating square roots in clojure using Newton-Raphson. For BrisFunctional.
line 21 sidesteps the fact that Math/abs doesn't work for clojure's Rational (ie fractional) datatype.
@mjg123
mjg123 / timestamper.sh
Created May 9, 2014 13:45
tiny shell script for adding timestamps to lines piped in from stdin
while read f; do
date +"%H:%M:%S " | tr -d '\n';
echo $f;
done