Thursday, July 29, 2010

Exit code idiom in Java

I have been looking into employing C 'enum' like exit codes in Java. For example, if the application you are writing will be called by a script so it is handy for the script to know when there is an exit that is OK, and when it is a FAIL.

I looked to the web for inspiration, and couldn't find anything Java specific, so, I have arrived at the following:

class MyClass {
  private static enum EXIT {
        EXIT (int code) {
            this.code = code;
        private int code;
        public int getCode() {
            return code;

   public static void main (String[] args) {
        if (args.length() < 1) {


Friday, July 9, 2010

backing up mysql database without mysql root password

This is a quickie, I needed to back up a mysql database without knowing the MySQL root user password.

I had sudo, so the solution was:

sudo /etc/init.d/mysql stop

sudo mysqld_safe --skip-grant-tables &

mysqldump --all-databases | gzip > /tmp/alldb.gz

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

there, I told you it was a quickie.

Wednesday, July 7, 2010

associationtypemismatch expected got array

I'm building an app a bit at a time. Sufficient time elapses between development effort that I forget some basic stuff.

Something that I haven't forgotten is how often I come across this error when I've made some changes to my models and edit forms:

ActiveRecord::AssociationTypeMismatch (MyModelName(#-613518908) expected, got Array(#-608606448)):

This typically means that I've forgotten:


in my model.