Friday, June 19, 2009

Javascript inheritance - the ultimate solution

Stop googling around. This is THE solution for javascript class inheritance unless you are using the Prototype framework

//Simply declare the following methods once:

Object.prototype.Inherits = function( parent )
{
if( arguments.length > 1 )
{
parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
}
else
{
parent.call( this );
}
}

Function.prototype.Inherits = function( parent )
{
this.prototype = new parent();
this.prototype.constructor = this;
}

//Then declare inheritance easily:

function Mammal( name )
{
this.name_ = name;
}

Cat.Inherits( Mammal );
function Cat( name )
{
this.Inherits( Mammal, name );
}

ColoredCat.Inherits( Cat );
function ColoredCat( name, color )
{
this.Inherits( Cat, name );
}

Lion.Inherits( ColoredCat );
function Lion( name )
{
this.Inherits( ColoredCat, name, "gold" );
}

Source code obtained from: http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html

Monday, June 8, 2009

Tyler B in action





Since stupid facebook doesn't take animated gifs,
here you go!



Wednesday, December 24, 2008

Installing the Eclipse Javascript editor (Javascript Development Tools - JSDT)

Every now and then I try to look for a good HTML and Javascript editor or IDE, but most tools I find from google are either commercial (e.g. IntelliJ) or simply not convincing enough that they will do the job properly. So the mission had not been successful and all the way I had been stuck with Textpad, until today. Today, I have come across this article about the Eclipse's Javascript Development Tools (JSDT) and found it extremely interesting because of my positive experience with Eclipse for Java. Unfortunately, the current documentation for JSDT sucks, if there is any. For instance, if you have already read the article above, you should be confused as to whether the T in JSDT stands for Toolkits or Tools >_<. Anyway, this is the official website for JSDT and it says "Tools" so I will stick with it. Installation can also be confusing because JSDT is part of the Eclipse's Web Tools Platform project (Web Developer Tools).

Without further ado, here are the steps for installation:
  • Open Eclipse
  • Go to Window > Preferences, search for Proxy and then configure the Network Connections if required
  • Go to Help > Software Updates, click on the "Available Software" tab
  • Expand the "Web Tools (WTP) Update Site"
  • At the bottom you should see "Web Tools Platform (WTP)" with the newest version number. Expand that.
  • Select "JavaScript Developer Tools" and "Web Developer Tools" and then click on Install at top-right. Ignore the "SDK" versions. Depending on your Eclipse version, "Web Developer Tools" may already be installed and you will get a message about that. If you only install "JavaScript Developer Tools", you won't be able to edit HTML, which is a headache, so please make sure both are installed!
That's it. Just open a new "Javascript Project" and play around. For instance, you can open a new javascript file with .js extension, and then type in "document." and then press ctrl-space, you will then see all the code completion suggestions. Write a few functions or classes in another javascript file and those declarations will be available via code completions as well (even they are not "included" at runtime, which is an imperfection of the IDE IMO). You can also right-click on the project, click on properties, go to JavaScript>JavaScript Libraries and then add the FireFox and IE libraries. But I don't find this particularly useful because after inclusion I still don't see the "innerHTML" property correctly referenced.

While I'm still in a good mood to share, let me share this article as well - 10 Eclipse Navigation Shortcuts Every Java Programmer Should Know [many applies to non-java as well]

[update 29/12/08] Although not free, IntelliJ IDEA 8 is definitely worth a try - get the 30-day trial!! Aptana is also worth checking out; it's free and Eclipse-based. Referencing is also smarter than other Eclipse variants!

Tuesday, January 29, 2008

VIRUS/ Trojan: How to remove Win32:OnLineGames -SR / Win32:Delf-HSQ

This article is about the removal of the super annoying, reoccurring, self-generating trojans, namely: Win32: OnLineGames-SR / Win32: Delf-HSQ / Win32: OnLineGames-BUK / Win32: OnLineGames-BSI / Win32: OnLineGames-BYS / Win32.OnLineGames / Win32.Delf.

Symptoms: Anti-virus software such as Avast and Spyware Doctor cannot completely remove the virus or trojan, because the source (the origin) of the problem is not identified. Instead, these anti-virus programs continuously detect the secondary viral (trojan) files that are derived from the problem source, such as Local Settings\Temp\tmp1.tmp, tmp2.tmp, Temporary Internet Files\Content.IE5\xxxx, which can never really get removed because they are continuously generated from the source. When a thorough scan is done in safe mode, you would find viral/trojan files such as DiskMan32.exe, Kvsc3.exe, AVPSrv.exe, mppds.exe, MsIMMs32.exe, NVDispDrv.exe, cmdbcs.exe, upxdnd.exe, msccrt.exe and DbgHlp32.exe in C:\windows, and their corresponding dll files (e.g. DiskMan32.dll) in c:\windows\system32. They can be removed, but similar viral files will be generated by the source in subsequent reboots.

Infection medium: I personally got the virus from a real player file, probably through some built-in plugins. So I learnt to make sure File>Work offline is checked before watching any movies and to disable any features related to plugins.

Solution: This is what I did to remove the virus:
  1. Check if c:\autorun.inf and c:\autoRun.exe exist. Remove them if they do. Do the same for drive d:\, e:\, etc (all other local hard drives). Then remove all detectable virus/trojan files in safe mode. (See this site)
  2. Uninstall Internet Explorer (just use Firefox or reinstall IE later) in Control Panel>Add or Remove Programs>Add/Remove Windows Components.
  3. Go to Start>Run>msconfig>startup. Uncheck ctfmon.exe (the probable source). According to Microsoft, a process called ctfmon.exe is used by Office XP (not windows xp, not office 2003 or other versions). However, I am using Office 03, so I believe this process is not neccessary for my system (office still runs well after disabling this). If you have Office XP, you may keep this process and just carry out point 3 below.
  4. Go to Start>Run>regedit and remove the following registry entries (based on my inspection with RegMon):
    • HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings
    • HKLM\SOFTWARE\Microsoft\Tracing\RASAPI32
      (if you are chicken, you can do a right-click>export to make a backup before doing a right-click>delete)
This should solve the problem. Some static infected files may still exist in your system, but your anti-virus software will have no problem in handling them. (BTW, avast is free... so no excuse for not having a anti-virus software in your windows; also, remember to keep your firewall UP running!)

Wednesday, January 2, 2008

你有幾 multitask


你用 Windows , 平均一次過開幾多個視窗? 你的 start bar 有幾多行? 我拉三行 (見圖)。

好羨慕別人有兩個大大的 monitor, 東西可以左放石放?

不用羨慕, 你可以有二十個免費的 mon (一般四個就足夠)。 那來? dexpot !

http://www.dexpot.de/index.php?lang=en

自己玩玩。包不後悔。

Saturday, November 24, 2007

momentum of life

不能轉
惟慢走
奈何能吊多久

Saturday, October 13, 2007

工作與我

Having a look at my old blog post, the time when I was totally determined to find a job was some time in April. Following my eager determination was months of failure and desperation. The first interview failure was definitely tough, but then subsequent failures and rejections became kind of normal for me.

Mixed emotions. Even when I finally got this petermac job I'm doing now, it took my mind a while to settle. Would I be better off if I got the Telstra job? What about the Origin job? At one point I thought the Business Intelligence positions offered by Telstra/Origin and other listed companies would be the perfect start for me. I realized later that I was just too ignorant and idealistic -- only half of my profile fits the field of BI, and my desire and dream can never count. I failed the job interviews, but I have never regretted that I tried; failure toughens people up, making me more emotionless, more invulnerable, teaching me how to do better in later interviews.

If business intelligence was my "dream job" before, then what am I doing in petermac now? Working as a bioinformatician now, have I given up or forgotten about my dream? No No No. Dreams evolve, what happened before was just a process, where i am now is where i am supposed to be, my destiny. If I am to do a comparison now, definitely the petermac job is far more perfect than the others in all aspects -- honourability, appreciation of my qualification, relatively smooth ride to a good future, and of course, salary.

Okay, my job is great, my previous career dream about business intelligence was crap. What about my other dreams, the other parts of me? Commiting to a job doesn't just take away my other career dreams, it seems to be sucking the whole me into it, little of myself is left on the earth. Right, i only work 8 hrs a day and there is supposed to be a good work/life balance. But why do I not feel like myself anymore! I used to think about how to play better warcraft, how to make myself a billionaire with zero capital, how to think of nothing, and etc, but now I'm not. Am I adopting? Or am I disappearing?

Saturday, May 26, 2007

>_< 黃家熙 巨人

本來呆滯的看着 hk.yahoo 新聞。 看到「黃家熙」三個字,驚訝的大叫了一聲,但心只無聊地想着:「同我中學同學『巨人』個名一樣啊!」。

再看一看,消防員? 好像有人說過給我聽巨人已投身消防。心感不妙。但有同名同姓的消防員,好出其嗎? 又再看一看,廿七歳? 在香港叫黃家熙又是二十七歳的,可能有一百個,但平均每一百人,有幾多個係消防員呢? 思想中開始出現「唔係呀ma」同「WHAT THE X」等等字句,內心亦開始回想起巨人的樣子﹑神態﹑故事﹑與我以往的交流﹑和球場中籃底下的影。

第二天報紙又形容多了,再不能否認已為港損軀的黃家熙就是當日九龍聖芳濟書院同學老師都喜歡的巨人。

巨人是好人,待人以誠。壞的同學﹑書蟲同學﹑呆的同學﹑偶像同學,個個都同佢有兩句,老師也喜歡他。籃球場上是 Shaq-Q O'neal... 經歷過罰球苦練的階段 :)

我希望巨人的英勇犧牲是有價值的 — 希望消防處會認真檢討,好讓近似的事情不會再發生。說真的,「因為閃燃所以出意外」絕不是理由。 隊目沒想到閃燃會出現嗎? 沒有防範嗎? 一千個理由也推卸不了這次意外是消防部署的疏忽。 種火的那些人也該死!


http://hk.news.yahoo.com/070521/12/27w14.html
http://hk.news.yahoo.com/070522/12/27xk4.html
http://hk.news.yahoo.com/070522/12/27xk6.html
http://hk.news.yahoo.com/070522/12/27w9d.html
http://hk.news.yahoo.com/070522/12/27w3i.html
http://hk.news.yahoo.com/070522/12/27xqe.html

Saturday, April 21, 2007

Promise VS Commitment

Promise = 諾言
Commitment = 承諾

中文上的解釋,我不懂分別。 英文的解釋好像比較容易理解。

Promises can be made as long as you can speak.
Commitments are hard facts, that are demonstrated by actions.

Promises can be easily broken. Commitments can fail too, but at least they make you closer to your goal.

So, I guess one step to achieve your goal is to TURN A PROMISE INTO A COMMITMENT.

How? Make some bold moves that force you to do something.


To learn swim, jump into the sea. (DEADLY)

To finish my thesis, find a job. (DEADLINE)

To live happily ever after with your loved one, pay deposit for your wedding dinner. (DEADLINE)

Smelling DEATH is the push, and is what makes you commit.

Fxxk compound interest

Just read some tutorials in investopedia.com. Like all other investment salesmen would say, one REASON to do financial investments is compound interest. What the fxxk? I believe this "reason" sucks, and is no longer valid in this modern 21st century.

Ok, maybe we are noobs who don't know how to buy the right stocks at the right time, and maybe we are not aware of many other ways to make effective use of our money. But hey, our money is not under the pillowcase, they are in the bank earning compound interest, however small it is. It is no way "compound interest" is the reason why we should learn various investment skills; it is simply the potential return that we need to emphasize on.

Can the people who write articles, as well as those financial counsellor and salesmen, be more creative, heartful, and throw away the old-school texts >_<

Tuesday, April 3, 2007

休息

休息 - 你做得到嗎?

忙碌完一輪,累了,你可能會聽音樂、飲吓茶、同人吹吹水、行吓街、又或者打吓機。 但這些都不等於休息。 做這些東西的同時,你的身體沒有休息,你的思想同樣沒有休息。

休息等於什麼都不做、什麼都不想。你又做得到嗎?

要思想靜止,大家都知道好難,如果唔係都唔會有咁多打坐修行班。

要行動靜止什麼都不做,你可願意嗎? 我相信很多人都會同我一樣,揪唔到時間出來乜都唔做,覺得有很多事情比坐响到十分鐘乜都唔做更加有價值更加有趣。

在此奉勸大家 ( 包括我自己 ) :唔諗唔郁廿分鐘,做人就會好輕鬆。 不做不想在這繁忙的社會裡是很有價值的。

Monday, March 26, 2007

Do you care?

Do you care about something, but you just can't help it? Maybe you just don't care about it enough.

If you care, then you see opportunities. If you care, then you would see other ways of achieving it. If you care enough, then at least you would think there ought to be a better solution.

Otherwise, it's all excuses for your careless.

In America's Next Top Model you always hear the girls say "only if you want it bad enough". To me, it is somewhat true.

So.. careless or excuses?

Sunday, March 18, 2007

近日日圓風波

為什麼日圓勁升? 日圓升怎影響股市和基金?


The article below was provided by ...Anonymous....

See this post for other explainations.

Theory behind "the Jap dollar" on stock market

Written by ...Anonymous..., 16 Mar 07

Japan has one of the largest foreign reserve in the world. What that means is that the Japanese has accumulated a lot of foreign currencies (or money so to speak) through trade in the 70's and 80's. When their economy collapsed in the early 90's (for reasons that are similar to HK in 97), no one is willing to borrow money to invest anymore. To simulate economy growth, the Jap central bank has lowered its interest rate to 0% within a few years. So it will cost absolutely nothing to borrow Yen. "Free" money so to speak.

So you are a foreign investors, looking for investments, what would you do? Jap's rate = 0%, US current interest rate is 5%, Aust ~ 6%, NZ 7%. The easiest thing you can do is to borrow Yen at no cost, convert into US/AUS/NZ and put a fix deposit in the bank for a year, earn the interest rate, and convert back to Yen again. You would have earn the >= 5% of interest. (This practice is referred to as Carry Trade)

You may wonder that the exchange rate would have changed so much in a year that the earnings on interest would have gone. Well, this might be true for other countries, but Jap central bank has a notorious reputation to stop the Yen devalued too much to protect the interest of the businesses who rely on exports for profits. So the exchange rate is guaranteed to be pretty stable in the foreseeable future.

Now of course, one don't have to be as conserved as I've mentioned and use the money for fixed deposit. Many of these "free" money would have used in many other ways. Shares, bonds, derivatives, equity...you name it.

So when the Jap central bank rised the interest rate from 0 to 0.5% within a short period of time, the general investment communities was panic since the cost of borrow the "free" money goes up. If your investments is not earning the 0.5% interest rate, than you better return the Yen. And simulatenously a lot of other people is returning the Yen, which pushed the Yen's rate higher (exchange rate). The higher rate would means that the cost of the Yen would be higher, compared to the time when you borrowed it for investment. So more people would return the Yen, and the vicious cycle goes on.

Of course, there are FXXKING millions of reasons why the stock market crashed. And people just love to explain these things.

Written by ...Anonymous..., 16 Mar 07


熊市和牛市係乜意思?

Read this link. You will know more about the rise and drop of stock prices:

http://hk.knowledge.yahoo.com/question/?qid=7007021702685

有野唔識?想學新野?太容易啦!

最近認識了《Yahoo!知識》 (thx matthew)。 它是一個網上發問的好地方。 同類的網站還有 experts-exchange.com, 但那網站是集中於問 IT 問題的。

網上發問好嗎?

我早在 experts-exchange 問了上一百條的問題。 其中過五十條的內容,並不是自己有興趣認識的,而是有須要認識的。讀萬卷書不如問一問。省時間啊。 現在有Yahoo!知識,我連自己最不懂而又想認識的範圍(如法律﹑經濟)都可以一問。不是很好嗎?

但曾經有個朋友同我講,佢話問問題好難。如果覺得問問題難而放棄認識,那真的很可惜。 我相信有些人覺得問問題難是因為他們不肯面對或不理解自己對那個題目的無知。 例如看完一篇文章唔明,會唔識問點解嗎? 唔明標題就直接問標題點解,有個字唔識也可直接問。但如果你要假設自己 "大概" 明,而只係 "唔知點解" 明唔得哂,那這就是問問題的障礙了。

想清楚自己不懂的是什麼是學習的第一步。厚面皮乜都問係第二步。

你的最愛網頁有 RSS 嗎?

Do your favourite websites have this icon ?

If your answer is yes, then you should check out Google Reader - http://reader.google.com

The icons or are usually referred to as RSS or Atom feeds. If your favourite webpage or blog provides this icon, you can right click on it, and then click on "Copy Shortcut" or "Copy Link Location". Then in your Google Reader, click on "Add Subscription", and then paste the link into it~ That's it.

Once you have done this to all your favourite pages, Google Reader will check for the updates in those pages for you -- you would not have to go to those individual pages separately and check for new stuff yourself, saving you heaps of time.

This picture on the right shows the websites that I have subscribed in my Google Reader.

For example, I have subscribed the Yahoo! News RSS feed into my Google Reader.

At the bottom of this blog, you would see "Posts (Atom)" and "Site Feed". They are the RSS feeds for this blog! (just another example)

[其他] 舊 BLOG

http://www.bloghk.com/blog.php?user=jtjli