Skip to content

Instantly share code, notes, and snippets.

Working from home

Peter Boling pboling

Working from home
View GitHub Profile
pboling / phone_finder.rb
Last active Aug 29, 2015
Find Phone Numbers in Dirty Database
View phone_finder.rb
# Lead.find_by_sql( 'leads', column_name: 'phone', phone: '(555) 760-2012'))
# User.find_by_sql( 'users', column_name: 'phone', phone: '555-223-4027'))
# Lead.where(email: ''), table: 'leads', column_name: 'phone', phone: '(555) 760-2012')
# User.where(email: ''), table: 'users', column_name: 'phone', phone: '555-223-4027')
# See:
module PhoneFinder
View api_logger.rb
require 'ext/grape_middleware_logger'
module TrumakerAPI
module Middleware
class ApiLogger < Grape::Middleware::Logger
def after "[api] Requested#{request_log}" if !request_log.blank?
if Rails.env.development?
response_body = JSON.parse(response.body.first)
pboling / nested_filters.rb
Last active Aug 29, 2015
View nested_filters.rb
module Concern
module NestedFilters
extend ActiveSupport::Concern
NestedFilter =, :filter_param_key, :filter_name, :filter_options)
NestedFilterOption =, :name)
included do
# Download all repos for an organization
curl -s$ORG_NAME/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load( { |repo| %x[git clone #{repo["ssh_url"]} ]}'
# Download all repos for a user
curl -s$USER_NAME/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load( { |repo| %x[git clone #{repo["ssh_url"]} ]}'
pboling / boolean.rb
Created Apr 3, 2015
TrueClass & FalseClass => Boolean Comparable hack
View boolean.rb
module Boolean
include Comparable
# true > false
def <=>(other)
raise ArgumentError, "Do not know how to compare #{other.class} with TrueClass and FalseClass" unless [TrueClass, FalseClass].include?(other.class)
other ? (self ? 0 : -1) : (self ? 1 : 0)
pboling / prepare-commit-msg
Last active Sep 19, 2015
commit message git hook: Adds story type and story ID to the end of each commit
View prepare-commit-msg
#!/usr/bin/env ruby
# vim: set syntax=ruby
# branches should be named like:
# <story_type>/<story_id>-explosion-in-the-fudge-factory-spec-suite-fix
# where story type is one of "hotfix", "bug", "feature", "candy"
branch = `git branch 2> /dev/null | grep -e ^* | awk '{print $2}'`
regex = /^(?<story_type>(hotfix)|(bug)|(feature)|(candy))\/(?<story_id>\d{8,})-.+\Z/
match_data = branch.match(regex)
pboling / gist:3714897
Last active Oct 10, 2015
compare specs run by rake & autotest
View gist:3714897
rake_files = "#{list of files copied from console when rake command is run}"
autotest_files = "#{list of files copied from console when autotest command is run}"
r = rake_files.split(' ').map {|x| ar = x.split('/'); ar[(ar.length-2)..(ar.length-1)].join('/')}
a = autotest_files.split(' ').map {|x| ar = x.gsub(/'/,'').split('/'); ar[(ar.length-2)..(ar.length-1)].join('/')}
# autotest will generally be lacking some, as its config becomes out of date
diff = r - a
pboling / plpgsql.rake
Last active Oct 12, 2015 — forked from rietta/plpgsql.rake
Are you using PostgreSQL and don't want to make your app run as PostgreSQL super user, then add this custom rake task to your `lib/tasks` folder and be happy.
View plpgsql.rake
# PostgreSQL writes two optional commands to the database schema
# file, called db/structure.sql, that can only be run as a root
# database user. These are not needed actually, so comment them
# out automatically
# COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
namespace :db do
pboling / std_out.rb
Created Oct 18, 2015
Rspec support: Silnce the `puts`
View std_out.rb
# Some specs causes a lot of stuff to output to the console during the spec run which interrupts the flow of lovely green dots.
# We don't want to ignore stuff that we want to see, like rspec deprecation warnings, but for an otherwise clean spec,
# that is puts ing things, we can turn those off by tagging the spec as :noisy.
RSpec.configure do |config|
original_stderr = $stderr
original_stdout = $stdout
config.before(:each, :noisy) do
# Redirect stderr and stdout
$stderr =, "w") # to /dev/null, since Ruby 1.9.3
$stdout =, "w") # to /dev/null, since Ruby 1.9.3
pboling / Airbrake GirlFriday Error
Created Feb 4, 2013
Airbrake generator fails on "uninitialized constant GirlFriday".
View Airbrake GirlFriday Error
script/rails generate airbrake --api-key key---derp
api_key: "key---derp"
js_api_key: "key---derp"
backtrace_filters: [#<Proc:0x007fa29d75c708@/Users/pboling/.rvm/gems/ruby-
development_environments: []
development_lookup: true
environment_name: "development"
host: ""