Skip to content

Instantly share code, notes, and snippets.


Elmer de Looff edelooff

View GitHub Profile
edelooff /
Last active Oct 12, 2018
Collection length checking before determining duplicate items
import timeit
'one', 'two', 'three', 'four', 'five', 'six',
'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve')
'one', 'two', 'three', 'four', 'five', 'six',
'seven', 'one', 'nine', 'two', 'eleven', 'three')
edelooff /
Created Jun 2, 2018
Example uses of Kalpa
from kalpa import Root, Node, branch
USERS = {...}
class Root(Root):
"""Traversal root for Pyramid application."""
users = branch('UserCollection')
edelooff /
Last active Apr 10, 2018
Simple Python Feistel encoder/decoder
"""A simple 8-round Feistel network to encode/decode 8-bit integers.
See for construction details.
from random import randint
KEYS = [(randint(11, 19), randint(1, 200)) for _ in range(ROUNDS)]
edelooff /
Created Aug 16, 2016
Pyramid 1.7 view deriver to alert on view_configs that lack a permission setting.
def permission_check(view, info):
"""View deriver to verify all view configs define a 'permission'.
This deriver prints a message for each view config that lacks a permission
setting. Regardless of this setting, the original view is returned.
opts = info.options
if opts.get('permission') is None:
name_parts = [opts['view'].__module__, opts['view'].__name__]
if opts['attr'] is not None:
edelooff /
Created Oct 1, 2014
Drawing tileable hexagons with PIL + Aggdraw
"""Module for drawing of randomly colored, tileable hexagons."""
import math
import random
from PIL import Image
from aggdraw import Draw, Brush
class HexagonGenerator(object):
edelooff / gist:1d280ec2745248295dae
Created Jun 9, 2014
reST article to demonstrate pelican issue #1369
View gist:1d280ec2745248295dae

Automatic post summary causes weird line numbers in code-block

Date: 2014/06/09
tags:Pelican, reStructuredText

This article is a demonstration for Pelican issue #1369. The SUMMARY_MAX_LENGTH is set to 100 words, which means that index pages will list the first 100 words of this article. This includes a portion of the below code snippet, which configured to have its line numbers in a table.