Skip to content

Instantly share code, notes, and snippets.

View mikecharles's full-sized avatar

Mike Charles mikecharles

View GitHub Profile
@mikecharles
mikecharles / list_modules.py
Last active April 25, 2024 17:55
Python script to list all submodules of a given Python package
#!/usr/bin/env python
import os, sys
import pkgutil
def list_submodules(list_name, package_name):
for loader, module_name, is_pkg in pkgutil.walk_packages(package_name.__path__, package_name.__name__+'.'):
list_name.append(module_name)
module_name = __import__(module_name, fromlist='dummylist')
if is_pkg:
@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 / start-vpn.py
Last active September 17, 2021 01:42
Start and stop OpenConnect VPN
#!/usr/bin/env python
from subprocess import call, PIPE
import os
user = '<user>'
vpn_servers = ['<server1>', '<server2>']
for vpn_server in vpn_servers:
@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 / 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 / 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 / README.md
Last active March 4, 2019 19:30
Deploy a Python application using Ansible and the Ansistrano role

To deploy your app, you'll need to install Ansible and the Ansistrano deploy and rollback Ansible Galaxy roles.

Then create a directory in your app (eg. named ansible) and put these files in there. You should only need to modify the top few variables in vars.yml to get the deployment working for your app.

To do the deployment, use a command like this:

ansible-playbook --limit ansible/deploy.yml

@mikecharles
mikecharles / README.md
Last active December 11, 2017 20:00
Display git status and graph continuously in the terminal

Note that this requires the following alias set in $HOME/.gitconfig:

[alias]

tree = "!f() { git log $@ --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit ; }; f"

@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 / README.md
Created March 3, 2016 18:59
Load config data in a Python application from a default config file, and override some user-defined variables from a separate config file

Replace all instances of with your app name (eg. 'my-python-app', dashes are allowed), and all instances of with your app's main module (eg. 'my_python_app', dashes are NOT allowed), and