Skip to content

Instantly share code, notes, and snippets.

@marcrobledo
marcrobledo / StringEncoder.js
Created April 9, 2026 18:35
String encoder/decoder using AES-CBC encryption
/**
* String encoder/decoder using AES-CBC encryption
* by Marc Robledo
*
* Usage:
* const myKey=await StringEncoder.buildKey('my secret password');
* const encodedString=await StringEncoder.encode('my secret string', myKey);
* const decodedString=await StringEncoder.decode(encodedString, myKey);
* console.log(decodedString);
*
@marcrobledo
marcrobledo / ArrayShuffle.js
Created April 9, 2026 18:17
Array.shuffle() implementation using Fisher-Yates algorithm
/**
* Array.shuffle() JS implementation using Fisher-Yates algorithm
*
* by Marc Robledo
* Released under no license
*
* Usage:
*
* const numbers = [1, 2, 3, 4, 5];
* const shuffledNumbers = numbers.shuffle();
@marcrobledo
marcrobledo / image-resizer.webworker.js
Last active March 19, 2026 10:33
Image Resizer Web Worker (with bilinear filter)
/**
* Web worker adaptation of pure JS image bilinear rescaler from https://stackoverflow.com/a/19144434
*
* by Marc Robledo
* Released under no license
*
* Usage:
*
* const webWorkerImageResizer = new Worker('image-resizer.webworker.js');
* webWorkerImageResizer.onmessage = event => { // listen for events from the worker
@marcrobledo
marcrobledo / stringTransformations.js
Last active May 8, 2025 10:04
JavaScript functions to transform strings to: slug, camelCase, PascalCase, snake_case and kebab-case
/**
* JavaScript functions to transform strings to:
* - slug
* - camelCase
* - PascalCase
* - snake_case
* - kebab-case
*
* Usage: ' *** This is just a test! *** '.slug(); //returns 'this-is-just-a-test'
* 'Do you like jalapeños and Pokémon!?'.slug(true); //returns 'do_you_like_jalapenos_and_pokemon'
@marcrobledo
marcrobledo / numberToStringFormatted.js
Last active February 2, 2025 18:44
JavaScript functions to turn Number objects into formatted number strings
/**
* JavaScript functions to turn Number objects into formatted number strings:
* - zero padded
* - hex bytes
*
* Usage: (1).toStringZeroPadded(); //returns '01';
* (10).toStringZeroPadded(3); //returns '010';
* (0x0f).toStringHexBytes(); //returns '0f';
* (0x0100).toStringHexBytes(); //returns '0100';
* (0x010200).toStringHexBytes(); //returns '00010200';
@marcrobledo
marcrobledo / warnOnLeave.js
Last active February 2, 2025 18:27
JavaScript function that enables or disables warning before closing page
/**
* JavaScript function that enables or disables warning before closing
* page
* Usage: warnOnLeave(true|false);
*
* by Marc Robledo
* Released under no license
*/
const warnOnLeave=(function(){
@marcrobledo
marcrobledo / isNavigatorMobile.js
Created February 2, 2025 17:22
JavaScript function that returns if the browser is running under a mobile device, based on userAgent data
/**
* JavaScript function that returns if the browser is running under a
* mobile device, based on userAgent data
*
* by Marc Robledo
* Released under no license
*/
const isNavigatorMobile=function(){
if(navigator.userAgentData && typeof navigator.userAgentData.mobile!=='undefined')
@marcrobledo
marcrobledo / foobar2000_jscript_panel_now_playing_export.js
Last active April 22, 2025 15:08
foobar2000 now playing track export to file
// ==PREPROCESSOR==
// @name "Now Playing exporter"
// @author "Marc Robledo"
// @version "1.0"
// ==/PREPROCESSOR==
// for use with https://github.com/jscript-panel
/* CONFIGURATION */