Posts

Visual Studio Code Extensions for UI development

Visual Studio Code is the best IDE for any front end development. During the code development we do lots of things other than coding. Things like formatting, making builds and much more. To help the developers speed up there are lots of extensions available for Visual Studio Code. I have listed down extensions which I believe will definitely help during front end development: Beautify It is a very nice extension for formatting HTML and CSS. You not don't need to worry about the indentation, alignment of HTML and CSS files. Just select the piece of code you want to format, right click and use "Format Selection" option. It will format the code for you. JSHint Good for any JavaScript development. It provides following features: - Highlight errors based on JavaScript rules - Highlights if any code is not following best practice. It helps to avoid the bugs which can come in future due to bad code practice. - Highlights unnecessary variable declarations. Highlights ...

Application Loading Sequence with Angular CLI

When we create an angular application with Angular-CLI, it creates a skeleton project with many folders and files. In this blog,  we will be only focusing on the application loading sequence i.e. which files get loaded first and which follows it and so on. When we run ng serve command, files are loaded in following sequence: index.html It is the main HTML page. Angular CLI automatically adds all JavaScript and CSS files when building your app main.ts The main entry point for your application. Compiles the application with the JIT compiler and Bootstraps the application's root module (AppModule) to run in the browser. app/app.module.ts Defines the root module, named AppModule, that tells Angular how to assemble the application. Initially declares only the AppComponent. As you add more components to the app, they must be declared here. ...

Stack implementation using VanillaJS

Stack is a very popular data structure. It is present as library classes/interfaces in many object oriented language like Java, C#. In JavaScript there is no stack data structure by default but we can create one. I have written following code which can be used to utilize Stack features in JavaScript development. import UVModal from './UVModal'; var Stack = function(){   var items = [];   /**    * @description Pushes an item onto the top of this stack.    * @param {any} item - the item to be pushed onto this stack.    */   function push(item) {     items.push(item);   }   /**    * @description Removes the object at the top of this stack and returns that object    * @return {any} - The object at the top of this stack    */   function pop() {     return items.pop();...

Unit Test: React-Bootstrap Modal

Writing unit test always help in longer run. Now a days almost all frameworks and libraries are supporting unit testing. In React Bootstrap, there is documentation for using the unit test cases but still writing unit test cases for React-Bootstrap Modal can get confusing. After spending hours on it finally I am able to write test cases for it. These code snippets can be used for other React-Bootstrap components as well (by changing the corresponding names). Modal Source code: import React from 'react'; import Container from 'react-bootstrap/Container'; import './uv-modal.css'; function UVModal(props) { return ( <Modal {...props} aria-labelledby="contained-modal-title-vcenter"> <Modal.Header closeButton> <Modal.Title id="contained-modal-title-vcenter"> Modal Title </Modal.Title> </Modal.Header> <Modal.Body> <Containe...

JavaScript Best Practices

Getting things done is good but getting things done in better way is what matters most. Everyone wants to make their website/application to be faster, lighter. No one likes slow website/application. In order to make website/application we have to set some best practices standards and every teammate should follow that. I have written down few of the best practices which I recommend to be followed in any JavaScript development. Use === Instead of == Eval = Evil Don't use short-hand                      Bad Recommended if(condition) x = false; if(condition){ x = false; } Place scripts at the bottom of your page. The fastest way to build a HTML list. var arr = ['item 1', 'item 2', 'item 3', ...]; var list = '<ul><li>'+arr.join('</li><li>')+'</li></ul>'; Reduce global variables and methods. Add comme...

Cheat Sheet - Jasmine

We reuse many things during any application development. While working with Jasmine, generally there two sources, Jasmine Docs or Google. Even though we refer these resources, it consumes lot of time to get what we want i.e. right syntax and example. To avoid doing this every time I have enlisted few of them as cheat sheet which can be used whenever required. Create spy object with spy methods mySpy = jasmine.createSpyObj('Contact', ['get','set']); Call fake method instead of real one. mySpy.pickContact.and.callFake(function () { return { id: 10 }; }); Call a spy method and return a value var contact = { id: 10 }; mySpy.pickContact.and.returnValue(contact); Call a spy method and return a async value var contact = { id: 10 }; mySpy.pickContact.and.returnValue(asyncData(contact)); Check call counts expect(mySpy.get.calls.count()).toBe(1, 'one call'); Check most recent call expect(mySpy.get.calls.mo...

Cheat Sheet - Git

While working with Git, generally there three sources, Git Official Docs , Bitbucket Docs   or Google. Even though we refer these resources, it consumes lot of time to get what we want i.e. right syntax and example. To avoid doing this every time I have enlisted few of them as cheat sheet which can be used whenever required. Initialize git repo $ git init Set User Name and Email Id $ git config --global user.name "<user_name>" $ git config --global user.email "<user_email_id>" List Global Settings $ git config --global --list Push all changed files $ git add . $ git commit –m "<commit_message>" $ git push origin <remote_branch_name> Push a specific commit $ git push origin <commit_SHA_id>:master Stash the changes. $ git stash save "<stash_message>" Get list of stash. $ git stash list Pop last stash $ git stash pop Pop a particular stash. ( Recommended )               Use ...