Search this site:

2010-02-28

Development Environment


I need a perfect environment to start my work, that's why I always spend many of my time tuning the workspace to make myself enjoy the work more. I just spent some time this weekend tunning the two IDE I used often~

Courier New was my choice for coding font, but sometimes it makes me feel bored. Tried a few other fonts come with Windows, but most of them are non-fixed width and not good for coding. At last I found one called Consolas and look nice to me at the size of 9pt. I made the font a bit smaller to display more codes on the screen. Scrolling really slows down my sense and feel on the codes that I want to avoid as much as possible.

I saw many other developers are using dark backgrounds instead of the default white ones in most of the IDE. Maybe it looks more comfortable in long time coding. However, those theme with dark background colors usually come with colorful foreground colors which may distract me... Pure white background is really a bit tiring, light gray may be a nice choice to me.

So this is how my Eclipse looks like now:


I did the similar for Visual Studio, and soon I noticed Visual Studio has no built-in support for current line highlighting... There seems not to be one for the coming 2010 version either... I can only rely on extensions for this tiny but killing feature... What a pity... Anyway found one useful and free one called Slickedit Gadgets. There are other alternatives like the famous ReSharper but they seems to have too much unnecessary feature for me. I am always reluctant to install too much... Simple is always the best :)

This is how my Visual Studio looks like after fine tuning:


That's it :)

2010-02-21

Locales in Android


I live in Hong Kong, and my mother language is Chinese (or Cantonese). However, I don't really enjoy user interfaces in Chinese. The fact that digital world is based in US cannot be changed - most computer terms are originally in English, and they are often poorly translated to other languages, at least not for Chinese... That's why the OS I use is always in English, and I install English version of software, and I use English interface in my Nexus One.

Unfortunately, Nexus One has only limited choice in locales (DO NOT mix up with the Android app named "Locale") by default. In the list, only 中文(繁體) [zh-HK] or English (United States) [en-US] are applicable to me, but none of them is my preference.

Non-tech guys may ask what codes like zh-HK and en-US are. These are so called locales in the computer world. The first part is a language code defined in ISO 693 describing what language should be used, while the second part is a country code defined in ISO 3166-1 describing things like date/time format, phone number format and currency. Software is supposed to display values accordingly to this locale settings.

So you may notice the problem here. I can't have both English user interface and the Hong Kong set of formats... For example, when displaying phone numbers...

This is how it looks like when en-US is chosen.

The dashes look really strange to people living in Hong Kong. We seldom divide phone numbers into groups. And even when we do, we don't make 3-digit groups (but 4-digit groups). I really can't recognize the phone number at first glance...

Changing to the zh-HK locale make the phone number looks better...

But as said, I am not comfortable with Chinese user interfaces...

Finally, I found a solution tonight. Some nice guys in Japan developed the MoreLocale 2 app for Android. Thanks to this great app I can finally set my locale as en-HK, having the result like this:


Footnotes #1: Yes, I know someone will notice that the phone number is the one in a recent popular TV ads (in Chinese). :D

Footnote #2: Yes again. I am that kind of people who are over-focusing on tiny parts of overall experience. One simple disadvantage may kill a product in my mind, and one simple advantage may make me become die hard fans :)

2010-02-11

1st Look at Buzz


Tried Buzz today... My question is why we need yet another "status" service...

Well, anyway, I am using it. LOL. It's nice for it to have easy importing from other content providers like Flickr, Blogger, Twitter, and etc. It doesn't require (or allow) you input credentials for imported (they called it "connected") sites, therefore only public content will be imported. And that's why my Twitter feeds aren't buzz-ed.

Also noticed that comments & follow-ups would be sent to your inbox automatically. I really wonder why this is needed when the Buzz link is directly below that of your Inbox. Anyway, it may be due to the fact that Buzz is built on the G-mail platform. Your own Buzzs even appear in the All Mail folder.

Can't find an option to turn that off yet. But if you are thinking how to get rid of those auto E-mails, try to create a filter. Buzz updates sent from address: noreply-XXXXXXXX@updates.google.com, where XXXXXXXX is profile ID of the sender. Anyway, it seems to be safe to create a filter like this:

from:updates.google.com

Happy Buzzzzzzzzzzzzzzzzzing!

2010-02-07

Batch insert to SQLite database on Android


I am using LIME for Cangjie(倉頡) input method on my Nexus one. The app is really nice and handy. However, there are quite a lot of users asking to improve the speed for loading the mappings.

After knowing the app was released as open source software, I immediately checked out the source and had a look on the loading function.

Oh, data was stored in SQLite. Below is the simplified version of pseudo code for the importing:

ArrayList list = new ArrayList();
count = 0;
while (reading a line from input file succeed) {
list.add(line);
if (count = 100) {
insertList(list);
reset(list);
count = 0;
} else {
count++;
}
}
insertList(list);


In order words, the author was trying to do a batch insert of 100 records (indeed 101...☺). This is a reasonable trial as batch insert can normally save some overheads. However, when I further went into the insertList() function, I saw something like the below pseudo code:
for each record in the list {
do_some_processing();
if (line represent a valid entry) {
db.insert(SOME_TABLE, null, SOME_VALUE);
}
some_other_processing();
}


Thanks to my previous projects involving SQLite, I believed I had found out the potential issue of the slow loading of mappings.

As described in my previous notes, SQLite, by default, creates a journal file for each transaction, and delete the file after the transaction completes. The above code does not explicitly create any transactions, so each insert call will be treated as an independent one. As a result, expansive file operations will be called frequently and slow down the process...

Therefore, I modified the code to make all the insert calls in the same batch in a single transaction:
try{
db.beginTransaction();
for each record in the list {
do_some_processing();
if (line represent a valid entry) {
db.insert(SOME_TABLE, null, SOME_VALUE);
}
some_other_processing();
}
db.setTransactionSuccessful();
} catch (SQLException e) {
} finally {
db.endTranscation();
}


I then tested the code in the emulator running on my notebook. The original code inserts at a rate of around 10 records per second, while the version with transaction inserts at a rate of 30+ records per seconds. WOW, that's a sound improvement!


I then attempted to increase the batch size from 100 (ok, 101...☺) to 500 (501...☺) and hoping for a further improvement. However,the insert rate drop to around 28 records per seconds. Still sounds good, but why not just keep the old batch size for a better result? The drop may due to limited resources in emulator, so in other words, the app will have a different optimal batch size on different handset. I rather keep that part untouched.

Reported the findings to the author, and hoping for a new release soon~ Anyway, just another story of optimizing the insert speed of large amount of data to SQLite. Enjoy! :)

Disclaimer

ALL CONTENTS AND INFORMATION IN THIS WEB SITE ARE PROVIDED "AS IT" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE ACCURACY AND AVAILABILITY OF THE CONTENTS, INFORMATION AND THE WEB SITE ITSELF ARE NOT GUARANTEED. THE AUTHOR TAKES NO RESPONSIBILITIES ON ANY COSTS OR DAMAGES (DIRECT OR INDIRECT) ARISING OUT OF OR IN CONNECTION WITH THE ACCESS, USAGE OR INABILITY OF USAGE OF THIS WEB SITE.