Skip to content

Instantly share code, notes, and snippets.

View tpope's full-sized avatar

Tim Pope tpope

View GitHub Profile
@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 / speeddating.vim
Created October 16, 2011 05:04
Increment keywords with speeddating.vim
" Place in ~/.vim/after/plugin/speeddating.vim
" In Vim, -4 % 3 == -1. Let's return 2 instead.
function! s:mod(a,b)
if (a:a < 0 && a:b > 0 || a:a > 0 && a:b < 0) && a:a % a:b != 0
return (a:a % a:b) + a:b
else
return a:a % a:b
endif
endfunction
@tpope
tpope / DefaultKeyBinding.dict
Created September 23, 2011 21:07
Place in ~/Library/KeyBindings/DefaultKeyBinding.dict
/* vim: set ft=c sw=4 et: */
{
"^u" = "deleteToBeginningOfParagraph:";
"^v" = "pageDown:";
"^w" = "deleteWordBackward:";
"~/" = "complete:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~b" = "moveWordBackward:";
"~d" = "deleteWordForward:";
@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 / .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
@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 / _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 / 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)