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

#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 / README.md
Created May 6, 2019 10:21 — forked from ondrejsika/README.md
MongoDB Cheat Sheet
# 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 / 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;
@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 = {}
};
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
services:
ca.org1.example.com:
# Example of dynamically overriding locale in Sails.js
For instance, if your app allows users to pick their preferred language, you might create a [policy](http://sailsjs.com/documentation/concepts/Policies) which checks for a custom language in the user's session, and if one exists, sets the appropriate locale for use in subsequent policies, controller actions, and views:
```js
// api/policies/localize.js
module.exports = function(req, res, next) {
// If no user is logged in, continue with the default locale.
if (!req.session.userId) {return next();}
// Load the user from the database

NOTE -

  • Remove -h option if you are doing operation on same machine
  • Remove -u , -p option if your database don't have username and password

Binary

Import database

mongorestore -h IP:port -d DB_Name -u user_name -p password <input db directory>
@lakshmankashyap
lakshmankashyap / createDefaultAccounts.js
Created March 16, 2018 18:43 — forked from pau1m/createDefaultAccounts.js
Handy script for generating Ethereum accounts (json files) from Mnemonic
//const argv = require('minimist')(process.argv.slice(2));
const Web3 = require("web3")
let web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
console.log(web3)
let bip39 = require("bip39")
let hdkey = require('ethereumjs-wallet/hdkey')
let mnemonic = "weather cancel symptom owner lumber bitter bread butter dice trial shrug glance"
let hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic))
// Set to m/44'/60'/0' for ledger nano s hardware wallet compatibilty
var Bitcore = require('bitcore');
var Address = Bitcore.Address;
var HDPrivateKey = Bitcore.HDPrivateKey;
var hdPrivateKey = new HDPrivateKey.fromSeed("bf8e06fd8c0dafbc831933422895ad68c0874439e177f136f8f756b360de94f8");
var hdPublicKey = hdPrivateKey.hdPublicKey;
var address = new Address(hdPublicKey.derive( Math.floor(Date.now() / 1000) ).publicKey);
var derivedAddress = new Address(hdPublicKey.derive( Math.floor(Date.now() / 1000) ).publicKey);