Skip to content

Instantly share code, notes, and snippets.

View muralikrishnat's full-sized avatar

Muralikrishna T muralikrishnat

View GitHub Profile
@muralikrishnat
muralikrishnat / app.js
Created September 6, 2015 07:31
Asynchronous Javascript Execution
//core method to handle execution
//has two arguments one is Array of methods that has to execute
//second param is enabling step by step execution.
function makeexecution(methodsArray, isStepbystep) {
//creating promise Object to return
var promise = {};
//method to execute steps one by one If isStepbystep flag is set as true
//It uses to execute array of methods in synchronous manner.
function executeNextMethod(methodsArray, methodIndex, callback) {
if (methodsArray.length === methodIndex) {
@muralikrishnat
muralikrishnat / basic-javscript-behaviour.js
Created September 17, 2015 14:45
Javascript basic behaviour of context
//Javascript basic behaviour
//As we know, everything in javascript is goes as key value Pair but the difference is context
var Name = "Jason Bourne";
//above code will declare variable called 'Name' and that is added to window object as below
console.log(window["Name"]); //prints 'Jason Bourne' in console
console.log(Name); //prints 'Jason Bourne' in console
//the context of variable declarassion is window, So we can access 'Name' in above ways
//either key of the window or direct variable name
//simple represenation of above variable under window is
//window = {
@muralikrishnat
muralikrishnat / dependency-injection-basics.js
Created September 18, 2015 11:13
Behind the scenes of Dependency Injection
//Pre-requirements: knowing following concepts is good to understand DI in better way.
//1.SingleTon Design Pattern and usage
//2.'call' and 'apply' methods
//Intro: Below Code example is the basic explanation of Dependency Injection
//it explains how we can achieve DI with basic things.
//gives basic idea of how DI will work ,how to handle arguments
//Declaring the Dependency Injection Manager class/function
@muralikrishnat
muralikrishnat / inheritance-concept.js
Created September 18, 2015 13:05
Inheritance in Javascript with simple example
//Intro : Basic explanation of Javascript Inheritance concept
//there are many ways to achieve inheritance feature in Javascript
//this is one of the approach I follow most of the time.
//Declaring Parent Class/Function
//with three properties and one method
var ParentClass = function(property1, property2){
this.Property1 = property1;
this.Property2 = property2;
@muralikrishnat
muralikrishnat / index.html
Created September 23, 2015 10:20
Two way binding for text with simple example using Javascript
<html>
<head>
<title>Behind the scenes of Two Way binding simple example for text</title>
<!-- Adding JS reference -->
<script src="two-way-binding.js"></script>
</head>
<!-- Invoking the binding Manager after completion of DOM load-->
<body onload="bindManager.init()">
<div class="demo-page">
@muralikrishnat
muralikrishnat / app.js
Last active August 30, 2022 05:42
Achieving routing using pure Javascript
var App = {};
var addRoutes = function () {
$NB.addRoute('/books/:id', function (params) {
console.log('Route is ', params.Title, params.id);
}, 'books');
$NB.addRoute('/:category/:id', function (params) {
console.log('Route is ', params.Title, params.category, params.id);
}, 'category');
@muralikrishnat
muralikrishnat / index.html
Created March 3, 2017 10:32
Concept of Virtual DOM
<!DOCTYPE html>
<html lang="en">
<head>
<title>Creating Virtual DOM</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="root"></div>
<script>
@muralikrishnat
muralikrishnat / basic-templating.html
Last active March 4, 2017 19:10
Secret of Javascript Templating
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
@muralikrishnat
muralikrishnat / fe-server.js
Created December 25, 2017 10:25
Node JS script as static server and proxy server
var static = require('node-static');
var rootRequest = require('request');
var fs = require('fs');
var path = require('path');
var buildInProgress = false;
module.exports = function(options) {
console.log('options', options);
var baseUrl = 'https://dev.azurewebsites.net';
@muralikrishnat
muralikrishnat / to-words.js
Created April 14, 2018 19:04
Converting number into word string
var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ','thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen '];
var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
function inWords (num) {
if ((num = num.toString()).length > 9) return 'overflow';
n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
if (!n) return; var str = '';
str += (n[1] != 0) ? (a[Number(n[1])] || b[n[1][0]] + ' ' + a[n[1][1]]) + 'crore ' : '';
str += (n[2] != 0) ? (a[Number(n[2])] || b[n[2][0]] + ' ' + a[n[2][1]]) + 'lakh ' : '';
str += (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'thousand ' : '';