This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const copy = item => { | |
return !item ? item | |
: Array.isArray(item) ? deepArrayCopy(item) | |
: Object.prototype.toString.call(item).includes('Date') ? new Date(item.getTime()) | |
: typeof item === 'object' ? deepCopy(item) | |
: item | |
} | |
const deepCopy = obj => { | |
const objKeys = Object.keys(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const trampoline = fn => (...args) => { | |
let res = fn(...args) | |
while(typeof res === 'function'){ | |
res = res() | |
} | |
return res | |
} | |
/*call trampoline with a function that returns either the resolved | |
value (if termination parameters are met) or the next function call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debounce = (callback, wait) => { | |
let timeout = null | |
return (...args) => { | |
const next = () => callback(...args) | |
clearTimeout(timeout) | |
timeout = setTimeout(next, wait) | |
} | |
} | |
const inputEl = document.getElementsByTagName('input')[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ARGS = process.argv.slice(2), | |
COMPONENT_NAME = ARGS[0], | |
COMPONENT_IS_SYSTEM = ARGS[1] == 'true', | |
JSX_SUUBPATH = (COMPONENT_IS_SYSTEM) ? 'systems' : 'components', | |
COMPONENT_DIR = `./${JSX_SUUBPATH}/${COMPONENT_NAME}`, | |
fs = require('fs') | |
if(!COMPONENT_NAME) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gameLoop = function(res) { | |
var gamepad = navigator.getGamepads(); | |
navigator.getGamepads()[0].buttons.forEach(function(button, i, buttons) { | |
if(button.pressed) console.log('pressed: ', buttons.slice(),' i: ', i, buttons[i]) | |
}); | |
requestAnimationFrame(gameLoop) | |
} | |
window.addEventListener('gamepadconnected', gameLoop) | |
// src: https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numsRef = { | |
1: 1, | |
2: 2, | |
3: 4, | |
4: { 1: 'hi' } | |
}; | |
let deepObj = { | |
numbers: numsRef | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createStore = (reducer, initialState) => { | |
const subscribers = []; | |
let currentState = initialState; | |
return { | |
getState: () => currentState, | |
subscribe: fn => { | |
subscribers.push(fn); | |
fn(currentState); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const generate2dBoard = (cols, rows) => { | |
let board = generate2dArray(cols, rows); | |
let roomSpecs = { | |
heightMin: 5, | |
heightMax: 6, | |
widthMin: 5, | |
widthMax: 6, | |
paddingMin: 1, | |
paddingMax: 4 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Oldsmobile = function(year, color) { | |
// private members: | |
var allowed = ['red', 'black', 'tan']; | |
var defaultColor = 'black'; | |
// manipulate instance initialization by accessing constructor methods: | |
Oldsmobile.addAllowed(allowed, 'blue'); | |
// privleged members: | |
this.color = allowed.find(_color => _color === color) ? color : defaultColor; |