Wednesday, September 3, 2008

Triggers wont work with jdbc queries

I wanted to execute trigger creation through ant scripts so that whole installation process will be automated. But unfortunately trigger creation script kept failing. After some googling I figured out that problem is in the command DELIMITER |. This command is one of commands available in mysql client and is not included in sql specification. Mysql default delimiter ; is used in trigger which is unfortunately mis guiding clients like jdbc query to stop at wrong delimiters, thus creating errors.
For the moment it seems like I have to invoke triggers using command line. Anyway if I found out a solution I will let you all know.

Tuesday, September 2, 2008

My first trigger...

I've been occupied with lot of work and could not find the time to sit and write some posts...
But this was sooo interesting and couldn't keep from coming here and posting it for ur knowledge...
This is the first trigger I have written.. It's something that is used to update a tables called values_table and template_table. I have changed some of the names of the table since it's from my cmpny project ;)
DELIMITER |


CREATE TRIGGER xxtriggername AFTER INSERT ON channel
FOR EACH
ROW BEGIN
INSERT INTO values_table
VALUES
(NULL , NEW.channel_id, 1, 1, 0.0),
(NULL , NEW.channel_id, 1, 2, 0.0),
(NULL , NEW.channel_id, 1, 3, 0.0),
(NULL , NEW.channel_id, 1, 4, 0.0),
(NULL , NEW.channel_id, 1, 5, 0.0),
(NULL , NEW.channel_id, 1, 6, 0.0),
(NULL , NEW.channel_id, 1, 7, 0.0),
(NULL , NEW.channel_id, 1, 8, 0.0),
(NULL , NEW.channel_id, 1, 9, 0.0),
(NULL , NEW.channel_id, 1, 10, 0.0),
(NULL , NEW.channel_id, 1, 11, 0.0),
(NULL , NEW.channel_id, 1, 12, 0.0),
(NULL , NEW.channel_id, 1, 13, 0.0),
(NULL , NEW.channel_id, 1, 14, 0.0),
(NULL , NEW.channel_id, 1, 15, 0.0),
(NULL , NEW.channel_id, 1, 16, 0.0),
(NULL , NEW.channel_id, 1, 17, 0.0),
(NULL , NEW.channel_id, 1, 18, 0.0),
(NULL , NEW.channel_id, 1, 19, 0.0),
(NULL , NEW.channel_id, 1, 20, 0.0),
(NULL , NEW.channel_id, 1, 21, 0.0),
(NULL , NEW.channel_id, 1, 22, 0.0),
(NULL , NEW.channel_id, 1, 23, 0.0),
(NULL , NEW.channel_id, 1, 24, 0.0);

INSERT INTO template_table VALUES (1,'Default template',NEW.channel_id);
END;

|
DELIMITER ;


Btw these links should help you get started if you are also new to triggers...

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html
http://www.digitalpropulsion.org/Programming/Triggers_in_MySQL_5_0

Saturday, August 2, 2008

Positioning div tables in center

Sometimes tables gives pain in the neck compared to divs. I needed to replace a table made with rounded corners using images to be replaced by a div tag because dojo Tree widget start going woo hoo with the table. Thus I created a table with rounded corners which got rid of problems with tree widget. But initially I couldn't center the table as there were no css attribute to center the div element. If you know the width of the div you are messing with there is a way to do this using css without the use of javascript!
So if you come across a situation to center the table horizontally here is the style to do it
#centered{
position: relative;
left: 50%;
width:600px;
margin-left:-300px;
}

Convocation

Finally we graduated! :). General convocation for University of Moratuwa for degrees completed from last years convocation was held at BMICH (as always) with presence of Chancellor and other academia on 25th June 2008. Here some of the pictures taken from my phone and Sithara's Camera. Gee that GHOST suite was funny!! :)


Communicasia Singapore from June 17-20


I got the opportunity to be at Communicasia 2008 which was held at Expo, Singapore. I together with Niranjan, and Shehan were there representing the company. Communicasia is regarded as one of the largest exhibitions in the telecommunication domain in our region. We left Sri Lanka from BIA on 17th Morning and was at Changi International Airport, Singapore by 6.30 am local time. We were staying at Golden Land Mark Hotel.


In Singapore almost all the things are defined. So nothing to worry about. If you get into a taxi they are all metered and have the rates written down in shutters. So nobody can cheat. But fairs are little high :). Also there are sign boards to get to anywhere and if you are thinking about violating any signs better have some money with you, as fines are quite high!




Golden Landmark hotel was little far away from Expo where exhibition was at. So we usually took the train from Bugis to Expo, via Tenah Merah interchange. Train service in Singapore known at MRT is quite efficient and cheap compared to Taxis. Ticketing system is completely automated and train service was nothing but great.

At the exhibition there were many leading vendors for telecom software and hardware as well as handset vendors. Exhibition halls were huge and there were about 4 of them. You could imagine the trouble of walking though all of them! It took us 3 days to cover most of them. Some of the coolest things that we came across was jeep mounted satellite disk and 3D tv. You can see some pics below

Wednesday, July 23, 2008

Customizing dojo DateTextBox

Sometimes things aint that easy when you really want to get something done in your way. I too felt like that when I wanted dijit.form.DateTextBox to display date in format dd-mm-yyyy. Many talked about using right locale. But I was not concerned about any locales but the format I wanted to get. So here is how you do it in dojo.
<input  id="date" 
value="2008-12-01"
dojoType="dijit.form.DateTextBox"
constraints="{datePattern:'dd-MM-yyyy'}"
invalidMessage="Invalid date dd-mm-yyyy"
promptMessage="dd-mm-yyyy"
/>

Tuesday, June 24, 2008

Understanding JSON

Some pple get scared when they see strange words like JSON. But if you take a closer look they are nothing ;). So here is a basic guide for JSON. JSON stands for JavaScript Object Notation. Also remember there is no "A" in between J and S ;P.
Here is a simple JSON object
{name:'Dilan'}

There is another way to write this
{'name':'Dilan'}

Both are same. Then how do we use JSON in javascript? Answer is pretty simple... here it is..
var person={'name':'Dilan'};
alert(person.name);

Done! That is it. Wait a sec how about if a person have many interests.. that needed to be represented in an array.. ok! here we go
var person = {'name':'Dilan', 'interests':['watch movies','play crickets','code']}

who la! We are done! So this should be a good foundation for you to start! Next time when your fellow developer or interview board ask for a JSON don't freak out! Just hit them back with a good example! cheers!!!

Assigning values to vars in Dojo

In dojo you can populate vars by using below syntax. Here continentStore is populated using countries.json file, method using is dojo.data.ItemFileReadStore.

<div dojoType="dojo.data.ItemFileReadStore" jsId="continentStore"
url="../tests/_data/countries.json"></div>


I have come across situations where I wanted to get this values assigned to just plain variables without using divs and dojoType etc. So this is how we do it.
var waveTreeDataSource = new dojo.data.ItemFileReadStore( {
data:{ identifier: 'name',
label: 'name',
items: [
{ name:'XXX', type:'media',
children:[{name:'A2P',children:[{name:'MCA'},{name:'Forex'}]},
{name:'P2P'}]},
{ name:'YYY' , type:'media',
children:[{_reference:'Test'},]},
{ name:'Test', type:'person', children:[{name:'test'}] },
{ name:'Dilan', type:'person'},
{ name:'Anuruddha', type: 'person'},
{ name:'KD', type: 'person'}
]
}
});

Just remember that we need to include same data structure in JSON file but we have to include it as object with data attribute as shown above. For more information take look at API documentation for dojo.data.ItemFileReadStore.

Monday, June 23, 2008

Eclipse - Ant View

Most of the time we prefer writing custom build scripts in ant for eclipse projects. But when we want to build/deploy project we will open that file and view the outline view to select the action we want to select and then right click on that action and build.. This is a tedious process if you need to build and deploy over and over again. But recently I have notices that there is another view that can have ant view so that we can double click on an action(deploy/build,etc) and make it work without having to go to the ant build file.
To enable that in eclipse all we have to do is go to Windows-> Show View -> Ant and click on it. Then you will see ant icon is left side dock area. Click on that to open ant window. Then right click on ant window body and select add build file. Select the build file from the project folder and who la! You have a ant view where you can double click and action to invoke it!
This looks confusing if you don't know what I'm talking about.. But if you are working on a spring project in eclipse I'm pretty sure that you know what I'm talking about! ;)

How to write blogs..

Well I must say that I'm not experienced blogger. But recently I have noticed that we take lot of time to get prepared to write blogs and end up writing nothing... So from now onwards, I thought of just writing on what I'm doing and problems that I encounter day today and How I overcome those stuff... Also I ask you(my friends) to do the same so that I can learn from them too...

Getting help for Dojo

Dojo is one of the best javascript toolkits. I would recommend it to anyone who want to try feature rich and robust toolkit. It is the most complete toolkit that comes with a liberal licensing scheme. Even though dojo is such an wonderful toolkit sometimes ppl find little difficult to find help related to dojo. Except for the fact that is has a wonderful getting started tutorial at dojotoolkit.org, all the other information are hidden and little difficult to find. So here I'm mentioning some of the information sources that may be useful to you.
1. http://dojotoolkit.org/
2. http://dojocampus.org/
3. http://sitepen.com/
4. IRC channle #dojo

Note that API , documentation and forums are available in dojotoolkit.org. Dojo campus contain more comprehensive tutorials and podcast for some important topics, etc. Sitepen has a brilliant blog which has more to the point information regarding features. Also IRC channels can be used to get in touch with most of the developers.

Saturday, June 14, 2008

Sampath Bank - Leaps ahead in customer satisfaction


Last week I was trying to increase the credit limit of my Sampath Bank credit card. I called over to bank and informed them my requirement. Then I had to write a letter of request and fax it to the bank. As soon as they got the fax, I've got not just credit limit increase but also upgrade from Silver card to Gold. My new gold card was ready 2 days after that.

Yesteryday I went to collect the card from Sampath Bank HQ at Sir James Peiris Mw, since it's the closest to my office :). When I signed the card, it happens to be that I have signed while it was upside down. I was so curious why they would mind that! According to the bank it's general practice to verify the sign with card with proper side up! If you signed it upside down store might reject you or worse you might get charged for credit card frauds. Since it would cause problems they wanted to issue another card instead of it. But I was worried that it will take sometimes(another 2 days may be). But to my amazement they said they can issue another card in 2 hours! It was SUPER FAST! I must admit that I'm really impressed with the type of service offered by Sampath Bank and would recommend everyone to get the same treat!

Tuesday, June 10, 2008

GIT - A bad choice for enterprise

While surfing around the Better Explained site, I happens to see a article which introduce users to the distributed version controlling (DVCS). At the end of the article there was video on youtube which happens to be a session on Git by Linus Torvalds for Google. It drew my attention and I actually watched it all the way through. Linus being a inspiring speaker is one thing but his version controlling thing, as in my opinion is not yet ready for a production companies. One the arguments he brings up in the session is that git allows open source to get over with it's politics of committer access. That is a valid point, having being able to have your own repository avoid having monarchy style control of a project. But this is not valid for enterprises who always want to have an upper hand on things. Also even though branching may be more smoother in DVCS, other troubles like lack on central control (even though we can mimic this) is not going to attract many enterprises soon to use DVCS.
Btw I'm not saying that SVN or CVS is better than Git but I think we need something that has better centralized control and have better merging support!

Wednesday, June 4, 2008

Spring turorial

After some time I decided to update little bit on what I'm doing these days. Well i've been messing up with spring mvc and spring web flow(SWF). Still i' m not very confortable with SWF. But I thought it would be nice to dissipate some knowledge on what is spring mvc and how you can use it. Before I start I must admit that I'm also new to this field, so what I'll be telling might not be accurate as some experts. :). So from today onwards I'm going to walk you though the concepts of spring (possibly with some tutorials).
So what is spring framework? Well it's another java framework which has lot of libraries and stuff... Probable reasons why u should use any framework is due to the fact that you can use already solved design patterns when u use them. WOW that was not so clear ;)! wait a sec... what is design pattern...well... design pattern is a basically a solution that is given for a well identified problem. So if you happen to encounter that same problem while developing what ever you develop you can use the solution for that design pattern to get over with it. (But you might need to customize depending on your exact requirement).
So where were we.... aha.. frameworks..spring framework... So basically we are using a framework to make our lives easier.....
I like spring framework because it has a great web framework under spring mvc and also support things like aspect oriented programming ...
I guess that is enough for this post.. I will be posting second post soon.. till then you can search buzz words.. spring, mvc, aspect oriented programming, framework, design patterns

Thursday, May 29, 2008

JSP problem

I've found a strange problem while trying the create a class called Test, was compiled and placed in WEB-INF/classes of my web root and wen I tried to access it from the index.jsp page like <% Test t = new Test(); out.print(t.getString()); %>. It doesn't seems to work. This is my class.
public Test{
public Test(){}
public getString(){
return "It's working";
}
}

I tried with different different stuff... for example I tried <%@ page import="Test" %>. It didn't work :(. But this worked when I put the Test file in a package called test.(Thus WEB-INF/classes/test/Test.class). Anyway I'm curious why it didn't work in first place. I always restarted the Tomcat(5.5/windows) when ever I made a change. Also I even tried with deleting catalina every and each time. Nothing worked for me... Hope someone knew :(

Wednesday, April 9, 2008

Eclipse for Spring



I've been trying to decide which IDE is better for spring framework related development. After a brief study I decided to go with Eclipse. Because it's light weight, feature rich and easy to use.
So if you are new to eclipse and want to download and install it to be used as a development environment for your project(with spring support). Here is what you got to do.... Get Eclise IDE for Java EE Developers from http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/europa/winter/eclipse-jee-europa-winter-win32.zip

Then follow the install guide for spring ide from here.
http://springide.org/project/wiki/SpringideInstall

Converting javascript string to int

Well it seems sometimes good to know all the basics before you go and do something. But most of the time people won't understand the basics until they come across a problem because of not knowing the basics. I'm these days working on a code base, where original developer no longer available. Time to time I get funny error. Yesterday when we checked interfaces after sometimes, I noticed that date is in correct. Actually it showed 1st of April! It worked fine last month!
So had to dig down to the code base and start debugging. Finally I figured out that it was a error due to Javascript string to int conversion. Consider these examples.
  1. parseInt('08',10)  // 8
  2. parseInt('8',8)    // 0 
  3. parseInt('08')     // 0
In our case, developer had used 3rd method where as he should have used first! Below is a total list of examples extracted from http://www.kourbatov.com/faq/convert2.htm

  1. parseInt('123.45')  // 123
  2. parseInt('77')      // 77
  3. parseInt('077',10)  // 77
  4. parseInt('77',8)    // 63  (= 7 + 7*8)
  5. parseInt('077')     // 63  (= 7 + 7*8)
  6. parseInt('77',16)   // 119 (= 7 + 7*16)
  7. parseInt('0x77')    // 119 (= 7 + 7*16)
  8. parseInt('099')     // 0 (9 is not an octal digit)
  9. parseInt('99',8)    // 0 or NaN, depending on the platform
  10. parseInt('0.1e6')   // 0
  11. parseInt('ZZ',36)   // 1295 (= 35 + 35*36)

Thursday, April 3, 2008

Do not do this with SVN!!

I had same copy of code at 2 locations in svn. I checked out one version(say A) and edited. And wanted to put the same copy to the other version(say B). So I checked out from B to another location and copied the working copy from A to B. And i started working on B. I committed... checked out.... no problems were detected until I checked out the code for a deployment from svn version of B. It was not update!!!
Guess what? As I copied version working copy of A to B. All the svn files came with A.
So I've been working inside a B svn copy but actually committing them to svn copy of A.

So if you ever wanted to update one svn copy to match another. Use export to export latest code and then copy them back to not up to date svn checkout!!!

Awk

Awk is a great tool if you are into shell scripts! If you are interested here are some links that might help you get started
http://www.vectorsite.net/tsawk_1.html#m2
http://www.uga.edu/~ucns/wsg/unix/awk/

Shell script problem

I wanted to split a string in shell array of the from 2008032800 to something like 2008 03 28 00. But as it seems this is extremely difficult to do using shell scripts! I tried in vain using grep and cut :'(
This is as close as I got
echo "2008032800" | grep "^.\{2\}"

Interestingly grep when match a part of a string, it continues to rip it off from the original text and remaining part is used again to match the regex! I wonder whether that is the correct thing to do!

Wednesday, April 2, 2008

All about laptop batteries...

Laptop batteries can create nice little headaches if we don't really pay attention to how they react to some of the things we do. For example you might think that charging battery full and then allowing it to discharge operating from battery alone once in a while, has nothing to do with life time of the battery. Believe it or not it's true. Actually it's being said that, doing so twice a month is required for battery. Also NEVER allow your Li/Ion battery to be at 100% charged and A/C plugged on (still charging..) . I'll tell you from the experience it'll cost you more than you expected if you do so.
So in a nutshell this is what you need to do to maximum your battery life...
1. Charge battery to 96-98% then disconnect a/c adapter and allow it to discharge maximum possible (3-5%) then charge again!
2. Make sure you charge 100% and discharge to 0% once in a month
3. Don't expose batteries to heat! it reduce battery life time.
4. If you are not using battery for long period (like weeks) remove your battery from laptop and keep it separate.
5. Do not ever discharge a battery using a method other than using laptop!

That is all about batteries that I got to know last few weeks! Hope this will help you to get the maximum out of your laptop battery. Finally if your battery is good as dead and can't find a cheap replacement look at ebay! I will give you more information on finding a replacement battery soon!

Evolution for Windows Users

As predicted by Gav, Evolution + Lighting is problematic. For example I can view the calendar objects sent via Outlook, but can't accept them.... So here I have found a windows version of the Evolution... hope it's useful for those who need a free mail client for windows

http://sourceforge.net/project/showfiles.php?group_id=159440&package_id=194380&release_id=492523

Getting calendar support for thunderbird


I've been receiving so many calendar objects from Outlook people recently and unfortunately I was not able to read any of them as it seems total junk in my Thunderbird client. So today I decided something had to be done about this. After few seconds of Googling I found a nice extension called "Mozilla Lightning" to get the job done. If you have the same problem here is the link to the solution
https://addons.mozilla.org/en-US/thunderbird/addon/2313

Tuesday, April 1, 2008

Wow it's tech time

Finally I've decided to talk abt the technical matters that I encounter every day and how I got them solved through a blog. Since my personal blog http://dilanspersonalblog.blogspot.com doesn't allow the tech stuff as it's personal, this will be my new home for technical discussions. Also all of you are welcomed to make any comments regarding the posts. See ya soon with the first technical post.......... :)

Monday, March 31, 2008

Yajith's party @ Queens Cafe - Duplication Rd




Yajith with many reasons decided to throw us a party someday in Feb. As a part of the it ,he gave us the opportunity to play pool. Honestly I don't nothing about this game and even not sure abt it's name. All I knew was that I had to take a stick and hit the white ball. As *they* say all that followed was history!!! :)

Here are photos....

Martin Wickramasigha folk museum








Just off Koggala free trade zone from the Galle side, in front of Fortress Hotel you can find the Martin Wickramasinghe Folk Museum. It is quite wonderfully built in a really wonderful environment. Cost of a ticket as I remember is about Rs. 40, which is quite cheap and there are quite lot of things to watch.
Actually it will take about 4 hours to cover all the things. It's open 6 days a week and only closed on Mondays. Based around the life and environment talked in the books of Martin Wickramasinghe, the museum will give a brief insight into the life at that time. In my view this is a must visit! Here are some photos....






Visits to lamda's home

Wow!! it was once again a marvelous trip to far far away to City of Kekanudura. As usual Lamda and Banda had arranged a dedicated Langama bus for the trip. Journey was nothing but filled with the trill and excitement. I'll leave comment about the food and bus ride to Sibba, and Gav. Here are the photos...

Wednesday, February 27, 2008

First class party at Dinemor(e)

It was great moment at our boarding considering that all of us got first classes... We 6 together with Manosha went to Dinemor(e), Colpetty to celebrate the first class... Here are some photos of that event...

WaveNET outing

Again in a day in January... oh... it was a holiday in January which we had our company outing to Blue Waters(TBW), Wadduwa. To get to TBW, you will have to get down from Talpitiya Junction which is one halt away from the Panadura-Wadduwa border bridge if you are coming from Panadura or about 2km from Wadduwa Junction. Abt the hotel... environment is great.. pool is nice.. and beautifull.. overall setting is great.... food seems ok.. And I don't know about the charges.. but it got to be little high.. ;)
We had loads of fun that day particularly playing what is called water polo which was ultimately named water rugby after few sessions of play. Also we had some small fun events in the morning prior to the fun we had at the pool. Here are some of the photos that were taken from my phone... and there are many which I can't upload... may be I will upload some later...

RMS from my w810i

These are some of the events that I captured from my phone while listening to Stallman's legacy leacture of Free Software. Also I saw an interesting thing just after the lecture from at the SLIIT. That is one of the laptops from One Laptop For Child project. It was really interesting except for the fact that person who was using is so keen on showing his colors to the gathered crowd. :D. Some of the below moments include RMS enjoying a Quality Tea from Sri Lanka.(damn dude we make best tea in the world - Ceylon tea). Section of the crowd and RMS in his priest kit!

Saturday, January 19, 2008

RMS visit Sri Lanka


Founder of free software foundation, writer of GPL license and a world renovened speaker Richard Matthews Stallman is currently in Sri Lanka as invitee from ICTA, Sri Lanka. I was there at SLIIT auditorium to witness his usual lecture on free software. Also as sub topics he discussed job opportunities with free software/business model and free software at education.

RMS as always was very critical about non free software and also emphasized the importants of freedom in the software referring to his 4 freedoms. Also as always he complain Linux systems clouding the work of GNU project by not mentioning it as GNU/Linux system.


New things that I learned from this speech is how the GNU name came into play. As he said at the time of the naming there was a trend for recursive acronyms. Specially with Emacs where there were lot of acronyms like EINE ("EINE Is Not Emacs") and ZWEI ("ZWEI Was EINE Initially"). Since the new operating system he's trying to make is similar to unix but Not Unix, the last two letters of the acronym was fixed with _NU. All what he did was replace letters starting from A to G.. ANU, BNU, CNU, DNU, ENU, HNU and Finally GNU. GNU is both funny and catchy was selected!
Also he said that Open source and Free Software different from the fundamental concepts. OSS believe in reliable working software where are FS believes in freedom of the software.