Skip to content

Instantly share code, notes, and snippets.

@hajovsky
hajovsky / yieldable_superagent.js
Last active August 29, 2015 14:04
yieldable superagent
var request = require('superagent');
var yieldable = require('yieldable');
var co = require('co');
yieldable([
request.Request
]);
co(function *() {
var ua = 'Mozilla/1.0';
@hajovsky
hajovsky / yieldable_mongodb.js
Created April 18, 2014 13:42
yieldable mongodb native driver
var mongo = require('mongodb');
var format = require('util').format;
var co = require('co');
const MONGO_URL = 'mongodb://127.0.0.1:27017/test';
// MongoClient.connect(MONGO_URL, function(err, db) {
// if(err) throw err;
// var collection = db.collection('test_insert');
// collection.insert({a:2}, function(err, docs) {
@hajovsky
hajovsky / gist:9778146
Created March 26, 2014 07:12
how to thunkify the mongodb native
// npm install mongodb thunkify-wrap co
var mongo = require('mongodb');
var t = require('thunkify-wrap');
var co = require('co');
co(function*(){
var db = yield t(mongo.MongoClient.connect)('mongodb://127.0.0.1:27017/test');
var items = db.collection('items');
// cleanup