Skip to content

Instantly share code, notes, and snippets.

View brentertz's full-sized avatar

Brent Ertz brentertz

View GitHub Profile
@brentertz
brentertz / blog-db-heroku-db-pull
Created August 12, 2011 15:55
For QuickLeft Blog Post on Heroku/Taps
$ heroku db:pull
...
Receiving schema
Schema: 100% |==========================================| Time: 00:00:00
Receiving indexes
users: 100% |==========================================| Time: 00:00:01
orders: 100% |==========================================| Time: 00:00:00
Receiving data
2 tables, 300 records
Resetting sequences
@brentertz
brentertz / original_static_assets_middleware.rb
Created September 2, 2011 15:00
heroku_rack - static asset middleware
module Heroku
class StaticAssetsMiddleware
def initialize(app)
@app = app
end
def call(env)
# call returns an array containing [response code, header, Rack::Response]
reply = @app.call(env)
@brentertz
brentertz / erb2haml.txt
Created September 16, 2011 14:55
# Convert erb to haml on command line...
gem install hpricot
gem install ruby_parser
# Find and list erb templates to convert, but don't convert
find . -name '*erb' | xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}'
# Find and convert erb to haml, (won't delete your erb)
find . -name '*erb' | xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | bash
@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 / quickleft.zsh-theme
Created November 25, 2011 22:27
An oh-my-zsh theme for QuickLeft
# QuickLeft theme for oh-my-zsh.
# Requires rvm or rbenv plugin (rbenv plugin - https://github.com/robbyrussell/oh-my-zsh/pull/670)
DEFAULT_TEXT_COLOR=$fg[white]
PROMPT_PREFIX_COLOR=$fg[white]
PROMPT_SUFFIX_COLOR=$fg[blue]
PROMPT_DIR_COLOR=$fg[yellow]
RUBY_PROMPT_COLOR=$fg[blue]
RUBY_PROMPT_INFO_COLOR=$fg[yellow]
GIT_PROMPT_COLOR=$fg[blue]
@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 / 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="[email protected]"
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 / 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 / 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 <[email protected]>"
"Foo Bar Bas <[email protected]>"
1.9.3p0 :002 > /(?<label>.*) <(?<email>[^>]*)/ =~ s
0
@brentertz
brentertz / engines
Created August 10, 2012 14:44
Getting started with Node and Express
{
"engines": {
"node": "0.8.x",
"npm": "1.1.x"
}
}