Skip to content

Instantly share code, notes, and snippets.

View louisstow's full-sized avatar

Louis Stowasser louisstow

View GitHub Profile
<h1 class="election-section">Electorate Results</h1>
<p class="count"><span class="percentcounted">79.5</span>% Counted. Updated <span class="updatedtime">9 Oct 2015, 11:14pm</span></p>
<div class="afterprefs placeholder">
<div class="election-well">
<h2>Count After Preferences</h2>
</div>
<div class="module afterprefs electable">
<table class="manual eg-table results-table">
<thead>
@louisstow
louisstow / external.js
Last active December 19, 2015 04:29
Force external links to open in a new browser window on Firefox OS
if (navigator.mozApps && window.locationbar.visible === false) {
var externalLinks = document.querySelectorAll("a[href^='http']:not([href*='"+location.host+"'])");
for (var i = 0; i < externalLinks.length; ++i) {
externalLinks[i].setAttribute("target", "_blank");
}
}
@louisstow
louisstow / layers.html
Created May 20, 2013 06:06
Example of a game with 3 canvas layers.
<div id="stage">
<canvas id="ui-layer" width="480" height="320"></canvas>
<canvas id="game-layer" width="480" height="320"></canvas>
<canvas id="background-layer" width="480" height="320"></canvas>
</div>
<style>
#stage {
width: 480px;
height: 320px;
@louisstow
louisstow / storage.js
Last active January 2, 2018 20:54
A simple storage object in JavaScript using localStorage.
var Storage = {
_cache: {},
get: function (key) {
if (!this._cache[key]) {
this._cache[key] = localStorage[key];
}
return this._cache[key];
},
@louisstow
louisstow / pool.js
Last active September 14, 2021 14:46
Generic object pool in JavaScript
var objectPool = [];
var marker = 0;
var poolSize = 0;
//any old JavaScript object
function commonObject () { }
commonObject.create = function () {
if (marker >= poolSize) {
commonObject.expandPool(poolSize * 2);
@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) {
@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 / 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 / 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");
#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