A new journey begins

Another big change in life is taking place. I’ve landed New York airport (JFK) a few hours ago to start my new life in the USA. After receiving my immigration visa at January 2014; I flew on February 8, 2014 leaving my crying parents along with brothers, sisters, nephews, niches, friends.

The upside (whether only or among many) of this migration is that I never knew that I’m loved by so many people. I wish I can respect all the love and care I’ve got so far and I wish I can settle myself (along with my wife) here in spite of being extremely home-seek.

Lessons learned while working with Backbone.js

I was developing a quite big Backbone.js application with my team of 2 more members. We were working on this project for about 7 months. We’ve learned an awful number of things in this journey as it was our biggest Javascript project for everyone in our team. Among many other things, OOP in Javascript always confuses me though I understand a few things better than earlier. I’ve tried to write a few things I’ve learned while working in this project; however, everything does not directly related to backbone.js

Source Code is the best documentation

I have relied on the backbonejs.org for several months for documentation purpose. However, I’ve found not everything was documented properly in the website. For example, from the website I knew fetch/sync accepts success and error as property of the options hash. What I didn’t know until I read the source code is that it also triggers sync and error events on success and failure respectively. Reading the official doc, I thought it’s possible only for save() method.

Simplified Object Copying

If I need to copy a variable/object attribute, I first need to check it whether it exists or not. Look at this example:

if(this.someAttribute){
  var localAttribute = this.someAttribute;
} else {
  var localAttribute = this.someAttribute = {} //or any default value;
}

However, while reading Backbone.js source code, I’ve learned we could write this in a very simplified one line.

var localAttribute = this.someAttribute || (this.someAttribute = {});

Changing in referenced object does not trigger events

When you change an attribute of a backbone model, change and change:attribute  events are triggered. For example,

object.set(‘name’, ‘The HungryCoder’) will trigger change and change:name events on object.  The following will not work.

var info = model.get('userInfo'); //returns a hash
info['id'] = 101;
model.set('userInfo', info);

The above change won’t trigger a change event. Here info variable is a reference to model’s userInfo and userInfo attribute in the object is already updated when you set info[‘id’] = 101;

In such cases, if you want to trigger the change events, you need to clone the attribute at first place when you are copying them.

var info = _.clone(model.get('userInfo'));
info['id'] = 101;
model.set('userInfo', info);

This will trigger change and change:info events correctly.

Learn fighting Zombies

If you’re working with Backbone.js for a while, chances are high that you’re already facing this kind of problems. Sometimes, you will notice that a particular action is triggering more than once though it is supposed to perform only once.

This happens because, even though, you remove elements from your DOM, they are still alive in your computer’s memory. Consider the example:

 

var Views.MyView = Backbone.View.extend({
  initialize: function() {
    this.model.on('change', this.render, this);
  },
  render: function() {
    //render template
    alert('hello');
  }
});

You’ve taken instance of this view and added to your DOM. When you wanted to remove these elements from DOM, you’ve called remove() method on this instance. Though the elements are removed from DOM, they are still in memory and can’t be cleaned up by Javascript’s garbage collectors as this object is still referenced from your model. It is due to the following line that you’ve written in our earlier view.

this.model.on('change', this.render, this);

The model has still a reference to this view and a referenced object is not cleaned. So your view is still going to alert you even if they are not visible in the DOM. This has been addressed in Backbone.js 0.9.9 where listenTo (and stopListening) is introduced. So you re-write the above line as following:

this.listenTo(this.model, 'change', this.render);

This will internally keep track of the bounded events and will reliably unbind any events when you call remove() on this view object.

to be updated…

Patriotism in TV Commercials

I’m big fan of TV commercials in indian televisions those try to promote patriotism. They nicely talks about their country and to love her even when advertising their products.

Though many of the TV programs (like Reality Shows, family breaking serials) ideas are borrowed from indian televisions, I was always thinking why we don’t see such patriotism in our ads?  Why our commercials do not talk to love our country, to use our local products! I think my days of frustration are over. Recently I’ve seen two tv commercials that are talking about the love for the country and make some change. I’ve embedded those two in this post.

Robi (Mobile operator) TV Commercial:

Frutika (mango juice) TV Commercial

These two are ads I watch in full each time they are broadcasted. Each time I see them I see like I’m seeing it for the first time.

If these ads can change a single person, or at least make him to think different; that’s a big success. I wish to more like these in coming days.

Handlebars helpers

In an application we are using Handlebars templating. However, we needed many custom helpers to do what we wanted to achieve. Here are some of those helpers. It may help someone who is looking for achieving similar things. Examples are included.

Adding/Subtracting

Character limit with trailing characters (optional).

Just received amazonkindle!

Today I came to office a bit late. Immediately after coming I was informed that a parcel has arrived on my name. I was expecting a dummy camera lens as it is supposed to come. However, seeing the packet I was a bit suspicious. The dummy lens’s package would not be so small. After I opened it, I could not believe my eyes. It is amazonkindle! Yes, I ordered it on 15th May from www.aliexpress.com! But still unbelievable. Do you know why? Keep following.

In aliexpress, when a order is placed and payment is done the order status was ‘Shipment Required‘. The seller was supposed to ship it and mark it as ‘Shipped’ and provide me the tracking ID. However, till now I did not receive any tracking and the order status was ‘Shipment Required’ last night. Seeing the seller is delaying unnecessarily, I canceled the order and aliexpress.com refunded me the whole money within few minutes. I also gave negative feedback to the buyer for wasting my time.

So, I guess you now can understand why I am so surprised seeing it. The seller must be stupid! Why s/he did not update the status of the order?

Anyway, as still in office, I could not get much time to explore it. I will explore it at home. I wish the seller will contact me and I will arrange a way to pay him.

The benefit of aliexpress is that it does keeps the money in escrow until you confirm that the product is reached to you and it is upto your expectation. I first heard about aliexpress.com from a member of Projanmo Forum.

My version is Kindle 3 WiFi + 3G. Costs (including shipping) was US$191. Also I had to pay 1050 tk here as excise duty and other fees.

Is it right time to buy Apple’s product from Bangladesh?

It has been about 11 months that I’ve purchased Macbook Pro 13.3 inches. Though I am extremely happy with hardware design, I am that level of unhappy due to instability of the Mac OS. I can’t run it for more than 3 days as it either hangs or become too unstable to use! Many applications including Firefox 4 crashing frequently on it.

Again, in the first month of purchase, a silica ball as been penetrated into its sound port (3.5mm) and to date it is safely there. Why? Because Aloha iShoppe, from where I’ve purchased it, said they can’t open it as it will void the Apple’s warranty though they are authorized dealer of Apple’s product! If I need to claim warranty, they would send the laptop to Singapore and it will take about 2 months to get back the laptop. Can you imagine?

Moreover from last week, power adapter for my macbook pro is dead. This morning I went to Executive Machines for asking the price of a macbook pro adapter. They said it is 8500 BDT. And they also said you can get yours one replaced from where you’ve purchased it as it has one year warranty (they also provide same warranty for their power adapters too)! Then I called to Aloha iShoppe and here is pattern of conversation:

Me: What is the warranty duration for power adapter of macbook pro?
Aloha: There is no warranty for the power adapter.
Me: But so far I know, it also has same warranty as the main body!
Aloha: When you’ve purchased it?
Me: Last june!
Aloha: Actually, it does not has so long warranty, it has about 90 days of warranty?
Me: But Executive Machines is giving 1 year warranty for power adapter.
Aloha: ummm, it is (1 year warranty) given for the products from this year, not for earlier products (power adapter)!
Me: What is the price of power adapter at your house?
Aloha: It is 9500 BDT.
Me: OMG! It is 8500 BDT at Executive Machines. Why you are charging higher prices with less warranty period?
Aloha: They might not have the product, they sometimes, tell prices for products even they don’t have.
Me: Well, they showed me the adapter

(I hang up the phone!)

If you read the above conversation, you will notice how inconsistent their information are!

With my bad experiences with Apple products, I don’t think we should buy Apple’s product unless there is a service center of Apple in Bangladesh! However, if you need to buy, I think it will be wise not to buy from Aloha iShoppe.

Few months ago, I purchased a remote control from Executive Machines by BDT 1700 whose price was asked 2800 at Aloha! So you see how much higher their prices and most importantly, poor after sales service.

My experience with phpXperts seminar 2010

phpXperts Seminar 2010, is my third program with phpXperts. Other than phpXperts programs, I have also joined in other programs like Facebook Developer Garage, SQABD Lightning Talks etc. However, this one is exceptional to me as I was one of the speakers in this session.

My initial gratitude goes to Hasin Hayder, who tried hard for first speakers like me. He even advised me about my topic “HTML5 – Web is getting sexy”! Continue reading →

300 posts on my blog – not a very small number

Confuscius said “It does not matter how slowly you go so long as you do not stop”. Interesting is that I learned about this quote just few minutes ago and when I knew about it, I thought slowly (without stopping) I have published 300 blog entries on this blog.

A few days ago, when I published my latest blog How I have solved the “The plugin generated xxxx characters of unexpected output during activation problem…” I did not notice that it was my 300th published post on this blog. I noticed it later and tweeted about it. Few friends also responded me with congrats. Thanks to all of them.

Today after reading the quote of the Confucius, I thought it is worthy to write a blog about my 300th blog post. Why? What’s the specialty of 300? Continue reading →

My two months experience with Macbook Pro

On July 11, 2010, I have purchased Macbook Pro from Aloha iShoppe! The main intended uses were developing iPhone application and getting more battery backup. I was excited seeing its look and feel! However, I was experiencing problems as soon as I started using it. I considered that as normal. Any new systems takes a while a adopt. But after about two months, I believe, problems are not decreasing! It significantly reduced my productivity. And no doubt I started hating Apple and its products. I hate it mostly specially for leeching my general computing habits! The daily problems I face with it are:

Continue reading →