Skip to content

Instantly share code, notes, and snippets.

View wil3's full-sized avatar

Wil Koch wil3

View GitHub Profile
@wil3
wil3 / sendgmail.py
Last active August 29, 2015 14:07
Send an email from your Gmail account using Python
#!/usr/bin/env python
"""Send an email with your Gmail account
"""
import smtplib
__author__ = "William Koch"
class SendGmail:

Keybase proof

I hereby claim:

  • I am wil3 on github.
  • I am wilkoch (https://keybase.io/wilkoch) on keybase.
  • I have a public key whose fingerprint is A13D 0086 FCEF 07F0 2B68 92EF 6AE1 45AF FEC0 1E3C

To claim this, I am signing this object:

@wil3
wil3 / ga_string.py
Created April 12, 2015 21:16
Genetic algorithm to evolve strings
#!/usr/bin/env python
__author__ = "William Koch"
import re
import sys
import random
import numpy
from deap import algorithms
from deap import base
from deap import creator
from deap import tools
import gzip, os, shutil
import cStringIO
from optparse import OptionParser
"""
Calculate the average entropy of files in the given directories
"""
def entropy(f):
import requests, time, sys, random, string
from urlparse import urlparse
from time import sleep
import argparse
#import subprocess
class MeasureBoot:
def __init__(self):
self.current_token = None
@wil3
wil3 / produce-consume.py
Created November 10, 2017 02:32
Python 2 Producer/Consumer demonstration
"""
Introduce producer/consumer model with thread safe queues
This demo can be first illustrated as an M/M/K queue in which we have incoming
messages at some rate added to a single queue, each consumer thread will
continually get and process items from the queue.
This is to demonstrate tradeoffs with the queue size, and number
""" Demo creating a simple webserver and using a pub/sub design pattern
to have handlers for the request url to do work off the critcal path. This could
for example be used to process data analytics.
The publisher uses the callback to signal to the subscriber data has changed.
Conditions are used to ensure subscribers are not reading data while it is being
written. This allows the sublisher to wait (sleep) until the publisher wakes
them up to process an event. See docs for more information on Conditions,
https://docs.python.org/2/library/threading.html#condition-objects
"""
Purpose:
This python script is meant to introduce you to parellel processing with
threads and processes. The example uses a simple worker than randomly selects
a letter and continually hashes this value. This demonstrates two methods for
creating a thread, (1) by specifying a target function or (2) inheriting
threading.Thread.
This lesson also shows that the Thread and Process API are (for the most part)
interchangable allowing us to simply replace threading.Thread with multiprocessing.Process
@wil3
wil3 / run_gymfc.py
Created October 16, 2018 18:25
Test of GymFC working with latest OpenAI baselines master branch
#!/usr/bin/env python3
import os
from baselines.common import tf_util as U
from baselines import logger
import gymfc
import argparse
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os, argparse
import tensorflow as tf
"""
This script converts a checkpoint to a pb file without needing to know
the names of the input and output nodes. This then allows you to use the
Tensorflow tool summarize_graph to identify potential input/output nodes.
Usage: