Skip to content

Instantly share code, notes, and snippets.

@leommoore
leommoore / mongodb_mongo_shell.md
Last active October 11, 2017 20:47
MongoDB - Mongo Shell

#MongoDB - Mongo Shell

###Single Task You can run commands in MongoDB from the command prompt by feeding the command into the mongo shell using:

mongo server1/admin --eval "db.runCommand({logRotate:1})"

mongo localhost:30000/admin --eval "db.runCommand({logRotate:1})"

This example will rotate the log file without remaining in the mongo shell. Note: admin refers to the admin database. Executing the command returns:

@leommoore
leommoore / btoa-atob.js
Last active November 19, 2017 08:00
btoa & atob
function btoa(str) {
if ((typeof str) !== 'string') {
str = JSON.stringify(str);
}
var buffer;
if (str instanceof Buffer) {
buffer = str;
@leommoore
leommoore / ssl_basics.md
Last active May 9, 2018 16:39
SSL Basics

#SSL Basics

Secure Socket Layer (SSL) is a mechanism to allow information to be securely communicated. Specifically, it is a cryptographic protocol that enables two parties such as a web server and a browser to exchange information securely by encrypting it before sending and decrypting it upon receipt. It is based on the X.509 standards.

##Symmetric and Asymmetric Encryption Encrypting and decrypting requires a secret like a password, which is known as a key. There are two types of key, symmetric and asymmetric. If a symmetric key is used it means that the same key is used to encrypt and decrypt the message. Asymmetric keys consist of a private and public key. The message sender encrypts the message using their private (secret) key and the message receiver can decrypt the message using the senders public key.

Asymmetric keys require more processing resources than symmetric keys. The problem is that to communicate using symmetric keys both parties have to have the symmetric keys first and the question is

@leommoore
leommoore / mongodb_basics.md
Last active May 17, 2018 11:33
MongoDB - Basics

#MongoDB - Basics

##Installation The Debian package management tool (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import the 10gen public GPG Key:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

Create a /etc/apt/sources.list.d/10gen.list file using the following command.

echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list

@leommoore
leommoore / mongodb_indexes.md
Last active May 31, 2018 06:59
MongoDB Indexes

#MongoDB Indexes There are 5 different index types supported in MongoDB.

  1. Regular (B-Tree) - supports indexes on a single or multiple fields
  2. Geo - supports indexing on a geographical location (useful for finding locations nearby)
  3. Text - Allows for search engine like full text searching
  4. Hashed - This is used primarily used for sharding as it evenly distributes the hashes rather than clustering them.
  5. Time to Life - This supports expiring based on a document date field

##Create Index

@leommoore
leommoore / letsencrypt_ubuntu_nginx.md
Last active August 8, 2018 10:37
Letsencrypt Ubuntu 14.04 Nginx

#Letsencrypt Ubuntu 14.04 Nginx Letsencrypt (https://letsencrypt.org) is an initative which aims to increase the use of encryption for websites. It basically allows people to apply for free certificates provided that they prove the they control the requested domain.

Note: As of 8th March 2016 letsencrypt is still in public beta.

##Installation To install the client, clone the repostiory from github.

git clone https://github.com/letsencrypt/letsencrypt.git
@leommoore
leommoore / mongodb_3.2.x_security.md
Last active October 19, 2018 00:39
MongoDB 3.2.x Security

#MongoDB 3.2.x Security

##Network Ports The standard ports used by mongo are:

ProcessRoleDefault Port
@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 || {};
}
@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 / 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