Skip to content

Instantly share code, notes, and snippets.

View Jberivera's full-sized avatar

Juan Bernardo Rivera Arias Jberivera

View GitHub Profile
class DiffClamp {
constructor(min, max) {
this.min = min;
this.max = max;
this.lastValue = 0;
this.value = 0;
}
getValue(value) {
const diff = value - this.lastValue;
function shuffle(array, result = []) {
if (array.length === 0) {
return result;
}
const randomIndex = Math.floor(Math.random() * (array.length - 1));
const item = array[randomIndex];
const tail = [
...array.slice(0, randomIndex),
...array.slice(randomIndex + 1),
function getModulo(value, modulus) {
return (
((value % modulus) + modulus) % modulus
);
}
^(ftp|https?):\/\/([^\s]+)\.([^\s|^\.]+)$
function getPath (path, obj = {}) {
const [head , ...tail] = Array.isArray(path) ? path : path.split(/\./g)
const value = obj[head]
if (tail.length === 0 || value === undefined) {
return value
}
return getPath(tail, obj[head])
}
function hexToRgbA(hex, opacity){
var c;
if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
c= hex.substring(1).split('');
if(c.length== 3){
c= [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c= '0x'+c.join('');
return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+opacity+')';
}
function createLoop (callback, delay, duration, animationEnd) {
let start = null;
let last = null;
let endAnimation = null;
function loop (timestamp) {
if (!start) {
start = timestamp;
last = timestamp;
};
(current + length + direction) % length
(current + direction) % length
function removeExtension (path) {
return path.split(/\.(\w{3}|(\w{4}))$/, 1)[0]
}
function generateHex() {
const min = 1118481; // parseInt('111111', 16)
const max = 16777215; // parseInt('FFFFFF', 16)
const randomColor = Math.floor(Math.random() * (max - min + 1)) + min;
return `#${randomColor.toString(16)}`;
}