Dec 242010

I am starting a series of blog posts for users who are new to Ubuntu. After spending all the time working on Windows, users face a learning curve for even doing simple tasks in Linux. I am going to explain some of those tasks and hopefully it makes things simpler.

The first task many users struggle with is usually shortcut keys. Having gotten used to a few short cut keys in Windows, users find it adapt to the different keys in Linux. I am going to explain how to see existing key mappings and add your own keys. Unlike Windows which usually comes with a single desktop management software – Windows Explorer, Linux has a multitude of options. The two most popular ones are GNOME and KDE. A list of keyboard shortcuts for both these environments can be found here.

Apart from the ones given, there might be scenarios where you want to add your own shortcut keys. Lets see how to do that. First on the top navigation menu, click System -> Preferences -> Keyboard Shortcuts

You will see the Shortcut keys window which can be collapsed to four main categories – Sound, Desktop, Accessibility and Windows Management.

Clicking on any of the categories gives you a list of functions and the shortcut keys assigned for them. Some functions are not assigned shortcuts and given as disabled. If you click on any function, it is highlighted and the shortcut changes to “New Shortcut…” The window is now ready to accept the new key combination and you can enter your desired key to it.

Oct 202010

For the last few months, I am almost exclusively using Ubuntu as my primary operating system. Due to this my .NET development suffered quite a bit and was limited just to work. To find a way around I installed Mono and played around with it.

Though a lot of people believe that .NET is completely tied with the Windows API, that is not exactly true. If we look at the source code of the .NET runtime (released by Microsoft under the name Rotor/SSCLI), there is a seperate layer called the Platform Adaption Layer (PAL) written which acts as an abstraction between the OS and runtime. This layer allows people to write their own implementations of the CLR to translate CIL into native code.

The mono project is one such effort which has ported .NET to both Mac and Linux environment. Even though Mono can work on Linux, I wouldnt really recommend using it for a production application because you might end up with bugs and small irritants while running it on linux which you can ill afford for a commercial application. So if you want to write once, run anywhere, Java is still your best bet.

To install Mono, first the repository needs to be added to the package manager. The mono packages are available here and a guide to add them is given here. After the source is added, click reload to update the list. The use the familiar apt-get command to install Mono. If that doesnt work enable the multiverse repositories or you can use the GUI Synaptic package manager.

Now mono is the application which can execute a .NET exe file. It however cannot compile the code. For that there is another application called mcs. To install it use the following command.

Now for the obligatory hello word program. Just write a simple program and save it as a text file.

Now lets compile it using mcs. The -v switch gives more detailed information in case a parsing error occurs.

If you observe the folder, you will see an exe file created with the same name as the source code file. Now, Linux has no idea how to run an exe without a compatibility layer (cough: emulator cough:) like WINE. So we can compare mono to be an very specific emulator only for .net applications. Even inside Windows, .NET assemblies are loaded differently than other windows dlls. The PE header contains an additional entry about the CLR version and the execution is transferred to the runtime rather than the operating system handling it. I think a similar process happens when we run the exe using mono. Here is the command.

The output of the program is displayed in the console.

Jul 272010

The number of apps in the Android market has been growing at a breakneck speed and soon looks to surpass 100,000, giving the iPhone app store a run for its money. The developer community has been showing some serious interest in developing apps for Android as well as contributing to the OS codebase. The lower entry fees (25$) as compared to the iPhone ($99), combined with the more liberal acceptance criteria has done much to fuel interest.

There are two kinds of contributions that interested developers can make to the Android platform. First is testing out and submitting patches to the Android codebase and the other is to write applications targeting the platform. The applications are to be written in Java which simplifies the development process by quite a bit. I wrote this post to show how to set up the Android development environment to write apps.

Before starting development, there are a few points every new mobile app developer should keep in mind. Though not an exhaustive list, it serves as a reminder of few crucial points.

A more comprehensive discussion can be found here.

  • The Java code that you write isnt compiled by the usual JVM but a lighter implementation called Dalvik. So a lot of compiler/runtime optimizations are unavailable to us yet. Just in Time Compilation has just been added in Froyo. Other optimizations like Method inlining, caching are not added so use direct fields where possible rather than properties.
  • Responsiveness is of paramount importance in a mobile OS. On a PC, people might not notice lags of a second or so, but on a handheld device, even the smallest of lags is instantly noticeable and decreases the user experience
  • Don’t take device display for granted. Android has been used on devices with varying display sizes – from phones to netbooks to tablet pcs. So while coding the layout, keep the appplication as end device agnostic as possible.

To get started, we need the following components.

  • Eclipse IDE (both Windows and Linux)
  • ADT plugin for Eclipse
  • Google SDK
  • Android platform components.

First the Eclipse IDE. This by the way, is the only step that would differ between Windows and Linux. All others are pretty much the same.

On Windows, the IDE can be downloaded from the site – and run the setup to install. Linux’s package manager makes the install a simple one step process. In the command line type

sudo apt-get install eclipse

Next, download the Google Android SDK from this page as per your platform. The MD5 checksums for the archive are given, so you can verify the integrity of the file after download. Expand the archive to the disk. Now we need to install the ADT plugin for Eclipse. To do that go to Help -> Install New Software. Here the site of the ADT plugin needs to be added – Once that is done click Add, and choose both  Android DDMS and Development tools and click Finish to install them

Now open Eclipse and choose Window -> Preferences -> Android. In the Options page, give the path of the folder where you stored the SDK.

Once that is done, we need to download the SDK components. These components differ for each API version. The higher the version goes, the more features you will get. But the number of devices your application will support would also decrease. So its always better to target the most stable current release which would be on a majority of devices. Go to Window ->Android SDK and AVD manager. In the Virtual Devices tab click Add and create a new Android Virtual Device. This is the emulator that we can use to test our applications on. Enter the required details and remember to set the memory card size above 10 MB. Once you Create the AVD, it will show up in the Virtual devices tab.

Then, select the Available packages tab in the same window and click on the plus sign next to the web address. This will give us the available packages which can be installed. Choose any one of your choice and click Install Selected.

Once the SDK is installed you will be able to create Android applicatons by Going to File -> New -> Project -> Android Project. In my next post I will explain how to write a simple Android application.

Jul 192010

AndroidVNC is an Android app that can be used to connnect and control a remote machine which runs a VNC server. There are many VNC servers available like RealVNC, TightVNC, X11VNC server etc. The VNC server listens to a port (typically 5900) which the VNC client, can connect to and view/control the machine remotely.

Running it on a machine is quite straightforward. All you need to do is to start the TightVNC service and connect it from the phone using the app that can be downloaded from the market. It works great and can be used to control your PC from anywhere as long as its connected to the net.

But when you want to connect to a machine running on a VM, things can get a bit tricky. Mainly because of the way VirtualBox works. The default networking mode between a Host OS and the guest OS is NAT (Network Address Translation), which makes the VirtualBox as an intermediary between the Host and the guest and maps traffic to and fro. Though this mode requires virtually no configuration, it also makes the guest OS inaccessible from the outside world. Since any VNC viewer requires connectivity to the VNC server running on a machine, this limitation was effectively a dealbreaker.

To avoid this, the packets which reach the host must be sent to the guest through some mechanism. VirtualBox provides such a mechanism to do it and the protocol is called SSH (Secure Shell) which allows two networked devices to exchange data with each other. What happens is we open a port on the host side and forward any data received to a specified port on the guest through TCP. However, the GUI interface doesn’t give this option, its in a command line tool called VBoxManage. Before running this command, get the local IP address from Ubuntu using the ifconfig command. The IP was

Now we need to tell VirtualBox to forward all data received on any specified host port to port 5901 on Ubuntu.
I used the port 2222. The command for this is given below. Keep in mind that the VM needs to be powered off to use this command. Here you need to substitute your VM name with VM_NAME_here parameter. The guestssh is just a name assigned to it and doesnt really matter. Next comes the protocol – TCP, followed by the port on the host 2222. The two values after it signify the local IP for the guest OS and and port on the guestOS which will recieve the data.

VBoxManage modifyvm "VM_name_here" --natpf1 "guestssh,tcp,,2222,,5901"

Now that forwarding is configured, power on the VM again and install any VNC server on Ubuntu. I used X11VNC for this exercise.

sudo apt-get install x11vnc vnc-java

After X11VNC is installed, start it by going to Applications -> Internet -> X11 VNC server. It will display a dialog asking for the options. Make sure the port is 5901 and click on OK.

After clicking on OK, in the next screen. Make sure the Accept Connections tab is checked and also give a password and click on Ok. The X11VNC should be visible on the top left of the screen (If you are using GNOME)

Now that VNC is listening to port 5901 on the server, you can test it by running a VNC viewer on the localhost and specifying the port 2222 and seeing if the connection is made. The host would be This connection should be forwarded to the Ubuntu’s 5901 and the connection should succeed. If not see the logfile of the X11VNC to see if the connection was rejected due to some reason.

If your all set, run the AndroidVNC application on your phone. Also a very important point – “If you are accessing the net through a slow connection such as GPRS, make sure the resolution on Ubuntu is set to the miminum to prevent timeouts.” Get the network IP of your host through ipconfig or a site such as and enter the required settings on your phone.

Nickname: Any nickname you want
Password : What you specificied on X11VNC
Address: The public IP of your computer you got from ipconfig.
Port: 2222

And hit connect. It might take upto a minute to draw the first frame. Once thats done, you will be able to completely control the computer from your phone.

You can also send text and other key commands to the VM from your phone using the app options. Just How cool is that??