Skip to content

Instantly share code, notes, and snippets.

View lakshmankashyap's full-sized avatar
🏠
Working from home

Lakshman lakshmankashyap

🏠
Working from home
View GitHub Profile
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
services:
ca.org1.example.com:
@lakshmankashyap
lakshmankashyap / localStorage.js
Created September 28, 2018 07:49 — forked from sanusart/localStorage.js
Jest mock localStorage #test #jest
// ./__mocks__/localStorage.js
let mockStorage = {};
module.exports = window.localStorage = {
setItem: (key, val) => Object.assign(mockStorage, {[key]: val}),
getItem: (key) => mockStorage[key],
clear: () => mockStorage = {}
};
@lakshmankashyap
lakshmankashyap / reduce-example.js
Created October 17, 2018 11:22 — forked from benwells/reduce-example.js
Using Array.reduce to sum a property in an array of objects
var accounts = [
{ name: 'James Brown', msgCount: 123 },
{ name: 'Stevie Wonder', msgCount: 22 },
{ name: 'Sly Stone', msgCount: 16 },
{ name: 'Otis Redding', msgCount: 300 } // Otis has the most messages
];
// get sum of msgCount prop across all objects in array
var msgTotal = accounts.reduce(function(prev, cur) {
return prev + cur.msgCount;
# Get documents, where writters are Joel Coen and Ethan Coen.
db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count()
# Get documents, where Jeff Bridges is playing leading role.
> db.movieDetails.find({ "actors.0": "Jeff Bridges" }).pretty()
@lakshmankashyap
lakshmankashyap / README.md
Created May 6, 2019 10:21 — forked from ondrejsika/README.md
MongoDB Cheat Sheet

#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

@lakshmankashyap
lakshmankashyap / MongoShard.bat
Created May 7, 2019 11:54 — forked from matthewtckr/MongoShard.bat
MongoDB Sharding Example
REM
REM Setup a MongoDB Sharded Cluster
REM
REM Reference: http://cookbook.mongodb.org/operations/convert-replica-set-to-replicated-shard-cluster/
REM More Info: http://www.kchodorow.com/blog/2010/08/09/sharding-and-replica-sets-illustrated/
REM
REM Download and Unpack MongoDB Software
REM
SET URL="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.6.11.zip"
@lakshmankashyap
lakshmankashyap / socket-cheatsheet.js
Created May 17, 2019 10:46 — forked from alexpchin/socket-cheatsheet.js
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender

fork_mode.js

var child_process = require('child_process');
var cpus = require('os').cpus();
var net = require('net');
var tcpSrv = net.createServer();

tcpSrv.listen(8000, function() {
    for (var i = 1; i <= cpus.length; i++) {

MongoDB - Setting up a Replica Set

cd \mongodbdir\

mkdir db1
mkdir db2
mkdir db3

Primary