Friday, March 19, 2010

Traffic Ticket Fines in California Effective 2010

Pay close attention to the rules of the road!

 Traffic Tickets Fines (Effective 01/06/2010) (California)
Total Fine Due
VC 12814.6
Failure to obey license provisions.
VC 14600(A)
Failure to notify DMV of address change within 10 days
Note: The fine may be reduced with valid proof of correction.
VC 16028(A)
Failure to provide evidence of financial responsibility (insurance)
Note: This fine may be reduced with proof of insurance on or after the violation date.
VC 21453(A)
Failure to stop at a red signal.
VC 22350
VC 22349
Unsafe Speed, 1 to 15 miles over the limit.
VC 22350
VC 22349
Unsafe Speed, 16 to 25 miles over the limit.
VC 22450
Failure to stop at a stop sign.
VC 22454(A)
Passing a school bus with flashing red signals.
VC 23123(A)
Drive using wireless phone not hands free, First offense
VC 23123(A)
Drive using wireless phone not hands free, For each subsequent offense.
VC 23123.5(A)
Drive while wireless device to send, read or write text.
VC 23124(B)
Minor drive using wireless phone.
VC 22500(I)
Parking in a bus loading area.
VC 22507.8(A through C)
Violation of disabled parking provisions, first offense.
VC 22507.8(A through C)
Violation of disabled parking provisions, second offense.
VC 26708(A)
Unlawful material on vehicle windows.
VC 27150(A and B)
Adequate muffler required
VC 27315(D and E)
Mandatory use of seat belts.
VC 27360(A and B)
Mandatory use of child passenger restraints
Note: This fine may be reduced by completing a court authorized child seat diversion program.
VC 27400
Headsets/Earplugs over both ears.
VC 27803 (A through C)
Motorcycle safety helmet requirements.
VC 34506.3
Commercial Driver - Log book violation
VC 4000(A)
No evidence of current registration.
Note: The fine may be reduced with valid proof of correction.
VC 4159
Notify DMV of change of address within 10 days.
Note: The fine may be reduced with valid proof of correction.
VC 5200
Display of license plates.
Note: The fine may be reduced with valid proof of correction.
VC 9400 (A through C)
Commercial weight fees due.
Note: The fine may be reduced with valid proof of correction.

Saturday, March 13, 2010

Replacing $ in a String in Java

I faced an issue in my project recently where we read a password for an admin user first from a file which has a dummy or wrong password written in it. Then I read the password from database and replace the dummy password with the real password that I get from Database. So the code was something very simple like this (this is actually different from originalk).

String myXmlDoc = readALargeXmlAsString();
String realPassword = readFromDatabase();
String password = myXmlDoc.replaceAll("dummyPassword", realPassword);

All on a sudden we found that this replacement started failing after the password of that admin user was changed recently. Here is the exception log.

Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(
at java.util.regex.Matcher.replaceAll(
at java.lang.String.replaceAll(
at com.salesforce.test.StringReplaceTest.main(

So I figured out from the log that it’s actually the replaceAll() pattern matching method that is causing the failure when you have $ in your replacement string (not in the pattern itself). So as per the first code example, if you had a $ character as one of the characters for realPassword, then it would throw the exception above. While the solution was to use a different admin for now who doesn’t have a password containing $ sign, I sat down to investigate it in detail and write a long term solution.
First I reproduced the issue in 3 different ways. Here is a code that will tell you depending on where you are putting the $ sign, the exception stack trace will be different. I give you the code and the compile and run instructions so that you can test it yourself.

package com.salesforce.test;

* To compiple: javac -d .
* To run: java com.salesforce.test.StringReplaceTest
* or, java com.salesforce.test.StringReplaceTest start
* or, java com.salesforce.test.StringReplaceTest middle
* or, java com.salesforce.test.StringReplaceTest end
* @author ashik
public class StringReplaceTest {
public static void main(String[] args) {
System.out.println("\nStringReplaceTest starts.....\n");
String firstStr = "I am a Java programmer working in USA. Chess is my hobby and here in USA lot of people play chess.";
System.out.println("firstStr before replacing = " + firstStr);
String positionPOfDollarSign = "";
if(args.length > 0) {
positionPOfDollarSign = args[0];
String secondStr = "";
if("start".equalsIgnoreCase(positionPOfDollarSign)) {
secondStr = firstStr.replaceAll("USA", "$PUT_A_VALUE123"); // illegal group reference
} else if("middle".equalsIgnoreCase(positionPOfDollarSign)) {
secondStr = firstStr.replaceAll("USA", "PUT_A_VALUE$123"); // String index out of range: 15
} else if("end".equalsIgnoreCase(positionPOfDollarSign)) {
secondStr = firstStr.replaceAll("USA", "PUT_A_VALUE123$"); // java.lang.IndexOutOfBoundsException: No group 1
} else {
secondStr = firstStr.replaceAll("USA", "PUT_A_VALUE123"); // no error
System.out.println("\nsecondStr after replacing firstStr = " + secondStr);
System.out.println("\nStringReplaceTest ends.....\n");

Developing the fix was a little tricky as replacing the $ and \ characters (these 2 are what makes trouble) using regular methods like Spring.split() or StringTokenizer class doesn’t work as those itself can’t process $ correctly. So I had to do my search and replace based on the String.indexOf() and String.substring(). Here is my fix and I would like to know your feedback on this. Please note that Apache StringUtils will be a very good resource to use here instead of trying to write the algorithm yourself.


import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

 * To compiple: javac -d .
 * To run: java
 * @author ashik
public final class SfdcReplaceSubstring3 {

 // private static String firstStr = "I am a Java programmer and a $Chess$ player working in USA. $Chess$ is my hobby and here in USA lot of people play $Chess$. USA had a great Chess player named Bobby Fischer.";

 private static String firstStr = "Java, Apex, $Chess$ and Oracle - which one do you like? I guess Chess. If not $Chess$ then what else?";

 private static String patternToSearch = "$Chess$";

 private static String[] replacementStrFromDB = { null, "", " ", "PUT_A_VALUE123",
   "PUT#A^VALUE!123?a+b/c>d", "PUT$A$VALUE123", "$PUT_A_VALUE123",
   "PUT_A_$VALUE123", "PUT_A_VALUE123$", "PUT_A_VALUE$123",
   "PUT_A_VALUE123$", "\\$PUT_A_VALUE123", "\\\\$PUT_A_VALUE123",
   "\\PUT_A_VALUE123", "\\\\PUT_A_VALUE123", "\\PUT_A_VALUE$123",
   "\\\\PUT_A_VALUE$123", "\\PUT_A_VALUE123$", "\\\\PUT_A_VALUE123$",
   "$PUT_A_VALUE$123$" };

 public static void main(String[] args) {
  System.out.println("\nfirstStr before replacing = " + firstStr);
  System.out.println("\npatternToSearch = " + patternToSearch);
  // System.out.println("Direct replacement: " +
  // matcher.replaceAll("PUT\\$A\\$VALUE123"));
  for (int i = 0; i < replacementStrFromDB.length; i++)
   try {
    System.out.println("\nExecuted test#"
      + (i + 1)
      + ": "
      + "firstStr after replacing with "
      + replacementStrFromDB[i]
      + " = "
      + replace(firstStr, patternToSearch,
   } catch (Exception e) {
    System.out.println("\nExecuted test#" + (i + 1) + ": "
      + "Exception while replacing firstStr with "
      + replacementStrFromDB[i] + " = " + e.getMessage());

 public static String replace(String text, String searchString,
   String replacement) {
  int start = 0;
  int end = text.indexOf(searchString, start);
  if (end == -1) {
   return text;
  int replLength = searchString.length();
  StringBuilder buf = new StringBuilder();
  while (end != -1) {
   buf.append(text.substring(start, end)).append(replacement);
   start = end + replLength;
   end = text.indexOf(searchString, start);
  return buf.toString();


Tuesday, March 09, 2010

Bon Jovi Concert, 1st ODI double century by Tendulkar and more

Last month (Feb 22, 2010 Monday to be precise) we went to see the live concert of Bon Jovi in San Jose. With me there were Shusmita, Shahriar, Nodee and Amin as we dropped Ahyan to Wali Bhai/Asha Vabi's house. Shusmita was interested when she heard about Bon Jovi and although I am in now way fac of English music except Michael Jackson and Hip Hop songs like 50 Cents, I agreed to the costly tickets of HP Pavilion in San Jose. We came back from office early that night and was on time at the stadium. I was understanding very well how good Bon Jovi was handling the crowd and making them stand on their feet. He has so many good songs although more than half of those I probably never heard. I enjoyed the show and his performance. So our next target in this line will be Black Eyed Peas (Ahyan's favorite) and Bryan Adams (Shusmita's favorite).

While last few months were great for me cricket wise as I was able to watch online several  Bangladesh and Sachin Tendulkar cricket games, the most rewarding one came at 24th February when Sachin made the first ODI double century in internal cricket (not counting women cricket). Aah, what an innings! No power hit, just fine pure cricketing brain and technique!!

While James Cameron's Avatar already crossed 2.5 billing USD in worldwide earnings, it lost the Oscar prizes to The Hurt Locker for best film and best director award. But at least amongst the 3 oscars it won, the best cinematography is there.

I got my new Macbook Pro laptop from office last week and am playing around with this. Right now, I have 2 PCs in office one Windows XP and another one Red Hat Linux Enterprise Edition 4.7. So this Mac is allowing me to use all the 3 worlds of O/S simultaneiusly. I like it.

In the meantime, we watched Karthik Calling Karthik recently in Union City. Deepika looked beautiful & Farhan proved that he is a great thinker. The movie was on my favorite topic schizophrenia and I could not help thinking of Humayun Ahmed's Misir Ali stories time and again while watching the movie. That prompted me to start reading the next project of Farhan Akhtar - The 3 Mistakes of My Life which is Chetan Bhagat's third book. I got the PDF version of the book online and it's about cricket, religious politics and rebellious love. About how 3 friends get caught in a tangle to earn some money and fame, and how they sort it out. The book was published in May 2008 and had an initial print-run of 200,000. The novel follows the story of three friends and is based in the city of Ahmedabad in western India. making Chetan the best selling English Novelist in India's history. Farhan's Excel Entertainment has bought the rights for making a movie based on this, and it will be directed by Abhishek Kapoor of Rock On!

I started regular Sunday hiking considering the Mount Whitney timeline is getting closer and also the rainy season is about to end that compelled me on and off to skip hiking in a few weekends. I particularly enjoyed lkast Sunday's hiking where we took a detour to cross a steep hill. While Sayeem and Shahriar were just fine, Hasinur and Nitol had to work a bit considering they have been out of hiking for a while now. Our next weekend plan is a grand Sunol Wilderness hike where lots of other Bangladeshi people are expected to join us. Please check our facebook group of Bay Area Bangladeshi Hikers Group for details.

Thoughts on Life, Death, and Overcoming Fear

I've been pondering a topic that's universally relevant yet rarely discussed - death and the anxieties it evokes. As I delve deeper ...