Skip to content

Instantly share code, notes, and snippets.

View brentertz's full-sized avatar

Brent Ertz brentertz

View GitHub Profile
@brentertz
brentertz / emitter.js
Created October 20, 2012 16:30
Node.js: Extend a class to be an EventEmitter
var util = require('util'),
EventEmitter = require('events').EventEmitter;
var Server = function() {
var self = this;
this.on('custom_event', function() {
self.logSomething('custom_event');
});
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@brentertz
brentertz / gist:3176445
Created July 25, 2012 14:24
Ruby regex capture named matches as local variables.
# You can name your captured matches and ruby will create local variables for you automatically.
# The regex is on Rubular at http://rubular.com/r/HJbhamKAib
$ irb
1.9.3p0 :001 > s = "Foo Bar Bas <foo@bar.com>"
"Foo Bar Bas <foo@bar.com>"
1.9.3p0 :002 > /(?<label>.*) <(?<email>[^>]*)/ =~ s
0
@brentertz
brentertz / ab.sh
Created March 27, 2012 14:35
Apache Bench - Load test a protected page
#!/bin/bash
COOKIE_JAR="ab-cookie-jar"
COOKIE_NAME="_myapp_session"
USERNAME="foo@bar.com"
PASSWORD="password"
LOGIN_PAGE_URI="http://localhost:3000/users/sign_in"
TEST_PAGE_URI="http://localhost:3000/dashboard"
echo "Logging in and storing session id."
@brentertz
brentertz / application.rb
Created February 4, 2012 22:43
Rack middleware to redirect WWW to non WWW domain.
# Configure Rack middleware
config.middleware.insert_before 0, 'WwwRedirect'
@brentertz
brentertz / sample-cla
Created June 9, 2017 14:25
sample-cla
This is a sample contributor's license agreemenet
@brentertz
brentertz / rails
Created July 11, 2012 22:45
Rack middleware to help avoid SEO duplicate content issues. Removes www and trailing slash and performs a permanent redirect.
config.middleware.insert_before(0, 'Rack::SeoRedirect')
@brentertz
brentertz / spec_helper.rb
Created January 6, 2013 04:00
database_cleaner alternative
config.around do |example|
ActiveRecord::Base.transaction do
example.run
raise ActiveRecord::Rollback
end
end
@brentertz
brentertz / say_formatter.rb
Last active December 10, 2015 00:19
Custom RSpec formatter that speaks aloud using the say command, if available.
require 'rspec/core/formatters/progress_formatter'
# Custom RSpec formatter that speaks aloud using the say command, if available.
# Not to be taken too seriously, but fun for annoying your coworkers.
# Usage: bundle exec rspec -r ./say_formatter.rb -f SayFormatter spec
class SayFormatter < RSpec::Core::Formatters::ProgressFormatter
VOICES = %w[Agnes Albert Alex Bad\ News Bahh Bells Boing Bruce Bubbles Cellos
Deranged Fred Good\ News Hysterical Junior Kathy Pipe\ Organ
Princess Ralph Trinoids Vicki Victoria Whisper Zarvox]
@brentertz
brentertz / application.rb
Last active October 13, 2015 06:58
Disallow site indexing in non-production environments
# Disallow site indexing in non-production environments
config.middleware.insert_before(::Rack::Lock, '::Rack::Robots')