Thursday, August 23, 2007

How to find out which process is listening on a port

for example, we want to find out which process is running on port 8005
  • First, use the following command to find if the port is is use or not
    netstat -an |grep 8005

  • Then, use the following command to find which process is using the port
    fuser -n tcp 8005
    the return will be something like '8005/tcp: 9113'.
    it shows pid.

  • After that, we can find the full process information.
    ps -ef |grep 9113

  • In the end. I wrote a script to put all those steps together

    status=`netstat -an |grep $1`
    if [ "$status" == "" ]; then
    echo "port $1 is free"
    ps -ef |grep `fuser -n tcp $1`

    Tuesday, August 14, 2007

    Setup Outlook Mobile for Gmail account

    Just got a smart phone with windows mobile 5 installed.
    It comes with Intel 520MHz cpu and 640*480 VGA.

    Here are the steps to setup Outlook Mobile for my Gmail account on windows mobile.
    1. Select to create new Outlook E-mail
    2. E-mail Setup (1/4)
    Enter e-mail address:
    3. E-mail Setup (2/4)
    User Infomration
    Your name: Johnson
    password: you_gmail_password
    4. E-mail Setup(3/4)
    Account Type: select Pop3
    5. E-mail Setup(4/4)
    Server Information
    Click 'Options' button
    6. Options (1/3)
    Use default
    7. Options (2/3)
    Check 'Require SSL connection'
    Check 'Outgoing mail requires authentication' (Since gmail needs auth for sending email)
    8. Options (3/3)
    Use default

    Until here, you are read to send and receive emails using Gmail
    Actually, i did not have a lot of time to play with it yet. will post more experience about this baby later.

    Saturday, August 11, 2007

    Building auto-translator based on google translate API (2)

    Got the draft version of the eclipse resource auto-translator works.
    For a input resource file in English below:


    The output resource file in Simplified Chinese looks really stupid.

    Need to find a way to let google translate to use IT dictionary!

    [Updated 08/12]
    Here are more info after digging into this problem.
    From Google Translate FAQ:

    Most state-of-the-art, commercial machine-translation systems in use today have been developed using a rules-based approach, and require a lot of work by linguists to define vocabularies and grammars.

    Our system takes a different approach: we feed the computer billions of words of text, both monolingual text in the target language, and aligned text consisting of examples of human translations between the languages. We then apply statistical learning techniques to build a translation model. We've achieved very good results in research evaluations"

    However, it can't be used to translate single word. since the algorithm needs context words to match for result.

    In our application, for example, menu labels are single word. such as "File", "Open"...etc.
    For workaround, I need to use an online dictionary for single word translation.
    One good candidate is worldlingo
    It is handy. allow you to select from list of dictionary, including computer/IT.

    Thursday, August 9, 2007

    editing binary file using VI

    Not using VI as HEX editor for quite long time. nearly forgot how to do it.

    Here are the commands:

    vi ~/
    [esc]:%!xxd -r

    Wednesday, August 8, 2007

    XML Transformer indent doesn't work with jdk5

    The below code works fine with jdk1.4, i can get nice formatted xml document.

    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{}indent-amount", "4");
    DOMSource source = new DOMSource(document);
    StreamResult stream = new StreamResult(os);
    transformer.transform(source, stream);

    However, found it doesn't work on jdk5.
    I need to change to the following work around code

    TransformerFactory transFactory = TransformerFactory.newInstance();
    new Integer(2));
    Transformer transformer = transFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{}indent-amount", "4");
    transformer.transform(new DOMSource(document),
    new StreamResult(new OutputStreamWriter(os, "utf-8")));

    Building auto-translator based on google translate API (1)

    I am writing an auto-translator plug-in. which will do the i18n for eclipse plugins and application automatically. After evaluate several online translating engine, i think google translate is more accurate. Although google does no provide an official API for their translate yet.

    Here is the translation mode definition class. It lists all translation directions supported by google so far.

    public final class TranslateMode {
    public static final TranslateMode ARABIC2ENGLISH= new TranslateMode("ar|en");
    public static final TranslateMode CHINESE2ENGLISH = new TranslateMode("zh|en");
    public static final TranslateMode CHINESECN2CHINESETW = new TranslateMode("zh-CN|zh-TW");
    public static final TranslateMode CHINESETW2CHINESECN = new TranslateMode("zh-TW|zh-CN");
    public static final TranslateMode ENGLISH2ARABIC = new TranslateMode("en|ar");
    public static final TranslateMode ENGLISH2CHINESECN = new TranslateMode("en|zh-CN");
    public static final TranslateMode ENGLISH2CHINESETW = new TranslateMode("en|zh-TW");
    public static final TranslateMode ENGLSISH2FRENCH = new TranslateMode("en|fr");
    public static final TranslateMode ENGLISH2GERMAN= new TranslateMode("en|de");
    public static final TranslateMode ENGLISH2ITALIAN= new TranslateMode("en|it");
    public static final TranslateMode ENGLISH2JAPANESE= new TranslateMode("en|ja");
    public static final TranslateMode ENGLISH2KOREAN= new TranslateMode("en|ko");
    public static final TranslateMode ENGLISH2PORTUGUESE= new TranslateMode("en|pt");
    public static final TranslateMode ENGLISH2RUSSIAN = new TranslateMode("en|ru");
    public static final TranslateMode ENGLISH2SPANISH = new TranslateMode("en|es");
    public static final TranslateMode FRANCH2ENGLISH = new TranslateMode("fr|en");
    public static final TranslateMode FRENCH2GERMAN = new TranslateMode("fr|de");
    public static final TranslateMode GERMAN2ENGLISH = new TranslateMode("de|en");
    public static final TranslateMode GERMAN2FRANCH = new TranslateMode("de|fr");
    public static final TranslateMode ITALIAN2ENGLISH = new TranslateMode("it|en");
    public static final TranslateMode JAPANESE2ENGLISH= new TranslateMode("ja|en");
    public static final TranslateMode KOREAN2ENGLISH = new TranslateMode("ko|en");
    public static final TranslateMode PORTUGUESE2ENGLISH = new TranslateMode("pt|en");
    public static final TranslateMode RUSSIAN2ENGLISH = new TranslateMode("ru|en");
    public static final TranslateMode SPANISH2ENGLISH = new TranslateMode("es|en");

    public String toString() {
    return langpair;

    private final String langpair;

    private TranslateMode(String mode) {
    langpair = mode;