Skip to content

Instantly share code, notes, and snippets.

@pcsanwald
pcsanwald / gist:3890237
Created October 15, 2012 00:12
Overtone drum loop of John "Jab'o" Starks' groove on James Brown's "Licking Stick"
(def snare (sample (freesound-path 26903)))
(def kick (sample (freesound-path 2086)))
(def ch (sample (freesound-path 802)))
(def oh (sample (freesound-path 26657)))
; define a metronome that will fire every eighth note
; at 100 bpm
(def met (metronome (* 100 2)))
@pcsanwald
pcsanwald / gist:3071225
Created July 8, 2012 14:37
name java files according to their public class declaration
# The regular expression checks for a public class declared in the file.
# The match, captured using the $1 variable, then is used to rename the file according
# to java conventions, i.e. ClassName.java
perl -ne '/public class ([a-zA-Z0-9]+) / && rename($ARGV,$1.".".java)' *
# I created this gist because manning ships the source code for "Hadoop in Action" in files called
# "listing-2-2", with no indication what kind of file it is.
@pcsanwald
pcsanwald / gist:3006378
Created June 27, 2012 19:51
collections example
package com.paulsanwald.prototype;
import static org.junit.Assert.*;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
import com.google.common.base.Predicate;
@pcsanwald
pcsanwald / gist:3006377
Created June 27, 2012 19:51
collections example
package com.redowl.prototype;
import static org.junit.Assert.*;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
import com.google.common.base.Predicate;
@pcsanwald
pcsanwald / midi-synth-demo.clj
Created May 28, 2012 22:52
demo your computer's builtin synthesizer sounds using middle C
(import 'javax.sound.midi.Synthesizer 'javax.sound.midi.MidiSystem)
; plays a middle C for 2 seconds, then pauses for 500ms
(defn play [channel]
(do
(.noteOn channel 67 1)
(Thread/sleep 2000)
(.allNotesOff channel)
(Thread/sleep 500)))
@pcsanwald
pcsanwald / barber.clj
Created April 5, 2012 01:04
Sleeping Barber...
; declare a total variable which will keep
; count of the number of haircuts
(def total (agent 0))
; declare a queue for customer/barber:producer/consumer behavior
(def seats (ref (clojure.lang.PersistentQueue/EMPTY)))
; it takes 20ms to give a haircut.
; when a haircut is done, we'll
; safely increment the total.
(defn cut-hair [thetotal]