Skip to content

Instantly share code, notes, and snippets.

View Marak's full-sized avatar

Marak

View GitHub Profile
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));
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
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 */
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');
var right;
var wrongs;
// remember developers, two wrongs never make a right
if((2 * wrongs).toString()==(right * 1).toString()){
alert('except in javascript');
}
$.getJSON = function(url, options, callback) {
$.ajax({
url: url,
global: false,
data : options,
contentType : "application/json",
dataType: "jsonp",
success: callback
});
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>';
}
@Marak
Marak / api.js
Created March 4, 2010 04:43 — forked from tim-smart/api.js
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!');
};
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
var sexy = Sexy({
type: "POST"
});
for (aTest in tests) {
var jsonRPCWrapper = {
method: tests[aTest].method,
params: [tests[aTest].params.data],
id: (new Date()).getTime()
};