Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tbranyen's full-sized avatar

Tim Branyen tbranyen

View GitHub Profile
@tbranyen
tbranyen / server.js
Last active July 4, 2021 18:44
backbone/node.js pushState enabled server
// Require libraries
var os = require("os");
var fs = require("fs");
var readline = require("readline");
var cluster = require("cluster");
var express = require("express");
var site = express();
// Var up, bro
var i, read;
@tbranyen
tbranyen / canvas.js
Created February 2, 2012 18:07
Lightweight canvas wrapper.
// Basic Usage:
//
// var main = new Canvas({ elem: "canvas" }, function(options) {
// // Instantiate anything specific here...
// // Main draw loop
// this.draw = function() {
//
// };
// });
//
@tbranyen
tbranyen / use.js
Created January 13, 2012 01:21
A RequireJS compatible plugin to provide shimming capabilities declaratively.
(function() {
var buildMap = {};
/* RequireJS Use Plugin v0.2.0
* Copyright 2012, Tim Branyen (@tbranyen)
* use.js may be freely distributed under the MIT license.
*/
define({
version: "0.2.0",
@tbranyen
tbranyen / game-of-life.js
Created July 29, 2020 17:32
For funsies
const grid = buildGrid(20, 50, [
(10 * 50) + 20,
(10 * 50) + 21,
(10 * 50) + 22,
(10 * 50) + 23,
(10 * 50) + 24,
(10 * 50) + 25,
(10 * 50) + 26,
(10 * 50) + 27,
(10 * 50) + 28,
@tbranyen
tbranyen / app.js
Created September 22, 2011 16:51
backbone.js sub routing
/* Pretend app setup stuff is here */
/* Kick off app */
jQuery(function($) {
var Gallery = app.module("gallery");
app.Router = Backbone.Router.extend({
initialize: function() {
this.gallery = new Gallery.Router("gallery/");
@tbranyen
tbranyen / doubletap-improved.js
Created July 5, 2011 21:44
doubletap-improved?
function doubleTouch(element, callback) {
if ((!element && !callback) || (!callback && typeof element !== 'function')) {
return;
} else if (!callback && typeof element === 'function') {
callback = element;
element = document;
}
var taps = 0;
@tbranyen
tbranyen / string.format.js
Created June 27, 2011 18:22
safer string formatting
// Inspired by http://bit.ly/juSAWl
// Augment String.prototype to allow for easier formatting. This implementation
// doesn't completely destroy any existing String.prototype.format functions,
// and will stringify objects/arrays.
String.prototype.format = function(i, safe, arg) {
function format() {
var str = this, len = arguments.length+1;
// For each {0} {1} {n...} replace with the argument in that position. If
@tbranyen
tbranyen / diffhtml.js
Last active April 24, 2019 04:20
diffHTML "Calculator" Experiment
import { innerHTML, html } from 'https://unpkg.com/diffhtml/dist/es';
let a = 1;
let b = 2;
const updateA = ({ target }) => (a = Number(target.value), render());
const updateB = ({ target }) => (b = Number(target.value), render());
function render() {
innerHTML(document.body, html`
@tbranyen
tbranyen / backbone.collectioncache.js
Created June 4, 2012 06:37
Backbone.Collection caching by URL
/*!
* backbone.collectioncache.js v0.0.2
* Copyright 2012, Tim Branyen (@tbranyen)
* backbone.collectioncache.js may be freely distributed under the MIT license.
*/
(function(window) {
"use strict";
// Dependencies
@tbranyen
tbranyen / page.js
Created April 19, 2013 14:35
Creating pages with Backbone and Layout Manager.
// Application.
var app = require("app");
// Page specific Views.
var Views = require("modules/page/views");
module.exports = Backbone.Model.extend({
defaults: {
title: "Unknown Page"
},