Sunday, August 15, 2010

Working with PDFs

Join PDF files using ghostscript:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf


Merge Two or More PDFs into a New Document using PDFtk
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
or (Using Handles):
pdftk A=1.pdf B=2.pdf cat A B output 12.pdf
or (Using Wildcards):
pdftk *.pdf cat output combined.pdf

Wednesday, June 9, 2010

Processes keeping your device busy while Unmounting

Many a times, when you are trying to unmount your usb device, you find it busy and can't figure out what process is keeping it busy. Some of the commands which can help you in this matter are "fuser" and "lsof". fuser displays the PID of processes using specified files or file systems. lsof  list the open files.  Just observe the output of my lsof command:


[Wed Jun 09|swg@insane:intel]$ lsof |grep Transcend
bash       8619        swg  cwd       DIR       8,17     4096      470 /media/Transcend/intel
lsof      13006        swg  cwd       DIR       8,17     4096      470 /media/Transcend/intel
grep      13007        swg  cwd       DIR       8,17     4096      470 /media/Transcend/intel
lsof      13008        swg  cwd       DIR       8,17     4096      470 /media/Transcend/intel


Transcend is my usb device which I want to unmount and it is giving me a 'device busy' error. I find that "current working directory" is accessing the this device apart from the other two commands about which I am aware of.  Hence, I need to come out of this directory called "/media/Transcend/intel" and do an unmount on the usb device.

Monday, June 7, 2010

Printing to a Samsung SCX-4300 printer shared on Windows XP from Debian Lenny

I got a Samsung SCX-4300 multi-function printer at my office. Currently, it is connected to a windows machine through a USB cable. I wanted to be able to use it as a network printer for my Debian laptop. After a bit of search on google, I could find a solution that worked for me. I must thank Anupam for helping me out during this process. I derived my understanding from this page and this article summarizes the steps that I followed.


  1. Install  "smbclient (including Samba)" and "cups" related packages using APT.
  2. I share the printer on windows machine as "EE-Print". I connect to it through samba client using following command:

    $ smbclient -L EE-Print
    Enter swg's password:
    Domain=[EE-PRINT] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

    Sharename       Type      Comment
    ---------       ----      -------
    E$              Disk      Default share
    IPC$            IPC       Remote IPC
    print$          Disk      Printer Drivers
    SharedDocs      Disk    
    G$              Disk      Default share
    Printer3        Printer   HP LaserJet P2050 Series PCL6
    Printer4        Printer   Network Printer
    Printer5        Printer   HP LaserJet 5
    F$              Disk      Default share
    ADMIN$          Disk      Remote Admin
    C$              Disk      Default share
    Samsung         Printer   Samsung SCX-4300 Series

    Domain=[EE-PRINT] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
    Server               Comment
    ---------            -------
    Workgroup            Master

  3. Now we open the browser and open the CUPS web-interface by typing in the following URL:
    http://localhost:631/

  4. Now add a new printer, give a name to it and Set the device type to "Windows Printer via SAMBA".

  5. Set the URI which includes the name that was listed earlier by smbclient, for example something like "smb://EE-Print/Samsung". If the printer is passworded, you would use something like "smb://username:password@EE-Print/Samsung".

  6. You need to install linux driver for the printer "Samsung SCX-4300". The linux driver can be downloaded from the Samsung's official site. Untar the pack and run the "autorun" script file as a root. It has a gui interface which guides through various installation process. Currently install it as a local usb based printer.

  7. Once you have installed the driver, restart the CUPS server and click on "modify properties" option for the printer. When it asks for a driver, then select "Samsung scx-4300 series" from the drop down menu. It will now ask for the root username and password. Remember to enter "root" in the username field and give root password in the password field.

  8. Now you should be able to print your test page. 

Monday, April 12, 2010

Reliance NetConnect Broadband on Debian Lenny

Instructions for meant for people in India. Apart from the vendor information, other things should work for just anyone and anywhere.

Useful Links:

  1. Link1. The usb_modeswitch can be downloaded from this link.
  2. Link2
  3. Link3.

Basic steps are as follows:
  1. Install usb_modeswitch package. You need to have tcl and libusb (along with the headers) installed on your system. Go through the README that comes with the usb_modeswitch package.
  2. Plugin your reliance netconnect device and run "lsusb" to find it vendor and product id.

    $ lsusb
    Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 002: ID 064e:a101 Suyin Corp. Acer CrystalEye Webcam
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 005 Device 006: ID 12d1:140b Huawei Technologies Co., Ltd. EC1260 Wireless Data Modem HSD USB Card
    Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

  3. Copy following lines to /etc/usb_modeswitch.conf

    # Huawei EC1260
    DefaultVendor= 0x12d1
    DefaultProduct=0x140b
    TargetClass=0xff
    CheckSuccess=20
    HuaweiMode=1

    I don't know much about the last 3 items. I copied the contents from a file named "12d1:1414" inside the folder /etc/usb_modeswitch.d/. Now run following command:

    $ sudo usb_modeswitch -c /etc/usb_modeswitch.conf

  4. Install the packages "wvdial" and "gnome-ppp" using synaptic manager (apt-get). You can download the packages manually as stated in the second link above. However, you may face dependency issue.

  5. $ sudo modprobe usbserial vendor=0x12d1 product=0x140b
  6. $ sudo wvdialconf

  7. Now edit the file /etc/wvdial.conf and add additional lines if you have to. Some of these lines are generated automatically by wvdialconf and hence you should not delete any of these. You should add your phone number, username and password and last few lines if necessary.

    [Dialer Defaults]
    Init1 = ATZ
    Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Modem Type = Analog Modem
    Phone = #777
    ISDN = 0
    New PPPD = yes
    Modem = /dev/ttyUSB0
    Username = 93xxxxxxxx
    Password = 93xxxxxxxx
    Baud = 9600
    Stupid Mode = 1


  8. Now you should be ready to test your network connection. On a console, run the following command:
    $ sudo wvdial

    --> WvDial: Internet dialer version 1.60
    --> Warning: section [Dialer netconnect] does not exist in wvdial.conf.
    --> Warning: inherited section [Modem0] does not exist in wvdial.conf
    --> Cannot get information for serial port.
    --> Initializing modem.
    --> Sending: ATZ
    ATZ
    OK
    --> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    OK
    --> Modem initialized.
    --> Sending: ATDT#777
    --> Waiting for carrier.
    ATDT#777
    CONNECT
    --> Carrier detected.  Starting PPP immediately.
    --> Starting pppd at Mon Apr 12 18:32:25 2010
    --> Pid of pppd: 17509
    --> Using interface ppp0
    --> pppd: ��[06][08]P�[06][08]
    --> pppd: ��[06][08]P�[06][08]
    --> pppd: ��[06][08]P�[06][08]
    --> pppd: ��[06][08]P�[06][08]
    --> local  IP address 115.184.110.26
    --> pppd: ��[06][08]P�[06][08]
    --> remote IP address 220.224.141.145
    --> pppd: ��[06][08]P�[06][08]
    --> primary   DNS address 202.138.103.100
    --> pppd: ��[06][08]P�[06][08]
    --> secondary DNS address 202.138.96.2
    --> pppd: ��[06][08]P�[06][08]

  9. Keep it running on the console. You configure your network manager (system->admin->network)  to use "PPP" connection as a default mode for connecting the internet. You may think of disabling other connections. For PPP connection, under general tab, check the box "Enable this connection" and select "serial modem" as the connection type. You can also fill in the phone number along with username and password. Under modem tab, it uses /dev/modem as the port (I don't know if it is correct). Under options, I have checked the box "set modem as default route to internet".


Sunday, March 28, 2010

Vim, GDB

In this aspect, Emacs has a better GDB interface. The best interface for using GDB with vim seems to be the clewn project. The installation is fairly easy. This page describes the process of installing and using gdb with vim. However, Clewn works only with gvim and not with vim. If you are using vim on a console, you need to recompile vim with vimgdb patch. The process is described on the Clewn webpage. You can click here . This option is little cumbersome as one has to download the source and compile it with the vimgdb patch. Since I like gvim, I prefer to use clewn.

Thursday, March 25, 2010

VIM, auto Completion

IF you are only interested in auto-completing long words as you type, then you look here.   Basically it says :

The function A_Very_Long_Function_Name() can be quite exasperating to type over and over again. While still in insert-mode, one can auto-complete a word by either searching forwards or backwards. In function, Another_Function() one can type A_Very... and hit CTRL-P. The first matching word will be displayed first. In this case it would be A_Very_Long_Variable_Name. To complete it correctly, one can hit CTRL-Pagain and the search continues upwards to the next matching word, which is A_Very_Long_Function_Name. As soon as the correct word is matched you can continue typing. VIM remains in insert-mode during the entire process.




However, if you are interested in having declarations for all functions available in C++ or in a library, you need to use ctags.  A very good explanation of the process to set it up is available here. It is quite long. I would just enumerate the steps for the sake of brevity. I tried it on both Debian 5.0 and Ubuntu 9.10 and it works perfectly. 


  1. Install exuberant-ctags

    $ sudo apt-get install ctags

  2. Download omnicppcomplete package and extract the zip file into your ~/.vim/ folder. After this .vim folder should look something like this. It may contain other folders depending on the original content of your .vim folder. IF you don't have a .vim folder in your home directory, then create now.

    $ cd ~/.vim
    $ ls
    after  autoload  doc  ftplugin omnicppcomplete-0.41.zip

  3. Generate tags for C++ . ctags generates a file called "tags". You should rename it to something like "cpp.tags". You can have different such files for different libraries.

    $ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q /usr/include/c++
    $ mv tags cpp.tags
  4. Now add following lines to ~/.vimrc file

    set tags+=~/.vim/cpp.tags
    set nocp
    filetype plugin on
    map  :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .

    Last command maps CTRL-F6 to generate tags in the current directory directly from vim editor.

  5. Open Vim and run following command to see the help files related omnicomplete.

    :helptags $HOME/.vim/doc
    :h omnicppcomplete


Sunday, March 14, 2010

Printing text files : a2ps

Usually it is easier to convert a text file directly into PS files and then into a pdf file. 


$ a2ps -R  -1 -o abc.ps abc.cpp
$ ps2pdf abc.ps abc.pdf 

-1 :  Predefined layout: 1 x 1 portrait, 80 chars/line, major rows (i.e. alias for `--columns=1 --rows=1 --portrait --chars-per-line=80 --major=rows').

-o : Output file

Monday, March 8, 2010

Installing Debian Lenny from a USB flash disk

I tried the instructions available at this link and it worked for me. I will just summarize the steps that I followed .  I am assuming that your flash disk is identified as /dev/sdf by your system. (Check dmesg output). If you have a bigger disk, you can create multiple partitions using fdisk. We will use /dev/sdf1 for our discussion.

  1. Create a Fat16 partition using fdisk. Some information about this is available here.

    # umount /dev/sdf1
    # mkdosfs /dev/sdf1


  2. Use syslinux as a boot loader

    # syslinux /dev/sdf1

  3. Download the current Debian hd-media installer images from here.  Download vmlinuz, initrd.gz from this page.

  4. Download the current Debian netinstall cd image from here.  Note that the versions of these two images must match.

  5. Copy necessary files into the disk

    # mount /dev/sdf1 /mnt/usb
    # cp vmlinuz /mnt/usb/
    # cp initrd.gz /mnt/usb/
    # cp debian-504-i386-netinst.iso /mnt/usb


  6. Create 'syslinux.cfg' file inside /mnt/usb/ containing following lines :

    default vmlinuz
    append initrd=initrd.gz


  7. Now unmount the usb disk and fix or create the mbr

    # umount /dev/sdf1
    #install-mbr /dev/sdf


  8. Now plug into the system where you want to install Debian. You need to select USB device as your first boot device.

Friday, February 26, 2010

Debian 5.0 Lenny

I moved over from Ubuntu 9.04 to Debian 5.0 recently. It was not because I did not like Ubuntu. I think Ubuntu is simply great and it has made Linux as user friendly as Windows. But I faced problems in compiling and installing some scientific packages. Hence, I had to move over to Debian. Moreover, I had been using Debian for a long time (nearly 4 years) before switching to Ubuntu. I am quite happy to be back to Debian. The current version 5.0 is certainly better than its predecessors. GUI functions are more stable. I have all the ingredients necessary for my work. I really don't worry about having latest packages as long as the current package is stable and it works. On this aspect, I faced trouble with Ubuntu sometimes. I am planning keep updating my readers about the problems I faced with Debian 5.0 and how to get around them.

Today, I would talk about the problem of VLC player not showing the video. It happened because of debian-multimedia repository. It upgraded some codes and vlc player stopped displaying video. The solution is to remove the debian-multimedia repository from /etc/apt/sources.list and then do the following :

$ sudo apt-get update
$ apt-get remove  ffmpeg libavcodec51 libavdevice52 libavformat52 libavutil49 libpostproc51 libswscale0
$ apt-get install ffmpeg libavcodec51 libavdevice52 libavformat52 libavutil49 libpostproc51 libswscale0



$ apt-get install vlc


After this, your VLC player should work normally. It worked for me.



Thursday, February 25, 2010

Adobe flash on Google Chrome, Ubuntu

If you are not able to see Youtube videos on Google chrome, then probably your flashplayer is not working properly.

For 64 bit machines, download the Adobe flashplayer from this link.
For 32 bit machines, download from here.

Extract from the tar ball :

$ tar -xzvf libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz

make a directory :

$ sudo mkdir /opt/google/chrome/plugins

$ sudo cp libflashplayer.so /opt/google/chrome/plugins

$ google-chrome --enable-plugins

You can change this command in your application menu as described here.

Saturday, January 30, 2010

Google IME for Indian Languages ...

Using indian languages on a computer had never been so easy. I mean you can type directly in hindi in any windows application - notepad or word or web browser. Thanks to the google transliteration IME. You really don't need to remember the hindi key sequence (which is the case when you use window's native IME support. You can just type in the roman characters and it converts them into your native language (the same thing that happens in Gmail or in other google application. There is a free software called "Baraha" which does the same thing. I have been using this software for quite some time and I found it useful. However, its integration with other windows application is not that good.

After saying all this, I suggest you to download google transliteration IME tool from this link and see for yourself.


Also go through the installation instruction ....

Here is a screenshot of how it looks on my computer. I advise you to enable the short-cut key for enabling and disabling google IME. The google IME icon is sitting at the bottom right corner of the screen.

In fact, I can write directly in Hindi here ... for instance ... क्या आप हिंदी देख सकते हैं ? यह बहुत अच्छा है.

Thursday, January 21, 2010

Convert PS and EPS files into JPEG

I got this useful information from this link.

You can convert any ps or eps file into a jpeg using ghostscript:

gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=myfile.jpg myfile.eps


This method has one flaw. It produces huge files. Depending on the eps file you may get something like 2000×3000 pixels which is slightly on the insane side. Also the file size of the JPG will be about 10 times that of the eps.
We will now need to trim and resize the file using some Image Magic tools:


mogrify -trim -resize 800x600 myfile.jpg


In order to execute this command on multiple files,  use following bash script

for k in $(ls *.eps); do b=`basename ${k%.eps}`; gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=$b.jpg $k; mogrify -trim -resize 800x600 $b.jpg; done
 

Saturday, January 9, 2010

Linux on windows: Cygwin

If you use applications that work on only windows (like gtalk, voipcall clients), then you feel like having linux environment on the side, so that you won't have reboot into linux for doing your work. For these people (including me), Cygwin is a good choice. For instance you can have the bash shell, emacs, gnuplot, xfig, gvim, latex, xdvi all at one place ...  The installations is very easy.  Don't forget to install X server of cygwin (cygwin/x) during the installation process. Particularly, latex is more neat to use on cygwin than installing miktex and other tools for the same purpose.