Skip to content

Instantly share code, notes, and snippets.

Working from home

Nicholas Cottrell niccottrell

Working from home
View GitHub Profile
niccottrell / db-compare.js
Last active Jul 19, 2022
Compare two MongoDB databases, comparing count and size for all collections along with spot-checking a sample of documents
View db-compare.js
MIT License
Copyright (c) 2017 Martin Buberl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
niccottrell / tuned-mongod-virtual-guest.conf
Created Mar 29, 2018
tuned profile for MongoDB on AWS
View tuned-mongod-virtual-guest.conf
# tuned configuration optimized for MongoDB on AWS (or other cloud services)
# based on the 'virtual-guest' tuned profile
# tested on RHEL7
summary=Optimize for MongoDB wiredTiger Performance
niccottrell / shard-key-compound.js
Last active Dec 21, 2017
Experimenting with hashs for years in compound shard keys
View shard-key-compound.js
* This script is to experiment with a compound shard key.
* Goals:
* 1. the hash (h) to always be the same for the same date (down to the day level)
* 2. documents with the same exact date (dMy) go on the same shard but different day to different shards
* 3. will work well with 100m+ documents
* 4. small overhead related to a simple (non-compound) date shard key
* 5. still support targeted queries (as long as "h" field is included in the query by the application)
niccottrell /
Created Mar 17, 2017
Yelp API example for v3 using Scribe Java
import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.model.*;
import com.github.scribejava.core.oauth.OAuth20Service;
import org.jetbrains.annotations.Nullable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
View inline-labels.js
// Inline Labels
// -------------------------------------------------- //
$('input, textarea').each(function() {
// load the corresponding label
var $self = $(this);
var $label = $("label[for='" + $self.attr("id") + "']").
if ($label.text(); {
niccottrell / mongodb-arbiter.conf
Created Aug 14, 2014
mongodb arbiter configuration file (shard)
View mongodb-arbiter.conf
destination: file
path: "/var/log/mongo/mongo-arb.log"
logAppend: true
dbPath: "/var/lib/mongo-arb"
fork: true
pidFilePath: "/var/run/mongo/"
# After etckeeper installation
/etc/etckeeper/etckeeper.conf VCS="git"
etckeeper init && etckeeper commit
# ------
git config --global "My Machine"
git config --global "etckeeper@my.machine"
niccottrell / functions.js
Created Apr 6, 2012 — forked from RedBeard0531/functions.js
Min, Max, Sum, Count, Avg, and Std deviation using MongoDB MapReduce
View functions.js
// derived from
function map() {
emit(1, // Or put a GROUP BY key here
{sum: this.value, // the field you want stats for
min: this.value,
max: this.value,
diff: 0, // M2,n: sum((val-mean)^2)