Django Login Session ID Extractor Script

In the not too distant past, I worked on an interesting web project in which my participation lasted a brief period. I enjoyed the time I spent working on it. It was a project based on Django and Python, two technologies that I simply love working with. The last tasks I worked on had to do with benchmarking the performance of the Django web application, as well as the webserver it was powered on, which was Apache.

I had to use the excellent and extensive Apache Benchmark utility, also commonly known as simply ab. If you’re not familiar with ab, I recommend you check it out. The problem I faced was not being able to benchmark views that required an authenticated web session. Simply put, I wasn’t able to use ab against views that were login protected. In order to solve this limitation and also to automate the process, I threw together a BASH shell script which I called The Django Login Session ID Extractor. It used a combination of Linux tools to log into the Django application via the login view, and extract out the SESSION ID thus created. This SESSION ID, then, could be passed to the ab command in order for it to hit login protected views.

This script proved really useful during testing, and would’ve even more had I continued to work on it. However, I decided to make the script available on GitHub for the world to use. I am hoping someone might make use of it.

Advertisements

Sleep bug on iOS 6.1.2 on iPhone 4S

I have been using an iPhone 4S for the most part of last year. I make it a point to keep iOS, which is the OS running on it, on it updated to the latest stable version. I am only a little hesitant about upgrading the OS as soon as there’s a newer version available. I used to be more suspicious of applying updates, say, a year ago, where I would wait it out, lurking on forums and Internet looking for people complaining about unsavoury experiences with the update or critical and/or annoying bugs that might stop me dead in my tracks from doing anything I wanted to do on my phone. However, now, I mostly just dive headlong into the update (and break all hell loose if anything untoward takes place, which I must add thankfully has yet to happen).

 

I’m running iOS 6.1.2 which at the time of writing is the latest iOS release, with iOS 6.1.3 doing the rounds in beta. However, of late, I have been noticing, rather infrequently, that my iPhone 4S stops waking up from sleep. The first time that happened I immediately thought the phone had frozen up and required a cold reboot (this hard and cold reboot terminologies continue to confound me to this day). Pressing the home button or the sleep button, or holding down either of them does nothing. The phone appears dead.

 

Luckily, right the first time it bumped its ugly head and gave me a scare, I accidentally managed to find a workaround to it. While pressing the two hardware buttons on the phone in the desperate hopes of waking up or rebooting the phone, I found out that simply pressing the Home and Sleep buttons together, as when taking a picture of the screen, brings the phone back from sleep, with that familiar click sound that comes from having taken a snapshot. And in fact, it does take a snapshot. Only, it also triggers the phone to wake from the sleep from which it appears to not wake up any other way.

 

I don’t know whether this bug has to do with iOS 6.1.2, iPhone 4S, iOS 6.1.2 on iPhone 4S, or something else entirely on my phone (say any app or a corrupt setting, though I have tried rebooting the phone and still found the problem to occur). It doesn’t occur all the time, or even from time to time: it’s quite infrequent. In fact, I’ve only had it bother me twice or thrice. But it did happen. And pressing Sleep and Home together helped pull me out.

 

I hope it helps you too if the Apple gods forbid you run into this issue on your iOS device.

Disabling auto-correct on TweetBot for Mac

My favourite Twitter client on iOS is TweetBot. It is there on both my iPhone and my iPad. I simply love it. There can probably be no comparison between the Twitter for iPhone/iPad (or any other third-party Twitter app) and TweetBot. The only little downside is that it is not free. It has to be bought separately on both the iPhone and iPad. But, it is a small price for an awesome piece of app.

Naturally, I wanted something as good as TweetBot on Mac. TweetBot wasn’t for Mac, and Twitter for Mac became a pain to use. I tried TweetDeck but couldn’t stand the sight of it. And then, TweetBot for Mac came along. It came as Alpha first, and remained Alpha for a while and was free to download and use. It then turned to Beta, and finally, it was released. There was a price tag on the final version, and I happily bought it off the Mac App Store. There were bugs here and there, but overall, it worked solidly. It was every bit as good as its iOS counterparts.

iOS has an “Auto Correct” functionality–which can be turned off from the settings, but which you shouldn’t do if you want to be able to type/tap text at ease on your device–which is smart enough to automatically detect what you’re typing that isn’t correct, suggest a correction, and then correct it. It is so unbelievably good that once you get used to, which takes very little time, you cannot simply live without it. At all. The same auto-correct feature is available on the latest OS X versions on the Mac as well. However, unlike the auto-correct on iOS which pops up a visible suggestion giving you an option to select or discard it, the auto-correct on Mac isn’t so effective because when you are typing fast on a keyboard, and as you type away, the auto-correct applies the suggested corrections without your really noticing them. The end result is that you end up with text with certain words that you did not remember typing at all and which, while are correct, don’t really make sense in the context. This becomes really very annoying.

While it is possible to globally disable “auto-correct” on OS X via settings, a lot of the apps unfortunately still override the setting. For those apps, the setting can be manually disabled from the “Edit > Spelling and Grammar” menu.

The same is the case with TweetBot for Mac. With one catch: you can manually disable the auto-correct from the menu bar, but not permamently. Every time you open a new compose tweet window, the setting is overriden once again. That’s annoying as hell.

Not having found any solution, I wrote to Tapbots (the authors of TweetBot) about it. They confirmed that indeed it was a bug in the current version and that it would be fixed in the new release. However, for the meantime, they suggested a temporary fix for the auto-correct that requires running a command on the Terminal. It’s pretty easy. All you have to do is open up Terminal, and run the following command:

defaults write com.tapbots.TweetbotMac TextAutoCorrect -bool NO

That’s it! Auto-correct will be permanently disabled for TweetBot for Mac. Bliss!

I would like to thank the Tapbots guys for kindly providing the fix and acknowledging the problem.

Mobile Safari Web Inspector on Safari on Mac.

If you tweak HTML and CSS and JavaScript on webpages, then you may appreciate how simple and convenient the plugin that goes by the name of Firebug for Firefox has made your life. I know it has for me. It is simply an indispensable piece of technology that I use every time I have to debug a CSS or HTML or JS issue on a webpage. Other browsers, notably Chrome and Safari, have built-in web inspectors which allow similar features.

I have of late been working on a lot of Mobile versions of websites, particularly those optimized for Mobile Safari and iOS devices using the fascinating jQuery Mobile framework. One of my biggest pet peeves while debugging issues on Mobile websites was not being able to debug the sites live on a mobile browser. More times than I’d care to acknowledge a particular mobile site, when viewed on a normal browser would look fine, but would have slight aberrations when viewed on a mobile browser. Those kind of issues are a real pain in the neck, because you are, more often than not, left to get sucked in an annoying cycle of wildly making changes in the HTML/CSS and refreshing the page on the mobile browser continuously in the hopes that the problem would fix itself.

However, today I bumped into a way to inspect and debug a mobile site on Mobile Safari by using Safari on a Mac computer (I am sure that it may work equally well for Safari on Windows, but I have not had reason nor occasion to try to find out). It not only works so well, but is also very straightforward to set up.

My testing environment includes an iPhone 4S running iOS 6 and a MacBook Pro running OS X Lion 10.7.5. Here are the steps you must follow in order to be able to inspect mobile web pages live via Safari on your Mac:

  • On your iOS device, turn on “Web Inspector” inside the Advanced settings for Safari. You’ll find these under the Settings app.
  • On the Advanced tab under Preferences for Safari on your Mac, you must check the “Show Develop menu in menu bar” setting.
  • Connect your iOS device to your Mac via the data cable.
  • You may now load on Mobile Safari the mobile webpage you want to inspect.
  • On Safari on Mac, open the Develop menu in the menu bar, select the name of your iOS device that will appear in the list, and click on the webpage shown on the pop-up that slides to the right.

The web inspector in Safari will kick in. You may explore the different tabs and functionality available there. The only downside is that no preview of the page is available on the inspector. Instead, the live page open on your Mobile Safari is the preview. You may go through the HTML source displayed inside the inspector, selecting the elements you want to inspect and notice that the corresponding elements are highlighted on the device. What’s more, you can also live edit the source as well as CSS, and they take effect almost immediately. How awesome is that!

iPad 2 WiFi greyed-out (N/A)

I purchased an Apple iPad 2 over half an year ago. I bought a Rilakkuma smart cover with it. The iPad was tugged inside the cover in the shop, and I never felt the need to take it out since. However yesterday the iPad gave me a scare.

It had been rather hot and humid the past couple of days, more humid than hot. Despite the temperature being around the 35-36C bracket, it felt as though it was actually over 40C. I had been using the iPad as a content consumption device heavily, but of late, I had only been reading books on it, thus keeping the WiFi disabled. Yesterday, however, I had issues with the WiFi scanning for networks. It couldn’t find any. I had given the problem to some rogue setting on the WiFi router (the WiFi, alledgedly, on iPad is sensitive to WiFi routers). But today, to my utter shock, I found the WiFi option under Settings disabled (greyed-out). What shocked me more was finding “N/A” listed next to WiFi under Settings > About, which meant that the OS didn’t find any WiFi chip/interface on the iPad.

That freaked me out. My first assumption was the WiFi chip had died. Reading a couple of posts on forums about the issue (there weren’t many covering the issue) confirmed that. However, someone suggested cooling down the iPad before powering it on again. Since I had already assumed the worst, I thought it wouldn’t hurt if I tried that suggestion.

I took the iPad out of its cover for the first time since purchasing it. I turned on the airco, powered off the iPad, and left it directly under the airco to let it cool off. After around twenty minutes, when the Aluminium backside of the iPad felt chilled to the touch, I crossed my fingers, and powered it on. Voila! The WiFi option was no longer greyed-out, and the Settings > About no longer showed a frightening N/A.

I heaved a deep sigh of relief.

I am lost as to the exact cause of the problem. I do know that high humidity (coupled with heat) plays havoc with electronics. And the iPad had been left around in closed, hot rooms every now and then (with other electronics, I must point out). Nevertheless, I’m glad it is working now.

iPad

I own a Nokia E72 mobile phone. While I have not owned mobile phones longer than five years, I have in that time span been through two mobile brands. My very first mobile phone, gifted to me by father when I was early on in the University, properly convinced that I didn’t need a mobile phone, was a Sony Ericsson. It was a small mobile phone, the name of which escapes me now. I may still have it, somewhere, in some drawers, lost but not forgotten. I used it until it nearly died out. The engravings on the buttons grew muddled, colour on the handset faded out, the battery dead, replaced and dead again, etc. It would be safe to say, in hindsight, that I used it heavily.

My second mobile phone was another Sony Ericsson. It was the first mobile phone I bought. I was immensely excited the night I bought it, on way from work. The excitement of buying a new gadget is one that doesn’t ever diminish in its intensity, never goes away, no matter how many gadgets you buy. It is there right around the time you decide to buy a new gadget, and lasts well until after you’ve bought it. That was my second Sony Ericsson phone, and would be my last.

After I had made heavy use of it, I slowly moved away from it over to Nokia. I had a mammoth but reliable Nokia E61 lying around, which I was using for testing Symbian applications. Yes, this was roughly the time when I worked on Symbian application development. And that is all I am going to say of it.

My fourth and current mobile phone is a successor to E61: Nokia E72. I loved that phone when I bought it. I still love it in some ways. While E61 could be said to be too, E72 is what you would call a proper smart-phone. It features a lot of things that could help you do all sorts of things on the Internet, besides the usual functions of phone. It also has a full QWERTY keyboard. While I had owned an iPod Touch, I’d not been a big fan of touch screen and touch phones. I strongly believed that I could never be able to reliably use a phone with touch screen as the only form of input. This bias was in part due to my reliance on and affinity for physical QWERTY keyboards on phones.

Over the past couple of months, I was growing a little frustrated with my E72. While it worked as anyone would expect of it, I found that as far as applications that let me run wild on the Internet were concerned, it was severely limited. Sure, there were applications to do anything from using Facebook to Twitter to Foursquare. But I felt stifled. There were browsers but I didn’t feel the urge to browse anything on my mobile, unless it was an absolute emergency. I could post tweets on Twitter, but I didn’t enjoy interacting with others’ tweets. The same could be said of my experiences with Facebook (as far as I can tell, there is no native, official application for Facebook from Facebook for Symbian S60) or Foursquare applications. It just wasn’t fun, or even comfortable.

So for the past couple of months, I had been strictly debating getting an iPhone. iPhone 4S was out by then and it made no sense to get anything below that model. Some friends suggested time and again to go for the iPad instead. Where I was almost convinced that iPhone 4S would be my fifth phone, the recommendations for iPad threw my mind back in a state of confusion. Naturally, I compared the pros and contrasted the cons of both devices. Of course, one is a phone, the other a tablet, but when I compared the iPhone to the iPad, I actually compared it with iPad and my E72. That is, if I were to get an iPad, I would continue to use my E72 for the phone needs. There was a big difference in price as well, with a factory unlocked iPhone 4S coming at an exorbitant 67k PKR locally, while an iPad2 with WiFi cost only 48k PKR.

I still remember clearly the night I was at the club on the courts, playing tennis with my partner. He had finally bought the iPhone 4 a day before, after having looked for the white one for under a week. That night, I came home, and finally made up my mind.

The next afternoon, I was at the Apple Store I regularly buy from, purchasing an iPad2 WiFi with 16GB disk space. I had decided it. As I would find out, it was one of the best decisions I had made in my life in a while.

Those familiar with the different iPad2 models available will know that there’s a WiFi + 3G one available. Apart from having to pay under 10k PKR more, the main reason why I decided against getting the 3G model was the unavailability of 3G in the country. I know that you don’t necessarily have to have 3G to be able to use the connection, because any type of data-plan from your provider, such as GPRS or EDGE, will work. However, as I will explain, iPad is a content consumption device. When I say that it is a content consumption device, I mean it in a massive way. It has been designed for consuming a lot of content, including in the form of video, audio, and text. When I decided to buy it, I imagined myself using the iPad like I do my laptop. And I can’t ever imagine using my laptop over EDGE/GPRS in a way that satisfies me. Similarly, I didn’t think the iPad would shine on an EDGE/GPRS connection.

In the next post, I will explain exactly how the arrival of iPad has changed my life, how it has affected it, how I use it, where and when I use it. I will also list down the wonderful apps I use frequently, and make an argument for iPad being an awesome device for reading books/content in particular.

A look at the year that went by!

There is little at least, if not a lot, to be gained from having an optimistic outlook towards life. I’ll be honest when I say I haven’t ever believed that entirely in my life. But from being pessimistic and negative for the most part, I’ve come to realise painfully the absence of optimism and how much it has the potential to scar you emotionally. It would also be wrong to say that it doesn’t hurt to be optimistic. Disappointment from something you had strong hopes for, can hurt you in a very real way. But, that is a price you can usually afford to pay.

Lying in bed, trying to think of what if anything phenomenal I accomplished throughout the year that is no more I am forced to draw nothing. I can’t remember anything significant I did. That doesn’t mean I didn’t do anything worthwhile or significant to any extent. I just can’t remember. It’s probably due to the cracking headache I’m having. I don’t know.

The year passed by so quick, it’s hard to say where it went. I’m not the kind of person, as much as I try to be otherwise, who makes clear, real goals and lives by them. That doesn’t mean I’ve no goals. I do. I’m just not obsessed with the whole goal-setting thing. Although a lot of times I think that things around me simply unfold themselves, and I naturally flow through them.

Work wise, this was the year where I tackled many different projects, of varying complexities and sizes. I learned a lot of new things. Of import were my exercises in finding ways to deploy both Django and web.py Python frameworks on IIS on Windows. I went on to write a guide to deploying web.py on IIS which got accepted into the official cookbook documentation for the web.py project.

Insofar as tech gadgets are concerned, I was lucky enough to upgrade to the high-end Apple’s MacBook Pros, especially since my previous MacBook had developed several faults. Very late in the year I made what was perhaps the best decision in terms of buying anything when I bought the iPad2. It would be an understatement to say that it has had an impact on my life. The iPad has had a phenomenal impact on my life. If it is any testament to that statement, I’m writing this post on the Elements app on the iPad and will publish it using the WordPress app. I’m so glad I made the decision to buy it after much deliberation.

This year saw a lot by way of reading. I bought more books in paperback and committed myself to reading more. Not only that, I also forced myself to reading, daily, two dozen different interesting feeds. With the coming of the iPad, my reading saw an exponential increase, not only in the form of ebooks but many online feeds and content sources. A man must read, in order to survive. I believe strongly in that.

On the personal side, there were certain events that shook my life. It didn’t affect anyone’s but my own life, but they had a huge impact on me, and not sadly in positive ways. My emotional self took a battering. I also played a small part in helping save a friend’s life from half way across the globe. Thankfully, this year saw family bonds getting a little stronger, which I am very grateful for.

With regards to tennis, this was a great year for me. My game improved by leaps and bounds and I played some of the best tennis of my life. I have been more and more in love with tennis every passing day. Sometimes I think that that is the only true love left in my life.

All in all, I can’t say that the year was bad for me, nor would I want to say it was great. It was a balanced mix of both good and bad. Regardless, I’m thankful for everything and everything. I’ve been blessed beyond what I care to realise. You only need look at someone less fortunate than yourself to realise what you have been given. I do that almost everyday. And I feel bad about those severely less fortunate in particular. Yet I’m also guilty of forcing myself in a bubble at times that hides away the outside from me. I should always realise. I should always be grateful.

My best wishes to each and everyone of you. Please stay safe and be well! A very happy new year to you.

Thank you!