Saliya's Blogs

Mostly technical stuff with some interesting moments of life

IntelliJIDEA: A Feature I Like to See

Recently I was doing some tiresome debugging with Java using IntelliJIDEA. It was then that I thought that there is a great improvement we can do. This is totally my imagination, so I am not sure on any implementations in the Internet (yet).

The IDEA enables you to put debug points. These debug points may serve in creating a virtual path to traverse through the code. Thus, you are able to quickly jump to the next important point of code by just hitting F9. All this works really well for your debugging scenario. Now, what if you want to debug a different scenario, yet do not want to remove the older debug points? Then you have no option other than to add any new break points for the new scenario along with the older break points. This works okay, but makes the life bit hard since F9 will jump to points which are useless for the new scenario.

So what I suggest is to have a mechanism to define break points separately for each debugging scenario. So when you place a break point you can give it a scenario ID and inform the debugger to follow the break points for the relevant ID. It will be like layers that you find in Adobe Photoshop. You can on/off layers. Similarly we can deactivate a set of debug points based on their ID.

I wonder what JetBrains would think about this :)

Huawei E160 on Ubuntu 8.04

Recently, I subscribed to a 3G Internet connection provided by Mobitel. The modem I purchased is Huawei E160. Just like the most other plug-n-play devices this gadget did not include drivers for Ubuntu :). Anyway, I decided to give a try to set it up and voila! it worked.

E160 has two modes of operation. It can act as a GSM modem and a data storage. So when you plug it in under Ubuntu it will attach it under one of these modes. If your network manager is older than version 0.97 then you it will normally get attached as a data storage device. You can see info on this by reading the kernel ring buffer with dmesg -c command (you will need root privileges, i.e. sudo dmesg -c). If it get attached as an storage device use usb_modeswitch to change its mode to a GSM modem.

If everything went well then the rest is pretty easy. You will need to install wvdial (i.e. sudo apt-get install wvdial). Then edit the /etc/wvdial.conf file to include the following settings. Note: these are valid only with Mobitel M3 service in Sri Lanka. You may have to change some settings depending on your service prvoider.

[Dialer Defaults]
Modem = /dev/ttyUSB0
Baud = 3600000
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Init3 =
Area Code =
Phone = *99#
Username = ppp
Password = ppp
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1


Now execute sudo wvdial and that's it. You are ready to go online with E160 :D

Unlock Toyota Corolla 141

On the eve of the Sinahala New Year, I was with my parents in our village. All the members of my mother's family were there to enjoy the occassion. Everything went fine until I accidently locked the car while the key was inside. The situation got worse when we found out that the extra key was inside the car as well. 

After trying out things in "Gone in 60 Seconds" I realized that they were not going to work. One of my relatives, however, found the dust hole cap of the driver's seat and tried to push the carpet hoping to create an entrance into the car. Aha! luck strucked, the carpet elevated the trunk opener and trunk popped. We were, yet, no way near to any of the keys in the car. Then I thought I could slide my hand through the joint of the back seat to grab the extra key. Oh! boy it was hard. So left with no hope, we searched for other ways to get in. 

The elder son of my aunt, however, was able to slide his hand without getting stucked and finally was able to grab the extra key, which was on the back seat. So much fun for the New Year :)

So here are few tips to avoid yourself getting into this situation.

1. Keep the extra key at home
2. Check the key before locking the car
3. If your key has a tag number keep it written in your pocket (this number can be used to cut an extra key for your car from the dealer)

Now the bottom line is that things in your trunk are not safe since it can easily be popped ;)

New Year Drink: Mango

Just before the Sinhala New Year I got the chance to taste a raw mango with salt and pepper. If you have not tried this before then my advice is do it today itself. Yep, the taste is awesome :)

Anyway, while eating I wanted something to drink as well. Um, so why not try a mango drink, I felt. 

What you need:
1. A raw mango (gira amba, rata amba, pol amba) except for karthakolomban
2. A mug (yea, who wants to get satisfied with just a cup of water) of water
3. Two table spoons of sugar (depends on your likeness)
4. Salt (very little)

How to:
1. Clean and peel the mango
2. Slice the peeled mango into small sections
3. Put the mango pieces into a blender and add water
4. Blend the mixture till you get a nice light greenish color
5. Filter the final mixuture to a jug and add sugar and salt as you like
6. Add two ice cubes and drink it.

Enjoy the drink while you wait for the New Year !

3G Experience with Mobitel M3: Huawei E 160

After relocating ourselves back to the village, I missed the luxury of Sri Lanka Telecom's (SLT) ADSL broadband connection. CDMA was the saviour till yesterday. Suntel, thogh charge a little bit than other providers, gave a fairly good connection (note: fairly good is w.r.t. the available connection speeds in Sri Lanka). 

Anyway, the need for a high speed connection grew pretty quickly. I tried Dialog, but it seems they do not have the 3G coverage out here. Taking bit of a risk, I decided to purchase a Mobitel connection. Honestly, their customer service was great. The only thing I did not like is the vendor locking of the 3G modem. I mean, the modem is from Huawei, so why do they want it to be locked only for Mobitel SIMs?

Regardless, of the vendor locking the connection was satisfactory with 3.6Mbps. I had to purchase a separate antenna for better reception, yet it is worth the price.

WSO2 Carbon: Feature Packs

I just realized the flexibility of WSO2 Carbon when I tried to install Business Process capability into WSO2 ESB, which is based on WSO2 Carbon.

Simply extracting and copying the bundles in the feature pack does the job. Try it out at http://wso2.org/downloads/carbon/feature_packs

Sri Lanka and GSoC

Sri Lankan students gave a huge impact on Google Summer of Code 2008. This is a video by ICTA on that where my good friend Heshan and others giving out there idea on GSoC.

Java Regex: Check for non word characters

I wanted to test a given string to see if it contains any non word characters in Java. Initially I came up with a lengthy version ;) Then after a bit of search I could simply shorten it.

Version1: regular expression

"\\p{Alnum}*[~!@#$%^&*()\\+=\\-:;<>\\s?\\[\\]{},/\\\\\"]+\\p{Alnum}*"

Version2: regular expression

"\\p{Alnum}*\\W+\\p{Alnum}*"

Here's a nice guide (http://java.sun.com/docs/books/tutorial/essential/regex/index.html) to start with Java regular expressions

Java Threads and Concurrency

The Sun's tutorial (http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html) on concurrency with Java is a great place to start with multi-threading.

Have fun with threads :)

Batch Resize Images

I was searching for a tool to scale images batch wise in Ubuntu and it seems that ImageMagick is just the one for it. Here's how you can get it working as well.

Step1: install ImageMagick

$ sudo apt-get install imagemagick

Step2: go to the images folder and type

$ mogrify -sample 1280 x 800 *.JPG

Here 1280 x 800 is the final size you want and *.JPG is the file set.

To get more info on command options, visit http://linuxuser32.wordpress.com/2007/06/16/batch-image-convert-scale-thumbnail-jpegs-pdf/

Playing with BlueProximity

I recently came across this nice blog which had a post on locking the screen automatically. Anyway after seeing the comments I found it will be interesting to use Bluetooth to achieve this. I wanted to write some script on my own to get it done. Anyway as an initial step I tried BlueProximity which comes with Ubuntu. Here is a list of steps to get everything working.

1. Install blueproximity:
$ sudo apt-get install blueproximity

2. Pair up your computer with your phone using Bluetooth. You can use System -> Preferences -> Bluetooth to do so.

3. start blueproximity:
$ blueproximity &

You will see the blueproximity icon appearing on your system panel.

4. Configure blueproximity to suit your likings, i.e. the distance after which your screen will get locked, time duration, etc.

That's it.

Anyway it is not kicking unless I can write my own code :D

Lectures at UoM

I started lecturing Data Structures and Algorithms to Level 2 students of the Dept. of Computer Science and Engineering, University of Moratuwa, Sri Lanka. Overall, it is a great experience and I really enjoy it. The bottom line that I understand is that it is only when you start teaching that you understand that you have to learn more ;)

Build Your Own SOA Middleware

If what comes out of the box does not suit your way of SOA requirements then try out WSO2 Carbon. The ebook (http://wso2.org/project/carbon/making_good_soa_great.pdf) says it all.

Beautiful Sri Lanka

Access Vista from Ubuntu

Ever tried accessing a shared folder in Vista from Ubuntu? Here are the simple step I followed.

For this example say your Vista user account is vista-pc and password is vista-pw. Also say the IP is 192.168.1.2

----Do the following in your Vista machine----
1. Start/Run secpol.msc
2. Open Local Policies/Security Options, find "Network Security: LAN Manager"
3. Change it to "Send LM & NTLM"
4. share the folder that you want (say movies)

---Do the following in your Ubuntu machine---
1. sudo apt-get install smbfs
2. sudo apt-get install smbclient
3. sudo mkdir /mnt/hd
4. sudo mount -t smbfs -o username=vista-pc,password=vista-pw //192.168.1.2/movies /mnt/hd

That's it :) You can now access the shared Vista folder from /mnt/hd

Increase Java Heap Memory for Maven

If you ever encounter an error saying Java heap is not enough, while building a project using Maven, the following content will help to get out of it. Thanks Charitha for finding this.

Set the MAVEN_OPTS system property,

e.g. MAVEN_OPTS=-Xmx1024m  will give you 1024 Mb heap

NBQSA Merit Award for Rampart2

Sameera, Kalani, Isuru and I developed a Web services security module for the well known Apache Axi2 middleware. The existing security module, Rampart, has issues concerning performance. Therefore, our solution mainly focused on high performance. We used the code name Rampart2 to refer our project, though it is not part of Apache yet. The performance comparison of Rampart and Rampart2 can be found here.

BCSLanka organizes a competition named National Best Quality Software each year. Rampart2 got selected and was given a merit award in this year's competition. 

We are happy with our achievement and are waiting for more good news on Rampart2.

Hard Times

I broke my spectacles and got a new pair from George Gooneratne Optometrists. Guess what? They have taken wrong measurements and I had to visit them again to replace the glasses with correct measurements. After spending about two hours at their lab I finally got my sparkling shiny spectacles. 

 

The day after I was playing basket ball at WSO2 when I got hit by the ball right on my face at a most unexpected time. I was actually catching my breath and I look up only to see something crashing on to me. The shiny new spectacles were broken into pieces and my nose got wounded. The wounds were not that serious and I was lucky not to bleed internally. I found the broken frame of my spectacles and thought, hey that's not too bad because I still have the frame to which I can get a pair of glasses fixed. I put all the pieces into my bag and came home. The next day I was getting ready to go and get new glasses fixed. I collected broken frame and believe me, one side arm was missing. What the hell? I told myself. I searched every possible place I could look into but came up with nothing. Hmm, that's life, I thought and went to optometrist and get a new spectacle fixed. 

 

The next day I was happy with my new spectacles and spent the day peacefully at WSO2. The entire day I was in a meeting and later in the evening I and the others were invited to dinner at an Indian restaurant. The food was okay, but it didn't sound right for me. The next morning I woke up to find that I am suffering from a very bad stomach ache. I spent the entire day at home unable to do anything. The medication came to effect only in the evening. Today is the second day of the very unpleasant "Digesting Error", and there is yet another day to go to end the week. I am expecting what next :)

Google Chrome - Fast and Elegant

I had couple of issues with IE and FF3 in Windows and I decided to give it a try with the Buzz: Google Chrome. Amazingly, it's pretty fast than I expected. The next thing I like about chrome is it's simplicity, no stupid buttons hanging all over your browser :). 

I like the concept of having processes for each tab. I am wondering that browser technology is going to be much like the OSs. I mean the comic book is filled with many OS concepts I have learnt :). 

Kudos to Chrome !!

Java Strings: literal.equals(param) OR param.equals(literal)

Comparing strings is bit tricky :) Say for an example you want to test a String reference against the literal "hello". In simple terms you have a String (say helloStr) and you want to see if the content of that is equals to "hello". You have two choices here,

1. helloStr.equals("hello")

2. "hello".equals(helloStr)

Both will do fine, but which is the better one? I've been using the second form but never thought of the difference (hmm, that's bad ;) anyway people do remember certain things bit later). In one of the code reviews at WSO2 it was revealed. The first form can lead to a Null pointer exception in the case when the helloStr is null. The second option will save you from this since the literal "hello" is not null always and you are invoking a method of a not null object. In this case even if the helloStr is actually null it doesn't matter because it'll only cause the program to check "hello" against null which results false.

If you are checking two String references then you have no option, but always try to invoke the equals() from the most probably not null reference.

Little things do matter :)