Skip to content

Instantly share code, notes, and snippets.

Evan Prothro eprothro

Block or report user

Report or block eprothro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Testing Modules with

It can be difficult to test the different scenarious for a module intended for use by including in another class.

If the class is statically defined in the spec, any later definitions extend, not replace, the first definition - which can cause test issues and breaks isolation between examples.

RSpec.describe SomeModule do
  class SomeIncluder
    include SomeModule
View Sublime Text go to spec or
eprothro / shards.yml
Created Apr 12, 2013
Dynamic Octopus configuration for master/slave horizontal DB scaling with a Rails application on the Heroku stack. See the wiki page for more info: Props to Heroku for the idea, gleaned from the dynamic database.yml they inject at build-time for rails apps.
View shards.yml
require 'cgi'
require 'uri'
def attribute(name, value, force_string = false)
if value
value_string =
if force_string
'"' + value + '"'
View sidekiq_depth_printer.rb
# Sidekiq Reporter
# Emit key statistics about Sidekiq queues to a stream.
# Examples:
# Log to STDOUT by default:
# ruby sidekiq_reporter.rb
View .bash_profile.bash
# ~/.bash_profile
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
source ~/
eprothro / prepend
Last active Aug 20, 2018
Ruby instrumentation glue example
View prepend
module Instrumentation

  def action(*args)
    super.tap do |r|
      puts "#=> instrumented action: succes=#{r} args=#{args}"
eprothro / gist:6243211
Last active Jun 8, 2018
Foundation Custom Forms Select Capybara Helper
View gist:6243211

Helper Module

# spec/support/custom_forms_helper.rb
module CustomFormsHelper
  def foundation_select(option, opts={})
    # Zurb Foundation adds custom markup after (and then hides)
    # the originating select. Here we simulate the user's interaction
    # with the custom form instead of just setting the hidden originating select's value
    originating_select_name = opts[:from]
View heroku logstash config
input {
  # translate syslog messages into logstash events
  # with priority field, fields added by SYSLOGLINE pattern
  # (e.g. timestamp, logsource, program, pid, etc.) and the 
  # rest of the syslog string in the message field
  syslog {
    # port => 514
    # codec => plain
    # syslog_field => "message"
eprothro / gist:214410555f9b198d296b
Last active May 15, 2018
Enumerators in Ruby | Primer
View gist:214410555f9b198d296b

Enumerators yield for each value in the enumeration

calling next returns the next value, and then raises when there's no values left
e = do |yielder|
  a = 1
  yielder.yield a
=> 1
eprothro / spec_boilerplate.rb
Created Oct 1, 2013
rspec boilerplate organization
View spec_boilerplate.rb
require 'spec_helper'
describe Resource do
let(:resource) { create :resource }
# ActiveRecord Relationship Behaviors #
context "with/when some context/event" do
You can’t perform that action at this time.