Monday, March 9, 2009

Dirty scripting

Java permits both
new Object[][] { new Object[] { ... } }
and
new Object[][] { { ... } }
Suppose we wanted to transform the former to the more concise latter form. Naturally, going through all of the source files is not an option, so we use the tools at hand:
grep -lr 'new Object\[\] {' . | xargs sed -i 's/new Object\[\] {/{/g'
grep locates files matching the pattern (note that this command might introduce errors in case of:
Object[] wontCompile() {
return new Object[] { };
}
). -r tells grep to recurse into subdirectories and -l - to output only the filenames. Sed takes the filenames and performs a substitution writing result to the same file (-i flag).

Thursday, November 13, 2008

Javascript tagName and labels

First of all, tagNames are always UPPERCASE! Secondly, when an event listener (onclick) is registered to an element, containing a label with its 'for' attribute set to a valid input id, click on that label will result in two events being fired: one for the label and one for the appropriate input.

Tuesday, November 4, 2008

Are you using getters and setters?

Then use them everywhere. I mean equals, toString, compare and other methods, belonging to the same class. Failing to do so might backfire any time you add some logic to the setter/getter (and I know, that getters/setters are considered an anti-pattern by some, but that's another topic).

Saturday, October 11, 2008

Eclimd doesn't see your workspace

Add
-Dosgi.instance.area.default=path_to_the_workspace
to the eclimd.bat run parameters.

Wednesday, October 8, 2008

Ibatis nested resultmap/select memo

Ibatis v. 2.1 : when using nested resultMaps you must put sqlMap namespace before the actual resultMap name. When using nested select - namespace isn't needed.

JSON-lib memo

JSON-lib library for java v. 2-2-2-jdk15. Uses java string quotes (double quotes) when serializing JSON objects to string.

Monday, September 29, 2008

Struts 1: Action to DispatchAction

In order to convert Action to DispatchAction, change the action name from 'execute' to 'unspecified' and add a 'parameter="something"' attribute to action node in struts.xml.