Skip to content

Instantly share code, notes, and snippets.

View louisstow's full-sized avatar

Louis Stowasser louisstow

View GitHub Profile
@louisstow
louisstow / RTree.js
Created November 14, 2010 05:41
Javascript RTree
var MAX_SUB_DIVISIONS = 6,
MAX_OBJECTS = 6,
results = [], //results of multiple quads
OBJECT = "object",
NULL = null,
mc = Math.ceil;
function RTree() {
this.root = new Box(0, 0, 1600, 800, null, 0);
}
@louisstow
louisstow / SAT.js
Created February 2, 2011 04:46
SAT collision detection in JS
SAT: function(poly1, poly2) {
var points1 = poly1.points,
points2 = poly2.points,
i = 0, l = points1.length,
j, k = points2.length,
normal = {x: 0, y: 0},
length,
min1, min2,
max1, max2,
interval,
@louisstow
louisstow / SAT.js
Created February 15, 2011 07:04
SAT Collision
SAT: function(poly1, poly2) {
var points1 = poly1.points,
points2 = poly2.points,
i = 0, l = points1.length,
j, k = points2.length,
normal = {x: 0, y: 0},
length,
min1, min2,
max1, max2,
interval,
(function() {
var privateVar = 5;
Crafty.c('NewComponent', {
publicPropertyA: null,
publicPropertyB: 33,
init: function(){
this.test = function() {
var embeded = true;
};
#Performance Testing Framework
Performance is a very important factor for JavaScript games. It becomes
a cruciual factor when you bring mobile devices into the mix.
Luckily we have some great tools for testing different methods of coding
such as JSPerf.com. This lets developers see which browsers perform best
doing what.
On the same vein, JSGameBench stress tested rendering methods for browsers
@louisstow
louisstow / gist:2348277
Created April 10, 2012 04:15
Include photo caption
(function(blog, limit) {
limit = +limit || 10;
var scriptTags = document.getElementsByTagName('script');
var scriptNode = scriptTags[scriptTags.length - 1];
var recent = document.createElement("div");
scriptNode.parentNode.appendChild(recent);
recent.setAttribute("class", "widget");
recent.setAttribute("id", "TumblrRecentPosts");
@louisstow
louisstow / require.js
Created October 26, 2012 19:27
Synchronous require for the browser
/**
* Shim the require function used in node.js
*/
(function() {
if (window.require !== undefined)
throw 'RequireException: \'require\' already defined in global scope';
@louisstow
louisstow / toc.js
Last active December 14, 2015 07:39
This function will generate an HTML string of a Table of Contents based on a parent node you provide and a start level of header tags.
/**
* @author Louis Stowasser <louisstow@gmail.com>
* License: MIT
*/
function generateTOC (rootNode, startLevel) {
var lastLevel = 0;
startLevel = startLevel || 2; //which H# tag to start indexing.
var html = "<ul>";
@louisstow
louisstow / gist:5427877
Created April 20, 2013 23:50
Convert to HTML entities
var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};
function escapeHtml (string) {