Skip to content

Instantly share code, notes, and snippets.

View clean_architecture_in_django_options.md

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.

View green-energy-blog-post.md

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".

View sync.py
import hashlib
import os
import shutil
from pathlib import Path
def hash_file(path):
hasher = hashlib.sha1()
with path.open("rb") as file:
while buf:= file.read(hasher.block_size):
@hjwp
hjwp / test_enums.py
Created Oct 27, 2020
Better string enums
View test_enums.py
import random
from enum import Enum, IntEnum
class BRAIN(str, Enum):
SMALL = "small"
MEDIUM = "medium"
GALAXY = "galaxy"
def __str__(self) -> str:
@hjwp
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"]
View mymodule.py
def foo() -> int:
return 42
@hjwp
hjwp / bowling.py
Last active Nov 23, 2019
Bowling TDD Kata
View bowling.py
STRIKE = 'X-'
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])
else:
@hjwp
hjwp / domain_model.py
Last active Feb 14, 2019
sqlalchemy mapping minimal example
View domain_model.py
'''stripped-down domain model, just order and warehouse'''
from __future__ import annotations
from dataclasses import dataclass
@dataclass(unsafe_hash=True)
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
WORKDIR /tmp
View index.html
<htmL>
<head>
<title>Hello, Greetings</title>
</head>
</html>