View add_attrs_to_obj.rb
def add_attrs(obj, attrs)
attrs.each do |k,v|
obj.send("#{k}=", v)
return obj
View suppress_ruby_output.rb
# Temporarily redirects STDOUT and STDERR to /dev/null
# but does print exceptions should there occur any.
# Call as:
# suppress_output { puts 'never printed' }
def suppress_output
original_stderr = $stderr.clone
original_stdout = $stdout.clone
$stderr.reopen('/dev/null', 'w'))
View braintree.rb
if Rails.env.production?
Braintree::Configuration.environment = Rails.env.staging? ? :sandbox : :production
Braintree::Configuration.merchant_id = ENV["braintree_merchant_id"]
Braintree::Configuration.public_key = ENV["braintree_public_key"]
Braintree::Configuration.private_key = ENV["braintree_private_key"]
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.merchant_id = "<super secret>"
Braintree::Configuration.public_key = "<super secret>"
Braintree::Configuration.private_key = "<super secret>"
View titleize.rb
def titleize(str) {|s| (x = s.strip.downcase)[0].upcase + x[1..-1]}.join(' ')
View rails_route_recognizer.rb
class RouteRecognizer
attr_reader :paths
# To use this inside your app, call:
# ``
# This returns an array, e.g.: ['assets','blog','team','faq','users']
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}
def initialize
View deserialize.js
function deserialize(string) {
var array = string.split('&');
var hash = {};
$.each(array, function(i, val) {
var data = val.split('=');
hash[data[0]] = decodeURIComponent(data[1]);
return hash;

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.


This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

# Create rails app
gem install make_it_so
make_it_so rails <name>
rake db:create db:migrate db:test:prepare && rspec
# get NPM set up (make sure node is installed)
npm init
npm install --save babel-loader gulp webpack gulp-webpack react redux react-redux
touch webpack.config.js
vim webpack.config.js
View halp.rb
module Halp
extend self
def format_host(str)
"#{(url = URI(str)).host}#{":#{url.port}" if url.port != 80}"