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
| 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 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
| 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 rowWeights = arr => { | |
| let a = 0; | |
| let b = 0; | |
| Object.entries(arr).forEach(([i, val]) => { | |
| i % 2 === 0 ? a += val : b += val; | |
| }); | |
| return [a, b]; | |
| } | |
| /* |
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
| /* Nodejs Quines */ | |
| // everything is wrapped in its own execution context so you can copy + paste the entire snippet without conflicts; | |
| // else, the liberal use of semicolons (and in some instances, the lack thereof) will confuse the interpreter and throw exceptions | |
| // IIFE ES6 quine | |
| { | |
| (x=_=>console.log(`(x=${x})();`))(); | |
| // 36 bytes |
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
| /* Snippets: Higher-order Functions and Functional Programming Patterns */ | |
| /* Execute function at N interval */ | |
| const setNIntervals = (fn, delay, rounds) => { | |
| if (!rounds) { | |
| return; | |
| } | |
| setTimeout(() => { | |
| fn(); |
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
| /* Simulates EventEmitter base, binds to and extends a given type | |
| * | |
| */ | |
| class EventBinder { | |
| listeners = {}; | |
| addListener(eventName, fn) { | |
| // eval if listener has already been registered | |
| this.listeners[eventName] = this.listeners[eventName] || []; | |
| this.listeners[eventName].push(fn); |
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
| // Code snippets from an article I wrote on working with JavaScript Objects | |
| // canonical link: https://goldmund.sh/entries/work-with-javascript-objects-like-a-pro | |
| // medium: https://medium.com/@exbotanical/work-with-javascript-objects-like-a-pro-876437a6a668 | |
| /* How to Find Props on a Nested Object (without needing to know what the Object looks like) */ | |
| const nestedPerson = { | |
| metadata: { | |
| id: 123456789, |
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
| #!/usr/bin/env node | |
| /** | |
| * @param {Object} config A configurations object for method mappings and options thereof. | |
| * @summary A logger module with a configurable prototype for dynamic output formatting. | |
| * @description This logger module enables the user to instantiate a customized logging utility | |
| * by passing in a configurations object. This configurations object is processed by the | |
| * constructor, wherein values then serve as mappings, the methods and properties of which are dynamically applied. | |
| * Ergo, this module allows the extension and augmentation of the `Console` object to create indeterminate, arbitrary | |
| * methods. |