Excel to Wiki table converter

Tab separated table - Excel / Google Sheet to Wiki table converter



Input : Paste Tab-separated table data ( eg : row/column from Excel, Google Docs etc)

Output : MediaWiki formatted table





Source : GitHub

Logging levels - meanings and use

All the popular logging frameworks follow the similar convention and naming for log levels. There are five priority levels in use.

Order ( high priority to low):
  • FATAL ERROR WARN INFO DEBUG TRACE
Meaning and Use:
  1. debug to write debugging messages which should not be printed when the application is in production.
  2. info for messages similar to the "verbose" mode of many applications.
  3. warn for warning messages which are logged to some log but the application is able to carry on without a problem.
  4. error for application error messages which are also logged to some log but, still, the application can hobble along. Such as when some administrator-supplied configuration parameter is incorrect and you fall back to using some hard-coded default value.
  5. fatal for critical messages, after logging of which the application quits abnormally.
 Additionally, there are two other levels. They have the obvious meanings.
  1. ALL
  2. OFF

grails detecting environment - groovy & gsp code

Grails/Groovy working code snippet to detect the current environment (development, test, production, or your  custom). Custom environment are defined in config.groovy file.

Detecting Environment in GSP code :

Following checks if current environment is other than production.
    <g:if test="${env != "production"}">
        //your logic 

    </g:if>

Detecting environment in Groovy Code ( in Controller, Service, etc..), using switch-case comparison

        switch(Environment.current.getName()){
            case "development":
                //do your stuff 1
                break;
            case "test":
                //do your stuff 2
                break;
            case "production":
                //do your stuff 3
                break;
            case "my_environment":  // for custom environment : my_environment
                //todo:
                break;
        }

Simple comparison in groovy

if(Environment.current.getName()=="development") {
    //do your stuff
}

Grails - auto login in spring security

Consider a typical web application where you have multiple user roles (like SUPER_ADMIN, OPERATOR, VISITOR etc ) and you need to do login and switch between them frequently. It certainly consumes a lot of time if you do this manually. One simple solution would be to use the browser's password remember feature. But this would not be useful if you need to switch between different role.

Here, I am going to do show how we can setup this mechanism in Grails applications which uses Spring Security plugin.

If you are using Spring Security plugin then, by default you will have following names for html textbox for username and password : j_username and j_password. and you have login request url as http://localhost:8080/YOUR_APP/j_spring_security_check .

The required login script :

Groovy Grails - Dynamic Method n Variable name and invoking them

Groovy allows to use dynamic method name and variable name and invoke/use them.

Dynamic Variable Names

Groovy allows to use variable name dynamically. To test this lets introduce a variable  "dogname" to Dog class

class Dog {
def dogname
...
}

//Testing dynamic variable name
        def aDog= new Dog()
aDog.name="Hachi"
def prop="dogname"

println aDog."$prop" // prints Hachi

git- saving username password - credential.helper cache - how to

Isn't is interesting if there is an option in GIT to save your credentials for short time so that you don't enter your username/password repeatedly each time when you do pull/push? Yes! there is an option introduced in GIT since 1.7.9 (released on January 2012). This method is more secure than permanently saving your username/password in   .git  file of your git clone directory.

So, run the following command at the GIT console (git bash) :
git config --global credential.helper cache
This caches the credentials for 15 minutes ( 900 seconds) by default. If you want a longer timeout period (say3600 seconds), you can do the following :
git config --global credential.helper 'cache --timeout=3600'