Day 40, Thorax.js sub views

Continue working on the client project.

Made significant progress with my Thorax project.

One cool thing is to have a child-view telling the parent-view to close.

I have a modal view with a sub-modal view. The modal view will have all the basic functions of a modal. The sub-modal view is going to change all the time, showing different content. The concept worked well until I hit the point that I need to: click a button inside the sub-modal view, and ask the modal view to close.

With the help of Victor, I did a couple of things:

1. on click, the sub-modal view triggers an ‘close-modal’ event
2. the modal view listens to the ‘close-modal’ event from the sub-modal view and close itself. The key is using Backbone’s listenTo function.
3. Of course, life is never that easy. In reality, I extended my modal view from the Backbone.bootstrap-modal library, added the “listenTo” in the initialize(), and also called the super class (Backbone.bootstrap-modal)’s initialize() too.

Anyway, I was so happy that it actually worked!!! Yeah….

Oh, Marcus hosted a technical interview meetup in HackReactor tonight. It was very informative.

First, he interviewed Kyle and another guy. Then, we broken into smaller groups to work on four different technical problems. In the end, he was interviewed by another guy.

Nothing is really surprising, but compared to a case interview, there is not enough focus on thinking out out during a technical interview. It makes sense since there are way more interactions between consultants and clients than the interaction between different developers. The other difference is a case interview will likely have many right answers, while a technical interview has at most a couple right answers, with one or two of them being the best.

Marcus asked the question on how to design the architecture of Twitter. I guess this must be a fairly popular question for backend positions. It involves understanding of different pieces of the stack, basic database queries and advanced database operations during scaling. To serve a user’s read request for his own timeline, the user’s timeline was precomputed and stored in the database. You are essentially sacrificing space for speed. The more we talked about Twitter, the more I appreciated the smooth operation of Weibo. Kudos to engineers in Weibo, you guys did an awesome job in scaling it up.

The four technical problems are: hashTable, breadth first / depth first tree traversal, count the frequency of characters and sort them by frequency … (don’t remember the last one)…

I came up with a way to do breadth first tree traversal:

var node_list = [];
node_list.push(root_node); //root_node is the first node in the tree
var i = 0;
while (node_list[i] !== undefined){
  //each node stores all the children in an array called node.children
  for(var j=0; j<node_list[i].children.length; j++){
    node_list.push( node_list[i].children[j] );
  i += 1;