Skip to content

Instantly share code, notes, and snippets.

View zbabtkis's full-sized avatar

Zachary Babtkis zbabtkis

View GitHub Profile
@zbabtkis
zbabtkis / easyIndex.js
Last active August 29, 2015 13:56
IndexedDB Made Easy
;(function(exports) {
var IDB = this.indexedDB || this.mozIndexedDB || this.webkitIndexedDB || this.msIndexedDB;
function Database(options) {
if (!options) throw new Database.DatabaseConstructorError;
this.version = options.version;
this.name = options.database;
this.initialize = options.initialize;
}
@zbabtkis
zbabtkis / DataBind.js
Created January 4, 2014 00:58
Tiny JavaScript data-binder using Object.observe.
var DataBind = function(el, model) {
this.el = el;
this.model = model;
// Bind event handlers to this.
this._updateModel = this._updateModel.bind(this);
this._updateEl = this._updateEl.bind(this);
Object.observe(model, this._updateEl);
this.el.addEventListener('keyup', this._updateModel, false);
@zbabtkis
zbabtkis / CDB.js
Created December 17, 2013 16:47
Composition based database tool.
var DB = {};
DB.collections = {};
var Collection = function(Constructor, IndexInterface) {
var d = []
, i = new IndexInterface;
return {
@zbabtkis
zbabtkis / ObjectObserver.js
Last active December 31, 2015 07:29
An Object.observe shim (use Object.observe = new ObjectObserver;)
ObjectObserver = function() {
var objects = []
, cache = []
, callbacks = [];
var compare = function(obj, old, change) {
var newObj = {};
for(var i in obj) {
if(obj.hasOwnProperty(i)) {
@zbabtkis
zbabtkis / LinkedList.js
Last active December 31, 2015 02:19
Arrayish Linked List in JavaScript
var LinkedList = function () {
"use strict";
var _this = this
, first
, last;
/**
* These hold data and link to the next node.
*
@zbabtkis
zbabtkis / StyleCopier.js
Last active December 30, 2015 07:39
Utility function to copy rules from all stylesheets to another document
/**
* Utility function to copy rules from all stylesheets to another document
*
* @author Zachary Babtkis <zackbabtkis@gmail.com>
* @date December 4th 2013
* @License WTFPL
*/
/**
* copy styles
@zbabtkis
zbabtkis / SimpleNodeRouter.js
Last active December 23, 2015 09:19
Super simple router for node js applications. Can handle file requests as well as clean url paths. Instantiate the Router object by passing the following in as a single object argument. ``` { basePath: '../public/', routes: { '/': function(req, res) { req.url = 'index.html'; this.route(req, res); } } ``` You can define more routes later using th…
var fs = require('fs')
, Router;
/**
* Router Constructor
*
* Sets default router values and provides file serving functionality.
*
* @param {Object} options Used to set basePath and default GET routes for Router.
*/
@zbabtkis
zbabtkis / Backbone LazyModel
Created August 29, 2013 23:55
Lazily load associated models and collections from a model easily.
(function(Factory) {
if(typeof define !== 'undefined') {
define(['backbone', 'underscore'], Factory);
} else if(typeof Backbone !== 'undefined'
&& typeof _ !== 'undefined'
&& typeof jQuery !== 'undefined') {
@zbabtkis
zbabtkis / gist:6009675
Created July 16, 2013 15:17
Your extremely controlling mother in code.
var Bani = (function() {
var types = {
'View': {
cool: 'hi',
age: new Date()
}
};
function extend(name, type, obj) {
var extension = function() {};
@zbabtkis
zbabtkis / gist:5639191
Last active December 17, 2015 16:29
Simple module function.
function module(require, func) {
for(var i = 0; i < require.length; i++) {
require[i] = window[require[i]];
}
exports[func].apply(this, require);
}