This file contains hidden or 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
class PagingModelEnumerator # sketchy version :D | |
include Enumerable | |
def initialize(model, opts) | |
@model = model | |
@find_opts, @count_opts = parse_opts(opts) | |
end | |
def each(&block) | |
page_size = 50 |
This file contains hidden or 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
; mmj: http://www.humatic.de/htools/mmj.htm | |
; rlwrap java -cp /usr/local/lib/clojure/clojure.jar:/usr/local/lib/mmj/mmj.jar -Djava.library.path=/usr/local/lib/mmj:/usr/lib/java clojure.lang.Repl | |
(ns org.jvoorhis.midi | |
(:import (de.humatic.mmj MidiSystem))) | |
(def out (MidiSystem/openMidiOutput 0)) | |
(defn make-note-on [c p v] | |
(let [msg (make-array (Byte/TYPE) 3)] |
This file contains hidden or 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
require 'music_player' | |
include AudioToolbox | |
p = MusicPlayer.new | |
s = MusicSequence.new | |
t = MusicTrack.new(s) | |
s.midi_endpoint = CoreMIDI.get_destination(ARGV.shift.to_i) | |
t.add_midi_note_message 0.0, MIDINoteMessage.new(:pitch => 60, :velocity => 64) | |
t.add_midi_note_message 1.0, MIDINoteMessage.new(:pitch => 64, :velocity => 96) |
This file contains hidden or 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
~ % sudo gem1.9 install ffi | |
Password: | |
Building native extensions. This could take a while... | |
ERROR: Error installing ffi: | |
ERROR: Failed to build gem native extension. | |
/usr/local/bin/ruby1.9 extconf.rb install ffi | |
checking for ffi_closure_alloc() in -lffi... no | |
creating Makefile | |
creating extconf.h |
This file contains hidden or 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
require 'audio_toolbox' | |
class DrumMachine | |
include AudioToolbox | |
def initialize | |
@player = MusicPlayer.new | |
@sequence = MusicSequence.new | |
@track = MusicTrack.new(@sequence) | |
@track.add 0.0, MIDIProgramChangeMessage.new(:channel => 10, :program => 26) |
This file contains hidden or 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
require 'audio_toolbox' | |
include AudioToolbox | |
player = MusicPlayer.new | |
sequence = MusicSequence.new | |
player.sequence = sequence | |
sequence.midi_endpoint = CoreMIDI.get_destination(ARGV.shift.to_i) | |
tempo = sequence.tracks.tempo | |
tempo.add 0.0, ExtendedTempoEvent.new(:bpm => 120.0) |
This file contains hidden or 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
class Val < Struct.new(:val) | |
def fold(rules) | |
rules[self.class].(val) | |
end | |
end | |
class Var < Struct.new(:lbl) | |
def fold(rules) | |
rules[self.class].(lbl) | |
end |
This file contains hidden or 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
class Additive | |
attr :value | |
def initialize(value) | |
@value = value | |
end | |
def mappend(m) Additive.new(@value + m.value) end | |
end | |
class Multiplicative | |
attr :value |
This file contains hidden or 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
def times_for_period(date) | |
days = work_days_for_period(date) | |
regular_hours_by_week = Hash.new(0) | |
out = { :regular_hours => 0, :other_hours => Hash.new(0) } | |
days.inject(out) { |results, day| | |
times = day.times | |
{ :regular_hours => results[:regular_hours] + times[:regular_hours] | |
:other_hours => results[:other_hours].merge(times[:other_hours]) { |_,a,b| a+b }} | |
}.merge(:weekly_hours => regular_hours_by_week.values_at(*regular_hours_by_week.keys.sort)) | |
end |
This file contains hidden or 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
# Bandlimited interpolation simulation, as described by Eq 1 of | |
# https://ccrma.stanford.edu/~jos/resample/Theory_Ideal_Bandlimited_Interpolation.html | |
Fs = 44100.0 # sampling rate | |
Ts = 2.26757369614512e-05 # sampling interval (1/Fs) | |
def interp(samps, t) | |
(0...samps.size).inject(0) { |sum, n| | |
sum + samps[n] * hs(t - n * Ts) | |
} |
OlderNewer