Skip to content

Instantly share code, notes, and snippets.

@bomatson
bomatson / minitest_string_spec.rb
Last active December 17, 2015 08:08
Tests against String
require "rubygems"
require "minitest/autorun"
class String
def my_test
"This is my test and I can cry if I want to"
end
def unstripped
class Surface
#...
SNARE_OPTIONS = { left: -51, right: 0, note: 38 }
KICK_OPTIONS = { left: 0, right: 100, note: 36 }
HAT_OPTIONS = { left: -100, right: -50, note: 57 }
def initialize(drum_type=nil, *opts)
case drum_type
when :snare
def on_frame(*args)
frame = args[1]
return if frame.pointables.empty?
set_finger_from(frame)
if @finger
x_position = @finger.tipPosition[0]
y_position = @finger.tipPosition[1]
def play(volume)
output = UniMIDI::Output.open(:first)
output.open do |node|
node.puts(0x90, @drum_note, volume)
sleep(0.1)
node.puts(0x80, @drum_note, volume)
end
end
class DrumSet < Artoo::MainRobot
#...
def initialize
@bass_drum = Surface.new(:kick)
@snare = Surface.new(:snare)
@hi_hat = Surface.new(:hat)
@crazy_sound = Surface.new(left: 151, right: 200, note: 22)
@drums = [@snare, @bass_drum, @hi_hat, @crazy_sound]
def is_a_hit?(timestamp, y_velocity)
if @previous[:y_velocity] && y_velocity && @previous[:y_velocity] > 0 && y_velocity < 0 && (timestamp - @previous[:timestamp] > 500)
true
end
false
end
def is_a_hit?(y_position)
if @previous[:y_position] && @previous[:y_position] > 150 && y_position < 150
true
else
false
end
end
def drum_for(x_position, y_velocity)
determine_volume_from(y_velocity)
drum_hit = @drums.detect do |drum|
x_position > drum.left_boundary && x_position < drum.right_boundary
end
drum_hit.play(@volume) if drum_hit
end
def determine_volume_from(velocity)
@volume = [[ 0, (velocity.abs/30).to_i ].max, 100].min
end
@bomatson
bomatson / .gitconfig
Created April 14, 2014 21:28
easily create new branches for chores, bugs, and features
[alias]
chore = "!sh -c 'git checkout -b chore/$1' -"
bug = "!sh -c 'git checkout -b bug/$1' -"
feature = "!sh -c 'git checkout -b feature/$1' -"