Tuesday, July 19, 2016

Knockout JS

What is Knockout JS?

It is a JavaScript library based on MVVM pattern. MVVM help us to build rich and responsive websites. MVVM means model (stored data), view (UI) and view model (it represent the model). This article covers basics of Knockout JS and its concept of program in easy and simple way.

To start with Knockout JS one should have basics of html, CSS, JavaScript, DOM and text editor.
KO is an abbreviation used for KnockoutJS.
Second word for Knockout JS is KO.
KO was developed by Steve Sanderson, employee of Microsoft.
What is Knockout JS?

It is a JavaScript library based on MVVM pattern. MVVM help us to build rich and responsive websites. MVVM means model (stored data), view (UI) and view model (it represent the model). This article covers basics of Knockout JS and its concept of program in easy and simple way.

To start with Knockout JS one should have basics of html, CSS, JavaScript, DOM and text editor.
KO is an abbreviation used for KnockoutJS.
Second word for Knockout JS is KO.
KO was developed by Steve Sanderson, employee of Microsoft.

Why knockout JS?


It is easy to handle data driven interfaces with KO. With KO we can write auto update UI codes. It is cannot replace JQuery but it can work as splement with smart and very useful feature. KO is small & lightweight. KO is independent. It is compatible with both client and server side technologies.


How to use knockout JS?


you can download production build of Knockout.js from its official website



 <script type='text/javascript' src='Directory_Name/knockout-3.3.0.js'></script>

Or you can include from CDN:



 <script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js" type="text/javascript"></script>


 Example



 <!DOCTYPE html>
<head>
   <title>KnockoutJS Simple Example</title>
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js" type="text/javascript"></script>
</head>

<body>
   <!-- This is called "view" of HTML markup that defines the appearance of UI -->
   <p>First String: <input data-bind="value: fstring" /></p>
   <p>Second String: <input data-bind="value: sstring" /></p>

   <p>First String: <strong data-bind="text: fstring">Hi</strong></p>
   <p>Second String: <strong data-bind="text: sstring">There</strong></p>

   <p>Derived String: <strong data-bind="text: tstring"></strong></p>

   <script>
   <!-- This is called "viewmodel". This javascript section defines the data and behavior of UI -->

   function AppViewModel() {
       this.fstring = ko.observable("Enter First String");
       this.sstring = ko.observable("Enter Second String");

       this.tstring = ko.computed(function() {
              return this.fstring() + " " + this.sstring();
    }, this);
   }

   // Activates knockout.js
   ko.applyBindings(new AppViewModel());
   </script>
</body>
</html>
  • We have two input boxes : First String and Second String. These 2 variables are initialized with values Enter First String and Enter 
  • Second String respectively in ViewModel. <p>First String: < input data-bind="value: fstring" /> </p>This is how we are binding values from ViewModel to HTML elements using 'data-bind' attribute in the body section.Here 'fstring' refers to ViewModel variable.
  •  this.fstring = ko.observable("Enter First String");ko.observable is a concept which keeps an eye on value changes so that it can update underlying ViewModel data.To understand this better, let's update first input box to "Hello" and Second input box to "world". You will see values are updated simultaneously. We will study more about this concept in KnockoutJS - Observables chapter.
  •  this.tstring = ko.computed(function() {return this.fstring() + " " + this.sstring();}, this); Next we have computed function in viewmodel. This function derives third string based on 2 strings mentioned earlier. So any updates made first to string it directly reflects to the third string. There is no need of writing extra code to accomplish this. This is just a simple example.
Output
Save the above code as example.html. Open this file in your browser and you will see an output as below:





Other interesting things to know?


Features



  • Declarative Binding - DOM elements are directly connected to model using data-bind attribute with very simple syntax.
  • Automatically Refresh for UI- Change made to view model data are reflected in UI automatically and vice-versa. It doesn’t require extra code.
  • Dependency Tracking - Relationships between attributes and library functions/components are transparent.
  • Temp late – it is used to build complex UI structures - with possibility of repeating or nesting blocks - as a function of view model data.
  • Extensible – We can easily extends custom behavior.

KnockoutJS is widely used for Single Page Applications - A web site that is created with ability to retrieve all necessary data dynamically with a single page load reducing server round trips.

KnockoutJS is a client side framework. This is a Javascript library which makes it very easy to bind HTML to domain data. It implements a pattern called"Model-View-ViewModel"(MVVM). Observables is the magic ingredient of KnockoutJS. All data remains in sync because of Observable attribute.


View


View is nothing but User Interface created using HTML elements and CSS styling.

You can bind HTML DOM elements to data model using KnockoutJS. It provides 2 way data binding between View and ViewModel using 'data-bind' concept, which means any updates done in UI are reflected in data model and any changes done in data model are reflected in UI. One can create self-updating UI with help ofknockoutJS.

ViewModel


ViewModel is a Javascript object which contains necessary properties and functions to represent data. View and ViewModel are connected together with declarative data-bind concept used in HTML. This makes it easy to change HTML without changing ViewModel. KnockoutJS takes care of automatic data refresh between them through use of Observables.

Synchronization of data is achieved through binding DOM elements to Data Model first using data-bind and then refreshing these 2 components through use of Observables. Dependency tracking is done automatically due to this synchronization of data. No extra coding is required to achieve it. KnockoutJS allows you to create direct connection between your display and underlying data.
You can create your own bindings called as custom bindings for application specific behaviors. This way knockout gives direct control of how you want to transform your data into HTML.

Model


Model is domain data on server and it gets manipulated as and when request is sent/received from ViewModel.

The data could be stored in database, cookie or other form of persistent storage. KnockoutJS does not worry about how it is stored. It is up to programmer to communicate between stored data and KnockoutJS.


Why knockout JS?


It is easy to handle data driven interfaces with KO. With KO we can write auto update UI codes. It is cannot replace JQuery but it can work as splement with smart and very useful feature. KO is small & lightweight. KO is independent. It is compatible with both client and server side technologies.


How to use knockout JS?


you can download production build of Knockout.js from its official website



 <script type='text/javascript' src='Directory_Name/knockout-3.3.0.js'></script>

Or you can include from CDN:



 <script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js" type="text/javascript"></script>


 Example



 <!DOCTYPE html>
<head>
   <title>KnockoutJS Simple Example</title>
   <script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js" type="text/javascript"></script>
</head>

<body>
   <!-- This is called "view" of HTML markup that defines the appearance of UI -->
   <p>First String: <input data-bind="value: fstring" /></p>
   <p>Second String: <input data-bind="value: sstring" /></p>

   <p>First String: <strong data-bind="text: fstring">Hi</strong></p>
   <p>Second String: <strong data-bind="text: sstring">There</strong></p>

   <p>Derived String: <strong data-bind="text: tstring"></strong></p>

   <script>
   <!-- This is called "viewmodel". This javascript section defines the data and behavior of UI -->

   function AppViewModel() {
       this.fstring = ko.observable("Enter First String");
       this.sstring = ko.observable("Enter Second String");

       this.tstring = ko.computed(function() {
              return this.fstring() + " " + this.sstring();
    }, this);
   }

   // Activates knockout.js
   ko.applyBindings(new AppViewModel());
   </script>
</body>
</html>

  • We have two input boxes : First String and Second String. These 2 variables are initialized with values Enter First String and Enter Second String respectively in ViewModel.
  •  <p>First String: < input data-bind="value: fstring" /> </p>This is how we are binding values from ViewModel to HTML elements using 'data-bind' attribute in the body section.Here 'fstring' refers to ViewModel variable.
  •  this.fstring = ko.observable("Enter First String");ko.observable is a concept which keeps an eye on value changes so that it can update underlying ViewModel data.To understand this better, let's update first input box to "Hello" and Second input box to "world". You will see values are updated simultaneously. We will study more about this concept in KnockoutJS - Observables chapter.
  • this.tstring = ko.computed(function() {return this.fstring() + " " + this.sstring();}, this); Next we have computed function in viewmodel. This function derives third string based on 2 strings mentioned earlier. So any updates made first to string it directly reflects to the third string. There is no need of writing extra code to accomplish this. This is just a simple example.

Output
Save the above code as example.html. Open this file in your browser and you will see an output as below:





Other interesting things to know?


Features


  • Declarative Binding - DOM elements are directly connected to model using data-bind attribute with very simple syntax.
  • Automatically Refresh for UI- Change made to view model data are reflected in UI automatically and vice-versa. It doesn’t require extra code.
  • Dependency Tracking - Relationships between attributes and library functions/components are transparent.
  • Temp late – it is used to build complex UI structures - with possibility of repeating or nesting blocks - as a function of view model data.
  • Extensible – We can easily extends custom behavior.

KnockoutJS is widely used for Single Page Applications - A web site that is created with ability to retrieve all necessary data dynamically with a single page load reducing server round trips.


KnockoutJS is a client side framework. This is a Javascript library which makes it very easy to bind HTML to domain data. It implements a pattern called"Model-View-ViewModel"(MVVM). Observables is the magic ingredient of KnockoutJS. All data remains in sync because of Observable attribute.


View


View is nothing but User Interface created using HTML elements and CSS styling.

You can bind HTML DOM elements to data model using KnockoutJS. It provides 2 way data binding between View and ViewModel using 'data-bind' concept, which means any updates done in UI are reflected in data model and any changes done in data model are reflected in UI. One can create self-updating UI with help ofknockoutJS.

ViewModel


ViewModel is a Javascript object which contains necessary properties and functions to represent data. View and ViewModel are connected together with declarative data-bind concept used in HTML. This makes it easy to change HTML without changing ViewModel. KnockoutJS takes care of automatic data refresh between them through use of Observables.

Synchronization of data is achieved through binding DOM elements to Data Model first using data-bind and then refreshing these 2 components through use of Observables. Dependency tracking is done automatically due to this synchronization of data. No extra coding is required to achieve it. KnockoutJS allows you to create direct connection between your display and underlying data.
You can create your own bindings called as custom bindings for application specific behaviors. This way knockout gives direct control of how you want to transform your data into HTML.

Model


Model is domain data on server and it gets manipulated as and when request is sent/received from ViewModel.

The data could be stored in database, cookie or other form of persistent storage. KnockoutJS does not worry about how it is stored. It is up to programmer to communicate between stored data and KnockoutJS.

Thursday, July 14, 2016

Mongo DB

What is Mongo DB?

Mongo DB is C++ open-source document database. This article will help you learn mongo DB database with simple and easy steps. Before going further one should have basic understanding of database, text editor etc. and also basic concept of RDBMS.

Collection of different types of data is called Database. We can also it is a type of container. Every single mongo DB server has more than one databases.
Mongo DB Is a document oriented database which provides great performance, very data availability and easy scalability.

Why to use Mongo DB?

· Document Oriented Storage
· Attribute with index
· Any time data availability
· Rich Queries
· Fast In-Place Updates

How to use Mongo DB?

Supported Platform.

Starting in version 2.2, Mongo DB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of Mongo DB.

For windows user.

Download mongodb.msi from below given link

https://www.mongodb.com/download-center?jmp=docs&_ga=1.34194593.1801687251.1468239835
After downloading locate the file and run a wizard will guide you through the installation process.

Basic syntax to use Database

use DATABASE_NAME

Example

This example will create database with name f_db:

>use f_db
switched to db f_db

Example to insert document to db

>db.f_col.insert({

   _id: ObjectId(7df78ad8902c),
   title: 'MongoDB Overview',
   tags: ['mongodb', 'database', 'NoSQL'],
  
})


Other interesting things to know?

Collection

RDBMS
MongoDB
Database
Database
Collection
Table
Documents
Tuple/Row
Field
Column
Embedded document
Table Join
Primary Key (Default key _id provided by mongo db itself)
Primary Key
Mongo DB
My SQL/Oracle
Mongo
My SQL/SQL plus


Group of mongo DB documents is called a collection. It is same as RDBMS table. It limit within one single database. Document in the collection are related to each other or it is of similar type. There is nothing like schema in collections.

Document

A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection's documents may hold different types of data.

A set of key value pair is called a Document. It contains dynamics schema which means the documents with same collection does not need to have the same set of fields or structure it can hold data with different types.

Advantages of Mongo DB over RDBMS

· Schema less
· Structure of a single object is clear
· No complex joins
· Deep query-ability. We can write dynamic query.
· Tuning
· Mongo DB is easy to scale
· Uses internal memory for storing the (windowed) working set, enabling faster access of data

Thursday, July 7, 2016

Angular JS

What is Angular JS?

Angular JS is one of the important framework of JavaScript. It is easy to add Angular JS to any HTML page just with a <script> tag. Angular JS is used bind data to HTML with its Expression and it also extends the attributes of HTML with Directives. Angular JS is library written in Java Script.

It extends the functionality of HTML with new attributes. It is MVW (Model-View-Whatever) structured framework which allow us to create dynamic web application. It is maintained by Google and is allows you to develop with well-constructed web app and it also easy to maintain. It uses declarative programming to build UI. It is client side so all processing is on the browser itself.

Why Angular JS?
  1. We can create and reuse the template any time and whenever we need it.
  2. There are 2 ways to bind the data, which is changing data will automatically change the element and changing element will change the data.
  3. We can directly use the code-behind with HTML.
  4. We can directly validate forms and fields without writing any type of code.
  5. We can control DOM structure.
  6. It allows us to write basic flow end-to-end testing, unit-testing.

In short, Angular JS provides all the functionality to build a CRUD application such as data-binding, data validation, URL routing, reusable HTML components and most importantly dependency injection.

How to use it?


Angular JS can be added to a web page with a script tag:


<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
or

<script src="your DIRECTORY/angularjs/1.4.8/angular.min.js"></script>


HTML example


<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="">
 
<p>Name: <input type="text" ng-model="name"></p>
 
<p ng-bind="name"></p>
</div>

</body>
</html>

We don’t need to start Angular JS it is automatically starts when html page is loaded.
The ng-app is a directive which tells Angular JS that the <div> element is "owner" of an Angular JS app.
The ng-model is also directive which binds the value of the input field to app variable name.
The ng-bind directive binds the inner HTML of the <p> tag to the application variable name.





Other interesting things to know about Agular JS

  • AngularJS is designed to separate your presentation layer from your business logic layer
  • AngularJS is a powerful tool which, when used correctly, can make your presentation layer both more maintainable and more robust
  • It is fully extensible and works well with other libraries