Skip to content

Instantly share code, notes, and snippets.

var file = '';
var stream = fs.createReadStream('/home/session/A0FFCFFC63DA8D1040586132C7422CA41C29AA4C.torrent');
//stream.setEncoding('UTF-8');
stream.on('data', function(data){
file += data;
});
stream.on('close', function(data){
sys.log('File read length: '.grey + file.length);
var stuff = bencode.decode(file.toString())
//console.log(sys.inspect(stuff));
@FLYBYME
FLYBYME / prototype.js
Created November 24, 2010 02:36
What way is better?
function boo(){
this.someShit = true;
}
//this is how im doing my prototype for each method
boo.prototype.too = function(val){
this.moreShit = false;
}
boo.prototype.uoo = function(val){
this.evenMoreShit = true;
big_pipe.onPageletArrive({
"phase":1,
"id":"pagelet_composer",
"page_cache":true,
"css":["3cT\/s","6koCa"],
"resource_map": {
"qxbCm": {
"type":"js",
"src":"http:\/\/static.ak.fbcdn.net\/rsrc.php\/v1\/ya\/r\/F0DxUOBa16_.js"
}
/* This is the format a typtical snippet will be in. */
/* This infinate loop will prevent CSRF attacks but causeing the script to become unresponsive
if someone tries to load an ajax request into a script tag. The infinate loop and comment wrapped
json object will have to be parsed out before you can parse the json object.
*/
for(;;);
/* For added secuity the whole json object is wrapped in a comment */
/*
{
../timestamp.cc:6:25:../long.cc:6:25: error: ../code.cc:6:25: ../dbref.cc:6:25: error: node_events.h: No such file or directorynode_events.h: No such file or directory
error: node_events.h: No such file or directory
error:
node_events.h: No such file or directory
../bson.cc:7:25: error: node_events.h: No such file or directory
../binary.cc:7:25:../objectid.cc:6:25: error: error: node_events.h: No such file or directory
node_events.h: No such file or directory
../long.cc:18: warning: this decimal constant is unsigned only in ISO C90
../long.cc:19: warning: this decimal constant is unsigned only in ISO C90
../bson.cc:43: warning: this decimal constant is unsigned only in ISO C90
Connecting to localhost:27017
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'dropDatabase' of null
at /home/dev/node-mongodb-native/examples/simple.js:19:6
at /home/dev/node-mongodb-native/lib/mongodb/db.js:79:30
at [object Object].<anonymous> (/home/dev/node-mongodb-native/lib/mongodb/connections/server.js:113:12)
at [object Object].emit (events.js:64:17)
@FLYBYME
FLYBYME / gist:1152826
Created August 17, 2011 22:39
main server
var cluster = require('cluster')
var express = require('express');
var app = express.createServer();
app.configure(function() {
app.use(express.vhost('wiyc.info', require('./apps/wiyc.info/app')));
})
@FLYBYME
FLYBYME / gist:1152828
Created August 17, 2011 22:40
vhost app
var express = require('express');
var app = module.exports = express.createServer();
app.configure(function() {
app.use(express.bodyParser());
app.use(express.methodOverride())
app.use(app.router);
var build = function(buildFn, name, html, callBack) {
this.name = name;
this.html = html;
this.buildFn = buildFn;
this.callBack = callBack;
buildFn.apply(this, [this])
}
build.prototype.render = function(name, callBack) {
console.log('router start')
var inherits = function(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor : {
value : ctor,
enumerable : false,
writable : true,
configurable : true
}