Stavros' Stuff

On programming and other things.

Show page generation time in Django

Ever longed for the good old PHP days? No? Good.

Earlier today, i.e. a few minutes ago, I was working on my latest guinea pig, TiThess. It’s an events guide for my city, and the latest project I’m trying everything on. I like having a project I can try new things on, as it helps keep my skills sharp.

As I was testing page load times with the excellent Web Page Test, trying to get them down to the absolute minimum, I was getting an F in time-to-first-byte. This is very odd, because the whole site is supposed to be cached, so I was wondering whether the cache is doing something wrong and slowing page generation down.

To make sure, I needed a simple way to show how long page generation took, like the old “page generated in X seconds” footer that was all the rage with PHP sites way back when. Here’s how I did it:

Continue reading…

The iRotary Saga

Wherein the rotary phone acquires electronics to connect to the mobile network and can function wholly unmolested

Welcome to part four of the iRotary trilogy! This is the part where we complete the project, along with the OFFICIAL TRAILER at the very end (spoiler alert!).

The original goal of this post was to complete the project, but I have delayed writing it for so long, that I think it would be better if I just started from the beginning, and produced one, cohesive narrative.

As you may remember from part one, I am a very angry person. Especially when talking on the phone, I get easily pissed off, and nowadays there’s no good way to express my frustration. I miss the olden days, where you had a nice physical handset you could slam into the phone to relieve your tension, but mobile phones just don’t provide the same pleasure. Undeterred, I set out to create a rotary phone that was also a mobile phone.

Thus, the iRotary was born.

Continue reading…

On API authentication

Make your API unhackable, like the Titanic

This post needs no introduction, so it doesn’t have one. If you want to write an API and need to know how to make it secure, and have the requests authenticate against a server or a client, look no further! Well, do look a bit further, because I’m going to tell you how to do all these things in this post.

Use cases

As with most other things, your API authentication method will depend on your use case. I will detail a few common ones, along with the best authentication scheme for each one:

Continue reading…

Standalone Django scripts: The definitive guide

Jeez, why is this so hard to find info on?

You know the deal, you have your fantastic Django application and it’s working great and everything, but you need to make a small change which is too cumbersome to do in the shell, so you figure “duh, I’ll just write a script to do it”. You write your external script in two minutes and then struggle for two hours to figure out how to load the models and the rest of the context so it will work with your app’s settings and all your Django goodness.

You visit StackOverflow and a bunch more sites, and they either tell you to use a management command, which is great advice, except your thing is a one-off and you don’t want to have to check it to git and go through all that hassle to get it deployed just to do this simple thing, or they give you some arcane lines that just don’t work.

Fear not, for I am here. I will give you five simple lines that will make everything work perfectly. Perfectly, I say!

Without further ado (all the previous ado was just so I could fill the paragraph so the side-box doesn’t look weird with short text), I give you the magic commands! Here they are:

Continue reading…

I took a picture: Hope

I took a picture: Hope

Hello! I took another photo! This time it’s rather dark, it’s a forest, at night, with an eerie light coming at the end of the path, through the fog. It has taught me three things:

  1. You don’t need many sophisticated adjustments to achieve most of the effects you will want to achieve. A few simple adjustments here and there can go a long way.
  2. I used to think that, when people said “I wanted to convey this specific feeling”, or “I wanted to achieve this objective with this piece”, it was bullshit. I see now that, oftentimes, you have a specific idea in mind and work towards it, as I did with this photo for the first time, for me.
  3. I shouldn’t dismiss mobile phones so easily. I didn’t have a camera with me at the time, and it was either “take the photo with the phone” or “don’t take it at all”, and I went with the former. It’s probably my favorite photo of mine so far, so you definitely won’t hear me dissing mobiles again. They can be very useful under specific circumstances (mostly when there’s a lot of light and you won’t need a large print).

In this post, I am going to show you the process from the initial, unedited copy, all the way to the final edit. Here’s the latter:

Let’s dive into the actual process, to see how it was created.

Continue reading…

Gweet: Messaging for your things

A message queue for the abhorrently named "Internet of Things"

As you may recall, I have hooked up various parts of my house to a computer so I can control them remotely. To do that, I have an HTTP server for which I open a port, and everything runs on this server, but what if I need to add another device? What if I need to have multiple devices listening for a command?

Having to open a port for each and every one of them, exposing them to the internet and configuring all this is a huge hassle, a security problem and very brittle. Wouldn’t it be much better if there were a centralized message queue where I could post messages and have an arbitrary number of devices read them?

It turns out, the excellent folks at

Continue reading…

I took a picture: Lethe & Seals

I took a picture: Lethe

WARNING: This post has nothing for anyone, it’s just me ranting about photography. Turn back now, you have been warned.

Apparently, photography is now a thing I like. It is also a thing I like a lot, so I have been doing it a lot. I’m not very good at it, but I’m blessed with not caring much about how good I am at a thing I like doing, which is apparently how you get good at things. I decided to write about photography-related things, even though I’m wildly unqualified, because I like having a sort of progression log.

A few days ago, I stumbled upon the ethereal photography of Darren Moore, and immediately fell in love. The outworldly appearance of his photographs

Continue reading…

iRotary - Part Three

Phone slam 3: The slammening

In part two of project iRotary, we actually got the phone to make calls, but we couldn’t talk or hear the other person. In this part, I promised you some hardcore microphone-to-headset action, and that’s exactly what I won’t deliver!

Instead, what I did was to procure the gorgeous phone you saw in the previous posts. That’s right! All this series so far has been a ruse! I didn’t have that phone to start with, I didn’t have it at all!

However, I do have it now, and I managed to enclose the Arduino in the actual phone. Let’s see how that happened.

Continue reading…

iRotary - Part Two

Working towards a phone I can slam

In part one of project iRotary, we got the Arduino to detect pulses from a rotary dial and turn them into a phone number, all in the name of turning this phone:

into a mobile phone I can use on the go. In part two, we will actually connect the Arduino to a GSM shield and place calls with the rotary dial like it’s 1993. I have seen the future, and it is the past. Read on for details!

Continue reading…

iRotary - Part One

Finally, a phone I can slam again!

Lately, my mobile phone (an HTC One) has become very slow. I think it’s mainly SwiftKey, which is slow like dog, but no matter. As a good consumerist, I must purchase a new phone. However, I am also an angry person, and I sorely miss the tactile sensation of slamming the phone on someone’s face.

Because of this, I decided to put my engineering degree to good use, and went out and bought a phone. Thus begins project iRotary, which aims to turn this:

Continue reading…