Author Archives: Philip Cunningham

Grossperskys Credit && Aw, Shucks

I wrote these tracks a while back, but they didn’t really fit with the stuff I’d written before now. Writing them helped get me up to speed with Ableton, which I really do miss.

Continue reading

Posted in News | Comments Off

Grossperskys Credit && Aw, Shucks

I wrote these tracks a while back, but they didn't really fit with the stuff I'd written before now. Writing them helped get me up to speed with Ableton, which I really do miss.

Continue reading

Posted in News | Comments Off

Decorating Active Record Scopes

I recently ran into a problem in work where I wanted serialize the same Active Record model to JSON differently depending on context.

The solution I ended up going with was to wrap objects inside an Active Record scope in another object and proxy unknown messages to the internal object.

The example here is somewhat trivial but having these little objects helped add clarity to our JSON API.

class JSONDecorator

  attr_reader :instance

  def self.decorate(instances)
    instances.map {|instance| new(instance) }
  end

  def as_json(opts={})
    raise "define as_json method on subclass"
  end

  def initialize(instance)
    @instance = instance
  end

  def method_missing(method, *args, &block)
    instance.send(method, *args, &block)
  end

end
class ComedianAvailability < JSONDecorator

  def as_json(opts={})
    json = Hash.new
    json["id"]        = id
    json["name"]      = title
    json["rating"]    = url
    json["available"] = available
    json
  end

  def available
    active ? "yes" : "no"
  end

end
json_response = ComedianAvailability.decorate(Comedian.scoped).to_json

Continue reading

Posted in News | Comments Off

Decorating Active Record Scopes

I recently ran into a problem in work where I wanted serialize the same Active Record model to JSON differently depending on context.

The solution I ended up going with was to wrap objects inside an Active Record scope in another object and proxy unk… Continue reading

Posted in News | Comments Off

The Sound of 122 Git Commits

Ever wondered what your environment sounded like every time you issued git commit? Nope? Neither had I but, I’m glad to say, that I now know.

I added a commit hook that recorded one second of audio from my laptop’s internal microphone every time I made a commit and stitched them together into a single audio file. The result is a series of audio snapshots.

Continue reading

Posted in News | Comments Off

The Sound of 122 Git Commits

Ever wondered what your environment sounded like every time you issued git commit? Nope? Neither had I but, I'm glad to say, that I now know.

I added a commit hook that recorded one second of audio from my laptop's internal microphone every ti… Continue reading

Posted in News | Comments Off

Ribiprocessing: A really slim layer between JRuby and Processing

I’m taking a class called Generative Creativity this semester and thought it’d be nice to use Ruby for my project. There’s already an option out there to use Processing from Ruby, ruby-processing, but it seemed really heavyweight for my needs and there doesn’t seem to be a very stable way to use it with Ruby 1.9.3 mode. I’ll probably expand ribiprocessing as the class progresses.

Installation

Add this line to your application’s Gemfile:

gem 'ribiprocessing'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ribiprocessing

Usage

require 'ribiprocessing'

class FlashingLightsSketch < Ribiprocessing::SimpleApp

  attr_reader :random_background

  def initialize(opts={})
    @random_background = opts[:random_background] || RandomBackground.new(self)
    super
  end

  def setup
    size 800, 600
  end

  def draw
    random_background.generate
  end

end

class RandomBackground
  include Ribiprocessing::Proxy

  def generate
    background rand(255), rand(255), rand(255)
  end

end

FlashingLightsSketch.new({:title=>"Flashing Lights"})

Continue reading

Posted in News | Comments Off

Ribiprocessing: A really slim layer between JRuby and Processing

I'm taking a class called Generative Creativity this semester and thought it'd be nice to use Ruby for my project. There's already an option out there to use Processing from Ruby, ruby-processing, but it seemed really heavyweight for my nee… Continue reading

Posted in News | Comments Off

Ribitco: Noddy runtime TCO for Ruby

So, I wrote my first RubyGem recently. It provides a class macro that allows you to tail-call optimise methods at runtime. Please note that this was just a bit of fun and I realise there are corner cases. The source code is available here.

Installation

Add this line to your application’s Gemfile:

gem 'ribitco'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ribitco

This Code

require 'ribitco'

class Recursive

  def factorial(n, acc=1)
    if n < 2 then acc else factorial(n - 1, n * acc) end
  end

  include Ribitco::TailCallOptimiser
  tco :factorial
end

Becomes

class Recursive

  define_method :factorial do |n, acc = 1|
    (n < 2) ? (acc) : (n = (n - 1); acc = (n * acc); redo)
  end

end

No Stack Explosion

example = Recursive.new
puts example.factorial(10000) # => 284625968091705451890641321211986889014805140170...

Continue reading

Posted in News | Comments Off

Ribitco: Noddy runtime TCO for Ruby

So, I wrote my first RubyGem recently. It provides a class macro that allows you to tail-call optimise methods at runtime. Please note that this was just a bit of fun and I realise there are corner cases. The source code is available here.

Installatio… Continue reading

Posted in News | Comments Off