Technology

JavaScript : String.slice() vs String.substring() vs String.substr()

In this blog, we will discuss about few methods that are used in JavaScript for partial string extraction. You can also see my blog specific on Arrays which are used in JavaScript. The following methods are :- slice() substring() substr() All these methods extracts parts of a string and returns the extracted parts in a...

by Vivek Garg
Tag: javascript
19-Feb-2015

Technology

JavaScript : Array.splice() vs Array.slice()

1. The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object. 2. The splice() method changes the original array and slice() method doesn't change the original array. 3. The splice() method can take n number of arguments: Argument 1: Index,...

by Vivek Garg
Tag: javascript
18-Feb-2015

Node.js

Highlighting links in text using “linky” filter

At times we come across few cases where we need to differentiate the links amongst the plain text. Angular provide us with a very useful filter named : "linky" which help us to do so. With the help of linky filter we can detect links from text and show them differently .  Linky takes text and produces HTML by wrapping all...

by Rubi Saini
Tag: javascript
13-Feb-2015

Node.js

High performance find query using lean() in mongoose

Lets start with a basic find query in mongoose and observe its execution time. [js] Event.find({'schedule.closing': {'$gte': +new Date()}}, {}, {limit:20, skip:0} ).exec(function (err, events){ ........ ........ } ); [/js] In my last project on Nodejs, I have used the above query to fetch the events...

by Sakshi Tyagi
Tag: javascript
13-Feb-2015

Node.js

‘resolve’ property in angular

Now a days , angular ui-router is being used actively for maintaining routes in angular applications. In my current project, I came across a use case in which I had to perform certain checks before executing certain route mapping. For example lets consider the most basic situation in which we want to directly show dashboard route in case...

by Rubi Saini
Tag: javascript
22-Jan-2015

Technology

How to get name initials as an image?

While making an application, showing user's image is a very common use case. Gone were the days when we used to show anonymous image in case a person's profile image or display image is not present. We can easily show a person's name initials as an image to identify the person. Like : Lets consider this html, where we use an...

by Sakshi Tyagi
Tag: javascript
07-Dec-2014

Android

Debugging Javascript on Android using Chrome

Nowadays almost all applications that we develop are made mobile friendly and a lot of times, everything works perfectly on desktop browsers but not on mobile. Even if we know it is some javascript that is not working as expected, it becomes quite difficult to narrow down on what is causing problem. As we cannot check console there, I...

by Vivek Sachdeva
Tag: javascript
30-Nov-2014

Technology

Variable Hoisting In JavaScript

Javascript handles function and variable declartions quite differently and you must have got stuck in one of the awkard scenarios due to it. First of all, you should be familiar with Scoping in JavaScript. If you are, then you would know already that JavaScript only has function scopes and no block scopes. [js] var a = 'hello'; ...

by Sakshi Tyagi
Tag: javascript
12-Oct-2014

Technology

Explicitly providing ng-model to DOM elements

In AngularJS, we can easily write our own custom directives to achieve required functionality. There are certain attributes which we provide in directive definition like restrict , scope , template, link, transclude etc. There is one more attribute named : require , which gives us the liberty to include another directive and inject...

by Sakshi Tyagi
Tag: javascript
28-Jul-2014

Grails

Uploading a file using only Ajax

We often need to upload a file without refreshing page or even before user submits the complete form. We have been using flash uploaders or i-frames to achieve that. However now it is possible to upload a file using only ajax and javascript. The first thing we need is a HTML form that will allow the user to select the file that they...

by Mansi Arora
Tag: javascript
04-Jul-2014

Node.js

Generate PDF in NodeJS using “node-phantom” module

PhantomJS is used to emulate browsers through command line, for generating PDFs, web page manipulation, headless testing and much more interesting stuff. Npm provides us a module called "node-phantom" which helps us to use PhantomJS in our NodeJS application in a non-fussy way. A prerequisite for using this module is, you must have...

by Sakshi Tyagi
Tag: javascript
27-Jun-2014

Node.js

Defining custom errors – NodeJS

Any well written piece of code should be defensive by nature with defensive error handling understanding that things could go wrong. Things would be great if we can define our own custom error classes which we can pass or throw in order to distinguish various errors. Custom error constructors helps in: ⇒   Identifying...

by Kushal Likhi
Tag: javascript
23-Jun-2014