Archive for November, 2008

Nov 30 2008

svnant 1.2.1 released

Published by jfrank under svnant

I fixed a few bugs in this release. One was dealing with remote info requests against files. A couple others were from updated subversion 1.5, and new svnant dependencies. I added a cleanup task, contributed to Oleg Byelkin.  Writing the tests for that was a little bit of a trick due to the fact that cleanup (in order to be succesful) needs to have a messed up working copy… so I settled for writing a lock file to the .svn/ and calling it succesful if it removed it.

svnant-1.2.1.zip

2 responses so far

Nov 29 2008

groovy code needs viagra (it keeps shrinking)

Published by jfrank under groovy

The other day I was talking to some coworkers about a groovy method that I had refactored. It was one that I had pulled the guts out because I needed two forms of the same data. So I added getDaySizeList which contains most of the logic, but I still needed to get a rollup sum from getDuration for another part of the application.

I knew groovy collections supported an “each” function that takes a closure. Groovy syntax allows for omission of parentheses when there is at least one argument, so it can look like this:

myCollection.each{ closure } not myCollection.each({ closure })

it would also allow you do things like:

myCollection.add object  (look no parens!)

which creeps me out right now, so I’m not going to think about it.

I digress… Here is my method, that I thought was a short implementation:

int getDuration(){
	int hours = 0;
	getDaySizeList().each{dayHourMap -> hours += dayHourMap.hours}
	return hours
}

I was excited, no visible loop, just something to do “each” for the members of the collection, drilling down into the hours property of the map in each collection item, summing them into a waiting “hours” int, then returning it. Slick.

Barney then replied that I should have (duh) used the sum closure-taking builtin in groovy… which turns the above method into this:

int getDuration(){
	return getDaySizeList().sum{it.hours}
}

“it” is the default single argument to the closure.  You can see I only kept the end of the closure, to the right of the former +=.

Magic.

One response so far

Nov 28 2008

Vacation ala Google Calendar

Published by jfrank under groovy

I’ve been building a railo-hibernate-groovy fto (flex time off) vacation app in my “for fun” time at work and home. The goal is to get an application that can replace the arcane paper based system that my company currently uses.

I have most of the front end of the app done, but I needed a good calendar view to show the events. I decided I would use google calendars, so I wrote a little calender wrapper. Here is a snippet of the test driver class. GoogleCalendar is mine, the *Entry items are part of the api.

This is groovy code, not java…

//omitting calendar name assumes the default users calendar
GoogleCalendar gc1 = new GoogleCalendar(username,password)
// adds an event 3 days in duration starting 3 days from now, with title and desc here
CalendarEventEntry entry = gc1.insertEvent("DELETE ME FTO","FTO",new Date()+3,new Date()+6)
gc1.deleteEvent(entry)

println("List of users owned calendars:")
for (CalendarEntry cal : gc1.getCalendars()) {
	println("\t" + cal.getTitle().getPlainText());
}

//this demonstrates the mixed constructor that is allowed in the groovy wrapper.
//i define a calendar name, and it looks it up and sets that as the calendar to work with
GoogleCalendar gc2 = new GoogleCalendar(username,password,"Web Services Team")
//adds an event 3 days in duration starting 2 days from now, with title and desc here on the WST calendar
gc2.insertEvent("Joshua FTO","FTO",new Date()+2,new Date()+5)

Such fun.

This will allow me to have a nice visual display of everyone’s scheduled vacation calendar, and have an easy way to share it with other apps/users such as our wiki.

No responses yet

Nov 28 2008

python packaging

Published by jfrank under python

Python packaging is a pain in the ass. There are some tools to make it easy, so easy in fact that it becomes even worse…

easy_install is the easiest thing since sliced bread. What does it do? Everything. Its so magic it probably installs itself recursively just for fun.

You want a package?

Ok just type this: easy_install sqlalchemy (for the awesome ORM package for python)

It magically goes and finds sqlalchemy, and installs it INTO your system python installed path.

Why is the standard assumption that if I want to use a python package that is say a dependency for my project, that I want to INSTALL IT INTO PYTHON running on my system?

What kind of crazy idea is this? It causes all kinds of issues. The first and most obvious is: What If I have two programs that expect different versions of a given package? Since the packages are installed in to the runtime and not my app, you have to know about this issue and work around it.

If packages were managed the java way, the assumption would be that I want to install the package in the app that I am working on, not into /systemjdk/extensions/somePackage

The only argument FOR doing it this way that I can think of is saving disk space. Disk space is cheap.

/rant.

Ok so honestly, can anyone tell me why this is?

2 responses so far