Skip to content

Instantly share code, notes, and snippets.

@iangreenleaf
iangreenleaf / svn_safe.sh
Created January 18, 2010 06:50
svn switch disaster prevention
#!/bin/bash
### Copyright 2009 Ian Young
### Available under the terms of the MIT license
### ABOUT
### Prevents you from svn switching to a mismatched directory in a different branch.
### See http://blog.iangreenleaf.com/2009/11/avoiding-disaster-when-using-svn-switch.html
### USAGE
@iangreenleaf
iangreenleaf / rsync-retry.sh
Created January 18, 2010 07:12
rsync with retries
#!/bin/bash
### ABOUT
### Runs rsync, retrying on errors up to a maximum number of tries.
### Simply edit the rsync line in the script to whatever parameters you need.
# Trap interrupts and exit instead of continuing the loop
trap "echo Exited!; exit;" SIGINT SIGTERM
MAX_RETRIES=50
@iangreenleaf
iangreenleaf / funcs.sh
Created August 13, 2010 20:51
Git unsigned merge hook
function error_message {
echo -e >&2 \
"---------------------------------------------------------------------------------------------------------" \
"\n$1" \
"\n---------------------------------------------------------------------------------------------------------"
}
function undo_merge {
error_message "Undoing your merge. Please fix the problem and try again."
@iangreenleaf
iangreenleaf / gist:535897
Created August 18, 2010 19:35
MySQL import with file names and progress bar
# Usage: reload-db /path/to/sqldump dbname
function reload-db {
for f in "$1"/*.sql; do
printf "%-${COLUMNS}s" "$f">&2;
cat "$f";
done \
| pv -s `du -sb "$1" | awk '{print $1}'` \
| mysql -uroot "$2";
if [ $? != 0 ]; then echo 'ERRORS!!!!!!!!!!!!!'; return $?; fi
@iangreenleaf
iangreenleaf / gist:562724
Created September 2, 2010 18:47
Impromptu Scheme session
;; Semicolons are comments
> (+ 2 4)
6
> (+ 2 4 8)
14
> (define double (lambda (a) (+ a a)))
> (double 3)
6
> '(1 2 3) ; this is a list
(1 2 3)
# Mergesort
# precondition: no nils in the array
def sort some_array
return some_array if some_array.length == 1
half_length = some_array.length / 2
first_half = sort(some_array[0,half_length])
second_half = sort(some_array[half_length, some_array.length - half_length])
result = []
@iangreenleaf
iangreenleaf / .gitconfig
Created September 20, 2010 21:30
Better diffs in git
[diff "ruby"]
wordRegex = (@@?|\\b:|[^:]:)?[[:alnum:]_]+|:\"[^\"]+\"|::|[^[:space:]]
[diff "php"]
wordRegex = \\${0,2}[[:alnum:]_]+|::|->|[^[:space:]]
@iangreenleaf
iangreenleaf / .gitconfig
Created October 23, 2010 00:11
My .gitconfig
[core]
excludesfile = /Users/ian/.gitignore
[color]
ui = auto
[alias]
co = checkout
st = status
br = branch
ci = commit
m = checkout master
@iangreenleaf
iangreenleaf / scopes.md
Created March 11, 2011 17:01
Scopes are awesome (stop writing SQL)

Stop writing SQL

Refresher

named_scope in 2.x.

named_scope :active, :conditions => { :status => "activo" }

Just scope now.

scope :active, where( :status => "activo" )

@iangreenleaf
iangreenleaf / yaml.vim
Created March 15, 2011 17:38
Dumb-smart indentation for Yaml
" Vim indent file
" Language: Yaml
" Author: Ian Young
" Get it bundled for pathogen: https://github.com/avakhov/vim-yaml
if exists("b:did_indent")
finish
endif
"runtime! indent/ruby.vim
"unlet! b:did_indent