Friday, September 9, 2011

Mounting remote file system using sshfs

sshfs is a tool which mounts remote file system on local machine. It internally uses SSH file transfer protocol. The current implementation of sshfs has dependcny on fuse.

following packages are required to be installed:
fuse (fuse-utils on some Linux distros)

On my open suse, fuse package was pre-installed and I needed to install sshfs.

the fuse kernel module has to be loaded before using sshfs. Here is the command to do that
modprobe fuse

I did not require anything to do anything for this on my open suse box because the fuse module was already loaded. This can be easily checked whether a particular module is already loaded or not using lsmod command.

Command to mount remote file system:
sshfs remote-user@remote-server:/remote/directory local-mount-directory

Tuesday, July 19, 2011


Linux allows different implementation of a single command/utility co-exist. For example you can install both open JDK and sun JDK at a time on Linux and can also make one of them as default. The default selection is made using links in the file system. This works as:-

$which java

$ls -l /usr/bin/java
/usr/bin/java -> /etc/alternatives/java

$ls -l /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-sun/bin/java

If we type command java on command prompt then /usr/bin/java is invoked. The /usr/java/bin points to /etc/alternatives/java and /etc/alternatives/java points to /usr/lib/jvm/jre-1.6.0-sun/bin/java. So the target of the command java becomes /usr/lib/jvm/jre-1.6.0-sun/bin/java

On Ubuntu, there is a graphical utility which lets you to change/configure the alternatives. But this is missing from the default install of openSUSE. But on the openSUSE this can be easily achieved by command line as -

update-alternatives --config java
This command will list all available options and will ask you to enter to select one of them.

Saturday, July 16, 2011

Mounting NTFS drive on openSUSE in read-write mode

Recently, I installed openSUSE 11.4 on my laptop. The laptop is dual boot with windows7. There was a minor issue. The NTFS drive was mounted read only by default. Editing /etc/fstab fixed the issue. Here was the original entry in the fstab:-

/dev/disk/by-id/ata-FUJITSU_MHV2080BH_PL_NW9ZT682CFW0-part2 /windows/D           ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0

I changed this to as below, to make it working
/dev/disk/by-id/ata-FUJITSU_MHV2080BH_PL_NW9ZT682CFW0-part2 /windows/D           ntfs-3g    defaults 0 0

Merging PDF files on Linux

There are many tools out there. gs is one of such command line tools to achieve this. Suppose there are two pdf files as file1.pdf and file2.pdf and we want to merge them into final.pdf, then the command will be -
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=final.pdf file1.pdf file2.pdf

More than two pdf can also be merged by providing their names in the command line argument.

Sunday, May 22, 2011

Connecting to internet on Linux with Airtel GPRS and Nokia mobile phone

The Nokia phone comes with a software called Nokia PC Suite which provides many utilities including Internet connection on PC via phone. Unfortunately this software is not available for Linux operating system. But, as usual, a little bit of hack can enable Internet connection on Linux using Nokia phone.
Here is what I have tried and it worked for me with Nokia N79 and Airtel (in India) as service provider.
- Install wvdial. It was installed by default on my box (open suse).
- edit /etc/wvdial.conf as
[Dialer Defaults]
Init1 = AT+CGDCONT=1,"IP",""
Modem Type = USB Modem
Phone = *99***1#
Password =" "
Username = " "
Modem = /dev/ttyACM1
Baud = 460800
auto DNS = 1
- Now from command prompt, run the command wvdial
- The wvdial will block the command prompt. If want to disconnect, then type Ctrl+C on the command prompt.

- I faced an issue. It was not automatically obtaining the DNS address. So Manually edited the /etc/resolve.conf as
These two nameservers are public nameserver by google.

- The user name and password here is blank string. There is no user name and password for Airtel. This should be changed accordingly if there is different service provider.

- While connecting the phone to PC, select PC Suite when asked in the phone as "Select USB Mode"

- /dev/ttyACM1 can be different on different machines. run the command dmesg as root just after connecting the phone to PC (by USB) and look for a line similar to

cdc_acm 1-1:1.1: ttyACM1: USB ACM device

Change the device name in the /etc/wvdial.conf to what it appears here

Monday, March 28, 2011

Facebook canvas application and cookie issue with Internet Explorer

The Internet Explorer does not allow cross domain cookies for iframe. This causes the Facebook iframe application to not be able to write Facebook authentication cookie on the client side and it tries to authenticate each time you try to access any page of the Facebook app. This problem does not exist for Firefox.
This can be easily solved using P3P header. Here is how this can be done in PHP
use this code wherever you write some cookie. This is harmless for Firefox.

Zypper/Yast: Download all RPM packages first and then install

Yast is the package management tool in open SuSE and its back-end is zypper. One of frequent issue that I have faced with zypper is that it installs a RPM package as soon as it downloads. It does not download the dependent RPMs before installing a RPM package. Sometime this leads to broken installs if there is some network problem while downloading the dependent RPMs. The problem becomes even worse if there is some network problem while the system update is going on. Once I had a broken update for KDE and I was not able to log into the GUI.
The behavior of zypper can be changed by config file. But I do not understand why the Open SuSE comes with behavior by default. The other popular Linux destro Ubuntu does not have this problem.
Anyway, I here is the solution to the probelm:-
Search for the line
By default this line is commented. Uncomment this line and change it to  
commit.downloadMode = DownloadInAdvance

Tuesday, February 22, 2011

Creating facebook test user account for testing your facebook application

If you are developing some Facebook application then you will need to test it with different user accounts. You will even need network of user account meaning accounts with friends. You would not like to do the testing with your real Facebook account because while testing you might be posting lot of junk data to your wall and this will get published to your friends news feed. You even might require adding new friend and removing friends for the testing purpose.
One option is to create fake accounts. But this is not clean way of doing. You will have to create so many fake email account and you will have to fill lot of fake user info. And another thing is that Facebook deletes fake account once they find it as fake.
There is other clean way of doing. Facebook provide API to create test accounts. These accounts will not be deleted by Facebook. Unfortunately Facebook currently does not provide any GUI to create test account. You will have to use Facebook API to achieve this. 
Here are the things that will be required to achieve this:-
1) A web browser (preferably firefox, I have not tested it on other browsers)
2) wget command line utility. This is freely available and most of the Linux distro has this by default. ( other tools like curl can be used but I am describing here with the help of wget). The reason we use wget is that we need HTTP post method.

Step 1: Get the application access token.
Type this URL in web browser.

Replace XXXXX appropriately with your app ID and app secret.

This will give you access token. In the browser you see content like
Please note down this access token.

Step 2: Create test accounts.
We will need wget command line utility for this. Run this command line utility to create a test user
wget --post-data "installed=true&permissions=read_stream&access_token=TOKEN"
Replace TOKEN with what you got in the step 1 as access token and replace APP_ID with your Facebook application id.
Run this command as many times as many users you want to create.

Step 3: Get the login URL for each users:
Type this URL in you browser
Replace TOKEN with what you got as access_token in step 1 and replace APP_ID with your Facebook application ID.

This will give you Info for each test account created. The info also contains login URL. Copy and paste the URL in browser to login into the test user account.

Few more things:
- The login URL is valid for one session only. You will have to repeat the step 3 to get new login URL.
- Access token is gets expired after some time. repeat the step 1 to get fresh access token.
-  Refer the facebook documentation here for more detail

Monday, February 7, 2011

MySql reseting root password

I was experimenting MySql yesterday and set some password for the root account. But today I forgot. Doing little bit of search on the net, I came across a simple way to reset the password. For this the root access of the OS is needed. Here are the steps:
- Log in as root on the SqlServer box
- stop the MySql server. command: /etc/init.d/mysqld stop
- start mySql in safe mode. command: mysqld_safe --skip-grant-tables
- The previous command will not free the terminal. So from other terminal (command prompt) do these-
mysql --user=root mysql
update user set Password=PASSWORD('new-password') where user='root';
flush privileges;

- Kill the mySql daemon. Command: killall mysqld

- start the mysql daemon. Command: /etc/init.d/mysqld start

Thursday, January 13, 2011

Selecting random record in MySQL

The random number generators are often used in almost all  kinds of application. The random numbers are generated using well known random number generator API. But what about selecting a random record from a database. There are cases we need this. for example- if you want to suggest a random picture to user in a web application. Pictures are stored in database. Fortunately databases provide this kind of feature but unfortunately different databases have different query to achieve this. Here is how this is achieved in MySQL  - 
SELECT columnName FROM tableName

The value of limit can be changed to number of records to fetch.

Tuesday, January 11, 2011

Scripting langauges

I have always been working with the compiled and statically typed languages like C, C++, Java, C#. I used to avoid scripting languages and also used to hate little bit these scripting languages. But recently started exploring PHP and JavaScript and it changed my perception. Now I started loving these languages. Programming in the these languages needs little bit of different mind set. It takes some time to think in terms of loosely typed coding style.

There are, of course, pro and cons. Here is what I have started observing about the scripting languages -

- You dont need to think in terms of types of data. Most of the time this is very good but some time this is very problematic, especially when you are dealing with string and integer together. In such case you need to explicitly cast to other type. Here is one PHP code which confused me at first glance -
$var = "false";
if ($var) {
echo "This is true";
} else {
echo "This is false";

First time when I was dealing with similar code, I was expecting it to print "false". But this prints true. I was thinking, as this is loosely typed language, it will convert the string to boolean automatically. But later found that the string is converted to boolean on the basis of null check. There are other instances, which are potentially confusing. This proves that the these languages are not completely type-less. Sometime you are forced to think in terms of their type and and some complicated rules about the conversion from one type to another.

- You dont need to compile! good or bad?? As I am coming form the background of complied languages, I am feeling this is as a bad thing. The compiler catches lot of error at the compile time but here I have to wait for runtime even for common syntax errors.

- Scripting languages saves you from writing lot of code that you end up writing in languages like Java or C#. Particularly writing the interfaces and thinking what class will implement what interface. As the function name and variable name resolution happens at run time, you can pass around object of any class provided that object
has that particular method or variable with that.

- The scripting language makes your life easier for most frequent operation on string, array, pattern matching etc.