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=, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. Access is denied.
File name: 'nunit-console-runner, Version=, 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, 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:

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 {
        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.

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"></span>

<span class="url"></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").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 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
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:

I then took the .config file from

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.

Saturday, March 27, 2010

rails ferret in production

I've had a few problems as i've moved from dev to production. My task has been complicated by not always maintaining my migrations. However the problem I've had recently has been with ferret not working.

When I've started './console/script procution' and try and rebuild indexes manually I get:

=> false

It turns out that the problem was that ferret has an expectation that in production, there will be a ferret server running. This is asserted in the file:


I commented out the production server and it works.

Friday, March 26, 2010

gnuplot point types

I was using gnuplot today and wanted a list of the different point types which are available so I could choose a suitable one.

After visiting the internet, I couldn't find a list so I made my own:

echo plot `perl -e 'for ($i = 0; $i < 30; $i++) {print " \"<echo $i 1\" u 1:2 pt $i ps 2 notitle, ";}'` | sed 's/,$//' | gnuplot -persist
echo set term postscript enhanced\; set output \'./points.eps\'\; plot `perl -e 'for ($i = 0; $i < 90; $i++) {print " \"<echo $i 1\" u 1:2 pt $i ps 1 notitle, ";}'` | sed 's/,$//' | gnuplot

Thursday, March 25, 2010

rails won't run in production

I've been working on a Rails app (2.3.5).

I'm hosting on modest hardware and chose Nginx and Thin to hopefully get the most performance out of my app.

My problem was that my app wouldn't run in production. It worked fine in development, but not in production.

There were a couple of problems:
  1. I was using a legacy database, and like non-pluralised table names, development picked up 'ActiveRecord::Base.pluralize_table_names = false' in my config/environment.rb, but I didn't seem to propagate to production. I added in 'ActiveRecord::Base.pluralize_table_names = false' into ./config/environments/production.rb
  2. Thin wouldn't start. Starting thin with -D allowed me to start it not daemonized, and then I could see the problem: 'Missing the Rails  gem. Please `gem install -v= rails`, update your RAILS_GEM_VERSION'.
    This is Thin reacting against rack version 1.1.0 apparently.
    gem uninstall --version '> 1.0.1' rack fixed that.
One less thing on my todo list.

Monday, February 8, 2010

Building TOra with Oracle support on Ubuntu

I'm doing some Oracle development, so I wanted to use the TOra db browser for convenience.

TOra is Free Software. There is a license conflict between TOra and the license that Oracle use on their client libraries. As a result TOra is not distributed with Oracle support: if you want to use TOra with Oracle, you must download the separate components, TOra source and Oracle client, and build TOra yourself.

This process is documented on the web, notably at pythian blog. However the instructions are for Ubuntu 9.04, and I'm using 9.10, so I thought there is an opportunity to document my experience as well.

So, on Ubuntu 9.10, I have installed Oracle XE (a resource-limited 10G installation), into it's default directory: /usr/lib/oracle/xe/

I'm also assuming that you, like me, have the three Oracle packages oracle-instantclient-basic- oracle-instantclient-devel- oracle-instantclient-sqlplus- installed in their default location: /usr/lib/oracle/

NOTE: I chose the '10.x' client packages - I'm not sure if this makes a difference.

It seems that the Ubuntu source for TOra have migrated to git, so when I tried to pull down the source using apt-get source I didn't have any joy. So I cloned the TOra git repository and attempted to modify the debian/rules file to include the relevant Oracle libraries. This wasn't possible - there were no configure rules in there...

So instead I configure using 'cmake'.
First I need to configure: ORACLE_HOME and LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=/usr/lib/oracle/
export ORACLE_HOME=/usr/lib/oracle/

I also need to install the old libstdc++5 which is available from the Debian repository:

Then a command line to configure build:

 fakeroot cmake -DORACLE_PATH_LIB=/usr/lib/oracle/ -DORACLE_LIBRARY_CLNTSH=/usr/lib/oracle/ -DORACLE_LIBRARY_OCCI=/usr/lib/oracle/ -DORACLE_INCLUDES=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/rdbms/public

NOTE: I'm calling in the INCLUDES from the XE install.
...and another to build:


And you should know what to do from here...

Saturday, January 23, 2010

FormFu, DBIC, model_config and resultset.

I have found myself back in Catalyst development work. This wouldn't be such a bad think if I hadn't just spent a whole day trying to fix up a form to edit a 'many_to_many' relationship which is stored in my Schema.

I've been following this post which says it should be about as simple as it sounds. i.e. not as simple as Rails, but definitely doable with finite effort. So, FormFu syntax not withstanding, I following these instructions but ended up with some peculiar error talking about 'result_source'. I tried playing with 'nested_name', 'model_config' etc... I began to think about building my Select in the controller.

Finally, I discovered my error: I had not configured Controller::HTML::FormFu which is shown nicely in this post:

That is a day of my life gone, but at least I will be able to rise from sleep tomorrow knowing that I can move onto doing some new development.

UPDATE: One additional comment to the post above from 2009-March. I found that I needed to use the many_to_many relationship as the nested_name, not the has_many as stated.

Friday, January 8, 2010

Skype on a Ubuntu HP Mini 1000

I have been playing with Ubuntu 9.10 on a HP Mini for a while - on and off.

I have a request to get Skype working. I struggled with this for a bit, but I couldn't get it to work with the duplex sound card: when I pluged a microphone in, the speakers stopped working for example.

Something changed - it could have been an kernel update - anyway, I can now use Skype with minimal effort - including the web-cam.

The vital thing I had to do was disable the checkbox (options->audio settings or something):

'Allow Skype to automatically adjust my mixer levels'

Then, I could twiddle the 'pulse audio' options (right click on the volume icon) to increase the microphone input level. It seemed that one problem was Skype wouldn't let me increase the microphone input level while I was letting it 'automatically adjust my mixer levels'.