Skip to content

Instantly share code, notes, and snippets.

@breenie
breenie / glacier.sh
Last active February 2, 2018 05:01
AWS Glacier uploader
#!/bin/bash
#
# This script takes a path to a file and uploads it to Amazon
# Glacier. It does this in several steps:
#
# 1. Split the file up into 1MiB chunks.
# 2. Initiate a multipart upload.
# 3. Upload each part individually.
# 4. Calculate the file's tree hash and finish the upload.
#
@breenie
breenie / download-rackspace-bucket.sh
Created July 27, 2017 11:49
Downloads all files from a rackspace bucket
#!/usr/bin/env bash
container=${1}
meta() {
local container=$1
local file="${PWD}/${container}.txt"
local META=" "
cat /dev/null > "${file}"
@breenie
breenie / gist:5f91e2cd39fa1e42024db1c2c79b2821
Created July 11, 2017 11:44
Repairing RAID 1 partitions
#!/usr/bin/env bash
pi@raspberrypi:~ $ sudo mdadm --create /dev/md2 --metadata=0.90 --raid-devices=2 --level=raid1 /dev/sda5 missing
mdadm: /dev/sda5 appears to be part of a raid array:
level=raid1 devices=2 ctime=Wed Feb 16 00:00:17 2011
Continue creating array? y
mdadm: array /dev/md2 started.
pi@raspberrypi:~ $ sudo mdadm --examine /dev/sda5
/dev/sda5:
Magic : a92b4efc
@breenie
breenie / filter-bool.php
Created May 3, 2017 14:56
Convert a value to a bool or null on failure
<?php
filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
@breenie
breenie / fingerprint.sh
Created April 4, 2017 08:48
Get SSH key fingerprint
# Using MD5...
ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub
# Or not...
ssh-keygen -lf ~/.ssh/id_rsa.pub
@breenie
breenie / gist:6ae19294652606070f6256b47a969ace
Created March 16, 2017 10:23
Trim quotes from a string
sed -e 's/^"//' -e 's/"$//'
@breenie
breenie / gist:34a692867df1653d28ec5b950fadf0dc
Created March 16, 2017 10:21
jq find node by child value
jq -r '.data[] | select(.thing.key == "value") | .thing.value_you_want'
@breenie
breenie / file-extension.php
Created February 7, 2017 12:02
PHP get file extension
<?php
substr(strrchr($filename, '.'), 1);
#!/bin/sh
INSTANCE_NAME=bingo
aws ec2 describe-instances --filter Name=tag:Name,Values=${INSTANCE_NAME} --query Reservations[].Instances[].PrivateDnsName
@breenie
breenie / strip-definer.sh
Last active August 9, 2016 10:22
Strip MySQL definer from dump files
#!/bin/sh
# Strip deinfers in comments
sed -ie 's/\/\*[^*]*DEFINER=[^*]*\*\///' path/to/file.sql
# Strip all definers
sed -i 's/DEFINER=`[^`]*`@`[^`]*`//' path/to/file.sql