Skip to content

Instantly share code, notes, and snippets.

@saintc0d3r
saintc0d3r / read_preference.js
Created July 13, 2014 06:54
[MongoDb][Node.js] A simple demo of read preference settings when reading documents from a replica set
/**
* A sample demo to demonstrate Read Preference settings when reading data from a replica set.
* Instructions:
* 1. Run your replica set servers.
* 2. Run this app (note: adjust the replica set's hosts & ports as you see them fit in your environments.)
* 3. Shutdown your replica set's primary node.
* 4. Watch the outputs of this running app. Confirm that the findOne were defered ( no errors being throws) when the primary node is downed and
* then come up again after a new primary node is elected in the replica set.
*/
@saintc0d3r
saintc0d3r / 01_init_sharded_env.sh
Last active August 29, 2015 14:03
[MongoDb][Bash] Create & Initialise MongoDb Shardings
# NOTES: Adjust replSet, dbpath, port parameters as you see them fit on your system environments.
# Supposed, by default, we want to create a shardings environment where it made up from 2 replica set & each replica set is made up form 3 nodes.
# Step #1: Create & Configure replica set for shard 0
# Creates data directories for 3 mongod servers (rs_01, rs_02, rs_03)
rm -rf *.log
rm -rf ~/MongoDatabase/shard_0/rs_01 ~/MongoDatabase/shard_0/rs_02 ~/MongoDatabase/shard_0/rs_03
mkdir -p ~/MongoDatabase/shard_0/rs_01 ~/MongoDatabase/shard_0/rs_02 ~/MongoDatabase/shard_0/rs_03
@saintc0d3r
saintc0d3r / 01_insert.js
Last active August 29, 2015 14:03
[MongoDb][Node.js] Create-Retrieve-Update-Delete (CRUD) in mongodb
/**
* A Simple demonstration of documents inserts against mongodb replica set
*/
var MongoClient = require('mongodb').MongoClient,
assert=require('assert');
var connection_string = "mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/pcshop";
console.log("[INFO] - Connecting to "+connection_string+" ...");
MongoClient.connect(connection_string, function(err, db){
if (err) throw err;
@saintc0d3r
saintc0d3r / remove_warnings_host_open_files_limit.txt
Created July 19, 2014 04:54
[MongoDb][MMS] HOW TO - Remove warning 'Host has low open files limit' on MMS->Hosts page
1. Display the list of ports used by running mongod through running this command:
ps aux | grep mongod
2. Make notes the port number of mongod process for each replica set's node.
3. Open the mongod's process limits file using text editor like cat or vim as shown in this following command:
vim /proc/<the mongod's port number noted in pror step>/limits
4. Notice 'Max processes' & 'Max open files' entries in the file. Their values should like 1024. At next step, we are going to increase those values. We could also check current limits settings through running this comand: ulimit -a
5. Open /etc/security/limits.conf file using text editor apps as root and add these following entries in the file then save the changes:
* hard nofile 64000
* soft nofile 64000
6. Logout from current session then relogin.
@saintc0d3r
saintc0d3r / mms_ retlated_stats.txt
Created July 19, 2014 07:14
[MongoDb][MMS] Stats that related one to another
1. opcounter, locks% (e.g. Bulk operations would results in high Locks % but low opcounter)
2. Lock%, journal stats%, flush average
3. Non-mapped virtual memory, connections
4. Cursors, connection.
@saintc0d3r
saintc0d3r / mms_recommended_alerts.txt
Last active August 29, 2015 14:04
[MongoDb][MMS] Recommended Alerts in MMS
@saintc0d3r
saintc0d3r / index.html
Created August 5, 2014 13:38
[Zurb] Basic HTML Template
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{mainTitle}}</title>
<link rel="stylesheet" href="assets/css/foundation.css" />
<script src="assets/js/vendor/modernizr.js"></script>
</head>
<body>
@saintc0d3r
saintc0d3r / maven_how_tos
Last active August 29, 2015 14:05
Maven's HOW TOs
I. Create a java project using Maven:
-------------------------------------
1. Run command: mvn archetype:generate.
2. On the next displayed prompt, press [ENTER].
3. At next prompt, enter 1-6 option on the prompt. Enter the highest option number (e.g. 6).
4. Enter 'groupId' on the next prompt (e.g. com.mycompanyname).
5. Enter 'artifactId' on the next prompt (e.g. myapplicationname).
6. Enter 'packageName' on the next prompt (e.g. com.mycompanyname).
7. Enter 'version' on the next prompth (e.g. 1.0.0).
8. Run this command to ensure that your java project has been created successfully:
@saintc0d3r
saintc0d3r / nginx.conf
Last active August 29, 2015 14:06
[NginX] How to reverse proxy your internal web application server(s) using Nginx
# This file is usually placed in this following path: /etc/nginx
user nginx;
#user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
@saintc0d3r
saintc0d3r / post_and_display.html
Last active August 29, 2015 14:07
[Angularjs] AJS Simple Demo of Posting Data into server & display a list of data on table
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<style>
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
}
th, td{