Skip to content

Instantly share code, notes, and snippets.

View kriszyp's full-sized avatar
💭
Working on @HarperFast

Kris Zyp kriszyp

💭
Working on @HarperFast
View GitHub Profile
db = new Storage # external implementation
Store = (entity) ->
find: db.find.bind db, entity
get: db.get.bind db, entity
save: db.save.bind db, entity
add: db.insert.bind db, entity
remove: db.remove.bind db, entity
update: db.update.bind db, entity
patch: db.patch.bind db, entity
@kriszyp
kriszyp / define-node.js
Created October 27, 2010 21:08
Add AMD/define() support to NodeJS
var currentModule, defaultCompile = module.constructor.prototype._compile;
module.constructor.prototype._compile = function(content, filename){
currentModule = this;
try{
return defaultCompile.call(this, content, filename);
}
finally {
currentModule = null;
}
};
require.def("uses-foo",["has!node:./node/foo,svg:./svg/foo,./default/foo"],function(foo){
foo.bar();
});
dojo.provide("dojo.socket");
dojo.socket = function(/*dojo.__XhrArgs*/ argsOrUrl){
// summary:
// Provides a simple socket connection using WebSocket or long-polling based
// communication in legacy browsers for comet-style communication. This is based
// on the WebSocket API and returns an object that implements the WebSocket interface:
// http://dev.w3.org/html5/websockets/#websocket
// argsOrUrl:
// This uses the same arguments as the other I/O functions in Dojo, or a
node>when = require("promised-io/promise").when;
[Function]
node>defer = require("promised-io/promise").defer;
[Function]
node>d = defer();
node>when(when(d.promise,function(){},function(){return 5}),function(){print("su
ccess");});
{ then: [Function] }
node>d.reject("error");
var request = require("rhino-http-client").request;
var r = request({url:"http://www.google.com"});
r.then(function(r){
print("status: " + r.status);
r.body.forEach(function(){
print("part")
}).then(function(){
print("done");
})
});
/**
* This is an example Wiki web application written on Pintura
*/
var pageFacets = require("./facet/page"),
pageChangeFacets = require("./facet/page-change"),
admins = require("commonjs-utils/settings").security.admins,
fullModel = require("./model/index"),
Package = require("perstore/model").Package,
copy = require("commonjs-utils/copy").copy,
Register = require("pintura/security").Register;
on the client side:
function monitor(){
dojo.xhr({
method:"POST",
url:"/TestCalls",
headers:{
"Accept":"message/json",
"Content-Type":"message/json"
},
postData: dojo.toJson([{method:"subscribe", subscribe:"hour"}]),
query = and
# Normalized components
nchar = unreserved / pct-encoded
name = *nchar
value = *nchar / typed-value / array
typed-value = *nchar ":" *nchar
array = "(" [ value *( "," value ) ] ")"
call = name "(" [ argument *( "," argument ) ] ")"
argument = call / value
var server = require("http").createServer(function(request, response){
});
var nodes = require("./multi-node").listen({
port: 80,
nodes: 4
}, server);
nodes.addListener("node", function(stream){
stream.write("hello");
});