Wednesday, December 29, 2010

getting workspace with gnome visal effects

I maintain linux-desktop-audit software. My Ubuntu machine recently allowed me to enable 'visual effects' to make nice looking transitions between workspaces.

However, this broke linux-desktop-audit. So, instead of listening to 'active_workspace_changed' the code should be listening to 'viewports_changed'. Once this event fires, to get the current workspace number I use the following code:

def viewport_change (self, screen):
        self.current_workspace = screen.get_active_workspace()
        v_x = self.current_workspace.get_viewport_x()
        v_y = self.current_workspace.get_viewport_y()
        v_w = screen.get_width()
        v_h = screen.get_height()
        v_r = self.current_workspace.get_width()
        v_c = self.current_workspace.get_height()
        total_cols = v_r/v_w
        total_rows = v_c/v_h
        desk_col = v_x/v_w
        desk_row = v_y/v_h
        ws_num = desk_col + (desk_row * total_cols)

Tuesday, November 23, 2010

NUnit-console-runner, FileLoadException, access is denied

I was using NUnit, and careless stuffed it into svn from my Linux box.
When I checked it out from svn onto my Windows environment I got this error when trying to run: ./nunit-console.exe:


Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'nunit-console-runner, Version=2.4.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. Access is denied.
File name: 'nunit-console-runner, Version=2.4.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' ---> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
   at NUnit.ConsoleRunner.Class1.Main(String[] args)

I had created a problem for myself because various dll's didn't have 'execute' flag enabled.

To fix this in a brutal way, from the cmd.com, I used:

cacls nunit.core.dll /p /e Everyone:F

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.