Skip to content

Instantly share code, notes, and snippets.


Adam Murray adamjmurray

  • Stripe
  • San Francisco
View GitHub Profile
adamjmurray / DLSSynth_with_Ruby_FFI.rb
Last active Apr 26, 2017
How to play MIDI using the OS X built-in DLS synth using Ruby & FFI
View DLSSynth_with_Ruby_FFI.rb
require 'ffi'
# A MIDI driver to play MIDI using OSX's built in DLS synthesizer.
# == Authors
# * Adam Murray <>
# == Copyright
adamjmurray / gist:3154437
Created Jul 21, 2012
Managing Ruby gems programmatically
View gist:3154437
# Environment, set GEM_HOME & GEM_PATH. For example, we can launch JRuby like this:
# GEM_HOME=/Users/amurray/tmp/gems/ GEM_PATH=/Users/amurray/tmp/gems java -jar ~/Downloads/jruby-complete-1.7.0.preview1.jar -S irb
# =====================
# LISTING gems
puts Gem::Specification.find_all.to_s
puts{|spec| "#{} (#{spec.version})" }
# =====================
# USING (a specific version of) gems
adamjmurray / file_definitely_exists.rb
Created Apr 12, 2012
How to detect that the case for a file path is correct on a case-insensitive file system
View file_definitely_exists.rb
class File
# Does a case-sensitive check for file existence.
# Unlike the normal File.exists? method on OS X with its case-insensitive-by-default FS
def self.definitely_exists? path
folder = File.dirname path
filename = File.basename path
# Unlike Ruby IO, ls, and find -f, this technique will fail to locate the file if the case is wrong:
not %x( find "#{folder}" -name "#{filename}" ).empty?
adamjmurray /
Created Dec 1, 2010
How to copy a github repository

I recently wanted to make a copy of a github project. It sounds like I basically want a fork but, as of November 2010, github does not allow you to fork your own project. I think the following steps are currently the most straightforward to copy a project.

First, I setup a new project on, let's call it "new_project_name". Let's call the original project "old_project_name". I will also refer to my github username as "github_username".

After new_project_name was created on github, I ran the following commands:

cd some_temp_dir
git clone
mv old_project_name new_project_name
cd new_project_name
adamjmurray / Mobius transformation in Processing: Ruby vs
Created Oct 12, 2010
Mobius transformation in Processing: Ruby vs Java
View Mobius transformation in Processing: Ruby vs

As you might expect, the Ruby version is much cleaner but also much slower. Not suitable for real time work, but I'd certainly prefer using Ruby's Complex objects with inline arithmetic for any offline rendering. We could speed up the Ruby version by not using Complex objects, but that's kind of the whole point of using Ruby for this sort of thing...

Ruby Version

load_libraries 'opengl'
include_package "processing.opengl"
require 'complex'
I = Complex::I
View Inline SVG on

I wanted to use inline SVG in a rails app. Two steps were needed to enable this:

  1. Set content type to application/xhtml+xml. I enabled this globally by adding this to application_controller.rb

     before_filter{ response.content_type = 'application/xhtml+xml' }
  2. Indicate we're using XHTML in the <html> tag. I enabled this globally in application.html.erb:

     <html xmlns="">
View midi_processor design
# Here's how I envision inline midi message processing could work.
# This is an octave transposer.
# It filters for note on and note off events and changes their pitch before passing them along.
# Other event types will be passed through automatically.
INPUTS/'Akai' >> midi_processor /note_(on|off)/ { |event,device|
event.pitch += 12
adamjmurray /
Created May 13, 2010
Setting up Rails 3 on OS X (as of May 13, 2010)

Getting setup with Rails 3 right now can be tricky because of bugs that manifest with various combinations of ruby and rails versions. The best thing to do right now is to get the bleeding edge version of everything. Using the following process you can do that without impacting your existing ruby / rails installation.

UPDATE: As of July 2, 2010 it looks like you don't have to grab Ruby 1.9.2-head any more. Release Candidate 1 (RC1) of 1.9.2 was released and it worked fine during my brief testing. You can get it @ or install with rvm (see below)

Install rvm

rvm is the 'ruby version manager' for easily managing multiple versions of ruby. If you don't have it already, run:

 bash < <( curl )
View stuck note prevention in midiator
# Make MIDIator cleanup at program termination:
class MIDIator::Driver
alias orig_init initialize
alias orig_note_on note_on
alias orig_note_off note_off
def initialize(*params)
@held_notes = {|hash,key| hash[key]={} }
at_exit do
View range.*
class Range
def * other
pairs = []
self.each do |i|
other.each do |j|
pairs << [i,j]
return pairs
You can’t perform that action at this time.