Archives for Uncategorized

Print assembly for Java

The modern openjdk’s JVM is able to print assembly for generated machine code – see Oracle’s blog post. To start working with this option you need hsdis plugin, available here. Then put the downloaded library to the location your OS aware of. E.g. if you’re using linux all you need is to update LD_LIBRARY_PATH: export [...]

Tuning Intellij Idea

First of all consider changing idea.vmoptions. idea.vmoptions is a text file with a list of JVM settings, it’s usually found in the bin folder in the Idea installation folder. This file can be open in any text editor. The following settings increase performance drastically on Sun JVM 1.6: -server -Xms128m -Xmx512m -XX:MaxPermSize=250m -XX:ReservedCodeCacheSize=64m -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts [...]

instanceof vs Visitor

I always was curious on how effective is visitor pattern vs instanceof when it comes to detect whether the given base implements certain interface or not. I had 7 interface classes and visitor for all of these, and 7 concrete implementations, then I tested instanceof and visitor pattern on a large collection of randomly picked [...]

How to write and debug your own annotations processor.

This is a short but comprehensive guide on how to write and debug your own annotations processor (assuming you are using Java 6, should work on Java 7 as well). Create jar where your annotations processor will reside, say ann-proc.jar (Just define annotation processor class).You may want to add dependency to the JDK’s tools.jar in [...]

Block internet access for application in Mac OS X

There is a wonderful set of native utilities named “sandbox”. These utilities include service sandboxd that, for example, prevents newly downloaded applications from being started immediately. In order to block a particular application from accessing internet (but without turning off all the networking services) you may use “sandbox-exec” utility. First of all, create sandbox profile [...]

Replace autogenerated method bodies with certain default implementation

This is the sample on how to replace certain implementation of the method with the other one using regular expressions. // search pattern: \{[\w/;\s\|\.]+\} // replace to: \{\nthrow new UnsupportedOperationException\(\);\n\}

Javascript snippet: “asUtfCodes” function

Sometimes I need to include escaped string sequence to my code (mostly for unit tests), because clearcase (VCS I forced to use by my current employer) chokes when it encounters UTF-8 -encoded source code. In order to make my life easier, I wrote a small function that transforms a given input string to it’s escaped [...]

Succinctness is power

Quite an interesting hypothesis of Paul Graham: My hypothesis is that succinctness is power, or is close enough that except in pathological examples you can treat them as identical. It seems to me that succinctness is what programming languages are for. Computers would be just as happy to be told what to do directly in [...]

Hello world!

I wonder what this button does?