Skip to content

Instantly share code, notes, and snippets.

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:

DEPRECATION WARNING: :confirm option is deprecated and will be removed from Rails 4.0. Use ':data => { :confirm => 'Text' }' instead.
@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.
@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: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
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
#!/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
class Plant
include MongoMapper::Document
key :weight, Float, :numeric => true
end
p = Plant.new(:weight => 'String')
p.weight # => 0.0
@bryckbost
bryckbost / canvas_test.html
Created June 8, 2010 18:20
Simple canvas example to draw a rectangle with a pointed end
<!DOCTYPE>
<html>
<head>
<script type="application/javascript">
// https://developer.mozilla.org/en/Canvas_tutorial
function draw() {
var canvas = document.getElementById('canvas');
if (canvas) {
require "rubygems"
require 'scrobbler'
require 'tinder'
user = Scrobbler::User.new('nsain')
output = "#{user.username}'s Top 5 Weekly Artists\n" + ("-" * (user.username.length + 30)) + "\n"
user.weekly_artist_chart[0..4].each {|t| output += "#{t.name} (#{t.playcount})\n" }
campfire = Tinder::Campfire.new('subdomain')