Base64 Encoding in Android 2.1 or Earlier

Base64 is common used. Now Google added a utility class android.util.Base64. Unfortunately it is only available in Android 2.2 and later.

So, you need just a little bit work to use it with Android 2.1 or ealier. Yes, just copy and past the source of Base64 into your project. Make sure to preserve the Apache 2.0 license section, in order to conform to the license. The source code is provided at the end of this post, for your reference.

My disclaimer: I am not responsible for any result in doing the practice described hereby. Read the license if you need.

Now let’s see example usage:

The output is:

Encoded: dGhpcyBpcyBhIG1lc3NhZ2UgYnkgZnJhbmsu

Decoded: this is a message by frank.

Let’s try decode the message in python:

You will get the same input message htere. Now you are ready to send your data to anywhere, like app engine, you know!

The android.util.Base64 source

Posted in android, java, python | Tagged , , | 3 Comments

Get the latitude and longitude from google map, which can be copied easily

1. Center the location of interest. You can use the yellow people marker to center it.
2. Copy and paste the following line to the address bar. Then press ENTER:


—- or —-


Posted in Internet | 1 Comment

Resolve ambiguities in antlr v3

When there is ambiguities in writing antlr grammar, there are different ways to solve it.

1. Simply avoid them. This is the ideal way when it’s possible.

2. Turn on backtracking, which is most inefficient way.

3. Use left factoring.

4. Use syntax predicates.

For some samples, check it out at

The format of sytnax predicate is close to semantic predicates. There are 3 types of them:

1. Validating semantic predicate, to place constraints on rules. For example
data : ( b += BYTE )+ {$b.size() <= 4}? ;
2. Gated semantic predicate, to turn on some alternatives under runtime condition. For example:
stat: ifState | {allowAssert}?=> assertStat ;
3. Disambiguating semantic predicate, to choose alternatives based on semantic context. For example:
stat: keyIf ID stat | keyCall ID ‘;’ ;
keyIf: {input.LT(1).getText().equals(“if”)}? ID ;
keyCall: {input.LT(1).getText().equals(“call”)}? ID ;

Posted in antlr | Leave a comment

How to read cassandra source code by Ran

Here is a good article explaining how to read cassandra source codes:

Understanding Cassandra Code Base:

Posted in Uncategorized | Tagged , | 1 Comment

A simple thrift tutorial

Check it out at

Posted in java | Leave a comment

Let firefox use your Windows authentications automatically

In Firefox, visit:


Then set network.automatic-ntlm-auth.trusted-uris to your trusted domains, separated by comma.

Posted in Internet | Leave a comment

A very nice presentation about agile software development

Some of my thoughts: Unit tests are very important in TDD. It enables you easily refactor code, adhere to customer requirements, and verify logics at earliest points. It also enables Continuously Integration to work brilliantly.

Posted in Uncategorized | Leave a comment

Interesting lessons in Cassandra Slides

There is a famous Cassandra PPT at SigMod 2008. In one slide, they presented several interesting lessons:

  1. Add fancy features only when absolutely required
  2. Many types of failures are possible
  3. Big systems need proper system-level monitoring
  4. Value simple designs

These lessons are interestingly useful. 🙂

Posted in Uncategorized | Leave a comment

ANTLR v3 Tutorials Aggregation

Here are some tutorial links for learning antlr v3:

  1. The Getting Started Tutorial from Official Site is Damn Good!
  2. ANTLR Works is a damn good tool!
  3. The Definitive Antlr Reference is a good book
  4. ANTLR 3.X Tutorials are good video course and introduced a damn good eclipse tool: ANTLR IDE.
Posted in antlr, DSL, eclipse | Tagged , , | Leave a comment

Retrieve Line Numbers and Column Numbers in your ANTLR AST

We know that you can easily get the line numbers and column numbers information from the lexer token, via the properties: line & pos.

When facing an Abstract Syntax Tree (AST), the rules may be rewritten so that the tree node tokens are in different order. Then how to retrieve the line numbers?

This is very important in language execution, because users will definitely need information about which line caused the issue.

The answer is simple: Retrieve the information from underlying lexer tokens. In a tree grammar rule, there may be multiple tokens. So it’s up to you to decide which token to look into. A naive method may be to look into the first token of  a tree node, using the start property.

There is another method. You can check it out at Recovering line and column numbers in your Antlr AST.

Posted in antlr | Leave a comment

Set the source level to Java 6 for maven 2 compiler

By default, the source level is 1.3 in maven 2. We need to config maven compiler to use Java 1.6. Add the following snippet to your pom:

Posted in java, maven2 | Tagged , , | Leave a comment

Very nice video for Eclipse & ANTLR v3 development

If you are doing antlr v3 for Java, you can be very interested in this series of video tutorials. It demos how to develop with antlr3 IDE, and also the process of a small language. It credits to Marcel for the recommendation. Check it out at:

ANTLR 3.x Tutorials:

Posted in antlr, java | Tagged , , , | Leave a comment

Something interesting in the Language “GO”

Recently I noticed many languages released or emerged, such as GO, NOOP, Simple for Android, and the one by vim author (sorry I cannot remember it).

Days ago, Google released a new language named ‘GO’. It is available at

This is interesting, because recently google released a couple of language tools. I am wondering: will it be natively supported by the possible upcoming Google Chrome OS?

I looked around the language grammar, and notice something interesting:

1. Is GO a dynamic language, or strong typed? Look at the variable declaration. They have the keyword ‘var’ which implies dynamic typing. However, you can specify the variable types!!

var i int; // define an integer. Doesn’t it look strange?

var j = 10; // j is an integer. This is like JavaScript

var x, y float = -1, -2; // define 2 floating numbers. The initializers are even stranger.

var a, b, c = 2.0, 1, “hello, world”; // they have different types. This looks like tuple in Python.

2. The authors try to reduce keyboard typing.

If you look at the if-statement or for-statement, you will notice that the parenthesis follow if/for is eliminated, although you can still use them, (because if/for statements expect an expression, while parenthesis enclosed expression is still expression).

3. The semicolon plays an important role. It is used a lot as statement delimiters. They don’t use NEWLINE. NEWLINE is treated as space char.

4. The switch statement is interesting. It helps to reduce the ugly of if-else-if-else-if-else statement. By their grammar, the code formatting can be prettier:

5. There is no while statement. Neither is do-while statement. They don’t even reserve while as a keyword!

6. The package import implies dynamic package loading. In Java/C#/Python/C++, generally you use a qualifier to denote a package name, such as: import java.util.Date.

In GO, it’s different by using string:


“io” ;


I think it implies that they want dynamic loading of packages. It will be much easier to compute a string at runtime, and then import the denoted package.

The above are what I have found so far. Haven’t installed the language environment so far. I probably will do it in December, after my CFA examination. 🙂

Posted in DSL | Leave a comment

Nice GEF Tutorial

GEF involves many concepts as it establishes its MVC convention. You may find tutorials from eclipse official site spend most paragraphs in concept explanation.

Here is a very nice tutorial focusing on step-by-step application. It’s not long, around 80 pages in PDF version:

Posted in eclipse | Tagged , , | Leave a comment

Internet Gene & Software Gene

Last week, I read an article about a famous IM company. One statement is very interesting: A company has its genes carrying by its people. The company has more internet genes, while Microsoft has more software genes as a comparison.

Internet generally requires or allows different development-shipping cycles. It can be shipping in finer granularity, e.g. a small release every 1~3 day. Therefore, it blows up the whole process of traditional software. Therefore, the production organizing around internet services is structured more to such cycles. Therefore, actively participant people are more important while they face more intensive life. 🙂

Posted in Internet | Tagged | Leave a comment