Pages

Saturday, January 23, 2016

The Cute Kittens With Their Mother Cat

The cute kittens with their mother Cat. 


This is the video I recorded at my neighbors' garden while they were away.

These are not their pets but street Cats. Two kittens and mother Cat were relaxing and enjoying the sunlight.

The mother Cat was actually knowing that I am recording this video so it kept on staring at me while I was recording! :)

The best part was that in the garden, there was an ample area to relax in the grass but mother Cat chose to sit on an elevated piece of rock which was actually little warm due to sunlight. Both baby kittens were equally enjoying the warmth as well as coziness and the comfort their mother has to offer.

Nice to see whole Cat family enjoying the day! :)



Try These Cat Food For Your Naughty But Adorable Cat!






Read More »

Friday, January 22, 2016

Unit Testing

Introduction

In the programming world, we often come across a word known as "Unit Testing". Many of us may or may not know what exactly it is. So in this post, I will share some of the information about Unit Testing with you all.

Few questions and their answers which are really important and must to know about "Unit Testing" are: 

What is Unit Testing?

Units are the smallest building blocks of software system. 

Unit testing takes place in the development environment and is the process of validating small building blocks of a software system before testing the system as a whole. 

Unit testing focuses on testing individual units of the software to ensure that those units are functioning the way they are supposed to do before integrating multiple units into modules.

Who does Unit Testing? 


When following a structural unit testing approach, also known as white-box testing, both developer and unit tester are the same.


When following a functional unit testing process, also known as black-box testing, developer and unit tester could be different people.


Why is Unit Testing Required? 


Unit testing is performed to improve the overall quality of the software written by developers in Construction Stage of the SDLC.

Since the unit testing is performed during the Construction Stage, developers can find defects earlier in the SDLC and fix them before system testing.



Above are the overall details about "What", "Who" and "Why" of Unit Testing. Let's see what are the advantages of "Unit Testing".

Advantage of Unit Testing

There are numerous benefits of performing unit testing:

Faster Development – When you write unit tests you'll spend less time debugging, and you'll have more confidence that changes to your code actually work. This confidence allows you to get more aggressive about refactoring code and adding new features. Without tests, it’s easy to become paranoid about refactoring or adding new features because you don't know what might break as a result.

Faster Debugging – Without unit testing, the time it takes to debug or resolve a functional test that may have failed can take a long time to track down. With unit testing however, the scope of the test is kept to a minimum, and the point at which a failure may be triggered can be isolated faster.

Better Design and Documentation – Writing unit tests forces developers into thinking how their code is going to be used and has generally resulted in better design and even better documentation. A comprehensive test suite can also help document the implicit behavior of the methods exposed in the classes, providing another mechanism for developers to find out more about the intended design of the class.

Better Feedback Mechanism – When all unit tests for a system are run as a whole, the state of the system as a whole can be measured. Unit tests also provide other developers with an instant mechanism of evaluating whether other parts of the code base are meeting their requirements or are still under development. Changes in test environments may sometimes cause problems with the code base, and continuous reporting of the unit test suites as a whole can help to indicate the state of the test environment.

Good Regression Testing Tool – A comprehensive unit test suite enables major refactoring and restructuring of the code base to be completed with greater confidence. As long as unit tests continue to pass, developers can be confident that their changes to the code did not have a negative impact on the functionality of the application as a whole.

Reduce Future Cost – Many studies have proved that it costs significantly more money to fix a bug found later in its release than earlier in its development. A good unit test suite will uncover basic bugs early on in the development cycle, reducing the potential of bugs surfacing later and reducing cost of future maintenance.



So, what all tools are available for different set of technologies to provide "Unit Testing" solutions?

Unit Testing Tooling Options

No single tool is likely to provide Unit Testing solutions for all the roadmaps//technologies and all types of units. The following list are popular Unit Testing tools for different types of technologies.

.NET
• Unit testing frameworks: NUnit, MSTest, xUnit, MBUnit
• Isolation frameworks: Microsoft Fakes, Moq, NUnit. Mocks
• Code Coverage frameworks: MSTest, OpenCover, dotCover, NCover

SQL Server
• Unit testing frameworks: Microsoft DB Test, tSQLt, redgate SQL Test

JavaScript
• Unit testing frameworks: Quit, Jasmine
• Test Runner frameworks: Karma, Chutzpah test running (Visual studio integrated test runner)

JAVA
• Unit testing frameworks: JUnit

PHP
• Unit testing frameworks: PHPUnit


Conclusion


In this post, we learnt and touched main content, information and questions/answers about "Unit Testing". I hope this post will help!

Read More »

Saturday, January 16, 2016

How To Create Fancy, Stylish Alert Dialog Box Using JQuery And How To Add Image In Alert Dialog Box

Introduction


In this post, I will demonstrate how to create alert dialog box which is fancy, stylish and have more control on what text to be displayed in its title and description. All in all, it will customized alert dialog box. 

This alert box will be different from the regular browser alert box which I feel is little difficult to customize and make it look fancy.

Prerequisites


To create fancy and stylish alert dialog box, we will use:
  • JQuery - To refer JQuery in our script, we will use its library from JQuery CDN
  • JQuery UI - To refer JQuery UI in our script, we will its librar from JQuery UI CDN
  • Basic knowledge of JQuery/Javascript

Let's begin...


There are few things need to be noted when we refer JQuery UI in our script code.

Firstly, we have to refer JQuery UI's ".css" file in our script code which contains the theme we will be using to create alert dialog box. To that alert dialog box, we will provide it with the fancy and stylish looks.

Secondly, we have to refer JQuery UI's ".js" file in our script code which contains all the functions we will be using in our script to trigger the alert dialog box.


Let's deep dive more and discuss little bit more about the JQuery UI's ".css" file and ".js" file reference. 

If you go to this location which has JQuery UI CDN page https://code.jquery.com/ui/, by the time I am writing this post, the JQuery UI CDN page shows content as shown in below screenshot.

You could in the below screenshot that by the time I am writing this post, this JQuery UI CDN page shows me first three top versions in its library.

The first i.e. jQuery UI - Git Builds is unstable and is not fit to use. And the second one i.e. jQuery UI 1.12 is "Pre-Release" so it is still not stable. 

Hence, we will consider and use jQuery UI 1.11 version as it is stable version. 

That means, we will be referring our ".js" file from jQuery UI 1.11 version.

If you notice just below Themes, we have plenty of them for e.g. 'black-tie', 'blitzer', 'cupertino' etc.

These are stable themes and hence we can use any one of these in our script code. These will be of ".css" file.



How to use it?


From JQuery UI CDN page, in this example, I will use ".css" file reference of "black-tie" theme and "minified.js" file reference of jQuery UI 1.11 library.

This is how we will provide the reference to all three files in our script code:

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/black-tie/jquery-ui.css">
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

In the above lines of code, we could see, in the first line I am referencing to the ".css" file of "black-tie" theme available in JQuery UI CDN library.

In the second line, I am referencing to the latest ".js" file available in JQuery CDN by the time I am writing this post.

And, in the third line, I am referencing to the latest and stable ".js" file available in JQuery UI CDN library.

How to get the alert dialog box?


Once we are done with referencing of the mandatory files as shown above, we will use JQuery UI's in built function for dialog box i.e. .dialog() function as shown below:

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/black-tie/jquery-ui.css">
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("<div title='Alert'> This is sample alert!</div>").dialog();        
    });  
 </script>

In the above code, we are creating dynamic "div" element and assigning it with the "title" property. 

Between the opening and closing "div" tag, we are providing the description and then calling it with the dialog function.

We can always change and assign any "title" and "description" for the "div" tag. 

When we will execute the above code, we will get following alert message:


So, we can see how easy it is to get the fancy and stylish alert dialog box.

Let's try any other ".css" theme reference file available in JQuery UI CDN.

For e.g., in above code we have used "black-tie" theme, now if we will use theme as "blitzer", we will get following result:




So, instead of using this code -

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/black-tie/jquery-ui.css">

We have used this code -

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/blitzer/jquery-ui.css">

In similar fashion, we can try other themes and opt for the best which suits us or our requirment.

How to add image to the alert dialog?


Let's say we want to add some image also in the alert dialog box.

Let's have below image and let's add it to the alert dialog box.



We can do the same by using below code:


<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/blitzer/jquery-ui.css">
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("<div title='Alert'><img src='C:/Users/Desktop/alert-icon.png' style='width:40px;
height:40px; vertical-align:middle;'/>  This is sample alert!</div>"
).dialog();
    });    
</script>

When will execute above script code, we will get following result.


In the above alert dialog box, we can see the image has been added and description text is right after it. We can place any of the elements in order accordingly to our needs.

Conclusion


In this post we have learnt how to create alert dialog box using JQuery. How to make alert dialog box fancy, stylish and use it with customization. Hope it helps!




Read More »

Thursday, January 14, 2016

How to get unique items or values from Multidimensional Array or an Object JQuery

Introduction


In my last post, I have demonstrated - How to get unique items or values from an Array using JQuery.

In this post, I will demonstrate how to get unique values from multidimensional array using JQuery.

Prerequisites



Let’s get started!


Before we filter the unique content from multidimensional array, let’s create the one first.

Below I have created a multidimensional array in a variable called “employee” which has two properties as “name” and “age”.
var employee = [{ "name": "Joe", "age": 25 },  // Line number 1
                { "name": "Ron", "age": 24 },  // Line number 2
                { "name": "Ken", "age": 32 },  // Line number 3
                { "name": "Dan", "age": 30 },  // Line number 4
                { "name": "Joe", "age": 25 },  // Line number 5
                { "name": "Tom", "age": 22 },  // Line number 6
                { "name": "Iva", "age": 36 },  // Line number 7
                { "name": "Joe", "age": 25 }]; // Line number 8

In the above code, if we notice, “employee” variable has “name” property “Joe” and “age” property “25” multiple times. In other words, records with the name “Joe” are duplicating.

To be precise, its occurrence in above array is thrice i.e. on line number 1, on line number 5 and on line number 8.

How to get rid of it and show records without dupes?


To get records without any duplication, let’s add some more code as:
 var dupes = [];
 var uniqueEmployees = [];

In above lines of code, we have created two more empty arrays. One will act like subordinate and other will store the unique values.
Now, we will use JQuery each function to iterate through “employee” variable to get all the records from it and then check duplicates. If no duplicates are found, we will store that in “uniqueEmployees” array.
$.each(employee, function (index, entry) {
            if (!dupes[entry.name]) {
                dupes[entry.name] = true;
                uniqueEmployees.push(entry);
            }
        });

So, in the above code, we can see the logic to loop through “employee” array and check the name in subordinate array. If nothing is found then insert the record in “uniqueEmployees” array and make dupes entry as true.

Once done, now, we can check what is it inside the “uniqueEmployees” array by using console.log() function as below:
console.log(uniqueEmployees);

This will display the output in our browser console as below:



We can see in above screenshot that we didn’t get repeating records for “Joe”.

We can also see the result in a string by alerting the string using below code:
var toDisplayText = "";
$.each(uniqueEmployees, function (index, entry) {
            toDisplayText += entry.name + ", " + entry.age + "\n";
        });

        alert(toDisplayText);

Above code will show us an output as:



Complete Code


Here is the complete code we have used to get unique items/values from multidimensional array:
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var dupes = [];
        var uniqueEmployees = [];
        var employee = [{ "name": "Joe", "age": 25 },
                        { "name": "Ron", "age": 24 },
                        { "name": "Ken", "age": 32 },
                        { "name": "Dan", "age": 30 },
                        { "name": "Joe", "age": 25 },
                        { "name": "Tom", "age": 22 },
                        { "name": "Iva", "age": 36 },
                        { "name": "Joe", "age": 25 }];      
    
        $.each(employee, function (index, entry) {
            if (!dupes[entry.name]) {
                dupes[entry.name] = true;
                uniqueEmployees.push(entry);
            }
        });

        console.log(uniqueEmployees);

        // Use below line of code to store the results of "uniqueEmployees" array in a string
        var toDisplayText = "";
        $.each(uniqueEmployees, function (index, entry) {
            toDisplayText += entry.name + ", " + entry.age + "\n";
        });

        alert(toDisplayText);
    });
</script>

Conclusion


In this post we seen how we can get unique items or values from multidimensional array, store it in a different array and display the items from it.


I hope it will be helpful to you!

Read More »

Tuesday, January 12, 2016

How to get unique items or values from an Array JQuery

Introduction


There are lots of ways by using programming techniques to filter the array data and get the unique item value(s) out of it. 

In this post, I will show how to filter the array data and get the unique item values from it by using JQuery.

Again, there are many ways to do the same in JQuery but I will show you one of many ways which I find is easy to use and implement.


Prerequisites



Let's get started!


To filter and get the unique items from an array, let's create a variable with a name as "fruits" and it has repeating items in it such as:

var fruits = ["Apple", "Oranges", "Grapes", "Guava", "Mango", "Apple", "Oranges", "Grapes", "Guava", "Mango", "Mango", "Apple", "Mango", "Apple", "Mango", "Apple"];

Now, we want to filter this array and we want unique items from the above array i.e. "Apple", "Oranges", "Grapes", "Guava" and "Mango".

To do the same, we will use .grep() function and .inArray() function of JQuery.

In laymen terms, grep() function is a utility function for arrays to filter out values.It finds the elements of an array which satisfy a filter function. The original array is not affected. 

To know more about JQuery grep() function, please see here http://api.jquery.com/jquery.grep/

The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, $.inArray() returns 0.


To know more about JQuery inArray() function, please see here https://api.jquery.com/jQuery.inArray/.

We will create another variable as "uniqueFruits" and in this variable, we will store all the unique items from the "fruits" variable we created above like this:

var uniqueFruits = $.grep(fruits, function (name, index) {
                return $.inArray(name, fruits) === index;
            }); // Returns Unique fruits

In the above lines of code, we now have all the unique fruits in the "uniqueFruits" variable and we can check the same by using alert function of Javascript or we can also check the same in browser console.

Note: We haven't touched/modified the "fruits" array. It still contains the original repeating fruits values.

Here is the browser console output of "uniqueFruits" variable:

console.log(uniqueFruits);

Gives output as:



Here is the browser alert() output of "uniqueFruits" variable:

alert(uniqueFruits);

Gives output as:


Here is the complete code we have used to filter an array and get a unique values out from it:

<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
        $(document).ready(function () {
            var fruits = ["Apple", "Oranges", "Grapes", "Guava", "Mango", "Apple", "Oranges", "Grapes", "Guava", "Mango", "Mango", "Apple", "Mango", "Apple", "Mango", "Apple"];

            var uniqueFruits = $.grep(fruits, function (name, index) {
                return $.inArray(name, fruits) === index;
            }); //Returns Unique fruits

            console.log(uniqueFruits); // Or alert(uniqueFruits);          
        });
</script>

In the above lines of code, in the first line, we are referencing to the JQuery CDN library.

In document.ready() function, we are using "fruits" array variable with repeating items in it.

And then by using .grep() and .inArray() function, we are fetching the records from array and checking if it is unique.

If it is unique, we are adding it to "uniqueFruits" variable.


Conclusion


In this post, we have seen how we can get unique items from an array using JQuery.

In my next post, I will share the information on how to get unique values from multidimensional array using JQuery.

Read More »