Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathon Reinhart JonathonReinhart

View GitHub Profile
@JonathonReinhart
JonathonReinhart / data.txt
Created Apr 2, 2021
Are multiple MAP_PRIVATE mappings of the same file, in the same process, still private?
View data.txt
0123456789ABCDEF
@JonathonReinhart
JonathonReinhart / google_dns_thing.py
Created Feb 19, 2021
Fetch all Google mail netblocks
View google_dns_thing.py
#!/usr/bin/env python3
import dns.resolver
from ipaddress import IPv4Network, IPv6Network, ip_address
GOOGLE_NETBLOCKS = [
'_netblocks.google.com',
'_netblocks2.google.com',
'_netblocks3.google.com',
]
@JonathonReinhart
JonathonReinhart / .env
Last active Jan 4, 2021
phpdotenv unset variable demo
View .env
# A simple, constant env var
CONST='A constant env var'
# Derived from another variable
DERIV="I came from ${CONST} with some more"
# An environment variable we expect to be set on the outside
EXT_SET=${ENV_EXT_SET}
# An environment variable we expect *not* to be set on the outside
@JonathonReinhart
JonathonReinhart / decrypt-pfsense-config.sh
Created Nov 5, 2020
Decrypt pfSense encrypted config backups
View decrypt-pfsense-config.sh
#!/bin/bash
# Adapted from https://forum.netgate.com/topic/139561
set -o pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $(basename $0) <encrypted-config>"
exit 1
fi
inpath="$1"
tmpout="$(mktemp)"
@JonathonReinhart
JonathonReinhart / docker-compose.yml
Last active Oct 24, 2020
Mysql docker image: Always run initialization scripts
View docker-compose.yml
version: '2'
services:
# MySQL Database
db:
image: mysql:5.6
volumes:
- ./data/mysql:/var/lib/mysql
- ./mysql-entrypoint.sh:/custom-entrypoint.sh:ro
@JonathonReinhart
JonathonReinhart / ANSI.md
Last active Sep 17, 2020 — forked from fnky/ANSI.md
ANSI Escape Codes
View ANSI.md

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1b
  • Decimal: 27
@JonathonReinhart
JonathonReinhart / compatrand.py
Last active Sep 1, 2020
Python 2.7, 3 compatible random seeding
View compatrand.py
from __future__ import print_function
import random
import sys
class CompatibleRandom(random.Random):
# Inspired by https://stackoverflow.com/a/55800424/119527
def seed(self, a):
if sys.version_info >= (3, 2):
super(CompatibleRandom, self).seed(a, version=1)
else:
@JonathonReinhart
JonathonReinhart / ve.sh
Created Aug 18, 2020
Bash function for easy virtualenv activation
View ve.sh
# Put this in your .bashrc or .bash_aliases
# List virtual envs
function list-virtualenvs() {
for d in *; do
if [[ -d "${d}" && -f "${d}/bin/activate" ]]; then
echo "${d}"
fi
done
}
View check_gofmt.sh
#!/bin/bash
PATHS='*.go internal'
# Run from project root
cd "$(dirname "${BASH_SOURCE[0]}")"
output="$(gofmt -l $PATHS)"
if [ ! -z "$output" ]; then
echo -e "The following files are not properly formatted:\n"
@JonathonReinhart
JonathonReinhart / human_size.py
Created Mar 29, 2019
Python human file size
View human_size.py
#!/usr/bin/env/python3
import math
def round_down(n, d=8):
# https://stackoverflow.com/a/43533589/119527
d = 10 ** d
return math.floor(n * d) / d
def human_size(n, decimal_places=2):
n = float(n)