Skip to content

Instantly share code, notes, and snippets.

View stouset's full-sized avatar

Stephen Touset stouset

View GitHub Profile
def join(*args)
args.unshift self
result = args.pop
result = Pathname.new(result) unless Pathname === result
return result if result.absolute?
args.reverse_each {|arg|
arg = Pathname.new(arg) unless Pathname === arg
result = arg + result
return result if result.absolute?
}
@stouset
stouset / foo.rb
Created December 1, 2011 01:24
autoload best practice
class Foo
autoload :Bar, 'foo/bar'
autoload :Baz, 'foo/baz'
end
Stage this hunk [y,n,q,a,d,/,k,K,g,e,?]? @@ -48 +81,2 @@
end
\ No newline at end of file
Stage this hunk [y,n,q,a,d,/,k,K,g,e,?]? @@ -48 +81,2 @@
end
\ No newline at end of file
Stage this hunk [y,n,q,a,d,/,k,K,g,e,?]? @@ -48 +81,2 @@
end
\ No newline at end of file
Stage this hunk [y,n,q,a,d,/,k,K,g,e,?]? @@ -48 +81,2 @@
@stouset
stouset / git-remote-merged
Created October 7, 2011 21:35
Merged branches
git branch -r | while read BRANCH; do
if [ `git incoming $BRANCH | wc -l` == 0 ]; then
echo $BRANCH
fi
done
@stouset
stouset / git-notify
Created October 7, 2011 21:33
Warn about unmerged branches
git branch -r | while read BRANCH; do
if [ `git incoming $BRANCH | wc -l` != 0 ]; then
AUTHOR=`git log $BRANCH -n 1 --format=format:%ae`
MESSAGE="You appear to be the person responsible for \`$BRANCH\`. It has unmerged commits. Can you take a second take make sure you still need it? If so, merge it when you can. If not, do a \`git push origin :${BRANCH#origin/}\`. Thanks."
echo -e $MESSAGE | mail -s "Possible stale branch" $AUTHOR
fi
done
@stouset
stouset / gist:1207165
Created September 9, 2011 19:54
Hash#fetch violates POLS
# which is the correct return value?
{ :a => 1, :b => 2 }.fetch(:a, :b) # => [ 1, 2 ]
{ :a => 1, :b => 2 }.fetch(:a, :b) # => :b
@stouset
stouset / .gitconfig
Created July 5, 2011 12:03
Git Config
[alias]
current-branch = "!f() { B=$(git symbolic-ref HEAD) && echo ${B#refs/heads/}; }; f"
current-remote = "!f() { B=$(git config branch.$(git current-branch).remote) && echo ${B}; }; f"
current-merge = "!f() { B=$(git config branch.$(git current-branch).merge) && echo ${B#refs/heads/}; }; f"
current-track = "!f() { R=$(git current-remote) && M=$(git current-merge) && echo ${R}/${M}; }; f"
remove = "!f() { git ls-files --deleted -z $@ | xargs -0 git rm -r; }; f"
addremove = "!f() { git add -v ${@-.}; git remove $@; }; f"
incoming = "!f() { T=$( [ \"${1}\" == \"\" ] && echo $(git current-track) || echo ${1} ) && git log ..${T}; }; f"
outgoing = "!f() { T=$( [ \"${1}\" == \"\" ] && echo $(git current-track) || echo ${1} ) && git log ${T}..; }; f"
wip = "!f() { git addremove $@; git commit -m 'Work in progress'; }; f"
@stouset
stouset / reactor.rb
Created June 13, 2011 15:42
Patch to auto-reload generated CSS/JS
def reload_browser(paths = [])
UI.info "Reloading browser: #{paths.join(' ')}"
paths.each do |path|
path = path.gsub %r{ (\.[^.]+) .* }x, '\1'
data = ['refresh', {
:path => "#{Dir.pwd}/#{path}",
:apply_js_live => @options[:apply_js_live],
:apply_css_live => @options[:apply_css_live]
}].to_json
@stouset
stouset / profile-update
Created April 25, 2011 19:38
Profile update script
#!/bin/bash
# include profile location variables
. ~/.profile
. ~/.profile.git/profile-env
# update ourself
(cd $DOT_PROFILE && git pull)
# symlink all home.d files into place