Skip to content

Instantly share code, notes, and snippets.

David Wolever wolever

Block or report user

Report or block wolever

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 maybe.ts
* Catches any exception which might be raised by a promise and returns a
* tuple of [result, error], where either the result or the error will be
* undefined:
* let [res, error] = await maybe(someApi.get(...))
* if (err) {
* return `Oh no there was an error: ${err}`
* }
* console.log('The result:', res)
wolever / fix-mouse.lua
Created Nov 7, 2019
Hammerspoon config to use mouse button 3 for scrolling, remap button 4 to middle button
View fix-mouse.lua
local scrollMouseButton = 3
local deferred = false
overrideOtherMouseDown ={ hs.eventtap.event.types.otherMouseDown }, function(e)
-- print(['mouseEventButtonNumber'])
local mouseButton = e:getProperty(['mouseEventButtonNumber'])
if mouseButton == scrollMouseButton then
deferred = true
return true
View token_value_at_block.sql
CREATE OR REPLACE VIEW accounts.address_token_balances AS (
LEAD(block_number, 1, 2147483647) OVER (
PARTITION BY address_hash, token_contract_address_hash
ORDER BY block_number ASC
) as next_block_number,
SUM(amount) OVER (
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 / watchdir
Created Oct 24, 2018
Watch a directory for changes and run a command when it does
View watchdir
# 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.
# --
IFS="`printf "\n\t"`"
set -u
if [[ "$#" -lt 2 ]]; then
wolever / git-bclean
Created Mar 27, 2018
Deletes all merged branches after prompting for confirmation. Use `-r` for remote branches.
View git-bclean
# 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.
# --
IFS="`printf "\n\t"`"
set -eu
wolever /
Created Dec 5, 2017
A Django model base class that hides models instead of deleting them.
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 /
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
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 / vimrc.vim
Created Aug 24, 2017
My rope-vim configuration
View vimrc.vim
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 / 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 and files for my implementation of monkeypatching.
  • The file contains a couple things:
You can’t perform that action at this time.