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

As a Godless heathen, I have no scripture from which to guide me in my day-to-day life, and I must look for meaning elsewhere. I believe I have found that meaning in the most unlikely of places; the Python shell. If you enter import this in to the Python interpreter, it will reveal to you an ancient wisdom in the guise of a collection guidelines for the Python language.

I have studied these words for many years and have come to believe that they are in fact guidelines for living a fulfilling and successful life. continue reading…

I've been toying with optimizing the caching on my blog recently – for my own interest (this humble blog doesn't get all that much traffic). All the same, any speed improvements will only mean snappier page-loads and greater capacity to handle a slashdotting, or similar.

I discovered that Nginx has a memcached module that can serve pages directly from memcached without touching the file-system, or a downstream web-app. Which makes for very fast response times. To get it working, you need to set a cache key named with the url of the page, and the value to the HTML. Alas, this means that it would not work with Django's caching mechanism due to the way Django caches unique pages based on the contents of the request header. continue reading…

In my last post I introduced extended-markup, which is the light-weight markup system used to generate posts in Django-Techblog. I'll cover a few other things it can do in this post.

When the Post model is saved to the database, the extended markup is parsed in to a structure that is basically a dictionary containing a list of chunks, and associated variables. The order that the chunks appear in each section is the same as the order they appear in the markup, unless a chunk variable called priority is defined. This causes the chunks to be sorted in descending order of priority, chunks without a priority value are assigned a default of 100.

Here is an example of two chunks with a priority value assigned: continue reading…

Django Tech Blog is now running my blog. It is only fitting that my first post on the new system is about the technology behind it.

I never intended to compete with Wordpress on number of features, and Techblog was never intended to be an all-things-to-everyone type of web application, but I can boast a few features that set it apart. I'll cover some of those features in future posts, for now I would like to go over the light-weight markup language I use for posts. continue reading…

The new Django blog system I have been working on is virtually finished, I'm just testing it at the moment. Now I know that by writing my own blog system I will miss out on all the capabilities of a full featured and mature system, such as Wordpress; but my new system -- which I call Django Techblog -- has a few features that Wordpress doesn't, but more importantly, it works just the way I want it to.

One of those new features is the ability to insert syntax highlighted code in to comments, which is very useful for a techy blog! I've created a post on the beta site, and I'd like to invite you to pop over and test the commenting system. I'll delete the comments when I'm satisfied it is working nicely and I can replace www.willmcgugan.com. So feel free to play about with it...

Please test the comment system on this post. Django Techblog was build for my own needs to be able to easily display code in posts and to allow readers to insert code in to comments without linking to external sites.

To insert code in to a comment use the [code] tag, you may optionally supply a language to syntax highlight the pasted code. For example [code python]import this[/code] should produce something along the following lines:

Some other tags you can use are: [b] [i] [s] [size] [url] [quote]

To get things started, lets pretend we are discussing the following piece of code which is in use in this blog, and is used to send out mails when a comment is made. The decorator is my version of Django's signals, which I will probably blog about at some point!

It's not easy being a Scotsman in England. Some of the locals have difficulty understanding my accent. I'm living in Oxford now, but it was the same in London. Recently, I had trouble ordering a coffee...

Me: Hi. I would like a tall white Americano to take away please.

Coffee guy: (shouts) Tall black Americano to go.

Me: Sorry, white.

Coffee guy: (shouts) Two Americanos to go.

Me: No, no. A white Americano.

Coffee guy: Both white, or just one?

*sigh*

Django has pretty good support for caching, which is one of the easiest ways of speeding up a web application. The default is to cache for ten minutes, which means that if you get multiple requests for a page within a ten minute window then Django can serve up a stored copy of the page without hitting the database or rendering the HTML. The caching period can be set per-page and fragments of pages can be cached rather than the whole, but the system rests on the fact that it doesn't matter if the content doesn't change for a period of time. continue reading…

Since Net Communities have their new developer, I can post the coder test I wrote to find a replacement. The test was not meant to be particularly challenging, and we only requested that developers do one out of the three problems. Most developers did all three--presumably in an effort to impress--but nobody got all three correct, first time around. That was probably my fault, because the third problem had a subtle issue that is easy to overlook.

I'll quote the problems here, including typos. Occasionally the way I phrased things was slightly ambiguous, but I didn't penalize if the candidate misunderstood a requirement due to my use of language.

Example input:

microsoft

apple

microsoft.

Apple?

security

microsoft

internet

Example output:

microsoft 3

apple 2 continue reading…

I've been working on a blog system in Django lately. I know, I know. Everyone is working on a blog system in Django. I'll discuss how I justify writing a new blog system when there is Wordpress and some excellent existing blog apps for Django. For now, I would like your opinion on the basic design. Here's a screenshot. Be honest, but if you think it sucks, you may make me cry -- I've been working on it for weeks!