Sunday, December 18, 2011

Using ArcGIS JS API v2.5 - v2.8

Some notes on using their API:
  • In 2.5, the path is /library/2.5/arcgis (or arcgis_compact)
  • In 2.6, the path changed to /library/2.6/jsapi (or jsapicompact), but the manual doesn't changed. So be careful when following the installation manual
  • The file in /library/2.6/jsapi/js/esri/jsapi.js will create a Javascript error. You might need to replace the file content with the one in ESRI ArcGIS JS API production site.

Something more about the Javascript files in the API:
  • The jsapi.js contains UTF8 characters (‰ - u8240, ¤ - u0164), when ArcGIS JS API "index.jsp" includes this file using <jsp:include>, the UTF8 characters will corrupted. I found two solutions for that
    1. Modify the jsapi.js, swap those UTF8 characters back to escaped (\u) characters, and save the file back as ANSI format. OR
    2. Modify the "index.jsp", avoid using <jsp:include>, try to use file reader with encoding specified. For example: FileUtils.readFileToString(new File(filepath_), "UTF8"); (where FileUtils is from org.apache.commons.io package)

Wednesday, December 14, 2011

100% Height DIV

The trick is to set body with height:100% in CSS:

<style>
   html, body {
      margin: 0px;
      height: 100%;
   }
</style>

Then DIV's CSS height:100% will work !

Tuesday, November 29, 2011

Cynefin methods


Cynefin methods, tools, and techniques have been successfully applied in organisations to address areas such as corporate strategy, innovation, culture transformation, weak signal detection, social networking, mergers & acquisitions, knowledge management and ageing workforce. It is useful in capturing tacit knowledge.
Ref: Cynefin framework (http://www.cynefin.net)

Themes for Notepad2

There is a nice color theme called obsidian for Notepad2. But it will hide your cursor after  importing it. To fix this, give a color and size to the caret in notepad2.ini. For example:

[Default Text]
...
Caret (Color, size 1-3)=fore:#FFFFFF; size:2;
...


Link to Obsidan for Notepad2

Some options for Tomcat 6

Not much options found, but I drop down the useful ones for reference. Note that those options should be assigned to the CATALINA_OPTS. Actually, you may put them in catalina.bat.

  • Startup memory size
    -Xms256m
  • Maximum memory size
    -Xmx256m
  • Garbage collection path
    -Xloggc:/gc.log
  • Disable DNS caching
    -Dsun.net.inetaddr.ttl=0
  • Skip quote escape checking (If you have tag like this <mytags:tag value="<%= "hi!" %>" /> , which is validate in Tomcat 5 before. In Tomcat 6, you may need to turn on the following option to prevent running into error. Ref: http://www.andowson.com/posts/list/346.page)
    -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPE=false
  • Turn on JMX remote
    -Dcom.sun.management.jmxremote
    -Dcom.sun.management.jmxremote.port=9004
    -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.ssl=false
  • Set default Tomcat language / locale to English
    -Duser.language=en

Monday, November 28, 2011

To measure a string length in pixel using Javascript

One may make use of Span.offsetWidth to measure the length of a string in Javascript environment, consider the following example:


<html>
<body>
    <select id="select1" style="width:100px;" onchange="checkStringWidth()">
        <option value="1">abcde abcde abcde abcde abcde</option>
        <option value="2">abcde abcde abcde abcde</option>
    </select>
    <br>
    Selected option: <span id="span1"></span>
    <br>
    Text width: <span id="lbWidth"></span>
</body>
</html>


<script>
    function checkStringWidth() {
        var select1 = document.getElementById('select1');
        var span1   = document.getElementById('span1');
        var lbWidth = document.getElementById('lbWidth');
        span1.innerHTML = select1.options[select1.selectedIndex].text;        
        lbWidth.innerHTML = span1.offsetWidth;
    }
</script>

Saturday, November 26, 2011

Just played around with Greasemonkey

I'm not a javascript expert, but just played around using js in greasemonkey, quite funny.

// ==UserScript==
// @name FilterGuruEntry
// @description Filter Guru Entry
// @include http://www.guru.com/pro/search_results.cfm*
// ==/UserScript==


var allTRs, thisTR;
allTRs = document.getElementsByTagName('SPAN');
for (var i = 0; i < allTRs.length; i++) {

thisTR = allTRs[i];

if (thisTR.getAttribute("class") == "btblue") {

//myTBODY = thisTR.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
myTR = thisTR.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
myTD = thisTR.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;

if (myTR.nodeName == "TR") {
//myTR.removeChild(myTD);
//myTR.removeChild(myTR.lastChild);
myTR.removeChild(myTD);

}

//myTBODY.removeChild(myTR);
}
}

Friday, November 25, 2011

To run portable Chrome using chrome.exe in \App\Chrome-bin

For portable Chrome, if you execute the \App\Chrome-bin\chrome.exe directly, you may not able to start Chrome and having a file "debug.log" stating that Chrome "Could not get Chrome DLL version.".

To handle this issue, you need to do the following:
  • Copy the chrome.exe to \App\Chrome-bin\15.0.874.120\ (depends on the Chrome version) and use the chrome.exe in this path instead
  • Specify the --User-Data-Dir and --Enable-Extension parameters

For example:
  • chrome.exe --User-Data-Dir="D:\ChromePortable\Data\profile" --Enable-Extensions

Some more parameters for reference:
  • Private browsing mode:
      --incognito
  • Read local files (e.g. local XML, XSL, etc):
      --allow-file-access-from-files

Thursday, November 24, 2011

Using Expression Language (EL) in JSP

To use EL in JSP, a page directive has to be specified:

<%@ page isELIgnored="false" %>


Then you can use EL in the JSP, e.g.:

<logic:iterate id="var" name="sampleForm" property="list" indexId="index"> 

          <p>${var.id}</p>
          <logic:equal name="var"
                       property="foo"
                       value="${sampleForm.list[index+1].foo}">
             Value is same as next entry.
          </logic:equal>
</logic:iterate>

Wednesday, November 23, 2011

Getting Action Mapping in JSP

One can use "org.apache.struts.action.mapping.instance" to get the action mapping in JSP:

import org.apache.struts.config.ActionConfig;
ActionConfig mapping = (ActionConfig)request.getAttribute("org.apache.struts.action.mapping.instance");

Form name will be mapping.getName()

Friday, November 18, 2011

To activate a window using VBS

set oShell = WScript.CreateObject("WScript.Shell")
call oShell.AppActivate(<Window's Title>)

Tuesday, November 15, 2011

Copy files from tsclient

For example:

xcopy \\TSCLIENT\F\$Update\ *.* "C:\Documents and Settings\%USERNAME%\My Documents\" /s /v /f


Monday, November 14, 2011

Enable/Disable network interface via command line

c:\> netsh interface set interface "INTERFACE_NAME" enable

OR

c:\> netsh interface set interface "INTERFACE_NAME"disable

Wednesday, November 2, 2011

Debug mode in Eclipse and Tomcat

For Tomcat:
  set JPDA_ADDRESS=8000
  set JPDA_TRANSPORT=dt_socket
  catalina.bat jpda start

For Eclipse:
  Set Connection Port (8000) and Connection Host (localhost) in "Run > Debug Configurations"
  Configuration Type: "Remote Java Application"
  Set connection port to "8000"
  Set connection host to "localhost"

Wednesday, October 26, 2011

Download Eclipse Plugins in Zip at GitHub

This can be done via:

https://github.com/eclipse-color-theme/eclipse-color-theme.github.com/zipball/master

Ref: https://github.com/eclipse-color-theme/eclipse-color-theme.github.com/issues/1

Wednesday, July 6, 2011

Firefox plugins

Some Firefox plugins recommended:

Firebug
Greasemonkey
Hide Caption Titlebar Plus
Hide Navigation Bar
HttpFox
ImagePref (not from mozilla site)
MM3-ProxySwitch
No Color
Stylish
User Agent Switcher
Web Developer

Wednesday, June 1, 2011

Search Engine Optimization Technique

For SEO, there are few things to note.

  1. Meaningful title
    "Production name | Description"

  2. Use of meta tag
    META DESCRIPTION, META KEYWORD

  3. Use of canonical link
    http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html

  4. Use of SiteMap
    http://code.google.com/p/googlessitemapgenerator/
    http://www.sitemaps.org/protocol.php

  5. Use alt text


More information:

  1. http://static.googleusercontent.com/external_content/untrusted_dlcp/www.google.com/zh-TW//webmasters/docs/search-engine-optimization-starter-guide.pdf

  2. http://www.seomoz.org/beginners-guide-to-seo

Sunday, March 27, 2011

Reading and saving UTF8 text file in Java

To read and save text file in Java, we need to add the "UTF-8" parameter in the Stream Reader.


File file = new File("1.txt");
BufferedReader reader = null;
try {
   reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
   String text = reader.readLine();
   String s1="\u6df1\u6c34\u57d7";
   String s2="深水埗";

   OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream("2.txt"),"UTF-8");
   out.write(text+s1+s2);
   out.flush();
   out.close();

} catch (Exception e) {
   e.printStackTrace();
}

Sync multiple git repo at once

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