Skip to content

Instantly share code, notes, and snippets.

View adamjmurray's full-sized avatar

Adam Murray adamjmurray

View GitHub Profile
class Range
def * other
pairs = []
self.each do |i|
other.each do |j|
pairs << [i,j]
end
end
return pairs
end
# 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)
orig_init(*params)
@held_notes = Hash.new {|hash,key| hash[key]={} }
at_exit do
@adamjmurray
adamjmurray / rails3_osx_setup.md
Created May 13, 2010 17:50
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 @ http://www.ruby-lang.org/en/news/2010/07/02/ruby-1-9-2-rc1-is-released/ 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 http://rvm.beginrescueend.com/releases/rvm-install-head )

# 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
device.receivers.each_send(event)
} >> OUTPUTS/'TO ABLETON'

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:

@adamjmurray
adamjmurray / Mobius transformation in Processing: Ruby vs Java.md
Created October 12, 2010 02:51
Mobius transformation in Processing: Ruby vs Java

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

@adamjmurray
adamjmurray / copy_github_repository.md
Created December 1, 2010 06:34
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 github.com, 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 [email protected]:github_username/old_project_name.git
mv old_project_name new_project_name

cd new_project_name

@adamjmurray
adamjmurray / file_definitely_exists.rb
Created April 12, 2012 00:25
How to detect that the case for a file path is correct on a case-insensitive file system
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?
end
end
@adamjmurray
adamjmurray / gist:3154437
Created July 21, 2012 03:18
Managing Ruby gems programmatically
# 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 Gem::Specification.find_all.map{|spec| "#{spec.name} (#{spec.version})" }
# =====================
# USING (a specific version of) gems
@adamjmurray
adamjmurray / DLSSynth_with_Ruby_FFI.rb
Last active April 26, 2017 13:47
How to play MIDI using the OS X built-in DLS synth using Ruby & FFI
require 'ffi'
# A MIDI driver to play MIDI using OSX's built in DLS synthesizer.
#
# == Authors
#
# * Adam Murray <[email protected]>
#
# == Copyright
#