Skip to content

Instantly share code, notes, and snippets.

@digitalicarus
digitalicarus / blowpop.js
Created February 6, 2014 22:26
center and expand canvas
var D = document
, body = D.body
, canvas = D.body.appendChild(D.createElement('canvas'))
, ctx = canvas.getContext('2d')
, width = 480
, height = 272
;
function vendorStyle (ele, prop, val) {
var caps = prop.charAt(0).toUpperCase() + prop.slice(1)
(function () {
var w = window
, d = document
, b = d.body
, h = d.getElementsByTagName('head')[0]
, s = d.getElementsByTagName('script')
, c = {} // cache
, m // main
, i // iter
, x = /\.js$/
//TODO: add object checks
searchTree function (node, getChildren, test) {
function find (node, parent) {
var kids = getChildren(node), i, ret = null;
if (test(node)) { return { parent: parent, match: node }; }
if (kids.length < 1) { return null; }
for (i=0; i<kids.length; i++) {
ret = find(kids[i], node);
if (ret) { return ret; }
@digitalicarus
digitalicarus / ply.js
Last active August 29, 2015 14:00
ply "parser"
var ply = function (raw) {
this.raw = raw;
this.parse();
};
ply.prototype.regex = {
newline: /\n/,
space: /\s+/,
leadspace: /^\s+/,
trailspace: /\s+$/,
@digitalicarus
digitalicarus / cube.obj
Last active August 29, 2015 14:02
files
# cube.obj
#
g cube
v 0.0 0.0 0.0
v 0.0 0.0 1.0
v 0.0 1.0 0.0
v 0.0 1.0 1.0
v 1.0 0.0 0.0
Object.prototype.hasPwnProperty = function (prop) { return (prop in this && !this.hasOwnProperty(prop)); };
@digitalicarus
digitalicarus / ex.js
Last active August 29, 2015 14:05
Reactive Expressions
var EX = function (expr) {
var result
, operands = {}
, operVals = Array.prototype.slice.call(arguments, 1)
, operSetFuncs = {}
;
function genResult () {
result = expr.apply(null, Object.keys(operands).map(function(v) {
return operands[v];
@digitalicarus
digitalicarus / ChronoTron.js
Created September 28, 2014 17:04
Another Game Loop
function ChronoTron(conf) {
function gots (name, type) {
return (
(type === 'Array') ?
conf[name] instanceof Array :
conf[name] && typeof conf[name] === type
);
}
switch (true) {
case typeof conf !== 'object':
@digitalicarus
digitalicarus / repeatAcc.js
Created November 8, 2014 18:54
repeat and accumulate
function repeatAcc(n,f) {
var accum = []; for (; n>0; n--) { accum.unshift(f(n)); }
return accum;
}
@digitalicarus
digitalicarus / tinyFunction.js
Last active August 29, 2015 14:11
tiny functions
function between (n,l,h) { return n >= l && n <= h; }
function timesDo (n, f) { for (; n>0; n--) { f(n); } }
function repeatAcc(n,f) { var accum = []; for (; n>0; n--) { accum.unshift(f(n)); } return accum; }