Skip to content

Instantly share code, notes, and snippets.

@matrey
matrey / ec2-create-ubuntu-ami.sh
Created October 15, 2020 05:41
ec2-create-ubuntu-ami.sh
#!/bin/bash
set -euo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Thanks:
# * https://github.com/alestic/alestic-git/blob/master/bin/alestic-git-build-ami for the overall approach and ec2 commands
# * https://github.com/kickstarter/build-ubuntu-ami/blob/master/data/user_data.sh.erb for the user script run in chroot
# * https://blog.tinned-software.net/mount-raw-image-of-entire-disc/ for how to mount the raw image with losetup
@matrey
matrey / ltsv.php
Created April 29, 2018 10:50
Linear TSV encode/decode for PHP
<?php
function ltsv_decode($data){
// From parse_field (https://github.com/solidsnack/tsv/blob/master/tsv.py#L90)
$stack = [];
$replaces = ['t' => "\t", 'n' => "\n", 'r' => "\r", '\\' => "\\"];
$tmp = explode("\\", $data, 2);
while (count($tmp) >= 2){
$stack[] = $tmp[0];
@matrey
matrey / update-multiple
Last active April 29, 2018 10:43
Multiple update hooks for Gitlab
#!/bin/bash
# The standard, global, Gitlab update hook
update_true_path="$(cd `dirname $(readlink $0)` && pwd)"
update_gitlab="$update_true_path/update"
# Additional, local, update.before and update.after hooks
hooks_dir="$(cd `dirname $0` && pwd)"
update_before="$hooks_dir/update.before"
update_after="$hooks_dir/update.after"