This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'),http = require('http'),multipart = require( 'multipart' ),fs=require('fs'),mime=require('./mime'),api=require('./api'),querystring=require('querystring'),url=require('url'),hookIO=require('./hookIO'); | |
http.createServer(function (req, resp) { | |
req.body = ''; | |
req.addListener('data',function(chunk){ | |
req.body += chunk | |
}) | |
req.addListener('end', function(){ | |
var httpParams = {}; | |
process.mixin(true, httpParams, url.parse(req.url)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hookIO.createHttpClient = function(options){ | |
sys.puts('i should be an event that does an http request for ' + JSON.stringify(options)); | |
var google = http.createClient(80, options.host); | |
var request = google.request("GET", options.path, {"host": options.host}); | |
request.addListener('response', function (response) { | |
//sys.puts("HTTP REQUEST STATUS CODE: " + response.statusCode); | |
//sys.puts("HEADERS: " + JSON.stringify(response.headers)); | |
response.setBodyEncoding("utf8"); | |
response.addListener("data", function (chunk) { | |
// ignore response for now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application.start = function(){ | |
//load data.json into application state | |
var x = posix.open(application.dataPath,process.O_CREAT|process.O_WRONLY|process.O_EXCL,0444).addCallback(function(fd){ | |
debug.log('new datastore created'); | |
}); | |
var boot = posix.cat( application.dataPath ).addCallback(function (applicationState) { | |
//debug.log(JSON.stringify(applicationState)); | |
/* try to evaluate application state into memory */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs.readFile(path, 'binary', function (error, content) | |
{ | |
if (error) { | |
resp.sendHeader(200,{'Content-Type':'text/html'}); | |
resp.write('404 file not found'); | |
resp.close(); | |
} | |
else { | |
resp.sendHeader(200,{'Content-Type':mime.mime(path)}); | |
resp.write(content, 'binary'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var right; | |
var wrongs; | |
// remember developers, two wrongs never make a right | |
if((2 * wrongs).toString()==(right * 1).toString()){ | |
alert('except in javascript'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.getJSON = function(url, options, callback) { | |
$.ajax({ | |
url: url, | |
global: false, | |
data : options, | |
contentType : "application/json", | |
dataType: "jsonp", | |
success: callback | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tree.build = function(data){ | |
var str='<ul>'; | |
for(var key in data){ | |
if(typeof data[key]=='object' && data[key]!=null){ | |
str+='<li>'+key+Tree.build(data[key])+'</li>'; | |
} | |
else | |
{ | |
str+='<li><strong>'+key+'</strong> : '+data[key]+'</li>'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.someMethod = function (arg1, arg2, callback) { | |
// Do this for safety's sake, people might accidentally send us an extra arg | |
arg1 = arguments[0]; | |
arg2 = arguments[1]; | |
callback = arguments[arguments.length - 1]; | |
callback(null, 'win!'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for( aTest in tests){ | |
//$('#testHTML').html(Tree.build(tests)); | |
var jsonRPCWrapper ={}; | |
jsonRPCWrapper.method = tests[aTest].method; | |
jsonRPCWrapper.params = [tests[aTest].params.data]; | |
jsonRPCWrapper.id = new Date().getTime(); | |
Sexy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sexy = Sexy({ | |
type: "POST" | |
}); | |
for (aTest in tests) { | |
var jsonRPCWrapper = { | |
method: tests[aTest].method, | |
params: [tests[aTest].params.data], | |
id: (new Date()).getTime() | |
}; |