Getting Started with Grails

Grails is an open-source, rapid web application development framework that provides a super-productive full-stack programming model based on the Groovy scripting language and built on top of Spring, Hibernate, and other standard Java frameworks.

At least that’s what the marketing hype says.

My take – Grails is an open-source answer to Rails for the Java Enterprise crowd.  It’s got all the flexibility of Ruby on Rails with the added benefit of being able to quickly leverage Java SDK resources from within the underlying language (called Groovy).  I’ve recently been working with Grails and a can say it’s an excellent platform for rapidly developing web front-ends that can work with your existing enterprise infrastructure.  Even better, it can work with almost seamlessly with your current/legacy Java application codebase.  But the trick to all of this is getting started.  The available documentation that you find online could be FAR better (and I’ll talk about that in other posts) but here are some resources and books that I’ve found to be excellent starting points.

Programming Groovy: Dynamic Productivity for the Java Developer

by Venkat Subramaniam

Vslg To become proficient at Grails, you need to understand the Groovy Programming language, it’s constructs, and it’s importance in contrast to the Java ecosphere. Dr. Subramaniam’s book provides an excellent foundation and starting point. I’ve kept the printed edition in my backpack with me and refer to it regularly. I’ve found the information and insights Dr. Subramaniam provides to be invaluable.You can order the printed and PDF book editions at the Pragmatic Programmer’s Website:


http://pragprog.com/book/vslg/programming-groovy

Getting Started with Grails, Second Edition

Scott Davis & Jason Rudolph

LandingPageCoverSo you’ve started reading about Groovy, but you need to find out more about Grails… This book is the next logical step in that progression. Davis’ and Rudolph’s book provides a step-by-step example showing how to create a basic application (called Racetrack) that takes you along the same development lines that the Depot application in the Dave Thomas/David Heinemeier Hansson Rails book does. You’ll learn how to leverage the underlying Hibernate layer via GORM (Grails Object Relational Mapping), connecting to external databases, the basics for developing robust MVC-based applications using GSP and Grails controllers, implementing basic security and user authentication, and working with the vast plugin library available to Grails developers. The best part is you can the book is in a “try before you buy” model. You can download the book for free from the InfoQ website, and if you find you like the book and find it useful, you can support the author’s efforts and buy a print version. I found the book valuable and was able to get a basic version of an application completed for a project in a day after working through the Racetrack example.

http://www.infoq.com/minibooks/grails-getting-started

The Groovy Language Homepage

Before you can do Grails – you need to get Groovy. Go here and get your Groove on.

http://groovy.codehaus.org/

The Grails Quick Start

Get grails direct from the source at Grails.org. If you want to spin up a Grails application and you are familiar with Ruby and Rails – this will get you going fast. Be sure to read the Installation section for getting the Grails environment configured and running before you use the Quick Start or you’ll get nowhere fast.

http://grails.org/Quick+Start

New Hosting Provider…

If you noticed an interruption to the blog or trying to email me it’s because I just changed all of my hosting and domain management to godaddy.com.  Now I’m not getting paid by them and I’m not going to post some ‘affilate link’ to them where I get a bonus if you sign up for service with them.  But what I AM going to say is that they’re probably the best hosting provider I’ve used since my original provider was bought.  Their prices are outstanding, their hosting feature set is excellent (they support WordPress, Ruby/Rails, and pretty much everything except Java/Tomcat/J2EE servers) and their technical support thus far has been second to none.

If you are looking for hosting or if you feel like you might be paying too MUCH for hosting (I certainly was) then I recommend you check out godaddy.com.  It’ll be worth your time.  It certainly was worth mine!

 

 

ADT and the ‘Debug Certificate Expired’ Error

Ran into this just this morning. I started up my Eclipse for Android environment and had all my projects greeting me with the error; “Debug certificate expired on 10/1/2011”. It’s an easy enough fix.

Delete your debug certificate under ~/.android/debug.keystore (on Linux and Mac OS X); the directory is something like %USERHOME%/.androidon Windows.

The Eclipse plugin should then generate a new certificate when you next try to build a debug package. You may need to clean and then build to generate the certificate.

Problem solved.

I’m writing this with tears on my eyes !!!

Does that title sound familiar? My wife and I got an email this morning from my father that read as follows:

Subject: I’m writing this with tears on my eyes !!!

Hello,

I’m sorry for this odd request and I’m writing this with tears on my eyes due to the situation of things right now, I’m stuck in London United Kingdom with my family,we came down here for vacation and we got Mugged at gunpoint, worse of it is cash cell phone and credit cards were stolen , it’s such a crazy and terrifying experience for us, we need help sort out our hotel bill and flying back home, the authorities are not being 100% helping us, but we thanks God we still have our passports, Our return flight leave today,But we still have problem in sorting out the hotel bills.Please help us i promise to refund it back.

Now I’m freaked out.

David.

There were two problems with this email:

  1. My father doesn’t write like he barely understands english. In fact he’s one of the most eloquent writers I have ever known and is a native speaker of the Queen’s English.
  2. My father lives 12 miles away and has no travel plans

Turns out this is happening to a surprising number of people. It’s a growingly common scam. It’s also happened to a friend of mine. Apparently there is a keystroke-logging trojan that’s in the wild. Virus scanners like F-Prot, and current Mal-ware scanners are not detecting it and it’s causing a lot of havoc:

  1. http://articles.cnn.com/2010-03-28/opinion/greene.email.scam_1_e-mail-first-byline-subject-line
  2. http://community.ca.com/blogs/securityadvisor/archive/2010/04/15/beware-of-scam-emails-i-m-writing-this-with-tears-in-my-eyes.aspx
  3. Google Support

If you see an email like this from any of your friends… CALL THEM before you decide to try to send money to them. Also, if you get an email like this from your friends, tell them to UNPLUG THEIR COMPUTER from the internet.. erase it completely and RE-install windows.

You could also tell them that perhaps they should consider buying a Mac… Because in 4 years of owning and using them I have yet to have them compromised by trash like this.

Open Terminal Here in Snow Leopard using Automator

A subject that has been visited plenty of times is having an “Open Terminal Here” ability from the Finder. For developers, it’s a easy way to look at files or folders and then jump quickly to a shell for the folder and execute shell commands (like mv or cp). Or to execute a build using make or ant.

I decided to make a version of that would work off the “Services” context menu. If you control-click a file and select Services | Open Terminal Here you’ll be taken to the folder containing that file. A control-click on a folder will take you to the folder you selected.

To use it, just unzip this file and put it in your ~/Library/Services folder.

Open Terminal Here.zip

The code itself is pretty straightforward:

(* 
   Workflow - Open Terminal Here 
   By David Orriss Jr - November 2010
   Another "Open Terminal Here" option.  This time as a service workflow in Automator

   For Snow Leopard
*)
on run {input, parameters}
	
	set the_path to (the POSIX path of input)
	
	set AppleScript's text item delimiters to "/"
	
	
	if the_path does not end with "/" then
		set parentPath to (items 1 thru -2 of text items of the_path) as string
		set the_path to parentPath
	end if
	
	set cmd to "cd " & quoted form of the_path & " && echo $'\ec'"
	
	tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
	
	tell application "Terminal"
		activate
		if terminalIsRunning is true then
			do script with command cmd
		else
			do script with command cmd in window 1
		end if
	end tell
end run

Seconds, Minutes, Hours – Converting Time Units in Ruby

I’m sure you’ve probably seen this question in your programming classes.. I decided I wanted to play with Ruby again and was remind of this problem, so thought it might be fun as a simple exercise to do this in Ruby.

The problem is to take a long integer and convert it to hours, minutes and seconds. This is a common issue in games, for example, where a countdown timer is represent internally in seconds. But players don’t want to see some huge number like 43678 seconds. They’d rather see 12:07:58 for hours, minutes and seconds. A couple of uses of the mod operator, and a couple of uses of the built-in formatter and you’re good to go.
Update: I wanted to clean up the code a bit more and put the ruby equivalent of a “main” via the __FILE__ check. This way you can just reuse the code via require if you so desire.

#!/usr/bin/env ruby

class TimeFormatter

  def format_time (timeElapsed) 

    @timeElapsed = timeElapsed

    #find the seconds
    seconds = @timeElapsed % 60

    #find the minutes
    minutes = (@timeElapsed / 60) % 60

    #find the hours
    hours = (@timeElapsed/3600)

    #format the time

    return hours.to_s + ":" + format("%02d",minutes.to_s) + ":" + format("%02d",seconds.to_s)
  end
end

if __FILE__ == $0
  formatter = TimeFormatter.new

  puts formatter.format_time(43678)
end

require: command not found in ruby

While I was getting some old Ruby code of mine out to convert ruby code to pretty HTML-formatted code suitable for blogging from Wolfman’s Howlings I got the following error:


$ ./ruby2html.rb 
./ruby2html.rb: line 9: require: command not found
./ruby2html.rb: line 10: require: command not found
./ruby2html.rb: line 11: require: command not found
./ruby2html.rb: line 14: syntax error near unexpected token `('
./ruby2html.rb: line 14: `    code= File.read(ARGV[0])'

Never saw this problem before, but obviously it was frustrating.

What had happened was I hadn’t deleted the tab spaces before the #!/usr/bin/env ruby line.

Apparently if there is any white space before the #!/usr/bin/env ruby the script will not run.

Swell.. 😐

How To: Apple Boot Camp 64-bit for Windows 7 on “unsupported” Macs

Do you own a Macbook Air or other modern Apple and want to install and use Windows 7 ala Boot Camp? If so, you may have encountered the dreaded “Boot Camp x64 is unsupported on this computer model” error dialog when trying to run the provided Snow Leopard Bood Camp setup.exe. Techulous has documented the workaround:

http://www.techulous.com/hardware/how-to-apple-boot-camp-64-bit-for-windows-7-on-unsupported-macs.html

Finding the Android Dev Phone 1 ROM Images

For some reason the ROM Images for the Android Dev Phone 1 have the links missing from the main ADP-1 download site. When you go to http://developer.htc.com/adp.html You’re greeted with a table of ROM images and file names but the links have been removed:

FirefoxScreenSnapz010.jpg

(You can click on the image to see the full-size version of the table.)

After some digging around I found that someone on the Android Developer List has found that the files are still on the website, only the links to them have been removed from the ADP-1 page. Creating the URL links are simple enough. You just start them with http://member.america.htc.com/download/RomCode/ADP and send with the file you want (i.e. ota-radio-2_22_19_26I.zip) The challenge here is that you cannot access those files directly, you have to be re-directed from http://developer.htc.com. If you’re a Linux or Mac user, this is solved with a simple shell script and the wget command. Modify the script for the ROM images that you want to download and you’re in business.

#!/bin/sh
IDIOTS1="http://developer.htc.com"
IDIOTS2="http://member.america.htc.com/download/RomCode/ADP"
wget "--referer=$IDIOTS1" "$IDIOTS2/ota-radio-2_22_19_26I.zip"
wget "--referer=$IDIOTS1" "$IDIOTS2/signed-dream_devphone_userdebug-img-14721.zip"
wget "--referer=$IDIOTS1" "$IDIOTS2/signed-dream_devphone_userdebug-ota-14721.zip"

If you’re a Windows user, you can accomplish the same thing if you have Cygwin installed: http://www.cygwin.com/


The script source for fetching the ROMs came from this discussion at The Android Developer mailing list. Thanks to Noah Tilton.