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 *google.com*
// ==/UserScript==

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

After adding this UserScript if you open any page that has google.com 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 www.userscript.org. This is a huge resource of UserScripts.

I hope you enjoyed this article! 🙂

Advertisements

How to Describe Table in MS SQL Server

Unlike Oracle or MySQL there is no DESCRIBE or DESC command to describe a table or object in MS SQL Server. But to describe a table or object MS SQL Server provides a very useful command or built-in stored procedure sp_help.  One can easily describe an object using this command.  You can use this command in the following ways:

> sp_help ‘your_object_name’ or
>
sp_help your_oject_name
The first method is more useful because you can specify db/schema name here. Here is the command along with output:
sp_help ‘dbo.Sales’
Output:
Output of sp_help command

More info  is available here

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].

Formulas:
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

Haversine:
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.

Really Software Testing is Not Inevitable and Never Complete

It is not new or I need not to prove it again that Testing is not Inevitable and Never Complete. But last month I had an experience from where again I have concluded that really Testing is not Inevitable and Never Complete. I’m sharing the experience here.

It was the day when we planned to ship a pilot release. According to our plan we were testing the product and on the final day and final moment we were not getting any bug from the product. Our SQA manager asked me whether there were any findings or we would ship the product. I told him that the product seemed to be stable, and we were ready for the release. I requested few minutes from him just for an overview of the product.

In the last moment I found a bug that was not a bug to me until a new feature was implemented in this new release. I reported the bug in the issue tracker and manually informed our SQA manager. Our SQA manager took it and instantly went to the Project Manager room. While the bug was fixing then I found another bug and before reporting it to the issue tracker I went to the Project Manager room and notify it to both SQA manager and PM.

Within a very short time the bugs were fixed and again we were testing the product. After finding those bugs some exploratory thinking came to my mind that I could find more bugs in the same area. Alas! I was true! I found another new bug that wasn’t a bug to me until I reported those bugs and started thinking about those bugs. In that day we found another three/four bugs in the same area. So a total of 6/7 bugs were found and that was within a very short time. The moment was really very exciting. We found a bug and PM fixed it and again we found a new bug and PM fixed it…. Once a time our PM told us that really it was interesting. It was like ACM Programming contest.

Form this experience, I found how Software Testing is challenging and how unpredictable is it! While a minute ago I was thinking there was no bug in the product there we fond so many bugs within very short time.  The software testing seems me like Unpredictable Test Cricket. Look at the score of 2nd Innings of 2nd Test Match 2010 between Bangladesh and India. Once a time Bangladesh were 290 for 3 and the innings came last to 312 for 10.  7 wickets gone for only 22 runs. Can you believe it?

That is why all we say Really Software Testing in Not Inevitable and Never Complete.

Usages of ROW_NUMBER() in MSSQL SERVER

A very important feature of SQL Server is the usages of ROW_NUMBER() function. It gives sequential row number[starts from 1] over duplicate touple (a set of column[s]) and the order you set. The sequence of using ROW_NUMBER() in your SELECT SQL is:

ROW_NUMBER ( ) OVER ( [ partition_by_clause ] order_by_clause )

The PARTITION BY clause determines the duplicate touples on which you
want the sequential row number and ORDER BY clause determines the
criteria to set row number.
Lets see how it works and how it helps us….

In a simple way consider you have a table SALES like

CustomerID ProductID PurchasedDate
C000001 P000001 2010-02-01
C000002 P000001 2010-02-01
C000002 P000001 2010-02-02
C000001 P000001 2010-02-02
C000001
P000002 2010-02-03
C000001 P000001 2010-02-03
C000002 P000002 2010-02-04
C000002 P000001 2010-02-04
C000001 P000001 2010-02-04

Now if you execute the following SQL:

SELECT CustomerID, ProductID, PurchasedDate, ROW_NUMBER() OVER (

PARTITION BY CustomerID, ProductID ORDER BY PurchasedDate DESC) AS RowNo

FROM SALES;

Then the output will be

CustomerID ProductID PurchasedDate RowNo
C000001 P000001 2010-02-04 1
C000001 P000001 2010-02-03 2
C000001 P000001 2010-02-02 3
C000001 P000001 2010-02-01 4
C000001 P000002 2010-02-03 1
C000002 P000001 2010-02-04 1
C000002 P000001 2010-02-02 2
C000002 P000001 2010-02-01 3
C000002 P000002 2010-02-04 1

Explanation of the output:
In the SALES table there has total four distinct CustomerID-ProductID combination. In the SELECT statement this distinct combination is gained by partitioning the column with CustomerID and ProductID columns. Then the partitioned columns are given row number based on PurchasedDate column. In this case the order is DESC.

So the combination C000001-P000001 has 4 rows with dates ‘2010-02-01’ to ‘2010-02-04’. So the ROW_NUMBER()[here the alias RowNo] of row C000001-P000001-2010-02-04 is 1 and then C000001-P000001-2010-02-01 is 4. Similarly the combination C000002-P000001 has three rows with dates ‘2010-02-01’, ‘2010-02-02’ and ‘2010-02-04’. So RowNo for the combination C000002-P000001-2010-02-04 is 1, C000002-P000001-2010-02-02 is 2 and C000002-P000001-2010-02-01 is 3. Here if you use the ASC as ORDER BY then the RowNo would be reverse than it is shown.

Now if you carefully see the second table then imagine how easy it is for you to select distinct CustomerID-ProductID based on most or least or Nth recent sales.

For example you now want to know the 3rd recent sales date of every CustomerID-ProductID combination. So your SQL will look like:

SELECT temp.CustomerID, temp.ProductID, temp.PurchasedDate
FROM (
SELECT CustomerID, ProductID, PurchasedDate, ROW_NUMBER() OVER(
PARTITION BY CustomerID, ProductID ORDER BY PurchasedDate ASC) AS RowNO

FROM SALES
) AS temp
WHERE temp.RowNo = 3;
The output is:

CustomerID ProductID PurchasedDate
C000001 P000001 2010-02-03
C000002 P000001 2010-02-04

Isn’t it very useful feature?

Do You Have a Hit List?

In software development life cycle this is a common scenario that the tester gets less time than the anticipation. And when he goes to execute test runs then he finds a very big gap between time and test cases. He blames the shortage time.

But devising a technique he can overcome much of the ‘time limitation’ problem. If he has a list with some key points that does not require writing down in test cases and without altering the keys he can apply much of the points in any situation and in any type of application, then of course it will save time to find/identify bugs. I call this list as a Hit List.

Basically the Hit List will have two types of contents. One is Context dependent key points and another is context independent key points.

Context dependent key points: Basically these key points remain unchanged throughout the application, points are identified through testing experiences on the application.  Example: Fixed format of Price, Acc No, Title, frequent occurrence of critical bug,…, etc.

If your are keen to grab these type of points then you can easily apply these to your testing software very quickly.

Context independent key points: These points that do not depend on your testing software. Example: data type conversion/overflow error, rounding/truncating problem of number/string/character.. data types, entering special characters to input fields, unplug network connection, read/write file accessing error, …,etc. You can identify same type of more points for your Hit List.

When you have identified the key points then you can apply these to your testing software/application very quickly. Depending on how fast you have access on the points, it will save much of your testing time.

Now the question where you will save your Hit List? The best position is to keep it in your mind. If the List grow enough or you are confused recalling them in time, then you can save these to writing documents like notepad, wordpad,..,etc.

On July 28, 2009 I had a presentation on it. You can find more from here(http://www.sqabd.com/lt_present.php?id=lt5).

Good luck