Archive

Archive for the ‘Programming’ Category

Grails 0.6 released

September 1st, 2007
Comments Off

Grails 0.6 has been released, here’s the release post.

For those wondering what it is, Grails is a framework for the Java platform designed for high productivity. I started using it for a project with version 0.5, have since moved to 0.5.6, and will soon upgrade to this latest version.

While I appreciate Ruby on Rails’ ideas, I don’t like Ruby itself as a language. We also know several clients that have Java as their standard platform, so Ruby on Rails or even Plone-based projects were out of the question. Groovy on Grails also caught my eye because, underneath, it’s all Java – so we had the wealth of Java libraries available to draw from.

Development is a breeze, and whenever I’ve encountered something that wasn’t well explained in the documentation the Grails community has been extremely helpful.

We’ve had no stability issues or performance issues, even though it’s months away from a 1.0 release and we’re testing it on a server with limited specs. The speed is beyond what I expected: pages that take a second or so on development on my Core2Duo 2.33GHz are spit out in milliseconds on the live site, which is running on one of Zone.net’s lower-end VU200 virtual servers.

Productivity has been great, even considering the learning curve. I came to Grails with no knowledge of Spring or Hibernate, and have had on occasion to learn not only of Grails and Groovy but the foundation it’s based on. Even so, in most cases it’s been out of curiosity for how something is being done behind the scenes (much time spent scrying Hibernate logs or looking at the generated db structure).

For me, the best thing so far was realizing that for the first time in a while it was taking me longer to come up with an implementation or design that I felt happy with than to actually execute it, and to experience how easy it is to change courses if I come up with something better. No “crap, if we do it better we’ve got to throw away three day’s worth of code” resistance.

That means my time is being used where it’s truly useful, and I’m ending up with approaches I’m happy with.

I’m absolutely sold.

Ricardo Programming

Hiring quality programmers

August 7th, 2007
Comments Off

On-the-spot article about hiring quality programmers, and the very high costs of staffing your company with adequate people.

When you work in an environment with experts things simply work. They are easier to use and require less initial training. The software is easier to modify. Requested changes happen more frequently and easily. Things just flow. It is the difference between Apple and Microsoft.

One of the comments hits squarely on the reason why things are not likely to get any better, if companies keep playing the same game:

If you do 10x better work, you get 10% better pay. If you’re a hotshot, it is simply not economical to go into industry. You do a startup, contract work, or switch fields (entrepreneurship, i-banking, etc.).

Ricardo Programming

JAI memory usage

August 3rd, 2007
Comments Off

I’m using Sun’s Java Advanced Imaging libraries for image manipulation on a personal project, as I’ve mentioned before.

Things were working swimmingly, but when I started testing with images from my phone’s camera the following exception started appearing:

Error: One factory fails for the operation “jpeg”
Occurs in: javax.media.jai.ThreadSafeOperationRegistry
java.lang.reflect.InvocationTargetException

[...]

The problem was not how the image had been created, as I originally suspected, but actually the image size – this seems to be a rather obscure way of telling you I’m out of heap space!. Increase the heap space or try with smaller images, and it should work just fine.

Ricardo Programming

Grails and HSQL vs H2 vs Derby

August 1st, 2007
Comments Off

I’ve been building a personal project for a couple months now using Groovy on Grails. Through all this time we’ve been working with in-memory HSQL databases, but now that we’re ready to do a test release I began testing embedded Java databases to pick which one we would use.

My first candidate was Apache Derby, based on some good performance reports I’ve read. Unfortunately, I immediately ran into a problem, where objects weren’t being committed right away. I would execute something like:


new Animal(name:"Misingo").save()
def misingo = Animal.findByName("Misingo")

And while the save call would succeed, the findByName function would fail. I began digging through Google trying to find a work around, but the voice of reason in my head told me that if I was having to look for fixes for trivial tasks, I shouldn’t rely on it for anything major.

Dropping back to considering HSQL with file-based tables, I started researching HSQL performance and ran into a HSQL vs Derby, where a history of Derby bugs is mentioned and several benchmarks are pointed to. This same article brought the very promising H2 Database to my attention, which comes with some pretty impressive benchmarks.

I downloaded it and attempted to get H2 working with Grails 0.5.6, and got an easy enough to fix error:

Could not determine Hibernate dialect for database name [H2]

In order for it to be recognized, you’ll have to create a file hibernate/hibernate-dialects.properties containing the following string:


H2Dialect=H2

This got H2 running and working perfectly for my development tests, but it failed when attempting to use production:

could not get database metadata
org.h2.jdbc.JdbcSQLException: Table SYSTEM_SEQUENCES not found [42S02-55]

Google searching for “H2 SYSTEM_SEQUENCES” yielded only 3 pages, two of them in Japanese. Not promising. Some testing determined that if the data source’s dbCreate property is set to either create or create-drop everything went smoothly, but it failed when set to update.

I went back to the H2 site, and found the following on the FAQ:

Is it Reliable?

That is not easy to say. It is still a quite new product. A lot of tests have been written, and the code coverage of these tests is very high. Randomized stress tests are run regularly. But as this is a relatively new product, there are probably some problems that have not yet been found. Areas that are not 100% tested:

  • Platforms other than Windows XP and the Sun JVM 1.4 and 1.5
  • Data types BLOB, CLOB, VARCHAR_IGNORECASE, OTHER
  • Cluster mode, 2-Phase Commit, Savepoints
  • Server mode (well tested, but not as well as Embedded mode)
  • Multi-Threading and using multiple connections
  • Updatable result sets
  • Referential integrity and check constraints, Triggers
  • ALTER TABLE statements, Views, Linked Tables, Schema, UNION

[...]

Evidently H2 is not ready for prime time – at least for my purposes – but it was refreshing to see the developer be upfront about it. I’ll wait before using it in production, but my hat’s off to Mr. Thomas Mueller – the creator – for his work on creating his own DBMS from scratch (again, he was one of the original creators of the Hypersonic SQL Project, on which HSQLDB is based).

So where does this leave me? Back with HSQLDB. Its performance is good, it’s stable and provides everything I need. I guess I must be getting old if I’m deciding based on stability and ease, not on shininess, but sanity has prevailed.

And after all, I did give shiny new thing a fair shot.


Bonus content:

Ricardo Programming , , , ,

Release

July 31st, 2007
Comments Off

Software release is such a pain. Better it remained hidden, cozy and safe, in our development environment.

Ricardo Programming

Server backups with Amazon S3

July 29th, 2007
Comments Off

Very detailed article on automating server backups using Amazon’s S3 system, which I’ve recently trying out using myself for one of my Assembla-hosted projects.

PS: Yes, I’m making the Assembla backups myself. I’m not too keen on giving someone else the secret access key.

Ricardo Programming, Science and Technology

JAI and masking operations

July 26th, 2007
Comments Off

I just spent a few hours tearing my hair out at an peculiar behavior with JAI, and thought to briefly document it in case anybody ran into a similar situation.

I started off from the code on this relatively old article, adapting it to my needs on Groovy. The intention was to:

  1. Get an image
  2. Crop it to a square
  3. Generate a thumbnail
  4. Add a mask to the thumbnail

The original test code we wrote work perfectly. The mask function was (with control output added):


public applyMask()
{
println("ON APPLY MASK")
println("Mask ${mask.getWidth()} x ${mask.getHeight()}")
println("Alpha ${alpha.getWidth()} x ${alpha.getHeight()}")
println("Image ${image.width} x ${image.height}")

ParameterBlock params = new ParameterBlock();
params.addSource(mask);
params.addSource(image);
params.add(alpha);
params.add(null);
params.add(new Boolean(false));
result = JAI.create("composite", params, null);

println("Result ${result.width} x ${result.height}")
}

Thumbnails were generated with:


def d = new ImageUtils()
d.load("cropped.jpg")

[178, 133, 69].each {
d.thumbnail(it)
println "Created thumbnail"
d.writeResult("Thumb_${it}.jpg", "JPEG")
}

And having generated them, we iterated through them with:


def e = new ImageUtils()

[178, 133, 69].each {
e.load("Thumb_${it}.jpg")
e.loadMask("Mask_${it}.jpg")
e.loadAlpha("Alpha_${it}.jpg")
e.applyMask()
println "Created Masked thumbnail"
e.writeResult("Masked_${it}.jpg", "JPEG")
}

to apply the corresponding masks.

Turns out that when the code was optimized to just handle everything in memory, without an intermediate save, the resulting image ended up missing a few pixels in all sizes. Executing


[178, 133, 69].each {
c.thumbnail(it)
println "Created thumbnail"
c.swapSource() // Assigns the result RenderedOp to copy to work from
c.loadMask("Mask_${it}.jpg")
c.loadAlpha("Alpha_${it}.jpg")
c.applyMask()
println "Created Masked thumbnail"
c.writeResult("Masked_${it}.jpg", "JPEG")
c.restoreOriginal()
}

gave us results like:

Mask 133 x 133
Alpha 133 x 133
Image 133 x 133
Result 133 x 128

This seems to be a JAI bug when working completely from memory RenderedOp sources. Saving a temporary thumbnail and loading it again before applying the mask works just fine.


[178, 133, 69].each {
c.thumbnail(it)
println "Created thumbnail"
c.writeResult("Thumb_${it}.jpg", "JPEG")
c.load("Thumb_${it}.jpg")
c.loadMask("Mask_${it}.jpg")
c.loadAlpha("Alpha_${it}.jpg")
c.applyMask()
}

Ricardo Programming

Postfix on OS X

July 25th, 2007
Comments Off

A very good page on setting up Postix as a mail server on OS X, including fixing a broken launchd script.

Set the org.postfix.master.plist file exactly as it is on that page. If you leave out the last two keys, it might tell you that it was launched but you won’t be able to reach it.

Also, the following commands might tell you that the script has already been loaded:

cd /System/Library/LaunchDaemons
sudo launchctl load org.postfix.master.plist

In that case, simply do

cd /System/Library/LaunchDaemons
sudo launchctl unload org.postfix.master.plist
sudo launchctl load org.postfix.master.plist

Ricardo Programming

Shirky on love as a success indicator

July 10th, 2007
Comments Off

Great speech by Clay Shirky about how much people love doing something is an indicator of if it will succeed.

Originally found via BoingBoing.

Ricardo Personal, Programming, Science and Technology

MySQL service stopping on its own

May 28th, 2007
Comments Off

Here’s a helpful bit for MySQL users for whom the service starts and shuts down immediately. After updating a few things on my Mac, MySQL started misbehaving – I ran it, the service started, and it stopped itself a second later. This is what my console looks like:


hydra:~ ricardo$ sudo /sw/bin/mysqld_safe
Password:
Starting mysqld daemon with databases from /sw/var/mysql
STOPPING server from pid file /sw/var/mysql/hydra.pid
070527 19:24:42 mysqld ended

Explicitly stating the user fixed the problem:


hydra:~ ricardo$ sudo /sw/bin/mysqld_safe --user=root

Ricardo Programming