Skip to content

Instantly share code, notes, and snippets.

@ronalstal
ronalstal / Example_Output.txt
Last active December 11, 2017 02:24
MongoDB aggregate: compare the performance of different pipelines
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017/m121
MongoDB server version: 3.4.10
Chapter 3 Lab Lookup Pipelines Performance Comparison
## start on air_alliances - using $filter
# initialization file (not found)
@ronalstal
ronalstal / compareFileRead.R
Created January 7, 2015 10:16
compare different methods to read and sub-set a big file
# Course Data Scientist - Exploratory Data Analysis - Course Project 1
# compare the different methods of reading in
# the file "household_power_consumption.txt" and
# subsetting Date to 1/2/2007 and 2/2/2007
library(data.table)
library(sqldf)
Sys.setlocale(category = "LC_MESSAGES", locale = "C") # english output of system.time
# wk4 PA.R R script for Prog Assign - week 4
# load the data set and create contigency table c
# for grouped petal width (col 4) and species col 5
fname <- 'wk4 dataset_390_1.txt'
colnames <- c('SL','SW','PL','PW','Species')
ds <- read.csv( fname, header = FALSE, sep = "\t", col.names=colnames)
breaks <- c(0.0, 0.5, 1.5, 2.0, 99.0) # right border included
ds$PWc <- cut(ds$PW, breaks=breaks, right = TRUE)
@ronalstal
ronalstal / recip.js
Last active December 12, 2015 01:09
mongo shell script for [mongodb-users] Backwards $all query...?
//
// reference: https://groups.google.com/forum/?fromgroups=&hl=pt-BR#!topic/mongodb-user/h2N5v8gwi6M
//
db.recip.drop();
db.recip.insert({_id:"B",i:[1,2,3,4,5,6]});
db.recip.insert({_id:"C",i:[1,2,3,6,9,8]});
db.recip.insert({_id:"D",i:[1,2,3]});
A = [1,2,3,4];
qry = {};
@ronalstal
ronalstal / carc.js
Created December 4, 2012 11:56
mongodb aggregate: Convert Aggregate Result To Collection
/*
convertAggregateResultToCollection (alias: carc)
Author: Ronald Stalder <[email protected]>
*/
var convertAggregateResultToCollection = function (aggResult, options) {
// void function to supress output
var _v = function() {};
@ronalstal
ronalstal / hw31verifyXP.js
Created November 17, 2012 21:50
M101 HW31 Verify script for mongo-shell without using aggregate
// for mongo shell
// verify homework 3-1 without using aggregate (for Windows XP)
// "provide the identity of the student with the highest average in the class"
var maxAvg = 0;
var maxAvgId = 0;
// loop per student, calculate its' average and compare
var cursor = db.students.find();
while ( cursor.hasNext() ) {
@ronalstal
ronalstal / removing.js
Created November 15, 2012 18:55
MongoDB course m0101 homework 3-2 for node.js
var mongodb = require('mongodb');
var _ = require('underscore');
var db = mongodb.Db('school', new mongodb.Server('localhost', 27017), {safe: true});
db.open(function(err, client) {
if(err) {
console.log('Error opening connection' + err);
}
console.log('db opened');
@ronalstal
ronalstal / hw2-2.js
Created November 6, 2012 20:01
MongoDB course m0101 homework 2-2 for node using mapReduce
var mongodb = require('mongodb');
var _ = require('underscore');
var db = mongodb.Db('students', new mongodb.Server('localhost', 27017), {safe: true});
db.open(function(err, client) {
if(err) {
console.log('Error opening connection' + err);
}
console.log('db opened');