Skip to content

Instantly share code, notes, and snippets.

View ansarisufiyan777's full-sized avatar
🎯
Focusing

Sufiyan Ansari ansarisufiyan777

🎯
Focusing
View GitHub Profile
@ansarisufiyan777
ansarisufiyan777 / Check.js
Last active December 3, 2018 08:43
Check server status (Node)
//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() {
exports.RunSingleton = function () {
Printer = (() => {
let instance = null;
function createPrinter() {
function print() {
console.log("Print function", this);
}
function stop() {
console.log("Stop printer", this);
}
exports.RunObserver = () => {
/**
* Subject could be anything, Whatsapp group, Circket feed, news letter
* notification
*/
var Subject = function () {
//List of subscribers
this.observers = [];
return {
//Module design patterns
exports.RunModular = () => {
Employee = (() => {
var emp = [];
console.log("Modular Pattern:", this)
// I am private
function privateFunction() {
console.log("Private function")
}
//prototype design patterns
exports.RunPrototype = () => {
TeslaModels = function () {
this.numWheels = 4;
this.manufacturer = 'Tesla';
this.make = 'Model S';
}
TeslaModels.prototype = function () {
var go = function () {
@ansarisufiyan777
ansarisufiyan777 / Binary-Tree-Algorithm.js
Created September 3, 2019 12:39
Binary tree in typescript
var stack = [];
/**
* get empty object node
*/
function getObj() {
return {
data: null,
isleft: true,
left: null,
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")