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
# spec_helper.rb | |
module BoxMatcher | |
class Box | |
def initialize(name) | |
@name = name | |
end | |
def matches?(actual) | |
raise "You must supply a 'containing' attribute (.containing 'foo')" unless @contents |
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
# some_object.html.erb_spec.rb | |
it "should render 'bleh' in a box named 'meh'" do | |
render "/some_object/show.html.erb" | |
response.should have_box_named("meh").containing('bleh') | |
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
./script/generate scaffold Video title:string video_url:string | |
#video.rb | |
class Video < ActiveRecord::Base | |
acts_as_video_fu | |
end | |
Video.create!(:title => "Some Title", :video_url => "http://www.youtube.com/watch?v=gEILFf2XSrM") | |
#show.html.erb |
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
# Usage: Date.today.weekdays_until(some_date_in_the_future) | |
class Date | |
def weekdays_until(date) | |
return 0 if date <= self | |
(self..date).select{|day| day.is_weekday?}.size | |
end | |
def is_weekday? | |
self.wday != 0 && self.wday != 6 |
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
function calc_pct_complete($job_id, $d) { | |
$pc = 0; | |
$sql = "some SQL query"; | |
$res = mysql_query($sql); | |
while ($row = mysql_fetch_array($res)) { | |
$x = total_days($row[start_date], $d) / total_days($row[start_date], $row[end_date]); | |
if ($x < 0) { | |
$x = 0; | |
} elseif ($x > 1) { | |
$x = 1; |
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 percentage_complete(date = Date.today) | |
self.phases.inject(0.0) do |sum, phase| | |
percent_complete = phase.percentage_complete(date) | |
percent_complete = percent_complete ** 2 unless %w{X Y}.include?(phase.name) | |
sum += (percent_complete * phase.percentage_of_hours) | |
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
/opt/ruby-enterprise-1.8.6-20080709/bin/ruby /opt/ruby-enterprise-1.8.6-20080709/bin/gem install aws-s3 |
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
#PassengerRuby /usr/bin/ruby | |
RailsRuby /opt/ruby-enterprise-1.8.6-20080709/bin/ruby |
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
if Job.is_creatable_by(@current_user) | |
... | |
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
if creatable | |
... | |
end |