This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(pubsub). | |
-export([handle/0, server/0]). | |
server() -> | |
register(ps, handle()). | |
%% handle/0 | |
handle() -> | |
spawn(fun () -> handle([]) end). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
altscreen on | |
termcap * OP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function stacktrace() { | |
frame=0 | |
while caller $frame ; do frame=$((frame + 1)) ; done | |
} | |
function lib_inner() { | |
stacktrace | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(cheat_sheet). % end with a period | |
%% Let these functions be called externally. | |
-export([countdown/1, countdown/0]). % number of parameters - it matters! | |
%% atoms begin with a lower-case letter | |
%% Variables begin with an upper-case letter | |
%% Start defining a function with the most specific case first | |
countdown(0) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(cheat_sheet_ipc). | |
-export([init/0, incr/1, decr/1, current/0]). % not loop/0 | |
%% Define a constant. | |
-define(SVC_NAME, counter_service). % atom, not Variable or string | |
%% Start a new process to manage our counter. | |
init() -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char | |
import System.IO | |
readFirstLine = withFile "test.txt" ReadMode (\handle -> do | |
line <- hGetLine handle | |
return line) | |
readAndPrintTestFile = withFile "test.txt" ReadMode (\handle -> do | |
contents <- hGetContents handle | |
-- unless we output contents in some way, it isn't evaluated, and will be empty |