Skip to content

Instantly share code, notes, and snippets.

View luhn's full-sized avatar

Theron Luhn luhn

View GitHub Profile
@luhn
luhn / cleanup.py
Last active March 12, 2023 11:54
An AWS Lambda function to delete old AMIs.
"""
Code adapted from and inspired by http://blog.ranman.org/cleaning-up-aws-with-boto3/.
"""
import os
import re
from datetime import datetime, timedelta
import boto3
@luhn
luhn / README.md
Last active January 3, 2023 18:31
PostgreSQL memory leak

This was performed on Ubuntu 14.04 with a fresh install of PostgreSQL 9.3.14 directly from the official Postgres apt repo. It only works if the query planner chooses the attached plan (with HashAggregate).

Create and populate a new database:

psql -U postgres -c "create database test;"
psql -U postgres test < populate.sql

Open a connection to the database and execute query.sql. The Postgres worker memory usage will rise approximately 50MB and won't be released until the connection is closed.

@luhn
luhn / memoize.py
Last active January 15, 2017 16:19
Memoize method decorator
import functools
class memoize_method:
"""
A decorator to memoize a method. The cache is stored as a dictionary
inside the object.
This functionality is similar to stdlib's :func:`functools.lru_cache`.
When using lru_cache on a method, the object will be used as part of the
@luhn
luhn / query_counter.py
Created March 21, 2017 17:35
SQLAlchemy query counter
from sqlalchemy import engine_from_config, event
from sqlalchemy.orm import sessionmaker
def query_count_hook(
conn, cursor, statement, parameters, context, executemany,
):
info = conn.info
info['query_count'] = info.get('query_count', 0) + 1
@luhn
luhn / traversal_paths.py
Created April 12, 2017 00:25
URL traversal sitemap
"""
Inspect a Pyramid app using URL traversal and construct URLs for all the views.
"""
def get_resources(self, root):
resources = {
type(root): root,
}
for resource in root.values():
resources.update(self.get_resources(resource))
@luhn
luhn / data.txt
Last active April 28, 2017 17:36
InfluxDB issue #8164
mymeasure,context=baz,view=3 duration=0.743992881887 1493397808910022759
mymeasure,context=foo,view=4 duration=0.340297307361 1493397809442500681
mymeasure,context=bar,view=2 duration=0.351295066647 1493397809994147837
mymeasure,context=bar,view=1 duration=0.485869769473 1493397810730819905
mymeasure,context=bar,view=1 duration=0.104839181702 1493397810993959410
@luhn
luhn / auth.py
Created November 20, 2018 07:09
# Interfaces
class IUserIdentity:
userid = None
class IIdentityPolicy:
def __call__(request):
""" Return the claimed identity of the user associated with the given
import sys
import inspect
def wrap(func):
attach()
return func
def attach():
@luhn
luhn / docker-compose.yml
Last active June 11, 2019 22:32
Fluentd Keepalive Bug
version: "3.7"
services:
src:
build:
context: .
dockerfile: src.Dockerfile
dst:
build:

Keybase proof

I hereby claim:

  • I am luhn on github.
  • I am luhn (https://keybase.io/luhn) on keybase.
  • I have a public key whose fingerprint is 8E57 AB5E 6FB9 441F 92C4 C3D8 9234 9742 8E86 184E

To claim this, I am signing this object: