Saturday, December 19, 2009

Skype in Linux

Recently I have started using Skype in Linux for video calls (calling home). My webcam (Logitech QuickCam Connect) works well in Linux but not directly under Skype ( I am on Ubuntu 9.10. After some net surfing, I found two solutions that worked:

Install gstfakevideo.
If webcam is at /dev/video0, then move it to, say /dev/video1 (gstfakevideo will use /dev/video0 for itself by default. This also means that in Skype Video settings, /dev/video0 is to be selected).
Start Skype as follows:
gstfakevideo v4l2src device=/dev/video1

Install libv4l (in Ubuntu it is libv4l-0).
Start Skype as follows:
LD_PRELOAD=/usr/lib/libv4l/ /usr/bin/skype

(change the above path names depending on where the libv4l and skype are installed in your system)

Now that I got video working under Skype, I faced another problem. The video was too dark, and the current Skype version for Linux does not provide any option to change the brightness, contrast, etc. Again, some net surfing, and the solution that works for me turns out to be xawtv.

xawtv includes along with it a tool called v4lctl, which allows one to control brightness, contrast, etc. of the video stream from v4l devices. For me, a simple

v4lctl bright 250

from the terminal during a Skype video call solved the brightness problem. For other options that can be changed via v4lctl, do a

v4lctl list.

I can't exactly remember the URLs from where I collected those solutions, but I do remember that all of that info was from the Skype forums.

Sunday, March 22, 2009

Narrowing down to a region in Emacs

Emacs is awesome! What a piece of software! Recently, I discovered a very useful feature in Emacs.

Let's say, you are writing some documentation in text-mode. Inside it, you need to write a piece of C code with proper indentation. You can switch to c-mode, but then the rest of your text starts looking weird with colors and all, and this is very distracting (to me at least). But Emacs, as usual, has a solution to this problem.

Select a few blank lines (where you want to insert your code) within the text, and give the command M-x narrow-to-region (the keyboard shortcut for this is C-x n n). You will find yourself in a buffer with only the region you selected. Then you can enter c-mode and write the code. When done, you can go back to your original full view by using the command M-x widen (or C-x n w) and switch back to whatever mode you were in (text-mode in this case).

I find this pretty useful.

Using "Abbreviated Skeletons" in Emacs

In Emacs, you can use code templates (using 'skeleton's in emacs) as abbreviations to speed up your coding. Here is an example:

Suppose I want to create a code-template for the for loop in c-mode in Emacs. To create the template, I can put the following function in my .emacs file:

(define-skeleton c-for
"Inserts a C for loop template."
> "for (;;){" \n
> _ \n
"}" > \n

(see the Autotype section of the emacs info)

After that, I can edit the abbreviation table by using the command M-x edit-abbrevs (i.e., Press Alt+x, and then give the command edit-abbrevs and press enter).

Then, under the heading (c-mode-abbrev-table), leaving a blank line, I can enter the following line:

"forst" 0 "" c-for

Then, I can save the changes by pressing C-c C-c (i.e., press Control+c twice). That's it.

Now, whenever I am writing a C program, if I need to use the template, I will just type "forst" (without the quotes), and if the abbrev-mode is turned on, then as soon as I enter a space, my template for the for statement gets entered with the cursor inside the for loop as follows:

for (;;){

(If the abbrev-mode is turned off, "forst" can still be expanded to the template by pressing "C-x a e", which basically stands for "abbreviation expand".

Oh, of course I need to save my abbreviations using M-x write-abbrevs-file if I want to use them in future emacs sessions. But that is obvious... although I have forgotten that on many occassions :-)

Wednesday, March 11, 2009

How I connected to Internet from Linux via Airtel GPRS

First of all, I needed to activate Airtel's MO (Mobile Office) GPRS service. At the moment, they provide a form of this service by which I will be charged @ 30p/50KB (at least that's what I understood from their website). So, here is what I did:

Activating the MO service

Dialed *567*1# to activate (*567*2# to deactivate) the service on my prepaid Airtel connection.

Configuring the mobile

To configure the mobile for the MO service, I needed to set the active GPRS access point to I have a Nokia 3220. There I had to set under Settings -> Connectivity -> GPRS -> GPRS Modem Settings -> Edit Active Access Point -> GPRS Access Point. Also, I set the Alias for Access Point, and Active Access Point to That was all I had to do on the mobile side.

Connecting the Mobile to my Linux box

I connected the mobile (Nokia 3220) using the Nokia CA-42 cable to an USB port on my 4 yr old Compaq Presario 2203AL Laptop running Fedora 10. I made sure that the kernel had recognized my mobile as an USB modem. I checked that using the command dmesg. Among the several lines of output, the following lines appeared:

usb 2-2: new full speed USB device using uhci_hcd and address 2
usb 2-2: configuration #1 chosen from 1 choice
usb 2-2: New USB device found, idVendor=0421, idProduct=0802
usb 2-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
cdc_acm: This device cannot do calls on its own. It is no modem.
cdc_acm 2-2:1.0: ttyACM0: USB ACM device
usbcore: registered new interface driver cdc_acm
cdc_acm: v0.26:USB Abstract Control Model driver for USB modems and ISDN adapters

Thus, my mobile was detected as an USB modem with device name ttyACM0 under the /dev directory.

Linux side configuration

First of all, I made sure that I had turned off my wi-fi connectivity on this laptop. Also, I don't use ethernet on this laptop. So, basically, I got totally offline. All I had to do now was to use wvdial program to connect to the internet via the mobile. For that I needed to create the file wvdial.conf in /etc/ directory, and put the following lines in it:

[Dialer Defaults]
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = USB Modem
Phone = *99***1#
Stupid Mode = 1
ISDN = 0
Username = "none"
Init1 = ATZ
Password = "none"
Modem = /dev/ttyACM0
Baud = 230400

Once that was done, I ran the command wvdial from a terminal with root privileges. (Of course, later I intend to write a suitable udev rules file so that the permissions of the ttyACM0 device will be set such that I will be able to run wvdial as a normal user.) Connectivity was established, ppp was started, and along with several lines of output from wvdial, I found the following lines of information:

--> local IP address
--> remote IP address
--> primary DNS address
--> secondary DNS address

I checked using ifconfig that ppp was up. Also, the command route -n showed that my default gateway was as expected from the above output. I then manually set the nameservers in the file /etc/resolv.conf.

That's all I had to do. I could now successfully ping any website, and surf the net, although very slowly... but who cares, it was fun :-)

To stop the connection, I just had to stop wvdial by pressing Control-C.

Sunday, March 8, 2009

Making Xmonad to show up in gdm session list

I am now for some reason having to use Fedora 10 on my home laptop... partly by choice, partly due to circumstances. As I expected, xmonad is not in yum repos (neither Fedora nor RPMFusion)... but thankfully, ghc and haskell libraries are. Anyways, I found an easy way to install haskell packages once ghc and friends are installed (more about that in a later post... probably). Well, installed xmonad, xmobar, etc. along with gmrun (this was in yum repos).

But now that I have xmonad installed, I needed xmonad to show up in gdm session list so that I could choose it over gnome. I had done this quite a while ago, before I started using debian based distros... so I had to re-learn the process (Xmonad FAQ page made the process trivial). Now that I know how it works, I thought I should blog about it so that I can look it up here again in case I forget again.

Well, after so much blah blah, the process is pretty straightforward. As with most Unixy ways of doing things, you just have to add a .desktop file, say, xmonad.desktop to "/usr/share/xsessions/".
The contents of this file is also quite straightforward:

[Desktop Entry]
Comment=This session starts xmonad

(OK, so you (assuming somebody other than me reads this) probably figured out by now that I used cabal to install xmonad... well, that saves me a blog post I guess :-)

xmonad should show up along with others in your gdm session list.

Monday, February 16, 2009

Creating a Calendar in Linux

Today I found a great program called "pcal". It can create good looking postscript calendars. Most importantly, it can mark holidays in the postscript output if a 'date file' (normally named .calendar) is provided to it.

I created a holiday list in my .calendar file as follows (the * after the dates indicate a holiday):

8/1/09* "Muharram"
23/1/09* "Netaji's Birthday"
26/1/09* "Republic Day"
31/1/09* "Saraswati Puja"
10/3/09* "Fateh-Duaz-Duham"

and then used pcal as follows to generate a nice single a4 page calendar for 2009:

pcal -P a4 -o -E -f .calendar -g holiday -w 2009

'-P a4' generates output for A4 sheet,
'-o' names the output file,
'-E' lets pcal know that my "date file" has dates in European format,
'-f .calendar' tells pcal the name of my "date file",
'-g holidays' tells pcal to use a particular color (in my case the default grey) for holidays,
'-w' tells pcal to create a whole year calendar (i.e. a full year on a single page).

Saturday, February 14, 2009

Setting "SHMConfig" to "true" for synclient to work in recent Linux distros


1. You use a synaptics touchpad on your laptop/netbook.

2. You use a recent Linux distro (like Fedora 10) that comes with a
blank /etc/X11/xorg.conf.

3. You don't like the way your distro has configured your touchpad by
default. For example, you would like to get a middle click by
tapping the upper right corner of the touchpad.


To change the synaptics touchpad options at runtime (i.e. while the X
Server is running), you need to use the command line program
"synclient" (or graphical programs like gsynaptics, etc.).

I prefer the command line "synclient" because it allows me to tweak a
lot of things that gsynaptics does not allow me to.

For example, to get a middle click by tapping the upper right corner
of your touchpad, run synclient with the following option:

synclient TapButton2=2 RTCornerButton=2

Read the synclient manual page for more details. Do a 'synclient -l'
to get the current user settings.

In Ubuntu 8.10, synclient is provided by the package

In Fedora 10, synclient is provided by the package

But to get synclient working, you need to have the option "SHMConfig"
set as "true" in your options to Xorg. This was earlier done by adding
the line:

Option "SHMConfig" "on"

in your /etc/X11/xorg.conf file in the Synaptics InputDevice section.
Now that this file is being deprecated, you need to find out how you
can provide this option to Xorg. If you are on Fedora 10 like me
(maybe this is also the case in Ubuntu 8.10, Fedora 9, etc.), you can
put this option in a hal configuration file in /etc/hal/fdi/policy/

Using root privileges, create a file named say, synaptics.fdi, in
/etc/hal/fdi/policy/ using your favorite editor, and put the following

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
<match key="info.capabilities" contains="input.touchpad">
<match key="info.product" contains="Synaptics TouchPad">
<merge key="input.x11_options.SHMConfig" type="string">true</merge>

Next, restart by using the command (as root):

/etc/init.d/haldaemon restart

(The above command is for Fedora users. Use hal instead of haldaemon
if you are on Ubuntu)

Next, restart X Server using the command:

killall -HUP Xorg

Once X Server restarts, you should be able to use synclient without
any problems.

For more information regarding Synaptics Touchpad configuration
and configuring other devices under Xorg, see