Skip to content

Instantly share code, notes, and snippets.

View nitin42's full-sized avatar
👋

Nitin Tulswani nitin42

👋
View GitHub Profile
@nitin42
nitin42 / universal-links-react-native.md
Last active February 16, 2024 11:45
Handling Universal Links in React Native web view
@nitin42
nitin42 / react-native-accordion.md
Last active March 27, 2023 18:40
Creating an accessible Accordion component in React Native
@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];
This file has been truncated, but you can view the full file.
/*
Jimp v0.2.28
https://github.com/oliver-moran/jimp
Ported for the Web by Phil Seaton
The MIT License (MIT)
Copyright (c) 2014 Oliver Moran
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@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 / eventemitter.js
Created June 19, 2017 21:46 — forked from mudge/eventemitter.js
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
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();
};
@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 / 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
}
class Grouping extends Expression {
constructor(expression) {
super()
this.expression = expression
}
handle(visitor) {
return visitor.visitGroupingExpression(this)
}
}