How to test your webcam in Ubuntu

Testing your webcam is done with mplayer, first though you’ll have to install mplayer as so:

sudo aptitude install mplayer

then fire up mplayer as so but in one line:

mplayer tv:// -tv driver=v4l2:width=320:height=240:fps=200:device=/dev/video0 -nosound

And you SHOULD see your pretty face on the screen. Good Luck.

Collectd Python plugin

One of the most interesting development in collectd recently (4.9) would have to be the availability of a Python binding. You can find the man page here with some samples.

Another interesting feature available with collectd plugins is the availability to overwrite the `hostname`. This opens up a whole new page to collectd, including what I’m attempting right now which is active checks.

In any case, a sample python plugin which overwrites the `hostname` would look like so:

# Sample Python module to use python plugin 

import collectd

#== Our Own Functions go here: ==#
def configer(ObjConfiguration):
   collectd.debug('Configuring Stuff') 

def initer():
    collectd.debug('initing stuff')

def reader(input_data=None):
    metric = collectd.Values();
    metric.plugin = 'python_plugin_test'
    metric.type = 'gauge'
    metric.values = [100] = 'OverwritenHostname'

#== Hook Callbacks, Order is important! ==#

Lets assume a few things here:

1. Collectd installation:

2. python plugins

3. plugin file will be in

The relevant corresponding config in /opt/collectd/current/etc/collectd.conf would look something like:

LoadPlugin python
<Plugin python>
  ModulePath "/opt/collectd/current/share/python/"
  LogTraces true
  Interactive false
  Import python_plugin_test
  <Module python_plugin_test>
    Test "This" "are" "the" "inputs"

Dont forget to test your plugins by running sbin/collectd -C  etc/collectd.conf -T If this causes nothing to be printed on the STDOUT, that means your plugins are good.

N900 development Part 2

Before you continue on reading, understand that a prerequisite is for you to start with part 1 and especially Maemo’s Getting Started guide.

For this guide, I’ll be showing how to create multiple widgets in one window. The code from Maemo provides you one window with one widget (the button). You cannot add on more widgets to the example just like that. Adding >1 widget to a HildonWindow will still allow the program to compile, however if you run it you will have to expect an error message that looks something like “… as a GtkBin subclass a HildonWindow can only contain one widget at a time; it already contains a widget of type …”

So the alternative is to create one vBox (or hBox) and pack all other widgets (including other hBox and vBox) inside of it. The end result from the sample should be an applicati
on with an interface that looks like this

3-button hello world app on N900 emulator

3-button hello world app on N900 emulator

The blog formatting makes it a bitch to paste my code here, so just download the code into scratchbox environment with something like this:


You should now be able to compile the program with the following line:

gcc hworld.c `pkg-config hildon-1 --cflags  --libs` -o hworld 

Execute the programe


And voila.

Take note of how the hbox is prepared and then packed into the vbox. Understanding the interaction is key to your own gui development with C, GTK, and Hildon.

Credit where credit’s due, I stole and modified the code from Maemo’s Wiki

Maemo SDK installation on Linux

There are 3 Options on how to install the Maemo 5 SDK,
1. The GUI Installer (recommended)
2. Script based installer.
Instruction for both can be found here
3. Manual installation

This is a Manual Installation instruction, covering the installation of Scratchbox, Nokia + Maemo binaries and Xephyr X server – which are the prerequisites for development. The host machine here is Debian based machine. so k/ubuntu will work. I’ve tried this on Kubuntu 9.10 with a 32-bit architecture and can confirmt that it works. I can’t guarantee you it will work on a 64-bit machine.

  1. Install Xephyr
  2. sudo aptitude install xserver-xephyr

  3. Download / Install scratchbox
  4. Note: before you start, take note that scratchbox installs by default in “/scratchbox” so make sure you have about 4GB’s in your “/” partition.
    sudo sh -c 'echo "deb maemo5-sdk main" > /etc/apt/sources.list.d/scratchbox.list'
    sudo aptitude update
    sudo aptitude install scratchbox-core scratchbox-libs scratchbox-devkit-qemu scratchbox-devkit-debian scratchbox-devkit-doctools scratchbox-devkit-perl scratchbox-toolchain-host-gcc scratchbox-toolchain-cs2007q3-glibc2.5-arm7 scratchbox-toolchain-cs2007q3-glibc2.5-i486 scratchbox-devkit-svn scratchbox-devkit-git scratchbox-devkit-apt-https

  5. Setup Scratchbox
  6. in the terminal, first make user you are logged in as your default user. Not the root user. And type:
    sudo /scratchbox/sbin/sbox_adduser $USER yes
    sudo ln -s /scratchbox/users/$USER/home/$USER /scratchbox/users/$USER/home/user
    This is optional, But I’d do it anyway just in case : sudo sh -c 'echo "nameserver" >> /scratchbox/etc/resolv.conf'
    sudo sh -c 'echo "nameserver" >> /scratchbox/etc/resolv.conf'

  7. Setup Mamemo Packages
  8. You will need to ensure:
    1. your group membership is registered in the current terminal
    2. VDSO support is disabled,
    to do so run these in the terminal: newgrp sbox
    sudo sh -c 'echo 0 > /proc/sys/vm/vdso_enabled'

  9. Log into scratchbox environment
  10. /scratchbox/login If this works, you will be inside of the scratchbox environment; and you will see something this in the terminal: [sbox->:~]>

  11. Configure the scratchbox x86 and armel target as such:
  12. sb-conf st FREMANTLE_X86 -c cs2007q3-glibc2.5-i486 -d perl:debian-etch:doctools:svn:git -t none
    sb-conf st FREMANTLE_ARMEL -c cs2007q3-glibc2.5-arm7 -d qemu:perl:debian-etch:doctools:svn:git -t qemu-arm-sb
    it is safe to ignore the warnings here.

  13. Now download the rootstraps:
  14. wget
    If networking doesn’t work inside of scratchbox, check your DNS server settings. Unfortunately there’s no `ping` inside of scratchbox so the only way to do this is to edit /scratchbox/etc/resolv.conf from OUTSIDE of scratchbox and paste the following:
    From inside scratchbox, paste the same lines to “/etc/resolv.conf”

  15. Now switch to the x86 target and install the binaries,
  16. sb-conf se FREMANTLE_X86
    sb-conf rs maemo-sdk-rootstrap_5.0_i386.tgz
    sb-conf in -edFL

  17. Add the nokia repos
  18. You’ll need to do some apt trickery here for maemo related items. So first accept the EULA here and copy the URL, paste the it into /etc/apt/sources.list (inside scratchbox) and then:
    apt-get update
    fakeroot apt-get install maemo-sdk-debug nokia-binaries nokia-apps
    Keep the url, you will need it later on in this installation

  19. fix the scratchbox symlinks
  20. According to the instructions from maemo you will need to remove a symlink and replace it with a folder so do this in the terminal: rm /targets/FREMANTLE_X86/opt
    mkdir /targets/FREMANTLE_X86/opt

  21. repeat the same for armel architecture
  22. At this point the x86 target is setup, you will need to do the same for the armel target.
    edit the file /etc/apt/sources.list and paste the URL that you got previously after agreeing to the EULA
    sb-conf se FREMANTLE_ARMEL
    sb-conf rs maemo-sdk-rootstrap_5.0_armel.tgz
    sb-conf in -edFL
    apt-get update
    fakeroot apt-get install maemo-sdk-debug nokia-binaries nokia-apps
    rm /targets/FREMANTLE_ARMEL/opt
    mkdir /targets/FREMANTLE_ARMEL/opt

  23. Startup Xephyr, with the x86 targets pointing the output to it
  24. export DISPLAY=:2 start
    And from OUTSIDE the scratchbox environment: Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -kb & And you will be greeted with a very reassuring emulator-like environment emulating the Maemo 5 on a Nokia N900 ūüėÄ

Using the Nokia N900 as a modem

For those of you who don’t know, I was lucky enough to be selected to receive a Nokia N900 for trial courtesy of WOMworld Nokia. I will write about my experience using the phone as a first-time smartphone user soon enough; I don’t think I’ve had enough time to build a first impression :)

For now though, here’s a howto on the first thing anyone would want to do with a 3G phone: turning it into a modem. This applies to someone in my scenario who is connecting a Nokia N900 to a Linux machine (also known as tethering). However it should apply the same to any other machine using the same concepts. Which is that you can plug the phone in, expect it to register as a USB modem, and use a dialer to dial out.

Step 1: Connect Your Phone
Make sure your phone is connected to the machine via the US cable that comes packaged with the phone. Upon connecting your phone to the machine you will see a pop-up on the phone that asks how you would like to connect this device, with the options being “Mass Storage mode” or “PC Suite Mode”. Technically you should be able to use the phone as a modem even without making a choice here, but if you can’t connect without choosing, choose “PC Suite Mode”.

Step 2: Make sure the phone is recognised as a USB modem
Make sure the phone (Nokia N900 in this case) is recognised as a USB modem by the machine. To do so run lsusb from the terminal. Which should give you something along the lines of
Bus 002 Device 007: ID 0421:01c8 Nokia Mobile Phones Next run ifconfig from the terminal, you should see a new device “usb0″. This is where you know you’re good to go. If you don’t get this, well, unplug the phone from the machine and try again.

Step 3: Make sure your phone is no longer connected to the internet.
edit: this step is dependent on your provider. You may not need this
That means shut down your Internet Connection (generally your 3G) on the N900. And on the N900 this was a little more difficult than I expected; because I did initially set my phone to connect whenever it can. Turning the 3G services off did nothing to override the previous settings, the phone just tries to reconnect again. That means you will have to first make sure you turn off the settings to “Always Connect” and only then turn the Internet Connection off.

Step 4: Configure your dialer
I use wvdial and i recommend you do too. If you don’t have it, install it (ie “sudo apt-get install wvdial). For this step there’s one really important detail that you will need to know which is your APN (Access Point Name). This differs across carriers so google for your carrier / ISP’s APN first. The next thing to know will be the credentials required to login. I’m using DiGi where the APN is “diginet”; the username “guest” and the password “guest”. The rest of the settings aren’t too different from my 3G broadband settings identified here.
Note: the modem in my case is registered as /dev/ttyACM0 which IIRC is a standard USB modem, but you will want to confirm the location of your modem before actually configuring your dialer

Step 5: Dial
As mentioned I use wvdial, so all I need to do is to ensure I have configure the config file at /etc/wvdial.conf and from terminal type sudo wvdial. I have included the wvdial config file below which of course works for me. Your own config file shouldn’t look that much different with the exception of the APN, the Username, the Password and maybe the Phone number.

[Dialer Defaults]
Modem = /dev/ttyACM0
Baud = 230400
Init1 = AT+CGDCONT=1,"IP","diginet"
Init3 =
Area Code =
Phone = *99***1#
Username = guest
Password = guest
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1
Check Def Route = 1

Swiftfox 3.5.4 and

After upgrading my Swiftfox from 3.5.3 to 3.5.4-1 it was Problems Galore.

Clicking the pretty swiftfox icon didnt work and typing `swiftfox` from the terminal (/usr/bin/swiftfox  which is a script that comes with the installation) gave me

/usr/lib/swiftfox/swiftfox-bin: symbol lookup error: /usr/lib/swiftfox/ undefined symbol: gdk_x11_window_get_drawable_impl

Which is when i figured the package maintainer was linking against the wrong libxul
A quick fix is to use libxul in¬†xulrunner-¬†If you do not have¬†xulrunner- you’ll need to install the package¬†xulrunner-1.9.1
sudo aptitude install xulrunner-1.9.1
Now, change the libxul that is used, which can be done by doing this:
cd /usr/lib/swiftfox
sudo mv
sudo ln -s ../xulrunner- .
And you’re good to go.

vim tips part 1.

Yes, A little bit of googling will give you good results but this is like most of all I have here: meant to be for beginners. so here goes.

Note my conventions
:w means type the phrase :w in normal mode (not insert mode)
`a` means hit the a key in normal mode

Tip #1 – Are you really using vim?
First off, you need to figure out if you’re using VI or VIM.
No  they are not the same and are not intended to be.
I believe ubuntu ships with vi and not vim so you do not get vim out of the box.
Some distros alias `vi` to `vim` but trust me, you will want to get used to typing `vim` not `vi`
This way you’re always sure you’re using vim and not vi

Tip #2 – Cursor Navigation
:1 takes you to the first line
:122 takes you to the 122nd line
:$ take you to the last line
`a` moves the cursor one character forward and enables INSERT
`i` does not move the cursor, it sets the cursor to INSERT wherever it is.
`o` moves the cursor one line down and enables INSERT

Tip #3 – File / Edit Management
`u` undoes your last action
:w saves the file
:q quits whatever you’re doing provided there’s no change to the file
:wq saves the file and then exits
:q! quits vim without saving
Do Not make it a habbit of hitting :wq!
This forces a save without a warning if there’s supposed to be one.

So thats it for the ultimate basics. Get used to this, more to come.

HOWTO Open Kopete links in Swiftfox

This of course works if you want to open Kopete links in Firefox as well. Instead of the default Konqueror. Just replace my ‘swiftfox’ in the commands with ‘firefox’

This assumes that you are using the same environment as I am (KDE4.2, Ubuntu 9.04)

1. System Settings* -> Default Applications -> Web Browser
2. Set the value for “in the following browser” as ” /usr/bin/swiftfox -new-tab ”
3. Apply
4. You’re Done.

*If you’re not sure where “System Settings” is, press Alt + F2 and type “System Settings” (remove quotes)

Battery Capacity Details on a Linux Laptop

All laptop batteries are created equal by Their Maker. But even so, some last longer than others despite coming out of the same production lines. Why? Because although it is manufactured to last (say) 5 hours, sometimes you only get 2 hours before it dies. Usually that means that your actual capacity is lower than what it was manufactured to be.

Here’s how you can figure out how useful your battery really is:

install acpi if it’s not yet available

sudo aptitude install acpi

Open a terminal / console and type:

acpi -V

See those details? Thats some minimal details available. Now for a more detailed view do this:

cat /proc/acpi/battery/BAT0/info

Look at the design capacity and last full capacity:

If you’re last full capacity is under the design capacity, then your battery cannot store as much power as it should and will therefore die faster than it should.

If the last full capacity is under 50% of the design capacity, I’d consider getting a new one.

How to install Swiftfox on K/Ubuntu

0. Take note that I use aptitude, apt-get will serve the same function.

1. edit /etc/apt/sources. list and add the following lines:

deb unstable non-free

2. Go to a terminal and type:

sudo aptitude update
sudo aptitude install swiftfox-prescott

3. You’re done. Look below for instructions on how to setup Java on Swiftfox

Note: Your best place to look for swiftfox and .deb is still here

Java on Swiftfox 3.5beta

0.1. Check if Java is installed. In a console type:

which java

0.2. If it is, check if Java is included on swiftfox as a plugin. In Swiftfox location bar type:


1. install java and swiftfox:

sudo aptitude install sun-java6-jre sun-java6-plugin sun-java6-fonts swiftfox-prescott

the sun-java6-plugin contains the plugins required for Firefox,
check for the plugin as in 0.2
but if Java in Swiftfox is still not including it by default, go to 2

2. link the plugin to swiftfox as such:

sudo ln -s /usr/lib/jvm/java-6-sun- /usr/lib/swiftfox/plugins/

this will differ according to the location and version of the java installed so, check first.

3. Startup Swiftfox, you will need to confirm your installation (0.2 above) or check it manually: go somewhere that requires java. Yahoo Pool is one of those..

K/Ubuntu for Developers

There are important packages that don’t come default with kubuntu which I would need for development. So after setting up a new installation of Kubuntu this is what I’d do:

sudo aptitude install openssh-server build-essential vim kdesvn mysql-server-5.0

These are needed as of kubuntu 9.04 – Jaunty and as you can see installs:

  • openssh-server – which will immediately listen on port 22
  • build-essential – compilers, etc
  • vim – because I don’t like using vi
  • kdesvn – Cuz can be easier to diff my devels
  • mysql-server – well… i need it and Mysql 5.1 does not have great reviews.

Even if you don’t want kdesvn, I’d take kompare any day. The best diff front end for KDE. Although kdiff3 (sudo aptitude install kdiff3) isn’t too bad.