Skip to content

Instantly share code, notes, and snippets.

Matthew Story matthewstory

  • AxialMarket
Block or report user

Report or block matthewstory

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View specify.py
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 Mar 20, 2014
unicodify and stringify decorators
View unicodify.py
'''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
View gist:5573424
#!/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 Dec 11, 2015
An example of how to coordinate writes from many forks to a single xapian database using a file lock to serialize writes.
View xapian_multi_fork_write.py
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 Dec 11, 2015
Simple Pre-Forked Python JSON-RPC Server
View gist:4547282
import os
import signal
import sys
import select
import errno
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
# BOOK-KEEPING
_PIDS = []
@matthewstory
matthewstory / .vimrc
Created Nov 21, 2011
i prefer minimalism in all things ...
View .vimrc
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 Nov 21, 2011
goodbye screen, hello tmux
View .tmux.conf
###########################################################
## .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
You can’t perform that action at this time.