Thursday, December 19, 2013

Grails getting the current environment name

Suppose you have created your own custom environment ,for example, purposes of deployment.
You may at times need to get the value of the environment. To do so

import grails.util.Environment

println Environment.current.name

Monday, September 30, 2013

groovy # pass closure to method

In groovy one can pass functionality as one would pass variables to a method The output should look like this
## Params asdfasdf
#### No params
If you choose to pass a closure that requires paramaters then one would need o sourround the closure in curly brackets
doWith(4, {param "asdfasdf"})
Otherwise
doWith(5,noparam)

Thursday, September 12, 2013

Ammend the previous local commit

Just in case you make a commit and you want to amend it you can do the following
git commit --amend

Thursday, July 11, 2013

ensure rollback in grails services...RuntimeException

In grails it is advisable to have all your business logic(database updates) in a service method,so that when some goes wrong then a rollback is issued.

An example of the things that can go wrong is

  • A domain contraint is violated
  • An exception is thrown..caused by some weird thing or bad code
But you can also issue an explicit rollback. This is done by throwing an RuntimeException or any excepton that extends a RuntimeException.

Recently where I work, we tried to explicitly throw an Exception in a service, like so
throw

new Exception()

But a rollback was not issued because the exception thrown wasn't a RuntimeException.
It is paramount that a RuntimeException is thrown if you desire a rollback in your services.

Check if grails domain is dirty

Suppose you want to save a grails domain if it has been modified only. To get the list of dirty property name you will do this
objectInstance.dirtyPropertyNames

Monday, June 10, 2013

string map to actual #groovy map

Convert a string map representation to a groovy map, for further manipulation
def stringMap = "['a':['c':'true'],'b':4]"
def map = evaluate(stringMap)

#bashing multiple expressions

So to do a couple of cool stuff in bash use the [[ many-expressions ]] brackets not the [ expression ]
For example one can do multiple expressions
if [[ foo || bar || baz ]] ; then
  ...
fi
For more info look at this stackoverflow

if elif else fi #bashing about

When running a webservice one needs a couple of good scripts that make work easier.
I have been using bash scripts for just that..
Bash is one of the weirdest languages i have had to learn...stuff isn't that straight forward. I hade to google this stuff up
If [ conditional expression1 ]
then
 statement1
 statement2
 .
elif [ conditional expression2 ]
then
 statement3
 statement4
 .
.
.
else
 statement5
fi
I wont take all the credit, I got the info from HERE

Friday, June 7, 2013

adding stuff in bash

I just stumbled on a how to add stuff in bash
total=`expr $val_1 + $val_2 + $val_3`