Skip to content

Instantly share code, notes, and snippets.

@geeksam
geeksam / tmux-client-2171.log
Created November 12, 2012 18:23
tmux barfs when sourcing config file with bad command

Works

~/.tmux.conf:

bind z send-keys "say ack" C-m

Launches, but prints error

~/.tmux.conf:

@geeksam
geeksam / gist:3875462
Created October 11, 2012 21:02
Roles in Ruby
class Role < Module
IncompleteInterface = Class.new(RuntimeError)
def included(receiver)
missing_methods = @public_api.map(&:to_sym) - receiver.public_instance_methods.map(&:to_sym)
unless missing_methods.empty?
raise IncompleteInterface,
"#{receiver} must implement these methods: #{missing_methods.inspect}"
end
@geeksam
geeksam / gist:3735442
Created September 17, 2012 03:46
Canned reply to recruiting inquiries

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.

@geeksam
geeksam / gist:3336885
Created August 13, 2012 04:15
Testing bicycle interface (from POODR)

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

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:2560081
Created April 30, 2012 17:12
Epic Morning Commute
  • 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
@geeksam
geeksam / gist:1881240
Created February 22, 2012 04:03
Slightly friendlier API for adding custom method traces to NewRelic
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:1689918
Created January 27, 2012 17:32
If Rails really, REALLY cared about OO principles
(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:1641464
Created January 19, 2012 17:59
Unsubscribe via snail mail? wtf?
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:1222811
Created September 16, 2011 18:53
HashProxy
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