Monday, November 22, 2010

[Java] What will be printed to a console?

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.remove(1);
System.out.println(list);

Thursday, November 18, 2010

Note for starting new Eclipse workspace

  • Import Formatter.
  • Customize Save Actions.
  • Set text editor "spaces for tabs" and "displayed tab width".
  • For MacOSX, change "Content Assist" short-key.
  • Set content assist to help import favorite static members.

Monday, November 1, 2010

[Java] Jars inside Jar

Jar that contains multiple jars inside is not support directly by Java. There are some workarounds on this.
  • Put jars in to jar as ordinary files then load them with your own customized classloader. There is a tool such as One-JAR™ but some people told that it causes performance problem (I have not try this).
  • Extract jars to .class and pack them together to a single jar. You can archive this easily with Ant's Zip Task
For me, I choose the second approach. There are more workarounds in reference links below.

Java: Easiest way to merge a release into one jar-file
Is it possible to package all the jar dependencies in one big jar ?

Sunday, October 31, 2010

Ubuntu RAR package file name character encoding problem

In my Ubuntu (currently version 10.10), package named "rar" has encoding problem with file that has file name in Thai. But for package named "unrar" there is no problem.

Saturday, September 18, 2010

Graceful OSX Shutdown from command line

If you use shutdown -h now running GUI programs will be forced to close. To tell them to close use
osascript -e 'tell application "System Events"' -e 'shut down' -e 'end tell'
Credit :

Thursday, June 17, 2010

Hg - How to combine many dirty commits to one

You can also make dirty research branch and remove it when done in Hg. Credit to Concatenating multiple changesets into one

The concepts are
  1. Jump to a changeset that is your last stable(good) changeset with command 'update'.
  2. Use command 'revert' to the last changeset of dirty branch*.
  3. Commit reverting, this will produce new head.
  4. Remove old head with command 'strip'** or pull from other repository the new head with command 'pull -r' and delete this repository.
* The Branch in this context means any branches in Hg graph does not mean to only Hg named branch.
** Strip is an Hg extension.

Monday, May 10, 2010

VIM - How to format and syntax highlight JSON file

Formatting
  • Run this command in shell 
    sudo cpan JSON::XS
  • Put this line to ~/.vimrc 
    map <leader>jt <Esc>:%!json_xs -f json -t json-pretty<CR>
  • When want to format JSON file press
    \jt

  • credit : “tidify” a json in vim
Syntax highlighting

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...