Skip to content

Instantly share code, notes, and snippets.

View deathbob's full-sized avatar

Bob Larrick deathbob

View GitHub Profile
master>rails new yammy
[... nothing to see here ...]
master>cd yammy
master>rails g model Dummy name:string
invoke active_record
create db/migrate/20110114203601_create_dummies.rb
create app/models/dummy.rb
invoke test_unit
create test/unit/dummy_test.rb
create test/fixtures/dummies.yml
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
require 'test_helper'
class Admin::ArticlesControllerTest < ActionController::TestCase
setup do
@article = articles(:one)
@typus_user = AdminUser.first
@request.session[:typus_user_id] = @typus_user.id
@request.env['HTTP_REFERER'] = '/admin/articles'
end
@deathbob
deathbob / after_set_user
Created February 2, 2011 02:37
Hack for devise after_set_user on warden::manager
# config/initializers/anything.rb
Warden::Manager.after_set_user do |user, auth, opts|
puts "Hello"
debugger
puts "Hi"
end
# fire up server
@deathbob
deathbob / mashup_getter.rb
Created February 21, 2011 01:59
Little script to help me catch up on my mashups!
#!ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'fileutils'
prefix = Time.new.strftime("%F")
FileUtils.mkdir(prefix) unless File.exists?(prefix)
@deathbob
deathbob / gist:862857
Created March 9, 2011 19:52
Car and cdr for strings in ruby.
class String
def car
self.match(/\s*(\S+)/) ? $1 : nil
end
def cbr(sep = ' ')
self.split(sep).at(0)
end
class TenCommandments
# Had to change this method name, it didn't read well in my test suite.
# t.should be_thou_shalt_not_kill??? Give me a break. Not idiomatic Ruby!
# *I* would't be caught dead with those specs on.
# def thou_shalt_not_kill
# true
# end
# Much more idiomatic. Now my specs read like butter too.
require 'spec_helper'
describe Gig do
before do
@gig = Gig.new
@gig.save
end
it "should belong to a user and validate the presence of a user" do
@deathbob
deathbob / Guardfile
Created June 23, 2011 21:27 — forked from brentkirby/Guardfile
Guard + Rspec + Spork
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2,
:cli => '--colour --drb --format documentation --fail-fast',
:all_after_pass => false,
:all_on_start => false,
:keep_failed => false,
:notify => true do
watch(%r{^spec/.+_spec\.rb$})
require 'spec_helper'
describe Users::OmniauthCallbacksController do
include Devise::TestHelpers
before :each do
@user = Factory.create(:user)
request.env["devise.mapping"] = Devise.mappings[:user]
end