Showing posts with label js. Show all posts
Showing posts with label js. Show all posts

Saturday, 21 June 2014

My experience with node and mongodb course "M101JS: MongoDB for Node.js Developers" (Third Week)

Well, currently I am into the third week of mongodb node course "M101JS: MongoDB for Node.js Developers" and I am pretty enjoying it.

Lots of personal learning into node and mongodb.

The third week subject of "Patterns, Case Studies & Tradeoffs" is really interesting.

Here is a list of topics, I learned about:
- Mongodb rich documents concept.
- Mongodb schema use cases.
- Mongodb one:one, one:many, many:many use cases.
- How to select schema based on the usage like whether you want max performance
  or it may be a tradeoff.

One important point, I learned during the course is:
"While relational databases usually go for the normalised 3rd form so that data usage is agnostic to application, but mongodb schema arrangement is very closely related to application usage and varies accordingly."

Thursday, 19 June 2014

The self-executing anonymous function

There are three parts to it:
1. It's anonymous and does not have a name.
2. It self executes.
3. It's a function.

Well, a self-executing anonymous function has it's own uses.

First case, where you need to execute some functionality without it effecting other surrounding functionality nor the surrounding environment effecting it. It basically creates a local private execution area bereft of the outside environment.

Example:

var name  = 'The Master Dev';

(function () {
    var name = 'The Rookie Dev';
    console.log(name); // Outputs "The Rookie Dev"
}) ();

console.log(name); // Outputs "The Master Dev"

Second case, where lets say you have a lot of code inside a <script> block and you want to test breakpoints and exit and not execute the remaining code, then in this case surrounding the entire code in a anonymous function and using return as an exit point helps.

Example:

<script>

var line = 'Hello World';

// some code
// here

// Need to debug here and exit

// and here

</script>

With self-executing anonymous function:

<script>

(function () {
    var line = 'Hello World';

    // some code
    // here

    return;

    // and here
});

</script>

Wednesday, 11 June 2014

An intro to Offline.js

Ever wondered how many times we have been browsing a site and we do not see any activity. After many wonders and one refresh, we find that our internet connection is down.

Well, wouldn't it be nice if someone notifies us. Do not worry, because Offline.js comes to your rescue to provide your users with that unique experience.

References:

Site: Offline.js
Docs: Offline.js doc
Github page: Offline.js Git
Demo page: Offline.js Demo

Some of the things it manages to do are:

1. It basically notifies the users that they have lost internet connectivity.
2. It captures ajax requests made during the offline state and remakes them when the connection is back.
3. It requires zero configuration.
4. It provides many themes to improve the user experience and to blend with your site.
5. It's minified and comes at 3kb size.