Showing posts with label 科技. Show all posts
Showing posts with label 科技. Show all posts

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

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

自己玩玩。包不後悔。

Sunday, March 18, 2007

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

最近認識了《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)