Skip to content

Instantly share code, notes, and snippets.

@bluegraybox
bluegraybox / Batbone-excerpt.coffee
Created March 29, 2012 15:53
Extending Backbone collections
@LIST = (path="", model=null, opts={}) ->
opts.model = model if model
Backbone.Collection.extend $.extend opts,
parse: ({data}) -> data
comparator: (item) ->
compare_item(item)
url: API path
@REVERSE_LIST = (path="", model=null, opts={}) ->
list = @LIST(path, model, opts)
$.extend list,
@bluegraybox
bluegraybox / find_missing_modules.sh
Created March 14, 2012 16:40
Find cpanm modules that failed to install
#!/bin/bash
# Report on modules that failed to install.
#
# Look for various "FAIL" messages in the cpanm build.log files.
# (FIXME: Explain the difference, and what they mean.)
# Parse out the module names and report any that are not installed.
logs=$HOME/.cpanm/work/*/build.log
@bluegraybox
bluegraybox / lib.sh
Created March 9, 2012 14:52
Stack traces in bash
#!/bin/bash
function stacktrace() {
frame=0
while caller $frame ; do frame=$((frame + 1)) ; done
}
function lib_inner() {
stacktrace
}
@bluegraybox
bluegraybox / .bashrc_ssh
Created March 8, 2012 02:22
Initialize ssh-agent in .bashrc
# Set up ssh-agent
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
@bluegraybox
bluegraybox / .screenrc
Created March 1, 2012 03:19
Config file for 'screen' utility.
altscreen on
termcap * OP
@bluegraybox
bluegraybox / for_lines.sh
Created February 15, 2012 03:01
Bash 'for' loop over lines, not words
#!/bin/bash
# Only split on newlines, so each line of data is one record.
default_IFS=$IFS
IFS="$(echo -e "\n\r")"
# each $line will be one line, even if there are spaces in it.
for line in $(cat sample_data.txt) ; do
# do stuff...
done
@bluegraybox
bluegraybox / pubsub.erl
Created January 18, 2012 02:22
Simple publish-subscribe service (for erlangdc)
-module(pubsub).
-export([handle/0, server/0]).
server() ->
register(ps, handle()).
%% handle/0
handle() ->
spawn(fun () -> handle([]) end).
@bluegraybox
bluegraybox / kvstore.erl
Created October 4, 2011 00:11
A simple REST key-value store using the spooky framework.
-module(hello_world).
-behaviour(spooky).
-export([init/1, get/2, loop/1]).
init([])->
%% register a process that holds our dict in memory
case whereis(store) of
undefined ->
Pid = spawn(?MODULE, loop, [dict:new()]),
register(store, Pid),
@bluegraybox
bluegraybox / wizard.sh
Created August 31, 2011 21:49
Framework for shell script wizard.
#!/bin/bash
# Interactive wizard to walk the user through a process.
# Tracks steps completed; allows user to exit at any point and pick back up there.
function step1 () {
read -p "step 1 ok, $1? " ok
}
function step2 () {
@bluegraybox
bluegraybox / update.sh
Created August 29, 2011 12:52
SVN update wrapper for teams
#!/bin/bash
# Update current SVN directory, creating diff & log files from previous version.
# For seeing what the rest of your team did.
last_rev=$(svn info | grep "^Revision: ")
last_rev=${last_rev#Revision: }
echo "Updating from $last_rev..."
svn up