*
A collection of arcane, and perhaps at times the most inane of my thoughts.

When a borg bonks the head

Stumbled upon an interesting trick with Python thanks to a talk on design patterns. The Borg design pattern is new to me, as a replacement for the simpleton. What caught my attention is the way it handles shared state instead of a shared singleton object.

A while back, working with Twitter's streaming API, it came in handy to work with incoming JSON data.

Python objects (modules, instances) hold symbol data and state in a special dict. The hack with the Borg pattern is to reuse this with a shared state dict. Nifty indeed.

I've in the past had flows where I use the setattr on a dict.items() but the simplicity of this one, 🤯

Gist that I used to create nested objects.
Borg design pattern / Repo.

The linked repo contains a handful of Python design patterns; a treasure trove of a reference.

August 2021 (3)July 2021 (1)June 2021 (1)May 2021 (4)April 2021 (6)March 2021 (6)February 2021 (1)November 2020 (11)