Skip to content

Instantly share code, notes, and snippets.

View cmbuckley's full-sized avatar

Chris Buckley cmbuckley

View GitHub Profile
@cmbuckley
cmbuckley / p.sh
Last active September 13, 2021 12:53
Use 1Password to copy a password to the clipboard
#!/bin/bash
check_session() {
[ -f $HOME/.op/token ] && export OP_SESSION_my="$(cat $HOME/.op/token)"
# attempt sign in if session is not active
if ! op get account &> /dev/null; then
signin
check_session
fi
}
@cmbuckley
cmbuckley / air-cert-dates.sh
Last active July 27, 2021 12:24
Verify Adobe AIR code signing certificate
#!/bin/bash
# Usage: ./air-cert-dates.sh /path/to/app.air
signatures="$(unzip -p "$1" META-INF/signatures.xml)"
xpath '//Signature[@Id="PackageSignature"]//X509Certificate[1]/text()' <<< "$signatures" 2>/dev/null \
| sed -e $'1s/^/-----BEGIN CERTIFICATE-----\\\n/;$s/$/\\\n-----END CERTIFICATE-----/' \
| openssl x509 -dates -noout \
| sed -e $'1s/^/metric,date\\\n/;s/=/,/'
tell application "Photos"
activate
set folderList to name of every folder
set selectedFolders to choose from list folderList with prompt "Select folders:" with multiple selections allowed
set destination to POSIX path of (choose folder with prompt "Please select a backup location:")
repeat with f in folders
if selectedFolders contains name of f then
my exportFolder(f, destination)
end if
@cmbuckley
cmbuckley / tools.md
Last active February 11, 2021 21:35
Tools I use and sometimes forget the name
<?php
$char = 'イ';
// What's the UTF-8 encoding of this character? (This file is saved in UTF-8)
var_dump(bin2hex($char)); // e382a4
// What does another encoding look like?
// See http://www.fileformat.info/info/unicode/char/30a4/charset_support.htm
var_dump(bin2hex(mb_convert_encoding($char, "EUC-JP", "UTF-8"))); // a5a4
@cmbuckley
cmbuckley / lockdown.json
Last active October 22, 2020 14:16
Match postcode to COVID lockdown key points
{
"E92000001": {
"country_or_area": "England",
"council": 0,
"wards": 0,
"postcodes": 0,
"full_or_partial": "F",
"key_points": "Your area is under Covid restrictions, in the Tier 1 (medium alert) category for England.",
"meeting_friends_and_family": "* You can mix socially in a group of up to six people from multiple households. This includes children and applies indoors and outdoors, including private homes. \n* Socialising in larger groups is against the law, with fines up to £6,400.\n* There are exceptions, for example if your household or support bubble is larger than six, or if someone enters your house to carry out work, registered childcare or care for a vulnerable person.\n",
@cmbuckley
cmbuckley / akamai.sh
Last active June 24, 2020 11:10
Akamai hosts updater
#!/bin/bash
domain=$1
origin="example-origin.net"
file=/etc/hosts
fqdn=
if [ $# -lt 1 ]; then
echo "Usage: $(basename "$0") DOMAIN [{production|staging|origin|off}]" >&2
exit 1
@cmbuckley
cmbuckley / test-old-usertrust.sh
Last active May 31, 2020 18:16
Check for old USERTrust intermediate certificate
#!/bin/bash
# Checks a server certificate chain for old USERTrust intermediate cert,
# which will expire in May 2020.
#
# Possible output:
#
# • Error (e.g. cannot connect to host)
# • Not a Sectigo/Comodo chain (cannot find one of the CAs)
# • New USERTrust root cert found (valid, but superfluous)
@cmbuckley
cmbuckley / update-ufw-github.sh
Created January 20, 2020 12:32
Update UFW with IPs from GitHub
#!/bin/bash
github=$(curl -s https://api.github.com/meta | jq -r '.web | .[]' | sed 's~/32~~' | sort)
ufw=$(ufw status | grep '# GitHub' | awk '{print $1}' | sort)
comm -13 <(echo "$ufw") <(echo "$github") | while read addition; do
echo "Adding $addition"
ufw allow out to $addition port 22 comment GitHub
done