This file contains 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
//convert string to url slug without affecting global variable | |
function urlSlug(title) { | |
return title.toLowerCase().trim().split(/\s+/).join("-") | |
} | |
//TO-DO: port this function into small application that generates url slugs |
This file contains 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
// zip object of arrays: { [],[], ... } -> [ arr1[0] + arr2[0] ], [ arr1[1], arr2[1], ... ] | |
const zip = (arrays) => { | |
return arrays[0].map(function(_,i){ | |
return arrays.map(function(array){return array[i]}) | |
}) | |
} | |
// e.g. | |
// stateArray = Object.values(this.context.state).map(i => stateArray.concat(i)) | |
// stateArray = this.zip(stateArray) |
This file contains 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
# # # REGEX # # # | |
# The ? matches zero or one of the preceding group. | |
# The * matches zero or more of the preceding group. | |
# The + matches one or more of the preceding group. | |
# The {n} matches exactly n of the preceding group. | |
# The {n,} matches n or more of the preceding group. | |
# The {,m} matches 0 to m of the preceding group. | |
# The {n,m} matches at least n and at most m of the preceding group. | |
# {n,m}? or *? or +? performs a non-greedy match of the preceding group. |
This file contains 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
# eve-linux configurations - not a script, but cmds | |
# bluetooth | |
hcitool scan | |
var=DEVICE | |
# as root |
This file contains 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. |
This file contains 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 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 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 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 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]; | |
} | |
/* |
OlderNewer