Google Adsense gets nice look and feel with Google Account

Seems Google has started integrating Google Adsense with Google Account. We believe this as a good step since it makes life easier, login to only one account but have many services working. Previously Google did this with Blogger as well. New login page is very nice and colorful. New login page looks as below.


Currently the two old and new login pages can be accessed using two different URLs, but this will be changed very soon.
Old login page: www.google.com/adsense/login3
New login page: www.google.com/adsense/login/

Artificial Intelligence and BASIC

When I was 13 or so years old I bought a book at You-Do-It Electronics titled Experiments in Artificial Intelligence for Small Computers, authored by John Krutch. This book influenced me in important ways. It teaches the essentials of AI so anyone could understand it. Examples are presented in the BASIC programming language. One of the examples presented is of the classic Eliza sort of conversational system. Not cutting edge research, but as a starter it gets the job done.

I was able to use the techniques in the book to create demos for the computers at NEECO. A person visiting the store would ask the computer about itself, and the computer would try and respond appropriately with a demonstration of features.

The book can still be purchased used on Amazon.

Sri Lanka through to World cup finals playing against 11 or 13?

Today is a special day for Sri Lankans as SL made their way to finals in World Cup 2007 after the semi final victory over New Zealand yesterday. That was a fantastic match even though it was hard to judge whether SL were playing against 13, not just 11 players. SL was playing against 11 friendly and claim NZ players (and 2 slightly unfair professional umpires).

Interesting point was both the 2 umpires, RE Koertzen (South Africa) and SJA Taufel (Australia) made poor LBW decisions against SL. One LBW was given for a thick edge and the other for a ball going far away from the leg stump. When NZs were batting, umpire RE Koertzen warned Dilhara twice putting him under huge pressure. Another a tough LBW decision was given against Rose Tailer for a ball slightly missing the stumps. We can not guess why such experienced umpires give that much bad decisions in crucial matches like semi finals.

Even with that type of a situation, SL team came up brilliantly in batting, balling as well as fielding. NZ got the wicket of SL inform batsman Sanath Jayasuriya pretty early putting SL under pressure. But SL came back strongly with Upul Tharanga's 70 followed by the superb captains knock of 115* by Mahela Jayawardana. SL scored over 100 runs in the last 10 overs. In the NZ innings, it was just a series of perfect bowling to get them all out for 208 runs. My deepest sympathies to all the New Zealanders.

We were discussing about the match here (before the match). Congratulations Sri Lanka and all the very best wishes for the coming finals to bring the World Cup here again.

Missing the Point

I read a paper the other day that described a system for teaching kids programming. It was one of those robot simulations where the student learns programming by using a special mini-language to teach an on-screen robot to accomplish certain goals.

So in this case the language in question is a simple one, specialized for the robot ideas as a gentle way to introduce programming.

Later in the same paper they described how a newer version of the system switched to Java as the language for the robot. I am amazed how easily people are brainwashed into using the popular thing in place of the right thing. Instead of something simple use the "industry standard" language, no matter how much it might damage their minds. :-/

What would be better? I guess the robot language they were using before would be just fine. Or pick some other simple language if you're looking for mindshare. BASIC, LOGO, Forth, Smalltalk.

World Cup Semi final on 24th: Sri Lanka vs New Zealands

Tomorrow (2007-04-24) is going to be a big big day for both Sri Lanka and New Zealand. Two teams meet each other in a crucial match, semi finals. In recent past, SL have done well against New Zealand. They once met in the super eight matches and Sri Lanka won comprehensively by 6 wickets.

According to news, the pitch at Sabina Park in Jamaica will have some bounce. This is said to be favoring NZs because SLs have much experiences on subcontinent wickets. But having the best balling department, SLs will be able to get the benefit of the bounce as well.

A quick comparison over the two teams

1. Captaincy:
Stephen Fleming, the New Zealand captain has more experience and is a good leading captain. But Mahela Jayawardane is one of the best positive captains in the world who has shown much colors in a lesser number of matches. So I weight SL has a good captaincy.

2. Balling attack:
NZ comes with one of the best ballers in the world, Shane Bond. But SL goes with 4 high class ballers: Vaas, Murali, Sanath and impressive Malinga. So SL has a huge advantage.

3. Batting:
NZ has a good batting line up starting with their captain, Fleming and following with Oram, Styris, McMillan and McCullum. SL comes with Sanath Jayasuriya (World's best batsman who frightens the opposite), following Sangakkara, Mahela, Chamara and Dilshan. So seems both have good batting attack. But it's a matter of getting some of them to show their class.

4. Fielding:
NZ is doing well of fielding, but they are not up to the level as much as SL. SL are putting huge pressure on the opposition by a showing a good team effort at the ground.

These are some comparisons, but the team that play as one unit and perform best will defeat the other. This is the first time NZ plays for a semi final in a world cup. So it will be a huge game for them.

But still I believe SL will beat NZ and go for the big final on 28th.

All the best wishes for SL from me and all the SL lovers. (Hope you are also joining with me to wish SL).

BASIC Contributed to Success of Industry

It seems to me that BASIC was one of the reasons for the success of the early microcomputer business. I get so many emails from people who:
  • bought a computer twenty or thirty years ago
  • learned BASIC and did fun and productive things
  • migrated to Microsoft Windows when it became the defacto standard OS
  • found Windows programming languages to be too hard
  • stopped programming for a LONG time
  • stumbled across Liberty BASIC http://www.libertybasic.com
  • started programming again in earnest!

The remarkable thing to me is that Liberty BASIC isn't as simple as the original BASIC interpreters were, but it is still so much easier than VB or Java that it serves as an acceptable gateway back into computing for so many people.

Open and read any file in a .war file of a web application with Java

Question: How can I open and read a file inside a war file of a web application?



Answer: InputStream can be used for this with a ClassLoader.




A code snippet for opening a file from Java for reading a file inside a web application is listed below. Commented line (InputStream inputStream = new FileInputStream(filePath);) shows the common approach used in non-web applications. Common approach is not usable with web applications (.war file) since it fails to find the files. Even though the correct relative path is provided, programs will face issues depending on the web server versions.





For web applications, the InputStream will be created using a ClassLoader. Following code snippet can be used for this requirement. But this approach has one limitation. This can read only the files inside WEB-INF/classes folder.
import java.io.InputStream;

public class WebAppFileReader {

public static void main(String[] args) throws Exception {

// full path: "C://projects//myWeb//WebRoot//WEB-INF//classes//testFile.txt";

String filePath = "testFile.txt";



// InputStream inputStream = new FileInputStream(filePath);

InputStream inputStream = WebAppFileReader.class.getClassLoader()

.getResourceAsStream(filePath);


int size = 10;

byte chars[] = new byte[size];

inputStream.read(chars);

String str = "";

for (int i = 0; i < size; i++) {

str += (char) chars[i];

}

System.out.println(str);

....

}

}


Note that only one change has to be made to make it read the files inside a web application. This is highlighted below.

1. InputStream inputStream = new FileInputStream(filePath);

2. InputStream inputStream = WebAppFileReader.class.getClassLoader()

.getResourceAsStream(filePath);



By replacing line #1 with #2, a class to read files of a web application is created. One important point to note is: WebAppFileReader is the name of the class in which these codes will be written. So if a different class is used with these code snippet, keep in mind to alter this line and add the class name of that.



Hope this will help you.

BASIC versus RoR?

Someone posed the question recently about how Run BASIC http://www.runbasic.com will stack up against Ruby on Rails. I think the question was meant primarily about performance. This is really an apples to oranges comparison because Run BASIC isn't meant to be a scripting language.

While I don't doubt that some people will use Run BASIC to create commercial sites, this is not the focus we are pursuing. Instead we are creating a tool for the traditional users of BASIC. If you want to learn or teach programming, if you want to create web apps for your use at home (or on your iPhone!), or if you need a custom application at the office and the IT folks and programmers are too busy to build it for you then Run BASIC is designed for you. :-)

Coming back to performance, the processing of large web applications is bottlenecked at the database. A Run BASIC front end to a database will perform similarly to other languages like Perl, Ruby, etc.

Implicitly defined class members

There are quite a few members that you can get implictly with your class. But only when you show the compiler a need for them. They are :

1. Default (zero-argument) constructor
2. Copy constructor
3. Assignment operator
4. Destructor
5. A pair of 'address-of' operators

Note that, if you define the copy constructor for your class, you don't get the default constructor. See details here : What members of a class are implicitly defined?

Good luck!

Bye!

Free New, Delete Malloc

On numerous ocassions have I found people making mistakes in usage of the memory allocation routines acceptable to C++. Primarily between new, delete and malloc, free (and not to mention the array forms of new and delete).

A mistake can be very dangerous from a memory leak to undefined behavior that may make your computer dissappear! :D Of course, I am kidding but it is still dangerous.

Take a look at this FAQ entry that I posted on Codeguru regarding the topic - C++ Memory Management : What is the difference between malloc/free and new/delete?

Hope you find it useful.

Take care!

C++ or ++C (read i++ or ++i)

Pre-increment and post-increment : achieve "almost" the same end result with a little difference. It is always adviced to use the pre-increment form in expressions where you do not care what value the expression ought to use - the new incremented one or the older value prior to increment. Also when it matters, if you need the former then use the pre-increment form and if the latter use the post-increment form. That is the basic difference.

The post increment form has a drawback of generating a temporary (yeah, that can be optimized by the optimizer but still).

To understand the difference and when to use which form, you may find this Codeguru FAQ entry quite helping : C++ Operator: Why should I use '++i' instead of 'i++'?

Have fun!

Operator overloading basics

It is quite true that operator overloading looks such a big deal for beginners. I had my problems with that as well when I started with C++ and kept ignoring it considering it to be a complex thingie. But I tell you it is not. For an initial introduction to it, you may find this Codeguru FAQ entry quite useful : C++ Operator: How to deal with operator overloading?

Hope you find it interesting and easy to follow.

Keep rocking! Cheers!

Cricket: Sri Lanka won by two runs over England in World Cup 2007


Sri Lanka vs England super 8 match was on 2007-04-04. They played an amazing match, it was the best game so far in this World Cup. Even that was one of the greatest matches I ever had watched.

Sri Lankans were all out for just 235 runs causing many discussions to calculate how many runs should have been added to make it a winnable score. Then England started batting, but they were 12/2 after 6 overs.

Over 20: Englands were in a comfortable situation, 100/2 with a RRR(required run rate) of 5.4. But this was easily reachable as Pietersen was batting impressively putting Sri Lankans under pressure.

Over 34: Pressure on Englands. They were 134/6, with a RRR of 6.4. And Sri Lankans needed only one wicket two celebrate the tail enders' fun. And England fans were dead silent.

Over 46: But that required wicket didn't fell and England batsman were rotating the strike well and they were 217/6 with a RRR of 9.5. But this was easily reachable as both the batsman were well established. It was just 19 runs from 12 balls.

Sri Lankans were under huge pressure, two more overs to go. Who should ball the late two overs?

Over 49: Lasith Malinga called for the 49th over. Big task for young Malinga.
1 1 0 1 W 4
This is a fantastic over. Malinga got the needed break through, but the last ball went for a four.

Over 50: Last over, 6 balls more to go, needs 12 runs. Who should ball the last 6 balls? Chaminda Vaas had two more overs, Sanath Jayasuriya had two more... No no it was Dilhara Fernando to ball the last over.
49.1 - 1 run
49.2 - 4 runs
49.3 - 2
49.4 - 1
49.5 - 1

Just 3 runs from the last ball, the well set batsman Bopara was facing. Dilhara came to ball the last ball, but stopped at the last second. Crowd get confused!!! He came back again, and balled him!
Oh! Dilhara balled him! Can you believe it? Sri Lanka won the match just by 2 runs.

What a fantastic game? You should have watched it.

Congratulations Sri Lanka.

Check out this stream