Skip to content

Instantly share code, notes, and snippets.

--langmap=ruby:+.rake
--regex-ruby=/(^|[:;])[ \t]*([A-Z][[:alnum:]_]+) *=/\2/c,class,constant/
--regex-ruby=/(^|;)[ \t]*(has_many|belongs_to|has_one|has_and_belongs_to_many)\(? *:([[:alnum:]_]+)/\3/f,function,association/
--regex-ruby=/(^|;)[ \t]*(named_)?scope\(? *:([[:alnum:]_]+)/\3/f,function,named_scope/
--regex-ruby=/(^|;)[ \t]*expose\(? *:([[:alnum:]_]+)/\2/f,function,exposure/
@tpope
tpope / splitjoin-maps.vim
Created October 24, 2012 22:12
Aggressively in-your-face splitjoin.vim mappings
function! s:join(cmd)
if exists(':SplitjoinJoin') && !v:count
let tick = b:changedtick
SplitjoinJoin
if tick == b:changedtick
execute 'normal! '.a:cmd
endif
else
execute 'normal! '.v:count.a:cmd
endif
@tpope
tpope / gist:2999229
Created June 26, 2012 21:26
Environment variable overrides in Rails
# Add config/overrides/*.yml to .gitignore
# and this near the top of application.rb
%w(defaults overrides).each do |type|
path = File.expand_path("../#{type}/#{Rails.env}.yml", __FILE__)
ENV.update(YAML.load_file(path)) if File.exist?(path)
end
# For things that are sensitive or developer dependent:
# config/overrides/{development,test}.yml
# For everything else:
@tpope
tpope / why_isnt_this_the_default.rb
Created June 5, 2012 17:34
Raise an error on missing assets
Sprockets::Helpers::RailsHelper::AssetPaths.class_eval do
class MissingAssetError < StandardError; end
def digest_for_with_presence_check(logical_path)
unless asset_environment[logical_path]
raise MissingAssetError.new("#{logical_path} doesn't exist")
end
digest_for_without_presence_check(logical_path)
end
alias_method_chain :digest_for, :presence_check
@tpope
tpope / gist:1218105
Created September 14, 2011 23:30
Part of rake tab completion in zsh
targets=( ${${(f)"$(_call_program targets $words[1] -sT $opt_args[(I)(-N|--nosearch)] ${(kv)opt_args[(I)(-f|--rakefile)]} 2>/dev/null)"}/(#b)rake ([^ ]##) ##\# (*)/${${match[1]}//:/\\:}:${match[2]:l}} )
@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 / 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 / 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