Skip to content

Instantly share code, notes, and snippets.

View wolever's full-sized avatar

David Wolever wolever

View GitHub Profile
@wolever
wolever / pyhierarchy2dot.py
Last active August 29, 2015 14:16
pyhierarchy2dot.py: generates a simple dot graph class hierarchy from a set of base classes.
"""
Generates a simple dot graph class hierarchy from a set of base classes.
Usage::
$ python pyhierarchy2dot.py sqlalchemy.String sqlalchemy.Integer sqlalchemy.DateTime
"""
import sys
import importlib
@wolever
wolever / git-blast
Last active November 30, 2016 14:24
git-blast: show git branches sorted by last commit date
#!/usr/bin/env python
"""
Shows git branches sorted by last commit date, noting when branch has been
merged:
$ git blast
* master 33 minutes ago
david 4 days ago [M]
unholy-david-payments 4 days ago
handsontable-2 5 days ago
@wolever
wolever / Conly.vim
Created February 3, 2015 20:50
:Conly Vim command to close all windows in the current column.
" :Co[nly] closes all other windows in the current column.
" For example, if the cursor is in the "cur" window, below, windows 1, 2, and
" 4 will be closed:
" +-------+ +-------+
" | win 1 | | |
" +-------+ | |
" | win 2 | | |
" +-------+ --> :Conly --> | cur |
" | cur | | |
" +-------+ | |
@wolever
wolever / api_client.py
Created November 19, 2014 21:28
A simple example of how I do logging in an API client
"""
When I integrate with a 3rd party API, I write a thin wrapper around it to
normalize any eccentricities and provide a well-defined Python-level API.
"""
log = logging.getLogger("acme.api")
class AcmeAPIClient(object):
def get_widgets(self):
"""
"""
Of special interest:
- The ``Target`` class
- The ``Target.confirm_command`` and ``Target.confirm_git_branch`` methods
- The list of target definitions (``targets = [...]``)
- Using the ``.ak-default-target`` file to define a default target (can be different across branches)
Example use: ``fab ak-dev deploy``
"""

Full-stack Software Developer with a flair for the fasionable

Are you a passionate web developer who wears skinny jeans, checks Foursquare before heading out, and builds sleek, sylish apps? We are looking for you!

Who we are

We are Second Funnel - a small, growing startup making the web more visually interesting and relevant. We believe advertising currently sucks, but can be made awesome. Or at least less terrible. How? Through visuals that peek curiousity and lead to interesting, engaging content (think Pinterest meets marketing).

@wolever
wolever / monkypatch_logging.py
Created September 14, 2014 21:21
Monkey patch for logging.LogRecord.getMessage so it will never, ever raise an exception
def monkeypatch_logging_getMessage():
""" Monkey patch logging.LogRecord.getMessage so it will never, ever raise an exception. """
from unstdlib import to_str
from logging import LogRecord
oldGetMessage = LogRecord.getMessage
def getMessage(self):
try:
return oldGetMessage(self)
except Exception as e:
@wolever
wolever / monkeypatch_queryset.py
Last active May 12, 2022 11:42
Monkeypatch Django 1.5's QuerySet adding a .first() method compatible with 1.6
def monkeypatch_queryset_first():
""" Monkeypatch QuerySet adding a `.first()` method which is compatible
with Django 1.6's `.first()`. """
from django.db.models.query import QuerySet
if hasattr(QuerySet, "first"):
import warnings
warnings.warn("QuerySet.first is already defined! "
"Monkey patch should be removed.")
return
def first(self):
@wolever
wolever / vs.sh
Created September 12, 2014 22:48
vs: shell functions to transparently call hg or git, whichever is appropriate
vs() {
# Guesses which version control system is correct for the current
# directory, then executes it with "${@}":
# $ cd hg_repo/
# $ vs version
# Mercurial Distributed SCM
# ...
# $ cd ../git_repo
# $ vs version
# git version 1.8.1.1
@wolever
wolever / notice_board.py
Last active August 29, 2015 14:04
What I'm currently calling the "Notice Board pattern". Is this already a thing?
"""
The Notice Board pattern: returns the most recent value associated with a key,
or blocks waiting for a new value if the current value has already been seen.
History is not stored; only the most recent value is available.
The physical analogy is a notice board like you might see at a train station:
when you arrive at the station you can glance at the board to check the current
departure time for your train, or you can stand around watching the board
waiting for the inevitable message that your train has been delayed.