center text in SVG shapes

Whenever you place text inside any SVG shape (rectangle, ellipse, circle etc), you would like to center text in SVG shape. In HTML placing a text relative to parent can be easily done using “text-align: center” property, similarly you can place text center of SVG shape with help of “text-anchor: middle”.  For SVG, it is not that straight forward but i will explain below, how you can achieve it. Let’s first of all create an svg tag as follow:

Now lets add a <g> tag inside svg to group multiple tag inside.

Now let’s add a circle and text tag inside <g> tag. …

Continue Reading

New ES6 Features

ECMAScript 6, also known as ECMAScript 2015, is the latest version of the ECMAScript standard. Implementation of these features in major JavaScript engines is underway now. See the ES6 standard for full specification of the ECMAScript 6 language.   ES6 includes the following new features: Arrow Function Classes Destructuring Constant and let Arrow Function: Arrow functions are a new ES6 syntax for writing JavaScript Functions. They will save developers time and simplify function scope. ES6 fat arrow functions have a shorter syntax compared to function expressions and lexically bind to this value. Arrow Function Syntax:

JavaScript function can be written in two ways …

Continue Reading

Adding large number in JavaScript

Today i had an Interview with one of the company and interviewer guy (Ritesh) asked me very simple problem that “How will you add two numbers if numbers are very large/Add large number in JavaScript?”. Frankly saying, i never gave a thought about this problem ever. My interviewer didn’t got got impressed but still i thought of solving it. So below id the function that i have coded for it. Problem: Javascript support at most 53 bit of integer only. If number goes beyond it, Javascript loose precision.  Small number can be added simply as follow:

But if you try …

Continue Reading

Javascript : Event binding on Dynamically created element

Whenever we bind events to DOM element, events got attached with all elements which are there in DOM but same events will not get attached to any element which is added dynamically. in order to understand event binding, let’s consider a below DOM structure.

Let’s apply some Styling to above HTML block.

Finally, let’s attach a addEventListener to element with class list-item.

Now if i click on final link, it will translate 30px in Y-axis. You can test the same in Codepen here. Now let’s add a dynamic DIV element with class list item and wrap it inside element with class …

Continue Reading

Angular 2 communication using Services

In this article we will discuss about communication using Services in Angular 2. This is very useful when you have more than one components which need to access and manipulate single source of data. This method is usually used in the following scenario:   Service making API hit to server and share data across all the component inside the web app. Service that pull and push data across multiple component because of it’s singleton property (Single source of truth).   Above are just the very common use cases of this methods. There are other lot of situations where you will be …

Continue Reading

Looping an Array In JSX – React JS

When you already have working experience on any of the tempting engines or framework which provide looping DOM functionality, you want it to be everywhere. As you already know, we have ng-repeat in Angular 1, *ngFor in Angular 2 etc, Likewise in React js which use JSX for templating, you can use the following method to Looping In JSX Array element.

  Output: Sahil Jake Jon Thruster Note: Looping In JSX might give you following error: Error : Each child in an array or iterator should have a unique “key” prop. You can clear above error by providing a unique …

Continue Reading

Deploy Angular 2 project in Subdirectory

Recently i was working on Angular 2 project using Angular-webpack starter template. When i was done developing whole project on my localhost. I build my project using “npm run build”. I tried loading the content of dist directory to one of my subdirectory on my hosting domain. As soon the upload is done, I got index.html at right place but every each link path is wrong like JS, CSS, Images, font-file etc. I Googled little bit but couldn’t able to find right solution at one place. So that’s why i thought of putting solving this riddle for anyone who will stuck …

Continue Reading

Git Tagging in Depth

Git tagging is actually applying marker at a specific point during the software development phase. This can be done either to go back at that particular state of your code or to mark different states of the project development which you can refer later on. In this Git tagging article, we will go through the following basic operations: Types of tag Creating a tag in a git repository List git tags How to tag an older commit Push a tag to a remote repository Checkout a new branch from a particular git tag Rename an existing tag Remove or delete a git tag …

Continue Reading

Cloning Object In JavaScript

Before going to Cloning Object In JavaScript, let’s first understand Object assignment in JavaScript. As we all know, Object assignment does not copy object but it just assign a reference to it.

Above code will output “Upwork” instead of “Media.net”. So both myInfo as well as copyInfo reference to same Object. Whenever you do any modification, it will be reflected for output of both the objects. So the question now is “how to Cloning Object In JavaScript”?. Note: Javascript is always “pass by value”, but when a variable refers to Object (including Array) than the value is just a reference to object. There …

Continue Reading