Skip to content

Instantly share code, notes, and snippets.

View rubiety's full-sized avatar

Ben Hughes rubiety

View GitHub Profile
#!/usr/bin/ruby
## JetBlue AYCJ Notifier
# So JetBlue doesn't want to tell us exactly when AYCJ-ers can book flights.
# This script polls my inbox for any new e-mail from JetBlue and continually
# contacts http://www.jetblue.com/aycj and sees if the "come back tomorrow" image is still there.
# If anything has changed or an error occurs, use's Mac OS "say" to dictate text and wake me up
# so I can book my damn flights. I really wonder how many people are going to stay up tonight hitting the
# refresh button every 10 seconds.
# Don't like for's?
#
module RubyScribe
module Transformers
class Eachifier < Transformer
def transform(e)
if e.is_a?(Sexp) && e.kind == :for
transform_for_to_each(e)
else
super
@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
#
@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

# 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
# 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
@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
}
@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 / 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 / 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"