Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Awake or Sleeping

Michael Bunsen mihow

💭
Awake or Sleeping
View GitHub Profile
@mihow
mihow / load_dotenv.sh
Last active Nov 29, 2021
Load environment variables from dotenv / .env file in Bash
View load_dotenv.sh
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@mihow
mihow / elasticsearch6_fuzzy.py
Last active Apr 7, 2021
Enable fuzziness for all Elasticsearch plaintext queries in Wagtail
View elasticsearch6_fuzzy.py
"""Elasticsearch backend that enables fuzzy search to all plaintext queries."""
from wagtail.search.backends.elasticsearch6 import (Elasticsearch6SearchBackend,
Elasticsearch6SearchQueryCompiler)
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
mihow / pytorch_utils.py
Last active Nov 5, 2020
Export PyTorch model to TorchScript / JIT format from fastai learner
View pytorch_utils.py
import os
import time
import pathlib
import tarfile
import tempfile
import torch
PROJECT_PATH = pathlib.Path(os.environ.get("PROJECT_PATH", "."))
@mihow
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
mihow / treebeard_migration_utils.py
Created Feb 29, 2020
Add wagtail child page in migrations
View treebeard_migration_utils.py
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.
https://django-treebeard.readthedocs.io/en/latest/api.html#treebeard.models.Node.add_child
@mihow
mihow / general.php
Created Jan 29, 2020
Cast env var to boolean with default value in PHP
View general.php
# https://craftcms.stackexchange.com/questions/13584/devmode-phpdotenv-variable-ignored
'devMode' => filter_var(getenv('DEV_MODE') ?: false, FILTER_VALIDATE_BOOLEAN),
@mihow
mihow / get-scipy-stack-for-aws-lambda.sh
Created Jan 29, 2016
Get the SciPy stack for deployment to AWS Lambda
View get-scipy-stack-for-aws-lambda.sh
#! /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
@mihow
mihow / two_axis_loop.pgm
Last active Oct 19, 2019
Arcus PMX-2ED-SA Program
View two_axis_loop.pgm
HSPD=20000
LSPD=1000
ACC=300
DEC=300
EO=3
WHILE 1 = 1
X50000
Y50000
WAITX
WAITY
@mihow
mihow / clean_lambda_versions.py
Last active Jul 20, 2019
Script for cleaning out old AWS Lambda function versions
View clean_lambda_versions.py
#! /usr/bin/env python3
import json
import boto3
import argparse
import time
lambda_client = boto3.client('lambda')
function_choices = [f['FunctionName'] for f in lambda_client.list_functions()['Functions']]
@mihow
mihow / gist:fe5fcf403a1da12052a4e62d49e05f53
Created Feb 21, 2019
Troubleshooting remote env vars
View gist:fe5fcf403a1da12052a4e62d49e05f53
# Send system env vars
python2 -c "import os, urllib; urllib.urlopen('https://NGROK_URL', data=urllib.urlencode(os.environ))"
# Send all running processes with arguments & env vars for process
# @TODO