May 27th 2008 Syntactic Sugar in Groovy and Ruby

Over on the RailsEnvy blog (the guys who made the “Rails vs. X commercials” last year), there’s an article that highlights some of the nice syntactic sugar that Groovy has that’s currently not available in Ruby.

I actually came to Groovy/Grails after working with Ruby/Rails for about a year. Both languages and framworks have their strengths and it’s nice to see cross-pollination of good ideas going both ways. From the comments, it sounds like Ruby 1.9 is getting some of the features that we’ve had in Groovy for a while.
Read More »

4 Comments » Posted by tednaleid / grails and groovy

May 19th 2008 Groovy: Don’t Fear the RegExp

Some people, when confronted with a problem, think “I know, I’ll use regular expressions!”
Now they have two problems. — Jaime Zawinski

There is a common and well-earned aversion in the Java world to regular expressions. Prior to Java 1.4, regular expressions weren’t even part of the core language. Post 1.4, using regular expressions is still a painful task of working with Pattern and Matcher objects. Lots of typing is involved to make anything happen. It’s difficult enough that most Java devs don’t end up using them enough to actually remember how to read a regular expression, and they need to dig up the JavaDocs (or cut and paste an old example), every time they want to use them.

This aversion has persisted into the Groovy community to a level that I haven’t seen in other dynamic scripting languages like Ruby, Python, and (obviously) Perl.

The current regexp docs that pop up when doing a google search are all outdated and don’t use any of the best techniques that are available in the groovy 1.5.X and 1.6-beta code that is now available. The recent Groovy Recipes book doesn’t have an entry for regular expressions in the index, and I was unable to find a single example of a regular expression in the entire book.

This is unfortunate because Groovy makes using regular expressions much easier than in Java. Under the covers, you’re still working with the same old Java Pattern and Matcher objects, but the Groovy syntax and additions to those classes are pleasant to work with.
Read More »

10 Comments » Posted by tednaleid / grails and groovy and unit testing

May 9th 2008 Top 3 Shortcuts for the Terminal

As my coworkers know, I’m a keyboard shortcut junkie. It’s a problem (and I need help), but I’d rather give you a taste of what I’ve been smoking and drag you down with me :).

Why only 3? Because people don’t learn a couple of pages of keystroke combinations at a time. But with only the 3 of the best keystrokes, there’s a good chance I’ll get you hooked and you’ll seek out some more.
Read More »

1 Comment » Posted by tednaleid / command line and osx and shortcut

May 7th 2008 What methods does my Groovy/Grails class have?

If you’ve ever wondered what methods a groovy class has available for you to call, all you need to do is ask the metaClass:

"foo".metaClass.methods*.name

Result:

["equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", "wait", 
"wait", "charAt", "codePointAt", "codePointBefore", "codePointCount", "compareTo", 
"compareTo", "compareToIgnoreCase", "concat", "contains", "contentEquals", 
"contentEquals", "copyValueOf", "copyValueOf", "endsWith", "equals", 
"equalsIgnoreCase", "format", "format", "getBytes", "getBytes",
 "getBytes", "getChars", "hashCode", "indexOf", "indexOf", "indexOf", 
"indexOf", "intern", "lastIndexOf", "lastIndexOf", "lastIndexOf", "lastIndexOf", 
"length", "matches", "offsetByCodePoints", "regionMatches", "regionMatches", 
"replace", "replace", "replaceAll", "replaceFirst", "split", "split", "startsWith",
 "startsWith", "subSequence", "substring", "substring", "toCharArray", 
"toLowerCase", "toLowerCase", "toString", "toUpperCase", "toUpperCase", 
"trim", "valueOf", "valueOf", "valueOf", "valueOf", "valueOf", "valueOf", 
"valueOf", "valueOf", "valueOf"]

There’s a lot of duplication in there, and the order is random, so I’ll often fix that like this:

"foo".metaClass.methods*.name.sort().unique()

Result:

["charAt", "codePointAt", "codePointBefore", "codePointCount", "compareTo",
 "compareToIgnoreCase", "concat", "contains", "contentEquals", "copyValueOf", 
"endsWith", "equals", "equalsIgnoreCase", "format", "getBytes", "getChars",
 "getClass", "hashCode", "indexOf", "intern", "lastIndexOf", "length", "matches", 
"notify", "notifyAll", "offsetByCodePoints", "regionMatches", "replace", "replaceAll",
 "replaceFirst", "split", "startsWith", "subSequence", "substring", "toCharArray", 
"toLowerCase", "toString", "toUpperCase", "trim", "valueOf", "wait"]

Read More »

4 Comments » Posted by tednaleid / grails and groovy and shortcut

May 1st 2008 Using Mercurial as a “super client” for Subversion

There’s a blog post by one of the subversion developers talking about the future of subversion in a DVCS world.

I agree with parts of the post (and many of the comments) that subversion will continue to be around for a long time, but that more and more developers will start using tools like mercurial and git as a “super client” for a normal centralized version control repository.

Read More »

3 Comments » Posted by tednaleid / command line and grails and osx and shortcut

Apr 26th 2008 Unminimize Windows on OS X

There’s a tip over on lifehacker that shows how to open a new window for an application that has no windows currently open by cmd-tabbing to it and then holding down the option key before releasing command.

This didn’t seem like that great of a tip to me at first, because cmd-N brings up a new window in just about any application that this will work for. Then I noticed the first comment where the poster noted that holding option down will also unminimize any minimized windows for that application. Something that I didn’t previously know how to do in native OSX after many google searches.

The native ways of using the keyboard to get it unminimized that I knew of were either kludgy (ctrl-F3 to select the dock and then using the arrows to find the minimized app and hitting return), or required an external app like Witch.

I’ve gotten into the habit of hiding windows (cmd-H) rather than minimizing, but this might get me to start using minimize again.

1 Comment » Posted by tednaleid / osx and shortcut

Apr 23rd 2008 Converting wordpress blog from wordpress.com to slicehost slice

I just finished the conversion over from a wordpress.com hosted blog to a wordpress blog that I’m running on a slicehost slice.

I think that it’s good to maintain your own linux server and get your hands dirty from time in Apache rewrite rules and php code.

The biggest reason for the switch is that the wordpress instance on wordpress.com completely mangles pasted grails and groovy code. It tries to make things pretty by changing a double dash to an mdash, single dashes to an ndash and double quotes to “smart” quotes (an oxymoron if there ever was one). Not to mention the manual &gt; and &lt; that you need to enter instead of > and <. These insidious changes make pasted code worthless and painful for readers to use.

After struggling with trying to get the formatting working correctly for a few weeks, I decided to host my own blog and use the great wp-syntax plugin.

I did need to do some reformatting on my old posts (as I don’t need to encode things anymore) and I believe that I have everything fixed now.  Let me know if you run across anything I’ve missed in the conversion.

No Comments » Posted by tednaleid / command line and grails and groovy

Apr 3rd 2008 Monitoring HTTP traffic to debug your Grails application

I’m often surprised when I run across developers who don’t have a variety of HTTP traffic monitoring apps as an integral part of their toolkit. When doing Grails development (or any web development really), being able to see the actual information that is going over the wire is invaluable.

Firebug

These days, more and more people are familiar with the amazing Firefox plugin Firebug. It allows you to view request and response information along with many other tricks.

Read More »

7 Comments » Posted by tednaleid / command line and grails and osx

Mar 31st 2008 Using Gant to execute a groovy script within the Grails context (updated)

In a previous post I showed a script that I had created to allow the execution of a groovy script within a grails application context (including access to domain objects, controllers, services, etc). A couple of people reported a problem with the script where they were getting lazy initialization exceptions. I finally tracked this issue down to one where many-to-many relationships are being used between two domain classes.

Here is an updated script that fixes this issue by setting up the hibernate session in the Gant script.
Read More »

17 Comments » Posted by tednaleid / command line and grails and groovy

Mar 25th 2008 Autocomplete Grails Script Names in bash/zsh

Jesse over at Refactr posted a nice tip about using tab completion for the ssh command. It grabs host names and IPs out of the ssh known_hosts file.

That got me to thinking that it would be pretty useful to have tab completion of Grails commands available. At my company, we’ve written about 20 custom Gant scripts and it can sometimes be a problem to remember their names. Running “grails help” often takes too long, so I probably ls scripts once a day or so to remind myself if it’s clean-db or clear-db.

I did a quick google search and found that Scott Davis posted some instructions about a year ago (originally by Doyle@DoyleCentral).

It was a good start, but there were two issues I had with the solution. The first is that it only worked in bash (I prefer zsh) and the second is that it used a static list of script names stored in the GRAILS_HOME directory. Any new scripts, or app specific scripts would need to be manually added to the static list.

Grails Gant scripts can exist in 4 possible locations:

  • $GRAILS_HOME/scripts
  • $USER_HOME/.grails/scripts
  • $PROJECT_HOME/scripts
  • $PROJECT_HOME/plugins/*/scripts

After some playing around, I was able to come up with a bash script that allows for real-time completion of all four potential script repositories. $PROJECT_HOME is considered to be the current directory, so if you’re not in a grails app, you’ll only see completion scripts for the first two.

Read More »

6 Comments » Posted by tednaleid / command line and grails and osx

« Prev - Next »