Skip to content

Instantly share code, notes, and snippets.

Will Vaughn nackjicholson

Block or report user

Report or block nackjicholson

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
nackjicholson /
Created Jun 9, 2019
json encoder for dataclass instances and enum and times.
class EnhancedJSONEncoder(json.JSONEncoder):
def default(self, o):
if is_dataclass(o):
return asdict(o)
if isinstance(o, Enum):
if isinstance(o, time):
return o.strftime("%H:%M")
return super().default(o)
nackjicholson /
Last active May 13, 2019
snippet of python to verify SNS signatures in flask app.
import json
import logging
from base64 import b64decode
from datetime import datetime, timezone
from urllib.request import urlopen
from M2Crypto import X509
from flask import Blueprint, request, jsonify
from werkzeug.exceptions import BadRequest, Unauthorized
nackjicholson /
Last active Aug 20, 2019
Emacs wisdom from the internet
brew install pgloader
brew install mysql@5.7
brew services start mysql@5.7
brew link mysql@5.7 --force

curl -LO
gunzip -k f1db.sql.gz
View gist:acdd07215690dd093b45f838853a080c
>>> import csv
>>> s = '"Yes, this line",can be, parsed as csv'
>>> list(csv.reader([s]))[0]
['Yes, this line', 'can be', ' parsed as csv']
nackjicholson /
Last active Oct 3, 2018
s3 list paginator tricks.
import boto3
s3_client = boto3.client('s3')
def list_dirs(bucket, prefix):
""" Yield direct child folders of the given prefix.
nackjicholson /
Last active Oct 1, 2018
Retriable class decorator, which would allow declaration time AND runtime resetting of decorator properties.
import time
from functools import wraps, update_wrapper
def scaled_retries(attempts, sleeptime, sleepscale):
scaled_sleeptime = sleeptime
for attempt_no in range(attempts):
yield attempt_no + 1, scaled_sleeptime
scaled_sleeptime *= sleepscale
nackjicholson /
Created Sep 21, 2018
Helpers for using pymongo and BSON types with flask server.
from flask import Flask
from .mongoflask import MongoJSONEncoder, ObjectIdConverter
from .db import get_db
def create_app():
app = Flask(__name__)
app.json_encoder = MongoJSONEncoder
app.url_map.converters['objectid'] = ObjectIdConverter
# Client sends their string, we interpret it as an ObjectId
nackjicholson /
Created Aug 16, 2018
A script for loading the into a non `virtualenv` virtual env like `poetry` or `python -m venv`.
import argparse
import base64
import os
import zlib
from pathlib import Path
def convert(s):
b = base64.b64decode(s.encode('ascii'))
return zlib.decompress(b).decode('utf-8')
nackjicholson /
Last active Mar 29, 2019
Vim, tmux, things I learned



Search and replace ' with " from the current cursor postion to the end of the file.



You can’t perform that action at this time.