Skip to content

Instantly share code, notes, and snippets.

@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
@mihow
mihow / remove_named_docker_volume.sh
Last active Jan 28, 2019
Remove named docker volume in docker-compose project
View remove_named_docker_volume.sh
#! /bin/sh
set -e
DOCKER_COMPOSE_SERVICE_NAME=db
CONTAINER_ID=`docker-compose ps -q $DOCKER_COMPOSE_SERVICE_NAME`
FULL_VOLUME_NAME=`docker inspect --format='{{range .Mounts}}{{.Name}} {{end}}' $CONTAINER_ID`
docker volume rm $FULL_VOLUME_NAME
@mihow
mihow / test_url_with_exit_code.sh
Last active Jan 15, 2019
Test a URL in bash script and exit on failure or return failure exit code.
View test_url_with_exit_code.sh
#! /bin/bash
set -o errexit
curl --fail --show-error --location http://httpbin.org/status/200 > /dev/null
echo "It worked!"
curl --fail --show-error --location http://httpbin.org/status/500 > /dev/null
echo "It failed, but you will never see this message."
@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 / 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}