Skip to content

Instantly share code, notes, and snippets.

@queso
queso / gist:12015
Created September 22, 2008 15:15
Time.now doesn't work for automatic timezone support, but it seems Time.zone.now does. All the documentation indicates that Time.now should work as well...
## Anyone care to explain why using Time.now and Time.zone.now result in two different times in the db?
>> e = Event.create(:title => "Test2", :url => "http://tests.com", :length => 60, :starts_at => Time.now + 1.day)
=> #<Event id: 4, user_id: nil, title: "Test2", url: "http://tests.com", starts_at: "2008-09-23 16:05:14", length: 60, category_id: nil, format_id: nil, advertisment_type: nil, highlight_type: nil, created_at: "2008-09-22 20:05:14", updated_at: "2008-09-22 20:05:14", permalink: "test2", description: nil, popularity: 0.0, promoted: false>
>> Time.now + 1.day
=> Tue Sep 23 16:05:26 -0400 2008
>> e = Event.create(:title => "Test2", :url => "http://tests.com", :length => 60, :starts_at => Time.zone.now + 1.day)
=> #<Event id: 5, user_id: nil, title: "Test2", url: "http://tests.com", starts_at: "2008-09-23 20:05:43", length: 60, category_id: nil, format_id: nil, advertisment_type: nil, highlight_type: nil, created_at: "2008-09-22 20:05:43", updated_at: "2008-09-22 20:05:43", permalink: "test
########## Why does the yield output outside the content_tag block?
# Method
def submit(*args)
@template.content_tag(:div, :class => "save_actions") {
super(*args) + (yield).to_s
}
end
#### spec_factory.rb
require 'factory_girl'
Factory.sequence :login do |n|
"bob#{n}"
end
Factory.sequence :email do |n|
"person#{n}@example.com"
end
# Specs
describe "process" do
before(:each) do
@starling = mock(Starling)
Starling.should_receive(:new).and_return(@starling)
@queue = Tweetbot::Queue.new
end
#!/usr/bin/env ruby
def mem_usage
`ps -o rss= -p #{$$}`.to_i
end
count = (ARGV[0] || 5).to_i
puts "current process id is #{$$}"
puts "Memory before anything: #{mem_usage}"
#!/usr/bin/env ruby
def mem_usage
`ps -o rss= -p #{$$}`.to_i
end
@count = (ARGV[0] || 5).to_i
puts "current process id is #{$$}"
puts "Memory before anything: #{mem_usage}"
class Mailer < ActionMailer::ARMailer
def setup_template(name, email)
site = SiteSetting.find(:first)
from site.admin_email.to_s
self.mailer_name = 'shared'
self.template = 'email'
options = { 'site' => site }
yield options if block_given?
@queso
queso / error
Created November 18, 2008 14:29
1)
NoMethodError in 'UserMailer should create a new email row when sending an email'
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.render_subject
/Users/josh/Code/HandCrafted/bootstrap/app/models/mailer.rb:16:in `setup_template'
/Users/josh/Code/HandCrafted/bootstrap/app/models/user_mailer.rb:23:in `setup_user_notification_email'
/Users/josh/Code/HandCrafted/bootstrap/app/models/user_mailer.rb:9:in `activation'
/Library/Ruby/Gems/1.8/gems/actionmailer-2.1.1/lib/action_mailer/base.rb:446:in `__send__'
/Library/Ruby/Gems/1.8/gems/actionmailer-2.1.1/lib/action_mailer/base.rb:446:in `create!'
/Library/Ruby/Gems/1.8/gems/actionmailer-2.1.1/lib/action_mailer/base.rb:439:in `initialize'
#!/usr/bin/env ruby
require 'rubygems'
require 'mysql'
require 'highline/import'
database = ARGV[0] + "_production"
username = ARGV[0] + "_dba"
password = ask("Enter the password for the new database: ") { |q| q.echo = "*" }
root_password = ask("Enter your root database password: ") { |q| q.echo = "*" }
this.loadCSS(this.doc,"/stylesheet/style.css");
html = "<div id='events'>"
html += "<div class=\'vevent clearfix\'>\n <div class=\'header clearfix\'>\n <abbr class=\'dtstart\' title=\'2008-09-10\'>Wed - Feb 11, 2009 @ 01:00PM CST<\/abbr>\n <span class=\'starts_in\'>Starts in 5 days<\/span>\n <\/div>\n <div class=\'voting\'>\n <div class=\'vote_count\'>\n <span class=\'vote_number\'>1<\/span>\n <span>vote<\/span>\n <\/div>\n <div class=\'vote_action\'>\n <div class=\'voteup\'>\n <span><a href=\"http://calfeed.local/events/25-test-8/vote\">vote up<\/a><\/span>\n <\/div>\n <\/div>\n <\/div>\n <div class=\'body\'>\n <h3 class=\'summary\'>\n <a href=\"/events/25-test-8\" class=\"url\">Test<\/a>\n <\/h3>\n <div class=\'description\'>\n <p>Apple / (test.com) &ndash; Test <a href=\"/events/25-test-8\">read more<\/a><\/p>\n <\/div>\n <div class=\'tools clearfix\'>\n <ul>\n <li class=\'comments_count\'><a href=\"/events/25-test-