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 findInArray = (array, iterator) => { | |
for (let [i, v] of Object.entries(array)) { | |
if (iterator(v, Number(i))) { | |
return Number(i); | |
} | |
} | |
return -1; | |
}; | |
/* |
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 weatherInfo = t => Object.values(((c) => ({ r: `${c} is ${c > 0 ? "above ": ""}freezing temperature` }))(((m) => (m - 32) * (5/9))(t)))[0]; | |
// calc f => c |
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
class UriBuilder { | |
constructor(uri) { | |
this.root = uri; | |
this.url = this.root.split("?"); | |
this.params = {}; | |
UriBuilder.populate.apply(this); | |
}; | |
static populate() { | |
if (!this.url.length < 2) { |
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 traverseTCPStates = eventList => { | |
let state = "CLOSED"; | |
const _states = { | |
"CLOSED" : [ | |
{ event: "APP_PASSIVE_OPEN", output: "LISTEN" }, | |
{ event: "APP_ACTIVE_OPEN", output: "SYN_SENT"} | |
], | |
"LISTEN": [ | |
{ event: "RCV_SYN", output: "SYN_RCVD" }, | |
{ event: "APP_SEND", output: "SYN_SENT" }, |
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
// usage of Revealing Constructor / Module Pattern here enables instance versus business logic discretion | |
const Logger = (function () { | |
/* Internal Methods and Properties */ | |
// standard color dict for extended options | |
const _colorDict = { | |
reset : "\x1b[0m", | |
bright : "\x1b[1m", | |
dim : "\x1b[2m", |
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
class BinaryHeap { | |
constructor(fn) { | |
this.scoreFunction = fn; | |
this.data = []; | |
} | |
push(el) { | |
this.data.push(el); | |
this.bubbleUp(this.data.length - 1); | |
} |
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
// curried generator | |
const renderStringInterval = value => function*(num) { | |
yield setInterval(() => console.log(value), num); | |
}; | |
renderStringInterval('test')(3000).next(); |
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
class TestController { | |
constructor(dataSource) { | |
this.data = dataSource; | |
} | |
dispatch(obj) { | |
switch(obj.method) { | |
case "GET": | |
return this.handleGet(obj.query); | |
case "DELETE": |
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
/* auxillary helpers */ | |
const setPermissions = (r, w, x) => ({ | |
read: r || false, | |
write: w || false, | |
execute: x || false, | |
}); | |
const permissionsEnum = { | |
read: "r", | |
write: "w", |
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 init = (db) => { | |
db.actions = {}; | |
db.store = {}; | |
db.register = (name, fn) => { | |
db.actions[name] = fn; | |
return db; | |
} | |
db.dispatch = (opt) => { |