Skip to content

Instantly share code, notes, and snippets.

View tpope's full-sized avatar

Tim Pope tpope

View GitHub Profile
@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
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)
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'
@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
@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 / 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 / gist:1169556
Created August 24, 2011 23:17
rvm --trace use 1.9.3-preview1@unknown
+__rvm_parse_args:727> [[ -n 4.3.10 ]]
+__rvm_parse_args:750> [[ -z '' && -n '' ]]
+__rvm_parse_args:752> [[ 0 -eq 1 || -n '' ]]
+__rvm_parse_args:20> [[ -n use ]]
+__rvm_parse_args:22> rvm_token=use
+__rvm_parse_args:24> (( 1 > 0 ))
+__rvm_parse_args:26> next_token=1.9.3-preview1@unknown
+__rvm_parse_args:27> shift
+__rvm_parse_args:32> case use ([[:alnum:]]*|@*)
+__rvm_parse_args:36> case use (use)
@tpope
tpope / _gem
Created August 27, 2011 18:58 — forked from alexvollmer/_gem
zsh completion for rubygems
#compdef gem gem1.9
gem_general_flags=("(-h --help)"{-h,--help}"[Get help on this command]"
"(-V --verbose)"{-V,--verbose}"[Set the verbose level of output]"
"(-q --quiet)"{-q,--quiet}"[Silence commands]"
"--config-file[Use this config file instead of default]:file:_files"
"--backtrace[Show stack backtrace on errors]"
"--debug[Turn on Ruby debugging]"
$nul_arg
)
@tpope
tpope / to_set_performance.rb
Created September 5, 2011 01:06 — forked from h3h/to_set_performance.rb
Don't Convert Arrays to Sets for Inclusion Checks
ids = (1..1_000_000).to_a; nil
x = rand(1_000_000)
Benchmark.realtime do
the_set = ids.to_set
1000.times do
the_set.include?(x)
end
end
# => 0.7543990612030029
@tpope
tpope / .inputrc
Created September 8, 2011 16:43
Basic amenities for vi readline bindings
set keymap vi-insert
Control-a: beginning-of-line
Control-b: backward-char
Control-d: delete-char
Control-e: end-of-line
Control-f: forward-char
Control-k: kill-line
Control-n: next-history
Control-p: previous-history
set keymap emacs-ctlx