Skip to content

Instantly share code, notes, and snippets.

@leommoore
leommoore / mongodb_setting_up_a_replica_set.md
Last active December 8, 2021 09:58
MongoDB - Setting up a Replica Set

#MongoDB - Setting up a Replica Set

cd \mongodbdir\

mkdir db1
mkdir db2
mkdir db3

###Primary mongod --dbpath ./db1 --port 30000 --replSet "demo"

@leommoore
leommoore / node_running_in_production.md
Last active November 21, 2021 00:50
Node - Running in Production

#Node - Running in Production This gist is based on the excellent post by @hacksparrow which is found at http://www.hacksparrow.com/running-express-js-in-production-mode.html. The main principle is that you want the application to detect that it is running on a production server and to use the production configuration. The way to do this is to set the NODE_ENV=production. To do this you need to do the following:

$ export NODE_ENV=production

But we have a little problem here. The NODE_ENV environment variable will be lost if the server restarts, so it is safer to put it in the .bash_profile file. That way the variable will set again every time the system reboots. You will find the file in your home directory. It's a hidden file, so you can't see it unless you do a ls -la. We will append the export command to the .bash_profile file.

@leommoore
leommoore / mongodb_3.2.x_logging.md
Last active July 4, 2021 10:51
MongoDB 3.2.x Logging

MongoDB 3.2.x Logging

The main log file is the mongod.log. You can specify the log file location when you are starting the mongod process but if you have installed on Ubuntu from a package then you log file will normally be located in /var/log/mongodb/mongod.log.

You can tail the log file using:

tail -f /var/log/mongodb/mongod.log

From the Mongo shell you can also view the log file using:

show logs

@leommoore
leommoore / mongodb_mapreduce.md
Last active May 2, 2021 20:29
MongoDB MapReduce

#MongoDB MapReduce

(See http://mapreduce.org/ for more information on MapReduce)

MapReduce is a programming framework popularized by Google and used to simplify data processing across massive data sets. As people rapidly increase their online activity and digital footprint, organizations are finding it vital to quickly analyze the huge amounts of data their customers and audiences generate to better understand and serve them. MapReduce is the tool that is helping those organizations.

Most enterprises deal with multiple types of data (text, rich text, rdbms, graph, etc…) and need to process all this data quickly and efficiently to derive meaningful insights that bring business value to the organization. With MapReduce, computational processing can occur on data stored either in a filesystem (unstructured) or within a database (structured).

There are two fundamental pieces of a MapReduce query:

@leommoore
leommoore / linux_ssh_basics.md
Last active March 31, 2021 17:03
Linux - SSH (Secure SHell) Basics

#Linux - SSH (Secure SHell) Basics ssh is a secure mechanism to interact with a computer remotely.

##Logging on ssh allows a user to log in remotely to a server with a ssh server running (ie openSSHServer). For example:

ssh pi@192.168.1.2

or, using a domain name like:

@leommoore
leommoore / mongodb_basic_commands.md
Last active January 16, 2021 16:36
MongoDB - Basic Commands

#MongoDB - Basic Commands

##Saving Data

db  //Tells you the current database

show collections //Shows the collections available in the current db

db.foo.save({_id:1, x:10}) //Save the document into the foo collection  

db.bar.save({_id:1, x:10}) //Save the document into the bar collection

@leommoore
leommoore / mongodb_3.2.x_reporting.md
Last active November 9, 2020 18:11
MongoDB 3.2.x Reporting

MongoDB 3.2.x Reporting

The find() operator creates a cursor to the data. The client can then parse through the data and do calculations on the data for reports purposes. However, with large data sets this is not practical. It makes far more sense for the server to do the calculations and return the result. This can save a considerable amount of unnecessary network traffic. You can however run the count on the cursor without much overhead.

db.mycollection.find().count()

Mongo has two other methods for reporting on data:

  • Aggregation
  • Map-Reduce
@leommoore
leommoore / mongodb_3.2.x_sharding.md
Last active May 7, 2019 11:50
MongoDB 3.2.x Sharding

#MongoDB 3.2.x Sharding Sharding is used when the database is too large to run on a single server and you need to spread the load across multiple servers. The name itself refers to the breaking (sharding) of the data into seperate groups of data which will reside on different servers.

##Configuration Server Start the server on your server (myserver0)

mongod --configsvr --dbpath /data

On myserver1 start the shard giving the configuration server as the --configdb option

@leommoore
leommoore / 00.howto_install_phantomjs.md
Last active January 9, 2019 15:38 — forked from julionc/00.howto_install_phantomjs.md
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

Version: 2.1.1

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
@leommoore
leommoore / javascript_dictionary.md
Last active October 25, 2018 08:25
JavaScript - Dictionary

#JavaScript - Dictionary

This allows you to store and lookup dictionary name value pairs

###Construction

var Dictionary = function Dictionary(startValues) {  
  this.data = startValues || {};
}