Skip to content

Instantly share code, notes, and snippets.

View Riebart's full-sized avatar

Mike Riebart

View GitHub Profile
@Riebart
Riebart / watch_fedex_package.sh
Created March 1, 2020 19:36
Watch a fedex package status via API calls
#!/bin/bash
tracking_number="$1"
while [ true ]
do
date +%FT%T
echo -n "Tracking ${tracking_number} "
curl 'https://www.fedex.com/trackingCal/track' \
-s \
-H 'Connection: keep-alive' \
-H 'Pragma: no-cache' \
@Riebart
Riebart / .bashrc.aws
Created October 26, 2019 01:17
Collection of bashrc contents that makes it a bit easier to work across accounts
#!/bin/bash
# For non-256 colour terminals
#PS1='\[\e]0;\w\a\]\n\[\e[00;35m\]${AWS_PROFILE}$([ "$AWS_PROFILE" == "" ] && echo -n "" || echo -n " ")'
# The default region, if set
PS1=$PS1'\[\033[38;5;92m\]${AWS_DEFAULT_REGION}$([ "$AWS_DEFAULT_REGION" == "" ] || echo -n " ")'
# The AWS profile
PS1=$PS1'\[\e]0;\w\a\]\[\033[38;5;208m\]${AWS_PROFILE}$([ "$AWS_PROFILE" == "" ] || echo -n " ")'
# The existence of environment variables
@Riebart
Riebart / do.js
Created September 19, 2019 17:19
Nodejs script to convert Textract output into a PDF using PDFkit
const fs = require('fs');
let rawdata = fs.readFileSync('/working/out4.json');
let data = JSON.parse(rawdata);
// You'll need to twiddle the dpi, page size, and font size to get your stuff to layout properly.
// Assumes uniform font size in the input.
let dpi = 200;
let width = 17 * dpi;
let height = 11 * dpi;
const PDFDocument = require('pdfkit');
@Riebart
Riebart / get_symlink_file_target.ps1
Created July 17, 2019 17:03
FInd the target of a file reparsepoint (such as those used for binaries in Store apps)
@Riebart
Riebart / ms_store_python.wls
Last active September 2, 2023 04:16
Find all installed Python packages from the Microsoft store, determine install location, and register them as external evalautors.
(* Run this every time the Python from the Store updates, since the binary location encodes the store full version *)
(* Note that Python 3.9 is supported in Mathematica 12.3.1, so the below patches are not relevant on modern versions, but are retained to aid those running older versions from perpetual licenses *)
(* Update to support Mathematica 12, which requires that Python >=3.8 at least reference python3.8.exe, not python.exe. *)
(* Note, python >3.7 is not officially supported in Mathematica 12.0.0, and other notebook interfaces.
Attempts to use it result in a "required field 'type_ignores' missing from module" error
Source: https://mathematica.stackexchange.com/questions/211984/solved-externalevaluatepysys-pycmd-evaluates-to-failure *)
(*
A patch to C:\Program Files\Wolfram Research\Mathematica\12.0\SystemFiles\Links\WolframClientForPython\wolframclient\utils\externalevaluate.py to enable 3.8:
66c66
< exec(compile(ast.Module(expressions, []), '', 'exec'), current)
@Riebart
Riebart / nginx_stream_tls.md
Last active July 16, 2019 21:04
Notes on configuring the nginx stream module to run as a non-root user

nginx Stream Module Config

This will use the nginx SSl stream, and ssl_stream_preread modules

Non-root running of the nginx master process

# chmod 777 /var/run
# mkdir /var/run/nginx
# chown -R www-data:www-data /var/run/nginx
@Riebart
Riebart / pihole_docker.sh
Created July 15, 2019 19:59
Start a PiHole docker container with the appropriate upstream DNS and server IPs autodetected.
#!/bin/bash
docker run --rm -d --name pihole \
-p 53:53/tcp -p 53:53/udp -p 80:80 \
-v /home/pihole/etc/pihole:/etc/pihole/ \
-v /home/pihole/etc/dnsmasq.d:/etc/dnsmasq.d/ \
--dns $(nslookup 1.1.1.1 | \
grep Server: | tr -s '\t' | \
cut -f2) \
-e DNS1=$(nslookup 1.1.1.1 | \
@Riebart
Riebart / wss-iam-listener.py
Last active October 31, 2018 05:06
Python script to listen to an AWS IoT Messaging endpoint, authenticating with IAM, and printing messages as they arrive.
#!/usr/bin/env python3
"""
Provide a simple wrapper for listening to an MQTT stream from an AWS IoT websocket endpoint. Prints messages to stdout.
"""
try:
from urllib.parse import urlparse, urlencode, parse_qs
except ImportError:
from urlparse import urlparse, parse_qs
from urllib import urlencode
@Riebart
Riebart / apigateway-invoke.py
Last active May 30, 2023 12:21
Python script to invoke an AWS API Gateway endpoint that requires IAM authentication. Uses boto for signing the request, and requests for issuing it.
#!/usr/bin/env python3
"""
Provides a simple Python wrapper for invoking an API Gateway endpoint using IAM signed requests.
Example:
python3 apigateway-invoke.py GET \
https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/default/MethodName | jq .
"""
try:
@Riebart
Riebart / script.ps1
Last active October 22, 2021 20:41
Generate code signing certificate and key using Powershell
# Generate a new certificate with key, marked exportable (the default), suitable for code signing.
# The certificate is stored in the personal certificate store.
New-SelfSignedCertificate -Subject "CN={YOUR NAME}" -KeySpec "Signature" -KeyUsage "DigitalSignature" -KeyUsageProperty "Sign" -Friendlyname "Code Signing" -NotAfter $([datetime]::now.AddYears(5)) -Type "CodeSigningCert" -CertStoreLocation cert:\currentuser\my -KeyAlgorithm RSA -Keylength 4096 -HashAlgorithm "SHA256" -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider"
# To Sign a Powershell script with a certificate
# - Find the key, which you can usually do with the thumbprint and knowing where it was stored
# - This may or may not work for you, depending on whether or not you have access to a functioning timestamp server
# - Regardless of the timestamp, the signature will still work, just won't say when it was signed.
$cert = (ls cert:currentuser\my\0BD717BC985949E736067A15CC7502A1EAE6D031)