Skip to content

Instantly share code, notes, and snippets.

class Plant
include MongoMapper::Document
key :weight, Float, :numeric => true
end
p = Plant.new(:weight => 'String')
p.weight # => 0.0
#!/bin/sh
echo "What should the Application be called (no spaces allowed e.g. GCal)?"
read inputline
name=$inputline
echo "What is the url (e.g. https://www.google.com/calendar/render)?"
read inputline
url=$inputline
def csrf_meta_tags
if protect_against_forgery?
[].tap do |tags|
tags << tag('meta', {:name => 'csrf-param', :content => request_forgery_protection_token})
tags << tag('meta', {:name => 'csrf-token', :content => form_authenticity_token})
end.join("\n").html_safe
end
end
@bryckbost
bryckbost / gist:945168
Created April 27, 2011 20:46
match versus =~.rb
require 'benchmark'
@string = "this is a long string that I want 123 to appear in"
Benchmark.bmbm(6) do |x|
x.report("String#match") do
100_000.times do
@string.match(/123/)
end
end
@bryckbost
bryckbost / gist:947005
Created April 28, 2011 18:48
Regex benchmark
require 'benchmark'
@string = "this is a long string that I want 123 to appear in"
Benchmark.bmbm(6) do |x|
x.report("String#match") do
1_000_000.times do
@string.match(/123/)
end
@bryckbost
bryckbost / gist:1040263
Created June 22, 2011 14:54
Capybara 1.0 and Chrome
# env.rb
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Download chromedriver from http://code.google.com/p/selenium/downloads/list
mv chromedriver to /usr/local/bin so it's in your path.
DEPRECATION WARNING: :confirm option is deprecated and will be removed from Rails 4.0. Use ':data => { :confirm => 'Text' }' instead.

Keybase proof

I hereby claim:

  • I am bryckbost on github.
  • I am bryckbost (https://keybase.io/bryckbost) on keybase.
  • I have a public key whose fingerprint is C96A 6B30 7473 6507 C1D2 8BE8 AAB0 83D9 6329 45C2

To claim this, I am signing this object: