Skip to content

Instantly share code, notes, and snippets.

Avatar

Iván Juárez Núñez vanrez-nez

View GitHub Profile
@vanrez-nez
vanrez-nez / idGenerator.js
Last active Apr 28, 2016
Generate string ID's of a fixed length
View idGenerator.js
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 );
}
View clampNumber.js
Number.prototype.clamp = function(min, max) {
return Math.min(Math.max(this, min), max);
};
@vanrez-nez
vanrez-nez / lerp.js
Last active Aug 29, 2015
linearly interpolate between two values
View lerp.js
//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;
}