Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Peter Boling pboling

🏠
Working from home
View GitHub Profile
@pboling
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
#
# CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
# COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
#
namespace :db do
View Post Upgrade to El Capitan, with Homebrew & Ruby.md

I upgraded to El Capitan, with Homebrew & Ruby, and this is how I did it flawlessly.

... and Xcode and Java, etc.

Prepare

If you don't already have homebrew installed, do that first, so you don't have to deal with SIP issues. Install all Software Updates available in the Apple Menu, up to and including El Capitan.

Hardware

@pboling
pboling / PhantomJS Install.md
Last active Jul 23, 2019
How to install old PhantomJS 1.8.2 on Mac OS X
View PhantomJS Install.md

PhantomJS

Install phantomjs (http://phantomjs.org)

brew has a recipe for phantomjs, but it has moved on to version 2.0.0, and we still require 1.8.2 (at newest), and we can't get that old and dirty with brew anymore.

On a Mac:

mkdir -p ~/root
wget https://phantomjs.googlecode.com/files/phantomjs-1.8.2-macosx.zip -O ~/root/phantomjs-1.8.2-macosx.zip
@pboling
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)
View slim_vs_haml.md

Analysis of Slim vs. Haml Project Health

  • Static data as of April 13, 2015, some updates as of October 1, 2015
# Metric Haml Slim Winner
1 Issues Open Issues Open Issues Slim
2 Stars Stars Open Issues Slim
3 Quality Stars Code Quality Slim
4 T
@pboling
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)
end
end
View clone-all-github-repos.sh
# Download all repos for an organization
ORG_NAME=trumaker
curl -s https://api.github.com/orgs/$ORG_NAME/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
# Download all repos for a user
USER_NAME=pboling
curl -s https://api.github.com/users/$USER_NAME/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
@pboling
pboling / nested_filters.rb
Last active Aug 29, 2015
Concern::NestedFilters
View nested_filters.rb
module Concern
module NestedFilters
extend ActiveSupport::Concern
CACHE_EXPIRATION = 1.days
NULL_SORT = "LAST"
NestedFilter = Struct.new(:filter_klass, :filter_param_key, :filter_name, :filter_options)
NestedFilterOption = Struct.new(:id, :name)
included do
View api_logger.rb
require 'ext/grape_middleware_logger'
module TrumakerAPI
module Middleware
class ApiLogger < Grape::Middleware::Logger
def after
logger.info "[api] Requested#{request_log}" if !request_log.blank?
if Rails.env.development?
response_body = JSON.parse(response.body.first)
@pboling
pboling / phone_finder.rb
Last active Aug 29, 2015
Find Phone Numbers in Dirty Database
View phone_finder.rb
# SQL_PHONE_NORMALIZER Example:
# Lead.find_by_sql(PhoneFinder::SQL_PHONE_NORMALIZER.call(table: 'leads', column_name: 'phone', phone: '(555) 760-2012'))
# User.find_by_sql(PhoneFinder::SQL_PHONE_NORMALIZER.call(table: 'users', column_name: 'phone', phone: '555-223-4027'))
#
# AREL_PHONE_NORMALIZER Example:
# PhoneFinder::AREL_PHONE_NORMALIZER.call(rel: Lead.where(email: 'peter.boling@example.org'), table: 'leads', column_name: 'phone', phone: '(555) 760-2012')
# PhoneFinder::AREL_PHONE_NORMALIZER.call(rel: User.where(email: 'peter.boling@example.org'), table: 'users', column_name: 'phone', phone: '555-223-4027')
#
# See: https://coderbits.com/posts/pCl7og
module PhoneFinder