Jonny Power

Jonny Power

Jonny power is a developer, currently based in Lancaster UK, with extensive experience building applications for the Web, iOS and Android.

If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.

Linus Torvalds

Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover.


Drop an email to any of the following adresses

Jonny Power
92 Upper Newtownards Road,
Grizedale College
Lancaster University,
Sunguru Limited
117 Upper Newtownards Road

Code Snippets

Stop Chrome from caching AJAX/POST requests

Chrome AJAX Post Standards

Browsers aren't meant to cache POST requests, but when developing a recent web application I found that chrome most definitly was caching POST requests. I was making them with jQuery's ajax post method $.post, so my first thought was to set jQuery's global ajax settings to cache : false. This didn't help, because jQuery also works on the assumption that post requests shouldn't be cached by the browser.

The jQuery api for $.post mentions the following on caching:

Pages fetched with POST are never cached, so the cache and ifModified options in jQuery.ajaxSetup() have no effect on these requests.jQuery API Documentation

Even sending a random string as a parameter didn't stop chrome from caching the result, very frustrating! A work around is to append a dud parameter with a value that is always unique to the URL.

In my case the below javascript snippet was enough to get around the problem.

  '/api/getNotifications?date='+new Date().getTime(), 
    // Do stuff
  1. jQuery's documentation page for $.post()

SQLAlchemy & MySQLdb: MySQL Server has gone away

python MySQL SQLAlchemy MySQLdb

I'm currently creating a large scale web application using Pyramid, the python webframework used by Reddit and others. Making use of the python SQLAlchemy, MySQLdb modules/libraries and a MySQL database for persistent storage makes things easy.

However, it's important to set up your engine correctly. I was having a hard time with OperationalErrors where my database connection pool would become useless after 8 hours throwing an exception: mysql server has 'gone away'.

Solving this is pretty easy, simply set your pool recyle period to something reasonable such as 3600 minutes (1 hour). If you use the create_engine method append pool_recycle=3600 to the end of your method call.

The SQLAlchemy documentation makes a specific reference to this problem when talking about pool_recycle:

Note that MySQL in particular will disconnect automatically if no activity is detected on a connection for eight hours (although this is configurable with the MySQLDB connection itself and the server configuration as well).SQLAlchemy Documentation

  1. SQLAlchemy Engine documentation

Snippet to climb iOS responder chain to first UIViewController

iOS Objective-C Custom UIView UIViewController

When implementing a custom UIView in iOS it isn't immediatly possible to manage things like touch events from the UIViewController. I prefer to manage them in the view controller to keep the code consistent with the standard UIView classes.

Using the below snippet it's real easy to forward the event from the UIView to the UIViewController.

UIResponder *responder = self;
while (responder.nextResponder != nil){
    responder = responder.nextResponder;
    if ([responder isKindOfClass:[UIViewController class]]) {
        // Got ViewController
// Responder object is first UIViewController in responder chain (or the last object in the chain if there is no UIViewController), do as needed
  1. Further reading on UIResponder & Responder Chain

  • Ajax
  • Javascript / jQuery
  • MySQL / SQLite
  • PHP
  • Pyramid / Django
  • JSP
  • HTML5 / CSS3
  • Hosting / Domains
  • iPhone / iPad / Android
  • Java w/ Android SDK
  • Objective-C for iOS
  • C
  • Java
  • Erlang
  • Python
  • Objective-C for MacOSX
  • Subversion / Git
  • LaTeX

  • BSc Hons Computer Science Innovation from Lancaster University, UK

Around the Web