Archive of articles classified as' "Uncategorized"

Back home

Grails build-test-data 1.1 released with new buildLazy functionality

2010/04/4

Version 1.1 of the build-test-data plugin has just been released.

It adds a new buildLazy method that will only create a new object graph if it can’t find an existing object that matches the build criteria specified.

Example:

    def a = new Author(firstName: "Ray", lastName: "Bradbury")
    a.save()
    assert 1 == Author.count()
 
    // Author table already has Ray Bradbury in it, finds existing record
    def bradbury = Author.buildLazy(lastName: "Bradbury")  
    assert 1 == Author.count()
    assert bradbury.firstName == "Ray"
 
    def newAuthor = Author.buildLazy(lastName: "Moore")
    assert 2 == Author.count() // creates a new record, no existing "Moore" author previously

I find this particularly useful for building testing data in the grails console. It allows me to do some quick setup of new objects and then concentrate on creating the code that I actually want to try out. Without buildLazy, I was always commenting out my creation code so that multiple executions of the test script didn’t create multiple copies of the same data (and potentially hit unique constraints issues that I had to screw around with).

Now, I no longer need to worry about commenting out the creation code after running it the first time.

Example:

def u = User.buildLazy(ssn: "123-456-7890") // User.ssn has unique constraint
u.foo()
u.bar()
u.baz()

Before buildLazy I’d need to comment out the user creation and replace it with a user.findBySsn. Now buildLazy does the creation and later finding for me. I can concentrate on making foo/bar/baz do what I want them to (the reason I opened the console in the first place).

2 Comments

Updated grails autocomplete script for zsh

2010/03/2

A couple of years ago, I created a grails auto-completion script for bash and zsh.

Since then, I’ve completely abandoned bash, in favor of zsh (which I consider to be the superior shell) and I’d been getting annoyed at a few issues in the last grails autocomplete script.

I finally got motivated to make some enhancements to it. Including support for grails 1.2 plugin scripts (1.2 moved the plugins into the ~/.grails directory), and support for test class name autocompletion (very useful for grails test-app).

To get it working (assuming you’re using zsh), you can either add the contents of my zshrc_grails_compinstall to your .zshrc file, or you can switch over to using my full zshrc setup, which has a number of nice features that I’ve collected over the years. I’ll also continue to update this as I think of new tricks.

After getting it installed, just type “grails” followed by a space and then hit tab. It will show you a list of all of the potential grails scripts for the application that you’re in. It’s aware of the version of the current app, as well as it’s application name based on the contents of application.properties, and also will include any scripts for the plugins you have installed in that app in ~/.grails/GRAILS_VERSION/projects/APP_NAME/plugins (in addition to the scripts in ./scripts, $GRAILS_HOME/scripts and ~/.grails/scripts).

After you choose your script (such as grails test-app hit space again and it will show you all of the test classes, with the full package for the class, under your test directory.

No Comments

Using iWork Numbers.app AppleScript to Sum Columns For All Tables on a Sheet

2010/02/7

Overall, I’m pretty happy with Numbers.app (part of Apple’s iWork suite) as a replacement for Excel. It’s considerably cheaper and has lots of user interface tweaks to make it more pleasant to work with.

One of these changes is that each sheet can actually have multiple tables on it, and these can be arranged independently on the same page. This prevents the problem that happens in excel where you have multiple sets of data you want to see at the same time, but the cell/row sizing for one set of data affects the data in the other set that happens to be on the same row.

I’ve been leveraging this for a one-off personal project and I had a need to sum up all of the data in the 2nd column on all of the tables within a particular sheet.

This brought me to AppleScript, Apple’s scripting language that’s used to drive applications.
Read the rest of this article »

1 Comment

Updated wordpress

2009/09/6

I’ve just switched hosting providers from slicehost to a reserved EC2 instance. I also upgraded from a really old version of wordpress to wordpress 2.8.4. I’ve been meaning to do this for a while now, but wanting to avoid yesterday’s worm prompted me to do it this weekend rather than next.

Let me know if you see any issues or broken links.

1 Comment

SelectorGadget makes CSS selectors really simple

2009/02/26

Today I’ve run across a few mentions of SelectorGadget. First when John Resig tweeted about it and now it’s at the top of Hacker News.

It’s worth all the attention it’s getting. It makes working with CSS selectors, and especially scraping websites, dead simple. This is the gateway into

The kind of information that it gives you can be fed into jQuery (or other CSS selector aware API’s like nokogiri or hpricot for Ruby or beautiful soup for Python) to easily get the right syntax for querying the DOM.

Check out the author’s screencast on the front page. He very quickly demonstrates how easy it is to use SelectorGadget to modify the scope of the intended selector.

P.S. if anyone is aware of any Groovy/Java parsers that can take CSS 3 selectors, I’d love to hear about them. Some quick googling isn’t showing anything.

2 Comments

StackOverflow.com

2008/09/23

I’m pretty impressed with the community that’s forming over at StackOverflow.com (Jeff Atwood and Joel Spolksy’s new developer focused Q&A startup).

I just asked a fairly detailed question about working with mercurial. Something that wasn’t (obviously) covered on the mercurial wiki, through googling, or in the mercurial handbook, and got a quality answer back in only 8 minutes. That’s fantastic for a general purpose development website and is a great start after only being open for a couple of weeks.

They’ve started up an interesting reward/karma system over there where they award badges (similar to achievements on Xbox360) for a bunch of different positive behaviors. A nice little token system that’s paired with “power-ups” at different point levels. It’s easy to get the first few badges with just a little participation on the website, and I can see how certain personality types that are common in engineers would get big rewards out of collecting these.

No Comments

Ubiquity – interesting looking command line for Firefox

2008/08/26

Just ran across Ubiquity over on on waxy.

It’s an alpha Firefox plugin that’s attempting to be a command line for the internet. It reminds me a little of yubnub, but quite a bit more powerful as it’s available on every page and is context sensitive.

Essentially, it has a set of built in commands (that you can add to an extend) and it’s aware of the current browser context, so if you have something highlighted, it can act on that subset of the current page.

Previously, I’ve been a heavy user of Firefox smart keywords, which allow you to assign aliases to bookmarks and type the aliases in the location bar. I’ve created smart keywords that allow me to search wikipedia, amazon, imdb and the dictionary. Ubiquity has all of these, plus a lot more built-in.

I’ve only been using it for a little bit, and there are some rough edges, but I think that there is quite a bit of promise here as well and thought that there might be a few other keyboard jockeys out there that would appreciate what Ubiquity is trying to do.

3 Comments

Pitfalls with Mercurial, ZSH and SSH

2008/07/29

I ran into a couple of issues trying to clone a mercurial repository over ssh tonight. I’m documenting the solutions here in case they’re useful for anyone else (or me when I forget what I did in 6 months :).

The first issue was that I’m running ssh on a non-standard port and the repository does not reside in my home directory.
Read the rest of this article »

1 Comment