Skip to content

Instantly share code, notes, and snippets.

View deathbob's full-sized avatar

Bob Larrick deathbob

View GitHub Profile
@deathbob
deathbob / gist:1102763
Created July 24, 2011 15:59 — forked from ianterrell/gist:1102751
Meta module madness
module Foo
def bar
@bar ||= self.snakes
end
def bar=(val)
@bar = val
end
end
@deathbob
deathbob / gist:1102683
Created July 24, 2011 14:38
Meta module madness
module Foo
def self.included(base)
class << base
attr_accessor :bar
end
base.instance_eval do
@bar ||= proc{self.snakes}.call
end
end
module Foo
def self.included(base)
class << base
attr_accessor :bar
end
base.instance_eval do
@bar = "pig"
end
end
end
@deathbob
deathbob / chunkybrawl.rb
Created June 29, 2011 19:25
Entry to CodeBrawl - ChunkyPNG edition
#! /usr/bin/env ruby
require 'rubygems'
require 'chunky_png'
image = ChunkyPNG::Image.from_file('input.png')
h = image.dimension.height
print "height #{h} \n"
w = image.dimension.width
print "width #{w} \n"
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
@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 Gig do
before do
@gig = Gig.new
@gig.save
end
it "should belong to a user and validate the presence of a user" do
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.
@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
@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)