Thursday, November 29, 2007

Google BAdSense

Google AdSense is buggy. I've tried signing up using my existing GMail account and it replies with "a user with the specified email address already exists". Of course it does exist, what do you think an existing Google account means?

Anyway, I'm as interested in placing ads on my site yet since I don't receive a lot of traffic. Perhaps when I get the traffic to make something on the side to help pay for Internet connectivity costs.

Downgrading from Windows Vista to XP

The firm I work at just ordered 10 new desktop PCs pre-installed with Windows XP to replace the PCs running Windows Vista. I guess this one is a first - replacing a newer version of an Operating System with an older version.

Saturday, November 24, 2007

Top 'n' SQL Query

The Top 'n' SQL Query is a common interview question and I've asked it a couple of times to fresh graduates who couldn't answer it - some didn't even know about the existence of the MAX group function.

I'm pretty sure everyone is familiar with the Oracle-specific statement:
SELECT sal FROM (
SELECT sal FROM mytable ORDER BY sal DESC
) WHERE ROWNUM < 10;

MySQL (and PostgreSQL) is pretty similar where you use a:
SELECT sal FROM mytable LIMIT 10;

With Microsoft SQL Server, you can use the SET ROWCOUNT 10 (Sybase supports this too) before executing a query to return ordered rows and this approach is similar to the MySQL approach. You can also use the TOP keyword (Firebird uses the FIRST keyword instead of the TOP keyword) as follows:
SELECT TOP 10 sal FROM mytable;
The TOP keyword also support the PERCENT keyword after the number, making it more flexible.

Also, with Microsoft SQL Server, you can use a ROW_NUMBER() OVER (ORDER BY column_name) to provide something similar to the ROWNUM pseudocolumn in Oracle. RANK is used similar to ROW_NUMBER, except that RANK supports the use of PARTITION BY (optional) in addition to ORDER BY.

I think an ANSI compliant statement that works across all databases would be something like this:
SELECT sal FROM mytable a WHERE 10 > (
SELECT COUNT(1) FROM mytable b
where b.sal > a.sal
)
ORDER BY sal DESC;

I think a more challenging question for a beginner would be to return the next highest after the Top 'n'. I think I'll save that for the time I'm interviewing experienced job applicants.

New PHP, No IMAP

I got PHP 5.2.5 compiled on my system with a new shiny Apache too. I started off with an old version of CURL so it didn't work. I then got the new version of CURL and it worked! I decided to get IMAP working by trying both the 2006 and the earlier versions, but neither work - the compilation stops due to a variable name conflict. I'm not sure if the 2007 release is stable, but I'll give it a shot.

Anyway, I'll probably just have to go without IMAP till someone decides to work on the source code and come up with a new release.

Saturday, November 17, 2007

NAnt ...a short introduction by Nitin Reddy Katkam

What is NAnt?

NAnt is a tool used to compile source code without using an IDE. It is a command-line utility and runs with instructions written in XML. With the ability to perform most compilation tasks and to execute commands, just as shell scripts do, NAnt makes a useful addition to the tools used by any large .NET software project. NAnt is actually a .NET version of the popular Apache Ant for Java.

Getting Started

If you would like to install NAnt, you can download the binaries required from: http://sourceforge.net/project/showfiles.php?group_id=31650

Compilation directives can be provided in the instruction file by either explicitly specifying the source files or by specifying the solution file from which all details required for compilation can be obtained. You can override solution settings by excluding projects from a solution.

You can find a sample build instruction file at: http://nant.sourceforge.net/release/latest/help/fundamentals/buildfiles.html

How does NAnt work?

NAnt follows the 'build target' concept from Make that allows you to perform a sequence of steps by providing a parameter; if no parameter is found, the default target specified is built. As is the case with makefile, NAnt can run without any parameters by looking for an instruction file in the current directory; for NAnt, the instruction file ends with a .build extension.

The command line parameters you can provide are: , -buildfile:, -D:=

Reference

For reference, you will probably want to start off with looking at the tasks that you can provide to NAnt at: http://nant.sourceforge.net/release/latest/help/tasks/index.html

You can get more at: http://nant.sourceforge.net/release/latest/help/

Additional Notes


When you build a project, NAnt compares the timestamp of the source code with that of the executables and only compiles if the timestamp of the source code is newer.

Friday, November 16, 2007

Unreal Tournament 2004 Rocks

I've been gaming lately. With a new copy of Unreal Tournament 2004, I decided to kill a couple of hours and have some fun. The game is revolutionary when it comes to team games. You can right vehicles with the truck being my favorite of the lot and you can have teammates shoot while you drive, or the other way round. There's also a tank that can take quite a lot of beating and turrents to defend the bases/camps. The graphics are not that great and gameplay may take a while to get used to, but once you're hooked, it's addictive, particularly the ability to have a voice chat with other players while in battle.

Wednesday, November 14, 2007

The MVC Pattern

The Model-View-Controller pattern is the most commonly used pattern for software development, after the N-tiered model. In the MVC pattern, the model is responsible for managing data. It's state is accessed by the view and mutated by the controller. The sole function of the view is to display data to the user. The controller is responsible for reacting to triggers from the user, for changing the state of the model, and for updating the view. Both the controller and the view are dependent on the model; however, the model is independent of both the controller and the view.

There are two variants of the MVC - the passive model, in which the model does not notify the view of any changes to it's state, and the active model, in which the model notifies the view of changes to it's state usually via the observer pattern.

The 3-tier architecture differs from the MVC in that there is a strict separation between the three layers, which prevents the top layer from communicating with the bottom layer. In the MVC, the model can notify the view of changes to it's state.

A pretty good diagram of the MVC can be found here:
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/images/app-archa2.gif