Skip to content

Instantly share code, notes, and snippets.

View niccottrell's full-sized avatar
Working from home

Nicholas Cottrell niccottrell

Working from home
View GitHub Profile
niccottrell / db-compare.js
Last active August 11, 2023 08:57
Compare two MongoDB databases, comparing count and size for all collections along with spot-checking a sample of documents
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 March 29, 2018 10:27
tuned profile for MongoDB on AWS
# 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 December 21, 2017 11:13
Experimenting with hashs for years in compound shard keys
* 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 March 17, 2017 09:18
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;
// 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 August 14, 2014 09:22
mongodb arbiter configuration file (shard)
destination: file
path: "/var/log/mongo/mongo-arb.log"
logAppend: true
dbPath: "/var/lib/mongo-arb"
fork: true
pidFilePath: "/var/run/mongo/"
niccottrell /
Last active December 23, 2015 08:49 — forked from zhovner/
# 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 April 6, 2012 16:48 — forked from RedBeard0531/functions.js
Min, Max, Sum, Count, Avg, and Std deviation using MongoDB MapReduce
// 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)