Skip to content

Instantly share code, notes, and snippets.

View turtlemonvh's full-sized avatar

Timothy turtlemonvh

View GitHub Profile
@turtlemonvh
turtlemonvh / Caddyfile
Last active June 6, 2025 08:17
Multi-host wildcard caddy example
a.myhost.com {
tls off
root /var/www/
proxy / localhost:8091
log log/access.a.log
}
b.myhost.com {
tls off
root /var/www/
@turtlemonvh
turtlemonvh / README.md
Created March 21, 2016 12:32
Pocket bookmarklet
@turtlemonvh
turtlemonvh / build_rpm.sh
Created March 24, 2016 21:37
Building an RPM from a python package on ubuntu
#!/usr/bin/env bash
# Ensure ruby tools needed for FPM are available
apt-get install -y ruby ruby-dev gem rpm
# Ensure FPM is installed
gem install fpm
# Run FPM to build an image
fpm -s python \
@turtlemonvh
turtlemonvh / README.md
Last active March 29, 2016 05:03
Mezzanine template tag for longer post description
@turtlemonvh
turtlemonvh / README.md
Last active November 9, 2022 17:51
Golang Equal JSON Strings

JSON string equality

A little utility for testing if 2 json strings are equal, for use in tests.

Example

go run main.go '{"dog": 5, "cat": 3}' '{"cat":3, "dog": 5}'

Caveats

@turtlemonvh
turtlemonvh / README.md
Last active April 18, 2016 18:51
Print out the structural differences between all json files in a directory (what data paths are present in some and absent in others).

Find structural diffs

A simple script to show the structural differences between json files.

Usage

# Pairwise diffs between all files ending with `.json` in the current directory
python record-template-diffs.py

Pairswise diffs between every file ending in allowed.json in the current directory

@turtlemonvh
turtlemonvh / extract_env_as_dict.py
Created April 29, 2016 16:37
Python one liner to extract env as dict
# If the file you need to source is `.setup-env`
[e.split("=")[0:2] for e in commands.getoutput(". .setup-env && env").split("\n")]
@turtlemonvh
turtlemonvh / README.md
Last active October 8, 2023 23:04
Multi-level arg parse

Multi-level arg parse

Shows how to structure a python app using arg parse that goes down many levels.

The "trick" is to

  • add a subparsers S1[]
  • add parsers P1[] to your subparser S1[x]
  • add a new set of subparsers S2[] to one of those parsers P1[x]
@turtlemonvh
turtlemonvh / README.md
Created August 8, 2016 18:27
Example vagrant file

Example vagrantfile

With ssh config adding, data directory mounted, provision script setup. 2 CPUs and 4 GB of RAM.

Create a setup bash script at provision/setup.sh and it will be run.

@turtlemonvh
turtlemonvh / human_bytes.py
Created October 26, 2016 18:59
Human bytes for python
# Print byte counts in a human-friendly way
def human_bytes(b):
kb = 1024
mb = kb*1024
gb = mb*1024
tb = gb*1024
if b < 1024:
return "%d b" % b