Skip to content

Instantly share code, notes, and snippets.

@solendil
solendil / logger.js
Last active Dec 13, 2020
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
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)