Skip to content

Instantly share code, notes, and snippets.

@geeksam
geeksam / gist:1128496
Created Aug 5, 2011
Platypus .rvmrc file
View gist:1128496
# PROJECT_RUBY="ruby-1.8.7-p302"
PROJECT_RUBY="rbx-1.2.3-20110315"
# use the global gemset in order to check for and install bundler, since we
# don't need it to be different for different projects
rvm use $PROJECT_RUBY@global --create --install
NEED_GEM_VERSION='1.3.7'
echo -n "Rubygems version 1.3.7 required. Do we have the right version?... "
if `ruby -rubygems -e "puts (Gem::VERSION == '$NEED_GEM_VERSION') ? exit(0) : exit(1)"`; then
@geeksam
geeksam / gist:1151929
Created Aug 17, 2011
gem_dep_tree output
View gist:1151929
rails 2.3.11 (>= 0)
actionmailer 2.3.11 (= 2.3.11)
actionpack 2.3.11 (= 2.3.11)
activesupport 2.3.11 (= 2.3.11)
rack 1.1.2 (~> 1.1.0)
activerecord 2.3.11 (= 2.3.11)
activeresource 2.3.11 (= 2.3.11)
rake 0.8.7 (>= 0.8.3)
rake 0.9.2 (>= 0.8.3)
rails 3.0.9 (>= 0)
View gist:1222811
class HashProxy
instance_methods.each { |meth| undef_method(meth) unless meth =~ /^__/ }
def self.new(delegate)
return delegate unless delegate.kind_of?(Hash)
super
end
def initialize(hash)
@hash = hash
@geeksam
geeksam / gist:1641464
Created Jan 19, 2012
Unsubscribe via snail mail? wtf?
View gist:1641464
If you'd prefer not to receive e-mail like this from Adobe in the future, please unsubscribe. Alternatively, you may mail your unsubscribe request to:
UNSUBSCRIBE
Adobe Systems Incorporated
Attn: Change of Address/Privacy
343 Preston Street
Ottawa, ON K1S 1N4
Canada
@geeksam
geeksam / gist:1689918
Created Jan 27, 2012
If Rails really, REALLY cared about OO principles
View gist:1689918
(In response to https://gist.github.com/1687527, with apologies and smoochies to @jc00ke.)
my-proj
|
-- app
|
-- data_mappers <--- (see note below)
-- models
-- views
-- controllers
@geeksam
geeksam / gist:1881240
Created Feb 22, 2012
Slightly friendlier API for adding custom method traces to NewRelic
View gist:1881240
require 'new_relic/agent/method_tracer'
class NR
# Convenience method for adding NewRelic tracing around specific methods of interest.
#
# Note about performance:
#
# " CAUTION - adding probes to your code adds overhead.
# Each probe burns about 20 microseconds of CPU.
# Be careful not to probe a method that's called frequently in a loop. "
@geeksam
geeksam / gist:2560081
Created Apr 30, 2012
Epic Morning Commute
View gist:2560081
  • Check bus arrival times, see that bus closest to my house is due... NOW.
  • Sprint out door.
  • Sprint down the long block, catch bus.
  • Get off bus downtown, use Car2Go membership to drive Smart Car rest of way to office (just for fun).
  • Get to office ready to set up ergonomically appropriate desk and monitors.
  • Discover that only one monitor has arrived (no desk), without the VESA mount adapter needed to put it on my monitor stand.
  • Unable to do any physical setup, go to sit on couch in lobby area.
  • Realize that I left my RSA token at home, 2.8 miles away.
  • Discover that wifi is not working. (RSA token wouldn't have helped anyway.)
  • Pack up, go back outside to the Car2Go Smart Car I parked directly in front of the office just 20 minutes earlier. RFID reader pauses, then displays message NO CONNECTION / Car temporarily not available for rental
View README.md

Rubyists! In the process of doing an "extract method object" refactoring, I wound up with a service object that calls several other (inner) service objects. A simplified version is below.

Note that (a) I'm using a simple Result object to report success/failure back to the calling code, and (b) I'm passing the same Result instance around to subservices (to keep track of overall process state).

My question is this: in a multistep process, how should I handle failure in an intermediate step?

The options I can think of are:

  1. As in the example below (do_phase_3 unless @result.failure?), explicitly check for failure in a substep, and abort manually.
  2. Raise an exception, which gets caught in the outer (class-level) .perform call, which then returns the result object as usual.
@geeksam
geeksam / gist:3336885
Created Aug 13, 2012
Testing bicycle interface (from POODR)
View gist:3336885

I really like the idea of testing the interface of the base Bicycle class, but I'm having that "someone on the Internet is WRONG!" feeling when I get to the section "Testing Concrete Subclass Behavior".

Specifically, you write "The RoadBikeTest should ensure that local_spares works while maintaining deliberate ignorance about the existence of the spares method. The shared BicycleInterfaceTest already proves that RoadBike responds correctly to spares, it is redundant and ultimately limiting to reference that method directly in this test."

The thing is, though, that--at least as written in the Rough Cut version of the book I'm looking at--the BicycleInterfaceTest doesn't prove that RoadBike responds correctly to spares. It only proves that it responds to spares.

So I went off to recreate the code locally to make sure that what I was seeing was correct, and sure enough, I can comment out the entire method body of Bicycle#spares, and all the interface tests pass because they're just checking #respon

@geeksam
geeksam / gist:3735442
Created Sep 17, 2012
Canned reply to recruiting inquiries
View gist:3735442

Hi, [insert recruiter's first name here]-

I've gone to some lengths to save everyone some time by maintaining a FAQ page on my resume website: http://resume.livingston-gray.com/faq.html

I've even gone so far as to change my LinkedIn profile so that it directs recruiters to read the FAQs before contacting me about relocation opportunities. So, thank you, [recruiter's first name]! By carefully ignoring all of that information, you've freed me from having to feel even remotely guilty for sending you a canned response.