will

Where there is a Will

Will McGugan's Blog

I am a freelance software engineer living in Edinburgh.

I post mostly about tech (particularly Python) and photography.

Background: A code monkey

My entry for /r/WildlifePhotography competition

Male Atlas Beetle

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…

I climbed to the top of Arthur's Seat today. Alas, the clouds came in and I didn't get any decent shots.

Of course, by time time I got back down again, the skies cleared and there was beautiful golden hour sun. So I had to settle for this shot of Salisbury Crags.

A photo of Salisbury Crags, in Edinburgh Scotland.

Tony Northrup does a great job of picking apart various myths and misconceptions regarding photography. His channel is full of other great stuff on photography.

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…