Skip to content

Instantly share code, notes, and snippets.

Matthieu Dumas solendil

Block or report user

Report or block solendil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View interweave-stretch.js
// interweave two arrays with stretching; i.e. if one is shorter than the other, its elements are
// distributed to cover most of the final array
const interweave = (A, B) => {
// create [0..1] index of each item
const map = array => array.map((val, i) => ({
array,
val,
index: array.length === 1 ? 0.5 : i / (array.length - 1)
}));
@solendil
solendil / csschanger.js
Last active Oct 30, 2016
A little utility to change the rules of a stylesheet on the fly.
View csschanger.js
/*
* Copyright 2016, Matthieu Dumas
* This work is licensed under the Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/
*/
/* Identify rules in a given stylesheet and change them on the fly.
* var ss = StyleChanger("my_custom_identifier"); // stylesheet must have a dummy identifying rule like .my_custom_identifier{color:black;}
* ss.change("darkolivegreen", "blue"); // change all values with a given original value
* ss.change("darkolivegreen", "green"); // ...can be applied many times (original values are saved)
@solendil
solendil / logger.js
Last active Nov 20, 2019
A simple Javascript logger with modules and levels that preserves line numbers
View logger.js
/*
* Copyright 2016, Matthieu Dumas
* This work is licensed under the Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/
*/
/* Usage :
* var log = Logger.get("myModule") // .level(Logger.ALL) implicit
* log.info("always a string as first argument", then, other, stuff)
* log.level(Logger.WARN) // or ALL, DEBUG, INFO, WARN, ERROR, OFF
You can’t perform that action at this time.