Skip to content

Instantly share code, notes, and snippets.

@tpope
tpope / find_first_or_nil.rb
Last active September 14, 2015 23:34 — forked from johana-star/find_first_or_nil.rb
A way to fing the first thing that matches or set to nil
grading_period = @context.courses.detect do |course|
gp = GradingPeriod.context_find(course, params[:grading_period_id]) and break gp
end
@tpope
tpope / git-ssh
Created May 9, 2015 18:26
SSH to Git remotes
#!/usr/bin/env bash
# SSH to the user and host given by a Git remote and chdir to the repo path.
# The first argument is the remote name. All other arguments are passed to
# SSH, with some fudging to run a login shell if no command is given.
# Use git ssh -d to see the exact SSH command.
# Copyright (c) Tim Pope. Distributed under the MIT License.
nmap <script> <SID>: :<C-R>=getcmdline() =~ ',' ? "\0250" : ""<CR>
nmap <script> d<CR> <SID>:Dispatch<CR>
nmap <script> d<Space> <SID>:Dispatch<Space>
nmap <script> d! <SID>:Dispatch!
nmap <script> <SID>make <SID>:<C-R>=exists(':Make') > 1 ? 'Make' : 'make'<CR>
nmap <script> m<CR> <SID>make<CR>
nmap <script> m<Space> <SID>make<Space>
nmap <script> m! <SID>make!
" Is there a better mnemonic than =?
@tpope
tpope / cloud2butt.vim
Created September 18, 2014 06:12
Cloud to Butt dot Vim
function! s:butt() abort
syn match cloud2butt "\<th\%(e cloud\>\)\@=" conceal cchar=m
syn match cloud2butt "\%(\<th\)\@<=e\%( cloud\>\)\@=" conceal cchar=y
syn match cloud2butt "\%(\<the \)\@<=c\%(loud\>\)\@=" conceal cchar=b
syn match cloud2butt "\%(\<the c\)\@<=l\%(oud\>\)\@=" conceal cchar=u
syn match cloud2butt "\%(\<the cl\)\@<=o\%(ud\>\)\@=" conceal cchar=t
syn match cloud2butt "\%(\<the clo\)\@<=ud\>" conceal cchar=t
endfunction
@tpope
tpope / autocmd.tim
Last active August 29, 2015 13:58
Autocmd DSL
(def ^:private autocmds (dict))
(defmacro augroup [name & body]
`(try
(execute "augroup" ~(str name))
(execute "autocmd!")
~@body
(finally (execute "augroup END"))))
(defmacro autocmd [type pattern & body]
(let [sym (gensym "autocmd")]
`(do
@tpope
tpope / githubmail.rb
Created March 19, 2014 01:00
Add a gmail label to all closed issues where I the tpope last commented
require 'gmail'
require 'github_api'
require 'netrc'
require 'pry'
netrc = Netrc.read
github = Github.new(basic_auth: netrc['api.github.com'].join(':'))
Gmail.new(*netrc['imap.gmail.com']) do |gmail|
gmail.inbox.emails(from: 'github.com').each do |message|
begin
[extensions]
color =
--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 / 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
@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