Skip to content

Instantly share code, notes, and snippets.

View Raynos's full-sized avatar

Jake Verbaten Raynos

View GitHub Profile
function createEvent(type, bubbles, cancelable) {
var ev
bubbles = bubbles || true
cancelable = cancelable || true
if (document.createEvent) {
ev = document.createEvent("Event")
ev.initEvent(type, bubbles, cancelable)
} else if (document.createEventObject) {
ev = document.createEventObject()
} else {
@Raynos
Raynos / partial.js
Created January 24, 2012 19:44
Partial non-enumerable implementation
/* partial non-enumerable property implementation
Adds a flag to a weakmap saying on obj foo property bar is not enumerable.
Then checks that flag in Object.keys emulation.
*/
// pd.Name :- https://github.com/Raynos/pd#pd.Name
var enumerables = pd.Name();
/**
* 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
@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);
}
@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 / 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);
}
var whitelistMap = {
"get": ["not_found"],
"insert": ["conflict"],
"delete": []
}
function makeWhitelistCallback(method, thing, cb) {
return error.whitelist(function _errors(err) {
if (err.syscall === "getaddrinfo") {
UserModel[method](thing, cb);
var adoptNode = (function () {
function setOwnerDocument(node, doc) {
// implement this. Step 1 of DOM4 adopt a node algorithm
node.triggerBaseUrlChange();
node._ownerDocument = doc;
node._attributes._ownerDocument = doc;
[].forEach.call(node.childNodes, function (node) {
setOwnerDocument(node, doc);
});
}
@Raynos
Raynos / pd.js
Created October 11, 2011 08:46
Node vanilla REST server
/*
A utility function to turn an object into a property descriptor hash
@param Object obj - the Object of keys & values to turn into an object of
keys and PropertyDescriptor(value)
*/
var pd = function _pd (obj) {
var o = {};
Object.keys(obj).forEach(function (key) {
var pd = Object.getOwnPropertyDescriptor(obj, key);
var pd = function _pd(props) {
var obj = {};
Object.keys(props).forEach(function (key) {
obj[key] = Object.getOwnPropertyDescriptor(props, key);
});
return obj;
};
pd.merge = function _merge() {
var o = {}