PhantomJS an Amazing Headless WebKit Scriptable with a JavaScript API

PhantomJS an Amazing Headless WebKit Scriptable with a JavaScript API

When I first read about PhantomJS, just became astonished to see how many reach features it has and how easy these are for the implementation! Really it is handy for developers and testers. And it is so easy to learn. I’m not going to discuss any details about it. Their documentation and getting started guide are well written and provide lots of real life examples. So if you are interested to learn it then you can visit this page.

An useful example and usage of PhantomJS is to capture web page screen in different output formats without involving any installed browser. You need very few lines of code to achieve this. You can capture the whole screen at a time in different formats. Here is the sample code (taken from here) to capture web screen:

var page = require(‘webpage’).create();‘’ , function () {




Recently I’ve created a windows application called CaptureWebPage. I’ve used the phantomjs.exe and .NET/C# to build that application. Here is the screen of the app:

Screen of CaptureWebPage

Screen of CaptureWebPage

If you have already visited this page or downloaded my application CaptureWebPage from codeproject then I’m sure you are also amazed with the features of PhantomJS, isn’t it? I will be really grateful to you if also please share your experience about PhantomJS.

Take Care of Your Alternative Email!

Alternative email ID is an easy way of retrieving forgotten password. Many of us use this feature in many applications. To use this feature we use two email IDs. Basically one email ID is for prime usages and another(the alternative email ID) is for retrieving the forgotten password of the prime email ID.

Since the usages of prime email ID are very frequent, therefore we take care of the ID and it’s password regularly. BUT have you thought about your secondary email ID? If the password of this ID is weak then it may cost you harmfully! If someone knows this ID’s password then you will loose everything! At first he will retrieve the password of your prime email ID [basically email IDs are public] and then … everything!

So beware about your secondary or alternative email ID and password. For security purposes you can use some unconventional secondary email ID[so that someone gets difficulty to know the ID] and of course a strong password. Those who use more than two email IDs should also be concerned about the passwords.

UserScript and greasemonkey an Easy Way to Modify Web Pages

Do you want to see a web page as you like? Do you want to add some extra functions to a web page that will work for you? Do you want to make these changes On-the-Fly to a web page? Do you want these to a web page that you haven’t developed by you or you have no modification access to it? Then here is UserScript and greasemonkey.

You can achieve those goals easily in Mozilla Firefox. You are needed only five basic steps:

1.  Add the gresemonkey [a Mozilla Firefox] extension to your Firefox browser

2. Write your desired functionality/features to a UserScript. Include/Exclude the web address(es) in your UserScript that you want/doesn’t want to have the feature(s)

3. Then add your UserScript to the greasemonkey

4. Enable(if not) the greasemonkey into your browser

5. Finally open your desired web page into the Firefox web browser.

Here I’m not going to explain more about the greasemonkey and UserScript. but the basic idea of UserScript is:
UserScript is nothing but JavaScript code. It has two main sections: a) Header: where you will provide the Name/Description of the script, include/exclude the web pages that you want/doesn’t want to have this UserScript and b) Body: where you will write your desired feature in JavaScript code.

Once you write a UserScript then greasemonkey will provide you option to attach the file into it. An important point is that a UserScript file will have the extension .user.js [e.g. MyFeature.user.js]

Here is a sample UserScript:

// ==UserScript==
// @name SayHelo
// @description Whenever a page of google will be loaded then it will say Helo to user

// @include **
// ==/UserScript==

function SayHeloToUser()
alert(“Helo I’m from UserScript”);

After adding this UserScript if you open any page that has in address bar then the message Helo I’m from UserScript will be shown by the browser.

> To know about greasemonkey follow the links greasemonkey and greasemonkey wiki.

> To know about how to add/delete/manage UserScript please click this link. Also don’t miss out to read the article from this diveintogreasemonkey, especially the PDF doc.

> To find existing UserScript that might work for you, follow the link This is a huge resource of UserScripts.

I hope you enjoyed this article! 🙂

Finding Distance between Two Points Given in Latitude and Longitude Points

In many application especially in GIS system it requires to find distance between two points given latitude and longitude. Here I’m explaining the procedure to find distance from such type of points.

At First, Let Us See How a Point is Represented:
A point P is given in the format P(40°44′55″N, 73°59′11″W ). The first part is called latitude and the last part is called longitude.  We read a latitude/longitude [e.g.] 40°44′55″N as 40 degree 44 minute and 55 second North[N=North, S=South and so on E and W].

There has many formulas to find distance from given latitude and longitude points. Among them two formulas are very easy to implement and give result with a very little error. One is Haversine and another is Spherical Low of Cosine.

Keep It Mind:
The above formulas are for spheroidal shape. The earth is not quite a sphere, there are small errors in using spherical geometry; the earth is oblate spheroidal with a radius varying between about 6,378km (equatorial) and 6,357km (polar), and local radius of curvature varying from 6,336km (equatorial meridian) to 6,399km (polar). 6,371 km is the generally accepted value for the Earth’s mean radius. This means that errors from assuming spherical geometry might be up to 0.55% crossing the equator, though generally below 0.3%, depending on latitude and direction of travel. AND both the formula find shortest distance on earth surface [as-the-crow-flies]. One can use Vincenty formula for accuracy up to 1mm

If P1(lat1, long1) and P2(lat2, long2) are two given points, R is radius of the Earth and D is the distance between the points then
D=C*R, Where
C = 2*atan2(√a, √(1−a)),
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1)*cos(lat2)*sin²(Δlong/2)

Here atan2(y,x) is a special implementation of arctangent atan(y/x) in programming languages.

Spherical Low of Cosine:
For the same two points and same assumption the distance D is
D = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(Δlong))*R
The Spherical Low of Cosine gives more computational precision and finds distance as small as 1m.

Please Note That:
Depending on the calculation of trigonometric function you are required to convert the latitude and longitude into radian unit.  So if we convert the point P(40°44′55″N, 73°59′11″W ) into radiance then,
Latitude = ( (40 + 44/60 + 55/(60*60) )/180 ) and
Longitude =( (73 + 59/60 + 11/(60*60) )/180)

Then depending on the unit of R the distance D will be in km/miles/…

When a latitude/longitude will have S/W direction then put the negative(-ve) value of the latitude/longitude into those formula.

So let start to compute distance between tow points given in latitude and longitude.