Joe Ray

Principal Engineer

Scratching an itch: why I like programming

Automation

The Indian train system is amazing considering the number of passengers it hauls around the country but it can be frustrating as a foreigner trying to book tickets, especially at the last minute.

Certain trains have tickets put aside for foreign tourists. This is fantastically useful given that most trains sell out well in advance but discovering which trains have foreign tourist quota tickets available is problematic as online booking agents don’t have the information – you can only buy them at stations. The process invariably involves the following steps:

  1. Navigate to Cleartrip site.
  2. Enter journey details and submit.
  3. Discover no trains run between the two chosen stations (Cleartrip only searches direct routes).
  4. Repeat step 2 until you get some results.
  5. Note down the train number and figure out the short codes for the departing and arriving stations.
  6. Navigate to the seat availability form on the Indian Rail website.
  7. Enter journey details and submit.
  8. Find you’ve entered something wrong – very likely given how exacting the form is.
  9. Go back, amend details and submit form.
  10. Find the site has reset the date of travel you put in.
  11. Repeat step 9.
  12. Repeat steps 8 through 11 once or twice.
  13. No foreign tourist quota tickets for this train.
  14. Go back to step 5.

If there are 20 trains on a given day for your route, checking each one manually becomes unfeasible.

Instead, I wrote a Greasemonkey script that automates the Indian Rail website portion of the process and reports the results right in my Cleartrip results page. What might have taken thirty minutes for each journey (and as I have no firm travel plans I’ve been checking a lot of journeys) now takes seconds. Itch scratched.

Another little automation project I recently completed was prompted by one of my guesthouses’ ISPs. To use the WiFi you were first required to log into a web page. Unfortunately, unless you kept the login page open, the session would frequently time out requiring another visit to the login page. Rather than doing this manually every time I discover I’d been logged out, I wrote a simple Python script to perform the task for me.

All it does is mimics the keepalive request that the login page performs once you’ve logged in. If the script detects the session has timed out anyway, it posts the login details to the ISP. This may not sound like a big win but when you’re working all day and the session is timing out several times an hour, it saved me going prematurely bald.

These two scripts only took me a couple of enjoyable hours to build, taught me more about the languages and domains I wrote them in and, most importantly, unlike the experience in the above XKCD comic, have saved me a lot of time.

Teaching the world to scratch their itches

A lot has been said of late about the value of teaching schoolchildren to code as the UK Government launched its Year of Code initiative earlier this year, although not without some controversy.

One of the reasons I love being a programmer is having the ability to solve problems by bashing out a few lines of code. Not only does this make my life easier but I get to enjoy the process as well.

My skills mean I’m able to recognise and understand a problem and come up with the solution, not just because I know a handful of programming languages (although that obviously helps) but because of the knowledge programming has given me about the world of technology and how it works.

My hope for the Year of Code is not that a whole generation decides they want to become the next Zuckerburg but that youth are given the tools to understand the technology that the world is increasingly reliant on and be able to make it serve their needs.

If that also results in someone being more likely to create the next Facebook, so much the better.

Contact Me

I love a good conversation! E-mail me (encrypted if you want) or find me on Twitter, LinkedIn and GitHub.