Skip to content

Instantly share code, notes, and snippets.

View alastairmccormack's full-sized avatar

Alastair McCormack alastairmccormack

View GitHub Profile
@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"},
@alastairmccormack
alastairmccormack / chardet_open.py
Last active March 16, 2016 11:11
Encoding detecting Python open() - Automatically detects encoding of existing text files for reading and writing
from chardet.universaldetector import UniversalDetector # pip install chardet
import io
import os.path
def open(file, mode='r', buffering=-1, encoding=None, errors=None,
newline=None, closefd=True):
""" A wrapper for io.open(), which tries to detect the encoding of a file
using chardet before reading or writing
Supports all arguments of io.open(). "encoding" is only used if file does
@alastairmccormack
alastairmccormack / hds_loadtest.py
Created September 4, 2015 09:06
Adobe HDS Load Testing Tool using Locust Framework. See inline for details
# HDS Load Testing Tool using Locust Load Testing Framework and HDS_Fragmenter library
# Simulates user access by fetching the bootstrap file to parse out fragment names.
# Bootstrap files are fetched 1/10 times.
#
# Usage:
# 1. Fetch dependencies given below
# 2. Edit "url_f4m_path" below to the stream-level manifest path/URI
# 3. Run: `locust -f hdslt.py -H http://my_origin_server`
# pip install locustio
@alastairmccormack
alastairmccormack / PKCS12 Cert Expire Check
Created October 19, 2014 00:30
Checks the expiry of a cert from the a PKCS12 file and alerts using tunable warning period
from OpenSSL.crypto import *
import time
import datetime
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="PKCS12/pfx file", metavar="FILE")
parser.add_option("-p", "--password",
@alastairmccormack
alastairmccormack / mp2aspect.py
Created March 4, 2014 21:26
MPEG 2 Transport Stream + MP2 Video DAR Aspect Detector
# An Display aspect ratio (DAR) detector for MPEG 2 Transport Streams with MP2 Video
import array
import logging
import sys
class NullHandler(logging.Handler):
def emit(self, record):
pass