Tuesday, July 19, 2011

/etc/alternatives/

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
/usr/bin/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","airtelgprs.com"
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.


Misc:
- I faced an issue. It was not automatically obtaining the DNS address. So Manually edited the /etc/resolve.conf as
nameserver 8.8.8.8
nameserver 8.8.4.4
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
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
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
commit.downloadMode
in 
/etc/zypp/zypp.conf
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.
https://graph.facebook.com/oauth/access_token?client_id=XXXXXX&client_secret=XXXXXX&grant_type=client_credentials

Replace XXXXX appropriately with your app ID and app secret.

This will give you access token. In the browser you see content like
access_token=XXXXX
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" https://graph.facebook.com/APP_ID/accounts/test-users
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
https://graph.facebook.com/APP_ID/accounts/test-users?access_token=TOKEN
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
http://developers.facebook.com/docs/test_users/