Skip to content

Instantly share code, notes, and snippets.

View pda's full-sized avatar
💾
Formatting…

Paul Annesley pda

💾
Formatting…
View GitHub Profile
@pda
pda / ec2-lvm.sh
Last active August 29, 2015 14:07
For EC2 instances with two instance volumes, use LVM to combine them into a single /mnt
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
set -x
DEVICE_B="/dev/xvdb"
DEVICE_C="/dev/xvdc"
VG_NAME="ephemeral"
LV_NAME="ephemeral"
DEVICE_LV="/dev/$VG_NAME/$LV_NAME"
@pda
pda / base_script.rb
Created June 3, 2014 21:02
BaseScript; small base for CLI scripts; signal handling, indented logging, colors ticks/crosses, injectable args/IO.
# A base class for implementing CLI scripts.
# ARGV and in/out IO's are injected, so can be mocked & tested.
# Basic signal handling by calling exit_on_signals inside work loops etc.
# Requires Ruby 2.0.0+ for keyword args etc.
class BaseScript
EXIT_SUCCESS = 0
INDENT = " "
def initialize(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr)
@pda
pda / git-push-as
Last active November 30, 2020 08:26
git-push-as: pull request without creating branches.
#!/bin/bash -e
# Push local changes on the current branch as a new branch, then
# reset the local branch back to its remote tracking branch.
#
# This enables a fast workflow:
# 10 `git commit` one or more changes to main.
# 20 `git push-as -p new-feature`
# 30 goto 10
@pda
pda / docker-mysql-initialize.sh
Created March 21, 2014 22:09
Docker script to initialize MySQL database; auth from remote hosts.
#!/bin/bash
# Initialize MySQL database.
# ADD this file into the container via Dockerfile.
# Assuming you specify a VOLUME ["/var/lib/mysql"] or `-v /var/lib/mysql` on the `docker run` command…
# Once built, do e.g. `docker run your_image /path/to/docker-mysql-initialize.sh`
# Again, make sure MySQL is persisting data outside the container for this to have any effect.
set -e
set -x
@pda
pda / args.sh
Last active August 29, 2015 13:57
Bash argument grouping
#!/bin/bash
A=("$@")
X="$@"
echo; echo '"$@": <-- correct'
for arg in "$@"; do echo "$arg"; done
echo; echo '"${A[@]}": <-- correct'
for arg in "${A[@]}"; do echo "$arg"; done
@pda
pda / getopts.sh
Created March 5, 2014 02:35
getopts (bash) usage example.
#!/bin/bash
# Example: ./getopts.sh -b world -a hello one two three
# Output: A=hello B=world 1=one 2=two 3=three 4=
while getopts "a:b:" opt; do
case "$opt" in
"a") A="$OPTARG";;
"b") B="$OPTARG";;
esac
@pda
pda / brew-uses-gnutls.txt
Created March 4, 2014 04:15
$ brew uses gnutls | cat
bitlbee
emacs
finch
freediameter
glib-networking
gnu-smalltalk
gst-plugins-bad
gwenhywfar
hamsterdb
inspircd
@pda
pda / lircd.conf
Created January 4, 2014 05:35
LIRC config for my Apple Remote (aluminum) on Raspberry Pi / RaspBMC via one of these IR receivers: http://www.ebay.com/itm/121156693642?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Sat Dec 7 19:14:59 2013
#
# contributed by
#
# brand: lirc-pda.conf
# model no. of remote control:
@pda
pda / 0_cause.rb
Created January 3, 2014 23:19
Recursively inspect Exception#cause to trace where the error condition originated.
name = ->(i){ "method_#{i}" }
methods = 10.times.map do |i|
define_method(name[i]) do
if i == 0
raise "Top level error from #{name[i]}"
else
begin
send name[i - 1]
rescue
raise "Error from rescue in #{name[i]}"
@pda
pda / heroku-postgres-migrate.sh
Last active December 25, 2015 01:39
Shell script to migrate between Heroku Postgres databases via pgbackups.
#!/usr/bin/env zsh
# Migrate data between Heroku Postgres databases via pgbackups.
# This involves downtime via `heroku maintenance:on`.
#
# To migrate example-app to HEROKU_POSTGRESQL_COLOR:
# heroku-postgres-migrate.sh <example-app> <HEROKU_POSTGRESQL_COLOR>
#
# To exit maintenance mode (in case something dies half-way):
# heroku-postgres-migrate.sh --wake