Stay Hungry. Stay Foolish.

Time flies in 2016. It’s almost 4th quarter of this year.

Looking back, so many things has happened this year, including baby Max, parents arrival & leave, quitting DOTA, excessive weight gain and limited exercise including early morning dog walking.

Quietly, so many other important aspects in me have also changed. Gold has slipped by before I could realize the substantial damage inside.

I need to remind myself again,

  1. Stay Hungry, stay foolish
  2. Keep fighter attitude
  3. Let presure drive instead of crash

Technically, maintain a good routine as,

  1. Keep Side project going
  2. Constant reading from Hacker News
  3. Clear objective & promises, and be competent of finishing it
  4. Keep posting weekly

Life isn’t going any easier as same as this blog/post won’t go anywhere else. Keeping the reminder of the future days (drinking chicken soup).

Don’t die inside. Keep fighting and thriving.

– The end –

Handy script to work with PDF files

PDF is commonly used printing file format. Creating & organising it might be a bit hard if without Acrobat Pro’s help.

Today I discovered some open source lib to manipulate PDF files, including Creating, Splitting, Merging, and Re-Ordering PDF pages.

Below is the script line for creating PDF,

echo 'Hello World!' | enscript -B -o - | ps2pdf - content.pdf

-B for enscript omit the header for the output


Here is the script for re-ordering the raw PDF into a book-style printable version.

#!/bin/bash

if [ $# -ne 2 ] ; then
    echo "Invalid input supplied, please choose input PDF and page counts"
    echo "    example : ./format.sh <input.pdf> <pageCount>"
    exit 1
fi

echo "Formatting begins ... "
file="$1"
pageCount="$2"

let "blankPageCount = $pageCount % 4"

# Check if blank page padding needed, if so create one
if [ $blankPageCount -ne 0 ] ; then
    echo ' ' | ps2pdf - blank.pdf 
fi

# setup each fold loop - one fold means one print page
let "foldCount = $pageCount / 4"
startFold=0
pageOrganizor=''

echo "    total $foldCount printing slides generated";
echo "    with $blankPageCount blank pages";

while [ $startFold -lt $foldCount ] ; do
    let "coverPrintpage = $startFold * 4 + 4"
    let "leftPrintpage = $startFold * 4 + 1"
    let "backPrintpage = $startFold * 4 + 3"
    pageOrganizor="$pageOrganizor A$coverPrintpage A$leftPrintpage-$backPrintpage"
    let "startFold += 1"
done

if [ $blankPageCount -eq 0 ] ; then
    cmd="pdftk A=$file cat$pageOrganizor output fmt_output.pdf"
elif [ $blankPageCount -eq 3 ] ; then
    let "blankStartPage = $pageCount-2"
    cmd="pdftk A=$file B=blank.pdf cat$pageOrganizor B A$blankStartPage-$pageCount output fmt_output.pdf"
elif [ $blankPageCount -eq 2 ] ; then
    let "blankStartPage = $pageCount-1"
    cmd="pdftk A=$file B=blank.pdf cat$pageOrganizor B A$blankStartPage A$pageCount B output fmt_output.pdf"
else
    cmd="pdftk A=$file B=blank.pdf cat$pageOrganizor B A$pageCount B B output fmt_output.pdf"
fi

echo "Merging pdfs ... "
$cmd

# cleanning up
echo "Cleanup and done"
if [ -e "blank.pdf" ] ; then
    rm blank.pdf
fi

Outline about RESTful API system

Recently I have been doing RESTful API programming a lot. My understanding about RESTful evolves from “HTTP-Only” request to something more. Below is what I get from recent thoughts.

  1. REST is Representational State Transfer

    It is and only is a design framework for making network communication “web-like.” No specific protocol was proposed, and its main focus was on the communication part. Several questions should be considered during the developement,

    • What are the components of the system?
    • How should they communicate with each other?
    • How do we ensure we can swap out different parts of the system at any time?
    • How can the system be scaled up to serve billions of users?
  2. Client-server

    This is basic system flow of any REST system looks like. It has to be 1-to-1 flow with a centralized resource server. And any other parties who wants to interact with the resources

  3. Stateless

    Most important principle in REST, which means “Each request is treated as a standalone“. In detail, when a client is not interacting with the server, the server has no idea of its existence. The server also does not keep a record of past requests.

  4. Stable identification of resources

    Each resource must be uniquely identified by a stable identifier. A “stable” identifier means that it does not change across interactions, and it does not change even when the state of the resource changes.

  5. Manipulation of resources through representations

    Client manipulates resources through sending representations to the server–usually a JSON object containing the content that it would like to add, delete, or modify. In WEB case, it sends an HTTP POST or PUT request with the content to the server. The server sends back a response indicating whether operation was successful.

  6. Self-descriptive messages

    A self-descriptive message is one that contains all the information that the recipient needs to understand it. In WEB case, for example, request like below

    GET / HTTP/1.1
    Host: www.example.com
    

    This message is self-descriptive because it told the server what HTTP method was used, and the protocol that was used (HTTP 1.1).

    The server may send back a response like this:

    HTTP/1.1 200 OK
    Content-Type: text/html
    
    <!DOCTYPE html>
    <html>
      <head>
        <title>Home Page</title>
      </head>
      </body>
        <div>Hello World!</div>
      </body>
    </html>
    

    This message is self-descriptive because it told the client how it needs to interpret the message body, by indicating that Content-type was text/html.

  7. Hypermedia

    Hypermedia is a fancy word for data sent from the server to the client that contains information about what the client can do next–in other words, what further requests it can make. (Optional)

  8. Cache refers to the constraint that server responses should be labelled as either cacheable or non-cacheable. It should contains in the “self-descriptive message” described mentioned above.
  9. Layered system refers to the fact that there can be more components than just servers and clients. For example, proxy as load balancer, or security checker, authenticator, gateway.
  10. Code on demand works as the ability for a server to send executable code to the client, for example, HTTP server send <script> tag to client to execute locally.

Quora Read about Job Difficulty

Today I came across a question about Job Difficulty in Quora. Ref

One line here hit me the most,

I believe comments are an abomination – if you need to comment the code, its overly complex and the code should be rewritten to be clearer

I can’t agree more.

Once in my early days of coding, I believe code should be properly commented with reasonably “human language” explanation.

However, when the coding progress, it really comes to a question of “why will I comment this well structured, perfectly cleared and beautifully styled code?”

Well, most of the times, daily tasks involves clear, straight-forward meaning of code which doesn’t requires too much thinking on algorithms, or sophisticated calculations. If you are writing something too complicated for a production env purpose, you are either over thinking the objective, or you just doing it quite inefficiently. Most of commonly used functionalities, (like jquery-file-uploader, or node cheerio, or node mongoose), try to find a library, and improve from there externally.

In summary, comment are only used for pieces of code where GEEKs wrote in dodgy “Hackthon” project where it can cut-corners, and improve trivial performance in exchange of hard reading style, in which case I would highly doubt there will be a comment.

Normal coding should always follow best practice, structure the code clearly (MVC, middleware, etc). Naming properly with intention of the code objectives. and styled consistently throughout the code. (Which means always space/tabs, and tabs is of 4 spaces wide).

Thanks for reading, keep up to date with resume & coding.

Shock Shock Shock, life is fast – 56 UP

56 UP Review

I got tremendous shock after view the moving called 56 up. Its way of expressing one’s life in a flash urges me doing something worthy immediately.

Once I were young, I thought there will always be plenty of time to plan things, and lay back a bit to enjoy the life a little bit, and push other important things later. Because I knew at that time, for certain, if I became determined at some later moment, I will finish the task which was important to me.


However, that moment never came…


I always find myself lots of reasons to make myself believe that I was delayed for so many practical reasons, holding the fear of facing the fact that I was behind schedule.

Life is to short for planning and holding unrealistic reasons to wait, to hesitate. In a flash, I am already near 30. I dare to say, when I am near 50 and started looking back, life is still in a flash. And you will never know where all the time has been gone when you can achieve so many and so much while you were 30.

Life has been given equally to all human being in terms of time. The question is whether one can seize it and accomplish something worthwhile.

The deepest fear in me now is spending the time for absolutely nothing, accomplished nothing. Waste my life in wandering. When look back, there is nothing worth mentioning. And life is already behind me, and then started deeply question myself, what have I done to my life?

Most people won’t regret, at lease won’t admit it to themselves. But the truth is they know for sure there is nothing can be done to fix the issue which are already happened. There are so many thing cannot be undone once the timing is passed.

So seize the opportunity now, and leave no regret in the future.

Push harder, and harder. The only reason of being unsatisfied is not pushing hard enough.

Only in that sense, one can say for sure, my life has reached the upmost limitation. Even that limitation is so insignificant comparing to others. You know for sure, you cannot do any better even if with a second chance granted.

TPG acquired iiNet for 1.4 Billion AU dollars

Absolutely out of no where, I heard colleagues talking about iiNet acquisition this morning after I stepped into the office.

Firstly, one colleague came to us say “HiFI”, and others are applauding.

Then several minutes later, majority of people are discussing about the stock price. Saying they should buying more beforehand.

It turns out the stock price really rock up from 7.4 to 9.1 (17:03 at Syndey time 13rd March, 2015).

What a shocking news. This is a Capital Game!

Agile software development

Manifesto:

  • Individuals and interactions over processes and tools
  • Working software over comprehensive documentation
  • Customer collaboration over contract negotiation
  • Responding to change over following a plan

According to Kent Beck, the Agile Manifesto is based on twelve principles:

  • Customer satisfaction by rapid delivery of useful software
  • Welcome changing requirements, even late in development
  • Working software is delivered frequently (weeks rather than months)
  • Working software is the principal measure of progress
  • Sustainable development, able to maintain a constant pace
  • Close, daily cooperation between business people and developers
  • Face-to-face conversation is the best form of communication (co-location)
  • Projects are built around motivated individuals, who should be trusted
  • Continuous attention to technical excellence and good design
  • Simplicity—the art of maximizing the amount of work not done—is essential
  • Self-organizing teams
  • Regular adaptation to changing circumstances

译文如下(Translation):

个体和互动 高于 流程和工具
工作的软件 高于 详尽的文档
客户合作 高于 合同谈判
响应变化 高于 遵循计划

澳元汇率走势分析

观察澳元近期5年内的走势,在08年到09年之间,澳元有一次惊人跳水。
但紧随其后的就是一次迅速爬升。如下图:
5yr-au-cny

我至今还深刻记得09年时间里,我忙于申请国外研究生学校,而众多的学校都因为金融危机而无法给学生开出奖学金。
正当我疲于奔命在联系教授时,澳币4.4的汇率使我眼前一亮,而由此踏上了澳洲之路。

回归正题,有网上分析认为这次澳币的跳水原因:“持续了近八年的套息交易在金融市场全部溃败的情况下失去了存在的空间,于是”反噬”的过程开始了。由于市场对未来前景的极度悲观。原油跳水到了30美元,除了黄金任何商品都在急剧下跌。由于很多银行人人自危,贸易融资担保几乎停止,贸易量急跌,衡量世界贸易兴旺的波罗的海干散货指数下跌超过90%。世界贸易将近陷入停滞。那个”美好的循环”转向了!此时澳元在短短的三个月内澳元/人民币从6.61跌到4.25,跌幅高达36%,澳元兑美元汇率跌幅更是高达40%。金融恐慌把澳元打入了冰窖。”

就是金融恐慌,容易造成澳币的币值波动。
作为一个以畜牧业,矿业出口为主要输出经济的大国,加工制造业主要靠外包东南亚和中国,高科技和金融服务业主要受美国的影响。总体来说,它是一个对国际贸易依赖较大的国家。所以全球经济的气温都会直接影响澳洲货币的价值。
最直接来说,就是澳洲为了保持贸易顺差,必须及时调整它的内部经济政策以及货币政策,来保证国内就业率和社会稳定。而澳洲为了保持其经济的增长和发展,就需要一方面综合丰富发展本国经济结构,另一方面稳固地适应到当前的世界经济格局中。

与此同时,再看澳币的迅速崛起过程,网上分析说:“在世界各国央行和政府的联手行动下,恐慌情绪慢慢在金融市场上消退,世界主要央行向金融市场保证,货币会充分供应,融资需求会得到有效满足。各主要国家央行利率急剧降低至前所未有地步。各国政府出台大额经济刺激计划。这一切让金融市场缓过劲来,原先冰封的商业票据市场和银行间拆借市场等金融市场开始解冻,进出口企业逐渐可以在银行获得贸易融资,国外银行承兑票据可以在本国银行贴现,世界贸易渐渐得以恢复,在金融血缓慢舒缓后通后世界贸易似乎活了过来。商品开始大幅反弹,囤积美元避险需求慢慢减少,外汇市场开始聚焦未来美国政府的巨额赤字。美元在危机后遭遇了”迟来的”打击。在中国再次钉住美元的汇率政策下,澳元/人民币开始了快速攀升的过程,至今已经上升至6.2,涨幅接近46%,几乎快要达到了跳水前的高度。澳元同时期对其他货币也是大幅反弹。
这样说明在世界经济局势好的情况下,澳洲凭借自身的资源优势,在市场利好的前提下,货物很容易出手。这样早就了澳洲经济的迅速复苏。

另外再看一幅数据:
1yr-au-cny
澳洲一年的汇率起伏如图所示。一年波动都在6.15以上,在5月底达到最低。
但有分析家认为,2013年是澳币跌的一年。
根据3月5号最新RBA消息:Statement by Glenn Stevens, Governor: Monetary Policy Decision
澳州储备银行将维持利息不变政策,因看其经济形势回暖。