Recent Posts (Page 15)

A Git Check for Missing Commits From a Remote

I recently add a pre-flight check to a devops project to ensure that all commits from the Git repository’s origin/master are present locally. This is to guard against developers accidentally reverting others’ deployed changes.

Read more...

Simplify Your If Statements That Return Booleans

Here’s a hint I have found myself repeating in code review. I learnt this from my university lecturer Tony Field, who probably repeated it in every lecture! He was teaching us Haskell, but it applies to Python, and most other programming languages.

Read more...

Make Django Tests Always Rebuild the Database if It Exists

If you use Django’s test runner, you’ll probably have encountered this message:

Read more...

Feature Checking versus Version Checking

Bruno Oliveira, known for his work on the pytest project, tweeted this thread last July:

Read more...

My Most Used pytest Commandline Flags

pytest is quickly becoming the “standard” Python testing framework. However it can be overwhelming to new users.

Read more...

Limit Your Try Clauses in Python

Take this code:

Read more...

Word Counting My Whole Site

My site is static HTML, built with Jekyll (more details in my colophon). This means I have a folder that contains the whole site in HTML files.

Read more...

Losslessly Compressing My JPEG Photos with jpegoptim

I’ve recently been running low on disk space on my laptop. I’ve freed some by removing files, but I’ve also been looking for ways to save space through compression.

Read more...

Working Around Memory Leaks in Your Django Application

Several large Django applications that I’ve worked on ended up with memory leaks at some point. The Python processes slowly increased their memory consumption until crashing. Not fun. Even with automatic restart of the process, there was still some downtime.

Read more...

A Single File Asynchronous Django Application

Django 3.0 alpha 1 came out this week. It introduces ASGI support thanks to lots of hard work by Andrew Godwin.

Read more...

Python: how I import the datetime module

Python’s datetime module risks a whole bunch of name confusion:

Read more...

Adding EC2 Instance Recovery Alarms with CloudFormation

Instance Recovery is a little-advertised, little-used feature of EC2. It doesn’t take long to set up and promises to recover your instance on the rare occasion that the underlying hardware fails. Recovery resumes the instance on new hardware, retaining its instance ID, private IP addresses, Elastic IP addresses, and all instance metadata.

Read more...

Jef Raskin on Why Software Is the Way It Is

I was reading 37signals’ Getting Real the other morning, and was struck by this quote in the chapter Embrace Constraints:

Read more...

My Appearance on DjangoChat

A few weeks ago I had the pleasure of talking over the internet with Will Vincent and Carlton Gibson about lots of Django-related topics. They somewhat informed me it was being recorded for a podcast.

Read more...

A Minimum Viable CloudFormation Template

Sometimes when testing CloudFormation features I need a minimum viable template to try that feature with.

Read more...

How to Add Database Modifications Beyond Migrations to Your Django Project

On several Django projects I’ve worked on, there has been a requirement for performing database modifications beyond Django migrations. For example:

Read more...

Feature-Policy updates - now required for an A+ on SecurityHeaders.com

In my blog post and DjangoCon Europe talk earlier this year How to Score A+ for Security Headers on Your Django Website, I covered that Feature-Policy was a “bonus header”. In a recent update, Scott Helme wrote that an A+ on SecurityHeaders.com now requires Feature-Policy. Also it no longer requires X-Xss-Protection (though it’s still a good idea).

Read more...

Validating CloudFormation Templates With cfn-lint

I’ve been working with CloudFormation in some form for about five years now. Two years ago at Time Out, I helped write an in-house tool that performed some basic template linting. One year ago at Genus AI, I started using the AWS Labs tool cfn-lint to validate my templates before deployment. It’s really neat, covers a lot more than our in-house tool did, and has saved me from a number of mistakes.

Read more...

Django’s Test Case Classes and a Three Times Speed-Up

This is a story about how I sped up a client’s Django test suite to be three times faster, through swapping the test case class in use.

Read more...

Tuples versus Lists in Python

One thing I often ask for in code review is conversion of tuples to lists. For example, imagine we had this Django admin class:

Read more...

Celery, Rabbits, and Warrens

Every time I pick up the Python job queue Celery after not using it for a while, I find I’ve forgotten exactly how RabbitMQ works. I find the Advanced Message Queuing Protocol (AMQP) concepts drop out of my head pretty quickly: Exchanges, Routing Keys, Bindings, Queues, Virtual Hosts…

Read more...

All Is Turned to Black

If the title worried you about my mental state, you can relax. It’s about the Python code formatter Black!

Read more...

PyLondinium 2019 Notes

PyLondinium ran for the second time last weekend. It’s a three day conference from Friday to Sunday, held in central London at the Bloomberg office.

Read more...

Running CloudFormation Drift Detection on All Your Stacks

CloudFormation’s stack drift detection feature is useful. It discovers ways your infrastructure that you beautifully set up with Infrastructure-as-Code has been fiddled with manually. Often this results from a “quick temporary fix” being applied manually on the web console at 2am, then forgotten about.

Read more...

The Simplest WSGI Middleware

My library apig-wsgi bridges between AWS API Gateway’s JSON format for HTTP requests and Python WSGI applications. Recently Théophile Chevalier opened an issue requesting the library add an extra WSGI environ variable. I closed it by pointing out that it’s not much code to add a custom WSGI middleware to do so (plus the exact key is a bit out of scope for the library).

Read more...