Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ericcornelissen
ericcornelissen / lib.rs
Last active December 18, 2023 23:15
A Rust implementation of an algorithm that converts a linearly stored m-by-m matrix A into a linear store of the q-by-q submatrices of A.
// SPDX-License-Identifier: MIT-0
/// Converts a linearly stored m-by-m matrix A into a linear store of the q-by-q
/// submatrices of A. For example, given the 4-by-4 matrix:
///
/// ```no-test
/// in = [ a b c d
/// e f g h
/// h i j k
/// l m n o ]
@ericcornelissen
ericcornelissen / maybe-run.cjs
Last active October 21, 2023 09:47
A JavaScript helper script to run a tool if it is present on the PATH and output a warning otherwise (CJS and ESM)
/**
* # Maybe Run JS
*
* Run a tool if it is present on the PATH, otherwise output a warning.
*
* Retrieved from (and updates available at):
* https://gist.github.com/ericcornelissen/6253b63db8c6f6ec6a58cb4d36c8e989
*
* ## Installation
*
@ericcornelissen
ericcornelissen / omit-very.md
Created October 23, 2020 19:06
A mapping file for wordrow to replace "very X" by a single word

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 October 23, 2020 18:35
A mapping file for wordrow between British and American English

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 / function-pipeline-creator.js
Last active May 15, 2019 23:33
Functional JavaScript: simple function pipeline creators
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);
}
@ericcornelissen
ericcornelissen / partial-left.js
Last active January 28, 2019 20:39
Simple and small wrapper to allow for partial function invocation from left to right
/**
* 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 January 28, 2019 20:36
Simple and small wrapper to allow for partial function invocation
/**
* 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 January 28, 2019 20:25
Automatically align text (using CSS letter-spacing) with JavaScript (example: https://codepen.io/ericornelissen/full/wjNzwR)
/**
* 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 January 28, 2019 20:16
Simple and small wrapper to curry functions of any arity
/**
* 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 / eql.js
Last active January 28, 2019 20:09
Small function to check equality across any number of variables.
/**
* 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