Skip to content

Instantly share code, notes, and snippets.

View nitin42's full-sized avatar
๐Ÿ‘‹

Nitin Tulswani nitin42

๐Ÿ‘‹
View GitHub Profile
var TrafficLight = function () {
var count = 0;
var currentState = new Red(this);
this.change = function (state) {
// limits number of changes
if (count++ >= 10) return;
currentState = state;
currentState.go();
};
/** @license React v16.1.0-beta
* react-reconciler.development.js
*
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/*
React v16.1.0-beta
react-reconciler.production.min.js
Copyright (c) 2013-present, Facebook, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
'use strict';var Va;
/** @license React v16.1.0-beta
* react-dom.development.js
*
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
(function (global, factory) {
/*
React v16.1.0-beta
react-dom.production.min.js
Copyright (c) 2013-present, Facebook, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
Modernizr 3.0.0pre (Custom Build) | MIT
*/
@nitin42
nitin42 / Observer.js
Created October 29, 2017 19:31
Observer pattern in a nutshell
function Click() {
this.handlers = []; // observers
}
Click.prototype = {
subscribe: function(fn) {
this.handlers.push(fn);
},
@nitin42
nitin42 / Flyweight.js
Created October 29, 2017 19:31
Flyweight pattern in a nutshell
function Flyweight (make, model, processor) {
this.make = make;
this.model = model;
this.processor = processor;
};
var FlyWeightFactory = (function () {
var flyweights = {};
return {
@nitin42
nitin42 / command.js
Created October 29, 2017 16:40
Command pattern in a nutshell
/**
* This is sample code which represents command pattern.
* A command pattern basically instructs a function to perform some actions.
* It is a function call wrapped in an object and very useful where we want a layer of abstraction between the action creator and the action to be performed
*/
// Action
function add(a, b) {
return a + b
}
@nitin42
nitin42 / require.js
Created October 8, 2017 15:33
How Node.js's require() works ??
const some_module = require('some_module')
/**
* require('some_module') calls Module._load
*
* Module._load then tries to load the module with a filename (also save it to the cache) using module.load(filename)
*
* module.load(filename), given a filename, passes it to the proper extension handler ('.js', '.json')
*
* If there were any errors when loading the file, it deletes the file from the cache (delete Module._cache[filename]) and throws an error
@nitin42
nitin42 / gc.js
Created September 23, 2017 17:50
Mark and Sweep Algorithm implementation
let HEAP = [];
const A = {
language: 'JavaScript'
};
HEAP.push(A);
const root = () => HEAP[0];