Archive for the 'geek stuffs' Category

Code for Concinnity

Hasn’t updated this blog for a long while! I just took a good look and I thought this blog is swarmed with things tagged geek stuffs, which prob­a­bly isn’t what I made this blog pri­mar­ily for.

So I am start­ing my second blog that focuses on these things:

Code for Concinnity

Hope­fully I’ll be migrat­ing my tech posts over there soon — if I can get off my lazy ass 😛

Hide eclipse’s toolbar, permanently

I’ve been a long time eclipse user since 3.0. What has bug­gered me since that time is the mys­te­ri­ous tool­bar – there is no way to turn it off! Since I think around eclipse 3.3 they added an option on the right click menu to “Hide Toolbar”, but that is only tem­po­rary. The tool­bar creeps right back in on restart!

eclipse-toolbar-right-click

After some LONG time strug­gle with the eclipse PDE (Plug-​in Devel­op­ment Envi­ron­ment), I finally rolled out this little plug-​in that hides the tool­bar for me on eclipse start up.

Man, I still cannot believe how much time it took to actu­ally write a simple plug-​in like this! Maybe that’s a reason why the eclipse plug-​in scene hasn’t seen much advances lately – there’s too darn little resources! I mean, for the most of us, dig­ging through API and classes man­u­ally aren’t the most pleas­ant thing to do.

Please go check out the Google Code project page or use this update site directly:

https://kizzx2.com/eclipse/hide-toolbar/updates/

P.S. I prob­a­bly will write some ecilpse plug-​in tuto­ri­als later, if I feel like it. So please stay tuned!

missing hard-disk space? – the answer!

Many of us Win­dows users have expe­ri­enced the frus­trat­ing mys­ter­ies – we find our hard-​disks shrink­ing and shrink­ing after some period of usage. Emp­ty­ing the recy­cle bin didn’t solve the mys­tery, nei­ther did clear­ing the TEMP folder.

Here I’ll present two amaz­ing, free­ware prod­ucts from Piriform

CCleaner

This pro­gram is an excel­lent clean up util­ity. As far as I have tested it myself, this is unlike many other prod­ucts which try to delete as many files as they could to make them sound useful. CCleaner per­forms safe oper­a­tions and I haven’t broken my com­puter with it. On my first time use, it dis­cov­ered and recov­ered more than 1GB of my hard disk space!

Defraggler

Another free­ware prod­uct from the same com­pany. Defrag­gler is orig­i­nally intented to use as a defrag­men­ta­tion tool, but it sur­pris­ingly served extremely well at dis­cov­er­ing large chunk of mys­te­ri­ous files that choke up pre­cious disk space. One unique fea­ture this piece of soft­ware has is the abil­ity to defrag indi­vid­ual files. And the Ana­lyzer is blaz­ing fast too – it ana­lyzed my 80GB drive in less than 10 sec­onds. Then I switched to the File list, and I can imme­di­ately sort by file size to find out the biggest files on my disk!

df3

Sea­soned users might say this cygwin com­mand accom­plishes the same result:

du . 2>/dev/null | sort -nr | less

But that would prob­a­bly take 10 min­utes instead of 10 seconds!

Update: WinDirStat

My latest favorite method to do this is to use WinDir­Stat. I’ll let the offi­cial screen­shot speak for itself:

windirstat

Totally reveals the answer, although Defrag­gler could still be faster in show­ing the biggest file.

cygwin+exim: setting up a local SMTP server for testing email applications

This is mainly a ref­er­ence for myself in case I forget how to do it later, as it took me a good deal of time to figure out.

Situation

I want to unit test appli­ca­tions that send emails. Obvi­ously I don’t want to be open­ing a dozen of real email accounts just to test this thing out. Nat­u­rally I would want to install an SMTP/POP3/IMAP server on Win­dows, and there is one free (open source) option that is quite promis­ing – hMailServer. How­ever, it still involves 2 (quite major) incon­ve­niences for my use case:

  • I have to go through the con­fig­u­ra­tion screens to create new users. i.e. if I want to send email to [email protected] I’d have to create the user account alice manually
  • I have to use an email client (like Out­look Express) to con­nect to the local POP3 server to view the emails. This seems redun­dant to me, since the files are already stored in my disks, why can’t I just view them?

The Solution

Then I came across exim on cygwin. exim is (as it claims to be) a vast improve­ment over the good ol’ send­mail. So I gave it a shot – man, that was awe­some! I can now direct my appli­ca­tion to send to arbi­trary address like [email protected], [email protected] and I can view the results imme­di­ately in a text file, solv­ing the two prob­lems men­tioned above. Here’s what I did:

  • Install exim using cygwin installer
  • Run exim-config
  • Edit /etc/exim.conf
  • Uncom­ment primary_hostname and set it to mail.local
  • Edit the router localuser, com­ment out the line check_local_user (If you don’t know what that means, just search for the line localuser:)
  • Edit %WINDIR%\system32\drivers\etc\hosts, add the line 127.0.0.1 mail.local
  • Finally, reboot the exim service

And there you go! You can now send mail to *@mail.local. To view the mail, go to /var/spool/mail which con­tains all the mail in text files. A simple tail -f /var/spool/mail/foobar can mon­i­tor the mail sent to [email protected]

A simple test to make sure everything’s working:

$ exim -bt [email protected]
[email protected]
  router = localuser, transport = local_delivery
# If something is wrong in your config, it would say "Unrouteable address"
 
# Now let's try sending an email
$ exim -v -odf [email protected]
Hello World!
.
LOG: MAIN
  <= [email protected] U=Chris P=local S=296
delivering KEQKED-0002RS-A7
LOG: MAIN
  => foobar <[email protected]> R=localuser T=local_delivery
LOG: MAIN
  Completed
 
# Cool, let's see if it really delivered
$ tail /var/spool/mail/foobar
Received: from Chris by mail.local with local (Exim 4.69)
        (envelope-from <[email protected]>)
        id KEQKED-0002RS-A7
        for [email protected]; Sun, 08 Feb 2009 15:20:39 +0800
Message-Id: <[email protected]>
From: Chris <[email protected]>
Date: Sun, 08 Feb 2009 15:20:39 +0800
 
Hello World

tricks for the Windows Power Users

Many crit­i­cize Win­dows as being not user-​friendly to power users – you can’t do things the fast way even when you’ve used it for a couple of years. Here’s some tricks I’ve accu­mu­lated over the years to make using Win­dows (hope­fully) as swift as a *nix guru.

Why should we use Win­dows when we want per­for­mance and speed? Well, I guess that’s we game play­ers have to live for

Customize your Run dialog

run

This is undoubt­edly the coolest and most pow­er­ful trick for Win­dows power users. To be able to type what­ever com­mand you want from the Win­dows com­mand prompt is like being able to place sym­bolic links in /usr/local/bin

  1. Create a direc­tory some­where con­ve­nient. A good place I used is %HOMEDRIVE%:%HOMEPATH%\Commands.
  2. Now you’ll want to add this direc­tory to your %PATH%. This is done by:
  3. Press Win + R to open the Run dialog
  4. Enter sysdm.cpl
  5. Append your Commands path to %PATH% in Advanced -> Envi­ron­ment Variables
  6. Now you can place short­cuts (*.lnk) and even BAT files there and they will be run when you type the com­mand in the Run dialog!

Useful commands for the Run dialog

Talk­ing about the Run dialog, there’s a hand­ful of useful com­mands you may want to mem­o­rize to speed things up a little bit:

notepad
calc
Cal­cu­la­tor
explorer
Opens Win­dows Explorer on path
con­trol netconnections
Opens the Net­work Con­nec­tions con­trol panel
sndvol / sndvol32
Opens the volume con­trol panel
sysdm.cpl
Opens System Properties
dxdiag
Opens DirectX Diagnostic
msinfo32
Opens System Information
msn­msgr
Opens Win­dows Live Messenger

Enhance your clipboard with ClipX

The clip­board is designed decades ago. Given today’s computers’ memory size, there’s no reason to jus­tify why we can only hold one value in the clip­board. Enhance it with this free­ware ClipX. You can store like 25 pre­vi­ous clip­board entries (includ­ing pic­tures, files) and recall them with one key com­bi­na­tion (default: Shift-Ctrl-V). Very handy for system admins and programmers

clipx-intray

Opening Task Manager directly on Vista

Microsoft changed the pop­u­lar key com­bi­na­tion Alt-Ctrl-Del to open a screen with a list of not very useful options instead of open­ing the task man­ager. Here’s the new key com­bi­na­tion to open the Task Man­ager directly:

Ctrl+Shift+Esc

Locking your computer from the command prompt

There are var­i­ous rea­sons you might want to do this instead of Win + L, such as from within a BAT script. Anyway here’s how to do it

rundll32 user32.dll, LockWorkStation

Putting files to the Recycle Bin from the command line

Oops, there’s no tricks to it. Down­load my recy­cle utility.

Comodo: a free antivirus/firewall solution vs. ESET Smart Security

Update 2: I’ve given this prod­uct some real life usage tests. I must con­clude that the antivirus component’s per­for­mance is slow, ugly and unac­cept­able. I was fooled by its small foot­print (memory usage), but the scan­ning speed is slow and it effec­tively ren­ders my com­puter unus­able when I am doing any slightly more demand­ing oper­a­tions. Bot­tom­line: Stray away from this if you want any per­for­mance at all – for that pur­pose, I’d say ESET AntiVirus is still the best

Update: Unfor­tu­nately, after some test­ing, I just real­ized Comodo’s UI still requires the use of a mouse. Although it has slightly more options than ESET’s fire­wall, the manda­tory use of mouse still sucks.

In the past I’ve always used the com­mer­cial NOD32 Antivirus. Since ver­sion 3 it has also included a fire­wall in the ESET Smart Secu­rity. I have been quite sat­is­fied with NOD32 Antivirus since it has a solid detec­tion rate and more impor­tantly to me, very min­i­mal use of system resources. This is unlike say Norton, which is noto­ri­ous for eating up 50% of your system resources even when it is doing observ­ably nothing.

Recently though, I started get­ting annoyed enough by ESET’s firewall’s user inter­face. Simply put, I’m get­ting really annoyed by the fact that I have to con­stantly click the fre­qently appear­ing pop ups. What’s worse, the pop ups must be clicked by a mouse – it doesn’t sup­port using a key­board with tab­bing to the right button.

That’s not too bad though, after maybe a year of using it, I’ve learned of its con­fig­u­ra­tion enough so that I could set up rules to pre­vent the pop ups from appear­ing so fre­quently, but the occas­sional pop ups that appear finally drove me to inves­ti­gate into better solutions.

Then I found Comodo Inter­net Secu­rity – which comes with an Antivirus and a Firewall.

Comodo has been well known for its fire­wall, but the Antivirus com­po­nent is the company’s new inven­tion – this is like the reverse of ESET, which is best known for its antivirus but then expanded its market to fire­wall too.

I still haven’t used Comodo long enough to do a com­pre­hen­sive review of the two, but there’s one thing that I can say for cer­tain: Comodo’s user inter­face is so much nicer and pro­vides much more options than ESET.

And from some­where I’ve read, per­for­mance and low system resources usage is one of the design philoso­phies of the Comodo’s team. I forgot where exactly but I think I read it from the Comodo’s offi­cial forum – you can prob­a­bly take a look and you’ll quickly real­ize how inter­ac­tive the sup­port staff are in the forum – some­thing that blew my expec­ta­tion for a free product.

So, give it a try for this free secu­rity prod­uct, it’s def­i­nitely not wosre, if not way better than, most of its paid counterparts.

cygwin: WARNING: terminal is not fully functional

I recently encoun­tered an error where when I do a less in cygwin it goes WARNING: terminal is not fully functional Quite some people seem to have encoun­tered this prob­lem before and there are some dis­cus­sion threads on the Web, but I couldn’t find a page that pointed out the direct solu­tion after some googling. Here’s what I did to fix the prob­lem: It turns out that the envi­ron­ment vari­able TERM is some­how set to dumb instead of the normal cygwin. Appar­ently the dumb ter­mi­nal is not as fully func­tional as cygwin. Here’s what I did to con­firm the prob­lem: $ echo $TERM dumb I got less work­ing prop­erly again by doing: $ export TERM=cygwin $ less It turned out that some­how the $TERM envi­ron­ment vari­able got set to dumb. To fix that, simply run sysdm.cpl from a Win­dows com­mand prompt, and delete the envi­ron­ment vari­able TERM. cygwin will then default TERM to cygwin

Windows: Delete to Recycle Bin from the command line

Update: Check out the new tool cmd-​recycle which is a lot more robust, writ­ten much more cleanly and just more cool!

I wrote this simple utiltiy some while ago, thought I might as well pub­lish it here.

Just copy recycle.exe to WINDOWS\system32 and you can start using

recycle recycle ... recycle * recycle ...

Full source code included (using C#). Enjoy!

Down­load

Google to add more chaos to Web developers’ lives?

I just saw Google adver­tis­ing their new exper­i­ment ven­tur­ing into the Web browser scene. The Chrome browser, like every­thing else from Google, is in BETA.

Now that is what con­cerns me most: Will this beta soft­ware just adds to foes Web devel­op­ers have to fight when com­bat­ing cross-​browser com­pat­i­bil­i­ties? Does the fact that it is beta imply that it will be con­stantly chang­ing, which mean we’d have to cope with like 10 more dif­fer­ent cases of dif­fer­ent ver­sions of Chrome?

let the Web browser “remember” HTTP authentication credentials using AJAX – the correct way vs. the wrong way

Under nor­mally cir­cum­stances, if you request an HTTP pro­tected resource with your Web browser, the server would return 401 Unau­tho­rized and an popup would appear to ask you for the cor­rect credentials:

That doesn’t look too Web 2.0-ish. Cur­rently there is way to work around this using an AJAX request first (there’s an arti­cle that dis­cusses the spe­cific tech­nique used). That way, the browser would “remember” the Autho­riza­tion header used in the pre­vi­ous AJAX request, so when the user requests another pro­tected resource in the same domain, the browser would also try to include the pre­vi­ously used Autho­riza­tion header.

How­ever, I couldn’t get it to work.

It turns out that the dif­fer­ence between my approach and the approach used in the arti­cle above is this:

// My way (doesn't work) var xhr = new XMLHttpRequest; xhr.open ( 'GET', '/url/to/resource', false ); xhr.setRequestHeader ( "Authorization", "Basic " + Base64.encode ( username, password ) ); xhr.send ( null ); // The working way var xhr = new XMLHttpRequest; xhr.open ( 'GET', '/url/to/resource', false, username, password ); xhr.send ( null );

Unbe­known to me was the fact that the 4th and 5th para­me­ter of XMLHttpRequest.open() could be used to spec­ify the user­name and pass­word for the request.

Appar­ently, the browser doesn’t remem­ber the cre­den­tials if I call XMLHttpRequest.setRequestHeader directly.

Note: All these have only been tested to work with MSIE/Firefox. Opera for instance, doesn’t seem to remem­ber the cre­den­tials no matter what I tried – it would still pop up an autho­riza­tion box when the user request a pro­tected resource.