Skip to content

Instantly share code, notes, and snippets.

View alastairmccormack's full-sized avatar

Alastair McCormack alastairmccormack

View GitHub Profile

Keybase proof

I hereby claim:

  • I am alastairmccormack on github.
  • I am amccormack (https://keybase.io/amccormack) on keybase.
  • I have a public key ASC5Len8bl7k_nzDIkwtrI-DzOWPrQqLNu2xXCmbKM_czwo

To claim this, I am signing this object:

@alastairmccormack
alastairmccormack / bitbucket_backup.py
Created July 18, 2019 15:33
Bitbucket Backup - Clones all repos for given username or team
# Requires Python 3.6 (for fstrings)
import requests
from git import Repo
import jmespath
import os.path
# Create an app password. Username can be found using: https://stackoverflow.com/a/44932928/1554386
username = ""
password = ""
@alastairmccormack
alastairmccormack / standard_password_encoder.py
Created July 3, 2019 20:06
A Python implementation of Spring Security StandardPasswordEncoder
import hashlib
import binascii
password_salthash_hex = '916b8cb7de146eab16c83ac3e7cdd33751a4cb19dced8da5aab38d94ebebcff968ca5099cfccf28d'
password_salthash = binascii.a2b_hex(password_salthash_hex)
password_hash = password_salthash[8:]
password_salt = password_salthash[:8]
password = b'11111'
@alastairmccormack
alastairmccormack / terraform.tf
Created April 23, 2019 17:41
One-liner Terraform external command to get current branch (No need to create additional script)
# Branch name accessible via: ${data.external.git-branch.result.branch}
data "external" "git-branch" {
program = ["/bin/bash", "-c", "jq -n --arg branch `git rev-parse --abbrev-ref HEAD` '{\"branch\":$branch}'"]
}
@alastairmccormack
alastairmccormack / rsa_verify_output.py
Last active January 16, 2018 11:55
Pycrypto: Raw RSA verify output
# When using raw RSA key calculations, it sometimes necessary to see the
# verification detail created as a result of a .sign() process (or encryption
# using the private key, which Java let's you do!)
# Pycrypto .verify() method only allows you to check a known value, where as
# openssl let's you see the verification response. I.e
# > openssl rsautl -inkey pub_key.pem -raw -verify -pubin -in mysig.txt
# The following code was found by digging into the Pycrypto innards:
@alastairmccormack
alastairmccormack / PEM2X509Certificate.java
Created October 17, 2017 15:42
PEM formatted certificate to java.security.cert.X509Certificate
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.openssl.PEMParser;
import java.security.cert.X509Certificate;
import java.io.FileReader;
import java.io.IOException;
import java.security.cert.CertificateException;
public class PEM2X509Certificate {
@alastairmccormack
alastairmccormack / Uint32.java
Created August 3, 2017 15:55
Java Binary Block Parser (JBBP) unsigned int 32 parser
import com.igormaznitsa.jbbp.JBBPCustomFieldTypeProcessor;
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
import com.igormaznitsa.jbbp.compiler.tokenizer.JBBPFieldTypeParameterContainer;
import com.igormaznitsa.jbbp.io.JBBPBitInputStream;
import com.igormaznitsa.jbbp.io.JBBPBitOrder;
import com.igormaznitsa.jbbp.io.JBBPByteOrder;
import com.igormaznitsa.jbbp.model.*;
import java.io.EOFException;
import java.io.IOException;
@alastairmccormack
alastairmccormack / GetWhereFrom.py
Created July 25, 2017 21:14
Get "where from" information in macOS / OS X for a file
import xattr
import plistlib
x = xattr.xattr('mydownloaded.file')
where_from_plist = x['com.apple.metadata:kMDItemWhereFroms']
where_from = plistlib.loads(where_from_plist)
# list object of URLs. Presumably right most is original URL and left most is the redirected location(s)
print(where_from)
@alastairmccormack
alastairmccormack / text_luhn.py
Created November 14, 2016 13:56
Luhn checkbit creator for text strings - Made Python3 compatible from https://wiki.openmrs.org/display/docs/Check+Digit+Algorithm
# 99.99 based on https://wiki.openmrs.org/display/docs/Check+Digit+Algorithm
def get_checkdigit(id_without_check):
# allowable characters within identifier
valid_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVYWXZ_"
# remove leading or trailing whitespace, convert to uppercase
id_without_checkdigit = id_without_check.strip().upper()
@alastairmccormack
alastairmccormack / presets.json
Last active August 16, 2016 12:06
AWS Elastic Transcode Profiles conforming to Apple's TN2224 Best Practice (Revision: 2016-08-02)
{
"Audio": {"AudioPackingMode": null,
"BitRate": "96",
"Channels": "2",
"Codec": "AAC",
"CodecOptions": {"BitDepth": null,
"BitOrder": null,
"Profile": "AAC-LC",
"Signed": null},
"SampleRate": "48000"},