Skip to content

Instantly share code, notes, and snippets.

View tpope's full-sized avatar

Tim Pope tpope

View GitHub Profile
@tpope
tpope / gist:1167200
Created August 24, 2011 02:52
Use .rbenv-version with RVM
# ~/.rvm/hooks/after_cd
local dir="$PWD"
while [ "$(dirname "$dir")" != "$dir" ]; do
if [ -f "$dir/.rbenv-version" ]; then
rvm use "$(cat "$dir/.rbenv-version")"
break
fi
dir="$(dirname "$dir")"
@tpope
tpope / account.html.haml
Created May 15, 2011 15:01
Our designers are way more clever than your designers
%fieldset.account_info
- ["First Name","Last Name","Email","Choose Password"].each do |n|
%dl.half
%dt
%label{:class => cycle("required", "", "required", "required")}=n
%dd
%input(type="text")
@tpope
tpope / uploads_controller.rb
Created April 18, 2011 02:27
Carrierwave on Heroku
class UploadsController < ApplicationController
def show
headers['Cache-Control'] = 'public; max-age=600'
send_file Rails.root.join("tmp/uploads/#{params[:path]}"), :disposition => 'inline'
end
end
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'hike', :git => 'git://github.com/sstephenson/hike.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'rack-ssl', :git => 'git://github.com/josh/rack-ssl.git'
gem 'rack-cache', :git => 'git://github.com/rtomayko/rack-cache.git'
ActionDispatch::Routing::PolymorphicRoutes.module_eval do
def polymorphic_url_with_hierarchy(record, options={})
record = record.hierarchy if record.respond_to?(:hierarchy)
polymorphic_url_without_hierarchy(record, options)
end
alias_method_chain :polymorphic_url, :hierarchy
end
ActionView::Helpers::FormHelper.module_eval do
def form_for_with_hierarchy(object, *args, &block)
@tpope
tpope / css.vim
Created January 2, 2011 05:42
Nikolai's fix to nested closing curly brace indenting
" Vim indent file
" Language: CSS
" Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2010-12-22
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
class SettingsController < ApplicationController
expose(:setting)
def update
setting.save
respond_with setting, :location => settings_path
end
end
@tpope
tpope / .gitattributes
Created October 24, 2010 20:38
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundlelock
db/schema.rb merge=railsschema
{:name => "John"}.factorbate :user do |parent|
activate!
{:body => "Your mom!"}.factorbate :comments, self
end
@tpope
tpope / morse.rb
Created June 11, 2010 03:50 — forked from ryanb/morse.rb
def morse s;s.upcase.gsub(/\S/){|x|("CF+(514M )DGL"[x[0]-65]).to_s(3).tr("12",".-")};end