Skip to content

Instantly share code, notes, and snippets.

@seanami
seanami / sinatra_erb_block_helper_test.rb
Created July 28, 2010 23:24
If you're using Sinatra with ERB and you want to write helpers that take blocks, you need a little bit of magic that other more complex frameworks provide for you (capture). Here's a really really simple example.
require 'rubygems'
require 'sinatra'
require 'erb'
helpers do
def buffer()
@_out_buf
end
def capture(buffer)
pos = buffer.size
#!/bin/bash
branch=`git status | head -n1 | cut -d' ' -f4`
rake cruise && git checkout master && git merge $branch && rake cruise && git push
@rkumar
rkumar / gist:445735
Created June 20, 2010 10:47
ruby's OptionParser to get subcommands
#!/usr/bin/env ruby -w
## Using ruby's standard OptionParser to get subcommand's in command line arguments
## Note you cannot do: opt.rb help command
## other options are commander, main, GLI, trollop...
# run it as
# ruby opt.rb --help
# ruby opt.rb foo --help
# ruby opt.rb foo -q
# etc
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
This example shows how to setup an environment running Rails 3 under 1.9.2 with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.2
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.2@rails3