Skip to content

Instantly share code, notes, and snippets.

View mdarby's full-sized avatar
💭
pending validation

Matt Darby mdarby

💭
pending validation
View GitHub Profile
# 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
# 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
./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
# 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
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;
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
/opt/ruby-enterprise-1.8.6-20080709/bin/ruby /opt/ruby-enterprise-1.8.6-20080709/bin/gem install aws-s3
#PassengerRuby /usr/bin/ruby
RailsRuby /opt/ruby-enterprise-1.8.6-20080709/bin/ruby
if Job.is_creatable_by(@current_user)
...
end
if creatable
...
end