Skip to content

Muthukrishnan

AI, Computer Vision, Algorithms and Mathematics

  • About me
May 13, 2016
  • Javascript

Difference between localStorage, sessionStorage and cookies

localStorage, sessionStorage and cookies are all client storage solutions which store data as key/value pairs in the browser. localStorage and sessionStorage both extend Storage. There is no difference between them except for the intended “non-persistence” of sessionStorage. sessionStorage maintains a separate storage area for each given origin that’s available for the duration of the page […]

May 8, 2016
  • Angularjs
  • Javascript

contenteditable DIV tag directive

Are you looking for a super simple WYSWYG editor and you don’t want to include any heavy library into your application. Then why not make your own using just a div. Take a look at the below directive. myApp.directive(“contenteditable”, function() { return { restrict: “A”, require: “ngModel”, link: function(scope, element, attrs, ngModel) { function read() […]

April 27, 2016
  • Javascript

Inheritance in Javascript

Inheritance is a concept which says you can create a class from another class if you would like to use its properties. A parent cantalk and caneat, so can the child because child “is a” subclass of Parent. While most programming languages have the concept of classes, in javascript its all about objects inheriting from other […]

April 27, 2016
  • Javascript

Different ways of creating an object in Javascript

//1. using curly braces var myVar = {}; //2. using new operator var myVar = new Object(); //3. using the Object.create method var myVar = Object.create(Object.prototype);

April 27, 2016
  • Javascript

for…in statement to loop through the javascript object properties

for..in is used to iterate through the properties in our javascript objects. The syntax for (variable in object) { //do something with the variable } Example “use strict” var obj = {a:1, b:2, c:3}; for (var prop in obj) { console.log(“obj.” + prop + ” = ” + obj[prop]); } // Output: // “obj.a = 1” […]

April 26, 2016
  • Javascript

Different ways of setting a value to a Javascript object

Different ways of setting a value to a Javascript object //create an object var myVar = {}; //1. set value using dot myVar.key = “myvalue”; //2. set value using square brackets myVar[“key2”] = “myValue2″ //3. set value using defineProperty Object.defineProperty(myVar,”key3”,{ value : “myValue3” }); Setting values using the dot syntax or square brackets is pretty easy […]

March 30, 2016
  • Javascript

Important Javascript Code snippets

To Generate UUID function generateUUID() { var d = new Date().getTime(); var uuid = ‘xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx’.replace(/[xy]/g, function(c) { var r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c == ‘x’ ? r : (r & 0x3 | 0x8)).toString(16); }); return uuid; } Sample output : 48808c28-24e0-4081-be13-2c27948bfa27 Extract […]

February 29, 2016
  • Angularjs
  • Javascript

Scroll to Top Angular Directive

The below directive creates a scroll to top icon on the bottom right corner of the page. On click it will smoothly scroll you position back to top. Angular Directive: function ScrollToTop() { return { template: “<a ng-click=’click()’ class=’scroll-to-top-anchor’></a>”, replace: true, scope: true, controller: function($scope) { $scope.click = function() { var startY = currentYPosition(); var stopY […]

February 24, 2016
  • Grus

Grus – An intelligent question answering machine

Lets say I give you a print out of Professor Albert Einstein’s Wikipedia page and tell you that I am going to ask you questions from that text. You will have enough time to read through the document and find the answers that I am looking for. Assuming you are good at finding answers, here is […]

February 23, 2016
  • Javascript

Code for Base64 Encoding and Decoding of String – Javascript

What is Base64? Base64 is a generic term for a number of similar encoding schemes that encode binary data by treating it numerically and translating it into a base 64 representation. The Base64 term originates from a specific MIME content transfer encoding. Base64 encoding schemes are commonly used when there is a need to encode […]

Posts navigation

‹ Previous page Next page ›
My Recently Published Book

© 2023 Muthukrishnan