Monday, June 18, 2012

Overriding window.open( ) in Javascript

Sometimes you may want override the window.open( ) in Javascript. It's strange, but you really it occasionally. Here is how we can do it:

var open_ = window.open;

window.open = function(url, name, opts) {
   return open_(url, name, opts);
}

Then you can add your own checking / modifications right before the window is opened.


Monday, June 11, 2012

ArcGIS JS: Move a graphic to top

To move a graphic in a ArcGIS JS GraphicsLayer to top:

g.getDojoShape().moveToFront();

But this may breaks the onClick event of the GraphicsLayer, beware.

Updated: in ArcGIS JS API version 3.8, use getShape( ) instead. ESRI... no more stupid naming please...



Thursday, May 31, 2012

Filter in Wireshark

Suppose you want to monitor the HTTP request from 192.168.0.1 to 202.168.1.2 with a particular URI (e.g. saveUserInfo/) using Wireshark, you can specify the above situation using the filter below:

ip.src == 192.168.0.1 and http.host = "202.168.1.2" and http.request.uri contains "saveUserInfo"

Quite handy :)

Monday, May 28, 2012

JSP too large for Tomcat

A long JSP just worked in Tomcat 6.0.29. Somehow when we put it in 6.0.35, it got error "Unresolved compilation problem".

It seems that the new Jasper (/lib/ecj-3.7.jar) just not work for large JSP. One of the solution will be using the Jasper from 6.0.29 (/lib/jasper-jdt.jar) instead.

Or.. keep using the 6.0.29 for some while...

Saturday, April 28, 2012

Small HTTP servers for Windows

Some mini size HTTP server software for Windows:
For nginx, if you want to add an alias which point to another location which is not under the root directory, you can put the following in the nginx.conf:

location /web {
    alias   d:/Code/nginx_web;
}
        
This means for locations http://yourhost/web, it is pointing to d:\Code\nginx_web actually.


So what about ProxyPass in nginx? I will try on it tomorrow. Keep update soon.

Thursday, March 29, 2012

Java encoding : UTF-8, Big5, x-MS950-HKSCS

Suppose you got a file in Big5 containing some HKSCS characters (e.g. 深水埗, 赤鱲角, etc). When your environment (Ref: Charset.defaultCharset( ) ) is either UTF-8 / Big5, you will never get the things work.

The proper encoding should be "x-MS950-HKSCS"

This situation happens when I'm try the same pieces of code in Java console / Eclipse console and JSP @ Tomcat. While JSP works fine, but sucks in console mode. Finally I found the JSP is actually using encoding "x-MS950-HKSCS".

To set environment charset in Eclipse:

Right click on the file that you are going to execute (e.g. Testing.java), then "Properties" → "Run/Debug Settings" → "Common" → "Encoding". Type "x-MS950-HKSCS" in the field.

What a pity!

Sunday, March 18, 2012

YUI LayoutUnit collapse

One can use layout.getUnitByPosition('left').collapse() and layout.getUnitByPosition('left').expand() to the layout units (except 'center' layout unit) in YUI's Layout.

Once the layout unit is collapsed, the size is determined by the attribute 'collapseSize'.

Anyway, YUI is something historical now.

Thursday, March 8, 2012

Change Windows Update Server URL

Modify the Windows Registry to change the WSUS URL:

\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUServer

Ref: http://technet.microsoft.com/en-us/library/cc708554(v=ws.10).aspx

Regexp match with GenericValidator

Just a reminder to use GenericValidator for a quick way to do regexp matching in Java.

boolean rslt = org.apache.commons.validator.GenericValidator.matchRegexp(str, "(?i)abc|def|ghi");


CSP on Apache

To add CSP to root if sort of funny. The following will NOT work for most cases !!     <LocationMatch "^/$">        Header s...