Friday, December 30, 2011

Advice from a Facebook Engineer

Extracted from a lovely article:

Meet a Facebook Engineer: Haiping Zhao



Q: What advice do you have for other engineers?
A: As a senior engineer, I have been through the programmer ranks and have distinct advice for each stage.

For junior programmers, I highly recommend spending time with a wide variety of technologies, including HTML, CSS, JavaScript, PHP, C, C++, Java, and SQL. This can help you identify your interests and potential directions for career development. Knowledge-wise, it is also extremely beneficial to have broad understanding of different problem solving methods.

For intermediate-level people, I think Facebook is one of the greatest places for having impact. By taking on challenging tasks, you can make changes that affect millions of users. Nothing is more exciting than seeing your code change the world. Facebook counts on our talents to come up with genuine ideas, respectful communications, and great implementations.

For senior people like me, it's really our job to coach young engineers on how to approach technical problems systematically and how to resolve disagreements gracefully. The job comes with the great responsibility of supervising the entire engineering force to move in a direction that we as a company are happy with. I hope senior engineers are willing to spend their time helping other people grow instead of just focusing on their own work. By putting ourselves into "sharing mode," we can help build a great software community within our respective companies that will proliferate for long, long time.

Haiping Zhao, a senior software engineer, writes code...for fun.

Thursday, December 22, 2011

Start to Learn Android Programming

I had the intent to learn Android programming 6 months ago. Since then, I have installed SDK several times, and gathered some study content such as reference books. But I haven't really started any developing activity until this week.

A couple of interesting or not so interesting finding so far.
  • The tutorials and the new training materials on the developer website are good. But there are far too many detailed technical documents, overwhelming. For an absolute beginner, a syllabus or a simplified guide is a must.
  • Like iOS applications or some web apps, Android is in favor of MVC paradigm -- with different terminolgoy. An article discusses the relationship of the model, view, controllers in Android.
  • Unlike iOS apps that have uniform screen size, Android developers need to consider different screen sizes a lot. The dpi concept doesn't really make things easier. 
  • I heard that XCode is really easy to use. I think Eclipse is a almost perfect IDE for developing Android apps, except a few drawbacks: huge memory consumption; manual SDK upgrading and manual emulator setup. Compared with visual studio, neither loses. 
  • Last, Android has built-in logging utility. One of the log level is called wtf -- "what a terrible failure".

Tuesday, November 29, 2011

Objective-C v.s. C# -- A Quick Compare

Here is a quick comparison table of some basic terminologies after I read "Learning Objective-C: A Primer":

Objective-C
C#
Instance variable
Member variable
“id” weakly type
“var” implicit type
Strong typed variable must declare itself to be pointer:
MyClass  *myObject1;
Reference type variables are by default pointers.
instance methods and class methods
object methods and static methods
Messaging an object
Invoking an instance’s method
Properties
Properties (get; set;)
“self”
“this”
protocol
interface

挥之不去的猎头公司

06-07年毕业找工作的时候,到处发简历,少不了那些知名的猎头公司。若干年后,只有一家猎头公司孜孜不倦地记得我,时不时有个猎头给我发信,告诉我某某投行有个什么机会,问我感不感兴趣,想要联系我。有时候我就删除了;有几次我心情还不错就很明确地告诉他们不感兴趣;最近几次我告诉他们,“请把我在你们公司的记录删除”,别再来烦我了。当然,如果事如所愿,我就不用写这篇blog了。

从我的角度,可以得出以下几点猜测:
1。这家公司要不就是人口众多,要不就是人员流动大,否则不会每次来找我人都不同。
2。投行市场很难做,猎头要找很多很多份简历才能找出合适的。否则我4、5年前的简历也不会被挖掘出来。
3。这些猎头也太不专业了,挖掘出来的简历也不看看,就到处撒网直接打电话发邮件。邮件还好说,手机号码换掉的可能性很高吧。

总之,我没有从那家猎头公司里得到过任何合适的工作机会。那家猎头公司的缩写是SJ。

Friday, November 25, 2011

HTML 5 is rising

Came across a well-written article about HTML 5 -- Top 10 Reasons to Use HTML5 Right Now. Good for reading. The key attractiveness of HTML5 is simple and powerful, standardised yet flexible.

When I read the section about Game Development, I couldn't help remembering the days when I did game development class project with CSS/Javascript/SVG in IE6. Yes, IE6 with all the confusing DOM structure. Kids nowadays are so lucky, they would not be bothered and bounded by the inferiorness of the browser.

[WordPress Contact Form 7] Add Numeric Type Field

This is about adding a numeric type "num" in Contact Form 7 (CF7, version 3.0.1) with minimum effort. This type only allows input to be numbers. Basically we will reuse a lot of the existing code in \wp-content\plugins\contact-form-7\modules\text.php It doesn't matter where do you put the code as long as they are in the same file.

1.
Register two shortcode:
wpcf7_add_shortcode( 'num', 'wpcf7_text_shortcode_handler', true );
wpcf7_add_shortcode( 'num*', 'wpcf7_text_shortcode_handler', true );

2.
Register the validation filter and implement the filter:
add_filter( 'wpcf7_validate_num', 'wpcf7_num_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_num*', 'wpcf7_num_validation_filter', 10, 2 );

function wpcf7_num_validation_filter( $result, $tag ) {
    $type = $tag['type'];
    $name = $tag['name'];

    $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );

    if ( 'num' == $type || 'num*' == $type ) {
        if ( 'num*' == $type && '' == $_POST[$name] ) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
        } elseif ( '' != $_POST[$name] && ! is_numeric( $_POST[$name] ) ) {
            $result['valid'] = false;
            $result['reason'][$name] = 'Numbers are required.';
        }
    }

    return $result;
}


3.
You can try to add your Tag Generator for the new type, but I just don't bother. To use the new field, it is the same as using [text] field, e.g. [num mobile /10 class:mobile]

Wednesday, November 23, 2011

ACS讲座之Strategic Knowledge

最近加入了ACS,昨天晚上第一次下班去听讲座。Strategic Knowledge by Dave Snowden。获益匪浅。先讲个小插曲。昨天晚上我穿得实在是有点休闲——T恤短裤。在门口被ACS的主席拦住,问我是不是注册过了。

一个小时的讲座,信息量非常大。很多理论穿插着许多有趣的故事。从故事中引起听众很多共鸣,而不是竭力灌输某个系统的想法。用Dave的话来说,人是从故事中学习理论的。其中一段经典的段子,“怎样管理小孩的聚会”,在youtube上找到了。

回想一下讲座的内容,很多对事物认知的哲学理论似曾相识。中国传统的道家法家文化中似乎都有涉及。可惜中国在重复着西方国家将要抛弃的管理理念,抛弃了自己千年来反复验证的价值观。

Dave的一些理论片段在这个post里可以略览。当然没有故事,这些理论有些苍白。

Tuesday, November 22, 2011

[WordPress Contact Form 7] Populate Select Dropdown from Database

Contact Form 7 (CF7) is a popular plugin for the WordPress CMS. It supports a few basic form components that allows user building a form quickly. One particular problem I had is to populate a drop down selection box from content stored in the database (e.g., a list of vacant positions). To dynamically populate dropdown options is not an uncommon task for site builders. And if you know something about programming, this wouldn't be hard either.

With CF7, you can only fill your options by hand. I have looked around for solutions, and found this post on the forum. However, it only appears to be working but not quite -- every time it rebuilds the options from database regardless user input, and nothing will be sent on submission (see the last comment in this post).

I then had to worked out my way; I believe this is original, so copy right reserved *_^. Here is how. (By the way, the version I am using is Contact Form 7 3.0.1).

In the wp-content\plugins\contact-form-7\modules\ folder, find the select.php. This is the file to be modified. (In general, I do NOT like to hack into the plugin source code. This will make upgrade difficult.)

1.
In function wpcf7_select_shortcode_handler, $values, $labels and $defaults need to be redefined for your customised dropdown. They are arrays for dropdown values, dropdown texts and default selection respectively. I have the following snippet right after $options are parsed (after line 50). Here my select field ID is "position".

if ($name == 'position') {
  // query the positions
  $positions = new WP_Query('YOUR_QUERY');
  
  while( $positions->have_posts() ) : $positions->the_post();
    array_push( $values, get_the_ID() );     // post ID as option value
    array_push( $labels, get_the_title() );  // post title as option text
  endwhile;
  
  // set the key of the default selection
  array_push( $defaults, 1 + array_search($YOUR_DEFAULT_VALUE, $values) );
} 

2.
In function wpcf7_select_validation_filter, you need to re-fill the dropdown option values before the post operation because they cannot be found in the shortcode. They will be needed in $_POST later. I have the following snippet right after the local variable definitions. The code is very similar.

if ($name == 'position') {
  // query the positions
  $positions = new WP_Query('YOUR_QUERY');
  while( $positions->have_posts() ) : $positions->the_post(); 
    array_push( $values, get_the_ID() );
  endwhile;
} 

And that is it.

Monday, November 14, 2011

LINQ Speedup

"From 10 minutes to 10 seconds" -- this is true experience I had. The brief story is, I had to insert a lot of records into the database. The way LINQ does (if you look at the generated query by using some SQL profiler) was to insert the record one-by-one surrounded with some safety check. Pretty straightforward; and it works fine in a small scale. In case you have cascaded data structure with a lot of Foreign keys floating around (which is normal for normal forms) in your database, the time it takes can be arbitrarily long -- Imagine how many tables it requires to lock before any one operation.

The way I found which works faster when inserting a lot of data in one go needs just a few extras.
  1. Cache/Serialise the tables to local data structures, if they are read repeatedly and not very large. This can save a lot of SELECT statements generated by LINQ. Preferably, perform a sorting on your local data structure, which can support faster BinarySearch(). (e.g.)
  2. Write a stored-procedure that handles Bulk-insert to multiple tables, in which you must have safety check and error handling as well. After all, stored procedures are first class citizen in handling the database operations. (e.g.)
  3. Instead of calling LINQ insert, call the stored procedure (registered as function import in .dbml). (e.g.)
All the above are not tricky to be done. But the result can be astonishing and worthwhile.

Gplus

Recently, I read a very insightful post about whether or not G+ is dying. The key question lies in front of the internet giant I guess is whether social networking is a service or a product.

I am a rare user of Facebook or Twitter; but I am a frequent user of Weibo. Not saying that Facebook or Twitter is not good, in fact they are great and lots and lots of my (non-Chinese) friends love them. Just I prefer Weibo as lots and lots of my (Chinese) friends are using them, even my parents and my in-laws are visiting Weibo regularly. Yes, it is not about which product is better, it is about who else is using it. That's the essence of Social networking. Of course better products attract more people, but there is also timing, preference, acceptance, etc.

Back to the capital G, there have not been a lot of exciting updates. Honestly, I haven't used "Like" or "+1"; I have not switched to the new look for my inbox; I visit G+ once a month probably. On the other hand, I am still a loyal gmail user. So will G+ be successful, we could have asked Steve.

Friday, November 11, 2011

Back on blogger

Back on as a blogger, after exactly one year since my last post -- yet another coincidence. There is no way for me to foresee one year ago that I would be moving to Brisbane, a city of burning sunshine to me. As I am communing to work everyday on bus, I start to have more time listening to interesting podcasts and thinking about some random stuff. Blogger is a good place for me to gather the thoughts and archive them.

I like the new look of blogger, like Wordpress but neater. I think I would spend some time to customise it. First thing on my list is to get some code block style working so that I can share my discovery during my technology adventure. In the spirit of "PseudoRandom Thoughts", I will also post some interesting findings or stories; and thinking should be posting more in Chinese.

To sum up, I resume my blogging habit on this special day 11/11/11.