Skip to content

Instantly share code, notes, and snippets.


Leland Batey lelandbatey

View GitHub Profile
lelandbatey /
Last active Mar 1, 2021
MongoDB, Motor, Tornado web server, all in Python; for testing
# In order to test an upgrade from Motor 1.x to Motor 2.1, we want to have
# automated tests verifying our existing MongoDB scaffolding isn't using any of
# the deprecated/removed features of PyMongo/Motor. Since Python is dynamic,
# and Motor is ESPECIALLY dynamic, using simple static analysis (such as with
# Vulture) can't give us accurate results. So instead, we must write unit tests
# which exercise the methods of common_python.mongo.Client, and by exercising
# them, verify that the fields/methods of the underlying MotorClient are being
# called correctly.
# However, we also want our unit tests to be _truly_ idempotent AND to test
lelandbatey /
Last active Feb 8, 2021 — forked from mrbar42/
bash scripts to create VOD HLS stream with ffmpeg almighty (tested on Linux and OS X)


bash beach.mkv

will produce:

      |- playlist.m3u8
      |- 360p.m3u8
lelandbatey /
Last active Jan 16, 2021
Pretty print large base 10 numbers and base 2 numbers
# Take a very large number and pretty print it in triplets of 3 digits, each triplet separated by a space.
def pnum_spc(n): print(' '.join([''.join(list(str(n))[::-1][i:i+3]) for i in range(0, len(str(n)), 3)][::-1]))
# >>> pnum_spc(32 ** 13)
# 36 893 488 147 419 103 232
# Print numbers as 32-bit binary numbers w/ spaces giving 4-bit words
def pbin_spc(n): print(' '.join([''.join(list(f'{n:032b}')[::-1][i:i+4][::-1]) for i in range(0, len(f'{n:032b}'), 4)][::-1]))
# >>> "{0:032b}".format(1234)
# '00000000000000000000010011010010'
# >>> pbin_spc(1234)
lelandbatey /
Created Sep 15, 2020
Refresh local AWS creds via Jumpcloud OTP
# This script runs the entire set of steps to authenticate with jumpcloud and
# refresh the temporarily stored AWS credentials.
cd "$HOME/Documents/jumpcloud_mfa/"
# Yes, the local OTP credentials on disk are encrypted with just the username of my user.
( (sleep 0.3; pkill -f "./ jumpcloud") & echo "$USER" | ./ jumpcloud-totp)
# puts the current otp in my clipboard, so we get it into a variable using xclip
lelandbatey /
Last active Mar 14, 2020
Show what cards you could be holding up in MTGA
import itertools
import json
Show the cards you could be holding up in MTGA at instant speed.
1. Make it color sensitive
2. Account for cards with flash
3. Make a UI (like at ALL)
lelandbatey /
Created Feb 5, 2020
Python class for tracking access to members of collections. Great for legacy code were we wonder "what's being accessed in this big dict and where is it being accessed?"
from __future__ import print_function
import inspect
import six
def fmt_stack(frames):
s = ""
for f in frames[::-1]:
s += "{}:{}: {}\n".format(f[1], f[2], '\\n'.join([x.replace('\n', '') for x in f[4]]))
return s
lelandbatey /
Last active Jul 27, 2020
A tool for viewing streams of timestamps as histograms. Uses Matplotlib and Pandas
#!/usr/bin/env python3
A tool for viewing streams of timestamps as histograms.
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib.dates as mdates
import pandas as pd
import itertools
import argparse
lelandbatey /
Created Oct 15, 2019
Read and process MTGA log events
import json
def arena_card_db():
carddb = dict()
with open("AllCards.json", 'r') as mtgjsonf:
carddb = json.load(mtgjsonf)
arena_cards = list()
for card_name, card in carddb.items():
lelandbatey / sane_text_formatter.go
Created Oct 1, 2019
Sane text formatter. Formats text in a 'nice' way, though very basic.
View sane_text_formatter.go
package main
import (
lelandbatey / json_schema_stats
Last active Jul 12, 2019
A tool for examining statistics about JSON object structures. A great way to examine documents in a MongoDB collection for consistency.
View json_schema_stats
#! /usr/bin/env python3
# Downloaded from here:
from collections import Sequence
from operator import itemgetter
from codecs import escape_encode
import argparse
import json
import math
import sys