Wednesday, November 14, 2012

Side notes on Android Dev

  1. To make your subclassed ViewPager (android.support.v4.view.ViewPager) work, prepare both the constructors in your class:
    • ViewPager(Context context)
    • ViewPager(Context context, AttributeSet attrs)
  2. In ActionBarSherlock, if you can't get the loading icon work, i.e. setSupportProgressBarIndeterminateVisibility( ) just got no effect at all, then you are very likely have a wrong Window class (android.view.Window) imported. You should include the ActionBarSherlock Window class instead.
    • com.actionbarsherlock.view.Window

Friday, September 21, 2012

Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver error

If you ever come up with the error using ChooserActivity with the Android emulator, you probably don't need to be worried.

It's basically because you only have a single choice to start the intent (e.g. send a message, choose a audio file, choose a picture, etc., in the emulator).

There is just no way to show you the option dialog, and the exception raised. Read the explanation in the following:

http://stackoverflow.com/questions/11308260/chooser-activity-leak-android

Tuesday, September 18, 2012

Android 2.2 SDK with strings.xml having multiple %s


When building the SearchableDictionary examples using 2.2 SDK, the strings.xml contains the following which fails the compilation:

<plurals name="search_results"> 
  <item quantity="one">%d result for \"%s\": </item>
  <item quantity="other">%d results for \"%s\": </item>
</plurals>

We need to change them to the following in order make it compiled:


<plurals name="search_results"> 
  <item quantity="one">%1$d result for \"%2$s\": </item>
  <item quantity="other">%1$d results for \"%2$s\": </item>
</plurals>


Reference:

Tuesday, September 11, 2012

Quick notes on Dojo 1.8

Just a quick notes on dojo 1.8. For example, if I want to use the Color object in dojo. I will:

   var Color;

   require(["dojo/_base/Color"], function(c) {
      Color = c;
   });

Then I can use the variable Color after the initialization is done. Am I correct? Should it be used in another way? :-)


Thursday, August 30, 2012

Upgrading from ArcGIS Android API v1.1 to v2.0

If you got a ArcGIS Android Project using ArcGIS API v1.1 and switch to v2.0, you will have a runtime exception when you do a pan action in the map view.

   FATAL EXCEPTION: main
   java.lang.UnsatisfiedLinkError: nativeSetAnimating
   com.esri.android.map.MapSurface.nativeSetAnimating(Native Method)
   ...

To solve this problem, you need to:
  1. Create a new ArcGIS Android project using v2.0
  2. Copy the files "libs/armeabi/libGLMapCore.so" and "libs/armeabi-v7a/libGLMapCore.so" back to your original v1.0 project directory
Very stupid right? But choose to use this product is stupid enough.


Tuesday, August 28, 2012

DOJO: Tab ordering in TabContainer

The tabContainer.getChildren( ) method returns a list of tab widget (ContentPane) in the container using the following way:

    dijit.findWidgets(tabContainer.containerNode)

However, if you did some drag and drop actions on the tab button list to rearrange the tab ordering, the tab sequence did not changed actually. To get a modified / correct ordered list, you may try to override the getChildren( ) method:

    myTabContainer.getChildren = function() {
        var list = this.tablist.getChildren();
        var rsltList = [];
        for (var idx=0; idx<list.length; idx++) {
           rsltList.push(list[idx].tab);
        }
        return rsltList;
    }

Noticed the underlined "tab" member variable in the code, you need to manually assign it when your tab page is created. Or you may find a way / method to get the Tab page object (ContentPane) via the Tab Button.

If you got any better method, please let me know :-)

Thursday, August 23, 2012

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



Friday, June 1, 2012

About OSX Lion's Apache

Just a quick notes on Lion's Apache information:

  1. Location of the httpd.conf: /etc/apache2/httpd.conf
  2. PHP: php5_module in httpd.conf
  3. Virtual hosts conf: /private/etc/apache2/extra/httpd-vhosts.conf (included in httpd.conf)
  4. Restart Apache: apachectl restart (requires root)

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, April 26, 2012

Editors for MacOS

Just need some nice text editor to code, here I found some nice stuff:

For TextWrangler, if we want to add color themes to it, we can put bbedit theme files to ~/Library/Application Support/TextWrangler/Color Schemes/


Monday, April 2, 2012

CSS DropShadown in IE9

Reference http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/

A good way to perform text shadow in IE9:


background-color: 'white';
filter: progid:DXImageTransform.Microsoft.Chroma(Color='white')
        progid:DXImageTransform.Microsoft.DropShadow(OffX=3, OffY=3, Color='white');


The point is to make use of Chroma filter and set a proper background-color. So great!

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

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");


Wednesday, February 15, 2012

Using "define" function in Dojo

You may experienced an error message "define is not defined" when using Dojo I got this error when trying the dojo.i18n feature when I did a dojo.requireLocalization( ) call. In some occasions a pre-built version of Dojo just don't have the "define" function at all (sigh.. ridiculous!). To solve this problem, consider the following (Dojo 1.6):

<script>
dojo.ready(function() {
    var currentModule;
    define=function(d,b,c){function g(a){if(a.charAt(0)==="."){for(a=d.substring(0,d.lastIndexOf("/")+1)+a;b!==a;)var b=a,a=a.replace(/\/[^\/]*\/\.\.\//,"/");a=a.replace(/\/\.\//g,"/")}return a.replace(/\//g,".")}c||(b?(c=b,b=d):(c=d,b=typeof c=="function"?["require","exports","module"].slice(0,c.length):[]),d=currentModule?currentModule.replace(/\./g,"/"):"anon");var e=d.replace(/\//g,"."),h=dojo.provide(e);if(typeof c=="function"){for(var i=[],a,f=0;f<b.length;f++){a=g(b[f]);var j=a.indexOf("!");if(j> -1)a.substring(0,j)=="i18n"&&(a=a.match(/^i18n\!(.+)\.nls\.([^\.]+)$/),dojo.requireLocalization(a[1],a[2])),a=null;else switch(a){case "require":a=function(a){return dojo.require(g(a))};break;case "exports":a=h;break;case "module":var k=a={exports:h};break;case "dojox":a=dojo.getObject(a);break;case "dojo/lib/kernel":case "dojo/lib/backCompat":a=dojo;break;default:a=dojo.require(a)}i.push(a)}b=c.apply(null,i)}else b=c;b&&(dojo._loadedModules[e]=b,dojo.setObject(e,b));if(k)dojo._loadedModules[e]=k.exports; return b};define.vendor="dojotoolkit.org";define.version=dojo.version;define("dojo/lib/kernel",[],dojo);define("dojo/lib/backCompat",[],dojo);define("dojo",[],dojo);define("dijit",[],this.dijit||(this.dijit={}));

    dojo.require("dojo.i18n");
    dojo.registerModulePath("language", "/path_to/language");
    // OR you can try the following if you want a relative path
    // dojo.registerModulePath("language", "../../../../../../language");
    // Suppose you are using Main.js to define the language
    dojo.requireLocalization("language","Main");
});

</script>

Reference: http://dojo-toolkit.33424.n3.nabble.com/define-is-not-defined-in-dojo-build-tt3128408.html#a3241874

Wednesday, February 8, 2012

Solution for java.io.NotSerializableException error when Tomcat reloads

To solve the Tomcat restart error, add <Manager> setting in <Context> section:

<Manager className="org.apache.catalina.session.PersistentManager" 
         saveOnRestart="false">
    <Store className="org.apache.catalina.session.FileStore"/>
</Manager>


References:

Wednesday, February 1, 2012

HIde Account at Windows Login Screen


The following steps can hide user account in Windows login screen:

  1. Go to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList\, if key not exists, create them.
  2. Add DWORD registry
  3. Set name = User account name (e.g. demouser)
  4. Set value = 0

Done.

Sunday, January 29, 2012

Spatial Reference of HK

The spatial reference of Hong Kong could be found at : http://spatialreference.org/ref/epsg/2326/

There is a link "Proj4" in that page which provides the Proj4js definitions for converting EPSG:2326 (HK1980 Grid) projection to other projection using the Proj4js library:

+proj=tmerc +lat_0=22.31213333333334 +lon_0=114.1785555555556 +k=1 +x_0=836694.05 +y_0=819069.8 +ellps=intl +towgs84=-162.619,-276.959,-161.764,0.067753,-2.24365,-1.15883,-1.09425 +units=m +no_defs 



Wednesday, January 25, 2012

Command line to get installed software / windows updates information

One can use wmic command to get the list of product installed in Windows:
 c:\> wmic product

You can also specify which data fields you want to retrieve, e.g.:
 c:\> wmic product get caption

We can also use wmic command to get the list of windows updates made on the machine:
 c:\> wmic qfe list

Sunday, January 15, 2012

Solving disk offline issue in Windows

You may experienced a message "The disk is offline because it has a signature collision with another disk that is online" / "磁碟簽章發生衝突" in Windows. The case for myself is switching two RAID-1 drives back to non-RAID devices, where the two drives will become identical and cause the collision problem. The following is the solution to turn on the offline disk:

c:\>diskpart
c:\>list disk (you may see your offline disk is in the list)
c:\>select disk 1
c:\>offline disk
c:\>online disk


Reference: http://beddingmall.blogspot.com/2011/01/blog-post_04.html

Thursday, January 12, 2012

Delete Acronis Failed Task

Just tried their solution, it works:
  1. Run Schedmgr.exe and issue the following command: task zap
  2. Delete the content of the following folders:
    Windows XP, Windows 2000/2003 (32/64 bit)
    - \Documents and Settings\All Users\Application Data\Acronis\BackupAndRecovery\MMS\Policies\
    - \Documents and Settings\All Users\Application Data\Acronis\BackupAndRecovery\MMS\TasksStorage\
    - \Documents and Settings\All Users\Application Data\Acronis\BackupAndRecovery\MMS\PolicyStatistics
    Windows Vista, Windows 7, Windows Server 2008 (32/64 bit)
    - \ProgramData\Acronis\BackupAndRecovery\MMS\Policies\
    - \ProgramData\Acronis\BackupAndRecovery\MMS\TasksStorage\
    - \ProgramData\Acronis\BackupAndRecovery\MMS\PolicyStatistics
  3. Recreate the tasks
Ref: http://forum.acronis.com/forum/10652

Tuesday, January 10, 2012

Column aggregation in Oracle

Suppose we have a table (TBL) in Oracle with columns (CATEGORY, ATTR). Consider the following:

CATEGORYATTR
1A
1B
1C
2D
2E
2F
3X
3Y
3Z

We want to convert the table as follows:

CATEGORYATTR
1A,B,C
2D,E,F
3X,Y,Z

This can be done via the SQL below:

select CATEGORY, 
       xmlagg(xmlelement(c, ATTR || ',')).extract('//text()') 
from TBL 
group by CATEGORY

Thursday, January 5, 2012

Determine user in Tomcat

To determine user authentication info in Tomcat, we can use the following:

getRemoteUser()
isUserInRole(String role)

Both methods are under javax.servlet.http.HttpServletRequest.

Sync multiple git repo at once

Use the following command in Linux will do the job:  ls -d RepoNames* | xargs -I{} git -C {} pull