Skip to content

Instantly share code, notes, and snippets.

@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active May 5, 2024 14:52
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@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 / .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 / gist:935741
Created April 21, 2011 23:58
Git interrogation oneliners
# Cumulative totals of lines added/deleted
git log --numstat STARTING_HASH..ENDING_HASH -M | grep '^[0-9]\+[[:space:]]\+[0-9]\+[[:space:]]' | awk '{added+=$1} {deleted+=$2} END { print added, deleted }'
@iangreenleaf
iangreenleaf / bitcoin_idle
Created June 2, 2011 02:04
Bitcoin mining when idle
#!/bin/bash
# Monitors for signals from gnome-screensaver and activates or deactivates
# bitcoin miners accordingly.
# Params to the mining programs are all hardcoded. Change 'em manually. Leave the "&"s.
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'" | \
while read line; do
case "$line" in
@iangreenleaf
iangreenleaf / gist:984bc6765d2a4dc49862
Created May 12, 2014 18:18
Import seperate git repo as subdirectory
export target=my_dir
git remote add "$target" file:////path/to/original/repo
git fetch "$target"
git co -b "$target" "$target/master"
# Probably breaks on whitespace, sorry dawg.
git filter-branch -f --tree-filter "mkdir -p \"$target\"; git ls-tree \$GIT_COMMIT --name-only | xargs --no-run-if-empty mv -t $target" "$target"
git co master
git merge "$target"
git remote remove "$target"
git br -d "$target"
@iangreenleaf
iangreenleaf / npm-troubleshooter
Last active March 26, 2024 16:50
THE MULTI-PURPOSE NPM TROUBLESHOOTING SCRIPT
#!/bin/bash
# THE MULTI-PURPOSE NPM TROUBLESHOOTING SCRIPT
# Guaranteed to fix any and every problem with your npm install!**
#
# © ️Ian Young 2016
#
# Usage:
# Simply run the script, passing as arguments the command that is failing.
# Come back in 1-45 minutes to a totally fixed npm install.