Skip to content

Instantly share code, notes, and snippets.

David Wolever wolever

View GitHub Profile
View print-leaked-events.js
#!/usr/bin/env node
// My modifications to this code are public domain
const { writeSync, readFile } = require("fs")
const async_hooks = require("async_hooks")
function showStack() {
let e = new Error()
writeSync(1, e.stack.split('\n').slice(2).join('\n') + '\n')
@wolever
wolever / watchdir
Created Oct 24, 2018
Watch a directory for changes and run a command when it does
View watchdir
#!/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 -u
if [[ "$#" -lt 2 ]]; then
@wolever
wolever / git-bclean
Created Mar 27, 2018
Deletes all merged branches after prompting for confirmation. Use `-r` for remote branches.
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=""
@wolever
wolever / deletablemodel.py
Created Dec 5, 2017
A Django model base class that hides models instead of deleting them.
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):
@wolever
wolever / return-in-finally.py
Last active Sep 1, 2017
Confusing bug I was hit with today: a `return` in a `finally` that ate an exception thrown from a generator
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.
"""
@wolever
wolever / vimrc.vim
Created Aug 24, 2017
My rope-vim configuration
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
@wolever
wolever / gevent-in-production.rst
Last active Jul 10, 2018
Point-form notes about using gevent in production
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:
@wolever
wolever / patch_django_create_test_db.py
Last active Apr 13, 2017
Prevent Django from asking if you're sure you'd like to delete your test database.
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)
@wolever
wolever / git-work-life
Last active Jul 8, 2017
Generates bar charts from your git repo to quantify your work-life balance
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
@wolever
wolever / rebuild-virtualenv
Last active Apr 11, 2017
A totally untested script for upgrading a virtualenv
View rebuild-virtualenv
#!/bin/bash
set -eu
if [[ -z "${1-}" ]]; then
echo "USAGE: $0 VIRTUAL_ENV_DIR"
exit 1
fi
venv="$1"
You can’t perform that action at this time.