will

It's All Geek to Me

Posts about technology, with a focus on web development with Python.

I am the author of Beginning Games Development with Python and PyGame.

Just landed in inthing is a new and quite interesting feature.

Version 0.1.4 adds a capture method which will record all standard output, i.e. anything you print to the terminal. It works as a context manager. Here's an example:

Any print statement inside the with block will be captured and posted online with the block exits.

You can also do something similar from the command line, with the inthing capture subcommand, which posts anything you pipe in to it as an event.

lets say you wanted to post the version of all you installed Python packages online. You could do something like the following:

For more information see the Inthing docs.

Inthing is still technically in beta, but these features are quite solid. Please give them a try, and let me know how it goes!

The Django code in this post comes from the official Django tutorial.

I've tried not to be disingenuous with the comparison, and I'm only going to compare like with like, so I can show code from both frameworks and let you draw your own conclusions. I'll cover the areas where they differ in another post.

Both Moya and Django use models to map databases on to familiar data structures. In the case of Moya, the mapping is done with SQLAlchemy. Django uses its own ORM.

Here's the models.py from the Django tutorial and a Moya version: continue reading…

Have you ever needed to test multiple user accounts in your web app?

If you need to check your permissions are working correctly, you might find you are constantly switching users by logging in and logging out. Or you could have an admin user signed in to Chrome, and another user signed in to Firefox. Either way, its a bit of a pain.

Here's a simpler solution; define multiple aliases to 127.0.0.1 in your /etc/hosts file. That way you can have one tab open at http://adminuser:8000/ and another open at http://user1:8000/ with two entirely different user accounts.

This assumes of course that you have a development server running locally, and that your app is configured to serve to these 'domains'.

For example (append this to /etc/hosts):

I spent an evening adding 'progressive' loading of the title images to my blog.

The title images for this blog are 3840 × 2160 and a hefty ~650K each. That's entirely intentional; as a photographer I wanted them to look as sharp as possible and take advantage of high pixel density screens.

The only downside of hi-res photos is that even with a good internet connection, you can still see the photo loading as the browser reads the JPEG. It's visually jarring and way too reminiscent of the web, circa 2000s.

A reasonable solution is to first download a smaller lower-resolution version, then load the full resolution image on top of that. So the user sees something relatively quickly, without the visual contrast of an image loading on a blank background. continue reading…

One of my goals for inthing.io was to make posting events realtime, in that events appear without a page refresh, and within a fraction of a second. And that largely seems to work.

Here's a quick screencast that shows it working:

I'll post about how it works in detail at some point, but the general gist is that there is a Tornado websocket server that inthing uses to broadcast information about updates. That server may be worth open-sourcing if there is enough interest. It could be useful for other projects, and its entirely independent.

There a few options, but I'm going to suggest using the inthing Python module.

First install inthing with PIP. You'll probably know if you need to use sudo or not:

Now fire up Python, and enter the following (copy and paste each line after the >>> prompt):

So far so good. We now have a Stream object called stream, with a corresponding live page on the web. We'll have a look at that later, but lets first do something interesting with it. Enter the following function (copy and paste all the text after the >>>):

If that pasted correctly, we should have a function that generates the Mandlebrot set in ASCII. Add it to the stream with the following:

Finally, to get the URL of the stream, do this:

If you visit that URL, you should see the Mandlebrot set you just generated. continue reading…

From one capital to another; I have moved from London to Edinburgh!

I'm looking forward to connecting with Edinburgh Pythonistas, techies and/or photographers. Get in touch if you would like to meet up for a beer or coffee.

Here's a few Edinburgh photos. You can tell by the sunshine that they are not recent shots...

A view from Calton Hill at sunset.

Edinburgh has some grand buildings.

An alternative view from Calton Hill.

A view of Edinburgh from inside the Nelson monument.

I'm happy to announce release 0.6.0 of Moya.

Moya is a web-application platform written in Python. In that respect it is a lot like other Python frameworks such as Django, Pyramid, Flask, Bottle etc. Moya has versatile URL routing, a fast template language, an ORM, a forms library, i18n support, image processing, and a variety of other tools to build a modern web app. Where Moya differs from other Python frameworks in that Python is not required to make use of these features. continue reading…

Raspberry Pis are useful little computers. I own several, since I work with them in my day job, and I thought it was about time I put one to use.

I also happen to keep tropical insects. Specifically, beetles. These are not your garden variety beetles, unless you happen to live in a rain forest. The ones I have at the moment are elephant beetles which come from Central and South America. Here's a photo:

Male elephant beetle. Banana for scale.

These insects are mostly nocturnal. During the day they tend to burrow under their bedding material (moss), or hang out on a branch. But during the night, they can be quite active. I know this because in the morning they have re-arranged the branches in their tank. continue reading…

Moya's template language is a spiritual successor to Django, and Jinja templates. It borrows a number of constructs from both, and adds a few of its own.

There is a slight difference in the syntax in that variables are substituted with ${variable} rather than {{ variable }}, but tags still use the familiar {% tag %} syntax.

Template languages are generally quite extensible, so there is probably nothing that Moya templates can do that Django / Jinja can't (via a plugin or extension), but there are a few things which are I think are more elegant in Moya's templates language (and built-in). I'm going to talk about a few of them in this post.

How often have you written code like this? continue reading…