36 entries tagged
Having got the first working version of the Picky Picky Game,
I have naturally now pulled it apart again. I decided
that now it is in a state where it makes sense to try to
package up a version for Adrian to try installing, I better
think about getting the module and package names right, since it
will be harder to change them later.
I have reorganized my Python classes in to their own
pdc (designed to prevent name collisions
with WWW-oriented packages by other people). I also
changed some of the file names—so that ‘
httputils’ becomes ‘
from pdc import
There is now a proper
suite for the
module (which has functions like
xmlencode). This is
easier to do for this odule than the others, which tend to
involve creating scads of HTML text which will be hard to check
for errors. For the URL-manipulating functions, the unit tests
turned out to be invaluable—there are a lot of corner
cases that I only sorted out because I had tests for
all of them.
Paint Shop Pro 8 (a
Windows paint program) is out in beta and uses Python as its scripting
engine. It also has new distortion and fancy brush features.
During an attempt to better organize a collection of T-SQL scripts I came
across a strange behaviour when converting Windows
ANSI (8-bit character data) to Unicode (16-bit character data)
which appears, surprisingly, to involve the ancient
convention of using Ctrl-Z (character 0x1A) to end files.
What do you mean, Ctrl-Z?
I’ve been amusing myself by concocting an
reader using XSLT to do the processing.
XSLT can even handle the downloading of the RSS
files, but this does not allow for caching or
aggregating—so I thought I would knock
something together in Python.
To make it easier to create pictures for the Picky
Picky Game, I have added code to automatically convert
Microsoft Windows Bitmap (
.bmp) files into
This is straightforward because I already was using PIL to check the
dimensions of the images. Converting to PNG (if the format is
one PIL knows) is pretty simple:
permittedTypes = ['image/png', 'image/jpeg', 'image/pjpeg', 'image/gif']
if not imt in permittedTypes:
buf = StringIO.StringIO()
data = buf.getvalue()
logger.log(slog.WARNING, 'Converted your image from %s to image/png' % imt,
'This may have lead to a slight loss of image quality.')
imt = 'image/png'
The above goes in the sequence of checks on uploaded images
(after the check for width × height, but before the check
for number of bytes). I think I spent longer creating
a BMP image to test it on than I did writing the new code!
The advantage of BMP support is that, if you have Microsoft
Windows, then you definitely have Microsoft Paint installed.
So long as you know about Start menu → Programs →
Accessories → Paint, and the Image → Attributes menu item,
you can create panels for Picky Picky Game.
My Percy Street comic strip is
published on-line at 100 dpi, using HTML to arrange the panels on the page.
I draw the pages at 300 dpi, which should be just high
enough resolution to print on paper. The printed version uses
PDF rather than HTML to
lay out the page. (The page has to be laid out because
I am drawing each panel as a separate image.)
Were you foolish enough to be creating a web application with ASP, then you will be used to
Write method of the
object to stream HTML to the web browser of your client. Today
I got caught out by a serious limitation of the implementation
Response.Write. (And this is not the first time
it has leapt out and bit me, either.)
I learned to use one of Microsoft’s many abandoned APIs this week:
the Data Access Object library.
I have decided to change the way my home site works. Up until now I
have been writing entries by creating a quasi-XML file containing the
HTML text; I am changing the format to be quasi-RFC-822: a text file
with a short header section at the top.
The text is translated to
HTML via the usual hacked-together nest of regexps.
My website is maintained by a rather complex amalgamation of software,
accreted over generations. Having migrated it from my old desktop
lickity to my new(ish) PowerBook Ariel, I now want to migrate it
again to my new server Tranq (a Tranquil PC T2); this will allow me to use
cron to keep
some parts up-to-date automatically.
I am still in the process of converting my website-maintaining
to work on Debian GNU/Linux rather than Mac OS X. Last episode left me
with a conundrum as how to convert SVG files to PNG for the sake of
browsers that cannot display SVG properly.
At work I keep my work-log and my work plan in one big XML document
(actually one per client, for the sake of limiting the enormity of the
files). This single document is then sliced and diced through various
XSL transforms to create different views: for example, when you look at
the entry for one task, you see all the notes describing that task and
the work I did on it, and when you look at the log for a particular day,
you see the notes for that day regardless of which task they belong to.
Nowadays my web presence (such as it is) is split over several sites
(Flickr, Delicious, LiveJournal, etc., as well as
this site). I want my home page to include pointers to these other sites--such as
the Flickr badge I described in the previous article.
To do this I need to download feeds from these other sites in order to
mix them in to my home page. I wrote a Python program called
wfreshen to do this.
I thought I might have a go at familiarizing myself with TurboGears, one of the new
Python web frameworks, by writing a new and improved clone of the
Picky Picky Game. Step one was verifying that I can upload pictures
easily. Step two was getting an identity system put together. Creating
a registration page and log-in form and so on is the obvious and dull
solution, so I thought I’d have a go at exploiting OpenID instead.
With all this buzz about OpenID all of a sudden I have been reminded
of how a while back I was tinkering with a TurboGears-based web game
using OpenID (see parts 1, 2, 3). Having learned more
about WSGI and Python Paste I am inclined to see how far I can
push the idea of writing web applications using WSGI and a collection of
WSGI filters as my framework.
Yes, I have redesigned my archive pages—that is, the ones where all the entries apart
from the most recent live, and the index pages for navigating between them. To see the new look you can visit the archive page for this entry.
Programmers learn through programming, and my research into OpenID
has got as far as a web application that lets you do nothing at all
except log in with OpenID. Along the way I have played a bit with
Canonical’s own object-relational mapper (ORM) called
I’ve just run my first client program against the CouchDb server. It doesn’t do much yet, but it shows that I’ve managed to install and build the thing successfully.
I have been experimenting with CouchDb by creating the beginnings of a
Python API for it. It is not really ready for prime time yet, but in
best free-software tradition I am publishing early and will add to it
when I have time.
C# Does not have a nice way to represent a dictionary as a single value: you can only
create an empty dictionary and add entries one by one. Which is annoyingly verbose if you
are used to a more reasonable programming language,
My current project at work has involved a quick-and-dirty crash-course in Drupal, a content-management system written in PHP. Here are some of my initial impressions.
Work on jeremyday.org.uk, the replacement for www.jeremydennis.co.uk continues apace. I’ve used spreadsite to create a projects list (which needs updating), created a new version of the The Weekly Strip archive, and had a long talk to Jamie Lokier about how caching should work on GNU/Linux systems and the WWW in general. Also I have created a new Atom feed for TWS.
It took me a weekend but I finally got Python 2.7 + PIL (Python
Imaging Library) working on my old PowerBook G4 12″ (which
runs Mac OS 10.4 Tiger). The problems I was having were partly because
of a mismatch between pre-compiled. and build-from-source packages.
I have started working on a little utility program for assembling
Minecraft texture packs. Its working title is
Minecraft Texture Maker. With it I an do mundane tasks like assembling the files in a
directory in to the ZIP archive that gets published, and also create new
texture packs by remixing existing ones. I have a vague ambition to
elaborate it in to a web app for remixing packs, but it is useful
I have a small Python project and would like to make it easy for
people to download and install it. Ideally it would be on the Python
Package Index PyPI (because if it isn’t on PyPI it does not
exist) with the proper dependency information to allow it to be
installed with commands like Pip. So what do I do?
I have created a web app called Texturejam to host remixes of
Minecraft texture packs. The idea is to host Texturepacker in a form
palatable to people who might want to use it.
I believe in Test-Driven Development but had somehow had never
gotten around to using mock objects until a few months ago. They’re
super-useful when testing classes that write to files or query remote
databases or what-have-you, or when the rest of your system is big and
hairy and setting up tests takes ridiculously more work than the test
I have installed PyPy on my server and switched my Kanbo test server to run on PyPy.
When I upgraded my iMac to Mac OS X 10.8 Mountain Lion it upgraded Python to
2.7.2, which is nice, but also lost my site-specific changes—such as the
installation of pip, virtualenv and virtualenvwrapper. These three
basic tools allow me to create isolated Python installations and install
packages in to them. So it was time to try to work out the neatest way to get
things set up again.
It has taken only ten years but we now have SVG support as good as it was ten
years ago using Adobe’s SVG Viewer plug-in in Netscape 4. I have decided it is
about time I resurrected my 2002 project, the Alleged Tarot.
I have started building a toy web application to give myself something to
But first I needed a fake data server to supply the data for it to serve.
As part of my new hobby to build a computer keyboard, I have to draw
the instructions for the cutting of the plate the switches are held in (see previous post for more on
what the plate is).
Rather than learn how to install and use a CAD system to do this, I
have written a Python module to do it for me.
My last Mac OS update replaced Python, which as usual broke the virtualenvs I
use and when building a new virtualenv it seemed like as good a time as any to
upgrade to Python 3 and Django 2.0. This lead to a lot of ‘adventures’
as I discovered how well Python 3 is or isn’t supported in my setup.
My web site settings file is broken so I might as well fix a few things.
I worked out why my ancient photo albums were broken.
Here’s a quick note about how to write tests for Django models that need to
queue Celery tasks when they are created.