This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Must easy and elegant way to create classes or complex objects in JavaScript | |
*/ | |
(function( window, document ){ | |
function Class( options ){ | |
if( this instanceof Class ){ | |
return Class.fn.init(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Very simple way to compute the center (centroid) of a triangle. | |
// The only things you have to know are the three vectors forming the triangle. | |
// vector = [x, y, z]; | |
var vectorA = [-1, -3, -2]; | |
var vectorB = [2, 1, 2]; | |
var vectorC = [8, -4, 1]; | |
var centerX = ((vectorA[0] + vectorB[0] + vectorC[0]) / 3); | |
var centerY = ((vectorA[1] + vectorB[1] + vectorC[1]) / 3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Easy way to find distance between two vectors in JavaScript | |
// [x, y, z] | |
var vectorFrom = [10, 10, 1]; | |
var vectorTo = [12, 11, 0]; | |
var distance = Math.sqrt(((vectorFrom[0] - vectorTo[0]) * (vectorFrom[0] - vectorTo[0])) + ((vectorFrom[1] - vectorTo[1]) * (vectorFrom[1] - vectorTo[1])) + ((vectorFrom[2] - vectorTo[2]) * (vectorFrom[2] - vectorTo[2]))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fast and easy way to combine (additive mode) two RGBA colors with JavaScript. | |
// [red, green, blue, alpha] based on these maximul values [255, 255, 255, 1]. | |
var base = [69, 109, 160, 1]; | |
var added = [61, 47, 82, 0.8]; | |
var mix = []; | |
mix[3] = 1 - (1 - added[3]) * (1 - base[3]); // alpha | |
mix[0] = Math.round((added[0] * added[3] / mix[3]) + (base[0] * base[3] * (1 - added[3]) / mix[3])); // red | |
mix[1] = Math.round((added[1] * added[3] / mix[3]) + (base[1] * base[3] * (1 - added[3]) / mix[3])); // green | |
mix[2] = Math.round((added[2] * added[3] / mix[3]) + (base[2] * base[3] * (1 - added[3]) / mix[3])); // blue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic JavaScript RegExps to parse JavaScript (itself ahah!) | |
// and translate it into HTML markup ready for CSS. | |
// Please, give me your feedback on twitter @JordanDelcros. | |
code // string (multiline) of JavaScript code | |
.replace(/&(lt|nbsp|amp)/gim, "&$1") | |
.replace(/(\/\/[^\n]*)/gi, "##comment••$1••comment##") | |
.replace(/(\/\*[\s\S]*?((\*\/)|$))/gi, "##comment••$1••comment##") | |
.replace(/(\"[\s\S]*?(\"|$))/gi, "##string••$1••string##") | |
.replace(/([\<\>\+\-\*\/\%\!]|\=+)/gim, "##math••$1••math##") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parser = function( html ){ | |
html = html | |
.replace(/&(lt|nbsp|amp)/gim, "&$1") | |
.replace(/•/gi, "·") | |
.replace(/#/gi, "#") | |
.replace(/</gim, "<") | |
.replace(/>/gim, ">") | |
.replace(/(<(?!\!)\/?(?:\w+)((?:\s*?[\w-]+(?:\s*=\s*)?(?:\"[^\"]*(?:\")?|\'[^\']*(?:\')?)?)*)?(?:\s*\/?\s*>|[\s\S]*$)?)/gi, function( matchTag ){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open -a Google\ Chrome --args --disable-webgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Default 2 numbers after comma | |
function fixNumber( number, precision = 1e2 ){ | |
return Math.sign(number) * (Math.round((Math.abs(number) + Number.EPSILON) * precision) / precision); | |
} |