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.

^(ht|f)tps?:(//)(\w+(:\w+)?@)?([-\w]+\.?)*[-\w]+(:[\d]{1,5})?(\/([-\w~!$+|.,=]|%[a-f\d]{2})+)*(/)?(\?([-\w~!$+|.,*:]|%[a-f\d{2}])+=?([-\w~!$+|.,*:=]|%[a-f\d]{2})*(\&([-\w~!$+|.,*:]|%[a-f\d{2}])+=?([-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)?(\#([-\w~!$+|.,*:=]|%[a-f\d]{2})*)?$


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.

October 27, 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.

August 15, 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!

June 23, 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_STATEMENT
from SYS.DBA_tab_columns
where 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.

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 something
.....

box.append('</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.

April 2, 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!!

March 9, 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 (gmail.com). 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.