Skip to content

Instantly share code, notes, and snippets.

@schacon
schacon / temp_path.rb
Created July 20, 2011 21:19
helper for tests to create a temp directory
def temp_path
t = Tempfile.new('graph')
fpath = t.path
t.unlink
FileUtils.mkdir_p(fpath)
fpath
end
#! /usr/bin/env ruby
$LOAD_PATH.unshift '/Users/schacon/projects/git/rugged/lib'
require 'rugged'
require 'rubygems'
require 'pp'
dir, id = "/opt/linux.git"
@schacon
schacon / stopwatch.rb
Created June 22, 2011 15:59
simple ruby stopwatch
class Stopwatch
attr_writer :splits, :max, :start, :end, :total
def initialize(message)
@message = message
@splits = []
@max = 5
end
@schacon
schacon / auto-backup.rb
Created May 12, 2011 23:50
Example Scripts from Three Trees Talk
back_branch = 'refs/heads/backup'
`rm /tmp/backup_index`
ENV['GIT_INDEX_FILE'] = '/tmp/backup_index'
last_commit = `git rev-parse #{back_branch}`.strip
last_tree = `git rev-parse #{back_branch}^{tree}`.strip
`git add --all`
next_tree = `git write-tree`.strip
@schacon
schacon / gist:942899
Created April 26, 2011 19:19
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
The sign-off is a simple line at the end of the explanation for
the patch, which certifies that you wrote it or otherwise have
the right to pass it on as a open-source patch. The rules are
pretty simple: if you can certify the below:
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
[alias]
serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git
unstage = reset HEAD
lol = log --oneline --graph --decorate
lols = log --oneline --graph --decorate --simplify-by-decoration --branches --remotes
branches = !git-branches
st = status -sb
ss = status --short
logg = log --oneline --graph --decorate
sh = !git-sh
@schacon
schacon / .gitconfig
Created April 11, 2011 21:43
insteadOf example
[url "https://github.com/"]
insteadOf = "gh:"
@schacon
schacon / crush.rb
Created March 21, 2011 17:58
pngcrush script to run in a directory of pngs
#! /usr/bin/env ruby
#
Dir.glob("*.png") do |file|
puts "crushing #{file}"
file2 = file + '.cr'
`pngcrush #{file} #{file2}`
save = File.stat(file).size - File.stat(file2).size
puts " save #{save}"
`mv #{file2} #{file}`