Skip to content

Instantly share code, notes, and snippets.

// doc, name, attrs, content, callback
v8::Handle<v8::Value>
XmlElement::New(const v8::Arguments& args) {
v8::HandleScope scope;
// was created by BUILD_NODE
if (args.Length() == 0 || args[0]->StrictEquals(v8::Null()))
return scope.Close(args.This());
XmlDocument *document = LibXmlObj::Unwrap<XmlDocument>(args[0]->ToObject());
var sys = require('sys');
var TwitterStream = require('evented-twitter').TwitterStream;
var t = new TwitterStream('polotek', '');
var params = {};
// statuses/sample from streaming api
var stream = t.sample('json', params);
/* How to use evented-twitter
* This example depends on http://github.com/creationix/node-router
*/
process.addListener('uncaughtExeption', function(err) {
sys.debug('UncaughtException: ' + err);
});
var sys = require('sys');
// res.write is defined by the app framework to take callbacks; it stores the
// callbacks in a queue that ensures FIFO order, and when req.end is called it
// waits for all the write callbacks to finish before ending
var hello = function(req, res) {
res.writeHead(200, {});
res.write(function(){ this('Hello World'); };
res.end();
}
exports.pump = function (readStream, writeStream, processChunk, callback) {
if(!callback) {
callback = processChunk;
processChunk = undefined;
}
readStream.addListener("data", function (chunk) {
var newChunk = processChunk ? processChunk(chunk) : chunk;
if (newChunk != null && writeStream.write(newChunk) === false) {
var l = function () {
writeStream.removeListener("drain", l);
var PumpLink = exports.PumpLink = function (readStream, writeStream, cb) {
var self = this;
this._rs = readStream
, this._ws = writeStream
, this._endcb;
this._datacb = function (chunk) {
if (writeStream.write(chunk) === false) {
var l = function () {
writeStream.removeListener("drain", l);
var server = require('./lib/node-router').getServer();
server.get("/json", function (req, res, match) {
res.write('querying... ', 'utf8');
db.query(/* huge long query */, function(results) {
for(var k in results) res.write(results[k].toString(), 'utf8');
res.end();
});
});
var sys = require('sys');
var Client = require('http').Client;
function MyClient() {
Client.call(this);
this.testProp = 'testprop';
};
sys.inherits(MyClient, Client);
MyClient.prototype.tester = function() { sys.puts(this.testProp); };
exports.MyClient = MyClient;
var sys = require('sys');
var http = require('http');
function MyClient() {
http.Client.call(this);
this.setRequestCtor(MyClientRequest);
this.testProp = 'myclient test prop';
}
sys.inherits(MyClient, http.Client);
MyClient.prototype.tester = function() { sys.puts(this.testProp); }
exports.MyClient = MyClient;
/** Testing sax push parsing
*
* The output file should have almost identical
* to the input file
*
* Known issues with this example output
*
* - Doesn't escape entities. You can do it
* manually on the character content.
* - Doesn't replicate self-closing tags.