Grails Growl-like notifications in Linux (Ubuntu, 9.04)
by Colin on May.24, 2009, under General, Groovy-Grails, Linux, Ubuntu
When I was developing on OSX, a fellow developer Ted Naleid tipped me off to a script that does Growl notifications for Grails events that Marc Palmer had written. The Growl notifications were handy, but now that I’ve been working on Linux, I’ve definitely missed them.
I first used a tool called Mumbles, which attempted to be a clone of Growl, but I later realized that the built in notification system is probably the way to go. After I learned of Ubuntu 9.04 (Jaunty Jackalope) had some major visualization enhancements to the notifications, I thought that it was definitely the way to go.
This is what I currently have with Ubuntu 9.04:


Implementing this is very simple, you simply create an _Events.groovy file in your ~/.grails/scripts directory (create it if it doesn’t exist) with the following contents (modified from the Growl Script):
eventStatusFinal = { msg ->
libNotify(’Final status’, msg)
}
eventStatusUpdate = { msg ->
libNotify(’Status’, msg)
}
eventCreatedFile = { fileName ->
//libNotify(’Created file’, fileName)
}
eventStatusError = { message ->
libNotify(’Error’, message)
}
eventExiting = { code ->
libNotify(’Exit’, "Return code $code")
}
eventCreatedArtefact = { type, file ->
libNotify(’Created artefct’, "$type with name $file")
}
eventCompileStart = { kind ->
//libNotify(’Compiling’, "Compiling $kind")
}
eventCompileEnd = { kind ->
//libNotify(’Compilation complete’, "Compiled $kind")
}
eventPluginInstalled = { pluginName ->
libNotify(’Plugin installed’, pluginName)
}
// Do the notification
void libNotify(title, message) {
def cmd = [
'notify-send',
title,
message,
'-i',
'grails'
]
cmd.execute()
}
It is simply using Groovy to execute "notify-send $title $message -i grails". if you don’t have notify-send, it is part of libnotify so sudo apt-get install libnotify-bin will get you what you need. If I get some time I’d like to find a way to take advantage of a Java Dbus implementation to talk to the notification system without having to go through libnotify.
If you want mumbles notifications just do something like this:
void mumblesNotify(title, message) {
def cmd = [
"mumbles-send",
"-l",
title,
message
]
cmd.execute()
}
Occasionally I’ll get a failure that there are too many files open (using .execute() in Groovy) and that should be cleared up by using a Java implementation of the DBus notifications.
Let me know what you think. Anything that could be done better?
Customizing rEFIt (an EFI Bootloader - Intel Macs) Slick!
by Colin on May.05, 2009, under General, Linux, Logo, Ubuntu
I recently installed Ubuntu 9.04(Jaunty Jackalope) on a 17" Macbook pro and as a part of that process, I had to install a bootloader called rEFIt. You could think of EFI is just a next-gen BIOS.
Even though the bootloader looks decent, I don’t like the look of silver/grey color, so I decided to customize it. The process to customize rEFIt was relatively straight forward and the result is beautiful.
This is what I came up with:
This is what it looks like with a Windows Partition:
I love the simplicity of it!!
Here is a closeup of the icons / OS Choices:

I don’t really know where the icons came from, but they look tasty
On Linux there is a decent package for working with mac icons (.icns) or sudo apt-get install icnsutils which will get you some useful tools (png2icns and icns2png)
I did have to make a few modifications to the Tux icon [os_linux.icns] to give him a ‘glow’ so that he doesn’t fade into the black on black:

This windows Icon [os_win.icns] is the stock version I think (send me a link to the author if you know):

I did add a slight ‘glow’ to the apple icon [os_mac.icns] (send me a link to the author if you know):

I tried a number of custom ’selected’ themes but gradients didn’t look right, so I went with the simple plan. The selection bitmap can be found here:

the process is simple once rEFIt is installed: modify the refit.conf with the icons in place, and you are done!
Here is what I came up with for my refit.conf (comments removed):
timeout 5
banner hostname.bmp
selection_big selection-big-ring.bmp
hideui tools shell funcs hdbadges label
legacyfirst
The original comments in the refit.conf file are helpful! Its straight forward if you can read
- timeout = the number of seconds before it automatically chooses for you
- banner = the bitmap of the upper part of the screen (top left pixel = background color)
- selection_big = the grey ‘ring’ that indicated the selection
- hideui = Hide elements of rEFIt so we can get a clean interface
- legacyfirst = Legacy OS first (Linux)
Use at your own risk!!
If I had the time, it would be fun to build/enhance rEFIt to have an all-black fill instead of the grey/silver.
I’ve had a good experience with Ubuntu 9.04 on a 17" Macbook Pro, and I’ll Blog about it - and see what I can do to help update the documentation - look for an upcoming post.
Ubuntu Logo
by Colin on May.03, 2009, under Linux, Logo, Ubuntu
I spent a little bit of time customizing rEFIt, which is an EFI Bootloader that can be used on intel macs. So far I like it. Its not 100% feature complete (imho), but its open source :-)
I found myself looking for a good logo for Ubuntu that it shows after you make your OS Choice in rEFIt. There was plenty of good artwork on deviantart.com, but I decided to make my own
So this is what I came up with based on one of the official logos:
ps, I also have a post coming on customizing rEFIt (it looks juicy)
Greasemonkey + live.gizmodo.com
by Colin on Mar.17, 2009, under General
The Keynote for iPhone 3.0 just got over and I thought I should share a tiny greasemonkey script that I put together to reload http://live.gizmodo.com/ much sooner than the 90 seconds that one would wait.
It is too bad that macrumorslive.com is out of buisiness since they got hacked this past January. Their application wasn’t too hard to mashup either. It was simply changing a timout var in one version and then changing an obfuscated function later.
So the Greasemonkey script is really a breeze, it simply loads jQuery, hides the banner/space-waster and sets a timer to reload the page after 15 seconds (15000 milliseconds…)
// ==UserScript==
// @name live.gizmodo.com
// @namespace live.gizmodo.com
// @description live.gizmodo.com
// @include http://live.gizmodo.com/
// ==/UserScript==
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
// All your GM code must be inside this function
function letsJQuery() {
$('#header_container').hide()
setTimeout(function(){ window.location.reload(true);}, 15000);
}
Overnight Website Challenge + Grails
by Colin on Feb.27, 2009, under General
Sierra Bravo is putting on an overnight website challenge tomorrow featuring 12 teams and 12 non-profits. The challenge is a great way to give back and strut our stuff.
I’m on a team called the Groovy Goolies and we plan to use Grails to deliver a powerful web-app. Our team has an excellent lineup with a broad range of experience and talent. I’m sure we’ll do great - we’ll definitely get to beat my friends on the Inetium Team. The rich set of Grails plugins, excellent testing support and the power of Groovy will go a long way.
Checkout another post from another team-member or follow us on twitter.
Groovy and Grails IDE Shootout
by Colin on Feb.11, 2009, under Groovy-Grails
Last night at the Groovy Users of Minnesota (GUM) meeting we did an IDE shootout where we covered Groovy and Grails support in the more popular IDEs.
Jesse O’neill-Oine from Refactr started us off with TextMate.
I (Colin Harrington) presented on Eclipse and Netbeans:
Hamlet D’arcy teamed up with Matt Abrams & Bob Schultz to close out the night with Jetbrains‘ IntelliJ-IDEA.
Ironically IntelliJ-IDEA 8.1 was released the very next day. Hamlet has some good tips on his blog about Intellij-IDEA.
This is an ever improving topic and changes very rapidly, so If we missed anything just drop us a comment
Special thanks to Guillaume Laforge, Petr Hejl, Sven Haiges of the Grails Podcast as well as everyone who has contributed to the community via blogposts, documentation updates, etc.
Enjoy.
GORM :: override a setter on a Grails Domain
by Colin on Jan.08, 2009, under Groovy-Grails
Rather than implement properties in the Java Language, we have a convention called a Java Bean. This basically means that properties are implemented with getter and setter methods with a PascalCase property name in the method among a few other simple conventions.
Grails makes it incredibly easy to manage domain classes since it is inherently domain-centric. When you need to enhance your Domain classes at the core of your application, you have an option of implementing your own getters and setters. I love that by default you do not have to implement your own setters, but you have the power to do so if you wish; the principle of sensible defaults. Here is an example of a Book Object with two properties, author and isbn.
class Book {
String author
String isbn
}
Consider the case where a Book is in your Database with the ISBN of 978-1430219262 and a user tries to search for "9781430219262". Unless you do some searchable magic, the user will not find the book. A simple solution fo the issue would be to never store ‘-’ in the databse. to make this happen you could easily remove the dash in the setter. So your domain would look like this:
class Book {
String author
String isbn
void setIsbn(String i) {
isbn = i.replace(’-',”)
}
}
When I first tried this, I failed a few times before I got it right. Maybe I was just spoiled with Groovy’s groovyness, but I started out writing
def setIsbn(i){ ... } and when that didn’t work: void setIsbn(i){ ... } which was being called, but never actually set the property. Then I had a forehead smacking moment where I realized that the method signature must precisely match the signature of a JavaBean setter like public void setPropertyName(Type propVal) { ... } In my case I had to make sure that the method was public (public by default), has a return type of void (which is not the default behavior of a closure), and the parameter passed in was of the same type as the property (String)
And then I blogged about it — the fourth day.
Customizing the Gnome Clock Panel (Ubuntu 8.10)
by Colin on Dec.18, 2008, under Linux, Ubuntu
One of the incredible benefits of running an open source operating system is the fact that you can customize just about everything.
I ran across a posting on Lifehacker about how to Customize your Linux Panel Clock. The Lifehacker article referenced another article that gives an example of how to customize it with some simple HTML tags and pretty standard time formatter values. The article isn’t exact for Ubuntu 8.10, but its there if you look for it (/apps/panel/applets/clock_screen0/prefs) I wasn’t able to get it to do the span tags in Ubuntu 8.10, but it might be more flexible in the near future according to this post.
* Note to self, play around with gconf-editor some more…
GSF :: Groovy Server Faces?
by Colin on Nov.09, 2008, under Groovy-Grails
Has anyone tried to make Java Server Faces (JSF) more groovy?
Not having done anything with JSF directly, I’m not sure what could be groovified, but I’d imagine that Groovy + JSF might make JSF more attractive to a certain type of developer. I’m familiar with the some of the .NET component paradigms and can imagine what it would be like in Java
From the little that I have heard/read, I understand that some of the pain in JSF is related to XML configuration. Groovy does XML quite beautifully and could provide some much needed value to that space. Any other areas that Groovy + JSF would shine? Am I completely off base? Again, I’m not an expert in JSF, but it may warrant a question to the Groovy User list.
Groovy Elvis Operator?:
by Colin on Oct.30, 2008, under Groovy-Grails
What is this Elvis Operator I vaguely recall? I’ll get to that just bear with me for a minute.
In Java I’ve seen too many null checks like the following:
If (something != null) {
val = something
} else {
val = defaultValue
}
Its handy to have the Groovy Truth so we don’t have to do null checks. Instead of writing if (something != null) { ... } we write if (something) { ... }
Well this type of branching logic is precisely why we have the ternary operator in both Java and Groovy. I’m surprised that the ternary operator is neglected by many developers. It turns our 4 lines of if/else logic into a single line like:
val = something ? something : defaultValue
The syntax and logic for the ternary operator is the same in Groovy as it is in Java; (Condition) ? Value-If-True : Value-If-False I’m not going to get into a lesson on the ternary operator and you can certainly read more here.
When using the ternary operator I had to repeat the variable something twice to do a simple check; This isn’t groovy and it definitely doesn’t lend itself to the principles of DRY! *Queue the Elvis operator*
Instead of writing: val = something ? something : defaultValue
We write: val = something ?: defaultValue
A more clear example would be as follows:
def rockstar
def defaultrockstar = rockstar ?: "Elvis Presley"
assert defaultrockstar == "Elvis Presley"
*Thank you Satish for the example
InfoQ also has an excellent example under the section Syntax Additions :: Elvis Operator.
It is nothing too special but It ends up being closer to how we think about code. Apparently the Elvis Operator was added in Groovy 1.5 and is called the ‘Elvis Operator’ due to its resemblance of Elvis’ trademark hair.
I find the Elvis operator useful, but I still find myself frequently repeating myself when dealing with the same variable.
def rockstar
rockstar = rockstar ?: "Elvis Presley"
If we have gone this far with the Elvis Operator, why not go the extra step and introduce something like long-eyed-elvis ?= or call it the Rick Astley Operator
def rockstar
rockstar ?= "Elvis Presley"
This would be effectively the same as:
rockstar = rockstar ? rockstar : "Elvis Presley"
or
rockstar = rockstar ?: "Elvis Presley"
One more for Good measure … rockstar.
More Reading on the Elvis Operator:
- http://maas-frensch.com/peter/2007/12/19/how-elvis-showed-me-a-neat-way-of-using-operators-in-ruby/
- http://www.codecommit.com/blog/scala/implementing-groovys-elvis-operator-in-scala
- http://jfkbits.blogspot.com/2008/02/call-by-name-yo-elvis.html
- http://docs.codehaus.org/display/GROOVY/Operators
?;-)

