A collection of technical articles, primarily on programming.

  • Pickling Python collections with non-built-in type keys and cycles.

    written on 16 Sep 2014 in category Python

    A presentation of various problems and an effective solution for pickling Python collections with non-built-in types as keys and cycles or self references. Applies to dictionaries, default dictionaries, ordered dictionaries, sets, and ordered sets, at all levels of the pickle and cPickle protocol, in Python 2 and 3. The entirety of the implementation is available as an open source package python-restorable-collections.

  • Collatz sequence generation performance profiling in Clojure (Project Euler Problem 14).

    written on 03 Aug 2014 in category Clojure

    I investigate the performance of several Collatz sequence generation algorithms through profiling Clojure code, inspired by Project Euler Problem 14 (no spoilers as I won't show the solution number in this article, however, if you run the code you will get the solution as the return value). My approach focuses on the number of specific operations of interest rather than clock time (but clock figures are also discussed).

  • Automating tree and graph visualisation unit tests in Python and Django.

    written on 29 May 2014 in category Python

    We deal with how to systematically test visualisations of tree and graph data structures in a frontend browser (rendered as SVG in JavaScript) from within a Python backend test framework.

  • Django application import and missed class_prepared signals

    written on 11 Aug 2011 in category Django

    Due to opaque application loading semantics within the Django i18n code, several model classes may be imported before a class_prepared signal listener connects, resulting in missing the signal entirely. Specifically, connecting to this signal from an application which appears first in INSTALLED_APPS, does not guarantee that it will execute when a class is first imported by any of the subsequent applications.

  • Propagating field changes in Django Model instance aliases

    written on 05 Apr 2010 in category Django

    Django's ORM creates multiple aliases for the same Model instance. In certain situations this may result in problematic behavior, as multiple operations on the same instance are interleaved, however, field access happens on different aliases of the instance, ultimately resulting in loss of updates.

  • Capturing invoking method information in Python

    written on 16 Mar 2010 in category Python

    The following decorator will capture all available information regarding the method which invokes the decorated method (the invoked method).

  • Ordering on a field in the "through" Model of a recursive ManyToMany relation in Django

    written on 06 Feb 2010 in category Django

    It is not possible to order a Django Model on a field of the Model acting as the intermediate through = ... of a ManyToMany relation, because queries will not return items in the correct order, and in addition will include duplicate items, even when using .distinct().

  • Duplicate items when ordering by Generic Relation in Django

    written on 27 Jan 2010 in category Django

    When the optional ordering = ... attribute of a Django Model's Meta class contains a GenericRelation from the Content Types framework, there is no way to eliminate duplicate items being returned, even when using .distinct() (since .order_by(...) is applied by the ORM only after the SQL SELECT DISTINCT clause is built).