Skip to content

Instantly share code, notes, and snippets.

View vanrez-nez's full-sized avatar

Ivan Juarez vanrez-nez

View GitHub Profile
@vanrez-nez
vanrez-nez / idGenerator.js
Last active April 28, 2016 23:23
Generate string ID's of a fixed length
function generateID() {
return ("000000" + (Math.random()*Math.pow(36,6) << 0).toString(36)).slice(-6));
}
function generateIDFromStr() {
var seed = str.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
return ( "000000" + ( seed << 0 ).toString( 36 ) ).slice( -6 );
}
@vanrez-nez
vanrez-nez / clampNumber.js
Last active August 29, 2015 14:15
Clamp number
Number.prototype.clamp = function(min, max) {
return Math.min(Math.max(this, min), max);
};
@vanrez-nez
vanrez-nez / lerp.js
Last active August 29, 2015 14:15
linearly interpolate between two values
//returns the interpolated value from a and b at the given weight (from 0 to 1)
var lerp = function(a, b, w) {
return (1 - w) * a + w * b;
}