Sunday, May 17, 2009

Moving to wordpress.com

It's been a while since I posted. I've been busy. But, I'll continue to blog. I will be moving the blog to wordpress.com under kopylenko.com domain name. Will see you there.

Wednesday, December 31, 2008

The year 2008 is done

That's it. The year 2008 has come to an end. Overall it was a very tough year - endless presidential election in the US (it felt like it), the global financial crisis, economic recession, etc. Personally, all of this didn't effect me that much (knock on the wood). Quite the opposite - it was more or less successful year for me:

  • Despite all of the political bullshit at work, I was able to go through it and successfully accomplish the given tasks, projects, etc.
  • I became a better Groovy and Grails hacker
  • I was able to finish and launch GrailsCrowd (which I really wanted to do)
  • I learned and therefore could "speak" Python, Erlang, and Scala
  • I started diving deep into FP (Functional Programming) via Erlang and Scala and started to appreciate its power and benefits
  • And last but not least, I became a better father!
My resolution for 2009 will be simple: I'd like to have a healthier lifestyle, work hard and care more for my family. Everything else will come.

Happy NEW 2009 YEAR!

Later...

Wednesday, November 26, 2008

Groovy script as a *nix command line utility

I was having some fun with Groovy the other day as I created quick and dirty simple script to find out the duration between 2 dates. I've always wanted a handy utility that could answer more or less precisely questions like 'how much time has passed since I bought my MacBook pro?' or 'how old was I when I moved to the United States?', etc.

So, without doing much research on what's available, I set out to use an excellent Joda time library in the Groovy script setting. And after 'shebanging' it (#!/usr/bin/env groovy) and installing it for example into /usr/sbin (provided that I have Groovy installed, $GROOVY_HOME set, and joda jar available ~/.groovy/lib), it's now available as a handy CLI utility where I could use it like this (how old was I when I started working at Rutgers): 'duration oct-9-1976 dec-9-2002' and the answer is: 26 years 2 months :-)

I like Groovy's seamless integration with Java and its libraries as well as 'low ceremony' approach such as simple script without 'main method noise' requirement, implicit availability of the args array, etc.!

There could be better ways to do this, but I had fun nevertheless :-)

Here's the script:



Later...

Thursday, September 18, 2008

Trying out Gist widget

Ok, I've been a user of Git distributed SCM system for a few months now. The Grails Crowd lives on GitHub as an open source project. I must say I've been pretty happy so far with Git and GitHub. Few months ago GitHub guys introduced 'Gist' - a GitHub backed directory of code snippets (yes, versioned in Git repo, so all the benefits of Git apply).

Here I'm just trying out an embeddable Gist widget:



When Gist will officially release an API, I might think about integrating it with Grails Crowd.

Later...

Monday, August 18, 2008

Grails Crowd has launched

After working on this project on and off for around 9 months (funny coincidence with pregnancy time frame :-) [life took precedence], I was finally able to finish and launch Grails Crowd - "the friendly online community (or directory) for Grails developers Worldwide".

I will most likely open source the code and let the community drive the innovation and the future direction of the site. I have pretty much decided that the home of the code will be GitHub :-)

Later...

Friday, July 18, 2008

Getting closer

As I'm getting closer to finishing up the essential code for GrailsCrowd, I noticed that I'm doing on the fly refactorings more seamlessly than I was able to do when I first started hacking with Groovy/Grails. And Groovy Closures are my friends these days :-)

Here's a small example from the GrailsCrowd code base - 2 simple controller actions to query for Grails projects by tags, only with the difference that the first action gets all the projects within a system for a specified tag (globally) and the other one gets projects for a tag for a specific member. Both actions operate on the Tag instance, so I refactored the common functionality of querying for Tags into a method which takes a closure:


class GrailsProjectController {

...
private def withTag(callable) {
if (!params.selectedTag) {
redirect(uri: '/notAllowed')
}
def tag = Tag.findByName(params.selectedTag)
callable(tag)
}
...
}


And then the above mentioned actions became:


class GrailsProjectController {

...
def findByTagGlobally = {
def total = 0
def projects = []
withTag {tag ->
if (tag) {
total = Tagging.countByTag(tag)
//Using CrieteriaBuilder here, so we could query by 'taggings' association
projects = GrailsProject.createCriteria().list(params) {
taggings {
eq('tag', tag)
}
} //Criteria builder
//Sort by name since GrailsProject implements Comparable and the name property is its natural order
projects.sort()

} //if
} //Closure
render(view: 'list', model: [projects: projects, navMenu: 'discoverNavigationByTag',
paginatingController: controllerName, paginatingAction: actionName, total: total,
menuContext: [tag: params.selectedTag]])
}

def findByTagForMember = {
def total = 0
def projects = []
def member = Member.findByName(params._name)
withTag {tag ->
if (tag) {
if (!member) {
redirect(uri: '/notAllowed')
}
total = Tagging.countByTagAndMember(tag, member)
//Using CrieteriaBuilder here, so we could query by 'taggings' association
projects = GrailsProject.createCriteria().list(params) {
taggings {
eq('tag', tag)
eq('member', member)
}
} //Criteria builder
//Sort by name since GrailsProject implements Comparable and the name property is its natural order
projects.sort()
} //if
} //Closure
render(view: 'list', model: [projects: projects, navMenu: 'memberProjectsNavigationByTag',
paginatingController: controllerName, paginatingAction: actionName, total: total,
menuContext: [tag: params.selectedTag, member: member]])
}
...
}


Also notice the use of GORM CriteriaBuilder which allowed to nicely query m:n 'Tagging' association class!

Keep Groovying.

Later...

Saturday, June 7, 2008

Programming with closures

Recently I caught myself thinking that my programming habits are changing while programming in Groovy. In particular, I started using closures more and more to clean up my code, make it more DRYer, e.g. by not just merely using existing closures provided by libraries such as GDK, GORM, etc., but by creating my own closures.

Here's a small example from GrailsCrowd. The idea here is to either 'accept project participation invitation' or 'reject project participation invitation'. So, in the Controller, I factored out the common code of retrieving the Member, Project, redirecting to the appropriate action afterwards, etc. to a private method which takes a closure, and calling that closure for the actual action of 'acceptance' or 'rejection':


private def withProject(callable) {
def invitee = freshCurrentlyLoggedInMember()
def creator = Member.findByName(params.creator)
def project = GrailsProject.get(params.projectId)
//Call the closure
callable([project:project,creator:creator,invitee:invitee])
redirect(controller: 'mailbox')
}

def acceptParticipationInvitation = {
withProject {projectMap ->
projectMap.project.acknowlegeParticipationAcceptance(projectMap.creator,
projectMap.invitee, params.messageId.toLong())
}
}

def rejectParticipationInvitation = {
withProject {projectMap ->
projectMap.project.rejectParticipationInvitation(projectMap.creator,
projectMap.invitee, params.messageId.toLong())
}
}


IMO, this makes code cleaner, reusable, and more maintainable. Also, this style of programming with closures kind of replaces good old Template Method design pattern.

Keep on Groovying, folks!

Later...