Skip to content

Instantly share code, notes, and snippets.

@illtellyoulater
illtellyoulater / regexp-single-multiline-comments.md
Last active October 20, 2023 04:49
REGEXP FOR SINGLE & MULTI-LINE COMMENTS (JS / C / C# / JAVA / etc.)

REGEXP FOR SINGLE & MULTI-LINE COMMENTS ( JS / C / C# / JAVA / etc... )

Tested in VS Codium and at https://regex101.com

\/\*[\s\S\n]*?\*\/|\/\/.*$

This will correctly match:

// single line comments

@illtellyoulater
illtellyoulater / range-scaling.js
Last active January 26, 2023 16:14 — forked from fpillet/scale.js
Javascript value scaling between two ranges, the correct way
function convertRange( value, r1, r2 ) {
return ( value - r1[ 0 ] ) * ( r2[ 1 ] - r2[ 0 ] ) / ( r1[ 1 ] - r1[ 0 ] ) + r2[ 0 ];
}
// example
convertRange(26, [0, 100], [-2, 2]);
// = -0.96
// another example
convertRange(26, [0, 100.1], [-2, 2]);