Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
mjumbewu / python_distribution_resources.md
Last active November 2, 2016 17:22
Setup.py Documentation and Resources

Resources for Distributing Python Tools

When trying to figure out how to structure your Python tool for distribution, it can be difficult to get started. This represents a set of writings that I stumbled across, or that others have pointed me to, that I think would use as chapters in a setup.py book.

Preface

@mjumbewu
mjumbewu / https_server.py
Created October 12, 2016 17:04
An extension to Python3's http.server module that allows creation of HTTPS servers. Inspired by @dergachev's even simpler https://gist.github.com/dergachev/7028596.
"""
An extension to Python3's http.server module that allows creation of HTTPS
servers. Inspired by @dergachev's https://gist.github.com/dergachev/7028596.
You can either use a separate certificate and key file:
python3 https_server.py -c server.crt -k server.key
Or generate a PEM file and use it as the certificate:
@mjumbewu
mjumbewu / loadtest.py
Last active October 9, 2016 00:58
Simple load tester that continuously sends GET requests to a list of URLs for a given duration of time. Requires python libraries click and requests.
#!/usr/bin/env python
from __future__ import print_function, division
import click
import csv
from datetime import timedelta
from itertools import cycle
from queue import Queue
import requests
rejected = lambda r: r.action == 'Reject'
approved = lambda r: r.action == 'Approve'
expensive = lambda r: approved(r) and r.data['amount'] >= 500
workflow(
roles=[
'Employee',
'Supervisor',
'CFO',
'Travel Reviewer' ],
@mjumbewu
mjumbewu / gatekeeper_logs.csv
Last active July 8, 2016 23:23
Simulating traffic against the AIS API
We can't make this file beautiful and searchable because it's too large.
ID,Class,Created,Endpoint ID,Key ID,Method,Path,Query,Response time,Response code,Response bytes,Test passed,Creator,Validation errors,Record title,Record url
42929373,Gatekeeper\Transactions\Transaction,1467057598,31,,GET,/account/406149600,format=json,846,200,2145,,,,,
42929372,Gatekeeper\Transactions\Transaction,1467057597,31,,GET,/account/871051400,format=json,892,200,2168,,,,,
42929370,Gatekeeper\Transactions\Transaction,1467057597,31,,GET,/account/022120300,format=json,839,200,2184,,,,,
42929369,Gatekeeper\Transactions\Transaction,1467057597,31,,GET,/address/2534%20HOLBROOK/,format=json,125,200,940,,,,,
42929368,Gatekeeper\Transactions\Transaction,1467057596,31,,GET,/address/1636%20SOUTH%2058TH%20STREET/,format=json,222,200,955,,,,,
42929366,Gatekeeper\Transactions\Transaction,1467057595,31,,GET,/address/1456%20N%20NEWKIRK%20STREET/,format=json,164,200,938,,,,,
42929365,Gatekeeper\Transactions\Transaction,1467057593,31,,GET,/address/4728%20TORRESDALE%20AVE/,format=json,128,200,55,,,,,
42929364,Gatekeepe
@mjumbewu
mjumbewu / gunicorn.conf.py
Created June 9, 2016 21:13
Patching psycopg2 for nonblocking use with gunicorn's gevent workers using psycogreen
from psycogreen.gevent import patch_psycopg
def post_fork(server, worker):
patch_psycopg()

Starting a new project

Rather than trying to plan the precise steps and concepts to cover as you build the project, it may be easier to work backwards, building the project as you would if it weren't for class first, and then breaking it down for instruction.

  1. Build the project out completely as quickly and simply as possible.
  2. Break down the project into conceptual pieces.
  • Use the CbK skill levels to map and order the skills you used to create
@mjumbewu
mjumbewu / nginx.conf
Created June 2, 2016 01:27
Simple SSL-enabled nginx config to serve static files
server {
listen 80;
return 301 https://\$host\$request_uri;
}
server {
listen 443 ssl;
ssl_certificate [PATH_TO_SSL_CERT];
ssl_certificate_key [PATH_TO_SSL_CERT_KEY];
@mjumbewu
mjumbewu / deploy.sh
Created May 20, 2016 15:31
Sample contents of a .travis folder for Phila deployments on AWS
#!/usr/bin/env bash
set -e
SCRIPTS_DIR=$(dirname $0)
KEYFILE=deploy.pem
INSTANCE_USER=ubuntu
ENCRYPTION_KEY='encrypted_${ENCRYPTION_ID}_key'
ENCRYPTION_IV='encrypted_${ENCRYPTION_ID}_iv'
# =============================================================================
# ON THE SERVER...
# Check the amount of disk space available on root (/) partition
df -h
# See where space is being consumed
cd /; sudo du -h --max-depth=1
# In this case, most was in /emergence; further digging and du-ing