A blog of Python-related topics and code.

A QR code generator in Django

The following code is the file for the make_qr app behind this QR code generator app. The qrcode Python package generates a Pillow Image object, which is encoded in base-64 for rendering in the template, saving the need for an intermediate PNG file.

Deleting Gmail messages by label with the Google API

Google's suite of APIs and their Python bindings can be used to delete emails automatically, saving the hassle of navigating page after page of 100 emails at a time. Setting up a Developer project, configuring OAuth access etc. is described on the Google Developers page here. Don't forget to add yourself as a Test User.

Modular arithmetic on a circle

Inspired by David Richeson's applet on GeoGebra the Python script below plots the lines joining pairs of points, evenly spaced on the perimeter of a circle according to the following algorithm: label the $n$ points $k=0, 1, 2, \ldots n-1$; then join point $k$ to point $mk\,\mathrm{mod}\,n$.

The Goat Problem

A goat is tethered on the perimeter of a circular paddock of grass by a rope of length $r$. What should $r$ be to allow the goat to graze on a maximum of half the area of the paddock?

Maurer Roses

A Maurer rose is a shape formed by connecting the points on a rose defined in the polar coordinate system by $r = \sin(n\theta)$ for some positive integer, $n$. The points to join are, in polar coordinates using degrees: