Skip to content

Instantly share code, notes, and snippets.

View tpope's full-sized avatar

Tim Pope tpope

View GitHub Profile
@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 / 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 / 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 / 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: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 / 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 / .netrc
Created December 10, 2012 00:46
Sample netrc
machine api.heroku.com
login my@email.com
password 01230123012301230123012301230123
machine api.github.com password something login somebody
machine ftp.server login abc password def account ghi macdef somemacro
cd somehwhere
continues until end of paragraph
@tpope
tpope / foremux
Last active August 11, 2016 16:42
#!/usr/bin/env ruby
# Install in PATH as foremux
if %w(help --help -h).include?(ARGV.first)
$stderr.puts <<-help
Usage:
foremux [PROCESS]
Options:
-e, [--env=ENV] # Specify an env file to load, defaults to .env
--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/
[extensions]
color =