View git-bclean
#!/bin/bash
# STOP! Before going any further, think: are you going to regret the decision
# to write this script?
# Deciding to write this in bash was not one of my better decisions.
# -- https://twitter.com/alex_gaynor/status/369892494114164736
IFS="`printf "\n\t"`"
set -eu
remotes=""
View deletablemodel.py
from django.utils import timezone
from django.db import models as m
from django.db.models.base import ModelBase
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.fields.related import SingleRelatedObjectDescriptor
from model_utils.managers import PassThroughManagerMixin
class DeletableQuerySetMixin(object):
View return-in-finally.py
"""
A demonstration of a subtle bug when a context manager uses
`return` in a `finally` block around a `yield`.
See comments on last line for an explanation.
Take-away: be very, very careful about using `return` in a
`finally` block.
"""
View vimrc.vim
" https://github.com/python-rope/ropevim
Plug 'python-rope/ropevim'
let g:ropevim_guess_project = 1
let g:ropevim_goto_def_newwin = 'vnew'
let ropevim_vim_completion=1
let ropevim_extended_complete=1
autocmd FileType python setlocal omnifunc=RopeCompleteFunc
map <c-c>i :RopeAutoImport<CR>
map <c-c>fo :RopeFindOccurrences<CR>
" <C-c>rr RopeRename
View gevent-in-production.rst
  • I've been using gevent in production for about 6 years, and I've only encountered a handful of issues:
  • All of my experience using gevent is in fully monkeypatched mode. It's certainky possible to use outside of monkeypatch mode, but I don't know anything about that.
  • See the monkeypatches.py and gevent_.py files for my implementation of monkeypatching.
  • The gevent_.py file contains a couple things:
View patch_django_create_test_db.py
"""
Add this function to your app's __init__.py (or similar) to prevent Django
from ever asking if you're sure you'd like to delete your test database.
"""
def _patch_django_create_test_db():
from django.db.backends.base.creation import BaseDatabaseCreation
old_create_test_db = BaseDatabaseCreation._create_test_db
def _create_test_db(self, verbosity, autoclobber, *args, **kwargs):
return old_create_test_db(self, verbosity, True, *args, **kwargs)
View git-work-life
#!/usr/bin/env python
from __future__ import division
"""
Installation
============
$ curl -O https://gist.githubusercontent.com/wolever/2a15db70f8cb255d753b2cdbb8a718ce/raw/git-work-life
$ chmod +x git-work-life
$ sudo mv git-work-life /usr/local/bin
View rebuild-virtualenv
#!/bin/bash
set -eu
if [[ -z "${1-}" ]]; then
echo "USAGE: $0 VIRTUAL_ENV_DIR"
exit 1
fi
venv="$1"
View lolmutex.js
/**
* A LocalStorage-based mutex. Guarantees¹ that only one browser window will be
* able to execute the code inside the callback at a time.
*
* Based on the Alur and Taubenfeld fast lock
* (http://www.cs.rochester.edu/research/synchronization/pseudocode/fastlock.html)
* with an added timeout to ensure there will be eventual progress in the event
* that a window is closed in the middle of the callback.
*
* 1. The guarantee assumes that the algorithm is correctly implemented.
View urllib3_requests_pyopenssl_sni_fix.py
"""
The correct set of steps to monkeypatch:
- gevent into threading, socket, etc
- PyOpenSSL with gevent (via gevent_openssl)
- PyOpenSSL to be compatible with
- urllib3 and requests.packages.urllib3 to use PyOpenSSL, which
lets them connect to servers using SNI
"""
import logging