.

Algorithm is fundamental of computer science, though it is not directly demanded in daily work. Continuing learning and solving algorithm problems makes me constantly aware of how many difficult problems exist in computer science area, and how tiny I am in computer science field. That is a big getaway for me, as CSer and tech worker, from the hype of all various of technologies, from up-and-down bubbled tech stock price, and from lucrative compensation TC numbers. It remindes me how I started CS track, and how I learned CS, and how I struggled with CS. I like the feeling of appreciation among all challenging problems in CS theories.

Keep coding, keep learning.

SL.

I love independent film.

Independent film is a kind of art, conveying intensive view of everything, while movies in theater is better for killing time.

Photo of Tiger Eyes

pic from: http://www.csmonitor.com

#AngularJS?

Based on JavaScript, like PHP and other script languages, can do (virtually) everything at client side.

#Build Website by AngularJS? It is enough!

##How to deploy on server?

I was confused by this. Because you can click the html file and see the website, but how to access via Internet? Apache server! It holds files on server, very powerful!

##Sometimes need more

###Bower? Package denpendecy manager. Declare lib dependency in bower.json, and type “bower install” to download all js libs. It is like maven in Java, but more light-weighted.

###Grunt? Make script alive. It is “task runner”, doing automations. Simply, it is something outside AngularJS, and do testing, minimize js libs into 1 file, and also can start up a server for scripts. Then you don’t need Apache server any more.

#Enough by AngularJS? Not really! Script is mainly used for loading views and handling some logic by controller in the middle. But cannot take heavy tasks. So we need more! MEAN.JS is a solution! MongoDB, Express, AngularJS, NodeJS. We have focused on AngularJS on client side. Now, M+E+N build the back-end server. Express is the web framework building on NodeJS, making it easier to handle web events. And NodeJS is server-side JS which connects MongoDB. MongoDB creates/ updates/ inserts/ deletes/ queries Json-format data.

#General View of App Generally, back-end server runs REST service. And front-end AngularJS makes request to REST server, and gets data to update views. That is very similar to mobile App dev. Client side code is equivalent to mobile app code, which both make request to REST server (or other ways) to obtain required data to update views. But mobile app is more complicated as it has cache mechanism so that can run offline as well.

Some traditional web apps, according to my understanding, are more rigid for front/back-end binding. Like structs in J2EE, the web app runs on the web container, and catch URL request, then route it to some functions to do logics, and then render the view page (asp for example), injecting data and loading the view. The workflow is like: request ->(struts) back-end -> view with data. And the web work with REST service is like: request -> view without data(js/php) -> back-end(restful) -> view with data.

#Conclusion Should learn more!

I guess some people think that iterative version of tree traversal is tedious to implement. But I found a very interesting fact that could make it as simple as recursive version.

As a reminder, for recursive version of pre/in/post-order traversal, the only difference is the order of following three lines:

dfs(root.left);//rec-l1
print(root);//rec-l2
dfs(root.right);//rec-;3

Similarly, if we take advantage of dummy node, for iterative version, the only difference is also the order of three lines:

if(node.right!=null) stack.push(node.right);//iter-l1
stack.push(node); stack.push(null);//iter-l2
if(node.left!=null) stack.push(node.left);//iter-l3

You may have noticed that the above two clips of code both represent the inorder traversal. And if we follow the order of rec-l1, rec-l3, rec-l2 or iter-l2, iter-l1, iter-l3, then we could get the postorder traversal. The source code of iterative version is shown at:

Most interestingly, there is another property of postorder traversal. Suppose we have a tree T, and the mirror tree of T is T’. Then postorder(T).reverse() equals to preorder(T’). So, if we use two stacks, then we could solve the postorder problem more simpler! The source code is shown at:

Both 2 solutions for postorder traversal can be extended to solve the n-ary tree postorder traversal (which could be a follow-up in a interview!).

I just started to learn iOS dev. And I discovered 3 ways to organized and navigate views for iOS.

  • Storyboard
  • Xib
  • By programming code

I initially followed the tutorial provided by Apple, and it instructs to use storyboard to organize views, which is visualizable. And later on I found some other projects are using xib. Some articles summrized the pro/con of those two methods. But the most interesting/technical way is to write view by code. I dig into the source code of Anypic, and fonud that programming the view is more universal though less visualizable. But I still love the third one. I found an article the compares the 3 methods for reference.