Skip to content

Instantly share code, notes, and snippets.

View r01010010's full-sized avatar

Paloma Jiménez r01010010

  • Barcelona
View GitHub Profile
@r01010010
r01010010 / SuperSchema.js
Last active August 29, 2015 14:11
reusable validation function
/*** Dependencies ***/
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ValidationError = require(g.wizco.dirs.libErrors + '/ValidationError');
/**
* SuperSchema
* Schema mongoose based SuperClass
*/
function SuperSchema(schema, _ev)
var server = new mongodb.Server('localhost', 27017, {auto_reconnect: true, safe: true});
var db = new mongodb.Db('scjs', server);
db.open(function(err, db) { if(err) throw err;
async.eachSeries(
// Collection
mongo_provinces
for(j = 0; j < provinces.length; j++){
var province = provinces[j];
var province_name = _s.strLeft(province.provincia, '/');
mongo_provinces[j] = {
_id: new mongodb.ObjectID()
, slug: _s.slugify(province_name)
, name: province_name
, country: "spain"
var data = fs.readFileSync('/etc/passwd');
/* This code would start 1000 simultaneous asynchronous file reads, and run the do_next_part()
function immediately. This has several problems: first, we’d like to wait until
all the file reads are done until going further.*/
for(var i = 1; i <= 1000; i++) {
fs.readFile('./'+i+'.txt', function() {
// do something with the file
});
This file has been truncated, but you can view the full file.
db.provinces.insert(
[ { _id: ObjectId("54715c1442d576600a9965fc"),
name: 'Araba/Álava',
country: 'spain',
towns:
[ { _id: ObjectId("54715c1442d576600a996630"),
name: 'Alegría-Dulantzi',
province_id: ObjectId("54715c1442d576600a9965fc") },
{ _id: ObjectId("54715c1442d576600a996631"),
name: 'Amurrio',
var mongodb = require('mongodb');
// Connection URL
var url = 'mongodb://localhost:27017/scjs';
// Use connect method to connect to the Server
mongodb.MongoClient.connect(url, function(err, db) {
if(err) { throw err } else {
console.log('yahooo');
}
});
var sinon = require('sinon');
var chai = require('chai');
expect = chai.expect;
should = chai.should();
assert = chai.assert;
var clock;
beforeEach(function () {
clock = sinon.useFakeTimers();
/**
* Dependencies
*/
fs = require('fs');
/**
* DB Initializer
*/
var i_mongoose = {