Skip to content

Instantly share code, notes, and snippets.

View Raynos's full-sized avatar

Jake Verbaten Raynos

View GitHub Profile
var UserModel = pd.make(Model,{
get: function _get(id, cb) {
// nano is a database client
this.nano.get(id,
// whitelist runs every error through the white list,
// if it fails (false) throw it
// if it succeeds (true) pass it to cb
error.whitelist(function _errors(err) {
if (err.syscall === 'getaddrinfo') {
UserModel.get(id, cb);
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);
});
}
<tbody>
{% for child in user.children if user.isFemale %}
<tr>
<td>{{ child }}</td>
</tr>
{% endfor %}
</tbody>
var person = Object.make(null, {
get name() {
return this.first_name + " " + this.last_name;
},
set name() {
...
},
greet: function (person) {
return this.name + ': Why, hello there, ' + person + '.'
}
@Raynos
Raynos / x.md
Created November 19, 2011 18:17

Common concerns about node

It's not even version 1 yet

So what? Version numbers matter these days? All software I realise never get's upto version "1".

Node.js is stable and it's a shining example for asynchronous IO using javascript.

Socket.io is stable and the best cross platform websocket abstraction I've seen. You want to use websockets in production today? Use socket.io

burrito(file, function (node) {
if (node.name === "call" &&
node.start.value === "load"
) {
// magic numbers everywhere!
var module = node.value[1][0][1];
preLoad(module);
}
});
@Raynos
Raynos / pd.js
Created November 20, 2011 15:01
var events = require('events');
var util = require('util');
var pd = require("pd");
pd.extendNatives(true);
var Test = {
Hello: pd.make(events.EventEmitter.prototype, {
World: function () { console.log("hello world");
})
var count = 3;
function next() {
count--;
if (count === 0) {
// continue
}
}
doAjax("do", next);
@Raynos
Raynos / x.js
Created November 21, 2011 16:50
<!DOCTYPE html>
<html>
<head>
<title>DOM-shim unit tests</title>
<link rel="stylesheet" href="resources/nodeunit.css" type="text/css" />
<script src="resources/es5-shim.js"></script>
<script src="resources/nodeunit.js"></script>
<script src="../code/my/file"></script>
</head>
<body>