Skip to content

Instantly share code, notes, and snippets.

View mr21's full-sized avatar
💭
"What I produce is 99.1% pure" - Walter White

Thomas Tortorini mr21

💭
"What I produce is 99.1% pure" - Walter White
View GitHub Profile
function numberBase( n ) {
const base = "abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWYXZ";
const len = BigInt( base.length );
let N = BigInt( n );
let s = "";
do {
s = base[ N % len ] + s;
N = N / len | 0n;
} while ( N > 0n );
@mr21
mr21 / lg.js
Created October 13, 2021 19:16
Shortcut for console.log function
function lg( a ) { return console.log.apply( console, arguments ), a; }
@mr21
mr21 / musical-scales.md
Last active December 4, 2023 12:55
Musical scales (major/minor)
11.22.63
12 monkeys
13 reasons why
2001 a space odyssey
24
3%
300
a beautiful mind
a clockwork orange
adventure time
var vid = document.querySelector( "video" );
var audioCtx = new AudioContext();
var source = audioCtx.createMediaElementSource( vid );
var compressor = audioCtx.createDynamicsCompressor();
var now = audioCtx.currentTime;
compressor.threshold.setValueAtTime( -50, now );
compressor.knee.setValueAtTime( 40, now );
compressor.ratio.setValueAtTime( 32, now );
compressor.attack.setValueAtTime( 0, now );
"use strict";
class DragNDrop {
constructor( el, opt = {} ) {
this._clickedElem =
this._draggedElem =
this._dragoverBCR =
this._dragoverElem = null;
this._handleSelector = opt.handleSelector || "*";
el.addEventListener( "mousedown", this._onmousedown.bind( this ) );
const Color = {
split( col ) {
switch ( col[ 0 ] ) {
case "r": return ( col[ 3 ] === "a"
? Color._rgbaExtract
: Color._rgbExtract )( col );
case "#": return ( col.length < 6
? Color._hex3Extract
: Color._hex6Extract )( col );
}
// create the new TodoMVC instance:
// ................................................................
const todomvc2 = new TodoMVC();
document.body.append( todomvc2.rootElement );
// move the first todo from the first todomvc to the second one
// ................................................................
const firstTodoId = Object.keys( todomvc.data )[ 0 ],
firstTodo = todomvc.data[ firstTodoId ];
"use strict";
class ElementMap {
constructor( data ) {
this._map = new Map();
this._keyToElement = new Map();
this.size = data ? data.length : 0;
if ( data ) {
data.forEach( d => this._map.set( d[ 0 ], d[ 1 ] ) );
}
@mr21
mr21 / build-prod.sh
Last active September 5, 2018 09:01
This shell script prints all the CSS/JS in the same index.html file
#!/bin/sh
# usage: ./build-prod.sh < index.html > index-prod.html
cssURLs=()
jsURLs=()
cssReg="<link.*['\"](.*\.css)['\"].*>"
jsReg="<script.*['\"](.*\.js)['\"].*></script>"
while read line