Skip to content

Instantly share code, notes, and snippets.

View gregtatum's full-sized avatar

Greg Tatum gregtatum

View GitHub Profile
@gregtatum
gregtatum / consoleMatrix.js
Created July 21, 2014 13:56
console.table for a three.js matrix4
//Utils.consoleMatrix( threeJsMatrix, 3 )
//Utils.consoleMatrix( threeJsMatrix )
var Utils = {
consoleMatrix : function( matrix, decimalPlaces ) {
var i, j, el, results;
@gregtatum
gregtatum / consoleMatrixElements.js
Last active August 29, 2015 14:09
consoleMatrixElements() - Output multiple console.tables() for an array buffer of matrix elements
var consoleMatrixElements = function( els, decimalPlaces ) {
var i, j, el, results;
results = [];
j = 0;
for( i=0; i < els.length; i++ ) {
if( j === 0 ) {
@gregtatum
gregtatum / newOperator.js
Last active August 29, 2015 14:12
newOperator function
/*
* This is an illustration of the new Object() functionality for JavaScript written
* as a function.
*/
function extend(a, b) {
var c = {}, attr;
for (attr in a) {
if (Object.prototype.hasOwnProperty.call(a, attr)) {
c[attr] = a[attr];
@gregtatum
gregtatum / 1-new-constructor.js
Last active August 29, 2015 14:13
Storing State in Functions
/*
Typical prototypical pattern. Store all state, configuration, and functions on the "this" object.
*/
var Car = function( engineType ) {
this.engine = engineType || "v4";
this.timesRevved = 0;
@gregtatum
gregtatum / root.js
Created January 14, 2015 20:21
Root calculator using Newton's Method
function pow( number, degree ) {
var memo = 1;
while( degree-- ) {
memo *= number;
}
return memo;
}
@gregtatum
gregtatum / functions-state.js
Created January 20, 2015 14:18
Storing state in functions
/*
* Different ways to save state or configure a function
*
*/
//-------------------------------------------------
// Typical prototypical inheritance
var Talker = function( phrase ) {
this.phrase = phrase;
@gregtatum
gregtatum / 1-wrap-value.js
Created January 21, 2015 18:27
Wrapped Value
function extendBind(target, object, state) {
var keys = Object.keys(object);
var i = keys.length;
while (i--) {
target[keys[i]] = object[keys[i]].bind(state);
}
return target;
}
function identityOrSet( v ) {
@gregtatum
gregtatum / three.console.js
Created January 28, 2015 05:08
THREE.Console
function roundTo( value, decimalPlaces ) {
if( typeof decimalPlaces === "number" ) {
return Math.round( Math.pow(10, decimalPlaces) * value ) / Math.pow(10, decimalPlaces);
} else {
return value;
@gregtatum
gregtatum / jshint-warnings.js
Created January 28, 2015 18:12
Observations on jshint's warnings for semicolons
function helloWorld1() {
}; // jshint warning
var helloWorld2 = function() {
}; // no jshint warning
function helloWorld3() {
var ringFunction = function( geometry, radius, segments ) {
var rStep = 2 * Math.PI / segments;
return {
create : function( height, skinIndex, skinWeight ) {
for( var i=0; i < segments; i++ ) {