Skip to content

Instantly share code, notes, and snippets.

View Raynos's full-sized avatar

Jake Verbaten Raynos

View GitHub Profile
@Raynos
Raynos / xhr.js
Created November 29, 2011 20:44
JSON by XHR
var xhr = new XMLHttpRequest;
xhr.addEventListener("load", function () {
var result = this.responseText;
});
xhr.open("GET", "url");
xhr.overrideMimeType("application/json");
xhr.send(JSON.stringify(data));
@Raynos
Raynos / file.js
Created November 30, 2011 15:27
Recursive fs.watch
fs.readdir(srcPath, handleDirectoryRead.bind(null, srcPath));
function handleDirectoryRead(srcPath, err, files) {
files.forEach(handleFile.bind(null, srcPath));
}
function handleFile(srcPath, file) {
var uri = path.join(srcPath, file);
fs.stat(uri, handleStat.bind(null, uri));
}
@Raynos
Raynos / clone.js
Created November 30, 2011 21:09
simple clone
function clone(o) {
var pds = {};
Object.getOwnPropertyNames(o).forEach(function _eachName(name) {
pds[name] = Object.getOwnPropertyDescriptor(o, name);
});
return Object.create(Object.getPrototypeOf(o), pds);
}
@Raynos
Raynos / real-easy.js
Created December 1, 2011 00:44
pub sub
var pubsub = (function () {
return { pub: pub, sub: sub, evs: {} };
function pub(ev, data) {
pubsub.evs[ev] && pubsub.evs[ev].forEach(function (h) { h(data); });
}
function sub(ev, h) {
(pubsub.evs[ev] || (pubsub.evs[ev] = [])).push(h);
}
@Raynos
Raynos / critique.md
Created December 1, 2011 14:15
jQuery library critique

jQuery

Related: [Why you don't need jQuery as an abstraction][2]

$ itself is a god object. Everything goes on it. The standard plugin / extension architecture that is recommended is to just bolt more methods on $ itself!

Surely this is bad. An example would be how we have both $.load which is overloaded to do completely different things. If they were on two separate sensibly named objects $Container.load and $EventTarget.load. Personally I would deprecate the latter in favour of .on('load'

The animation should be it's own little modular thing, not bolted onto $. Ajax should be it's own little modular thing, not bolted onto $

@Raynos
Raynos / store.js
Created December 1, 2011 18:24
DOM data stores
var uuid = 0,
domShimString = "__domShim__";
var dataManager = {
_stores: {},
getStore: function _getStore(el) {
var id = el[str];
if (id === undefined) {
return this._createStore(el);
}
/**
* Javascript Application Core (Layer 1)
* -----------------------------------------
* The core is the only part from the application which has direct access to the base library.
* Any access to the base library (from a Module) is marshaled down through the Sandbox.
* Furthermore, the Core is responsible for Module lifecycles, communication between modules,
* error handling and extensions.
*
* -----------------------------------------
* Author: Andreas Goebel
DOMCommand(function (document, window) {
// do shit
}).send(dnode);
@Raynos
Raynos / x.js
Created December 3, 2011 15:05
make non enumerable
function makeNonEnumerable(obj /*, props */) {
var names = [].slice.call(arguments, 1);
names.forEach(makeNonEnumerable);
function makeNonEnumerable(name) {
var pd = Object.getOwnPropertyDescriptor(obj, name);
pd.enumerable = false;
Object.defineProperty(obj, name, pd);
}
}
@Raynos
Raynos / cleaned.js
Created December 3, 2011 16:28
Cleaning attempt
/**
* BarFoos Module (Layer 3)
* -----------------------------------------
* Box3D: This module handles the center box with help of CSS3 in 3D
*
* This code runs in strict mode (if supported by the environment).
* -----------------------------------------
* Author: Andreas Goebel
* Date: 2011-11-12
* Changed: 2011-11-12