Skip to content

Instantly share code, notes, and snippets.

@terakilobyte
terakilobyte / Dockerfile
Created January 21, 2018 15:15
m036 docker
# Grabbing Ubuntu
FROM ubuntu
# Install MongoDB
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 && \
echo "deb [ arch=amd64 ] http://repo.mongodb.com/apt/ubuntu trusty/mongodb-enterprise/3.6 multiverse" | tee /etc/apt/sources.list.d/mongodb-enterprise.list && \
apt-get update && \
apt-get install -y mongodb-enterprise && apt-get install -y libgssapi-krb5-2 libsasl2-2 libssl1.0.0 libstdc++6 snmp && \
echo 'manual' | tee /etc/init/mongod.override
@terakilobyte
terakilobyte / scratch.js
Created November 16, 2017 13:38
validatePipeline1.js
function validateLab1 (pipeline) {
var aggregations = db.getSiblingDB("aggregations")
if (!pipeline) {
print("var pipeline isn't properly set up!")
} else {
var studentSubmission = aggregations.movies.aggregate(pipeline)
try {
var keys = Object.keys(Object.getPrototypeOf(studentSubmission)).length
var batchSize = studentSubmission._batch.length
var totalReturned = studentSubmission.itcount()
/*
*
* Mongo-Hacker
* MongoDB Shell Enhancements for Hackers
*
* Tyler J. Brock - 2013 - 2016
*
* http://tylerbrock.github.com/mongo-hacker
*
*
@terakilobyte
terakilobyte / gist:4742624acf19bd2e35a38df0705d4fdd
Created October 17, 2017 17:26
l trim, r trim, and trim in MongoDB's Aggregation Framework
db.trim.insertMany([
{
"_id" : ObjectId("59e0d1e8505f76f4acde0609"),
"a" : " \t\n\r abc \t\n\r "
}
{ "_id" : ObjectId("59e4d34cd1fb8f891853bca4"), "a" : "xy" }
{ "_id" : ObjectId("59e4e55dd1fb8f891853bca5"), "a" : " " }
{ "_id" : ObjectId("59e4e56fd1fb8f891853bca6"), "a" : " " }
{ "_id" : ObjectId("59e4e578d1fb8f891853bca7"), "a" : " a " }
])
@terakilobyte
terakilobyte / install.sh
Created July 11, 2017 22:46
Install MongoDB on OSX/Linux
# Just copy and paste all of the below. This assumes you've downloaded MongoDB to your ~/Downloads directory!
mkdir ~/MongoDB && find ~/Downloads -name "mongodb-*.tgz" | \
xargs -I@ tar -C ~/MongoDB -xzvf @ --strip-components 1 && \
printf '\n# MongoDB Setup Begin\nMONGODB="$HOME/MongoDB/bin"\nPATH="$PATH:$MONGODB"\n# MongoDB Setup End\n' \
>> `(find $HOME -maxdepth 1 -type f -name "*.zshrc" -o -name "*.bashrc")` \
&& source `(find $HOME -maxdepth 1 -type f -name "*.zshrc" -o -name "*.bashrc")`
@terakilobyte
terakilobyte / Vagrantfile
Created June 2, 2017 20:27
Vagrantfile for MongoDB
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.box_check_update = false
config.vm.synced_folder "shared/", "/shared", create: true
config.vm.synced_folder "dataset/", "/dataset", create: true
# configuring port forwarding to access vm ports on the host system
for i in 27000..27100
config.vm.network :forwarded_port, guest: i, host: i
end
for i in 30000..30100
function convertToRoman (num) {
  let romans = [['I', 'V', 'X'], ['X', 'L', 'C'], ['C', 'D', 'M'], ['M']]
function getOutput (number, one, five, ten) {
var romanMap = {
0: () => ‘’,
1: one => `${one}`,
2: one => romanMap[1](one) + romanMap[1](one),
3: one => romanMap[2](one) + romanMap[1](one),
4: (one, five) => romanMap[1](one) + `${five}`,
5: (one, five) => `${five}`,
function mergesort (arr) {
let totalOperations = 0
// this is just to debounce the logging
let timeout
function debouncedLog () {
clearTimeout(timeout)
timeout = setTimeout(() => console.log(`${totalOperations} operations`), 500)
}
function split (unsorted) {
totalOperations++
function insertionSort(arr) {
let totalActions = 0;
for (let i = 0; i < arr.length; i++) {
totalActions++;
let smallestIndex = i;
for (let j = i + 1; j < arr.length; j++) {
totalActions++;
if (arr[j] < arr[smallestIndex]) {
smallestIndex = j;
totalActions++;
function bubbleSort(arr) {
let totalOperations = 0;
for (let i = 0; i < arr.length - 1; i++) {
totalOperations++;
for (let j = 0; j < arr.length - 1 - i; j++) {
totalOperations++;
if (arr[j] > arr[j + 1]) {
let tmp = arr[j + 1];
totalOperations++;
arr[j + 1] = arr[j];