Skip to content

Instantly share code, notes, and snippets.

View mikecharles's full-sized avatar

Mike Charles mikecharles

View GitHub Profile
@mikecharles
mikecharles / cdf-correction.ipynb
Last active August 29, 2015 14:26
CDF correction
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mikecharles
mikecharles / MANIFEST.in
Last active October 26, 2015 21:04
Cut a release of a Python package - updates a VERSION file, makes a git commit and tag, and uploads the updated package to a PyPI repository
include VERSION
@mikecharles
mikecharles / README.md
Last active December 11, 2015 15:40
Execute a function in Python when the main application is finished running

When driver.py finishes running, email.send_email() is executed. This is because in the driver, it is registered in the atexit module:

import atexit
atexit.register(send_email)

which means that when the driver is finished and is about to exit, the send_email() function will be the last thing that runs. In this example send_email() simply prints that it's sending an email, but this is where you should actually email report_obj out.

See this script in action.

@mikecharles
mikecharles / ordinal.py
Created February 8, 2016 21:33
Ordinal of a number in Python
ordinal = lambda n: "%d%s" % (n,"tsnrhtdd"[(n/10%10!=1)*(n%10<4)*n%10::4])
@mikecharles
mikecharles / backup-conda-env.sh
Last active March 25, 2016 21:21
Backup an anaconda environment
#!/bin/sh
# Set usage function
usage() {
status=$1
read -rd '' usage << EOM
Usage: [OPTIONS] SOURCE DEST
Backup the SOURCE anaconda environment to DEST
@mikecharles
mikecharles / clabel-issue.ipynb
Last active May 17, 2016 18:16
Matplotlib issue where clabels are plotted outside the projection limb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mikecharles
mikecharles / run.sh
Created May 17, 2016 18:48
Find corrupt MySQL database tables that
echo "The following MySQL database tables are corrupt:"
mysql -Nse "show databases" | while read database ; do
mysql -Nse "show tables from $database" | while read table ; do
test=`mysql -e "select * from ${database}.${table} limit 1" 2> /dev/null`
if [[ $? -ne 0 ]] ; then
echo "${database}.${table}"
fi
done
done
@mikecharles
mikecharles / source-activate-completion.sh
Last active May 23, 2016 15:41
Bash completion script for source activating a conda environment
_complete_source_activate_conda()
{
if [ ${COMP_WORDS[COMP_CWORD-1]} != "activate" ] ; then
return 0
fi
local cur env_list
cur=${COMP_WORDS[COMP_CWORD]}
env_list=$(conda env list | sed '1d;2d;$d' | awk {'print $1'})
COMPREPLY=( $(compgen -W "${env_list[@]}" -- "$cur") )
}
@mikecharles
mikecharles / browse.html
Created July 5, 2016 18:21
Browse image files by date/lead
<!DOCTYPE html>
<html>
<head>
<title>Image Browser</title>
<style>
img[name=image] {
max-width: 100%;
height: auto;
}
</style>
@mikecharles
mikecharles / keep-trying.sh
Last active August 24, 2016 15:23
Keep trying a command every X minutes, and stop after Y minutes have passed, or the command succeeds
#!/bin/sh
#---------------------------------------------------------------------------------------------------
# Usage
#
usage() {
printf "$(basename "$0") -s <TIME_BETWEEN_TRIES> -t <TIME_TO_TRY> <COMMAND>\n"
printf " where:\n"
printf " -s TIME_BETWEEN_TRIES time (minutes) between each try\n"
printf " -t TIME_TO_TRY total time (minutes) to try the command before giving up\n"