Skip to content

Instantly share code, notes, and snippets.


How to do clean architecture in Django - some options

Assumptions & Context

Assumes an existing Django app with substantial complexity, and the intuition that "clean architecture" might solve some problems.

Django's sweet spot is rapid application development, CRUD, low to moderate domain complexity / application size.


Are Green Electricity Tariffs a Waste of Time?

I've been looking into "green energy" tariffs recently. tl;dr: mostly, they're equivalent to voting Green in a safe Labour seat. A protest vote, with minimal immediate impact.

This was prompted by a friend expressing skepticism about them, words to the effect of "just rearranging slices in the pie chart, without changing any of the sizes".

import hashlib
import os
import shutil
from pathlib import Path
def hash_file(path):
hasher = hashlib.sha1()
with"rb") as file:
while buf:=
hjwp /
Created Oct 27, 2020
Better string enums
import random
from enum import Enum, IntEnum
class BRAIN(str, Enum):
SMALL = "small"
MEDIUM = "medium"
GALAXY = "galaxy"
def __str__(self) -> str:
hjwp / default-acl.json
Last active May 4, 2020
Eventstore perms bug repro
View default-acl.json
"eventId": "7c314750-05e1-439f-b2eb-f5b0e019be72",
"eventType": "update-default-acl",
"data": {
"$userStreamAcl" : {
"$r" : ["$admin", "$ops", "test-user"],
"$w" : ["$admin", "$ops", "test-user"],
"$d" : ["$admin", "$ops"],
"$mr" : ["$admin", "$ops"],
"$mw" : ["$admin", "$ops"]
def foo() -> int:
return 42
hjwp /
Last active Nov 23, 2019
Bowling TDD Kata
def score_frame(frame, next_frame):
if frame[:2] == STRIKE:
if next_frame == STRIKE:
return 20
if next_frame is LAST_FRAME:
first_ball_next_frame = int(frame[2])
second_ball_next_frame = int(frame[3])
hjwp /
Last active Feb 14, 2019
sqlalchemy mapping minimal example
'''stripped-down domain model, just order and warehouse'''
from __future__ import annotations
from dataclasses import dataclass
class Line:
sku: str
qty: int
View Dockerfile
FROM ubuntu
RUN apt-get update && apt-get install -y -q python3.7 python3.7-dev python3-pip git
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
RUN pip3 install pip pipenv
View index.html
<title>Hello, Greetings</title>