Skip to content

Instantly share code, notes, and snippets.

@ericcornelissen
ericcornelissen / omit-very.md
Created Oct 23, 2020
A mapping file for wordrow to replace "very X" by a single word
View omit-very.md

Omit "very"

This file defines mappings to improve English writing using [wordrow] by changing "very X" by a single word that means the same.

Very X Improvement
very afraid terrified
very angry furious
very bad atrocious
@ericcornelissen
ericcornelissen / british-american.md
Created Oct 23, 2020
A mapping file for wordrow between British and American English
View british-american.md

British to American

This file defines a mapping from British to American English for [wordrow]. You can use it to convert British to American English:

$ wordrow --map-file british-american.md input.txt

or to convert American to British English:

$ wordrow --invert --map-file british-american.md input.txt

@ericcornelissen
ericcornelissen / eql.js
Last active Jan 28, 2019
Small function to check equality across any number of variables.
View eql.js
/**
* Check equality across any number of variables.
*
* @example <caption>Simple usage</caption>
* var a = 1, b = 1, c = 1, d = 2;
* eql(a, b, c); // returns True
* eql(a, b, c, d); // returns False
*
* @example <caption>Wierd use cases</caption>
* eql("foobar"); // returns True
@ericcornelissen
ericcornelissen / partial-left.js
Last active Jan 28, 2019
Simple and small wrapper to allow for partial function invocation from left to right
View partial-left.js
/**
* Make a function partially invokable from left to right.
*
* @example
* let addThreeNumbers = partialLeft((a, b, c) => a + b + c);
* addThreeNumbers(1)(2)(3); // => 6
* addThreeNumbers(1, 2)(3); // => 6
* addThreeNumbers(1)(2, 3); // => 6
* addThreeNumbers(1, 2, 3); // => 6
*
@ericcornelissen
ericcornelissen / partial.js
Last active Jan 28, 2019
Simple and small wrapper to allow for partial function invocation
View partial.js
/**
* Make a function partially invokable, meaning that its
* arguments can be provided in any order.
*
* @example
* let addThreeNumbers = partial((a, b, c) => a + b + c);
* let plus4 = addThreeNumbers(1, _, 3);
* plus4(4); // => 8
*
* @param {Function} fn The function to apply partial invokability to.
@ericcornelissen
ericcornelissen / align-text.js
Last active Jan 28, 2019
Automatically align text (using CSS letter-spacing) with JavaScript (example: https://codepen.io/ericornelissen/full/wjNzwR)
View align-text.js
/**
* Automatically align the text of one element with
* the text of another element.
*
* @param {Node} node The element to align.
* @param {Node} target The element to align with.
* @license The-Unlicense
*/
function alignTextWith(node, target) {
const targetWidth = target.offsetWidth;
@ericcornelissen
ericcornelissen / curry.js
Last active Jan 28, 2019
Simple and small wrapper to curry functions of any arity
View curry.js
/**
* Curry a function of any length. Note that a curried
* function accepts only one argument at the time.
*
* @example <caption>Simple usage</caption>
* let addTwoNumbers = curry((x, y) => x + y);
* addTwoNumbers(1); // => Function[y => 1 + y]
* addTwoNumbers(1)(3); // => 4
*
* @example <caption>Incorrect usage</caption>
@ericcornelissen
ericcornelissen / array-string-sort.js
Last active Jan 28, 2019
JavaScript Array prototype method to sort strings containing numbers correctly
View array-string-sort.js
/**
* Sort an array of string alpha-numerically.
*
* @example
* // returns ['1', '2', '10', '20'] rather then ['1', '10', '2', '20']
* ['1', '20', '10', '2'].strSort();
*
* @return {array} The alpha-numerically sorted array.
* @license The-Unlicense
*/
@ericcornelissen
ericcornelissen / function-pipeline-creator.js
Last active May 15, 2019
Functional JavaScript: simple function pipeline creators
View function-pipeline-creator.js
let pipe = function() {
let functions = arguments,
intermediate = undefined;
return function() {
intermediate = functions[0].apply(this, arguments);
for(let i = 1; i < functions.length; i++) {
intermediate = functions[i](intermediate);
}