Skip to content

Instantly share code, notes, and snippets.

View eigenben's full-sized avatar

Ben Hughes eigenben

View GitHub Profile
class Project
def penguin
self.class.where(:something => parent_object.something)
end
end
@eigenben
eigenben / 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",
@eigenben
eigenben / 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
@eigenben
eigenben / 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"
@eigenben
eigenben / 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
@eigenben
eigenben / 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
@eigenben
eigenben / 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
@eigenben
eigenben / 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