Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Sufiyan Ansari ansarisufiyan777

🎯
Focusing
View GitHub Profile
View Prototype-Inheritance.js
function Parent(name, address) {
this.fatherName = name || "unknown";
this.fatherAddress = address || "Unknown";
}
Parent.prototype.PrintParent = function () {
console.log("In Parent",this);
}
console.log("Creating child")
View Binary-Tree-Algorithm.js
var stack = [];
/**
* get empty object node
*/
function getObj() {
return {
data: null,
isleft: true,
left: null,
View Prototype-Pattern.js
//prototype design patterns
exports.RunPrototype = () => {
TeslaModels = function () {
this.numWheels = 4;
this.manufacturer = 'Tesla';
this.make = 'Model S';
}
TeslaModels.prototype = function () {
var go = function () {
View Modular-Pattern.js
//Module design patterns
exports.RunModular = () => {
Employee = (() => {
var emp = [];
console.log("Modular Pattern:", this)
// I am private
function privateFunction() {
console.log("Private function")
}
View Observer-Pattern.js
exports.RunObserver = () => {
/**
* Subject could be anything, Whatsapp group, Circket feed, news letter
* notification
*/
var Subject = function () {
//List of subscribers
this.observers = [];
return {
View Singleton-Pattern.js
exports.RunSingleton = function () {
Printer = (() => {
let instance = null;
function createPrinter() {
function print() {
console.log("Print function", this);
}
function stop() {
console.log("Stop printer", this);
}
@ansarisufiyan777
ansarisufiyan777 / Check.js
Last active Dec 3, 2018
Check server status (Node)
View Check.js
//npm install bluebird
//npm install net
var net = require('net');
var Promise = require('bluebird');
function checkConnection(host, port, timeout) {
return new Promise(function(resolve, reject) {
timeout = timeout || 10000; // default of 10 seconds
var timer = setTimeout(function() {