Friday, August 6, 2010

handy java property to dump http traffic.

I find myself needing this command and unable to remember it or find it on Google easily. So I'm going to make a note of it here to save my precious memory for other more important information:

-Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true

Right, now I can try and remember where I live...

Tuesday, August 3, 2010

svn Id keyword in Perl

My Perl program wants to report it's SVN Id keyword. Setting this up is simple enough if you follow one of the many excellent examples on the web. However I found that it was beyond me to get the value of my Id printed out by my code.
The problem is that the completed SVN Id keyword contains @ and $ symbols.

So my code resorts to greping it's self to get the value from the source code.

# $Id$
my $id_str = `grep -m1 '\$Id:' $0`;
print $id_str;


It feels like a crime against programming, but it works - and provided that there is an $Id$ before the grep command, it should work reliabably.

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 {
        OK(0), BAD_COMMANDLINE(1), INPUT_ERROR(10);
      
        EXIT (int code) {
            this.code = code;
        }
        private int code;
        public int getCode() {
            return code;
        }
    }

   public static void main (String[] args) {
        if (args.length() < 1) {
            System.exit(EXIT.BAD_COMMANDLINE.getCode());
        }

        System.exit(EXIT.OK.getCode());
    }
}

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:

accepts_nested_attributes_for

in my model.

Monday, June 21, 2010

JQuery automatic linking

I have some values on my webpage, they are URLs and I have wrapped them in the form:


<span class="url">google.com</span>

<span class="url">http://lwn.net</span>

What I would like is to reneder anything that is of class 'url' as a link. And I would also like to stick a http:// infront of links that are currently missing them.

For this I use JQuery (I should get around to doing something sensible in the database as well but not just now).

So the JQuery looks like:
  $(".url:not(:contains('http://'))").prepend("http://");
  $(".url").each(function() {
    $(this) .replaceWith("" + $(this).text() + "");
   });

That's it.

Tuesday, April 13, 2010

building kernel for joggler

The excellent Playing the Joggler blog contains all the information you need to build a 2.6.33.2 kernel for your joggler. I thought I would collect together what I did so interested others can complete to process too:

I cloned the git 'baseline' branch of
http://gitorious.org/mer-meego/mer-meego-kernel
then applied the patches.
[the 'joggler' branch of this repo now has the patches applied - so cloning that will avoid adding the patches].
The patches can be found here:
http://adqmisc.googlecode.com/svn/trunk/joggler/

I then took the .config file from
http://jogglerhacks.blogspot.com/2010/04/kernel-config-for-2633-for-joggler.html

I did:
1. make
2. make modules
3. make modules_install INSTALL_MOD_DIR=./initfs (I think)
4. make bzImage - (and renamed the image vmlinuz)

I took the initrd from efi-nokeyboard.tar.gz and put the modules (that I built with line 3 above) into a new initrd. Instructions for rebuilding a initrd can also be found on the excellent Playing the Joggler blog.

There is a great wiki that contains information about running alternative OS's on the Joggler - and it has a page on building the kernel which is worth watching.