Monday 15 April 2013

Underscore.js






Underscore.js is a tiny JavaScript utility library that makes working with some of the common data structures used in JavaScript much easier. Using Underscore is extremely easy. It is not tightly bound to the DOM, doesn’t make any assumptions about other libraries or frameworks that may be in use and doesn’t require any setup or configuration. We can simply include the library file in your page and you can start calling its methods.

The library is composed of about 80 functions that provide functional programming support without extending the built-in javascript objects. What makes this library stand out is that it delegates to built-in functions if our browser or javascript engine supports it. There are several benefits of using underscore.js.

  • A performance boost due to the execution of native code.
  • Your code won’t break even if a particular browser or javascript engine doesn’t yet support the ECMA Script 5 specification.
  • More intuitive and concise javascript code.
Some of the functions out of many are explained here:

_.each
The _.each function allows for iteration through a collection in a more semantically meaningful way and will call the native function if it is supported. Please go through the code given below.

function SomeFunction(item)
{
    //function codes
}
for (index = 0; index < maxCount; ++index)
{
    SomeFunction(collection[index], index);
}
//using _.each
function SomeFunction(item)
{
    //function codes
}
.each(collection, SomeFunction);

As you can see from this example, what needs to be expressed in several lines of code can be done with one line. The code that uses _.each is elegant, far more meaningful, and it will be as efficient as it can be for the given execution environment.

_.map
The _.map function exposes the ability to “map” or transform a list by executing a user specified function. It provides a powerful way to efficiently iterate through a collection performing some operation on each element of the collection. It will also call to the native function if it is supported.


function Transformer(item)
{
   // function codes
}
var transformed = new Array();
for (index = 0; index < maxCount; ++index)
{
   transformed.push(Transformer(collection[index]));
}
// _.map to transform items in an element
function Transformer(item)
{
   // function codes
}
var transformed = _.map(collection, Transformer);

Like the _.each function _.map provides a more expressive and concise syntax for what is truly happening in the code.

_.filter
The _.filter function iterates over the provided collection, returning an array of all the values that meet the criteria of a user specified function.

function FilterCondition(item)
{
 // function codes
}
var selected = new Array();
for (index = 0; index < maxCount; ++index)
{
if (FilterCondition(collection[index]))
   {
      selected.push(collection[index]);
   }
}
// _.filter
function FilterCondition(item)
{
 // function codes
}
var selected = _.filter(collection, FilterCondition);

We can see how compact the old function code has become by using _.filter. We can also see that the use of _.filter forces the user of the function to have better separation of behaviors within their javascript code instead of having massive blocks of code that are at best tough to read and at worst introduce odd side-effects.

The above examples highlights the fact that underscore.js is one of those libraries that we should “just use”. It adds no overhead, is trivial to integrate and makes your code more robust.





[
Expecting Your Valuable Comments]
Thank You





Backbone.js







Backbone is a lightweight Model-View Javascript framework designed to help organise our websites. Backbone is based on the popular Model-View-Controller pattern.

Backbone focuses most of it’s attention on the ModelView and Collection. These are the three main components that allows us to create apps which separate out our data from our interface by storing data in our Models which are combined together in Collections, which are then bound to Views. Models represent the data within an app and can service one or many Views at any one time. Collections group together Models and can make changes across Models, Views are the visual elements we see on the page. The elements/Views listen for changes to the Model and update accordingly.

Backbone has two dependencies in order to work correctly. jQuery and Underscore.js .The Underscore library is a nice utility belt of helpful methods which complement and enhance Backbone.

Models : A Model represents the interactive data, data-logic and validation functionality within an application. It does not need to know about the Views or Collections, it simply retrieves data from a source and then stores the data as an object.

Events : An Event play an important part within an app. Events can be used to communicate to Views when data has changed in the Model, this gives the view the chance to react to the change and update the template accordingly.

List of all of the built-in events:

  • change (Model, options) — when a Model’s attributes have changed.
  • add (Model, Collection) — when a Model is added to a Collection.
  • remove (Model, Collection) — when a Model is removed from a Collection.
  • reset (Collection) — when the Collection’s entire contents have been replaced.
  • destroy (Model, Collection) — when a Model is destroyed.
  • change:[attribute] (Model, value, options) — when a specific attribute has been updated.
  • sync (Model, Collection) — triggers whenever a Model has been successfully synced to the server.
  • error (Model, Collection) — when a Model validation fails, or a save call fails on the server.
  • route:[name] (router) — when one of a router’s routes has matched.
  • all — this special event fires for any triggered event, passing the event name as the first argument.



[
Expecting Your Valuable Comments]
Thank You



Sunday 17 March 2013

MongoDB








Mongo is an open source nosql document-oriented database system which is very different from MySQL. The most considerable difference is that MySQL is written using SQL queries, while MongoDB is focused on BSON (Binary JSON) a binary object format similar to, but more expressive than JSON.

Instead of tables, a MongoDB database stores its data in collections, which are equivalent to RDBMS tables. A collection holds one or more documen, which corresponds to a record or a row in a relational database table, and each document has one or more fields, which corresponds to a column in a relational database table.

MongoDB will create collections and databases on their first use. We do not need to create the database or collection before inserting data.

MongoDB uses dynamic schemas. We can create collections without defining the structure and we also can change the structure of documents simply by adding new fields or by deleting existing ones.

Basic Commands of MongoDB:

* use mydb : Sets the context to mydb database. 
* mydb.mycol.insert( { "name" : "Mongo" } ) : Inserts document into the collection mycol.
* show.collections Shows the existing collections in database.
* mydb.mycol.find( ) : Shows the documents within a collection mycol.
* mydb.mycol.findOne( ) : Retrieves single document from the collection mycol.
* mydb.mycol.find( ).limits( n ) : Retrieves n document from the collection mycol.

Advantages of MongoDB

1Lightening fast.
2Auto sharding on it's way.
3Replication is very easy.
4You can perform rich queries, can create on the fly indexes with a single command.


Disadvantages of MongoDB

1Very unreliable.
2Indexes take up a lot of RAM.


Here you can get the Paint application using MongoDB




[Expecting Your Valuable Comments]
Thank You

Friday 8 March 2013

Tweets

Twitter Application

Enter Twitter Handle


Tweets

Thursday 7 March 2013

Huffman coding in JavaScript






Huffman coding is one of the earliest and best-know methods of text compression. It uses the principle that the common symbols are coded in just a few bits, while rare ones have longer code words.

Check out the blog post on huffman coding to understand the principles and methods that we already discussed.

Try to encode and decode data using the application developed in javascript given below. And you can download the javascript code.

Huffman coding

Enter the string to encode




Decoded text




Tuesday 12 February 2013

DJANGO





Django is a high level python web framework. First of all, why we need a framework?

Because frameworks intended to solve these problems:

1.  When multiple parts of our application needs to connect to the database.
2.  When the developer needs to worry about printing the "Content Type" line and remembering to close a 
     database connections.
3. When this code is reused in multiple environments with a 
     separate database.
4. When novice wishes to redesign the page.

MVC Design Pattern

In Django we split python code to over four Python files 
*Models.py 
*Views.py  
*Urls.py 
*HTML Template


1. Models : The file model.py contains the database description 
                   and is represented as Python class. This class is called Model. 
                   Using models we can create, retrieve, update and delete  the
                   records in our database. This makes it simple compared to 
                   SQL statements.

2. Views : The views.py file contains the business logic for the page.

3. Urls : The Urls.py file directs to the views corresponding to their 
              URL patterns.

4. HTML : The HTML templates gives designs to the web pages. 

These sections follows a pattern called Model-View-Controller (MVC).
Here database data (the model) is separate from request-routing logic (the controller), which in turn is separate from the user interface.

Advantage of this Model-View-Controller approach is that, the components are loosely coupled:

* Developer can change the URL for a part of the application without 
   affecting its implementation.
* Designers can change a page’s design in HTML code without modifying 
   Python code.
* Simple to rename a database table,since we need to specify the change in 
   a single place.

Here is the code simple paint application that i made using Django:

And here you will get the paint application that i developed in django and deployed in heroku free web server:



[Expecting Your Valuable Comments]
Thank You


Friday 18 January 2013

Software as a service ( SaaS )





Different kinds of software codes

Legacy code
* Beautiful code
* Unexpectedly short lived code

Legacy code : Old software meet customer's needs, but difficult to evolve due to design inelegance.

Beautiful code : Software meet customer's needs and easy to evolve.

Unexpectedly short lived code : Softwares that doesn't meet customer's needs. It takes long period to develop and it disappears within a short period.

Software development life cycles

* Waterfall model
* Spiral model
* Agile model

Waterfall model : It is a sequential design process , in which progress is seen as flowing  downwards through the phases, such as:

*Requirement specification
* Design
* Coding
* Integration
* Testing and debugging
* Installation
* Maintenance

Spiral model : This process combines prototyping with the designs in each steps. This model combines prototyping features and waterfall model. Thus it allows for incremental releases of the product through each time around the spiral.

Agile model : Continuous improvements and continuously refine working but incomplete prototype until customers happy, with customer feedback on each iteration and Test Driven Development (TDD) to reduce mistakes.

Assurance


Verification - Did you build the thing right
Validation - Did you build the right thing
Testing - Not a exhaustive testing 
Use Automation, Coverage, Regression testing, Integration testing, Test Driven Design


Productivity


Clarity via conciseness
         - Syntax: short and easier to read
         - Raise the level of abstraction
* Synthesis
         -Automatic code generation
* Reuse
         - Procedures and functions
         - Standardized Libraries
         - OOP
         - Design Patterns
* Automation and tools
         - Replace long and dull manual tasks with automation to save time and 
            improve accuracy
         - Dependability or User interface

Software as a service ( SaaS )


* SaaS delivers software & data as a service
* No worries in installation
* No data loss
* Easy for groups to interact with same data
* Easier upgrading features

Service oriented architecture ( SOA )

* Software architecture, where all components are designed to be services
Applications composed of inter operable services

Demands of SaaS    

* Communication
* Scalability
* Dependability
Cluster - commodity hardware
* Utility Computing / Public Cloud Computing

Cloud Computing

font-size: 15px; In the SaaS model, cloud providers install and operate application software in the cloud and cloud users access the software from cloud clients. The cloud users do not manage the cloud infrastructure and platform on which the application is running. This eliminates the need to install and run the application on the cloud user's own computers simplifying maintenance and support. What makes a cloud application different from other applications is its scalability. This can be achieved by cloning tasks onto multiple virtual machines at run-time to meet the changing work demand.



[Expecting Your Valuable Comments]
Thank You