Skip to content

Instantly share code, notes, and snippets.

@mihow
mihow / export_env_file_vars.sh
Created December 19, 2018 00:05
Set environment vars from a file
# 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 December 7, 2018 23:31 — 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)
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 November 8, 2018 00:39
Create temporary migrations when deploying dev from CircleCi
# 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 September 8, 2017 23:37 — forked from awesomebytes/reduce_faces.py
Executing meshlab from commandline reduce faces of a mesh iteratively
#!/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 February 11, 2017 09:08
Refactor from functions to class functions by adding `self` to all function arguments (VIM search and replace command)
# 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 February 4, 2017 07:52 — forked from Zulko/cubes_pyode_vapory.py
3D cubes animation with PyODE and Vapory
"""
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 February 4, 2017 07:52 — forked from Zulko/cubes_pyode_vapory.py
3D cubes animation with PyODE and Vapory
"""
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 April 23, 2024 22:07
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@mihow
mihow / logging_example.py
Last active January 24, 2017 19:44
Basic logging configuration in Python
import logging
logging.basicConfig(format='%(levelname)s:%(message)s')
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
def main():
log.info("Great info")
log.debug("You won't see this")
@mihow
mihow / get-scipy-stack-for-aws-lambda.sh
Created January 29, 2016 02:32
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