Skip to content

Instantly share code, notes, and snippets.

View joho's full-sized avatar
At harbour

John Barton joho

At harbour
View GitHub Profile
@joho
joho / gist:7238
Created August 26, 2008 09:09 — forked from ryan-allen/gist:7230
,---------------------.
_.--._ ( I only bone *artists* )
,' `. `-,-------------------'
/ __) __` \ _.-'
( (`-`(-') )
/) \ _ / (
/' )-._.' . \ ___
( ,--., `.)___(___)
)( /-.,--'\ _ \X/`
'/ .'/ \ ( Uu")\
@joho
joho / gist:15236
Created October 7, 2008 04:02
git log | grep -i 'dhh'
git log | grep -i 'dhh'
DHH is an a-hole. validates_uniqueness_of is supposed to be case insensitive by default according to the docs, but it ain't.
if i ever meet DHH i'm gonna punch him in the face for changing this aspect of the rails api, then i'm gonna get him to punch me in the face for not fixing all the holes in our app, and now i'm gonna go hunting in the logs to find the user who pissed us off so we can all punch them in the face
stupid madness, stupid dhh and stupid me redux
stupid madness, stupid dhh and stupid me
#!/usr/bin/env ruby
# Open a new tab in Terminal
# usage: tab [cmd]
# If cmd is specified, it will be run in new tab while old tab is reactivated.
# If no cmd, new tab is activated
require "rubygems"
# gem install rb-appscript
require "appscript"
include Appscript
@joho
joho / with.rb
Created November 18, 2008 03:47 — forked from ryan-allen/with.rb
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def scoped_variable(*objects)
yield(objects)
end
alias scoped_variable scoped_variables
end
@joho
joho / with.rb
Created November 18, 2008 03:51
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def with(object)
yield(object)
end
end
@reports = []
@joho
joho / with.rb
Created November 18, 2008 03:56
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def with(object)
yield(object)
end
end
@reports = []
@joho
joho / with.rb
Created November 18, 2008 05:47 — forked from xaviershay/with.rb
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def with(object)
yield(object)
end
end
@reports = []
@joho
joho / gist:39169
Created December 22, 2008 22:40 — forked from notahat/gist:39132
value = "Don T Alias"
first_name, last_name = value.reverse.split(' ', 2).reverse.collect(&:reverse)
first_name = first_name.to_s
last_name = last_name.to_s
# Refactored to take into account Xavier's pathological aversion to case statements:
last_space_index = value.rindex(' ') || value.size
first_name, last_name = value[0..last_space_index].strip, value[last_space_index..value.size].strip
---
# http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002047
class Item < ActiveRecord::Base
before_save :tidy_up_vals
def tidy_up_vals
self.price = Money.new(price_before_type_cast.to_i * 100)
end
end
@joho
joho / lazy_load_attributes.rb
Created January 15, 2009 04:28
Lazy load your attributes with ActiveRecord
module LazyLoadingAttributes
def lazy_attribute(attribute_name)
send attribute_name
rescue ActiveRecord::MissingAttributeError
if id
reload
send attribute_name
else
raise "Cannot lazy load attributes without and ID (can't find the original record)"
end