Tuesday, 15 January 2008

Integrating SyntaxHighlighter with Blogger

I've just found a quick and easy way of integrating SyntaxHighlighter with Blogger. Go and check this blog entry and start posting coloured code snippets!

Two things to note though. If your theme uses background images for <li> elements, you will have to apply this patch to your CSS:

div.dp-highlighter li {
background-image: none;
Otherwise each line of your code snippets will start with a background image as it is coded with an <li> element.

Finally, if you copy and paste the whole javascript from step 2 your syntax highlighting will only support the following languages:
  • Cpp
  • CShapr
  • CSS
  • Java
  • JScript
  • Sql
  • Xml
Syntax Highlighter supports more, for example Ruby, Delphi or VB. If you want to use any of them, you can do this by adding an extra line like this (for Ruby):

<script src='http://[YOUR HOST]/shBrushRuby.js' type='text/javascript'/>

Tuesday, 27 November 2007

Firefox 3 Beta 1 passes the Second Acid Test

I was quite excited when Firefox 3 Beta 1 was released a few days ago - for at least two reasons.

The first thing I thought about the other day was the memory - I was hoping I will read something about it in the release notes, as the second version of the browser can consume lots of MB of RAM. By the way, I am not sure what the world record is, but here you can see Firefox at 1.8 GB. Therefore, it was really nice to find out that "over 300 individual memory leaks have been plugged"!

The first thing I did though after installing FF 3 Beta 1 was to see how it does with the second acid test and whether it can be as perfect as Opera is. And to my surprise, Firefox is actually perfect! Finally, it renders the correct 'face':

Just after that test I read about rendering improvements in CSS in the release notes. Well done the Firefox dev team! For me as a web developer that is a really good news.

Monday, 17 September 2007

NetBeans 6.0 Beta 1 and custom Tomcat

I've just installed the first beta version of NetBeans 6.0, which was released today. Just out of curiosity, to see how it looks, performs and whether or not there is something better than Eclipse has. It was the full pack including Java SE, Web & Java EE, Mobility, SOA, Ruby, C/C++ and GlassFish. I decided not to install Tomcat as I had it already. To be honest, I got surprised before I even started using it ...

The installation took a long while, about 3, maybe 5 minutes. It was the full installation, so fair enough, though still don't understand why it has to take so long. Eclipse can be installed just by unzipping it to a directory of your choice and that's it. +1 for Eclipse.

NetBeans 6.0 requires about 400 MB for the full installation, plus 140 for GlassFish, if you choose to install it. Quite a lot, however my Eclipse 3.3 takes about the same size with the latest patches and the following plug-ins: Subclipse, Spring IDE, Tomcat , Maven 2, Web Tools and PMD.

The biggest surprise, however, was Tomcat integration. As I mentioned before, I chose to use my own Tomcat, so the first thing I did after startup was to add it to the servers. Here I got an odd warning saying that I might have problems running Tomcat as the startup scripts are missing (due to the windows installation which does not include these). The 'add server' wizard closed down, Tomcat was added successfully. When I tried to start it I understood what the warning was all about:

You must be joking, I thought. That's ridiculous! Why the Tomcat plug-in in Eclipse can start any Tomcat since version 3.3 (including my Windows-based) without any startup scripts, and NetBeans simply can not?! I don't believe the NetBeans team don't know that they can use bootstrap.jar instead. And guess what, all the instructions how to use it are in catalina.bat!

After that, I decided not to play with NetBeans 6.0 Beta 1 any more. And if there is anything I am going to uninstall is definitely not Tomcat, but NetBeans.

Oh, and one more thing. Does anyone know why NetBeans reads my floppy disk on startup and exit? Does it search for the missing catalina.bat??

Thursday, 16 August 2007

Learning GigaSpaces at Financial Times

If someone had told me that I was going to work at Financial Times at one day, I would never have believed...

It is happening now, I've just joined a project for the FT where some of the work is going to be done at the client's office! The funny thing is that I have been passing FT's building on my bicycle for the last one year or so and have never even thought that I might work at that place.

Today I spent my first day at FT learning GigaSpaces and OpenSpaces. Yet another stuff I have never thought I might need to learn in my career! Especially that I am slowly thinking of doing RoR development (after a couple of years of Java). Now it looks like I will be doing Java for another couple of months, if not for a year. Even so, I think it is worth having GigaSpaces in my CV!

Anyway, I am not an expert here, but it sounds like a very promising solution for a highly performant, scalable and distributed application. Something the FT need!

Sunday, 15 July 2007

Firefox at 1.8 GB of RAM

One of the reasons why I hate Firefox is the memory that it uses. It needs about 100MB - 200MB for 10 tabs, or even more if one of these is Gmail or Google Reader. If you open more tabs and switch quickly between them etc, the browser just slows down and needs a restart.

But this is actually nothing compared to what Firefox managed to do today. I was navigating Google maps with about 10 other tabs opened at the same time, when this happend:

My box has 'only' 2 gigs of RAM. I guess Firefox would have used even more if there was more to use ...

Luckily, I didn't have to restart my box, just the browser ;-)

Sunday, 3 June 2007

Grails 0.5.5 - testing controllers with Mocks and Expando

In this blog entry I would like to show you how to unit test a typical 'update' action in Grails using Groovy Mocks and the ExpandoMetaClass.

Let's assume we have an action like this:
 def updateword = {
     def word = Word.get( params.word_id )
     if(word) {
         word.pl = params.word_translation
         if(word.save()) {
         else {
             render("Error updating word")
     else {
         render("Word does not exist")
In brief, it updates a Word instance by getting a Word from the database, modifying its 'pl' property and saving it back to the database.

Now, how would you unit test the execution path where the "Error updating word" message gets rendered? To do that, you need a scenario where a Word instance gets returned from the database but fails to save back after the update operation. Here is how you can do it using Mocks and Expandos:
 void testUpdateExistingWordSaveFailure() {
     def mock = new MockFor(Word)
     def fakeWord = new Expando(save: {false})
     mock.demand.get { fakeWord }
     mock.use {
         def wc = new WordController()
         wc.params.word_translation = "tak"
         assertEquals "Error updating word", 

The flow of the test is as follows:
  1. Create a mock for the Word class
  2. Craete a fake word instance (Expando) which replaces the 'save' method
  3. Demand the Word class to return the faked word when the get method is called (exactly once)
  4. Use the mock and call the updateword closure
  5. Assert if the correct message was rendered to the browser
See the Unit & Integration Testing Controllers page to understand the last step - getting a text from the response.