Monday, September 06, 2010

World War II + India + Java

While exploring Java timezone related API, it was a surprise to me that during the World War II, India(being colony of England) had Daylight Saving Time !

This timezone was in effect from 1-Sept-1942 to 15-Oct-1945. Interestingly, this DST is supported by Java date time API.

DateFormat indiaDtFmt = new SimpleDateFormat("dd/MM/yyyy HH'h'mm");
DateFormat gmtDtFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


Date worldWarIIDate = indiaDtFmt.parse("02/02/1944 06h30");
Date nonWorldWarIIDate = indiaDtFmt.parse("02/02/2006 06h30");

System.err.println(gmtDtFmt.format(worldWarIIDate) +" GMT");
System.err.println(gmtDtFmt.format(nonWorldWarIIDate) +" GMT");

The above code produces the following output.

1944-02-02 00:00:00 GMT
2006-02-02 01:00:00 GMT

So the during the World War II, India was in the timezone +4.30 GMT compared to the normal timezone of +5.30 GMT.

This also mean the horoscopes of the people born in India during the World War II need to take this DST into consideration. These people include celebrities like Ilaiyaraaja,Azim Premji,Amitabh Bachchan etc.

Obviously this well known to Astrologers.Here is one of the links for war-time correction for horoscopes. Another link for war time correction across the world.

Saturday, July 31, 2010

Auto Fare Converter

New Auto fare in Bangalore is in effect from Aug 1, 2010. But, Autos have been given 2 month time period to change their meters.

As a result, commuters are expected to know the fare conversion from old to new. Either trust the Auto Driver or have a print of the fare conversion table published.

So I quickly wrote a mobile application to do the conversion. I wrote 2 versions, one android version and other Java ME (MIDP 2.0) application.

Here are the links to the application installables

Application Usage:
  1. Enter the current fare in the meter.
  2. Click Convert button.
  3. The amount you need to pay, the new fare, will be shown.

Monday, July 26, 2010

BMTC Bus Ticket Cost Calculation

In a recent travel through BMTC bus to my office, I was involved in a big fight between another software engineer and the bus conductor on - how the ticket price was calculated? The software engineer did not know Kannada and the bus conductor could explain in the English. I served as the translator in that heated argument :)... here is the info how the ticket price is calculated.

Note: The calculation is performed by the ticketing machine given to the bus conductor so the conductor cannot cheat you!

BMTC divides the routes into stages. Following is the 'Fare Table' of BMTC Bus No 45. You can get the 'Fare Table' for your route from the conductor....Please Ask!


Now the stage you climb the bus is the Stage 1 for you and of course the stage you get off is the last stage for you. Lets see the following examples of fare calculation with the previous assumption.

Fare from

  • KAMAKYA to KBS = Stage 8 - Stage 0 = 8 Stages crossed = Rs 16
  • BANK COLONY to GOODS Road = Stage 7 - Stage 4 = 3 Stages Crossed = Rs 9
  • GOODS ROAD to KBS = Stage 8 - Stage 7 = 1 Stage crossed = Rs 5

List stageList=[KAMKYA...KBS]
List fareList=[0..16]
int start= stageList.indexOf[YOUR START STAGE]
int end = stageList.indexOf[YOUR END STAGE]
Fare= fareList[end-start]

Hope the calculation is clear!

Sunday, May 30, 2010

Reading Java Concurrency

The j.u.c package added to Java in 1.5 introduced me to the world of Concurrency research itself. Somehow i never thought of looking to this package beyond Executors class.

Here is the study plan for that worked for me...
  1. Locks, Conditions And Fairness
  2. Understanding the Java Memory Model and its fix by JSR 133
  3. Happens-Before and volatile.
  4. LL/SC, CAS concepts
  5. Atomic package
  6. Concurrent Data Structures & Synchronizers
  7. Executors,Futures and other threading concepts.
People & Forums:
  1. Articles by Brian Goetz, Doug Lea
  2. Java concurrency Interest group.

Two useful books:
  1. Concurrent Programming In Java by Doug Lea.
  2. Java Concurrency in Practice By Brian Goetz

Sunday, January 31, 2010

Here is the perl script to convert .rm files to .mp3 format on linux. Needed this script since my DVD player cannot play .rm files. Script needs the following software to work
  1. Perl
  2. mplayer
  3. lame
  4. wget
The script can download rm or ram files and then process the download .rm files to produce the .mp3 file.
#!/usr/bin/perl -w
use strict;


&usage if @ARGV!=1;
my $fileName=shift;
&usage if ($fileName !~ m#\.(ram|rm)$#);
&process_ram($fileName) if ($fileName =~ m|\.ram$|);
&process_rm($fileName) if ($fileName =~ m|\.rm$|);

sub usage(){
print STDERR "usage: $0 filename.rm/ram\n";
exit 1;

sub process_ram(){
my $fileName=shift;
open RAM_FILE, $fileName || die "Failed To Process File: $!";
chop if ~ m/\r$/;
$_ = &processUrl($_);
close RAM_FILE;

sub process_rm(){
my $fileName=shift;

sub convertToMp3(){
my $fileName=shift;
chop($fileName) if $fileName =~ m/\r$/;
print "Processing File...$fileName";
my ($dirName,$baseName)=&dirname($fileName);
$baseName =~ s/\.rm/.mp3/;
die "Invalid File: ${fileName}" unless(-e $fileName);
`mplayer $fileName -ao pcm 2>/dev/null`;
`lame -h -b 128 audiodump.wav $dirName/$baseName`;
`rm audiodump.wav`;

sub dirname(){
return (".",$_[0]) unless $_[0] =~ m|^/|;
return $_[0]=~ m|(.*/)(.*)$|;
sub processUrl(){
my $fileName=shift;
return $fileName =~ m|.*/(.*)$|,$1;
return $fileName;

sub isUrl(){
$_[0] =~ m/^http.*/;

sub download(){
print "Downloading File...$_[0]";
system("wget -c $_[0]")==0 || die "Failed to download file: $_[0]";