Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Awake or Sleeping

Michael Bunsen mihow

💭
Awake or Sleeping
View GitHub Profile
@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 / auto_watch_releases_only.js
Created Jan 7, 2019
Change watch settings in Github to release-only in bulk
View auto_watch_releases_only.js
// By jonashaag https://github.com/isaacs/github/issues/410#issuecomment-442248565
const child_process = require('child_process')
const puppeteer = require('puppeteer')
const devices = require('puppeteer/DeviceDescriptors')
const iPhone = devices['iPhone 6']
const USER = 'youruser'
const PW = 'xxxxxx'
@mihow
mihow / export_env_file_vars.sh
Created Dec 19, 2018
Set environment vars from a file
View export_env_file_vars.sh
# Ignores commented out lines and handles spaces
# https://stackoverflow.com/questions/19331497/set-environment-variables-from-file-of-key-pair-values
export $(grep -v '^#' .env | xargs -d '\n')
@mihow
mihow / fix_database_to_utf8.py
Created Dec 7, 2018 — forked from miratcan/fix_database_to_utf8.py
Small python script that converts character sets to utf8 in all databases and tables. My solution for "Illegal mix of collations" errors. (http://stackoverflow.com/questions/3029321/how-to-solve-illegal-mix-of-collations-in-mysql)
View fix_database_to_utf8.py
from MySQLdb import connect
conn = connect(user="[USER]", passwd= "[PASSWORD]")
cur = conn.cursor()
cur.execute("show databases;")
dbs_to_update = filter(
lambda db: db not in ('information_schema', 'mysql', 'performance_schema'),
[dbname[0] for dbname in cur.fetchall()])
@mihow
mihow / config.yml
Created Nov 8, 2018
Create temporary migrations when deploying dev from CircleCi
View config.yml
# Dev only:
# Create migrations for any model changes that don't have migrations committed yet.
# Makes the migrations locally and push them up since we can't write files outside /tmp in Lambda
if [[ "${CIRCLE_BRANCH}" == "dev" ]]
then
python manage.py makemigrations --name ${CIRCLE_BRANCH}_`date "+%Y%m%d-%H%M%S"` --settings=app.settings.production
fi
zappa update -s config/zappa_settings.json ${CIRCLE_BRANCH}
@mihow
mihow / reduce_faces.py
Created Sep 8, 2017 — forked from awesomebytes/reduce_faces.py
Executing meshlab from commandline reduce faces of a mesh iteratively
View reduce_faces.py
#!/usr/bin/env python
import sys
import os
import subprocess
# Script taken from doing the needed operation
# (Filters > Remeshing, Simplification and Reconstruction >
# Quadric Edge Collapse Decimation, with parameters:
# 0.9 percentage reduction (10%), 0.3 Quality threshold (70%)
@mihow
mihow / python_file.vim
Last active Feb 11, 2017
Refactor from functions to class functions by adding `self` to all function arguments (VIM search and replace command)
View python_file.vim
# For functions with existing arguments
:%s/def \(.\+\)(\(.\+\)):/def \1(self, \2):/
# For functions with no arguments
:%s/def \(.\+\)():/def \1(self):/
@mihow
mihow / cubes_pyode_vapory.py
Created Feb 4, 2017 — forked from Zulko/cubes_pyode_vapory.py
3D cubes animation with PyODE and Vapory
View cubes_pyode_vapory.py
"""
Physics simulation with PyODE followed by a (basic) rendering with Vapory
See the result here: http://i.imgur.com/TdhxwGz.gifv
Zulko 2014
This script is placed in the Public Domain (Licence Creative Commons 0)
"""
@mihow
mihow / cubes_pyode_vapory.py
Created Feb 4, 2017 — forked from Zulko/cubes_pyode_vapory.py
3D cubes animation with PyODE and Vapory
View cubes_pyode_vapory.py
"""
Physics simulation with PyODE followed by a (basic) rendering with Vapory
See the result here: http://i.imgur.com/TdhxwGz.gifv
Zulko 2014
This script is placed in the Public Domain (Licence Creative Commons 0)
"""
@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