Saturday, December 29, 2007

VarArgs in Java 5

Introduced in Tiger (Java 1.5.0), variable arguments enables Java methods to accept a variable (0..*) number of arguments thus allowing users greater flexibility in passing calling methods, previously dealt with using arrays.

The last parameter in the list is defined with a "type ... variable_name" syntax (note the ellipsis).

Example:
private static int sum(int ... numbers) {
  int accum = 0;
  for (int i=0; i<numbers.length; i++) {
    accum += numbers[i];
  }
  return accum;
}

Implicit variable declaration in .NET 3.5

In C# 3 and Visual Basic 9, you can declare variables without having to specify the type of the variable. This isn't the same as the variant type in Visual Basic, but rather the compiler's ability to determine the type of the variable from the initialization value.

Here's how it works:
var i = 3; //C#
Dim i = 3 'VB

Using implicit declaration of variables requires you to specify a non-null value since a null only represents the generic object type.

EDIT: You can get the implicit declarations feature in LINQ projects (CTP) with Visual Studio 2005.

Friday, December 28, 2007

Google's 403 for View as HTML


Google is probably having to deal with a load on it's servers this holiday season and so they're restricting access to their "View as HTML" feature. The message displayed is:

We're sorry...

... but your query looks similar to automated requests from a computer virus or spyware application. To protect our users, we can't process your request right now.

We'll restore your access as quickly as possible, so try again soon. In the meantime, if you suspect that your computer or network has been infected, you might want to run a virus checker or spyware remover to make sure that your systems are free of viruses and other spurious software.

We apologize for the inconvenience, and hope we'll see you again on Google.

MacOS X's .DS_Store files

I noticed a couple of .DS_Store files appearing in some of the archives that I've been receiving and recognized them as MacOS X files used for display, much like the Windows thumbs.db (created to store thumbnails of files - check the "Do not cache thumbnails" in Tools > Folder Options > View). I looked up more info and here's what I came across:

Under Macintosh OSX .DS_Store holds the information which controls the way a folder will be opened; i.e., the shape and size of the window, the position of the window on the desktop and whether file, folder or icon view has been selected. If you were to delete the .DS_Store the folder would revert to the system default next time it is opened and a new blank .DS_Store would appear (invisibly).

You can disable the creation of .DS_Store files by MacOS X by running this command from the terminal window: defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Tuesday, December 25, 2007

NetBeans 6.0 bug

Although I'm a fan of NetBeans because it's a simple IDE that runs with limited memory too, I must admit that it is quite buggy. One of the features of NetBeans is that it locks the GUI code so you can't accidentally break the GUI builder. I've tried Borland's JBuilder and breaking the GUI builder with custom code was one of the problems I came across. However, when NetBeans breaks itself, I can't get into the code to change it, which is one of the complaints that I have with the IDE. I wish it had a "hack-the-code" option where I could at least change the variable names - all I did was delete a menubar and add a new menubar... when I went into code view, it still had the old menubar and used the old menubar for the frame - the new one was an unused variable!

Anyway, I guess it's back to Wordpad for me.

Monday, December 24, 2007

Column-oriented vs Relational

Column-oriented databases are the next big thing for data warehouses, having passed through object databases for specialized applications. For a while, InterSystems Cache enjoyed the spotlight as a high performance object database. Now, Vertica is the hottest thing the database world has to offer as a column-oriented database.

Column-oriented databases store column-data as a contiguous sequence, as opposed to relational databases which store row-data in contiguous allocation units. This makes it simpler to make schema changes, and offered better performance for OLAP applications. Relational databases still are the best solution for general purpose OLTP applications so it isn't the end for them yet, although they were architected almost three decades ago.

Sunday, December 23, 2007

VS2008 Express

The Visual Studio 2008 Express offline installer is a corrupt image being offered for download from the Microsoft website. A lot of people have complained about the "Program too big to fit in memory" error so it's yet another bug from infamous Microsoft. It's a free product so no one really cares at this stage, unless they are paying for bandwidth.

Thursday, December 20, 2007

Regex for doesn't contain

^((?!my string).)*$ Is the regular expression for does not contain "my string". Wondering how someone can come up with that? Check out the reference at:
http://www.regular-expressions.info/refadv.html

There's a basic and advanced regular expression reference section so check out both!b

Wednesday, December 19, 2007

Sun Java on Fedora Core 8

There's been a successful install of Sun Java 1.6.0 on Fedora Core 8 with instructions posted at: http://vertito.blogspot.com/2007/11/sun-java-on-fedora-8-install-howto.html

I haven't been able to try it yet, but I'll do so soon.

Tuesday, December 18, 2007

Microsoft's 2008 Platform

Microsoft is releasing Microsoft Windows 2008, Microsoft Visual Studio 2008 and Microsoft SQL Server 2008 at an event on February 27, 2008 7am. It's a pretty major event since it marks the next leap since the 2005 release.

The best feature of the new platform is LINQ, which enables developers to treat data as entities rather than relational tables. It's like taking NHibernate to the next level and integrating it with the programming language.

Monday, December 17, 2007

Sun pushing for NetBeans

Sun is bringing it's IDEs to an end and would be helping it's customers move to NetBeans for development. It's actually a pretty good idea since most of the Java world is pretty much standardizing on either Eclipse or NetBeans. With more of the community shifting to Eclipse, the only reason NetBeans would remain alive is if there are sufficient users working with it.

IP Address Lookup

You can easily get the geographical location for an IP address at http://www.ip-adress.com . It even displays a nice little map, though you shouldn't expect it to be accurate enough to go on a hunt for a hacker with your GPS tracker ;-)

Oracle iSqlPlus

Oracle has a pretty good web based tool for executing queries against the database called iSqlPlus. It is quite similar to Sql*Plus, but is better suited for testers than DBAs. In Sql*Plus, users complained about long lines that would get wrapped, thus messing up the output. Since iSqlPlus works within your browser, it builds an HTML table containing query results with a width just enough to display all the results. It also keeps a history of previously executed statements for the sesson, so you can easily execute a previously executed query.

For a default install of Oracle, you'll generally find iSqlPlus installed at http://localhost:5560/isqlplus . Do add your comments to this post if you've had a chance to use both.

Sunday, December 16, 2007

ProBE

The proxy based estimation method is based on drawing upon previous experience with a similar project to get a rough estimate of the time required for building software. Unlike the wideband delphi method, it relies less on expertise and more on historical data. This technique is commonly applied when comparing projects within a similar domain.

Wideband Delphi

The wideband delphi software estimation technique is actually a process where a group of experts arrive at a consensus based on the Work Breakdown Structure. It's simplicity is one of it's greatest strengths and it relies heavily on the experience of the experts called in to make the decision. If there are large differences in the estimates, they resolve it through further discussion and finally come up with the final numbers.

Wednesday, December 12, 2007

NCover

NCover is a pretty good code coverage tool for .NET. You can use it to determine which parts of your code aren't tested by unit tests, thus letting you know if you need to write more tests.

A common problem identified by code coverage tools is that you have blocks of code that you wouldn't encounter under regular circumstances, such as Exception blocks that are intended to catch unforseen errors or error conditions that occur rarely. Due to insufficient testing for those blocks, you could be releasing some untested code that could result in a bug.

NCover can be run with pretty much any kind of tests - you just need to provide them as parameters to the command line NCover tool or browse to find the executable for the graphical tool so you aren't limited to any single testing framework, such as NUnit.

Sunday, December 9, 2007

Sun Java on Fedora 8 has an issue

Fedora 8 has a buggy libxcb package due to which we get the following error when using Sun Java...

java:scb-slib-c:so:scb_slib_unlock:Assertion 'c->xlib.lock' failed.
Aborted.

You can, however, use the default Java that ships with Fedora 8.

Saturday, December 8, 2007

Upgrade to FC8

Fedora Core 7 was pretty cool when it was released. I showed all the guys and girls at work how it could do better on fancy effects than Windows Vista when you turned on the Desktop Effects and used Gnome. When the launch of Fedora 8 was announced, I just had to go and get myself one of those. I started off by upgrading my desktop at work from Fedora Core 7 to Fedora Core 8 and it seems to do a pretty good job on some counts. I had to upgrade KDE-SVN for it to work, which was just a matter of typing a "yum update kdesvn". The OpenOffice icons from my taskbar are now missing but the documents that I had placed on my desktop now have thumbnails displayed. There's lots more to it, but I guess I'll write more as I come across it.

Friday, December 7, 2007

WSUS

Microsoft has a Windows Server Update Service (WSUS) utility that we can use to download updates and get them installed within the network. It can download updates for different versions Microsoft Windows Operating System. The domain clients have to be setup via Group Policy. For workgroup clients, you would have to make registry changes; see:
http://msmvps.com/blogs/athif/archive/2005/09/14/Manually_Configure_WUA.aspx

To manually search and download Windows updates, you can also use the Microsoft Windows Update Catalog via your browser. Unfortunately, it doesn't list available updates so you can't browse - all it's got is a search box where you can type the update that you're looking for.

Thursday, November 29, 2007

Intel vPro

Intel's vPro is a hardware based management solutions for systems. The benefit of using a hardware based approach is that you do not require the PC to be running and don't even require the Operating System to be started up.

The Altaris Console Management is probably more popular among the vPro-based tools for administration, but you'll find more tools shipped from Avocent, BMC Software, CA, Farstone, Kingsoft, HP OpenView, LANDesk, Medialand, Microsoft SMS, StarSoftComm, and SyAM.

You can also get the Intel AMT developer tools from:
http://softwarecommunity.intel.com/articles/eng/1034.htm

For details from an Altaris Console Management demo, go to:
http://arstechnica.com/articles/paedia/hardware/vpro.ars/2

VS2008 and .NET 3.5 released on 19 Nov 07

Visual Studio 2008 was released on 19th November 2007. The Express editions are available as a free download. .NET 3.5 brings a lot of updates to C# and VB.NET as languages. LINQ is probably the most awaited feature.

For newbies, having Windows Presentation Foundation, Workflow Foundation and Communication Foundation integrated in the IDE is probably the best part.

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

Message Queue Characteristics

Message Queues can be characterized by the following attributes:

Delivery

Guaranteed delivery of messages are provided by persistent queues, which store messages in files or databases. Non-persistent queues store messages in memory and thus message delivery is not guaranteed if the message queue provider fails. A persistent message queue is required to confirm the receipt and receive acknowledgement of the delivery of a message.

Transaction Support

Messages can be grouped together into a transaction, such that either none or all of the messages in the transaction would be processed by the client.

Messaging Models

The two types of domain models or messaging models are Peer-to-peer and Publish-subscribe. In the peer-to-peer model, the message from the queue is received by one recipient after which it is deleted from the queue. In the publish-subscribe model, the publisher sends a message to the queue with a topic and all registered subscribers receive the message.

Durable/Non-durable

A non-durable subscriber can receive messages only if it is connected to the message queue. A durable subscriber can receive unexpired messages after it reconnects to the queue.

Push/Pull Delivery Mechanism

Messages can be delivered by a queue using either a push mechanism where the queue actively sends the messages to the receiver, or a pull mechanism where the receiver polls the queue periodically to check for messages.


Synchronous and Asynchronous messaging

In synchronous messaging, a message isn't stored on a queue while sending, but a direct connection is established to a client where the message is placed on a target queue thus providing real-time delivery.

In asynchronous messaging, the message is placed onto a remote queue and is sent to an intermediary store for delivery to a client.

Virus Killer

While searching for an antivirus to run on Linux, I came across this game called the Virus Killer. In the game, you'll have to protect your files by blasting away the viruses that come crawling from Microsoft Outlook Express, Microsoft Internet Explorer and the Recycle Bin by zapping them with the mouse cursor. It's fun and the game's got a nice theme to it.

Tuesday, November 13, 2007

Auto-update of Windows Service

I was thinking about an developing application to perform an auto-update of a Windows service. In my previous post, I've posted details on controlling a windows service so to add more to it, I could get the path of the EXE from the registry at HKLM-System-CurrentControlSet-Service-[ServiceName]. So, if I could stop the service and replace the executables with a new version of the service, I could create an auto-updater for the service!

Now, if there's a DLL that's being started by svchost.exe, there's a name following the "-k" that represents multiple DLLs. Updating those is a story I'll write about some other time! :-)

My Web Windows Services Console

I've been thinking about working on a tiny web application to remotely start and stop Windows services via a browser and I finally stopped thinking and did something about it. It was remarkably simple with the GridView control and it took a little over fifteen minutes, including the time to chat via IM with a buddy.

I had to include the System.ServiceProcess assembly and calling the System.ServiceProcess.ServiceController.GetServices() method returned an array of System.ServiceProcess.ServiceController. Now, the GetServices method has an overload that takes a machine name but I haven't tried it yet. It probably needs either a Windows domain or some way to authenticate with the other machine - the former I don't have and the latter I can't be bothered with right now.

I added a Start/Stop button and it did actually effect the service, but I had to add an ASP.NET Button to act as a refresh button to actually see the new status of the service due to the time it takes to actually start/stop. I added a two second sleep and tested it against the Windows Time service but that didn't seem to work and I'm guessing I need a longer sleep time.

Anyway, that's as far as I'll build for my little web Windows Services console.

UPDATE: I decided to venture a little further and found the method ServiceController.WaitForStatus that takes in the desired status and timeout as parameters.

Monday, November 12, 2007

Remotely enable remote access

If you've forgotten to enable Remote Desktop on your Windows box and you really need to get in, there's a free bit of software from IntelliAdmin to enable it. Check it out at: http://www.intelliadmin.com/blog/2006/06/remotely-enable-remote-desktop.html

Inflexible ASP.NET Calendar control

The ASP.NET Calendar control forces developers to use Saturdays and Sundays as the weekend. Now, although this may seem insignificant, a lot of developers require a calendar control to display working and non-working days and they need to define these as the 'weekend' days. Also, some parts of the world observe the weekend on Friday and Saturday, or Thursday and Friday, or just Friday.

There is an awkward way - by overriding the DayRender event and resetting the styles for Saturday and Sunday, and applying the styles for the days you want to mark as non-working days.

Either way, when I'm developing a calendar control, I know what I'm going to build into it.

Wednesday, November 7, 2007

The Joys of Distance Interviewing

I'm having a first solo at recruitment and so I asked a co-worker about her experiences at hiring new staff. She mentioned about an online interview she took for .NET. She's into PHP and open-source technologies so she got a question off the Internet. The reply was the answer pasted from the same website!

Sunday, November 4, 2007

MSDN: About Enterprise Architects

There's an interesting blog article on MSDN about Enterprise Architects. Check it out:
http://msdn2.microsoft.com/en-us/library/bb945098.aspx

You may also want to take a look at some other blogs by Microsoft Architects:
http://msdn2.microsoft.com/en-us/architecture/aa699386.aspx

Friday, November 2, 2007

Resource files in Java

Just as we have resource files when developing with .NET, Java can read from resource files located in a directory listed for the class path.

You can use one of the following two statements depending on the context from which you want to read the resource file:

[className].class.getClassLoader().getResourceAsStream
("filename"); //to call from a static context

this.getClass().getResourceAsStream("filename"); //to call from a non-static context

Bridging Business and I.T.


In many firms, the department working on the core business shares little with the I.T. division and they talk completely different languages. Here's a little comic that I found at: http://www.insurancebroadcasting.com/Cartoon_2.gif

Findstr to grep on Windows

If you've been using grep all week only to come home to an PC running Windows, you're probably missing a part of your life when you leave your Linux workstation.

If you've been in the dark on the Findstr command line utility for Windows, you'll certainly love my blog for this. If you're on a text file containing huge amounts of text, such as a log file (I've got a log4net log that generates a few hundred lines every hour... that is after disabling the memcache logging) you can get Findstr to search for all lines with a particular word. Findstr does regular expressions too. It's got many of the options that grep does - printing filenames for matches, printing lines that do not match, and multiple file search.

iPod Touch picky about its electrons

I just came across a blog post by Daniel Schneller about his iPod Touch being very picky about where it gets its electrons from. It can get charged via a USB port and gets charged while running Windows or MacOS but not when running Linux. The fix was to install a driver, but it seems pretty odd anyway. I connect my iMate Jasjar to the computer (irrespective of which OS is running) and sometimes to the DVD player.

I can understand people being cautious about where they get their money from to avoid counterfeit but why would an iPod touch want to know where it gets its electrons from?

An AppSettings Equivalent

I've been looking for an equivalent of the AppSettings file in Java and came across the java.util.Properties class. I haven't tried it yet but I'm guessing I've got to explicitly specify the file from which I'm going to read the properties from and save the values to. It's good enough for me.

Episode 6 of Bionic Woman missing

Bionic Woman Episode 6 of Season 1 seems to be missing. Usually the episode comes up in a search on Mininova for download as a torrent on Wednesday or latest by Thursday.

I prefer to download them before watching because I've got a slow connection :-(

Method Extensions in C# 3.0

One of the new features in C#.NET 3.0 is method extensions. You can add additional methods, for example, to the String class so you can have a ToEmployee method in it. The only difference between a regular static method and a method extension is the addition of the "this" keyword before the parameter declaration.

Generic software components

When building software, most projects reduce development time by making integrating re-usable components. When building a re-usable component, there are two popular strategies for configuring a generic component to the application - you could either have a configuration file, as most .NET applications do, or you could have all configuration parameters sent in via code through setting properties and calling constructors or other methods.

The essence of building a generic component is that you should think of the component as a breadboard - somebody somewhere would want to do something that you did not intent and the ability to adapt the component to the scenario is what makes a successful component.

Wednesday, October 31, 2007

Changing AppSettings in .NET

Using appsettings("key")=value . Will change the settings in memory and not in web.config

To change it in both, use this method:

VB:

Private Sub ChangeAppSettings(ByVal key As String, ByVal NewValue As String)
Dim cfg As Configuration
cfg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")

Dim setting As KeyValueConfigurationElement = _
CType(cfg.AppSettings.Settings(key), KeyValueConfigurationElement)

If Not setting Is Nothing Then
setting.Value = NewValue
cfg.Save()
End If
End Sub

C#:

private void ChangeAppSettings(string key, string NewValue)
{
Configuration cfg;
cfg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

KeyValueConfigurationElement setting = (KeyValueConfigurationElement)cfg.AppSettings.Settings(key);

if ((setting != null)) {
setting.Value = NewValue;
cfg.Save();
}
}

Disabling ASP.NET Caching

Most web applications with authentication disable caching so after you logout, you can't click the back button to try and view pages that you shouldn't be accessing.

In ASP.NET, you can use the following code to disable caching
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetNoStore()

There are some other snippets you could try out too. Here's one:

Response.ClearHeaders();
Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1

Another one to add directly to the HTML code on your page (this one has been known to not work on Firefox):

meta equiv="CACHE-CONTROL" content="NO-CACHE"

You'll probably want to test the code with all of your target web browsers.

Sunday, October 28, 2007

.NET to Java

The JaCIL compiler can convert .NET assemblies (binaries) to Java byte code. The output is a Java Archive (JAR). You can find more here:
http://www.cs.rit.edu/~atg2335/project/quickstart.php

Saturday, October 27, 2007

Mini-blog comment replies

A lot of people these days write short tit-bits on social networking sites instead of paragraphs and journals of hand-written notes. I think it's an evolution of the Orkut scrapbook and the Facebook wall - you would now post messages to your own scrapbook/wall and people following your mini-blog get notified, often via a free SMS text message.

When you let visitors add comments to your posts, you would reply back to their comment and there's no way for them to know that you've replied to their comment. Blogger.com addresses that by emailing you all comments after yours (or at least that's what I think it does) if you check a little box when posting a comment.

Some systems are smarter and maintain a tree-like structure to keep track of which post is a reply to which other post, but then it all depends on how the designers intended it to be. Being an architect myself, I have to make trade-offs between cost and functionality and, in the end, the more you spend, the better stuff you can come up with.

Friday, October 26, 2007

Java Application as a Windows Service

I was looking up some way to turn a Java application into a Windows service.

In Linux/Unix, it's much simpler since all you need to do is specify a command with all arguments, which in our case is the JVM executable java.exe with the class or Java archive name as a parameter.

In Windows, we would use a product like the Java Service Wrapper or the Java Service Launcher to launch the application whenever Windows starts up, without requiring the user to log in.
I haven't tried either of those products yet since I'm not currently into Java development, but when I do I'll post more about them here.

Monday, October 22, 2007

.NET Remoting over TCP

Remoting in .NET is quite similar to RMI in Java. To begin with, we need an object that has the methods we would be executing on the server-side. This object inherits from MarshalByRefObject. This indicates that the client does not get a copy of the object but rather a reference to the remote object. We then have a hosting process and a client process.

In our example, the hosting process creates a new instance of the TcpChannel class (pass the TCP port number to the constructor of TcpChannel for the server hosting process) and registers the object using ChannelServices.RegisterChannel. Then, the class we are hosting has to be registered using the RemotingConfiguration.RegisterWellKnownServiceType method - it takes the type of our class as the first parameter, the registration name as the second parameter and the object mode (singleton & single call modes) as the third parameter. When creating a console application, we would usually add a Console.ReadLine statement at the end of the application to prevent it from exiting.

The client application would create and register an instance of TcpChannel. Then, obtain an instance of the class hosted on the server using Activator.GetObject - with the type of the class as the first parameter and the URL (Example: tcp://localhost:8080/my_service) as the second parameter. You can now call methods on the object as you would for a normal object.

Sunday, October 21, 2007

Type Forwarding

Type Forwarding enables client applications to refer to a library at compile time for a type that is later moved to another library.

Example:
using System.Runtime.CompilerServices;
[assembly:TypeForwardedTo(typeof(DestinationLib.TheType))]

The IFormattable interface

Implementing the IFormattable interface let's you do much more with the ToString() method if you're developing text-based applications or are trying to create strings out of object fields.

To implement the IFormattable interface, you have to create a ToString method that accepts a format string and an IFormatProvider object. The IFormatProvider object isn't relevant but the format string can be used, such as to return only one field of an object. Here's a sample implementation:

class TimeInterval : IFormattable {

...

public override string ToString() {
return ToString(null, null);
}

public string ToString (string format, IFormatProvider formatProvider) {

if (format == null) {
return this.Hour.ToString() + ":" + this.Minute.ToString();
} else if (format == "h") {
return this.Hour.ToString();
} else if (format == "m") {
return this.Minute.ToString();
} else throw new Exception("Invalid format specified");
}
}

To use the new method, you could provide a format string to either string.Format or Console.WriteLine. Example:
TimeInterval timeInterval = new TimeInterval();
Console.WriteLine("{0:h} hours and {0:m} minutes", timeInterval);
Console.WriteLine("{0,2:h}:{0,2:m}", timeInterval); //the ",2" specifies the minimum number of characters in the resulting string - if positive, the output is left-padded, otherwise it is right-padded

Saturday, October 20, 2007

Common Interfaces

The following are some common interfaces implemented by user-defined types:

IComparable: This is required for sorting.

IDisposable: This is used for manually disposing an object

IConvertible: This provides conversion to a base type

ICloneable: This is to provide a copy for an object

IEquatable: This is used when comparison of objects using "==" is required

IFormattable: This is used to convert an object into a formatted string (rather than use the base ToString method)

Group chat coming soon in GoogleTalk

Google has a GoogleTalk gadget web client accessible from it's website at http://www.google.com/talk . It features Group chat but the downside is that it doesn't receive offline messages. As a friend from the old country would say, you've got to pick what suits the moment.

If it's any indicate of what's to come, we should see Group Chat in the GoogleTalk client sometime soon.

RSS vs Atom

RSS and Atom are both used to publish news feeds (summarized content used by readers to track content changes). Both are quite popular, although RSS has received more attention than Atom. RSS is a specification by the Harvard University, whereas Atom is an RFC by the IETF and IESG.

I read a pretty interesting comparison of the two at:
http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared

Friday, October 19, 2007

VB 7 vs VB 8: Operator Overloading

When designing .NET as a programming platform, the designers could either leave out operator overloading, as Java does, or they could continue the tradition started off by C and continued by C++ to provide greater control to the programmer. They chose to let the programmer decide which path to take and so added the feature into the framework, but for some reason didn't provide a way to use it through Visual Basic .NET 2003 (VB 7).

In .NET 1.1, VB 7 did not include the concept of operator overloading. You could neither define nor use overloaded operators and the workaround was to create methods, such as a .Add(object) method. C#, however, did include operator overloading even on .NET 1.1.

.NET 2.0 introduced the Operator keyword in Visual Basic, a feature in VB 8, which reduces the amount of code and provides added convenience for the developers.

.NET Value Types

Value types in .NET

The following are the built-in value types in .NET. Value types are stored on the stack and can be accessed more efficiently than reference types.

Type: SByte
Alias(es): sbyte
Size (in bytes): 1
Range: -128 to 127

Type: Byte
Alias(es): byte
Size (in bytes): 1
Range: 0 to 255

Type: Int16
Alias(es): Short, short
Size (in bytes): 2
Range: -32768 to 32767

Type: Int32
Alias(es): Integer, int
Size (in bytes): 4
Range: -2147483648 to 2147483647

Type: UInt32
Alias(es): UInteger, uint
Size (in bytes): 4
Range: 0 to 4294967295

Type: Int64
Alias(es): Long, long
Size (in bytes): 8
Range: -9223372036854775808 to 9223372036854775807

Type: Single
Alias(es): float
Size (in bytes): 4
Range: -3.402823E+38 to 3.402823E+38

Type: Double
Alias(es): double
Size (in bytes): 8
Range: -1.79769313486232E+308 to 1.79769313486232E+308

Type: Decimal
Alias(es): decimal
Size (in bytes): 16
Range: -79228162514264337593543950335 to 79228162514264337593543950335

Type: Char
Alias(es): char
Size (in bytes): 2
Range:

Type: Boolean
Alias(es): bool
Size (in bytes): ?
Range: true, false

Type: IntPtr
Alias(es):
Size (in bytes): Platform-specific
Range:

Type: DateTime
Alias(es): Date, date
Size (in bytes): 8
Range: 1/1/0001 12:00:00 AM to 12/31/9999 11:59:59 PM


Operations with Int32, UInt32 and Double types are optimized by the runtime or the hardware.

Browsing the Linux source code

The Linux source code is a pain to go through. There's so much in there that you need to get someone to tell you where to look if you're ever planning to change anything. There are things to make your life easier, though. The LXR C source code to HTML converter adds cross-references and hyperlinks so you can find your way around just any piece of C source code. The folks at Promethos were nice enough to run the LXR on the Linux source code and the resulting HTML is available at: http://www.promethos.org/lxr/http/source

Unlike in real life, most of the good things in the computing world are free!

The Bionic Woman

Today is my weekend. I've been catching up with the Bionic Woman TV series and it's pretty neat. I've seen most of the episodes of the 1976 series and all the aired episodes of this year's series. I even saw the pre-air version of the first episode - they edited out a whole character! She wasn't all that pretty so who cares? :-P

The 1976 series starts off with Jamie Summers coming out of surgery to fix some of the bugs from her bionic replacement operation (in the 1976 series, Jamie Summers has a parachute-related accident). She returns home to Ojai and becomes a school teacher at an air force base and takes up some missions. Except for the 1st and 2nd episodes, all the others are pretty much disconnected.

In the 2007 series, Jamie Summers is carrying and shortly after meeting up with Will, her boyfriend to tell him about her pregnancy, she has a vehicle accident caused by Sara, the first bionic woman, suffers injuries and the only way to save her is through bionic replacement. Sara meets up with her a couple of times and in the 3rd episode she tells Jamie she is dying and needs her help... Sara took up bionic replacement before the technology was perfected and wants Jamie to go back with her to try some of the 'upgrades' as a fix.

Update: I watched episode 4 today and apparently Jamie has her clock ticking just like Sara does. The project sponsor does promise to work on a cure at the end of the episode.

Symantec blocks email

Symantec Client Firewall prevents me from sending out email from an email client that uses GMail as a server. I ran a system restore and got back all the factory-installed software and the Symantec suite happens to be one of them.

I haven't uninstalled it yet. I'm just sending my email through GMail's web interface for now, but something has got to change soon - either Symantec gives me an update or I move to something else.

Thursday, October 18, 2007

Project Planner on Windows

If you want to create a Gantt chart and manage a To Do list of tasks on a project, you don't have to spend a couple of hundred dollars to buy MS Project. You can settle for Planner, an open-source project management utility included with most Linux distributions. A windows version is available at: http://winplanner.sourceforge.net/ for free download.