Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
@terrainoob
terrainoob / custom_steps.rb
Created May 6, 2009 14:20
Cucumber subdomain testing
Given /^I visit subdomain (.+)$/ do |sub|
host! "#{sub}.#{TEST_DOMAIN}" #TEST_DOMAIN is defined in test.rb. In my case TEST_DOMAIN = 'example.com'
end
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
class ApplicationController < ActionController::Base
include Intercession
before_filter :load_skin
before_filter :require_user
before_filter :require_matching_skin
before_filter :require_admin
def load_skin
session.skin = Skin.for_request(request)
@vvalgis
vvalgis / Capistrano tasks for starting unicorn.rb
Created May 7, 2010 08:13
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
@airblade
airblade / html.rb
Created May 12, 2010 09:02 — forked from mislav/html.rb
require 'nokogiri'
ugly = Nokogiri::HTML ARGF
tidy = Nokogiri::XSLT File.open('tidy.xsl')
nice = tidy.transform(ugly).to_html
puts nice
# Rackup file for serving up a static site from a "public" directory
#
# Useful for chucking a static site on Heroku
class IndexRewriter
def initialize(app) @app = app end
def call(env)
env["PATH_INFO"].gsub! /\/$/, '/index.html'
@app.call(env)
end
@defunkt
defunkt / ruby.sh
Created May 19, 2010 17:53
My Ruby Setup
# directory structure of /ruby
$ tree -L 1 /ruby
/ruby
|-- default -> ree-1.8.7
|-- ree-1.8.7
`-- ruby-1.9.1-p376
3 directories, 0 files
@nruth
nruth / cookie_steps.rb
Created July 21, 2010 17:16
Testing login "remember me" feature with Capybara (rack::test or selenium) - deleting the session cookie (only)