Skip to content

Instantly share code, notes, and snippets.

View rahearn's full-sized avatar

Ryan Ahearn rahearn

  • 18F (work) + personal projects
  • Baltimore, MD
View GitHub Profile
@rahearn
rahearn / test_connection.sh
Created September 13, 2012 13:59
Simple ping script to test connectivity. Used previously to build case against Comcast's terrible service even while not home.
#!/bin/sh
# Simple script for checking network availability every 5 minutes
while true; do
ping -c 1 www.google.com &> /dev/null
echo "$? `date`" | tee -a ~/output.txt
sleep 300
done
@rahearn
rahearn / delegate_matcher.rb
Created March 27, 2012 21:21
RSpec matcher for "should delegate(:action).to :other_model"
# code source: https://github.com/thoughtbot/shoulda/issues/174
RSpec::Matchers.define :delegate do |delegated_method|
chain :to do |target_method|
@target_method = target_method
end
chain :as do |method_on_target|
@method_on_target = method_on_target
end
@rahearn
rahearn / auto_strip_text_attributes.rb
Created March 20, 2012 19:17
Adding functionality to every model in a system
# This file is in lib
module AutoStripTextAttributes
extend ActiveSupport::Concern
included do
text_columns = columns.collect do |c|
c.name.to_sym if c.type == :string || c.type == :text
end.compact