Shortcut to Groovy on Windows

I frequently find myself wanting to reach for my favorite toy when I need to do something ad-hoc. Whether its iterating local files and echoing their paths to the end of a text document or scanning my Music folder to pull out all of the “.m4a” files. No matter what the job I always have the same reflex to reach for my toy. It always feels just out of reach so I have to stretch a little to get it. Hi, I’m Cliff. You’re here because you played with toys when you were younger. Maybe your toys were cooler than mine. Maybe your family could afford the entire Voltron set whereas we could only buy the blue lion. Maybe your toys are rusty now and maybe my toy is better than yours. My favorite toy these days is Groovy. Now that I’m spending more time on Windows (XP not Longhorn, not Vista, not 7, just reliable ol’ XP), I’ve gotten used to the “open command here” power toy that puts a command prompt pointing to the selected folder in Explorer. Lots of times I use this and then run “groovyConsole”. (Recently I’d been experiencing %Path% issue so its been a little more complicated but we’ll save that for another post.) I’m going to share my latest little shortcut/tip with you.

Run Groovy Here
The same way the Cmd Here will point a command prompt to a folder I hack the registry to get Groovy to launch in whatever folder you right click in Explorer. Assuming you have Groovy’s bin folder in your %Path% use these steps.

  • Hit WinKey+R and type regedit in the run dialog.
  • drill into the path HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell and create a key called “RunGroovy” without the quotes.
  • Double click (or edit) the Default entry and add whatever text you want to show in Explorer’s right mouse menu. I use “Run Groovy Here” but you could use “Format C:”, “Hack The White House”, “Legalize the Herb” or whatever strikes you as appropriate.
  • Create a key within that key (right clicking under the default entry) and name it command.
  • Use the following in the default entry: cmd.exe /c “cd %1 && groovyConsole”

The change takes effect immediately and you may now poke around your file system opening a Groovy console in random locations. Why should you care? Well, for starters, its a quick way to start scripting over a particular directory. All of your objects can be coded relative to the folder you launched from. So if you run it from “C:\Documents and Settings\Clifton\My Documents\My Music” you can write an easy one-liner that iterates your mp3 collection like so:
new File(“.”).eachFileRecurse { if(‘mp3’)) print it + ‘\n’ }

But I write mobile??!! I don’t know Groovy!!!
All the more reason to love Groovy! Assuming you’ve spent a good amount of your time with J2ME and pre-processors you already know Groovy. Install it from the home site, open the Groovy Console and start writing Java code. The syntax starts off roughly 90% the same as Java! You just have to use regular 1.5 Javadocs instead of MIDP2 and/or CLDC Javadocs which a very similar in the available classes. The better news is that you get a refreshing break from the restrictions of J2ME as you get a richer API and way more features. So what can you use it for since It doesn’t run on the phones yet? There at least a dozen every day tasks that would be easier managed in Groovy. A batch image processor that finds files locally and runs them through another program then stages them in your J2ME project is one example. A deployment script that takes your compiled source, logs into a remote server then pushes the MIDlet to a running OTA server is another. You could even write a script that launches an emulator under a virtual machine hosted in Parallels or VMWare and points it to your compiled MIDlet, if you were a Mac user. The possibilities are endless.

Whaevert happened to Max Headroom?

Now I’m starting to “get” the Twitter thing. I’ve been following another trending topic #whateverhappenedto and posting a few of my own. I started catching flashbacks. Saturday morning cartoons, Sunday afternoon Karate shows, Poltergeist, Garbage Pail Kids, The Last Dragon… all of it flashing before me. Hi, I’m Cliff. You’re here because you wanna know what happened to Max Headroom. Maybe you had something to do with his disappearance. Whatever the case I know you were at least born in or before the mid 70s as that would make you a child of the 80s. One of the easiest ways to confirm this fact would be to mention, out loud, any two consecutive days of the week. If you are from my era then you would have the Happy Days theme song stuck in your head for the remainder of the day.

Doesn’t Max remind you of Joe Mchale? Don’t act like it’s just me!

XCode orange breakpoints???

I waste more time not knowing the details behind XCode. I’m playing with some basic image drawing code and trying to figure out why my custom UIView doesn’t appear on screen. Naturally I click the gutter in the drawRect method to set a break-point. XCode moonwalks right over the breakpoint each time! I try all different kinds of varaitions of my custom drawing, both overriding UIImageView and manually adding it to another view. Each time XCode does a hop-scotch over the drawRect breakpoint. I only notice that the break point turns orage when I run the program. I finally figure out that I had a type-o in a custom graphic file name causing it to appear like nothing was happening. Still XCode ignores my breakpoint.

Because I’ve seen this behavior before I now know my code is begin executed even though XCode doesn’t honor my breakpoint. What I really need to know is why does XCode sometimes ignore breakpoints? What is the significance of these orange breakpoints? As of now there’s nothing I can do to set the break-point except for checking the checkbox in the breakpoint manager dialog. Why does this happen? Why is my IDE clowning me?

Found the answer here. In short, XCode sometimes gets its symbol references confused. To rememdy the problem you can either disable “Lazy Loading of Symbols” in the debug preferences or delete the file from XCode (just remove the reference not the actual file) and re-add it.

#Songsincode – It was fun while it lasted

Activity seems to have slowed significantly on the #songsincode trend on Twitter. It’s just as well since we all have day jobs and need a lot less distraction. I posted a few of my own. For those of you that didn’t figure them all out here’s the expanded list:

Take out the paper and the trash! Or you don’t get no spendin’ cash!
-(double) get {return getpaper && trash == taken_out ? spending_cash : nil} #songsincode

Stayin’ alive, staying alive! Ah-ah-ah-ah…
it=new Thread(go); try{it.start();} catch(InterruptedException e) {it.start(); out.println(”ah-ah-ah-ah” + it.isAlive());} #songsincode

Stayin’ alive, staying alive! Ah-ah-ah-ah…
foreverTask = new Thread(this); while(foreverTask.isAlive()) {System.out.println(”ah… ah… ah… ah…”);} #songsincode

Everybody dance now! Let the rythm take control, let the rythm move you
everybody.each { Date()); } rhythm.take(new Control()); rhythm.move(you); #songsincode

Whitney Houston: If I should stay,
I would only be in your way.
So I’ll go, but I know
I’ll think of you ev’ry step of the way.

if(i.shouldStay()) yourWay.contains(i); else { i.go(); for(eachStep : theWay) i.know(i.hasThoughtsOfYou); } #songsincode

Kriss Kross: some of them try to rhyme but they can’t rhyme like this 4x
4.times{ someOfThem.each { them -> assertFalse this.rhyme.compareTo(them.tryToRhyme()) : “can’t be done”} } #songsincode

Seal: I compare you to a kiss from the rose on the grey. Ooh, the more I get of you the stranger I feel… yeah!
[@”you” caseInsensativeCompare:@”a kiss from a rose on the grey”]; while([self get:@”you”]) {NSAssert([self feelStranger]);} #songsincode

Notorious B.I.G. If you got a gun up in your waist please don’t shoot up the place
Cause I see some ladies tonight who should be havin my baby

if(you.gunUpInYoWaist()) {please {shootUpthePlace(NO)} } else { ladies.each{ i.see it.canBeHavingMyBaby() } } #songsincode

Michael Jackson: C’mon with the force don’t stop! Don’t stop ’til you get enough!
MJ RIP: while(true) { if(you.getEnough()) break; else keepOnWith(THE_FORCE) } #songsincode

Bobby Brown: Every little step I take, you will be there every little step I make, we’ll be together…
2.times{ [1..99].step {assert you.willBeThere() && me.isTogetherWith(you)} } #songsincode

R. Kelly: I believe I can fly
I believe I can touch the sky
I think about it every night and day

thinkAboutIt = {i.setBelief({ assert i.canFly() && i.canTouch(getSky())})} nightsAndDays.each { thinkAboutIt() } #songsincode

Is there a groovy way to do this in ObjC?

You gotta be kidding me!!! I’m writing some code TDD style for a change. I’m trying to do this in an X-Code iPhone project, knowing all too well the pain of Objective-C verbosity. I get to the point where I wanna load a test resource. Because there’s no getClass().getResourceAsStream in Obj-C iPhone land I’m reduced to this:
+(NSData*) loadTestResourceData:(NSString*)resourceName
NSRange range = [resourceName rangeOfString:@"." options:NSBackwardsSearch];
NSString *file = [resourceName substringToIndex:range.location];
NSString *ext = [resourceName substringFromIndex:range.location + 1];
NSString *path = [[NSBundle bundleForClass:[MyTestSupport class]] pathForResource:file ofType:ext];
return [NSData dataWithContentsOfFile:path];

There has got to be justice here! I miss the days when I could post a question on Nabble saying, “Is there a groovy way to do this? [code-snipet]” At any rate, I’m really upset because I can’t get CoverStory gcov stuff working with my iPhone projects. I don’t particularly care about test coverage but I did find some good usage for coverage tools. Do you do iPhone stuff? Have you used CoverStory? Can you help?

Blackberry Device Debugging… Take 5

So I finally got the debugger attached to a Blackberry simulator. I can step through simple hello world apps in most simulators. I can’t debug our main app yet. I figured out how to hack a user supplied jad into a Blackberry project created with the Eclipse plugin. Its not straight forward. You can’t just add a Jad to the project. You can’t use the import command. You have to manually edit the “.jdp” file. I only know to do this because I remembered the rapc command line syntax. I also learned from my earlier JDE hacking, how to edit this file to add additional files to the project. I’m having trouble getting something more complicated loaded on the Storm simulator. It must be because I didn’t add the 4.7 component pack. Instead I tried to change the library variable created by the 4.5 pack to point to an existing net.rim.api.jar that I pulled out of a JDE 4.7 install. It’s late and the downloads for the rest of the component packs are taking forever. Why does the Blackberry update site want to authenticate you once for each component pack you download?

CoreAudio Conflict with iPod

I don’t have a lot of time to blog but I gotta get this out. I’d been playing with streaming audio in an iPhone app I wrote when things suddenly stopped working. It was the weirdest experience I ever had. I made a minor change pulling my audio from a URL which I reverted and still it wouldn’t work. It had been fully functional the night before and this left me puzzled. I tried rebooting my phone, still nothing. I went back to some earlier tutorials which all stopped working. My last effort was to try a video tutorial which played without sound. For some unknown reason I decided to plug in my earbuds and that’s when I discovered the iPod was paused in the background. Stopping the iPod allowed all the other apps to function once again. Heads up to you if you’re doing any work with Core audio or even the AVPlayer because it too is subject to the same behavior. The scariest part is that I had just fixed two major bugs last night and had intended to do an ad-hoc demo in a meeting which was luckily rescheduled.