Friday, January 30, 2009

Java tip: how to split a string with "." (a dot)

String a = "a.jpg";
String str = a.split(".")[0];
This will throw ArrayOutOfBoundException
Why is this?
This is because "." is a reserved character in regular expression, representing any character.
Instead, we should use the following statement:
String str = a.split("\\.")[0];
When the code is compiled, the regular expression is known as "\.", which is what we want it to be

Click here for something funny

HERE

Thursday, January 29, 2009

Java: How to read pixel RGB values from images

BufferedImage img = null;

int w, h;

int pixels[];

try {

img = ImageIO.read(new File("images/secret.jpg"));

w = img.getWidth();

h = img.getHeight();

pixels = new int[w * h];

img.getRGB(0, 0, w, h, pixels, 0, w);

System.out.println(img.getWidth() + " X " + img.getHeight());

System.out.println("R:" + ((pixels[0] >> 16) & 0xff) + " G:" + ((pixels[0] >> 8) & 0xff) + " B:" + (pixels[0] & 0xff));

} catch (IOException e) {

e.printStackTrace();

}


//Based on the sample code, it is really easy to see how to read RGB values from any image files.

Wednesday, January 21, 2009

Damn it: How on earth can I get tcpdump running on gphone adroid g1 ???

//Anyone have any idea???

//I tried to search online and found my own blog -_-!!!

Finally, with the help of Timur, I can now run tcpdump on a holiday version of GPhone, it also works for Developer version GPhone, but not the normal version, because tcpdump requires root mode.

See my other post :

Finally tcpdump on GPhone G1 Android

See this link for help.

Monday, January 19, 2009

What is iPhone root access password?

"alpine"

In iPhone, you can't use this password to use "sudo", but you can still gain root access
In terminal, type "su" and enter pwd "alpine", then you enter root mode.
Really funny that sudo's password is not su's