Skip to content

Instantly share code, notes, and snippets.

View rubiety's full-sized avatar

Ben Hughes rubiety

View GitHub Profile
@rubiety
rubiety / jazzity_scale_tones.js
Created April 15, 2012 16:57
Jazzity Scale/Mode Tone Indexes
// Generated from Ruby:
// JSON.pretty_generate Scale.all.map do |s|
// {:name => s.name, :modes => s.modes.inject({}) {|b,m| b[m.name] = m.tones.map(&:tone); b} }
// end
[
{
"name": "Major",
@rubiety
rubiety / png_renderer.rb
Created January 15, 2012 22:51
Jazzity PngRenderer using Capybara Webkit
require "capybara/rails"
class PngRenderer
include Capybara::DSL
DEFAULT_PATH = Rails.root.join("public/images/rendered")
def initialize(url)
@url = url
end
@rubiety
rubiety / staff_to_png.rb
Created January 15, 2012 00:00
Background PNG Generation for Jazzity
require "capybara/rails"
Capybara.javascript_driver = :webkit
class StaffToPng
@queue = :staff_to_png
def self.perform(chord)
visit "/chords/#{chord}"
page.driver.render "generations/#{chord}.png"
@rubiety
rubiety / gist:1448238
Created December 8, 2011 19:46
freezing.rb
class City
def freezing?
case name
when "San Diego"
current_temperature < 60
when "Austin"
current_temperature < 50
when "Rochester"
current_temperature < -10
else
@rubiety
rubiety / scale.rb
Created May 14, 2011 06:36
Jazzity Rails + Backbone.js + Coffeescript Example
class Scale < ActiveRecord::Base
include KeyContext
has_many :tones, :class_name => 'ScaleTone', :extend => ToneSequence, :dependent => :destroy
delegate :notes, :to => :tones
end
@rubiety
rubiety / roman_numerals.rb
Created May 5, 2011 23:22
Roman Numeral Ruby Quiz
#!/usr/bin/env ruby
MAPPINGS = {
"I" => 1,
"V" => 5,
"X" => 10,
"L" => 50,
"C" => 100,
"D" => 500,
"M" => 1000
}
# MODEL
class Theater
named_scope :with_recent_comments,
:select => "*, recent_comments.created_at AS last_comment_at",
:joins => "INNER JOIN (SELECT id, entity_id, created_at FROM comments WHERE entity_type = 'Theater' ORDER by id DESC LIMIT 100)
AS recent_comments ON recent_comments.entity_id = theaters.id",
:order => "recent_comments.created_at DESC"
end
# MODEL
class Theater
named_scope :with_recent_comments,
:select => "*, recent_comments.created_at AS last_comment_at",
:joins => "INNER JOIN (SELECT id, entity_id, created_at FROM comments WHERE entity_type = 'Theater' LIMIT 100)
AS recent_comments ON recent_comments.entity_id = theaters.id",
:order => "recent_comments.created_at DESC"
end
@rubiety
rubiety / web_services.md
Created April 12, 2011 19:17 — forked from ryanb/web_services.md
Web Services to Recommend

Different services I can suggest when a non-tech friend or family member asks me how they can cheaply make a website and possibly use it to sell stuff online.

Website Hosting

@rubiety
rubiety / idiomizing_transforms.rb
Created October 27, 2010 21:31
Awesome "idiomizing transformations" just written for ruby_scribe.
# = For to Each Block Transform
# Finds instances using "for something in collection"-style of iteration and converts
# it to using a standard collection.each block.
#
# Example:
#
# for element in collection
# do_something(element)
# end
#