Loading... Born a day after the American Independence in Jalandhar, Punjab, India, I've spent most part of my life there. Studied till 5th standard in St. Joseph's Convent School, Jalandhar, and later had to join Apeejay School, Jalandhar as, perhaps, the former school decided boys could be troublesome in a girls' school after 5th. After completing schooling in APJ (till 12th), joined National Institute of Technology [NITJ] (again, in Jalandhar) as a Computer Science & Engineering student in 2005. During the worst period of downtime (recession), got an on-campus placement in Accenture in 2008. Graduating from college took another year after that, and finally joined Accenture in mid-2009. This is my story so far... Btw, you can find me on: google+ twitter last.fm github librarything granular steam
@AnuragBhandari twitter updates
Tech enthusiast, open source evangelist, book worm, software developer, sports fan, passionate gamer, movie buff.
  • One thing I'd really like to see in @MEIZU's #FlymeOS is Lockscreen Notifications. I really miss them. Otherwise, Flyme is pretty and nice. —
  • I have never seen an upload speed like this in my entire life. Simply wow! #nextra #opticfiber http://t.co/I7EbllG3z7
  • @anurag_bhatia Every Mac upgrade will come with its own set of pains :p —
Apr 25

Ionic is based on Angular. Angular has views and controllers. A view’s controller is supposed to execute each time the view is opened or navigated to. In Ionic, that doesn’t happen.

Take for instance this setup: you’re building a social app that has a Login view. You’ve configured the routes such that the Home view is set to open by default. Each time the app is loaded from scratch: (i) Home view opens, (ii) login session check is performed, and (iii) user is redirected to Login view if session has expired.

Now because Home view has loaded once and its controller executed alongside, the following piece of code will NOT execute again once login is successful on Login view and user is redirected back to Home view, perhaps through $state.go.

.controller('HomeController', function ($scope) {
    // Read username from local storage
    $scope.userEmail = window.localStorage['app.user.email'];

So if the value stored in local storage was an empty string when HomeController ran, $scope.userEmail would still be empty string even after LoginController has updated the local storage value.

Until this very moment, I didn’t have a damning clue to this apparently illogical problem. My searches for angular controller runs only once, angular $state.go controller doesn't execute, and so on naturally went fruitless because I wasn’t searching it right! Apparently, people were not facing the same problem.

A developer on stackoverflow reported that an NG controller should actually run each time its view loads. On the same stackoverflow question, I found my answer.

As per Ionic’s official docs on ion-view:

Views are cached to improve performance. Views can be cached, which means controllers normally only load once, which may affect your controller logic. To know when a view has entered or left, events have been added that are emitted from the view’s scope.

So the problem of run-once controllers is very Ionic specific. And so is the solution. The way to go about the problem is to move your code, that’s supposed to be executed each time a view is shown, from the root of your controller to the view’s $ionicView.enter event handler.

.controller('HomeController', function ($scope) {
    $scope.$on('$ionicView.enter', function () {
        // All code in this function will execute each time Home view is shown
        $scope.userEmail = window.localStorage['app.user.email'];

That’s it!

Tagged with:
Mar 23

I just realised that I completely forgot to cover my Brussels trip of last year. Shame on me! I had been meaning to do that since more than a year, but never really got myself to sit down and write [a lengthy post]. Before going any further, I promise that I’ll keep this one short. Mine was a short trip (just 3 days, aww shucks), but I have a lot to tell about all that I experienced in such a short while. Maybe some other time…

Visiting Brussels, Belgium, was my first foreign trip, something I absolutely enjoyed. It’s always exciting to go see, live and explore other places, cultures and people. Of course that’s not why I went there. My visit was two pronged: (a) joining my fellow folks at OpenMandriva’s stall at FOSDEM (b) delivering a lightening talk at the same event.

FOSDEM is a free event for software developers to meet, share ideas and collaborate.
Every year, thousands of developers of free and open source software from all over the world gather at the event in Brussels.

Continue reading »

Tagged with:
Nov 08

Hence, I submit to my uncontrolled urge to share this beautiful poem I heard in Interstellar.

Dylan Thomas, 1951

Do not go gentle into that good night,
Old age should burn and rave at close of day;
Rage, rage against the dying of the light.

Though wise men at their end know dark is right,
Because their words had forked no lightning they
Do not go gentle into that good night.

Good men, the last wave by, crying how bright
Their frail deeds might have danced in a green bay,
Rage, rage against the dying of the light.

Wild men who caught and sang the sun in flight,
And learn, too late, they grieved it on its way,
Do not go gentle into that good night.

Grave men, near death, who see with blinding sight
Blind eyes could blaze like meteors and be gay,
Rage, rage against the dying of the light.

And you, my father, there on the sad height,
Curse, bless, me now with your fierce tears, I pray.
Do not go gentle into that good night.
Rage, rage against the dying of the light.

Tagged with:
Oct 09

Amitabh Bachchan recited this beautiful, inspiring poem in the closing moments of the historic KBC episode that saw, for the first time ever, a prize money of Rs. 7 crore (approx. USD 1.2 million) being won.

The poem was written by Harivansh Rai Bachchan, Amitabh’s father, and it goes like this:

लहरों से डर कर नौका पार नहीं होती,
कोशिश करने वालों की कभी हार नहीं होती।

नन्हीं चींटी जब दाना लेकर चलती है,
चढ़ती दीवारों पर, सौ बार फिसलती है।
मन का विश्वास रगों में साहस भरता है,
चढ़कर गिरना, गिरकर चढ़ना न अखरता है।
आख़िर उसकी मेहनत बेकार नहीं होती,
कोशिश करने वालों की कभी हार नहीं होती।

डुबकियां सिंधु में गोताखोर लगाता है,
जा जा कर खाली हाथ लौटकर आता है।
मिलते नहीं सहज ही मोती गहरे पानी में,
बढ़ता दुगना उत्साह इसी हैरानी में।
मुट्ठी उसकी खाली हर बार नहीं होती,
कोशिश करने वालों की कभी हार नहीं होती।

असफलता एक चुनौती है, इसे स्वीकार करो,
क्या कमी रह गई, देखो और सुधार करो।
जब तक न सफल हो, नींद चैन को त्यागो तुम,
संघर्ष का मैदान छोड़ कर मत भागो तुम।
कुछ किये बिना ही जय जय कार नहीं होती,
कोशिश करने वालों की कभी हार नहीं होती।

Aug 07

ST makes it pretty straightforward to access webservices or APIs through its various data proxies and Ext.Ajax. But consuming an API protected under basic authentication can be tricky. Both data proxies and Ext.Ajax provide setUsername() and setPassword() methods, and they work fine on most browsers. But in my experience using these methods, I had big time face-palm moments in case of Safari, iOS, and some Android versions. When these methods are used, an ST app sets the Authorization header AND makes all API requests through URLs formed such as this:


I’m not sure why this is such a big deal for some browsers, but they seem to get confused due to the presence of these two things — Authorization header and user:passwd URL.

The trick to solving the issue is to NOT use setUsername() and setPassword(), and instead set the HTTP headers yourself.

Data Proxies have a headers config.

	'Authorization': 'Basic ' + btoa(username + ':' + password)

Ext.Ajax has a defaultHeaders config.

	'Authorization': 'Basic ' + btoa(username + ':' + password)
preload preload preload