Skip to content

Instantly share code, notes, and snippets.

@dpwright
dpwright / rubygmail.rb
Created April 16, 2012 00:57
Sending email with Ruby + Google Apps Mail
#!/usr/bin/env ruby
require 'rubygems'
require 'tlsmail'
msg=<<EOF
From: Test Sender <[email protected]>
To: Test Recipient <[email protected]>
Subject: test
@dpwright
dpwright / selectivelydelete-sed.sh
Created April 17, 2012 00:46
Selectively deleting any instance of LINE from files matching SEARCH using sed
grep -Rl "SEARCH" . | while read FILE; do sed -i "" "/LINE/d" $FILE; done
grep -Rl "SEARCH" . | while read FILE; do sed "/LINE/d" $FILE > tmp; mv tmp $FILE ; done
@dpwright
dpwright / selectivelydelete-ex.sh
Created April 17, 2012 00:57
Selectively deleting any instance of LINE from files matching SEARCH using ex
grep -Rl "SEARCH" . | while read FILE; do (echo "g/LINE/d"; echo 'wq') | ex -s FILE; done
@dpwright
dpwright / git-merge-keep-mine.sh
Created May 11, 2012 03:29
Git merge driver which always accepts your own version of a file
# I want to keep MY version when there is a conflict
# Nothing to do: %A (the second parameter) already contains my version
# Just indicate the merge has been successfully "resolved" with the exit status
exit 0
@dpwright
dpwright / git-merge-keep-theirs.sh
Created May 11, 2012 03:33
Git merge driver which always accepts their version of a file
# I want to keep THEIR version when there is a conflict
# Copy their version over ours and report success
cp -f $3 $2
exit 0
@dpwright
dpwright / .gitattributes
Created May 11, 2012 03:37
Telling git to use our custom merge drivers
*.exe -crlf -diff merge=keep-mine
*.tga -crlf -diff merge=keep-mine
@dpwright
dpwright / svn-notify-hook.sh
Created May 30, 2012 05:34
SVN post-commit hook to send emails to file owners
#!/usr/bin/env bash
LOOK=/usr/bin/svnlook
REPOS="$1"
REV="$2"
PROJECT="$3"
AUTHOR=$($LOOK author $REPOS -r $REV)
DOMAIN=domain.com
@dpwright
dpwright / .gitconfig
Created June 5, 2012 06:39
Git alias to open all diffs in vim tabs
dt = "!f() { vim -p $(git diff --name-only) +\"tabdo Gdiff $@\" +tabfirst; }; f"
@dpwright
dpwright / filesize.sh
Created June 25, 2012 02:13
Bash oneliner: watch a filesize
while true; do echo -e -n "\r`ls -l -h FILENAME | awk '{ print $5 }'`"; done
@dpwright
dpwright / .gitconfig
Created June 26, 2012 06:14
Git alias to amend a specific commit earlier in the tree
amend-commit = "!f() { START=`(git symbolic-ref -q HEAD || git rev-parse HEAD) | cut -d"/" -f 3`; git checkout -q $1 && git commit --amend && git rebase --onto HEAD $1 $START; }; f"