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
use-sparingly / bitbucket_backup.py
Created Jul 18, 2019
Bitbucket Backup - Clones all repos for given username or team
View bitbucket_backup.py
# 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 = ""
@use-sparingly
use-sparingly / standard_password_encoder.py
Created Jul 3, 2019
A Python implementation of Spring Security StandardPasswordEncoder
View standard_password_encoder.py
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
use-sparingly / terraform.tf
Created Apr 23, 2019
One-liner Terraform external command to get current branch (No need to create additional script)
View terraform.tf
# 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}'"]
}
View keybase.md

Keybase proof

I hereby claim:

  • I am use-sparingly on github.
  • I am amccormack (https://keybase.io/amccormack) on keybase.
  • I have a public key ASC-q_aQ1b4G0hW5kwKkcDfRv67PnGboJxp6jPOQ92MNcgo

To claim this, I am signing this object:

@use-sparingly
use-sparingly / rsa_verify_output.py
Last active Jan 16, 2018
Pycrypto: Raw RSA verify output
View rsa_verify_output.py
# 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
use-sparingly / PEM2X509Certificate.java
Created Oct 17, 2017
PEM formatted certificate to java.security.cert.X509Certificate
View PEM2X509Certificate.java
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 {
@use-sparingly
use-sparingly / Uint32.java
Created Aug 3, 2017
Java Binary Block Parser (JBBP) unsigned int 32 parser
View Uint32.java
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;
@use-sparingly
use-sparingly / GetWhereFrom.py
Created Jul 25, 2017
Get "where from" information in macOS / OS X for a file
View GetWhereFrom.py
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)
@use-sparingly
use-sparingly / text_luhn.py
Created Nov 14, 2016
Luhn checkbit creator for text strings - Made Python3 compatible from https://wiki.openmrs.org/display/docs/Check+Digit+Algorithm
View text_luhn.py
# 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()
@use-sparingly
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.