Skip to content

Instantly share code, notes, and snippets.

mihow /
Created March 14, 2023 01:16
Send a GET request as a POST to overcome 414 Request-URI Too Large
# Submit a "GET" request via POST so we can send
# more data than fits in a URL
resp =
headers = {'X-HTTP-Method-Override': 'GET'},
mihow /
Last active February 4, 2023 00:08
Bash Parallel File Download
# bash ./ url_list.txt
set -o nounset
set -o errexit
mihow / get_table_sizes.sql
Created January 28, 2023 00:11
PostgreSQL - Get size of all tables
View get_table_sizes.sql
SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS index
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS table
SELECT *, total_bytes-index_bytes-coalesce(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS table_name
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
mihow /
Last active August 23, 2022 00:06
Example python logging configs
This works when running code as script, module and with doctests.
Also sets the log level for imported packages like requests.
python -m mymodule.myfile
python mymodule/
python -m unittest mymodule/
import logging
mihow /
Last active July 8, 2022 00:07
Install Docker on Ubuntu (Tested on 20.04 LTS Focal)
#! /bin/bash
set -o errexit
set -o nounset
set -o xtrace
curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
mihow /
Last active January 26, 2022 03:53
Using SSH agent forwarding & bastion server / jump box
# Start SSH agent
eval $(ssh-agent)
# Add specific key
ssh-add ~/.ssh/butterfly.pem
# Add default key (if needed for GitHub, etc)
# SSH config entries
mihow /
Last active January 23, 2022 03:45
PyTorch model to JIT / TorchScript
import os
import time
import pathlib
import tarfile
import tempfile
import torch
PROJECT_PATH = pathlib.Path(os.environ.get("PROJECT_PATH", "."))
mihow / nginx.conf
Created May 3, 2020 01:45
Multi RTMP proxy
View nginx.conf
worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
server {
listen 1935;
listen [::]:1935 ipv6only=on;
application live {
live on;
mihow /
Created February 29, 2020 04:54
Add wagtail child page in migrations
def add_child_page(parent_page, instance):
Mimic the behavior of the "add_child" from Django treebeard.
We can't use `parent_page.add_child(instance=child_page)` inside of
migrations because historical models don't have access to class
methods. This replicates the behavior of `add_child` by calculating
the treebeard path, path depth and url path.
mihow / general.php
Created January 29, 2020 01:08
Cast env var to boolean with default value in PHP
View general.php
'devMode' => filter_var(getenv('DEV_MODE') ?: false, FILTER_VALIDATE_BOOLEAN),