Skip to content

Instantly share code, notes, and snippets.

View mlissner's full-sized avatar

Mike Lissner mlissner

View GitHub Profile
@mlissner
mlissner / decorators.py
Last active May 6, 2021 15:05
A retry decorator to catch specific exceptions and retry the code, with exponential backoff
import time
from functools import wraps
from typing import Callable, Type
def retry(
ExceptionToCheck: Type[Exception],
tries: int = 4,
delay: float = 3,
backoff: float = 2,
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@mlissner
mlissner / filters.js
Created March 7, 2019 23:09
Regular expressions for parsing law citations from the U.S., Canada, Europe, and Australia (and probably more). Originally from the Jureeka project.
// ==UserScript==
// @name Jureeka
// @namespace http://www.jureeka.org
// @description Turns legal citations in webpages into hyperlinks that direct you to online legal source material.
// ==/UserScript==
// $Id: jureeka.js 1256 2012-02-13 19:06:16Z imad $
/*
Warnings:
@mlissner
mlissner / dwolla.py
Created December 30, 2014 19:24
GAH! time.sleep(1)
def process_dwolla_transaction_status_callback(request):
if request.method == 'POST':
data = simplejson.loads(request.body)
logger.info('Dwolla transaction status callback triggered with '
'data: %s' % data)
if check_dwolla_signature(
request.META['HTTP_X_DWOLLA_SIGNATURE'],
request.body):
# Statuses can be found at:
# https://developers.dwolla.com/dev/pages/statuses
@mlissner
mlissner / admin.py
Created December 30, 2014 18:49
How do I make line 9 work?
from django.contrib import admin
from alert.donate.models import Donation
from alert.userHandling.models import UserProfile
class DonorInline(admin.TabularInline):
model = UserProfile.donation.through
max_num = 1
raw_id_fields = ('donation',)
@mlissner
mlissner / celeryd
Created December 22, 2014 05:34
Mine.
start_workers () {
echo "Starting workers with command: "
echo " $CELERYD_MULTI start $CELERYD_NODES $DAEMON_OPTS \
--pidfile=\"$CELERYD_PID_FILE\" \
--logfile=\"$CELERYD_LOG_FILE\" \
--loglevel=\"$CELERYD_LOG_LEVEL\" \
--cmd=\"$CELERYD\" $CELERYD_OPTS"
$CELERYD_MULTI start $CELERYD_NODES $DAEMON_OPTS \
--pidfile="$CELERYD_PID_FILE" \
--logfile="$CELERYD_LOG_FILE" \
@mlissner
mlissner / keybase.md
Created December 4, 2014 22:03
Verifying my github for keybase.io

Keybase proof

I hereby claim:

  • I am mlissner on github.
  • I am mlissner (https://keybase.io/mlissner) on keybase.
  • I have a public key whose fingerprint is E64F 32B9 B2CE 993E 6D2A 60A5 DE79 459C D047 ACFE

To claim this, I am signing this object:

@mlissner
mlissner / __init__.py
Created November 24, 2014 18:40
Another attempt at nuking stftime.
import datetime
import warnings
class CleanDateTime(datetime.datetime):
def strftime(self, *args, **kwargs):
# warnings.warn('strftime is deprecated', DeprecationWarning,
# stacklevel=2)
return super(CleanDateTime, self).strftime(*args, **kwargs)
@mlissner
mlissner / __init__.py
Created November 21, 2014 19:45
An attempt at nuking strftime in Django. Alas it also breaks Django.
import datetime
print "Now killing strftime."
class CleanDateTime(datetime.datetime):
def strftime(self, format):
raise NotImplemented(
"Strftime doesn't support dates prior to 1900 and as a "
"consequence CourtListener nukes them from the standard library. "
count | count
---------+--------
2590457 | 395389