Tuesday, November 18, 2008

How to connect G1 GPhone Android T-Mobile with Computer via USB

This is really a simple task.
Just connect USB with you gphone and you computer via USB cable.
Then in the phone's notification area (on top the screen). Drag all the notifications out and there is a notification about USB. Click it and a pop up will ask you to "mount" or "unmount". Click mount and you can copy things in and out of G1's SD card between you computer and the phone.


Monday, November 17, 2008

Error from debugger: Error launching remote program: security policy error

I paid $99 and became an iPhone developer today.
When I tried to run a program on iPhone, I got the following error:
"Error from debugger: Error launching remote program: security policy error" in the xcode.
I followed exactly the steps of it.

Later, I found this is a really stupid small mistake.
In xcode, Groups & Files -> Targets -> xxxxx (xxxxx is your project name). Highlight it and click Info (command + i). 
In the "Properties" tab, there is an "Identifier" field. DEFAULT VALUE IS WRONG!!!
You need you use your own one that you use in creating an app id.
In iPhone Developer Program's program portal page. Click App IDs. Each id will look like this
XXXXXXXXXX is the nenerated bundle id.
In the "Identifier" filed of "Properties" tab, type "com.mywebsitename".
If this is not consistent with the one used in program portal page, when you try to launch program. "Error from debugger: Error launching remote program: security policy error" will be prompted.

How come Apple give such an stupid error that gives no information at all???

Recently I'm struggling with Apple and iPhone.
If I have a chance to choose whether to choose iPhone as my development platform, I will definitely say "NO!". I would rather use QBASIC in "文曲星" (a small computing device famous in China)

Tuesday, November 4, 2008

Convert Human Readable Time Format to Unix Time & Java Milliseconds ( (Java Code))

I just wrote a java program to convert Human Readable Time Format to Unix Time & Java Milliseconds ( (Java Code)).
The code can be accessed here.
I also put it as follows to make it searchable:
To test it, you can convert the milliseconds back to human readable time format here.

//Created on Nov 4, 2008 5:31:17 PM
//Author : Junxian Huang
package iperf;

public class HjxTimeConverter {
public static void main(String[] argv){
System.out.println("Time converter works");
//long milli = HjxTimeConverter.getMilliseconds(1986, 6, 11, 16, 20, 0, 0, -5);
long milli = HjxTimeConverter.getMilliseconds(2008, 11, 4, 18, 22, 0, 0, -5);
//long milli = HjxTimeConverter.getMilliseconds(1970, 2, 2, 2, 15, 1, 1, -5);
public static final int BASE_YEAR = 1970;
public static final int BASE_MONTH = 1;
public static final int BASE_DAY = 1;
public static final int BASE_HOUR = 0;
public static final int BASE_MINUTE = 0;
public static final int BASE_SECOND = 0;
public static final long MILLI_IN_A_SECOND = 1000;
public static final long MILLI_IN_A_MINUTE = 60 * MILLI_IN_A_SECOND;
public static final long MILLI_IN_A_HOUR = 60 * MILLI_IN_A_MINUTE;
public static final long MILLI_IN_A_DAY = 24 * MILLI_IN_A_HOUR;
public static final long MILLI_IN_MONTH[] = {
0, //A pad
28 * MILLI_IN_A_DAY,//For leap year, we add one day
* @author Junxian Huang
* @Time Created on Nov 4, 2008 5:31:17 PM
* Given time is local time based on the supplied time zone
* @param year
* @param month
* @param day
* @param hour : hour should in 24 hour format, e.g. 8pm should be 20, 12am (midnight) is 0, 12pm (noon) is 12
* @param minute
* @param second
* @param millisecond
* @param time_zone : Number follows GMT for your time zone.
* For Ann Arbor (EST which is GMT -5, time_zone = -5)
* @return Java Milliseconds
* You can check this using the online converter here (http://www.munc.com/jseffects/timeConverter.html)
public static long getMilliseconds(int year, int month, int day, int hour, int minute, int second, int millisecond, int time_zone){

long milli = 0;
int i;
for(i = BASE_YEAR ; i <>
if(i % 4 == 0){
//For leap year
milli += 366 * MILLI_IN_A_DAY;
milli += 365 * MILLI_IN_A_DAY;
for(i = BASE_MONTH ; i <>
if(year % 4 == 0 && i == 2){
//For leap year, February
milli += MILLI_IN_MONTH[i];
for(i = BASE_DAY ; i <>
milli += MILLI_IN_A_DAY;
for(i = BASE_HOUR ; i <>
milli += MILLI_IN_A_HOUR;
for(i = BASE_MINUTE ; i <>
for(i = BASE_SECOND ; i <>
milli += millisecond;
milli -= time_zone * MILLI_IN_A_HOUR; //We should subtract here!
return milli;

Saturday, October 25, 2008

How to run your first Java Servlet

Step by step running your first Java Servlet.

Step 1. Install tomcat http server from here. Select the binary based on your operating system. If you are using Windows, just click here. After download, just install it. After installation, you can access your home page at "http://localhost:8080" actually it is the content in "C:\xxx\Tomcat 6.0\webapps\" where "xxx" is the installation directory of your tomcat.

Step 2. Install java. How to do that? Search online, it is pretty simple. After installation, run in the command windows "javac", if it says "'javac.exe' is not recognized as an internal or externa command, operable program or batch file." You have to run "set PATH=%PATH%;C:\Program Files\Java\jdk1.6.0_10\bin" to add the java bin directory to Windows PATH variable. Make sure use your own directory for javac (I'm using jdk 6 update 10).

Step 3. Write your first Servlet
Store the following into "HelloServlet"
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request,
            HttpServletResponse response)
throws ServletException, IOException {

// Use "request" to read incoming HTTP headers (e.g. cookies)
// and HTML form data (e.g. data the user entered and submitted)
// Use "response" to specify the HTTP response line and headers
// (e.g. specifying the content type, setting cookies).
PrintWriter out = response.getWriter();
out.println("Hello Servlet");

// Use "out" to send content to browser

Step 4.  In "cmd" command line, run "javac HelloServlet.java", if everything goes well, you will get a new file "HelloServlet.class"

Step 5. Goto to your home directory for tomcat (mine is "F:\Study\tomcat\Tomcat 6.0\webapps"). Make a new directory called whatever, say "test".
Inside test, make a new directory called "WEB-INF". Go into "WEB-INF", make a new directory called "classes", put "HelloServlet.class" into "classes". 

Step 6. Inside directory "WEB-INF", make a new file called "web.xml".
It can be downloaded here. After you download, change the file name from "web.xml2" to "web.xml", because .xml file can be interpretted by many browsers.

Step 7. Open your browser and type "http://localhost:8080/test/HelloServlet"

If you see a blank page with a line of words "hello servlet", you are all set with your first java servlet.

Actually, I'm new to java servlet too. But I found it really powerful and interesting.

Friday, October 24, 2008

Python notes : input

In python, the easiest way to get an input is by using:
The difference between the two is that input will interpret what you have input while raw_input will just record faithfully whatever you have typed in including backspace.
For example, when you type three symbols "H", input method will return H while raw_input will return "H"

Hello world program for python input:
test_str = input("input some thing")
print test
test_str2 = raw_input("input some thing raw")
print test_str2

Saturday, October 11, 2008

Top 500 most popular websites full list in plain text

I just wrote a java program to output the 500 most popular websites full list in plain text for programming purposes. Any one who in need of the plaintext version of this is welcome to use my results.
My results are based on the results from Alexa's Global Top 500 most popular websites (http://www.alexa.com/site/ds/top_sites?ts_mode=global〈=none).

Format: Each line contains the index number and an URL separated by a space (" " in java)
1 http://www.yahoo.com/
2 http://www.google.com/
3 http://www.youtube.com/
4 http://www.live.com/
5 http://www.facebook.com/
6 http://www.msn.com/
7 http://www.myspace.com/
8 http://www.wikipedia.org/
9 http://www.blogger.com/
10 http://www.yahoo.co.jp/
11 http://www.baidu.com/
12 http://www.rapidshare.com/
13 http://www.microsoft.com/
14 http://www.google.co.in/
15 http://www.google.de/
16 http://www.hi5.com/
17 http://www.qq.com/
18 http://www.ebay.com/
19 http://www.google.fr/
20 http://www.sina.com.cn/
21 http://www.google.co.uk/
22 http://www.mail.ru/
23 http://www.orkut.com.br/
24 http://www.fc2.com/
25 http://www.aol.com/
26 http://www.vkontakte.ru/
27 http://www.google.com.br/
28 http://www.wordpress.com/
29 http://www.google.it/
30 http://www.flickr.com/
31 http://www.photobucket.com/
32 http://www.yandex.ru/
33 http://www.google.es/
34 http://www.google.co.jp/
35 http://www.google.cn/
36 http://www.amazon.com/
37 http://www.go.com/
38 http://www.naver.com/
39 http://www.craigslist.org/
40 http://www.friendster.com/
41 http://www.odnoklassniki.ru/
42 http://www.orkut.co.in/
43 http://www.google.com.mx/
44 http://www.imdb.com/
45 http://www.bbc.co.uk/
46 http://www.youporn.com/
47 http://www.taobao.com/
48 http://www.cnn.com/
49 http://www.adultfriendfinder.com/
50 http://www.googlesyndication.com/
51 http://www.skyrock.com/
52 http://www.163.com/
53 http://www.redtube.com/
54 http://www.imageshack.us/
55 http://www.youku.com/
56 http://www.ask.com/
57 http://www.google.ca/
58 http://www.uol.com.br/
59 http://www.pornhub.com/
60 http://www.espn.go.com/
61 http://www.adobe.com/
62 http://www.rakuten.co.jp/
63 http://www.orkut.com/
64 http://www.sohu.com/
65 http://www.ebay.de/
66 http://www.netlog.com/
67 http://www.apple.com/
68 http://www.dailymotion.com/
69 http://www.mixi.jp/
70 http://www.metroflog.com/
71 http://www.rambler.ru/
72 http://www.daum.net/
73 http://www.vmn.net/
74 http://www.rediff.com/
75 http://www.livedoor.com/
76 http://www.yahoo.com.cn/
77 http://www.google.com.tr/
78 http://www.fastclick.com/
79 http://www.fotolog.net/
80 http://www.livejournal.com/
81 http://www.about.com/
82 http://www.megavideo.com/
83 http://www.nytimes.com/
84 http://www.globo.com/
85 http://www.nicovideo.jp/
86 http://www.wretch.cc/
87 http://www.mininova.org/
88 http://www.soso.com/
89 http://www.google.com.au/
90 http://www.ameblo.jp/
91 http://www.nasza-klasa.pl/
92 http://www.google.pl/
93 http://www.goo.ne.jp/
94 http://www.google.co.id/
95 http://www.google.com.sa/
96 http://www.ku6.com/
97 http://www.yourfilehost.com/
98 http://www.imagevenue.com/
99 http://www.bebo.com/
100 http://www.comcast.net
101 http://www.google.ru/
102 http://ebay.co.uk/
103 http://www.free.fr/
104 http://www.mediafire.com/
105 http://www.4shared.com/
106 http://www.terra.com.br/
107 http://www.veoh.com/
108 http://www.megaupload.com/
109 http://www.xunlei.com/
110 http://www.google.nl/
111 http://www.xvideos.com/
112 http://www.perfspot.com/
113 http://www.google.co.th/
114 http://www.google.com.ar/
115 http://www.zshare.net/
116 http://www.weather.com/
117 http://www.deviantart.com/
118 http://www.tube8.com/
119 http://www.geocities.com/
120 http://www.doubleclick.com/
121 http://www.download.com/
122 http://www.orange.fr/
123 http://www.nifty.com/
124 http://www.amazon.co.jp/
125 http://www.tagged.com/
126 http://www.livejasmin.com/
127 http://www.sogou.com/
128 http://www.thepiratebay.org/
129 http://www.mop.com/
130 http://www.2ch.net/
131 http://www.gmx.net/
132 http://www.metacafe.com/
133 http://www.clicksor.com/
134 http://www.tudou.com/
135 http://www.adultadworld.com/
136 http://www.pconline.com.cn/
137 http://www.homeway.com.cn/
138 http://www.clicksor.net/
139 http://www.partypoker.com/
140 http://www.biglobe.ne.jp/
141 http://www.xnxx.com/
142 http://www.cyworld.com/
143 http://www.amazon.de/
144 http://www.maktoob.com/
145 http://www.geocities.jp/
146 http://www.google.co.za/
147 http://www.tribalfusion.com/
148 http://www.studiverzeichnis.com/
149 http://www.infoseek.co.jp/
150 http://www.sourceforge.net/
151 http://www.dell.com/
152 http://www.alibaba.com/
153 http://www.google.com.eg/
154 http://www.onet.pl/
155 http://www.cnet.com/
156 http://www.zol.com.cn/
157 http://www.kaixin001.com/
158 http://www.conduit.com/
159 http://www.gamespot.com/
160 http://www.imeem.com/
161 http://www.tinypic.com/
162 http://www.icq.com/
163 http://www.reference.com/
164 http://www.sakura.ne.jp/
165 http://www.alice.it/
166 http://www.ig.com.br/
167 http://www.answers.com/
168 http://www.multiply.com/
169 http://www.libero.it/
170 http://www.aim.com/
171 http://www.hyves.nl/
172 http://www.files.wordpress.com/
173 http://www.google.co.ve/
174 http://www.depositfiles.com/
175 http://www.ign.com/
176 http://www.wikimedia.org/
177 http://www.blogfa.com/
178 http://www.narod.ru/
179 http://www.mapquest.com/
180 http://www.xiaonei.com/
181 http://www.web.de/
182 http://www.hp.com/
183 http://www.google.com.co/
184 http://www.sonico.com/
185 http://www.smileycentral.com/
186 http://www.google.com.pk/
187 http://www.easy-share.com/
188 http://www.google.be/
189 http://www.vnexpress.net/
190 http://www.brazzers.com/
191 http://www.linkedin.com/
192 http://www.allegro.pl/
193 http://www.mozilla.com/
194 http://www.seznam.cz/
195 http://www.bp.blogspot.com/
196 http://www.pogo.com/
197 http://www.people.com.cn/
198 http://www.zedo.com/
199 http://www.miniclip.com/
200 http://www.filefactory.com/
201 http://www.isohunt.com/
202 http://www.typepad.com/
203 http://www.ebay.it/
204 http://www.megarotic.com/
205 http://www.ocn.ne.jp/
206 http://www.hatena.ne.jp/
207 http://www.ziddu.com/
208 http://www.badongo.com/
209 http://www.wp.pl/
210 http://www.google.com.pe/
211 http://www.xhamster.com/
212 http://www.badoo.com/
213 http://www.torrentz.com/
214 http://www.taringa.net/
215 http://www.pchome.net/
216 http://www.soufun.com/
217 http://www.linkbucks.com/
218 http://www.google.at/
219 http://www.sendspace.com/
220 http://www.ebay.fr/
221 http://www.mercadolivre.com.br/
222 http://www.dtiblog.com/
223 http://www.realitykings.com/
224 http://www.schuelervz.net/
225 http://www.gougou.com/
226 http://www.gamefaqs.com/
227 http://www.ning.com/
228 http://www.foxnews.com/
229 http://www.mercadolibre.com.mx/
230 http://www.seesaa.net/
231 http://www.mywebsearch.com/
232 http://www.theplanet.com/
233 http://www.google.se/
234 http://www.ucoz.ru/
235 http://www.6.cn/
236 http://www.indiatimes.com/
237 http://www.tianya.cn/
238 http://www.reuters.com/
239 http://www.sweetim.com/
240 http://www.saatchi-gallery.co.uk/
241 http://www.xtube.com/
242 http://www.google.com.vn/
243 http://www.mlb.com/
244 http://www.kooora.com/
245 http://www.anonym.to/
246 http://www.usercash.com/
247 http://www.google.cl/
248 http://www.foxsports.com/
249 http://www.paypopup.com/
250 http://www.nfl.com/
251 http://www.washingtonpost.com/
252 http://www.watch-movies.net/
253 http://www.ifeng.com/
254 http://www.google.gr/
255 http://www.softonic.com/
256 http://www.google.pt/
257 http://www.att.net/
258 http://www.google.ch/
259 http://www.disney.go.com/
260 http://www.ezinearticles.com/
261 http://www.wamba.com/
262 http://www.china.com/
263 http://www.tom.com/
264 http://www.sportsline.com/
265 http://www.zaycev.net/
266 http://www.target.com/
267 http://www.pcpop.com/
268 http://www.netflix.com/
269 http://www.symantec.com/
270 http://www.google.ro/
271 http://www.walmart.com/
272 http://www.amazon.co.uk/
273 http://www.jugem.jp/
274 http://www.it168.com/
275 http://www.rr.com/
276 http://www.wer-kennt-wen.de/
277 http://www.onemanga.com/
278 http://www.leo.org/
279 http://www.careerbuilder.com/
280 http://www.skype.com/
281 http://www.msn.ca/
282 http://www.milliyet.com.tr/
283 http://www.rmxads.com/
284 http://www.xinhuanet.com/
285 http://www.freewebs.com/
286 http://www.naukri.com/
287 http://www.126.com/
288 http://www.hurriyet.com.tr/
289 http://www.digg.com/
290 http://www.people.com/
291 http://www.marca.com/
292 http://www.verycd.com/
293 http://www.travian.ae/
294 http://www.ameba.jp/
295 http://www.bestbuy.com/
296 http://www.brothersoft.com/
297 http://www.match.com/
298 http://www.bangbros1.com/
299 http://www.runescape.com/
300 http://www.empas.com/
301 http://dantri.com.vn/
302 http://www.xanga.com/
303 http://www.softpedia.com/
304 http://www.bloomberg.com/
305 http://www.paipai.com/
306 http://www.zylom.com/
307 http://www.break.com/
308 http://www.exblog.jp/
309 http://www.slide.com/
310 http://www.wsj.com/
311 http://www.monster.com/
312 http://www.spankwire.com/
313 http://www.marketgid.com/
314 http://www.aweber.com/
315 http://www.msplinks.com/
316 http://www.tripod.com/
317 http://www.xboard.us/
318 http://www.bild.de/
319 http://www.dmm.co.jp/
320 http://www.fling.com/
321 http://www.myfreepaysite.com/
322 http://www.spiegel.de/
323 http://www.fanfiction.net/
324 http://www.wwe.com/
325 http://www.liveinternet.ru/
326 http://www.payserve.com/
327 http://www.last.fm/
328 http://www.scribd.com/
329 http://www.att.com/
330 http://www.repubblica.it/
331 http://www.google.ae/
332 http://www.bigpoint.com/
333 http://www.playlist.com/
334 http://www.google.com.my/
335 http://www.livescore.com/
336 http://www.cocolog-nifty.com/
337 http://www.wikia.com/
338 http://www.ikea.com/
339 http://www.guardian.co.uk/
340 http://www.letitbit.net/
341 http://www.cartoonnetwork.com/
342 http://www.invisionfree.com/
343 http://www.verizon.net/
344 http://www.usps.com/
345 http://www.co.cc/
346 http://www.freeones.com/
347 http://www.nih.gov/
348 http://www.livedoor.biz/
349 http://www.ynet.com/
350 http://www.aebn.net/
351 http://www.ups.com/
352 http://www.yaplog.jp/
353 http://www.justin.tv/
354 http://www.mtv.com/
355 http://www.linternaute.com/
356 http://www.latimes.com/
357 http://www.ebay.com.au/
358 http://www.yesky.com/
359 http://www.sexyono.com/
360 http://www.39.net/
361 http://www.excite.co.jp/
362 http://www.sanook.com/
363 http://www.googlepages.com/
364 http://www.debonairblog.com/
365 http://www.wordreference.com/
366 http://www.google.co.hu/
367 http://www.forumcommunity.net/
368 http://www.edgesuite.net/
369 http://www.elmundo.es/
370 http://www.mobile.de/
371 http://www.musica.com/
372 http://www.myway.com/
373 http://www.neopets.com/
374 http://www.ifolder.ru/
375 http://www.google.dk/
376 http://www.yam.com/
377 http://www.interia.pl/
378 http://www.commentcamarche.net/
379 http://www.4dh.com/
380 http://www.mynet.com/
381 http://www.tuenti.com/
382 http://www.t-online.de/
383 http://www.pornorama.com/
384 http://www.truveo.com/
385 http://www.abcnews.go.com/
386 http://www.y8.com/
387 http://www.quizrocket.com/
388 http://www.startimes2.com/
389 http://www.opendns.com/
390 http://www.myyearbook.com/
391 http://www.clarin.com/
392 http://www.yieldmanager.com/
393 http://www.secureserver.net/
394 http://www.over-blog.com/
395 http://www.altervista.org/
396 http://www.mercadolibre.com.ar/
397 http://www.minijuegos.com/
398 http://www.information.com/
399 http://www.telegraph.co.uk/
400 http://www.thefreedictionary.com/
401 http://google.co.il/
402 http://www.worldofwarcraft.com/
403 http://www.incredimail.com/
404 http://www.dion.ne.jp/
405 http://www.so-net.ne.jp/
406 http://www.nate.com/
407 http://www.enet.com.cn/
408 http://www.teacup.com/
409 http://www.petardas.com/
410 http://www.in.com/
411 http://www.marketwatch.com/
412 http://www.zing.vn/
413 http://www.kakaku.com/
414 http://www.google.ie/
415 http://www.ultimate-guitar.com/
416 http://www.filefront.com/
417 http://www.megaclick.com/
418 http://www.pornotube.com/
419 http://www.forbes.com/
420 http://www.iwiw.hu/
421 http://www.hulu.com/
422 http://www.ggpht.com/
423 http://www.metrolyrics.com/
424 http://www.adsrevenue.net/
425 http://www.sapo.pt/
426 http://www.pichunter.com/
427 http://www.univision.com/
428 http://www.google.fi/
429 http://www.google.com.ph/
430 http://www.56.com/
431 http://www.google.dz/
432 http://www.nbc.com/
433 http://www.sify.com/
434 http://www.bharatstudent.com/
435 http://www.tv.com/
436 http://www.hornymatches.com/
437 http://www.chinaren.com/
438 http://www.ninemsn.com.au/
439 http://www.globe7.com/
440 http://www.addictinggames.com/
441 http://www.leboncoin.fr/
442 http://www.real.com/
443 http://www.bramjnet.com/
444 http://www.corriere.it/
445 http://www.fimserve.com/
446 http://www.webshots.com/
447 http://www.tripadvisor.com/
448 http://www.prizee.com/
449 http://www.chip.de/
450 http://www.blogchina.com/
451 http://www.chase.com/
452 http://www.limewire.com/
453 http://www.freelotto.com/
454 http://www.irctc.co.in/
455 http://www.atdmt.com/
456 http://www.perezhilton.com/
457 http://www.888.com/
458 http://www.shinobi.jp/
459 http://www.zedge.net/
460 http://www.eastmoney.com/
461 http://www.dailymail.co.uk/
462 http://www.ovguide.com/
463 http://www.gametrailers.com/
464 http://www.dyndns.org/
465 http://www.ibm.com/
466 http://www.bankofamerica.com/
467 http://www.plentyoffish.com/
468 http://www.nokia.com/
469 http://www.usatoday.com/
470 http://www.fotka.pl/
471 http://www.nba.com/
472 http://www.xe.com/
473 http://www.uwants.com/
474 http://www.technorati.com/
475 http://www.tu.tv/
476 http://www.gaiaonline.com/
477 http://www.meebo.com/
478 http://www.yimg.com/
479 http://www.cricinfo.com/
480 http://www.expedia.com/
481 http://www.atwiki.jp/
482 http://www.google.com.ua/
483 http://www.gamer.com.tw/
484 http://www.01net.com/
485 http://www.timesonline.co.uk/
486 http://www.iij4u.or.jp/
487 http://www.oyunlar1.com/
488 http://www.1und1.de/
489 http://www.usagc.org/
490 http://www.winamp.com/
491 http://www.gyao.jp/
492 http://www.21cn.com/
493 http://www.ea.com/
494 http://www.esnips.com/
495 http://www.newegg.com/
496 http://www.orgasm.com/
497 http://www.wachovia.com/
498 http://www.mobile9.com/
499 http://www.dada.net/
500 http://www.google.com.tw

Thursday, October 9, 2008

Big-endian VS Little-endian

I've long been confused by these two concepts, because I didn't find a good way to remember.
Today I met with them again and finally know where they come from and then can easily remember because I think I found what they actually mean.
For little-endian, see this graph
For big-endian see this graph
What is endian?
It means the end. So big-endian means an end(start) with big value!
So byte in the low address has bigger value.
For little-endian, an end has little value!
So byte in the low address has small value.

Then we can remember.

For 16 bits and 32 bits endian, they are different.
In 32 bits endian, each 32 bits are treated as a whole as a number.

Perl Bitwise String Operators

The following perl scrap seems horrible, see if you can understand it
if ($ident !~ /^\241\262\303\324/ &&
   $ident !~ /^\324\303\262\241/ &&
   $ident !~ /^\241\262\315\064/ &&
   $ident !~ /^\064\315\262\241/)
       die "ERROR: Not a tcpdump file (or unknown version) $file\n";
To understand it, we have to first get farmiliar with perl bitwise string operators.
Bitstrings of any size may be manipulated by the bitwise operators (~ | & ^).
If you know them already, just skip them.

~ is the negation unary operator:
"Unary "~'' performs bitwise negation, i.e., 1's complement. For example, 0666 &~ 027 is 0640." referenced from here.

| is the binary or operator, 
"Binary "|'' returns its operators ORed together bit by bit."

& is the binary and operator,
"Binary "&'' returns its operators ANDed together bit by bit."

^ is the binary exclusive or operator,
"Binary "^'' returns its operators XORed together bit by bit."

So what does "!~" mean?
Unary "!'' performs logical negation, i.e., "not''.  "~" for exclusive or.
Well, we should learn that, "!~" itself is a binding operator.
First have a look at "=~", which is related with "!~"

Binary "=~'' binds a scalar expression to a pattern match. Certain operations search or modify the string $_ by default. This operator makes that kind of operation work on some other string. The right argument is a search pattern, substitution, or transliteration. The left argument is what is supposed to be searched, substituted, or transliterated instead of the default $_. The return value indicates the success of the operation. (If the right argument is an expression rather than a search pattern, substitution, or transliteration, it is interpreted as a search pattern at run time. This can be is less efficient than an explicit search, because the pattern must be compiled every time the expression is evaluated.

Binary "!~'' is just like "=~'' except the return value is negated in the logical sense.

Unary "\'' creates a reference to whatever follows it.
\241 can be viewed as a char in C, for example, CR+LF is "\012\015" or "\cJ\cM".

Here "^" is not exclusive or, but define the pattern that is at the beginning of a line

For "$ident !~ /^\241\262\303\324/", the left thing for us to know is /.../
This is a search pattern.
"$ident" is a variable to be matched.
So we know what the following scrap means now:
if ($ident !~ /^\241\262\303\324/ &&
    $ident !~ /^\324\303\262\241/ &&
    $ident !~ /^\241\262\315\064/ &&
    $ident !~ /^\064\315\262\241/)
        die "ERROR: Not a tcpdump file (or unknown version) $file\n";
If the beginning(^) of $ident is not one of the following for cases:
It will die with error "ERROR: Not a tcpdump file (or unknown version) $file\n"

This is the first step to understand god-read-perl

Tuesday, October 7, 2008

How to jailbreak iphone with firmware 2.1

Step by step jailbreak iphone with firmware 2.1
1. Install iTunes 8.0 (I used

2. Download the latest 2.1 IPSW firmware from Apple for 3G at here.

3. Download QuickPwn v1.2.0 with 2.1 ipsw support at here. Then extract the zip (there is no need to install). Don’t use QuickPwn 1.50, it doesn’t work when you try to load it the IPSW file.

4. Connect your iPhone (with power on) to your computer using USB cable.

5. Launch itunes 8.0. (You will see the your ipho
ne under the devices menu of itunes)

6. Shift-click on the restore button and browse to the 2.1 IPSW file you just downloaded.

7. After the upgrade (about 10 minutes wait for me) your iPhone will be running on 2.1 software 
Following steps will be involed, you don't have to control, they are automatic
"Prepare your iphone to restore" (multiple times)
"Prepare your iphone software to restore"
"Restoring iPhone software ..." (slowest)
"Verifying iPhone software..."
"Verifying iPhone restore..."
"Restoring iPhone firmware..."

After that, the following box will appear

8. Don't close iTunes. Launch QuickPwn by opening the folder where you extracted it and double clicking QuickPwnGUI1.20.exe

9. Select your device. Click the next arrow (Mine is iphone 3G).

10. On the next page, click browse and load the 2.1 IPSW firmware you just downloaded. Then click next arrow.

11. On the next page, make sure you select the "Cydia" checkbox (without Cydia, why do you need to jailbreak your iphone?). You can check "Installer" and replace logo as desired.

12. Now click on the Go button which will bring up a DOS window with some instructions. (wait for 2 minutes)

13. You’ll eventually get to a prompt to turn off your iPhone. (Don't hit enter until you've turned your iphone off)

14. Turn off your iPhone (hold power, slide to power off), then type "y" to contiune. Don’t disconnect your iPhone.

(Read carefully about this step, you have to be really carefully about the time)
You will be instructed on how to put your iPhone into DFU mode. Read it through to give yourself a refresher and ask yourself, "Are you ready to begin?"
1. Once you hit "y" you will get a 5 second countdown. 
YOU DON'T NEED TO DO ANYTHING YET. Let it count down to 0, 
2. then start the entire DFU procedure by holding the power button for 5 seconds
3. then pressing Home while continuing to hold Power for a 10 second count down, and 
4. finally releasing Power but continuing to hold Home for 30 seconds. For me, it counted down to about 20 seconds (meaning only 10 seconds passed) after which the computer detected the iPhone was in DFU mode. When this happens, you don’t need to hold anything down anymore and the countdown will terminate.

16. You'll see a couple tasks execute on the DOS windows and the progress. On your iphone, you will see a pineapple with a crack on it. Let it work its magic and once it finishes, you will have a pwned jailbroken iPhone running 2.1!

17. During the process you will get some error messages from iTunes. Yawn and ignore.

18. (Optional, I don't do this) If you don’t get your network provider signal, you need to downgrade the baseband to version 4.6 which is unlockable. Install BootNeuter from Cydia and set the settings as shown. Then hit the Flash button.

19. (Not complete yet.) Install total commander and T-Pot addon for it. Refer to my previous article for doing this.

20. Make sure your iPhone is on and still connected to your computer via the USB cable. Use TotalCommander to browse to your iPhone file system by first clicking -/- on the drop down menu with all the drives. Then double click on [T-PoT]. (This trick is just browing iphone file system, refer this my previous article)

21. You are now in your iPhone's file system. Use TotalCommander to navigate to
Just in case things don’t work out, make sure you save your existing MobileInstallation file simply by dragging the file over to the other window.

22. Now replace the MobileInstallation file on your iPhone with this patched one for v2.1 firmware.

23. Now use TotalCommander to navigate to 
and backup your existing "com.apple.mobile.installation.plist" file first, then delete it

24. Reboot your iPhone. Now ponder why you went through all this trouble (like us). Enjoy!

References pages

Sunday, October 5, 2008

Notes for tcpdump

Note 1 
I run tcpdump in iphone to listen to the packet traffic
I run "tcpdump -vvv -i en0 > en0" and "tcpdump -vvv -i pdp_ip0" at the same time in the terminal.
I the result file "en0", I find the following
>>> NBT UDP PACKET(138) Res=0x110E ID=0x81CE IP=169 (0xa9).254 (0xfe).223 (0xdf).49 (0x31) Port=138 (0x8a) Length=197 (0xc5) Res2=0x0 
WARNING: Short packet. Try increasing the snap length
I searched it and this needs not to be worried.

It's not something to be worried about. It's not a FreeBSD or 
SAMBA problem, either. 

It's tcpdump complaining about snaplen (-s ) being 
shorter than at least one packet it encountered in the stream.

For recovery purpose, I rewrite this line to "(Recovered by Junxian )id 33230, offset 0", so that the id can be recorded by my Perl script.

Start to learn Perl: Difference between single-quote and double-quotes

$s = 1;
print '$sAND\n';  will result in
print "$s \n"; will result in

In single-quote, compiler leaves everything what they are, while for double-quotes, special characters will be replaced

Refer to this page.

Start to learn Perl: Differences among exists, defined, and true

my %h = ();
#%h is a hash table
$h{'undef'} = undef;
$h{'defined_but_false'} = 0;
$h{'defined_and_true'} = 'true';

$key = 'undef';
print "Value EXISTS, but may be undefined.\n" if exists  $h{ $key };
print "Value is DEFINED, but may be false.\n" if defined $h{ $key };
print "Value is TRUE at h key $key.\n"     if         $h{ $key };
print "\n";

$key = 'defined_but_false';
print "Value EXISTS, but may be undefined.\n" if exists  $h{ $key };
print "Value is DEFINED, but may be false.\n" if defined $h{ $key };
print "Value is TRUE at h key $key.\n"     if         $h{ $key };
print "\n";

$key = 'defined_and_true';
print "Value EXISTS, but may be undefined.\n" if exists  $h{ $key };
print "Value is DEFINED, but may be false.\n" if defined $h{ $key };
print "Value is TRUE at h key $key.\n"     if         $h{ $key };
print "\n";

Store the above to "test.pl"
and run "perl test.pl"
You will get the following results:

Value EXISTS, but may be undefined.

Value EXISTS, but may be undefined.
Value is DEFINED, but may be false.

Value EXISTS, but may be undefined.
Value is DEFINED, but may be false.
Value is TRUE at h key defined_and_true.

So if a variable is true, then it is defined, and if a variable is defined, then it exists.
But reverse is not true.
A variable exists but may not have been defined, and a variable is defined but may not be true

How to share iphone's internet connection with you laptop using Wi-Fi connection, or say use iphone as a modem

This article aims to provide a way to connect your laptop with iphone using Wi-Fi connection, and use iPhone as the modem of your laptop, so you can have access to the internet with your iphone's 3G or 2G data service. This is really cool when you are at home and have a laptop, but you don't have internet access, either wired or wireless. The bandwidth is good, with this trick, you firefox is enabled to surf on the Internet.

Step 1: Jailbreak your iphone. (How to? I will write another article on how to do this. )
Before you do this, think carefully, because it violates the warrenty.

Step 2: Create a Ad-Hoc (device-to-device) connection using your laptop, in order to achieve this task, refer to my article for windows xp here, for mac os, I think it is also very easy.
Add your iphone to this network (Settings->Wi-Fi->enable Wi-Fi and choose the ad-hoc network)

Step 3: Install 3Proxy and Terminal

After jail broke iPhone, a Cydia icon will appear on one of the App pages. Load Cydia, and after self updating by Cydia, go to Install tab -> All Packages. Install both MobileTerminal and 3Proxy, then hit the Home button. The phone will restart and Terminal will be installed on iPHone Home screen. (refer to this page)
MobileTerminal enables you to run program with terminal as in linux.
3Proxy is for making your iphone a server using socks 5 protocol.

Step 4: Find your iPhone's IP address. 
This can be found by running "ifconfig" command in the terminal, but of course, you need to first install the package required for "ifconfig", search it in Cydia
Or, the easier way is the go inside the Wi-Fi connection by clicking the ">" sign of the current Wi-Fi connection in the "Settings->Wi-Fi" menu, write this address down in a paper.

Step 5: Open the terminal, type "socks" and click "return", it will hang there, it is fine, because the server is running and waiting for connection

Step 6:Run Safari on the iPhone and Open a Web Page
Launch Mobile Safari on iPhone and browse to any web page.
Note that this step is important to ensure that iPhone will internally switch itself and fallback to 3G GSM data connection when it fails to get through to Internet using the ad-hoc wireless connection, without dropping or terminating the ad-hoc network, allowing the SOCKS proxy server to transmit and transfer data via 3G network connection
(Each time when you find the iphone modem is not working, you should repeat this step)

Step 7: Configure Web Browser Fire Fox
Run Firefox web browser to configure proxy server for Internet traffic. In Firefox, go to Preferences -> Advanced -> Network -> Settings. Then, fill in the iPhone’s IP address written down from step 5 above into the SOCKS Host field, and enter 1080 as the port number.
Make sure all other proxy fields are blank and/or 0.

Step 8: Tunnel and Forward DNS Resolution Requests Through SOCKS Proxy
3Proxy SOCKS proxy can resolve target DNS names if the application sends domain name resolving requests to the SOCKS proxy. However, each application that requires to go to Internet via SOCKS proxy had to be configured manually, as most program will attempt to resolve a domain name against remote DNS server via HTTP protocol.

Firefox, for one, has such capability to force DNS resolution via SOCKS protocol. To enable such advanced option, type "about:config" into Firefox URL Location Bar. A huge list will appear, search for "socks" and change the value for network.proxy.socks_remote_dns preference to true (double click to change the value).
The DNS resolution limitation through SOCKS proxy also explains why some applications do not successfully browsing or connecting to Internet websites through tethering iPhone. However, once DNS requests have been cached locally, the domain will work system wide.

Now you can use the configured Fire Fox to go to any websites you are interested. You can do everything, even watch youtube videos smoothly.

(Don't forget to restore the changes that you made just now)
Step 9: Terminate socks proxy
After using the Internet connection via iPhone, terminate the SOCKS proxy server running on iPhone by switching back to Terminal, and then press and hold the Home button until Terminal quits, else it may slowly drain the battery life of iPhone.

Step 10: Change the fire fox configuration back, think what you did just now, and reverse.

Have fun!

How to browse iPod Touch/iPhone with USB and without Wi-Fi

I think without even jailbreaking iphone or iPod Touch, you can use my tricks to browse into the file system of them.
I will only use iPhone as an example.
iPhone is using Darwin file system, which is a distribution based on Free BSD.
Step 1: Download and install Total Commander, choose on of the download links in the list and install it.

Step 2: Download T-Pot from here, choose T-Pot.1.1.zip

Step 3: Open total commander, and browse into directory where you put T-Pot.1.1.zip, and double click it. You will be asked whether to install "Ipod Touch/iPhone USB filesystem browser", click "yes"

Step 4: Connect you iPhone with the computer using USB, and launch itunes

Step 5: Choose from the driver list (the list of [-\-]  [-C-], etc), choose "[-\-]", you will see "[T-PoT]", click it!

Step 6: Then you are browsing the iphone file system!

Typically, in the iPhone file system root, you will find "lib" "bin" "dev" "sbin" "System" "usr" folders, and some of them are similar to linux file system, you can easily download files and upload files from and to iPhone or iPod Touch.

Also, you can refer to this page

Have fun!

Saturday, October 4, 2008

Set up an Ad-Hoc network in your home for windows XP

Today I  set up an Ad-Hoc network of two windows XP computers.
And computer A can successfully access the web server at computer B.
With Internet connection sharing, you can ever make two laptops have Internet access at the same time, when there is only one network cable and no wireless network connections.
But of course, when one is downloading a file, the other will suffer and experience low bandwidth.

How to do this?
1 Go to Wireless Network Connection, click "Set up a wireless network for a home or small office"
2 Choose set up a new wireless network
3 Plugin your USB drive
4 Choose "use a USB flash drive"
5 Follow the instructions, and unplug the USB and plug it to the other computer
6 On the other laptop, authrun the USB and use the "run wireless wizard"
7 When it says that you have successfully added this computer to the ad hoc, unplug USB
8 Plug the USB back and click "Next" where you stopped
Then follows the steps and you can complete

How to share internet connections?
This is the options that you choose when you are creating the networks.
For example, they have such choice, "this computer connects directly to the internet, and other computers use its internet connection to have internet access" then, the other computer will have to choose "this computer use the other computer's internet connection to have internet access". And here we are.

Be sure to close the windows fire wall on both computers so that the traffic will not be blocked.

Also, you have to add the ad hoc to the preferred networks.
To do this, go to the "Wireless Network Connection Properties", and click "Wireless Networks", click add, and fill the information of you ad hoc. 

Be sure to check the box "Connect even if this network is not broadcasting"
(But I really have no idea why only one of my two laptops have this option, while the other doesn't have. Though one is enough)
So that this laptop will initiate the broadcasting and the other laptop will sense it.
Otherwise, none of them will see any available wireless connections in the list.

If you have any problem with this, give me an email (hjx@umich.edu)
I hope to be helpful, because this damn thing cost me a lot of trouble.

A small web service "Beetle Word-Phrase Checker"

Have a look at here

I built this for fun, and it is just new born, so it looks very basic and basic.

What I want to do is to provide an online word phrase checker.
That aims to correct your spellings when you are not sure.

For example, when you type "Internattional" Beetle will return a list of words with the first one "international"

For phrase checking, when you type "fall on love", Beetle will return a list of phrases with the first one "fall in love"

Currently, these functions are not finished yet. But I will work on them when I have time (of course not now, because we have a paper deadline on December)

I also want to add a web spider that crawl the web pages to gradually improve its database.

Give me some suggestions if you have some good ideas.
I think this kind of staff is really interesting and coding it is really fun.

By the way, I used java to analyze data, and web pages are written in php or basic html.
I used eclipse 3.4 Ganymede for Java. This is a really cool staff and I really like coding with eclipse. I use SVN and eclipse plugin subversive to do version control, so that I can easily program both on my laptop and on my desktop :D. For php and html, I use notepad++ to "program", I don't like IDE for html and php, because I really like building small blocks into a huge structure.

How remove the annoying system beep for Vista?

When you do some operations that are not proper, and when you don't have an ear phone or a sound box, Vista system will make an annoying beep. It will still generate this beep when you have even muted the sound control. How to remove this sound?

Go to "Computer" 's "Properties"
Click "Device Manager"
In the "View" menu of "Device Manager" window, choose "Show hidden devices"
Then an item "Non-plug and play drivers" will appear
Expand it, and double click "Beep" which is it sub-item.

Click the stop button.

Then don't forget to click "OK"

And the annoying beep is removed

Friday, October 3, 2008

How to install Darwin Streaming Server in Windows XP

You have to first install activeperl
Refer to my article to get this done.

Then refer to this and this.
Choose earlier version of Darwin Streaming Server at here.
When you download this file, extract it to somewhere.
Browse into the folder, and click install.bat.
Then it will beginning a console and begin installation.
It will ask you to type a user name and a password.
Then it will say "adding userName XXX"
In my case, it will hang there.
I just close the window.
Browse into "C:\Program Files\Darwin Streaming Server" or wherever else that you install you darwin streaming server, and click streamingadminserver.pl, a console will appear and hang there, then your server is beginning to listen on the port 1220

Open a browser with URL "http://localhost:1220"
A quicktime logo will appear and ask you for username and password.
Then it works.
Follow the steps and choose port 80 to go through the firewalls.

How to install perl in Windows XP

Download ActivePerl from here or here.
You need to input your name and email.
But it is free

Begin installation, follow the steps

[Check] Add Perl to the PATH environment variable
[Check] Create Perl file extension association
And your installation will be smooth.

refer to this page

After installation finished,  you will see the release note

ActivePerl 1004 -- Release Notes

Welcome, and thank you for downloading ActivePerl. This release corresponds to Perl version 5.10.

The following platforms are supported by this release:

  • AIX 5.1 or later (rs6000)

  • Linux: glibc 2.3 or later (x86 and x64)

  • Mac OS X 10.4 or later (x86 and powerpc)

  • Solaris 2.8 or later (sparc, 32 and 64 bit)

  • Solaris 10 or later (x86)

  • Windows 2000 (x86)

  • Windows XP, 2003, Vista (x86 and x64)


It is very cool to support so many platforms.

Apache conf
You have to have your apache web server running.
In "C:\Program Files\Apache Software Foundation\Apache2.2\conf"
Edit the httpd.conf file which is the configuration file of apache server in the following way

Activating CGI
Using Notepad (or other text editor) openhttpd.conf (also should be start-menu shortcut called "Edit Apache HTTP httpd.conf File") and search for Options Indexes "FollowSymLinks" (about line 217) when you find it add "ExecCGI" to the end so it looks like "Options Indexes FollowSymLinks ExecCGI"

You should restart your apache server after these changes
this page is very helpful for you to get perl cgi runing properly

Ubuntu 8.10 Beta Release, Install it!

Ubuntu 8.10 Betta has been released on Oct. 2, 2008.
I just download it from http://mirror.csclub.uwaterloo.ca/ubuntu-releases/8.10/ubuntu-8.10-beta-desktop-i386.iso this is very fast.
I downloaded it in less than 5 minutes in Michigan.

I just wasted a CD, because I used Vista's default burner to burn this image to the CD.
And system cannot boot. Because Microsoft protects its datatype to be recognizable only by Windows. I throw the CD in trash bottle and follow the steps in https://help.ubuntu.com/community/BurningIsoHowto
First download and installed InfraRecorder, then burn the CD (choose .iso file)
Then you are done.
I haven't tested whether I can installed ubuntu yet.
But I think there is not problem with this approach.

//I've tested it and successfully installed ubuntu 8.10 to my dell desktop.
//But the problem here is that the network interface can not be detected
//ifconfig there is only a loopback interface
//How to make ubuntu 8.10 have Internet access?
//I will fix it later