This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Taken from http://coderrr.wordpress.com/2008/04/22/building-the-right-class-with-sti-in-rails/ | |
class GenericClass < ActiveRecord::Base | |
class << self | |
def new_with_cast(*a, &b) | |
if (h = a.first).is_a? Hash and (type = h[:type] || h['type']) and (klass = type.constantize) != self | |
raise "wtF hax!!" unless klass < self # klass should be a descendant of us | |
return klass.new(*a, &b) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Commit < Struct.new(:path) | |
class << self | |
def all | |
commits = `git log --decorate --pretty=oneline` | |
[].tap do |refs| | |
commits.split(/\n/).each do |commit| | |
refs << Commit.new(commit) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
osascript -e "set Volume 10" && say "this will turn your volume on and say something" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This allows you to have namespaced models in fixjour | |
module Fixjour | |
class Builder | |
def name | |
@name ||= (@options[:as] || @klass.name.underscore).to_s.gsub("/", "_") | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# created by Peter Jaros and Jeff Dean | |
require "rubygems" | |
require "spec" | |
require "active_support" | |
module Weekdays | |
def advance_weekdays(days) | |
d = self | |
days.times do |day| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
See http://www.websequencediagrams.com/ for awesome diagrams. It has an api as well. | |
DSL-based state machine implementations make it hard to follow good coding practices, such as: | |
- keeping things DRY | |
- making sure that objects have single responsibility | |
- making sure that classes change at the same pace (open closed) | |
- making sure that classes only depend on classes that change less often than they do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def in_memory_database? | |
ENV["RAILS_ENV"] == "test" and | |
ENV["IN_MEMORY_DB"] and | |
Rails::Configuration.new.database_configuration['test-in-memory']['database'] == ':memory:' | |
end | |
$TESTING=true | |
if in_memory_database? | |
puts "connecting to in-memory database ..." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When /^I type "([^\"]*)" into the "([^\"]*)" rich text editor$/ do |description, iframe_id| | |
selenium.select_frame "id=#{iframe_id}" | |
selenium.type_keys "css=body", description | |
selenium.select_frame "relative=top" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/hellos/erb.html.erb | |
# note the leading spaces - this makes it exactly the same number of bytes that erector outputs | |
<%- 1000.times do -%><%= render :partial => "simple" %><%- end -%> | |
# app/views/hellos/_simple.html.erb | |
<p><%= "hello world" %></p> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Views::Layouts::Application < Erector::Widget | |
def render | |
div :class => "header" do | |
text "header" | |
end | |
div :class => "body" do | |
inner_content | |
end | |