s = Test.new(:name => "foo")
# ActiveRecord::Test after_initialize
# ActiveRecord::Test after_initialize, :on => :update
# ActiveRecord::Test after_initialize, :on => :create
# ActiveRecord::TestObserver after_initialize
# ===> #<Test id: nil, name: "foo", created_at: nil, updated_at: nil>
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
Jbuilder.encode do |json| | |
json.content format_content(@message.content) | |
json.(@message, :created_at, :updated_at) | |
json.author do |json| | |
json.name @message.creator.name.familiar | |
json.email_address @message.creator.email_address_with_name | |
json.url url_for(@message.creator, format: :json) | |
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
#!/usr/bin/env ruby | |
# Put this file in the root of your Rails project, | |
# then run it to output the SQL needed to change all | |
# your tables and columns to the same character set | |
# and collation. | |
# | |
# > ruby character_set_and_collation.rb | |
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
$ brew install bash-completion | |
==> Downloading http://bash-completion.alioth.debian.org/files/bash-completion-1.3.tar.bz2 | |
######################################################################## 100.0% | |
==> ./configure --prefix=/usr/local/Cellar/bash-completion/1.3 | |
==> make install | |
==> Caveats | |
Add the following lines to your ~/.bash_profile file: | |
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
fi |
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
task :copy_jquery_files do | |
# Jasmine doesn't work with the asset pipeline; therefore we copy the jquery | |
# files manually. | |
spec = Gem::Specification.find_by_name("jquery-rails") | |
jquery_dir = Pathname.new(Gem.dir) + | |
"gems" + | |
"#{spec.name}-#{spec.version}" + | |
"vendor" + | |
"assets" + | |
"javascripts" |
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
= httperf --server localhost --port 3000 --uri /render_text --num-conns 500 --num-calls 20 | |
== Ruby 1.9.2/WEBrick | |
Request rate: 329.5 req/s (3.0 ms/req) | |
Request rate: 334.6 req/s (3.0 ms/req) | |
== Ruby 1.9.2/Passenger | |
Request rate: 539.5 req/s (1.9 ms/req) | |
Request rate: 543.1 req/s (1.8 ms/req) |
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
#!/usr/bin/python | |
# | |
# git-slim | |
# | |
# Remove big files from git repo history. | |
# | |
# Requires GitPython (https://github.com/gitpython-developers/GitPython) | |
# | |
# References: | |
# - http://help.github.com/remove-sensitive-data/ |
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
# blog post: http://blog.slashpoundbang.com/post/12694519460/email-validation-in-rails-3-or-active-model-without | |
# http://my.rails-royce.org/2010/07/21/email-validation-in-ruby-on-rails-without-regexp/ | |
class EmailValidator < ActiveModel::EachValidator | |
# Domain must be present and have two or more parts. | |
def validate_each(record, attribute, value) | |
address = Mail::Address.new value | |
record.errors[attribute] << (options[:message] || 'is invalid') unless (address.address == value && address.domain && address.__send__(:tree).domain.dot_atom_text.elements.size > 1 rescue false) | |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'date' | |
Benchmark.bm do|b| | |
ITERATE = 100000 | |
b.report("strptime") do | |
time = "2011-05-25 00:00:03 -0400" | |
fmt = "%Y-%m-%d %H:%M:%S %z" |
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 test_register_uri_for_post_method_with_parameters | |
FakeWeb.register_uri(:post, "http://example.com/users", :body => "User list 1", :parameters => {:p1 => 'v1'}) | |
FakeWeb.register_uri(:post, "http://example.com/users", :body => "User list 2", :parameters => :any) | |
assert_equal 2, FakeWeb::Registry.instance.uri_map.values.first[:post].size | |
assert FakeWeb.registered_uri?(:post, "http://example.com/users", :parameters => {:p1 => 'v1'}) | |
assert FakeWeb.registered_uri?(:post, "http://example.com/users", :parameters => :any) | |
end |