Tuesday, November 25, 2014

Getting started with grails Quartz jobs

Quick start in grails jobs using the grails Quartz plugin
   class MyJob {
       def grailsApplication

       def execute(context) {
               def myService = grailsApplication.mainContext.myService
               def domainInstance = MyDomain.get(context.mergedJobDataMap.get('domainId'))
       }
   }

Wednesday, October 22, 2014

Using HTML data attributes

For those who have always been hearing about data attributes and have never actually understood how to use them. Here is an article to help you get a start on using them

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes



Tuesday, October 21, 2014

How to start your grails integration tests

I always keep forgetting how to start writing my grails integration tests. I hope this helps someone

class TestISpec extends grails.plugin.spock.IntegrationSpec {
     def 'this should do that'() {}
}

Thursday, October 9, 2014

Getting unique commits in a branch ..well almost

To list unique commits in a branch
git log --first-parent --no-merges
For more details checkout http://stackoverflow.com/questions/5720343/using-git-show-all-commits-that-exist-only-on-one-specific-branch-and-not-a
Then you can format the output as follows
git log --first-parent --no-merges --pretty=format:"%H %s"
Then you get something like
3d6995f61c1359e44c98433bb5ed4251798002c3 My Commit

Wednesday, March 26, 2014

NoClassDefFoundError

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

Read more: http://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html#ixzz2x8LeYeww

Wednesday, January 22, 2014

Extract value from string using regex in java

So suppose you want to extract values from a string based on a certain regex pattern. The thing that i didn't know was that I needed to use () around the data I wanted to capture.


Output
http://home.com
56

I dedicate this post to all laymen out there, who get confused with coding and stuff

Listen for text changes on EditText

Assume you want to enable a button only if some changes have been made to a form. You can do this by using android.text.TextWatcher
Simply create a new instance of TextWatcher and implement the required methods
There you have it. For more info checkout http://developer.android.com/reference/android/text/TextWatcher.html

Tuesday, January 21, 2014

The magic of grep and sed and xargs

You want to get all files that have a certain string

grep -rl "ToMatch" <folder>

You then want to replace that string with another string

grep -rl "ToMatch" | xargs sed -i s/ToMatch/Replaced/g

The xargs command passes the values from "grep -rl "ToMatch" <folder>" to the sed command as arguments

For more info on how to use xargs look at http://unixhelp.ed.ac.uk/CGI/man-cgi?xargs

Friday, January 17, 2014

Delete values from a map through a loop

So you woke up today and you want to delete values from a map, as you loop through the map (For whatever reason). So you right this is groovy

Code
Output
[a,b,c]
Wrong !!!!
You actually get a ConcurrentModificationException.... hahaha :D <- This is me laughing at you. So you need to

Wednesday, January 15, 2014

Java String.equals versus == [duplicate]

String.equals("some string") checks the contents of the string
"==" checks if the object references are identical