Skip to content

Instantly share code, notes, and snippets.

//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
@exbotanical
exbotanical / zipArrays.js
Created February 10, 2020 16:34
zip an object of arrays js
// 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)
@exbotanical
exbotanical / py_regex_notes.py
Created March 2, 2020 22:06
python, [regex, re module] (more notes re py roborant)
# # # 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.
@exbotanical
exbotanical / eve-linux.sh
Created March 9, 2020 04:56
eve linux configs
# eve-linux configurations - not a script, but cmds
# bluetooth
hcitool scan
var=DEVICE
# as root
@exbotanical
exbotanical / custom-logger.js
Last active July 7, 2020 23:57
A logger module with a configurable prototype for dynamic output formatting (including colored).
#!/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.
@exbotanical
exbotanical / walk-nested-obj.js
Last active July 7, 2020 23:56
How to Find Props on a Nested Object (without needing to know what the Object looks like)
// 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,
@exbotanical
exbotanical / custom-event-binder.js
Last active July 7, 2020 23:56
A custom implementation of the EventEmitter class
/* 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);
/* Snippets: Higher-order Functions and Functional Programming Patterns */
/* Execute function at N interval */
const setNIntervals = (fn, delay, rounds) => {
if (!rounds) {
return;
}
setTimeout(() => {
fn();
@exbotanical
exbotanical / quines.js
Created July 9, 2020 20:41
Code Golf with JavaScript
/* 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
@exbotanical
exbotanical / alternated-weight.js
Last active July 18, 2020 05:17
more codegolf
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];
}
/*