Articles in the How-It-Works category

Lessons from UTF-8

By Eric — — 2 minute read

XKCD Standards

The famous XKCD comic includes "character encodings" in its list of proliferating standards, and it is no joke. There are dozens, just counting the ones in common use. But the UTF-8 encoding seems unique in that it didn't just add one more, but is managing to legitimately become that one …

Read more...

Python Time 2025

By Eric — — 2 minute read

A quick reference for time...

Get the current time in UTC

from datetime import datetime, UTC

datetime.now(UTC)
datetime.datetime(2025, 1, 28, 23, 4, 45, 419714, tzinfo=datetime.timezone.utc)

You might think you should use datetime.utcnow() but:

Deprecated since version 3.12: Use datetime.now() with …

Read more...

SQLAlchemy Cascade Delete: Clarity through Examples

By Eric — — 11 minute read

Since there is overlapping "cascade delete" functionality supported by SQLAlchemy -- with the ORM handling some deletes and the database itself handling others -- it can be hard to know the right way to set it up. Here are some examples to help clarify how it all works.

Starting Example

Here we …

Read more...

Public Key Cryptography Made Easy

By Eric — — 2 minute read

Learning about cryptography can be discouraging. You get so bombarded by "don't invent your own", "you're doing it wrong", and "even really smart people screw this up" that you wonder why you even bother to try. For me, the answer is because if you don't learn it, someone who knows …

Read more...

SQLAlchemy with Python 64-bit on Windows

By Eric — — 2 minute read

While hooking up SQLAlchemy for a web project, I kept running into attribute errors for 'session_registry'. I figured I was doing something wrong, so I thought I'd just walk through the tutorial as a sanity check.

I was, apparently, insane.

>>> u = session.query(User).filter_by(name='ed').first()
Traceback (most …

Read more...

Python Packaging (2013 Edition)

By Eric —

About a year ago, I set out to get a solid working understanding of Python packaging, resulting in a lengthy blog post of what I learned. There have been some significant course changes over that year such that my original post is wrong in several regards.

Here's a summary of …

Read more...

Python Packaging Demystified

By Eric — — 6 minute read

IMPORTANT: Some of the information in this post is now obsolete. Please see here.

Randomly take a couple of words from the following list, put them together, and there's a decent chance you'll come up with something real involving Python packaging.

  • setup
  • install
  • dist
  • distribute
  • tools
  • utils
  • easy
  • py

The …

Read more...

MessageBox: Just Say Nein

By Eric — — 1 minute read

The Windows MessageBox is really convenient to use. A single line of code gets you a dialog box with a caption, a message, an icon and a set of available buttons that cover a lot of possible input scenarios. Unfortunately, the text on the buttons is supplied by the system …

Read more...

.NET Color Struct Equality

By Eric —

When is white not white? When one is Color.White and the other is Color.FromArgb(0xff, 0xff, 0xff, 0xff).

I was trying to data bind a list of colors to a ComboBox and have the SelectedValue property bound to a particular color. The frustrating thing was that even though …

Read more...

.NET Cold Startup Performance: More

By Eric — — 2 minute read

A few months ago I wrote about an approach to improving .NET cold startup performance. Here's a little more information that I've learned since then.

Another useful tool for optimizing cold startup is Microsoft's free CLR Profiler 2.0. While this tool has the aesthetics of a wadded-up paper sack …

Read more...