Python Design Patterns

After going through https://python-patterns.guide/, I decide to use some simple, contrived Python programs to get familiar with several Python-compatible patterns. In this article, I'll show four design patterns that are fully compatible with Python and very easy to use: the observer pattern, the strategy pattern, the decorator pattern and the flyweight pattern. The observer pattern The observer pattern is a behavioral design pattern where an object, known as the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes. ...

August 29, 2025 · Walden Cui

Curse of knowledge

There is a kind of sadness that comes from knowing too much, from seeing the world as it truly is. It is the sadness of understanding that life is not a grand adventure, but a series of small, insignificant moments, that love is not a fairy tale, but a fragile, fleeting emotion, that happiness is not a permanent state, but a rare, fleeting glimpse of something we can never hold onto. And in that understanding, there is a profound loneliness, a sense of being cut off from the world, from other people, from oneself. ...

September 4, 2024 · Walden Cui

The Golden Verses of Pythagoras

1 First worship the Immortal gods, as they are established and ordained by the Law. 2 Reverence the Oath, and next the Heroes, full of goodness and light. 3 Honour likewise the Terrestrial Daemons by rendering them the worship lawfully due to them. 4 Honour likewise your parents, and those most nearly related to you. 5 Of all the rest of mankind, make him your friend who distinguishes himself by his virtue. ...

July 1, 2024 · Walden Cui

Postgresql15 Django Setup

How to setup databases for your application and testing? Database creation CREATE DATABASE mydb; CREATE DATABASE test_mydb; CREATE USER me WITH PASSWORD 'password'; -- Connect to mydb \connect mydb; -- AWS quirks GRANT me TO POSTGRES; -- Create a schema with me as owner CREATE SCHEMA my_schema AUTHORIZATION me; -- Create an extension CREATE EXTENSION postgis SCHEMA my_schema; -- Connect to test_mydb \connect test_mydb; -- Create a schema with me as owner CREATE SCHEMA test_schema AUTHORIZATION me; -- Create an extension CREATE EXTENSION postgis SCHEMA test_schema; GRANT ALL PRIVILEGES ON DATABASE my_db TO me; -- Settings recommended by Django doc ALTER ROLE me SET client_encoding TO 'utf8'; ALTER ROLE me SET default_transaction_isolation TO 'read committed'; ALTER ROLE me SET timezone TO 'UTC'; The DATABASE_URL will be DATABASE_URL='postgresql://me:password@myHost:myPort/mydb?options=–search_path%3Dmy_schema,test_schema' ...

April 10, 2024 · Walden Cui

On Learning

10 Things Software Developers Should Learn about Learning Human memory is not made of bits A large chunk of learning is about remembering. Yet a human's memory is quite different from a computer's memory. We commit to our memory what we want to remember often imprecisely. The addition of related or unrelated memories may distort it ("spreading activation"). Not to mention the fact that we constantly forget what we learned as long as we don't use it. Overall it is a haphazard event. ...

January 8, 2024 · Walden Cui

A Recluse

I'm spending a little time each day to read some traditional Chinese literature. Recently I've been interested in a book that can be dated to the early Zhou dynasty. I Ching was believed (by some) to be written by King Wen of Zhou when he was a prisoner at Youli, apparently before 1000 BC. If it is true, this is currently the oldest book that I've ever read. What I'd like to share today is some comment on the first stacked line of the hexagram qian (䷀) from Confucius. ...

December 17, 2023 · Walden Cui