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.
Unknown
Drop an email to any of the following adresses
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.
$.post(
'/api/getNotifications?date='+new Date().getTime(),
function(data){
// Do stuff
}
);
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
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
break;
}
}
// Responder object is first UIViewController in responder chain (or the last object in the chain if there is no UIViewController), do as needed