This is the preamble.
Table of Contents
| #!/usr/bin/bash | |
| function wrapInGraph() { | |
| # print beginning of DOT file, including formatting commands | |
| cat <<END | |
| digraph G { | |
| rankdir=LR; | |
| graph [ | |
| K=1.0, | |
| overlap=false, |
| # For reference: 1>&2 redirects output to stderr | |
| # This script should only be sourced by other scripts | |
| if [[ "$0" != '-bash' ]] ; then | |
| echo 'WARNING: functions.sh should be sourced, not executed' 1>&2 | |
| fi | |
| # Check for an error, and optionally display a message | |
| function check_ok() { |
| #!/usr/local/bin/bash | |
| # Homebrew bash because macOS standard bash is too old for 'wait -n'. | |
| max_jobs=10 | |
| data=`seq 1 20` | |
| # Process to be run in background | |
| function batch_job() { | |
| echo "Starting $1" |
| #!/usr/bin/ruby -w | |
| require 'find' | |
| require 'md5' | |
| dir = ARGV[0] | |
| dir = "." unless dir | |
| digests = {} | |
| Find.find( dir ) do |f| |
| #!/usr/local/bin/python | |
| from collections import defaultdict | |
| import pprint | |
| import sqlite3 | |
| import sys | |
| ADDRESS_DB_FILE = 'Contacts-2016-01-23.abbu/AddressBook-v22.abcddb' | |
| def main(): |
This is the preamble.
| import Data.Char | |
| import qualified Data.String as S | |
| import System.IO | |
| import System.Environment | |
| -- Parses indented text into a tree structure, where each node is represented as a (content, children) tuple | |
| -- Example invocation: | |
| -- echo -e "a\n b\n c\n d\n d2\n e\nf\n g\n h\n i\n j\n k\nl\n" | ./parse_indents | |
| -- a {b, c {d, d2}, e}, f {g {h {i}}, j, k}, l |
| 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 |
| -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() -> |
| -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) -> |