Skip to content

Instantly share code, notes, and snippets.

View matthewstory's full-sized avatar

Matthew Story matthewstory

View GitHub Profile
import typing
__all__ = [ "Attribute", "AttributeMeta", "Spec", "undefaulted" ]
# sentinel
undefaulted = object()
class Attribute:
# support an optional type declaration which does nothing at present
def __init__(self, type_: typing.Any = None, default = undefaulted) -> None:
@matthewstory
matthewstory / unicodify.py
Created March 20, 2014 04:47
unicodify and stringify decorators
'''Decorators to convert all arguments passed to a function or method to
unicode or str, including default arguments'''
import sys
import functools
import inspect
def _convert_arg(arg, from_, conv, enc):
'''Safely convert unicode to string or string to unicode'''
return getattr(arg, conv)(encoding=enc) if isinstance(arg, from_) else arg
#!/bin/sh
# git post-commit hook for pyflakes'ing modified files
git log --oneline --name-only | sed -n '2,$p' | while read f; do
if [ "${f%.py}" != "$f" -a -e "$f" ]; then
echo "$f"
elif file "$f" 2> /dev/null | grep python > /dev/null 2>&1; then
echo "$f"
fi
done | xargs pyflakes || echo "PYFLAKES FAILED, PLEASE INSPECT"
@matthewstory
matthewstory / xapian_multi_fork_write.py
Last active December 11, 2015 08:58
An example of how to coordinate writes from many forks to a single xapian database using a file lock to serialize writes.
import fcntl
import time
import os
import sys
import shutil
import errno
import xapian as _x
# list of children to wait on
_pids = []
@matthewstory
matthewstory / gist:4547282
Last active January 20, 2022 15:05
Simple Pre-Forked Python JSON-RPC Server
import os
import signal
import sys
import select
import errno
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
# BOOK-KEEPING
_PIDS = []
@matthewstory
matthewstory / .vimrc
Created November 21, 2011 04:22
i prefer minimalism in all things ...
syntax on
set viminfo='20,\"500
set tabstop=4 shiftwidth=4 expandtab
set nohlsearch
set ignorecase smartcase
set number
autocmd FileType php set smartindent
autocmd FileType javascript set smartindent
autocmd FileType python set smartindent
autocmd FileType c set smartindent noexpandtab
@matthewstory
matthewstory / .tmux.conf
Created November 21, 2011 04:19
goodbye screen, hello tmux
###########################################################
## .tmux.conf
##
## first pass at a .tmux.conf to make transition from
## gnu screen bearable
###########################################################
# screenesque prefix
set -g prefix C-a
bind C-a send-prefix