I am Mohammad Farhan Husain, a Bangladeshi American. This is all about my day-to-day life and opinions.
Saturday, December 31, 2011
My first domain
Saturday, November 19, 2011
My Kindle Fire review
Thursday, November 10, 2011
C/C++ going stronger than what people think
Link: http://www.tiobe.com/content/paperinfo/tpci/images/tpci_trends.png
Wednesday, November 09, 2011
Development model using Git branching
Thursday, October 20, 2011
Quick and easy way to split lots of strings in Java
1. StringTokenizer
2. Scanner
3. String.split
StringTokenizer had to be discarded immediately as it is getting old and is only there for backward compatibility. The Javadoc itself says, "StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code." The Scanner is a great utility but seems to be bit heavy for that method. I had to keep in mind that the method would be called potentially billions of times in a row and it has to be as quick as possible. This left me with only the last option. String.split works in a simple way. It returns an array of strings. So, I could just use something like this:
However, as noted here, there is a performance issue with this. Each String.split() call compiles a regular expression pattern and then uses the pattern to split the string. The pattern compilation is indeed very expensive and can slow the method down significantly. So, essentially what the String.split() method does is this:
public String[] split(String regex) {
return Pattern.compile(regex).split(this);
}
By looking at the implementation, it becomes immediately obvious what one can do if lots of strings need to be split by the same regular expression. One can just have a pre-compiled pattern and call its split method repeatedly:
Patter pattern = Pattern.compile(regex);
...
for (String str : strings) {
String splits [] = pattern.split(str);
// Do something with the splits ...
}
The only thing unknown to me is whether the returned strings allocate new memory or the Pattern.split() method just behaves as String.substring(). But from running the code with more than 2.5 billion strings, I did not see any performance difference between the old and the new approach. It might mean that copies of strings are actually not made.
Tuesday, October 11, 2011
Netflix does not support Linux!
Friday, August 12, 2011
A tortured choice in famine: Which child lives?
Wednesday, August 03, 2011
My Review of Roku 2 XS Streaming Player
Adds an enhanced remote for playing games, plus extra connectivity options.
Roku rocks!
Pros: Easy to use, High quality picture, Great value, Reliability, Compact, Built in Wi-Fi
Cons: Want more video choices, Set up bugs
Best Uses: Living room
Describe Yourself: Power User, Netflix fan, Technophile
I bought Roku one week ago and I am absolutely enjoying it. The picture quality is superb. However, I faced few minor problems though, most of them during installation. While I was setting up my Wi-Fi connection, it hanged in the third step (connecing to Internet) and I needed to restart it. After I restarted it, it failed to connect to my Wi-Fi at first and said that the password is wrong. I found the password to be correct and tried once more without changing any thing and it worked fine. Since then I am facing no problem with connectivity. The only problem I am having persistently is with the Picasa application. It cannot show any photo though it can show the albums with their covers showing correctly.
Overall, I am very satisfied with my purchase.
(legalese)
Tuesday, July 26, 2011
Eclipse Color Themes Plugin
Wednesday, July 20, 2011
Finance minister justifies his purchase decision with a sound logic!
He wants to buy the buses from India and what he says about the decision is, "We could have bought them from other places, but since we're getting the credit from India, we should bring them from India". Is this a logic we want to hear from a finance minister? In today's world, purchase decisions are made not to express gratitude. We should get the best buses the money can buy. If those buses happen to be produced by India then it is fine. There can be one more reason to buy it from India even if they are not the best ones, that is if it is a condition specified in the loan agreement. For no other reason we can choose India as a source for the buses, let alone gratitude. I wonder how this guy qualifies to be our finance minister. The other day I was reading a news about him blabbering that we are going to compete with world economic powers like India and China soon. The commentators on the Prothom Alo page did not like that. I did not take it seriously then. But now I think this guy truly is an incompetent finance minister. Had Bangladesh been a developed democratic country, this guy would have lost his position for these reason. But all we can do is to pray to Allah to save us from incompetent ministers like him.
Thursday, June 30, 2011
Navigation between Vim tabs
map <F7> :tabp<Enter>
map <F8> :tabn<Enter>
imap <F7> <Esc>:tabp<Enter>
imap <F8> <Esc>:tabn<Enter>
I used both map and imap commands because one works in Ubuntu Linux but not when I use iTerm in Mac OS X and vice versa.