Skip to content

Instantly share code, notes, and snippets.


Denis Krienbühl href

View GitHub Profile
href /
Created Oct 27, 2011
Convert any dictionary to a named tuple
from collections import namedtuple
def convert(dictionary):
return namedtuple('GenericDict', dictionary.keys())(**dictionary)
>>> d = dictionary(a=1, b='b', c=[3])
>>> named = convert(d)
>>> named.a == d.a
>>> named.b == d.b
href /
Last active Jul 9, 2020
Generates an S3 HTML Upload Form for Object Storage
#!/usr/bin/env python
# This script generates an example HTML form that can directly upload files to
# an S3 bucket at
# Based on the following work:
# -
# -
# Requires Python 3 and boto3 to work:
href /
Created May 25, 2018
Installs Suitable with Mitogen using Python 2.7 for Testing
#!/usr/bin/env bash
set -eu
if [ -z "$path" ]; then
echo "Please pass an install directory"
exit 1
href /
Created May 24, 2018
Example of our internal use of Suitable
import click
from suitable import Api
from textwrap import dedent
def upgrade_puppet(hostname):
""" Upgrades a puppet client from puppet 3.8 to 4.x. """
href /
Created Aug 30, 2016
Calculate the Yubikey serial number from the OTP
# adapted from Java:
# e38e46ee90296a852374a8b744555e99d16b6ca7/src/classes/Modhex.cls
ALPHABET = 'cbdefghijklnrtuv'
def yubikey_otp_to_serial(otp):
""" Takes a Yubikey OTP and calculates the serial number of the key.
href /
Last active Sep 28, 2017
Internal redirects in Morepath
""" Simple redirects for renamed paths using a generic redirect model.
For static paths:
class OldPathRedirect(Redirect):
to = '/new-path'
For wildcard paths (e.g. /old-pages/my-page to /new-pages/my-page):
href /
Last active Feb 24, 2017
Checks exported 1password urls against the domains affected by Cloudbleed.
""" Checks exported 1password urls against the domains affected by Cloudbleed.
1. Export the 1password urls (as csv containing *only* the url column!!).
2. Store the exported file in the current directory as 'export.csv'.
3. Run python3 ./
href /
Created Dec 9, 2016
An exploration of transaction integration for PonyORM
import transaction
from pony.orm import Database, PrimaryKey, Required
from pony.orm.core import DBSessionContextManager
from pony.orm.core import commit, flush, rollback
class CustomDBSessionContextManager(DBSessionContextManager):
def _enter(self, *args, **kwargs):
href /
Created Sep 9, 2013
Simple function / class to put records into groups if they belong together
class United(object):
""" Puts items added through 'append' into the same group as the last
item which was appended, as long as the matchfn which is passed the last
and the current item returns true.
united = United(lambda last, current: last == current)
href / gist:b72b317db2d679711883
Last active Aug 29, 2015 — forked from bubenkoff/gist:5764377
pytest-xdist with Buildout on Python 3
View gist:b72b317db2d679711883
recipe = zc.recipe.egg
interpreter = py
initialization =
import sys, os