Skip to content

Instantly share code, notes, and snippets.

View mohankumar-i2i's full-sized avatar

Mohan Kumar mohankumar-i2i

  • ideas2it technologies
  • chennai,tamil nadu,India
View GitHub Profile
@mohankumar-i2i
mohankumar-i2i / installing-node-with-nvm.md
Created September 17, 2018 11:56 — forked from d2s/installing-node-with-nvm.md
Installing Node.js for Linux & macOS with nvm
@mohankumar-i2i
mohankumar-i2i / postman-pre-request.js
Created September 18, 2018 18:30 — forked from bcnzer/postman-pre-request.js
Postman pre-request script to automatically get a bearer token from Auth0 and save it for reuse
const echoPostRequest = {
url: 'https://<my url>.auth0.com/oauth/token',
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'application/json',
raw: JSON.stringify(
{
client_id:'<your client ID>',
client_secret:'<your client secret>',
@mohankumar-i2i
mohankumar-i2i / async-foreach.js
Created September 19, 2018 10:31 — forked from atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@mohankumar-i2i
mohankumar-i2i / node-and-express.md
Created September 22, 2018 18:13 — forked from anotheruiguy/node-and-express.md
Set up a new Node.js project with Express >4.0: a newb's guide

And my article is deprecated!

As of just writing this, Express 4.0 was released and there are points in there that no longer matter. So, this remains as a great >4.0 article.

Node.js is the red-hot new hotness! You can't throw a stick on the internet without hitting someone talking about Node. But why? For one, it's built on JavaScript which is completely ubiquitous. So, why not build a development stack and server on JavaScript? I would argue that the installation is almost painless while the terseness of the language is not.

While you can create apps 100% from Node.js, the Express framework is a great tool that helps you solve many standard problems without having to write boilerplate code.

Node.js is here and it's not going anywhere anytime soon. So if you are new to Node.js, Express, and even JavaScript in general, this is a great newb's step-by-step guide to get started.

@mohankumar-i2i
mohankumar-i2i / install-docker.sh
Created September 24, 2018 08:44 — forked from sheikhwaqas/install-docker.sh
Install Docker & Docker-Compose on Ubuntu 16.04 LTS (Xenial). Run this file with sudo.
# Install Pre-requisites
apt update
apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update
# Install Docker CE
apt install docker-ce -y
@mohankumar-i2i
mohankumar-i2i / Mongo.md
Created January 2, 2019 05:56 — forked from jnewman12/Mongo.md
Data Modeling With Mongo

Data Modeling with MongoDB

mongo


Objectives

  • Understand model relationships in MongoDB
  • Understand One-to-Many relationships
@mohankumar-i2i
mohankumar-i2i / better-nodejs-require-paths.md
Created January 22, 2019 17:16 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

const crypto = require("crypto");
const start = Date.now();
function logHashTime(label) {
crypto.pbkdf2("a", "b", 100000, 512, "sha512", () => {
console.log("Hash-"+label+": ", Date.now() - start);
});
}
logHashTime(1);
logHashTime(2);
const https = require('https');
const crypto = require('crypto');
const fs = require('fs');
const start = Date.now();
setImmediate(() => console.log('this is set immediate 1'));
setImmediate(() => console.log('this is set immediate 2'));
setImmediate(() => console.log('this is set immediate 3'));
@mohankumar-i2i
mohankumar-i2i / sync-async-hybrid.js
Created February 14, 2020 09:38
hybrid function
var fs = require('fs');
const cache = {};
function readFile(fileName, callback) {
if (cache[fileName]) {
return callback(null, cache[fileName])
}
fs.readFile(fileName, (err, fileContent) => {
if (err) {
console.log(err);