Skip to content

Instantly share code, notes, and snippets.

Awake or Sleeping

Michael Bunsen mihow

Awake or Sleeping
View GitHub Profile
mihow /
Last active Aug 7, 2022
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
export $(cat .env | xargs)
mihow /
Last active Jul 8, 2022
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 Mar 1, 2022
Import existing PEM file as EC2 Key Pair with boto3 & paramiko
import os
import base64
import struct
import boto3
import paramiko
from paramiko.util import deflate_long
PEM_FILEPATH = '~/.ssh/test-key.pem'
mihow /
Last active Jan 26, 2022
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 Jan 23, 2022
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 /
Last active Apr 7, 2021
Enable fuzziness for all Elasticsearch plaintext queries in Wagtail
"""Elasticsearch backend that enables fuzzy search to all plaintext queries."""
from import (Elasticsearch6SearchBackend,
class ElasticsearchQueryCompilerWithFuzziness(Elasticsearch6SearchQueryCompiler):
Copy of Elasticsearch6SearchQueryCompiler class with a modified default query.
Adds the "fuzziness" parameter to all queries so that we can return inexact
matches for misspellings, etc.
mihow / nginx.conf
Created May 3, 2020
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 Feb 29, 2020
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 Jan 29, 2020
Cast env var to boolean with default value in PHP
View general.php
'devMode' => filter_var(getenv('DEV_MODE') ?: false, FILTER_VALIDATE_BOOLEAN),
mihow /
Created Jan 29, 2016
Get the SciPy stack for deployment to AWS Lambda
#! /usr/bin/env bash
# Install the SciPy stack on Amazon Linux and prepare it for AWS Lambda
yum -y update
yum -y groupinstall "Development Tools"
yum -y install blas --enablerepo=epel
yum -y install lapack --enablerepo=epel
yum -y install atlas-sse3-devel --enablerepo=epel
yum -y install Cython --enablerepo=epel