HTML link for bookmarking a page

Hi there,

Ability to simply add your website to someone's bookmarks list can increase your traffic and chances that some one will visit your page again.

This is not because of shortcut purposes - currently bookmarking the page is pretty simply and quick anyway. You can use the Bookmarks menu or some keyboard shortcuts, i.e. CTRL+D in Firefox.

But this is more because if someone actually see the link/text saying 'Bookmark This Page' or 'Add it to your favorite' then there is a better chance that your website will be added.

OK so here is the simple HTML code for adding bookmark link:
<a href="javascript:if(document.all)window.external.AddFavorite(location.href,document.title);else%20if(window.sidebar)window.sidebar.addPanel(document.title,location.href,'');">BOOKMARK THIS PAGE</a>

In result you will have the link: BOOKMARK THIS PAGE

This it it. Hope it will be helpful.

JAVA - getting server date from remote host

Date objects in Java are quite common. Usually if you want to get the current date and time you just need to create new instance of java.util.Date:

new Date();

It is simply and straight forward in most cases. It returns whatever current date is on the client machine. 

But there might be a case when you want to have the actual date from the remote server. It is useful for example if you have trial version of your software and would like to check the real date or in general if the time is very important thing in your application.

Remote host date and time can be get from connection header. Example code below:
01. Date remoteDate = null;
03. URLConnection urlConn = url.openConnection();
04. HttpURLConnection conn = (HttpURLConnection) urlConn;
05. conn.setConnectTimeout(10000);
06. conn.setReadTimeout(10000);
07. conn.setInstanceFollowRedirects( true );
08. conn.setRequestProperty( "User-agent", "spider" );
09. conn.connect();
20. Map<String,List<String>> header = conn.getHeaderFields();
21. for (String key : header.keySet()) {
22.     if (key != null && "Date".equals(key)) {
23.         List<String> data = header.get(key);
24.         String dateString = data.get(0);
25.         SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
26.         remoteDate = sdf.parse(dateString);
27.         break;

28.     }
29. }

Some notes for this code example:

Line 22. Some of the key from header map fields may be null and we are interested only in 'Date' field.

Line 25. This one depends on the date format returned by the server. In this example it is valid for example for:
Sat, 13 Oct 2012 17:57:50

And this it - you got a date :) 

Permission problems for FAT filesystems (Ubuntu)


Here is quick post about resolving problems with mounting FAT32 paritions on Ubuntu.

There are several ways to mount a partition, for example:
1. Manual by clicking on the device from the UI ('Places').
2. Configure FSTAB to do the job for you automatically.
3. Use GUI tools such as pysdm.
4. Manual from command line.

There might be a problem with permissions of writing or even accessing mounted fat partition. You can get message that you do not have permission to see the disk content or something similar.

Basically partition type of the fat file system is called VFAT in Unix based system. By default when you mount it the ownership of the place belongs to the root user. So you have to be a root to write files to the partition. Even more - you may also not be allowed to change ownership.

So to resolve this problems you can create an entry in /etc/fstab containing some special "settings" which will mount the partition for you with all required rights:

# device mount_point  type properties X Y
/dev/sda1 /media/directory  vfat umask=0000,rw,user 0 0

The key elements are the flags:
  • rw - mount as read and write (but it is not enough for fat devices)
  • user - permits any user to mount the filesystem
  • umask - gives actual permissions or rather resets it - this actually seems to resolve an issue with lack of permission for user due to root ownership
This topic, setting and flags could be discussed in more details but umask=0000 should do the trick.

VPN Nortel via vpnc on Ubuntu

You may want to use VPN Nortel connection via vpnc client on Ubuntu. The default version does not support it - I mean it does not allow you to use PIN-token authentication mode.

However there is a workaround!
First you will need to checkout the vpnc-nortel sources directly from the SVN repo. It would be good to have subversion and vpnc dependencies before so please run:
sudo apt-get install build-essential subversion

sudo apt-get build-dep vpnc

Then to checkout from SVN:

svn co -r 517

This will get the revision 517 which is the latest at the time of writing this post.

One minor step before building the sources is to edit the Makefile and set the PREFIX var to be /usr

Now you can build the sources:
sudo make install

From now on you should be able to use it to connect via PIN-token authentication. Settings are stored in the /etc/vpnc where you can set default configuration by editing default.conf file. For example:

IPSec gateway <gateway_address>
IPSec ID <group_username_or_id>
IPSec secret <user_password>
Vendor nortel
Nortel Client ID V05_01
IKE Authmode PIN-token
Xauth username <auth_username>
Xauth PIN <pin>

To connect just run: sudo vpnc

To disconnect: sudo vpnc-disconnect

This is it. Cheers!