Vote 1

Is Ruby very syntax rich? Do you like it? I don’t.

August 19th, 2008

I tried delving into Ruby couple of times in the past. Every time I had this weird feeling of what am I doing here when I am already very well conversant with a simpler language - Java, which gives me everything I need. Ruby just felt very syntax rich, may ways and interesting tricks to do stuff and so on.While these may be appealing to a script-kiddie, nice syntactical sugars do not help much in the long run or help you create robust code (unless you love flying whales and a service which fails every other day).

I am not afraid of developing CRUD interfaces nor do I find it time consuming. What value can I get from RoR? Every time I delve into Ruby & RoR, I come back feeling unsatisfied. What am I missing here?

Read more (315 words) »

Vote 1

Apache Ant: How To Set Property When Initially Unset

August 19th, 2008

Also: How To Flexibly Pass JVM parameters to Apache Ant Java (Runtime) Task

Apache Ant is an excellent Java based build & deployment system using XML configuration file. In Ant properties are extensively used to configure tasks, conditionally run targets and more. In short they are an intergral part of build system. My requirement was simple. I wanted to pass JVM arguments to the Java runtime. However sometime I wanted to invoke it without passing any special runtime arguments. Unfortunately jvmarg element doesn't like it when its value is an empty string or even a string with spaces. Finding no way to fool it, I then tried to find a way to set the property to something when it is initially not set (while invoking). This proved surprisingly hard to do. Here is an elegant (I think) solution I came up with. Read more (231 words) »

Vote 1

Apache Ant: How To Include Multiple Jar Files In A Single Jar File

August 19th, 2008

Apache Ant is an excellent and popular Java based build system. It has several built-in commands (tasks in Ant lingo) one of which allows you to create Jar file from your existing class file and resources. What if you wanted to include not just class files but selective contents of other jar files too and make a single big jar file?

Ant provides an undocumented way to include the contents of multiple jar files within a single jar file.
Read more (180 words) »

Vote 1

Db4o Note: Db4o.configure() != Db4o.newConfiguration()

August 19th, 2008

In earlier versions of Db4o we used Db4o.configure() to configure all Db4o database globally (across all ObjectContainer). However in 7.2 (and above) versions of Db4o Db4o.configure() has been deprecated and it is suggested to use Db4o.newConfiguration() instead. Unfortuanately they do not clearly mention anywhere that these two functions are not equivalent. I assumed they are equivalent like Db4o.set()is equivalent Db4o.store() or Db4o.get() is equivalent to Db4o.queryByExample().

Read more (201 words) »

Vote 2

Biggest Db4o Gotcha!

August 18th, 2008

Db4o is an excellent open source object database for Java & .NET platform by Carl Rosenberger's team. I highly recommend it for rapid prototyping and RAD. It transparently handles object storage and retrieval. Today I will talk about the single biggest gotcha in Db4o which is bound to stumble any newcomer as well as pros who haven't been using it in a while.

In Db4o you can create an complex objects with other objects as its member and Db4o will save them all like a champ with a single set() (now store()) method. So intuitively you try to use the same concept for updating the database. This is where you will stumble. Db4o by default doesn't recurse when updating an object.The stranger aspect is that when you save it to the database with a store or set and then retrieve it again it will appear to work fine. However after you close and re-open the database your data will be lost! This is the single most baffling feature I found in Db4o.

Read more (318 words) »

Vote 1

How To Debug Smack API (Java XMPP Library)

August 17th, 2008

Smack is an excellent Java XMPP Library. While creating a pubsub broker in XMPP I faced a strange issue where few messages were missing. I then found a simple way to debug the Smack library. Just start your JVM (java) with the following option:
Read more (81 words) »

Vote 3

One MySQL Configuration Tip That Can Dramatically Improve MySQL Performance

August 13th, 2008

I mean every word of it. I found this simple configuration tip after days of continuously looking at MySQL logs (mytop), top, slow log queries, debugging the hell out of applications, reading tons of MySQL optimization tips (and pulling my remaining hairs in frustration) on the web. Even MySQL optimization tips from MySQL doesn't mention it. And yet this single tip solved all my MySQL headaches and performance problems. Here are some of the problems I faced:

My powerful dedicated server was frequently consuming 100% of the CPU even with moderate load.
Even with tons of optimization and indexes, I found my server idle CPU going to 0%. The key resource consumer was MySQL. The worst part was that MySQL refused to serve new request as all threads were exhausted waiting (for some miracle to happen?).

Does any of that sound familiar? Then read on for the gory technical explanations and the tip.

BTW: My initial reaction to such problems was the standard one. I looked at MySQL master-master replication (this is better than the master-slave replication which WordPress.com does for its sites) to take care of the increased load. Fortunately this single configuration change made my server take at least 10 times more load than before.

Read more (590 words) »

Vote 3

How To Automatically Start Nginx & Fastcgi on Reboot on Fedora Linux

August 10th, 2008

nginx [engine x] is a high quality, light footprint (much ligher than Apache HTTPD), high performance HTTP server and mail proxy server written by Igor Sysoev. nginx is distributed under BSD license unlike its competitor Lighttpd. We are progressively transferring our sites over to nginx. Today when I had to restart the server, I realized (after few hours) with horror that we had forgot to add the script to start nginx automatically after reboot. When you want any command to execute everytime after a reboot you should add it to /etc/rc.local. The commands in rc.local are executed *after* all the other init scripts. To automatically start nginx as well as fastcgi on reboot you should add the following lines to /etc/rc.local at the end -

Read more (300 words) »

Vote 3

Nginx: How To Stop Referrer Spam With Keyword Filtering

August 8th, 2008

You can configure Nginx to stop referrer spam by checking for bad keywords like tramadol, phentermine etc. This reduces the load on your server as well as prevents filling your referrer logs with invalid entries. Here is my nginx configuration to stop referrer spam (feel free to copy it):
Read more (139 words) »

Vote 2

Nginx: How To Redirect /index.php To / To Avoid Content Duplication

August 8th, 2008

Normally any website that responds to /index.php also responds to /. This has the potential to duplicate content. So how can you re-direct /index.php to / without causing infinite loop in nginx?

Here is a simple solution:

Read more (77 words) »