Skip to content

Instantly share code, notes, and snippets.

View guybrush's full-sized avatar

Patrick guybrush

View GitHub Profile
// this is how one would fetch tweets, right?
var http = require('http')
, twitter = http.createClient('80', 'api.twitter.com')
, request = twitter.request
( 'GET'
, '/1/statuses/user_timeline.json?user_id=56828167'
, {'host': 'api.twitter.com'}
)
, result = ''
while (true) {
var now = new Date().getTime()
console.log(now)
}
data =
{ a :
{ aa :
{ aaa : 'aaa'
, aab : 'aab'
}
}
, b :
{ ba :
{ baa : 'baa'
/***************************
benchmark nstore.get(id) versus nstore.find({id:id})
{ 'randomID1' : { 1 :
{ id : '1' { title : 'title1'
, title : 'title1' , content : 'content1'
, content : 'content1' }
} , 2 :
, 'randomID2' { title : 'title2'
var nStore = require('nstore');
var users = nStore.new(__dirname+'/users.db', function () {
users.save("creationix", {name: "Tim Caswell", age: 28}, function (err) {
if (err) { throw err; }
});
users.find({age: 28}, function (err, results) {
if (err) { throw err; }
else { console.log(results); }
});
});
var db = require('dirty')(__dirname+'/feeds_dirty.db')
, n = 100000
, start, t1, t2, t3
;
db.on('load', function(){
start = Date.now();
console.log('----------- starting');
for (var i=0; i<n; i++)
db.set(i, { title : 'title '+i
@guybrush
guybrush / gist:721762
Created November 30, 2010 14:38
nodejs file-sha1
#!/usr/bin/env node
require('fs').readFile('image.png',function(err, data){
console.log(require('crypto').createHash('sha1').update(data).digest('hex'))
})
@guybrush
guybrush / gist:723435
Created December 1, 2010 12:53
multiple prototypal inhertiance in javascript
var A, B, C, test;
A = function() {};
A.prototype.aMethod = function() {
console.log('aMethod');
};
B = function() {};
B.prototype.bMethod = function() {
console.log('bMethod');
@guybrush
guybrush / gist:724232
Created December 1, 2010 21:10
keys object handling
var keys = require('keys')
, store = new keys.Memory({reapInterval:200})
;
store.set('foo', JSON.stringify({bla:"blub"}), function(err){
if (err)
console.log(err);
else
store.get('foo', function(err, val){
err
unhosted.send( 'asdf'
, to
, key
, val
);
unhosted.send
( 'asdf'
, to
, key