Skip to content

Instantly share code, notes, and snippets.

View jhallard's full-sized avatar
🏠
Working from home

John Allard jhallard

🏠
Working from home
View GitHub Profile
@jhallard
jhallard / benford_distribution_checker.py
Last active November 5, 2020 20:18
Detroit Benford Distribution Checker
#!/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 November 18, 2019 22:21
bUsINeSS JoHN - take a string and print all combinations of upper/lower case letters in the string to stdout
#!/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 August 22, 2018 22:38
JSON description of the most popular licenses for public datasets and their respective legal ramifications
{
"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 June 22, 2018 22:56
Visualize the motion vectors in an h264 encoded video using ffmpeg and vlc (works on OSX)
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 June 22, 2018 22:48
Show the keyframe indices in a video using ffprobe
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 June 22, 2018 22:45
Show an R,G,B color from the terminal using python and PIL
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 June 22, 2018 22:42
Get the format and encoding information for a video in json format from ffprobe
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 June 22, 2018 22:40
How to encode a gif from a video file using ffmpeg at a specific resolution and bitrate
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 June 22, 2018 19:10
Bash function to concatenate all mp4 video file into a single mp4 file at /tmp/concat
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 June 1, 2017 20:34
A simple python script to "mockify" a series of words given either through sys.argv or stdin.
#!/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