"; */ ?>


Aug 08

Make rails.vim Work: Compile VIM From Sources

rails.vimEver heard about rails.vim project? “Accept no imitations: rails.vim is the one true Vim plugin for syntax highlighing, easy navigation, and script invocation for all your Ruby on Rails applications, transparently and unobtrusively” says creator Tim Pope.

The very good “rails.vim” guide can be found here or just by reading project’s vimdoc here.


There is however one gotcha for Ubuntu Hardy Heron lovers (or other modern Linux distros). Using rails.vim would result in VIM “segmentation fault”crashes similar to:

Vim: Caught deadly signal ABRT
Vim: Finished.


This is due to the fact that a packaged VIM that comes from some Linux distros repositories has old patches.


One of possible solutions would be to download most current VIM sources from http://www.vim.org/sources.php and compile/install it manually. Below is how it is done on Ubuntu (but should be pretty similar on any Linux distro):

1. Get vim sources:

wget ftp://ftp.vim.org/pub/vim/unix/vim-7.1.tar.bz2

(where ‘7.1’ is the current VIM version at the moment of writing)

2. Unpack it

tar -xvjf vim-7.1.tar.bz2

3. Install terminal libraries (vim needs them to compile correctly)

sudo apt-get install libncurses5-dev

4. Configure / Compile / Install

./configure --with-features=huge
sudo make install

5. Point your system to newly compiled VIM:

sudo rm /etc/alternatives/vi
sudo rm /etc/alternatives/vim
sudo rm /etc/alternatives/vimdiff
sudo ln -s /usr/local/bin/vim /etc/alternatives/vi
sudo ln -s /usr/local/bin/vim /etc/alternatives/vim
sudo ln -s /usr/local/bin/vimdiff /etc/alternatives/vimdiff


Jul 08

Forward VNC through SSH

linuxmce screenshotFrequently I need to access my LinuxMCE machine over VNC, due to different reasons (when I am not home, when my Wii Remote batteries died, etc..). Usually SSH solves most of my needs, but sometimes it is very nice to control my linuxMCE box over VNC.

Here I will show you several very easy steps on how to configure your server/client to be able to tunnel VNC traffic through SSH, and be able to control your server in the GUI way :) This approach will work on most systems (not LinuxMCE specific) although here I chose Ubuntu as an “example OS”.

Before we begin, I would assume that:

  • The server already has ssh server installed, if not:
    sudo apt-get install openssh-server
  • If connecting from the outside (like from work to home box), your router’s firewall forwards port 22 to your server’s IP

Here is how it is done:

Server Side Configuration

1. Installing VNC server, here I chose to install x11vnc, but it could be pretty much any VNC server of your choice (TightVNC, etc..):

sudo apt-get install x11vnc

2. Now let’s finish :) our server configuration by running the VNC server:


by default it is going to run without a password, and on port 5900

Client Side Configuration

1. In order to connect to the VNC server, we need to have a VNC viewer installed:

sudo apt-get install xvncviewer

* again, it can be pretty much any VNC viewer of your choice

2. Now the most interesting part of this whole process – enter this command:

ssh -L 5900: yourusername@yourserver.com

this tells your system to tunnel all the traffic from the port 5900 on “yourserver.com” to the local (client’s) port 5900 via SSH. Simple, and yet very powerful – a “magic one-liner” :)

3. Fire up another shell on the client side and enter:


do you see a cute colorful square screen? Do you recognize your server’s Desktop?

Done :)

P.S. For LinuxMCE specifically, you should also add a couple firewall rules:

– Go to the LinuxMCE web admin
– From the upper menu, go to “Advanced -> Network -> Firewall rules”

add this three rules:

tcp  	5900 to 5900  	5900             port_forward
tcp 	5900 to 5900 	0 	0                        core_input
tcp  	22 to 22  	0  	0                        core_input

– The first rule allows external network (Internet) to access the VNC server on the Core (LinuxMCE server)
– The second rule allows anybody inside the home network ( since it is not wise to open 5900 port on your router to the whole world ) to have their 5900 port to be forwarded to the Core.
– The third rule (I think you already have it) allows anybody to access LinuxMCE server via port 22 (SSH)

Be careful about the rules above, as I assume that your LinuxMCE server is behind another firewall, cause you really do not want to open 5900 port to the public

Jul 08

Install rtGui on Ubuntu

rtorrent project logortGui is a web based front end for rTorrent – the Linux command line BitTorrent client. It’s written in PHP and uses XML-RPC to communicate with the rTorrent client.

There are several guides on how to install rtGui on Ubuntu or just POL (Plain Old Linux), but all of them seem to be missing one or two things to make them complete.

Here I went from scratch, step by step to install rtGui on Ubuntu (actually KUbuntu, and to be more specific linuxMCE but it would not matter in this case, since this guide is for any more or less recent Ubuntu distro). I tried to make this guide as complete as possible so it does not miss any installation steps, and if you have any questions/comments, you are welcome to post them in comments section. Now sit back, relax and… let’s get to work! :)

Step 1.  Install PHP with XML-RPC and a SCGI apache module:

sudo apt-get install php5 php5-xmlrpc libapache2-mod-scgi

Step 2. Edit Apache default server config:

sudo vi /etc/apache2/sites-enabled/000-default

(If you are using linuxMCE, edit /etc/apache2/sites-enabled/pluto file instead)
Add the following lines, above the last “</VirtualHost>” (or download example from http://rtgui.googlecode.com/files/000-default ):

LoadModule scgi_module /usr/lib/apache2/modules/mod_scgi.so

Restart apache:

sudo apache2ctl restart

Step 3. Create .rtorrent.rc file – see http://libtorrent.rakshasa.no/browser/trunk/rtorrent/doc/rtorrent.rc?rev=latest or download example from http://rtgui.googlecode.com/files/.rtorrent.rc and save to your home directory – ~/.rtorrent.rc

* make sure .rtorrent.rc has this line:

scgi_port =

Step 4. Create directories for rtorrent to use, and change the ownership to the user that runs rtorrent:

mkdir /Torrents /Torrents/Downloading /Torrents/Downloading/rtorrent.session
/Torrents/Complete /Torrents/TorrentFiles /Torrents/TorrentFiles/Auto
chown username /Torrents /Torrents/Downloading /Torrents/Downloading/rtorrent.session
/Torrents/Complete /Torrents/TorrentFiles /Torrents/TorrentFiles/Auto

* here “username” is the user who will run rtorrent 

Step 5. Instal XML-RPC library:

sudo apt-get install libxmlrpc-c3-dev
sudo apt-get install libxmlrpc-c3

Step 6. Install latest version of both – libtorrent & rtorrent:

NOTE: Depending on packages installed on the system, you might need these dependencies:

sudo apt-get install libncurses5-dev libsigc++-2.0-dev libcurl4-openssl-dev build-essential

Download latest version (X.Y.Z) of libtorrent from http://libtorrent.rakshasa.no/downloads/ into /usr/local/ directory:

wget http://libtorrent.rakshasa.no/downloads/libtorrent-X.Y.Z.tar.gz
sudo tar xvf libtorrent-X.Y.Z.tar.gz
cd libtorrent-0.11.1
sudo ./configure
sudo make
sudo make install

Download rtorrent latest version (X.Y.Z) from http://libtorrent.rakshasa.no/downloads/ in /usr/local/ directory.

wget http://libtorrent.rakshasa.no/downloads/rtorrent-X.Y.Z.tar.gz
sudo tar xvf rtorrent-X.Y.Z.tar.gz
cd rtorrent-X.Y.Z
sudo ./configure --with-xmlrpc-c
sudo make
sudo make install

* make sure  you configure rtorrent with “–with-xmlrpc-c” option

After the above 6 steps we are ready to install rtGui (and other GUIs for rtorrent: wTorrent, etc..)

Step 7. Install rtGui:

Download rtgui from http://code.google.com/p/rtgui/downloads/list
Extract files to webserver directory:

sudo tar xvzf ~/rtgui-0.2.3.tgz -C /var/www

* 0.2.3 is the current version at the moment of writing

You can edit “/var/www/rtgui/config.php” if you’d like to change rtGui default settings. Most of the time you don’t have to.

*** Step 8. Start rtorrent:


Step 9. Done! :) Open your browser, and go to http://localhost/rtgui/

*** (!) Since rtGui talks to rtorrent via XML-RPC gateway, rtorrent has to be started – otherwise rtGui has nobody to talk to :) In case rtorrent is not started when you accessing rtGui via web browser, you would get:

Warning: file_get_contents(http://localhost/RPC2) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /var/www/rtgui/functions.php on line 10

This is because there is nobody listening on port 5000 – remember the line “scgi_port =″ in .rtorrent.rc? We have configured rtorrent with ” –with-xmlrpc-c” option, hence when rtorrent is up and running it will listen on “scgi_port” (in this case 5000) and will be able to handle XML-RPC requests/responses.

Happy rTorrenting!

Jul 08

Restore/Format USB Flash Drive

Who does not have a flash memory USB drive? (128Mb – 16Gb…) Everybody does, even my dog, if I had one, would have it. However, sometimes these little dongles can be tricky to use if they are not properly formatted. The usual format for the flash memory USB drive is FAT16, and it is understood by many operating systems with no problem. But in case the drive is not formatted properly/or you think it is not formatted properly, you can always reformat it, and here is how.

The whole process consists of 5 steps ans takes about 15 seconds um.. if do it slowly.. :)

In case you need to find the actual device your USB drive was associated with look here “Find USB flash device/drive in Linux

WARNING: All the data will be lost from the flash UBS drive since we are going to reformat it.

We are going to use fdisk utility, so “for starters” here are available commands that you can use with fdisk:

a – toggle a bootable flag
b – edit bsd disklabel
c – toggle the dos compatibility flag
d – delete a partition
l – list known partition types
m – print this menu
n – add a new partition
o – create a new empty DOS partition table
p – print the partition table
q – quit without saving changes
s – create a new empty Sun disklabel
t – change a partition’s system id
u – change display/entry units
v – verify the partition table
w – write table to disk and exit
x – extra functionality (experts only)

Now let’s get to cooking a new and fresh flash memory USB drive…

Step 1. Run fdisk via sudo on your USB flash drive device:

user@host:~$ sudo fdisk /dev/sdb

enter “p” command to list current partition table of the USB drive:

Command (m for help): p
Disk /dev/sdb: 1039 MB, 1039663104 bytes
32 heads, 62 sectors/track, 1023 cylinders
Units = cylinders of 1984 * 512 = 1015808 bytes
Disk identifier: 0xf1f494df
Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1023     1014785   83  Linux

Here you will see whatever partition (if any) currently present. In my case (above) it is a “Linux” partition, in your case it may be something different. But it does not really matter, because we are going to delete it anyway:

Step 2. Enter “d” command to delete existing partition (if you have any). If you have several, delete several by using”d” command multiple times:

Command (m for help): d
Selected partition 1

Step 3. Now let’s get to business and enter “n” command to create a new partition:

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-1023, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1023, default 1023):
Using default value 1023

As you can see from above, I entered “1” for “Partition number”, and hit enter key twice to leave everything by default.

Now let us list current partitions with “p” command again:

Command (m for help): p
Disk /dev/sdb: 1039 MB, 1039663104 bytes
32 heads, 62 sectors/track, 1023 cylinders
Units = cylinders of 1984 * 512 = 1015808 bytes
Disk identifier: 0xf1f494df
Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1023     1014785   83  Linux

We have a single “Linux” partition which is fine (for now).

Step 4. Time to actually apply our changes, so enter a “w” command that will write out all the changes to the USB drive.

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

fdisk will write all the changes to the USB drive and exit. But we are not done yet. Our goal is to make a (in this case) FAT16 partition, so this USB drive can be read by most operating systems.

Step 5. For that we will use mkfs.vfat utility:

user@host:~$ sudo mkfs.vfat -F 16 /dev/sdb1
mkfs.vfat 2.11 (12 Mar 2005)

Now we are good to go! It was easy, as I promised :)

Let’s look at the new USB drive now. Mounting it first:

user@host:~$ sudo mount /dev/sdb1 /mnt/flashka/
user@host:~$ cd /mnt/flashka/
user@host:/mnt/flashka$ ls -l
total 0

Checking what it has under the hood:

user@host:/mnt/flashka$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             991M     0  991M   0% /mnt/flashka

It has 991Mb which is what they call 1Gb flash memory USB drive! :)

Jul 08

Spring Web Application Context Visibility

spring framework logoWhile developing a Web App using Spring little things can take a lot of time to resolve. At the end they may appear to be very simple, and you may ask your self “how could I not think of it before – it is so obvious!”. Well, yea, it is obvious, but you just have to know it! One of the places that helps you to solve the “obvious” (and not so obvious), so you do not have to spin your wheels is, with no doubts, the spring forum. However you need to know the right search criteria to find what you need.

Here I just want to share something small but important about the visibility of Spring Contexts in a Web App.

Looking at org.springframework.web.servlet.DispatcherServlet API notice this:

“A web application can define any number of DispatcherServlets. Each servlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener, if any, will be shared.”

This brings an interesting point – in a Spring Web App you have one root application context which is private, and many dispatcher servlet application contexts which are children of the root application context:


In the above, everything that is defined in “contextConfigLocation” is your root application context. Every “dispatcher-servlet-number-x” (“dispatcher-servlet-number-1”, “dispatcher-servlet-number-2”, etc..) would represent a child application context which will see (have the visibility to) all the beans from the parent (root) context, but will not see any of the beans defined by its siblings – another dispatcher servlet contexts.

The only gotcha in the above visibility is BeanFactoryPostProcessor / BeanPostProcessor (s) – like “PropertyPlaceholderConfigurer” for example. These guys apply ONLY to beans in its own context. For example, if you have PropertyPlaceholderConfigurer defined in the root application context, none of root’s children will be able to use it (see) the ${properties}.

Here is the semi-official version “why” from Juergen (Spring Lead Developer):

“PropertyPlaceholderConfigurer is an implementation of the BeanFactoryPostProcessor interface: This interface and its sibling BeanPostProcessor just apply to the BeanFactory that defines them, that is, to the application context that defines them.

If you combine multiple config files into a single contextConfigLocation, a PropertyPlaceholderConfigurer defined in any of the files will apply to all of the files, because they are loaded into a single application context.

However, a DispatcherServlet has its own application context, just using the root web application context as parent. Therefore, it needs to define its own BeanFactoryPostProcessors and/or BeanPostProcessors, in this case its own PropertyPlaceholderConfigurer.”

Happy Springing!