Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

John Allard jhallard

🏠
Working from home
View GitHub Profile
@jhallard
jhallard / benford_distribution_checker.py
Last active Nov 5, 2020
Detroit Benford Distribution Checker
View benford_distribution_checker.py
#!/usr/bin/env python3
"""
Download the Detroit precinct reporting data from here:
https://election-county-reports-prod112020.s3.amazonaws.com/4539283c-3f09-4fdf-ad93-0bfd82d32be1/c64f9ade-9049-43ef-ab73-3feebc7ef5f0/Results%20per%20Precinct%20Data%20report.pdf
save it to /tmp/data.txt and this will anlayze the dem/repub reported vote counts and show their benford distribution
"""
data = open('/tmp/data.txt').readlines()
@jhallard
jhallard / business_john.py
Last active Nov 18, 2019
bUsINeSS JoHN - take a string and print all combinations of upper/lower case letters in the string to stdout
View business_john.py
#!/usr/bin/env python
"""
This is a dumb script and isn't too well written. The entire point is to take a string
like "business john" and print all combinations of upper/lower case letters for all
alpha characters in the string, e.g.
bUsiNEsS joHn
BuSInEsS JoHn
...
@jhallard
jhallard / dataset_licenses.json
Created Aug 22, 2018
JSON description of the most popular licenses for public datasets and their respective legal ramifications
View dataset_licenses.json
{
"Public Domain": {
"license_name": "Public Domain",
"license_full_name": "Public Domain Mark",
"license_text_url": "https://creativecommons.org/choose/mark/",
"license_attributes": {
"public_domain": true,
"required_attribution_upon_sharing": false,
"requires_share_alike": false,
"commercially_available": true,
@jhallard
jhallard / vis_motion_vectors.sh
Created Jun 22, 2018
Visualize the motion vectors in an h264 encoded video using ffmpeg and vlc (works on OSX)
View vis_motion_vectors.sh
vis_motion_vectors ()
{
if [ "$#" -lt 1 ]; then
echo "Need an input file";
return 1;
else
ffmpeg -y -loglevel error -flags2 +export_mvs -i "$1" -vf codecview=mv=pf+bf+bb /tmp/motion_vectors.mp4;
case "$(uname -s)" in
Linux*) vlc /tmp/motion_vectors.mp4;;
Darwin*) open /tmp/motion_vectors.mp4 -a vlc;;
@jhallard
jhallard / showkeyframes.sh
Created Jun 22, 2018
Show the keyframe indices in a video using ffprobe
View showkeyframes.sh
show_keyframes() {
ffprobe -loglevel error -select_streams v -show_frames -show_entries frame=pict_type -of csv $1 | grep -n I | cut -d ':' -f 1
}
# use like
# $ show_keyframes /tmp/video.mp4
# 1
# 31
# 61
# 91
@jhallard
jhallard / showcolor.sh
Created Jun 22, 2018
Show an R,G,B color from the terminal using python and PIL
View showcolor.sh
showcolor () {
if [ "$#" -lt 3 ]; then
echo "need to give 3 (r,g,b) values"
return 1
fi
python -c "from PIL import Image; Image.new('RGB', (300, 300), ($1, $2, $3)).show()"
}
# use like
# $ showcolor 125 125 200
@jhallard
jhallard / get_format_info.sh
Created Jun 22, 2018
Get the format and encoding information for a video in json format from ffprobe
View get_format_info.sh
get_format_info ()
{
ffprobe -v error -select_streams v:0 -show_entries stream -of default=noprint_wrappers=1 -print_format json "$1"
}
# use like get_format_info /tmp/video.mp4
# $ get_format_info /tmp/video.mp4
{
"programs": [
@jhallard
jhallard / gifencode.sh
Created Jun 22, 2018
How to encode a gif from a video file using ffmpeg at a specific resolution and bitrate
View gifencode.sh
gifenc ()
{
palette="/tmp/palette.png";
filters="fps=$4,scale=$3:-1:flags=lanczos";
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette;
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
}
# use like this to encode /tmp/video.mp4 to /tmp/output.gif at 240p and 12fps
# $ gifenc /tmp/video.mp4 /tmp/output.gif 240 12
@jhallard
jhallard / ffconcat.sh
Created Jun 22, 2018
Bash function to concatenate all mp4 video file into a single mp4 file at /tmp/concat
View ffconcat.sh
function vidconcat {
TEMP=$(mktemp /tmp/temporary-file.XXXXXXXX)
for file in "$@"
do
echo "file '$file'" >> $TEMP
done
ffmpeg -loglevel error -hide_banner -f concat -safe 0 -i $TEMP -c copy /tmp/concat.mp4
echo "concat video file is at /tmp/concat.mp4"
rm -f $TEMP
}
@jhallard
jhallard / mockify.py
Created Jun 1, 2017
A simple python script to "mockify" a series of words given either through sys.argv or stdin.
View mockify.py
#!/usr/bin/env python
import sys
import os
import random
def mockify_word(word):
last_cap = False
letters = list(word)
for index in range(0, len(letters)):
upper_chance = 1