Skip to content

Instantly share code, notes, and snippets.

Alastair McCormack use-sparingly

Block or report user

Report or block use-sparingly

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
use-sparingly /
Created Jul 18, 2019
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:
username = ""
password = ""
use-sparingly /
Created Jul 3, 2019
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'
use-sparingly /
Created Apr 23, 2019
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}'"]

Keybase proof

I hereby claim:

  • I am use-sparingly on github.
  • I am amccormack ( on keybase.
  • I have a public key ASC-q_aQ1b4G0hW5kwKkcDfRv67PnGboJxp6jPOQ92MNcgo

To claim this, I am signing this object:

use-sparingly /
Last active Jan 16, 2018
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:
use-sparingly /
Created Oct 17, 2017
PEM formatted certificate to
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.openssl.PEMParser;
public class PEM2X509Certificate {
use-sparingly /
Created Aug 3, 2017
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.model.*;
use-sparingly /
Created Jul 25, 2017
Get "where from" information in macOS / OS X for a file
import xattr
import plistlib
x = xattr.xattr('mydownloaded.file')
where_from_plist = x['']
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)
use-sparingly /
Created Nov 14, 2016
Luhn checkbit creator for text strings - Made Python3 compatible from
# 99.99 based on
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()
use-sparingly / presets.json
Last active Aug 16, 2016
AWS Elastic Transcode Profiles conforming to Apple's TN2224 Best Practice (Revision: 2016-08-02)
View presets.json
"Audio": {"AudioPackingMode": null,
"BitRate": "96",
"Channels": "2",
"Codec": "AAC",
"CodecOptions": {"BitDepth": null,
"BitOrder": null,
"Profile": "AAC-LC",
"Signed": null},
"SampleRate": "48000"},
You can’t perform that action at this time.