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
@lakshmankashyap
lakshmankashyap / mongo_group_by_day.js
Created August 17, 2020 13:32 — forked from cschlyter/mongo_group_by_day.js
MongoDB: group data by day (group)
db.link_access.group(
{
keyf: function(doc) {
var date = new Date(doc.date);
var dateKey = (date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear()+'';
return {'day': dateKey};
},
cond: {short_id: "N"},
initial: {count:0},
reduce: function(obj, prev) {prev.count++;}
@lakshmankashyap
lakshmankashyap / app.js
Created May 12, 2020 05:35 — forked from joshnuss/app.js
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./permission"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@lakshmankashyap
lakshmankashyap / System Design.md
Created June 12, 2019 07:51 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@lakshmankashyap
lakshmankashyap / javascript_deep_dive.md
Created June 12, 2019 07:48 — forked from faressoft/javascript_deep_dive.md
JavaScript Deep Dive to Crack The JavaScript Interviews
@lakshmankashyap
lakshmankashyap / scalability.md
Created June 12, 2019 07:48 — forked from faressoft/scalability.md
Scalability Overview, Terms, and Methodologies

Instead of writing a long article I wrote this summary to give a good overview about software systems scalability by listing the main terms and methodologies that widely used to build stable systems that are able to scale and handle the increasing amont of users and data.

Index

  • Scalability
  • Terms System Quality Attributes
  • Failover
  • Load Balancer
  • MapReduce
  • Caching
@lakshmankashyap
lakshmankashyap / Makefile
Created May 30, 2019 10:54 — forked from checkaayush/Makefile
Makefile to setup MongoDB Replica Set for development
# Setup local MongoDB Replica Set for development.
DB_ROOT ?= /tmp
DB1_PATH ?= ${DB_ROOT}/db1
DB2_PATH ?= ${DB_ROOT}/db2
DB3_PATH ?= ${DB_ROOT}/db3
DB1_PORT ?= 30000
DB2_PORT ?= 40000
DB3_PORT ?= 50000

MongoDB - Setting up a Replica Set

cd \mongodbdir\

mkdir db1
mkdir db2
mkdir db3

Primary

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++) {
@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
@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"