Monday, November 16, 2009

URL Regular Expression Pattern

Tonight I search for a regex pattern to parsing ftp or http url. I found some but I choose Ivan's pattern and then I modify it to suit my problem. this is the result.


Some paths derive from Ivan's pattern and some I rewrite it. I note this for further use in the future. Hope it maybe useful to you too.
And I also found regexpal which is a great online regex tool.

Wednesday, October 28, 2009

GoogleSurfKey will be outdated soon.

Today I just see that Google is doing keyboard shortcut feature for their search result page. Although now it's in google lab and just a experimental feature but I think it will be out of the lab soon. It's a good news for keyboard-centric user like me. :D So my GoogleSurfKey script will be outdated soon.

You can try this new Google's experimental feature out at the Google Experimental page. Now it can use only in main english google.

Sunday, August 16, 2009

Google Surf Key 0.3.0 is released!!

I've not updated Google Surf Key script for a long time. Now I update it and release the new version 0.3.0. Recently google search has updated new result page layout and the DOM layout has changed (more complex) so my script hasn't worked anymore.

Install it here

This is version 0.3.0 changelog.

version 0.3.0 released.(15 Aug 2009)
- Updated for new Google's search result page layout.
- Fixed the 10 results limitation.(Only j,k traversing not number keys)
- Add l command to toggle show the index label.
- Change the implementation to use JQuery 1.2.6.
- Improve the link focusing.

Hope you like it!

Wednesday, June 24, 2009

Convert all column data type from VARCHAR2 to NVARCHAR2 and vice versa in Oracle 11g

I found a problem about the encoding and some data size issues. So I need to convert all column in all table in my database from VARCHAR2 to NVARCHAR2 with the same size. Definitely I can convert the data type column by column manually but it takes time and not a smart way. So this is the way.

I logged in as SYS and run this sql statement.

select 'ALTER TABLE '||OWNER||'.'||TABLE_NAME||' MODIFY('||COLUMN_NAME||' NVARCHAR2('||DATA_LENGTH||'));' AS GEN_SQL_STATEMENTfrom   SYS.DBA_tab_columnswhere  owner = 'ownername' and DATA_TYPE = 'VARCHAR2';

The result is the rows of ALTER statement filled with the table name, column name and new data type.
Then I copied all rows and concatenate them with some editor. and then run them as a sql script.

If you want to convert from NVARCHAR2 to VARCHAR2, just switch 'VARCHAR2' and NVARCHAR2' in above sql statement. You can modify above script as well to suit your propose.

Finally, you cannot convert the column which is not empty otherwise the error will occur.

Tuesday, June 2, 2009

IE6 crashes on JQuery append() function

This is a problem only on IE6 as I know. (IE7 and Firefox3 are tested.) This is my JQuery code that causes IE6 crashed.

var table = $("#contact_list");table.empty();$("group",data).each(function(){var group_name = $(this).attr("name");table.append("<tr><td>"+group_name+"</td></tr>");$("user",$(this)).each(function(){var username = $(this).text();table.append("<tr><td>"+username+"</td></tr>");});});

When I saw IE6 crashed, I tried to figure out what was the problem and found it was an append function. So I tried to implement the code in many ways and I saw something.

It will crashes if the html string as an argument of the function is not a properly dom object or closed tag. For example

var box = $("#contact_list");box.append('<table>');//do'</table>');

So I solved this problem by define an variable for collecting all the html string which I want to append and append it by append() in the end. And the code works fine on IE6.

Friday, April 3, 2009

Switch input language by Caps Lock #2

Due to comments in this post, I tried to find another way to use caps lock key for switching input language. The limit of that post is it works only Windows which has grave accent(`) option for switch language but many computer hasn't that option. It usually has Left Alt+Shift option.

So I have to remap caps lock key to left alt+shift. There is no way to do this in Windows registry. I found AutoHotkey can do this for me.

Steps are

  1. Download and install AutoHotkey in your computer.

  2. Write .ahk script like below
    Capslock::Send {LAlt down}{Shift}{LAlt up}

  3. Save this file and try double click to run it.

  4. Test it by press caps lock and see.

  5. Create shortcut to this .ahk file and move it to Startup folder in Start menu. [Do this to run this script at startup]

Hope you like it!!

Tuesday, March 10, 2009

Major Limitation of Gmail and Google Calendar in Offline Mode

Recently Google launched an offline mode of Gmail in labs and just few days ago Google Calendar offline mode had been released in beta after the news of this feature over a year.

Both of them use the capabilities of Google Gears for running in offline. So I installed Google Chrome for try out these things.

It works nicely but I found a major limitation. A few days ago ,I was disconnected and I opened the Gmail. I expected that I could browse my email easily and see my drafts but it didn’t work.

Google Chrome showed an error. It said “105 (net::ERR_NAME_NOT_RESOLVED)” that is about Chrome cannot resolve an IP address of website ( So it cannot work offline. The same error was shown when I tried the Calendar.

But Google Document or Remember The Milk which support Gears work correctly.

Gmail and Calendar work in offline mode correctly if they have already been opened before your computer is disconnected. They will switch to offline mode and continue running correctly.

I wish this limitation will be removed soon.

Monday, March 2, 2009

Booting Process Tuning in FreeBSD 7.1

This is the last semester in my undergraduate student life, I attended the FreeBSD class and the last project is "Special Problem: Subsystem Tuning".
The project's objective is to tune or optimize a subsystem of FreeBSD and/or its environs (applications, utilities, etc.) to make it perform better.
I choose to tune the booting process of FreeBSD. Due to my laziness and lack of time, so I didn’t do tuning as much as I expected. but if I have time……if I have time…..
Here is my presentation.

Sunday, February 22, 2009

Upgrade Thinkpad X200 Harddisk and Keep Service Partition Safe By Puppy Linux.

I bought a Thinkpad X200 with 80 GB harddisk 2 months ago. I'm very impressed with this thinkpad. Now I'd like to upgrade my harddisk from 80 GB to 320 GB because I need more space.
The usual procedure , replace it with a new harddisk and format, is fine but that procedure will blow your Service partition away. In term of Thinkpad , this kind of partition is called "Predesktop Area".
Predesktop Area or you'll see a partition named "Service003" in Computer is needed for booting your Thinkpad in Rescue And Recovery mode by Press Blue ThinkVantage at the boot time.
This mode can format your harddisk and recover it to the factory-installed state.
So I'd like to keep Service partition. Many people in the forums recommend to use Acronis True Image to clone the whole disk. It's a good application. I tried it and succeeded the cloning process. It works except booting in Rescue And Recovery mode.
So I searched for another way. and found the PuppyLinux is a good way.
Disclaimer : Do it at your own risk!!!. It works for me but I can't gurantee it'll work for your X200 or other model too.
Objective : To migrate all the data in the old harddisk to the new bigger harddisk and all data must remains. Can boot to windows with no problem and boot to Rescue and Recovery mode by pressing the blue button at the boot time.
Tools :

  • New bigger harddisk.

  • The USB externel harddisk enclosure.

  • PuppyLinux CD

  • A Screwdriver
Environment : In my old harddisk I have layout like this.

Method :
  1. [optional but recommend] Create the Product Recovery Media (if you've created it) by Start->All Programs -> ThinkVantage -> Create Product Recovery Media
    The Product Recovery Media needs 1 blank CD for start CD and 2 blank DVD. It's for using to rescue system when you cannont boot to your harddisk or you want to recovery your whole disk to factory-installed state (I think it includes Service partition).
    ** Product Recovery Media can create only once. It you lose it, you may contact Lenevo Support to have a new one.(maybe free or not)

  2. [optional] Recover the Lenevo Partition (after create Product Recovery Media) by double click on this parition in Computer and choose Recover space.

  3. Reboot to Puppy Linux CD. (you may have to select boot order by press F12 at the boot time)

  4. Wait for the system is ready.

  5. Integrate the new harddisk with the external HD enclosure.

  6. Plug the external to the Thinkpad. Puppy may see new the drive if it was formatted.

  7. Run Pudd (Menu -> Utility -> Pudd copy drive/partition) to clone the internal harddisk to usb external harddisk. The main point is that cloning the all partition from disk to disk in "As is" mode that means the partition size will not expand propotionally. From 80 GB to 320 GB, you'll see the unallocated area 240GB approx in the rest of the external harddisk.

  8. It takes about half an hour for clone the disk. The limitation of Pudd is that no progress showing. Please wait patiently and wish it's working.

  9. When Pudd finished his work, run GParted (Menu -> System -> Gparted). You'll see the partition layout of the external harddisk as same as the old 80GB one.

  10. Now using the GParted to resize/move/create/delete some partitions except Service partition as you like.

  11. This is mine. (you'll see the 1 MB unallocated area at the beginning of disk. I think this results in why Acronis didn't works. )
  12. Shut down the computer.

  13. Switch the harddisk 80GB and 320GB. You may need a good screw driver. Do it by the Thinkpad Manual. It's very easy.

Now you can continue working with the new bigger space.
Wish it works for you too.

Monday, January 26, 2009

My favourite Dijkstra's epigrams

Do not try to change the world. Give the world the opportunity to change itself.

The question of whether computers can think is like the question of whether submarines can swim.

Computer Science is no more about computers than astronomy is about telescopes.

A formula is worth a thousand pictures.

Progress is possible only if we train ourselves to think about programs without thinking of them as pieces of executable code.

Program testing can at best show the presence of errors but never their absence.

I pray daily that more of my fellow programmers may find the means of freeing themselves from the curse of compatibility.

If you carefully read its literature and analyze what its devotees actually do, you will discover that software engineering has accepted as its charter, “How to program if you cannot.”
Waiting is a very funny activity: you can’t wait twice as fast.

Mathematicians are like managers; they want improvement without change.

source : Memorial Resolution - Edsger Wyber Dijkstra