Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
night-fury-rider / shot-hand.js
Created September 9, 2020 04:01
Without Short hand condition
if(isVisible) {
console.log('We should use the braces even if there is only one statement in block');
}
@night-fury-rider
night-fury-rider / npm-package.json
Last active March 26, 2021 05:26
NPM Package - package.json
{
"name": "@uv-tech/util",
"version": "1.0.5",
"description": "It is a utility package intended to be used for doing common utilities.",
"main": "lib/index.js",
"type": "lib",
"scripts": {
"build": "tsc -p ."
},
"keywords": [
@night-fury-rider
night-fury-rider / observer-design-pattern.ts
Created July 9, 2020 12:30
Design Pattern - Observer
const employeeObservable = new Rx.Observable(employeeObserver => {
employeeObserver.next('Yuvraj Patil');
employeeObserver.next('Ganesh Gaitonde');
});
employeeObservable.subscribe(employeeName => {
console.log('Promoted Employee: ', employeeName);
});
@night-fury-rider
night-fury-rider / closure-loop.js
Created June 24, 2020 04:04
Closure inside loop
for(var i=0; i<5; i++) {
(function (i){
setTimeout(function() {
console.log(i);
}, 0);
})(i);
}
var uvHttp = new XMLHttpRequest();
uvHttp.onreadystatechange = function() {
console.log('HTTP state change callback executed');
};
uvHttp.open("GET", "/getUser", true);
uvHttp.send();
document.getElementById("add-user").addEventListener("click", addUser);
function addUser() {
console.log('User has been added');
}
@night-fury-rider
night-fury-rider / setInterval.js
Created June 24, 2020 03:02
Basic setInterval
var numberOfKingdoms = 7;
setInterval(function(){
alert('Jon should be king of ' + numberOfKingdoms + ' kingdoms');
}, 500)
@night-fury-rider
night-fury-rider / setTimeout.js
Last active July 3, 2020 13:48
Basic SetTimeout
var numberOfKingdoms = 7;
setTimeout(function(){
alert('Jon should be king of ' + numberOfKingdoms + ' kingdoms');
}, 500);
@night-fury-rider
night-fury-rider / Basic Closure.js
Last active July 3, 2020 13:35
What we need is closure - Basic
var sodexoAmount = 25;
function getSalary(baseSalary) {
var transportAmount = 50;
function calculateSalary(hraAmount) {
var specialAllowance = 75;
return specialAllowance + hraAmount + baseSalary + transportAmount + sodexoAmount;
}
return calculateSalary;
}
var monthlySalary = getSalary(100);
@night-fury-rider
night-fury-rider / uv-util.service.spec.ts
Last active May 31, 2020 04:31
Unit testing Angular Application using Jasmine - Util Service spec
import { TestBed } from '@angular/core/testing';
import * as globalmocks from '../globalmocks';
import { UvUtilService } from './uv-util.service';
describe('UvUtilService', () => {
let service: UvUtilService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(UvUtilService);