Javascript (7)


ES6 Javascript quick recap cookbook

// crreate a whole random number between [0,20) function wholeRandomNumber(){ return Math.floor(Math.random() * 20) } console.log(wholeRandomNumber()) // random numbers within a range [min, max] function randomRange(min, max){ return Math.floor(Math.random()*(max-min + 1)) + min } console.log(randomRange(1,2)) // parseInt // return integer from a string. It will returrn NaN if string cannot be converted to a number […]




Add Axios to your Vue app

Install axios npm install –save axios Then goto src/ folder and add a file called RestAPIService.js. In this file we will reside all our AXIOS interfacing code and Rest API calls. The RestAPIService.js looks like this: import axios from ‘axios’; const API_URL = ‘http://localhost:8000/api’; export class RestAPIService{ constructor(){ } async getCodes() { const url = […]




Building Front-End App in Vue with Vuetify – Part 2

We have been building Currency Converter using Vue.js. In the part-1 we built the basic layout of the app with navbar. In this tutorial we will setup a form with validation. The code for this is here. Please note that the code has been committed under commits matching with Parts. So for complete code for […]




Building Front-End App in Vue with Vuetify – Part 1

In this series, we will be building front-end app Currency Converter using Vue and Vuetify. The code for this is here. Please note that the code has been committed under commits matching with Parts. So for complete code for this tutorial, please refer to commit branch “part-1”. Pre-requisites: Please ensure that npm-cli is installed. You […]




Tips for making reusable React components

Tip 1: props.children const Picture = (props) => { return ( <div> <img src={props.src}/> {props.children} </div> ) } render () { return ( <div className=’container’> <Picture key={picture.id} src={picture.src}> //what is placed here is passed as props.children </Picture> </div> ) } Instead of invoking the component with a self-closing tag <Picture /> if you invoke it will full opening […]




Generator Functions in Javascript

We will be building on what we discussed in previous post generator-functions-using-co Here we will focus on how to implement something analogous to co. i.e. actually implement an iterable. How to run the function* Steps involved in running through a generator function. If its a bit confusing, it will be clear when we look at the […]




Generator Functions using co

Generator functions are a concept lifted likely from Python where they are used heavily in applications like web-crawlers. There are no prerequisites to this article but if you had an idea about Python generators, its the exact same concept implemented in Javascript. Definition Generators are functions which can be exited and later re-entered. Their context […]