Skip to content

Instantly share code, notes, and snippets.

@aliles
aliles / cache_import.py
Created August 12, 2014 12:27
PEP 302 import hook to caching system path contents
"""PEP 302 import hook to caching system path contents.
Implements an import hook using a finder and loader class to load Python
modules from system paths while caching the path contents.
"""
from __future__ import print_function
import glob
import imp
import os
@aliles
aliles / Vagrantfile
Created May 16, 2014 13:03
Vagrantfile to provision a virtual machine with ZeroVM.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# 64-bit Ubuntu 12.04 LTS
config.vm.box = "hashicorp/precise64"
@aliles
aliles / abstract.txt
Last active August 29, 2015 14:00
Command line programs for busy developers
Command line interface tools are the new web framework. In addition to the
Python standard library's getopt, optparse and argparse there is a bewildering
array of packages available on the Python Packaging Index. Packages like Click,
Cliff, Docopt, Invoke all provide different mechanics for creating command line
applications. When all you want to do is expose a command line and get back to
creating functionality, it’s hard to know which alternative to reach for.
This presentation will have two parts, the first half will be a brief survey
of popular modules. Strengths, weaknesses and design philosophies will be
compared by creating command line processing for the same example program.
@aliles
aliles / git remote -v
Created April 18, 2014 12:23
Proof of concept Git command that generates commit code names based on each commit's hash value. Code names are generated from Princeton's Wordnet database in the same manner as http://twoslug.aaroniles.net/
$ git remote -v
origin git@github.com:aliles-heroku/twoslug.git (fetch)
origin git@github.com:aliles-heroku/twoslug.git (push)
@aliles
aliles / output.txt
Created April 1, 2014 11:24
Random words of maximum 10 characters generated using a Markov chain ov 4-tuple sequences from nouns in the wordnet database.
$ python run.py markov --length 10 --chain 4 --words 30
ledgeringw
fmri
blockscrew
stickpoolr
trudentine
shirtlifto
northomosi
pollusiona
aralytechi
@aliles
aliles / flask_quickstart.py
Created February 18, 2014 11:39
Example CLI help output for possible re-implementation of boolean flags for begins.
from flask import Flask
import begin
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
@begin.start(env_prefix='WEB_')
@aliles
aliles / context.py
Created February 17, 2014 11:20
Class switching context object to prevent applications for assigning to protected properties. Uses class swizzling.
"Program execution context"
import warnings
class SwizzleContext(object):
"""Type switching context object base class
Supports the context manager protocol to switch the instance from a
MutableContext to the protected Context.
"""
@aliles
aliles / rawhelp.py
Created February 16, 2014 10:40
Example usage of the new begin.formatters module to preserve whitespace from docstrings in help output.
import begin
my_formatter = begin.formatters.compose(begin.formatters.RawDescription)
@begin.subcommand
def sub():
"""Such text
Very whitespace
So exact
"""
@aliles
aliles / api_endpoint_templating.py
Created January 20, 2014 12:00
API endpoint templating using Jinja2 templates and Twisted.Web.
"""API endpoint templating using Jinja2.
Rendering of Jinja2 templates, with external actions, using Twisted.Web.
Combining external actions for Jinja2 [1] with Twisted's deferreds inside the
Twisted's web framework. Jinja2 templates are iteratively processed [2] to
render an API response [3]. The template prepares, executes and formats the
response from an HTTP request.
When run, the application looks up an email address provided as a GET paramater
@aliles
aliles / twisted_render_jinja2.py
Created January 17, 2014 11:02
Iterative rendering of Jinja2 template, with external actions, using Twisted.
"""Rendering of Jinja2 templates, with external actions, using Twisted.
Combines external actions for Jinja2 [1] with Twisted's deferreds for
cooperative iterator consumption [2] to render template. The template prepares,
executes and formats the response from an HTTP request.
[1] https://gist.github.com/aliles/8417271
[2] https://gist.github.com/aliles/8454244
"""
import os