Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Nicholas Cottrell niccottrell

🏠
Working from home
Block or report user

Report or block niccottrell

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@niccottrell
niccottrell / db-compare.js
Last active Oct 4, 2019
Compare two MongoDB databases, comparing count and size for all collections along with spot-checking a sample of documents
View db-compare.js
// 1. Configure settings below
// 2. Run with "mongo db-spotchecks.js"
uriOld = "mongodb://user:pass@hosname:27017/admin?replicaSet=MySet&ssl=true"
uriNew = "mongodb://localhost"
dbName = "MyDB";
excludeCollections= ["CronLog", "HitLog", "Freq", "SystemLog", "Message"] // Exclude any non-critical collections
sample = {
min: 10,
max: 2000
@niccottrell
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
#
[main]
summary=Optimize for MongoDB wiredTiger Performance
include=virtual-guest
@niccottrell
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
niccottrell / YelpApi.java
Created Mar 17, 2017
Yelp API example for v3 using Scribe Java
View YelpApi.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
niccottrell / mongodb-arbiter.conf
Created Aug 14, 2014
mongodb arbiter configuration file (shard)
View mongodb-arbiter.conf
systemLog:
destination: file
path: "/var/log/mongo/mongo-arb.log"
logAppend: true
storage:
dbPath: "/var/lib/mongo-arb"
processManagement:
fork: true
pidFilePath: "/var/run/mongo/mongod-arb.pid"
net:
View etckeeper.sh
# After etckeeper installation
/etc/etckeeper/etckeeper.conf VCS="git"
etckeeper init && etckeeper commit
# ------
git config --global user.name "My Machine"
git config --global user.email "etckeeper@my.machine"
@niccottrell
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 http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm
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,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
You can’t perform that action at this time.