Skip to content

Instantly share code, notes, and snippets.


Cole Tierney putnamhill

View GitHub Profile
View git-init-remote
# create remote origin and push
ssh "$remote_host" "test -d $remote_repo_path || exit 1" || \
ssh "$remote_host" "git init --bare $remote_repo_path"
putnamhill /
Last active Apr 20, 2021
parse firewall rules with xslt

parse firewall rules with xslt

to run

xsltproc firewall.xsl source.xml

to test with bash

diff --report-identical-files <(xsltproc firewall.xsl source.xml) expect

Git current branch

The shell used in the following examples is bash, but the commands can be adapted for other shells.

reading it

Determine if working in a git repository

The goal here is to have a performant way to determine if we are in a git repo without printing anything.

git status --porcelain --untracked-files=no &>/dev/null && \
putnamhill / ics2stdout.awk
Created Feb 23, 2019
an awk script to convert Apple's reminder lists to plain text
View ics2stdout.awk
#!/usr/bin/env awk -f
FS = ":"
RS = "\r\n"
OFS = "\t"
my_status = ""
putnamhill /
Last active May 17, 2021
Steps to attach a dmg disk image using hdiutil while capturing the mount point and dev entry for detaching when done
# use process redirection to capture the mount point and dev entry
IFS=$'\n' read -rd '\n' mount_point dev_entry < <(
# mount the diskimage (leave out -readonly if making changes to the file system)
hdiutil attach -readonly -plist "$dmg_path" | \
putnamhill /
Last active Jan 11, 2018
Print items of in-list that are not in other-list; i.e. the relative complement of in-list and other-list.
#!/usr/bin/perl -w
use Getopt::Long;
# use diagnostics;
sub usage {
my $name = $0;
$name =~ s/.*\///;
print <<EOT;
Usage: $name [options] in-list other-list
putnamhill /
Created Nov 19, 2017
Reads the coinmarketcap ticker and writes the prices for a cryptocoins to a file
get_data() {
# if the parameter is a local file just cat it (for testing) otherwise try curl
{ test -r "$1" && cat "$1" || curl -s "$1"; } | \
jq --raw-output \
'.[] | "\(.symbol | ascii_downcase) \(.price_usd)"'
process() {
putnamhill /
Last active Dec 14, 2017
Steps to create a bare git repo
## setting up a personal git repository that you can push change sets to
## ssh-host: a host defined in ~/.ssh/config (see: ssh_config(5))
## camaro: the name of the repo
# on a remote host or local filesystem:
git init --bare camaro.git # (option: use --shared if there are other contributors)
# on local host cd to camaro directory:
git remote add origin ssh-host:[path/]camaro.git
# (for origin on local filesystem: git remote add origin file:///media/volume-name/camaro.git)
putnamhill /
Last active Jan 13, 2018
collection of miscellaneous jq snippets
# print value pairs from an array in lower case
jq --raw-output '.[] | "\(.key_1 | ascii_downcase) \(.key_2 | ascii_downcase)"'
# convert `key=value` lines into `{"key":"value"}` json
jq --raw-input 'split("=") | {(.[0]):.[1]}' some.conf | jq --slurp 'add'
# validate json (bad)
echo '{hello: "there"}' | jq . >/dev/null 2>&1 && echo good json || echo bad json
bad json
putnamhill /
Last active Dec 14, 2017
Reads ip addresses from the command line or stdin and prints them if they belong to any of the three RFC1918 private address blocks
#!/usr/bin/perl -w
use Net::CIDR;
use Getopt::Long;
# Net::CIDR one liner:
# perl -mNet::CIDR -ne 'print if Net::CIDR::cidrlookup($_, ("", "", ""))'
# TODO: add ip address validation