Skip to content

Instantly share code, notes, and snippets.

View peacefixation's full-sized avatar

Matt Jarvis peacefixation

  • Melbourne, Australia
View GitHub Profile
@peacefixation
peacefixation / .curlrc
Last active March 27, 2019 01:51
Curl configuration
# add a new line to the end of each curl response
-w "\n"
@peacefixation
peacefixation / install-osx-high-sierra-command-line.sh
Last active September 28, 2025 09:06
Install OS X High Sierra without converting to APFS file system
# create a USB installer
# https://support.apple.com/en-au/HT201372
Download the OS X High Sierra installer via the App Store, it will be installed into the /Applications directory
If it opens automatically, close it
Insert a USB stick (8GB+)
Run the following command where MyVolume is the name of the USB volume:
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume
# boot the USB installer
@peacefixation
peacefixation / create-osx-package.sh
Last active February 6, 2019 04:40
Create OS X package with preinstall and postinstall scripts
#!/bin/bash
##
# Create the directory skeleton for a new package and a Makefile to build it
##
if [ "$#" -ne 1 ]; then
echo "Usage: $0 \"package name\""
exit 1
fi
@peacefixation
peacefixation / .gitconfig
Last active December 3, 2025 22:27
Git cheat sheet
# ...
[alias]
cm = commit -m
co = checkout
cof = "!checkout_fzf() { \
local branches branch; \
branches=$(git --no-pager branch | grep -v HEAD | sed 's/.* //' | sed 's/release.*//' | grep -v '^$' | sort -u) && \
branch=$(echo \"$branches\" | fzf +m) && \
git checkout $branch; \
@peacefixation
peacefixation / download.js
Last active March 27, 2019 01:40
Download the contents of a HTML element
var downloadButton = document.getElementById('downloadButton');
downloadButton.addEventListener('click', function () {
var contents = document.getElementById('someDiv').innerHTML;
if (contents.length = 0) {
return;
}
var filename = 'some-filename.txt';
@peacefixation
peacefixation / save-email-attachment.php
Last active March 27, 2019 01:40
Save email attachment with mailparse
#!/usr/bin/php
<?php
// create a resource
$parsed = mailparse_msg_create();
// read the mime-encoded email file from stdin
$email = file_get_contents('php://stdin');
// parse the mime-encoded email
mailparse_msg_parse($parsed, $email);
$structure = mailparse_msg_get_structure($parsed);
@peacefixation
peacefixation / find-replace.sh
Last active March 27, 2019 01:40
Find files containing text and replace the text
find /some/path -type f -exec grep 'find this text' -l {} \; -exec sed -i '' 's/find this text/replace with this text/g' {} \;
@peacefixation
peacefixation / find-active-user.sh
Last active March 27, 2019 01:39
Find the active user by checking /dev/console
# format the output of stat and show the active user (as a string)
stat -f "%Su" /dev/console
@peacefixation
peacefixation / clean-asterisk-db.sh
Last active March 27, 2019 01:39
Remove keys from Asterisk database
# remove each family of keys that match the specified pattern from the Asterisk database
# 4 digits
FAMILY_PATTERN="[0-9][0-9][0-9][0-9]"
for FAMILY in `asterisk -rx "database show" | cut -d' ' -f1 | egrep -a "/${FAMILY_PATTERN}/" | cut -d'/' -f2 | uniq`; do
asterisk -rx "database deltree ${FAMILY}";
done
@peacefixation
peacefixation / ssh-agent-forward.sh
Last active March 27, 2019 01:39
Forward SSH agent to remote host
# https://www.ssh.com/ssh/agent
# https://developer.github.com/v3/guides/using-ssh-agent-forwarding/#setting-up-ssh-agent-forwarding
# on the remote host
# /etc/ssh/sshd_config must have 'AllowAgentForwarding yes'
# on your local machine
# /etc/ssh/ssh_config must have 'ForwardAgent yes'
cat >> ~/.ssh/config <<EOF