Thursday, November 8, 2012

Eclipse Refactoring: Delete getters and setters

Delete getters and setters
Deleting getters and setters isn’t as straightforward as just deleting the field in the editor. However, you can delete a field and its getters/setters from the Outline view.
Open the Outline view (Alt+Shift+Q, O), select the field you want to delete and pressDelete (or right-click, Delete). Eclipse will ask you whether you want to delete the getters/setters as well. Just choose Yes To All and they will be removed.
You need to have fields visible in the Outline view to use this feature (ie. untoggle the Hide Fields button ).
You can select multiple fields simultaneously. And you can delete individual getters/setters (excluding the field) by just selecting the getter/setter and pressing Delete.

Tuesday, November 6, 2012

Windows: find and kill process with a particular port


netstat -ano displays all the tcp and udp process with assinged process id's.
To get a process with a particular port (say 8080) use
netstat -ano | findstr 8080
This would display something like

here 82360 is the PID. Now to kill this process use
kill -f 82360
You can verify if the process has indeed been killed by executing netstat -ano | findstr 8080 again

Friday, September 14, 2012

IPTools

All IP tools (ping, traceroute, reverse dna lookup, IP routing, resolve host etc.) at a single place
http://www.iptools.com/

Monday, September 10, 2012

Groovy Tip: append list

Groovy provides plus method to append a new list to an existing list at a specified index

public List plus(int index, List additions)
e.g.
def items = [1, 2, 3]
def newItems = items.plus(2, 'a'..'c')
will result in [1, 2, 'a', 'b', 'c', 3]

Tuesday, September 4, 2012

Tip: Dynamically execute a groovy script



You can execute a dynamically generated groovy script or a script stored in a text file or variable using GroovyShell. See example below


def script = ''' def x = 'my dynamically' def y = ' executed script' return x << y ''' def shell = new GroovyShell() def result = shell.evaluate(script) println result
The above script would print "my dynamically executed script" If you want to pass variable to your script, you can make use of binding variables. See below

def script = ''' def code1 = """${crypto.code1}""" def code2 = """${crypto.code2}""" return code1 << ' ' << code2 ''' def crypto = [code1:'my dynamically',code2:'executed script'] def shell = new GroovyShell( new Binding(crypto:crypto) ) def result = shell.evaluate(script) println result
For those who are new to groovy operator << is for creating StringBuffer