Convert an Object-Attribute-Value file into a structured table

November 13th, 2007

Some qemu tips

November 2nd, 2007

I’ve been playing with qemu recently and I’ve discovered some tips that make working with it easier.

start qemu with “-monitor stdio” in the console, and you can put qemu commands into the console. None of this “ctrl-alt-2″ then “sendkey ctrl-alt-f2″, “ctrl-alt-1″ stuff.

Instead of making a big blank 5GB file for the hard disk this way:
dd if=/dev/zero of=hda.img bs=1M count=5000
Do it this way:
qemu-img create hda.qcow 5G -f qcow
This creates a qcow format image. It’s the same, but it will only take as much space as is needed. The first version takes up 5GB.

You can eject the cdrom with ‘eject cdrom’ and ‘put in a new cd’ with “change cdrom /path/to/new.iso”

[source]

How to install kqemu in ubuntu feisty

September 25th, 2007

QEMU is an open source emulator. I use it regularly to test Camarabuntu installers. Out of the box, emulators do not run as fast as the computer you’re running them on. They run several orders of magnitude slower. However QEMU has kQEMU, which speeds the QEMU up to near native speeds and makes it very usable. This script will install it if it’s not there, and if it’s already install, it’ll set it up on Ubuntu Feisty.

#! /bin/bash
sudo modprobe kqemu

if [ $? -eq 1 ] ; then
    echo "kQEMU was not installed. Press enter to install it now, or Control-C to quit. This might take a few minutes and might require internet access. It might ask if you want to install some source files, press enter if that happens"
    read
    sudo apt-get install qemu kernel-package linux-source kqemu-source build-essential
    sudo module-assistant prepare
    sudo module-assistant build kqemu
    sudo module-assistant install kqemu
fi

sudo mknod /dev/kqemu c 250 0
sudo chmod 666 /dev/kqemu

You don’t have to change how you’re using qemu. Before you start using qemu, just run this script. Run qemu as normal.

If you start qemu and you get an error message like “Could not open ‘/dev/kqemu’ - QEMU acceleration layer not activated”, then you have not properly installed kqemu and the emulator will be very slow. If you do not see that message then the emulator will be fast.

[source]

Camarabuntu public git repository

September 22nd, 2007

Previously I had described how to automate and edubuntu install CD and how to install edubuntu over a network. This all dealt with the installation of edubuntu. I’m starting to do this more now and I’ve started using git the new version control system written by Linux Torvalds. It’s a distributed version control system. One can get free git hosting from repo.or.cz

I’ve created a git repository for my work on camarabuntu. Currently it’s very basic and just bunch of scripts. Don’t worry I won’t be adding whole ISOs to this repo. I’ve enabled annonymous commit access via the mob branch, so free free to commit to it and let me know what you’re doing.

Conduit - One way Gmail Contacts support

September 9th, 2007

Conduit is a syncronization programme for Gnome. It’s still a work in progress

I’ve added one-way Gmail contacts support. You can now use gmail contacts as an data source, i.e. you can download all your gmail contacts into a folder. I have also improved the Contact -> vCard file convertor, the file name is now more human understandable.

I’ve made some patches. They should work against svn revision 838, which is the current head of the svn trunk.

Download the patches here:

How big is my terminal?

August 29th, 2007

While poking around I discovered that you can use the stty size command to get the dimensions in columns and rows of the current terminal window.

This little bash functions can help. We have to tell stty what terminal (ie tty) to use. By default it’ll use the stdin, which doesn’t work if you’re chaining commands.

TTY=$(tty)
function rows {
    stty --file=${TTY} size | sed 's/^([0-9]*) ([0-9]*)/1/'
}
function cols {
    stty --file=${TTY} size | sed 's/^([0-9]*) ([0-9]*)/2/'
}

Example usage:

dmesg | tail -n $(( $(rows) - 2 ))

XChat plugin to show join/parts on specific channels

August 28th, 2007

As I said before, you can permantly hide join and parts globally in XChat. Sometimes you want to show join/parts on some channels but not for others. This plugin allows you to specify some channels that you want to always show join/parts on, and some to never show join/parts. This will override the global settings.

Change the options at the start of the file and save as ~/.xchat2/customjoinparts.py

This version will always show join/parts on #python, and never on #xchat.

__module_name__ = "CustomJoinPart"
__module_version__ = "1.0"
__module_description__ = "Automatically show join parts on a per channel basis"

show_join_parts = [
    [ 'FreeNode', '#python' ],
]

hide_join_parts = [
   [ 'FreeNode', '#xchat'],
]

import xchat

def channel_joined(word, word_eol, userdata):
    global show_join_parts, hide_join_parts

    curr_channel = xchat.get_info("channel")
    curr_network = xchat.get_info("network")
    for network, channel in show_join_parts:
        if curr_network == network and curr_channel == channel:
            # this is the a channel we are to show join parts
            xchat.command("CHANOPT CONFMODE OFF")
            print "Showing Join/Parts in this channel"
    for network, channel in hide_join_parts:
        if curr_channel == network and curr_channel == channel:
            xchat.command("CHANOPT CONFMODE ON")
            print "Hiding all Join/Parts in this channel"

    # Don't eat this event, let other plugins and xchat see it too
    return xchat.EAT_NONE 

xchat.hook_print( "You Join", channel_joined )

print __module_name__ + " version " + __module_version__ + " loaded"

XChat plugin to monitor channels

August 23rd, 2007

Sometimes you want to monitor a low activity channel while doing something else. This plugin uses GNOME’s notifications to show you a notification of each message in the channel.

Save this as watch.py and put it in ~/.xchat2/

# Copyright 2007 Rory McCann
# Released under the GNU GPL v3 or later

# Configuration options go here

notification_title = "Message in %(channel)s"
notification_text = "<%(nick)s> %(message)s"

# End of configuration options.

__module_name__ = "WatchChannel"
__module_version__ = "1.0"
__module_description__ = "Watches a channel for new messages"

import xchat, pynotify

# This is empty at the start obviously, but it will contain network name and
# then channel name tuples.
channels_to_watch = set()

def watch_channel(word, word_eol, userdata):
	global channels_to_watch
	channels_to_watch.add((xchat.get_info("network"), xchat.get_info("channel")))
	xchat.prnt("You are now watching %s. You are now watching a total of %d channels" % (xchat.get_info("channel"), len(channels_to_watch)) )
	return xchat.EAT_ALL

def unwatch_channel(word, word_eol, userdata):
	global channels_to_watch
	tuple = (xchat.get_info("network"), xchat.get_info("channel"))
	if tuple in channels_to_watch:
		channels_to_watch.remove(tuple)
		xchat.prnt("You are no longer watching %s" % (xchat.get_info("channel")))
	return xchat.EAT_ALL

def message_recieved(word, word_eol, userdata):
	global channels_to_watch, notification_title, notification_text
	#print "channels to watch:", str(channels_to_watch)
	network, channel = xchat.get_info("network"), xchat.get_info("channel")
	nick, message = word[0], word[1]
	if nick[0:2] == 'x032':
		# Occasionally there are 3 characters at the front, this will remove them. I don't know why they are there.
		nick = nick[3:]
	details = {'channel':channel, 'message':message, 'nick':nick}
	if (network,channel) in channels_to_watch:
		n = pynotify.Notification(notification_title % details, notification_text % details, "file:///usr/share/pixmaps/xchat.png")
		n.show()

	return xchat.EAT_NONE

pynotify.init("Channel watcher")

xchat.hook_command("watch", watch_channel)
xchat.hook_command("unwatch", unwatch_channel)

xchat.hook_print("Your Message", message_recieved)
xchat.hook_print("Channel Message", message_recieved)

print __module_name__ + " version " + __module_version__ + " loaded"

Greasemonkey / Javascript snippet for removing elements from a webpage

August 17th, 2007

I use greasemonkey frequently and love the idea of modifiying the internet for your own purposes. It’s like open source web pages. I have several greasemonkey scripts on UserScripts.

A frequent use of greasemonkey is to remove elements from a web page, such as advertisments. This Javascript function takes an array of xpath queries and removes all those elements.

function remove_annoying( xpath_queries )
{
    for( j=0; j

An example of this is:

var annoying_elements = new Array( "//*[@class='commerceTD']", "//*[@class='orange_bg_30']/..", "//*[@id='siBoxDiv']" );
remove_annoying( annoying_elements );

This function is used in my script to clean up tripadvisor, a site with travel listing.

Contact me

August 16th, 2007

If you have something to say about anything I post, please leave a comment on that entry. However I might not notice it for a while.

I can be contacted via email at rory (at) technomancy (dot) org. I am currently based in Dublin, Ireland.