Skip to content

Instantly share code, notes, and snippets.

View cddr's full-sized avatar

Andy Chambers cddr

View GitHub Profile
@cddr
cddr / fixup-whitespace.sh
Created September 13, 2013 20:03
Fixes whitespace only on the lines I've changed
# Really dumb script to fix up whitespace but only on the lines changed in the current
# commit. Run this script from your $PROJECT/.git/hooks/pre-commit
#
git diff HEAD --no-color > /tmp/stage.diff
git apply -R /tmp/stage.diff
git apply --whitespace=fix /tmp/stage.diff
@cddr
cddr / fixup-whitespace.sh
Created September 13, 2013 20:03
Fixes whitespace only on the lines I've changed
# Really dumb script to fix up whitespace but only on the lines changed in the current
# commit. Run this script from your $PROJECT/.git/hooks/pre-commit
#
git diff HEAD --no-color > /tmp/stage.diff
git apply -R /tmp/stage.diff
git apply --whitespace=fix /tmp/stage.diff
@cddr
cddr / git-fu.sh
Created July 11, 2013 19:09
Find the first few branches that contain the specified commit
# Find the pull request that introduced a given commit
COMMIT=c78f9ef # just an example commit id
# This will list the first few branches that contain this commit (including only "pull request" branches)
git branch -r --contains $COMMIT |grep "origin/pr" |sort |head
@cddr
cddr / annotate.js
Created July 11, 2013 15:19
Annotate a page with a formtastic form
javascript: (function () {
$("label").prepend(function () {
if ($("abbr sup", this).length === 0) {
var annotation = $("<sup>", { "text": $(this).attr("for"),
"style": "color: red" });
return $("<abbr>").append(annotation);
}
})
})();
@cddr
cddr / yolo
Last active December 16, 2015 17:29
Finding a memory leak in ruby2/rails4
#You Only Leak Once
# Install valgrind using one of the following
brew install valgrind
sudo apt-get install vagrind
# make sure valgrind is enabled in your ruby build
CONFIGURE_OPTS="--with-valgrind" rbenv install 2.0.0-p0
# control test (should not show any memory leaks)
@cddr
cddr / gist:5228055
Created March 23, 2013 15:15
Common Lisp validation syntax
(defclass venue (validatable)
((zip :col-type string :initarg :zip :accessor zip)
(phone :col-type string :initarg :phone :accessor phone)
(website :col-type (or db-null string) :initarg :website :accessor website))
(:metaclass pomo:dao-class)
(:keys id))
(defvalidators venue ()
(website (start-with "https://"))
(phone (match "(\\d\\d\\d)-\\d\\d\\d-\\d\\d\\d"))
@cddr
cddr / stuey.rb
Created February 25, 2013 23:15
Testing daemons.....
MUM=["mom", "mommy", "mother", "mama"]
loop do
puts MUM.sample
sleep(1)
end
# Script to review code in the order specified by Dougo on where_web. If you
# prefer a different order just rearrange the order of "git diffs", and maybe
# alter the definition of "ordered_files" if you actually add or remove a step
#
# It assumes you've checked out a local copy of the pull request and are
# comparing that with develop.
#
BASE=develop
HEAD=HEAD
@cddr
cddr / code-review.sh
Created January 30, 2013 22:51
Simple script to help reviewing large pull requests
# Helper script for anyone that has to review Ken's massive pull requests
#
# Usage:
# 0. Save this file as ~/bin/code-review, make it executable and put it in your $PATH
# 1. Use https://gist.github.com/3342247 to get a local copy of the PR
# 2. Save this as ~/bin/code-review
# 3. $ git checkout pr/foo
# 4. $ git diff develop.. --oneline |code-review
#
ps -ef |grep long-running-proc
502 6536 5782 0 21:02 pts/8 00:00:07 long-running-proc
kill -s SIGCONT 6536