Skip to content

Instantly share code, notes, and snippets.

View akumbhani66's full-sized avatar
🎯
Focusing

Ashvin Kumbhani akumbhani66

🎯
Focusing
View GitHub Profile
@akumbhani66
akumbhani66 / no-await-inside-loop.js
Created May 30, 2019 10:42
no await inside for-loop
const arrayOfData = [1, 2, 3, 4]
const promises = [];
for (let i = 0; i < arrayOfData.length; i += 1) {
// Don't use await here, as each request needs to wait untill previous not complete.
// Let's push all the promise and resolve them once instea
// await someAPI(arrayOfData[i])
promises.push(someAPI(arrayOfData[i]));
}
@akumbhani66
akumbhani66 / main.go
Created January 2, 2019 16:06
Simple Go program to serve current directory.
package main
import (
"log"
"net/http"
)
func main() {
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("./"))))
log.Println("Listening at 3000...")
@akumbhani66
akumbhani66 / async.js
Last active January 1, 2019 12:15
Basic of async.
const fs = require('fs')
function myReaddir() {
return new Promise((resolve, reject) => {
fs.readdir("./aaa", function(err, files){
if(err) {
reject(err);
} else {
resolve(files);
}
@akumbhani66
akumbhani66 / tmux.md
Created December 19, 2018 12:08 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

  1. copy directory cp -R --dir

  2. Find files find / name *.js mlocate - ubuntu locate - mac

  3. check space df -h

@akumbhani66
akumbhani66 / go handy commands.txt
Created November 28, 2018 13:16
Go handy commands.
List of dependencies used by project.
go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
@akumbhani66
akumbhani66 / sample.js
Created September 29, 2018 11:57
ES6 tricks to make life easy with javascript.
includes.
=========
// old way was using indexOf() functio.
let a = "ABCD"
console.log(a.includes("A")) // true
console.log(a.includes("Z")) // false
Remove unwanted properties from object.
=======================================
// To remove all process
docker rm -f $(docker ps -a -q)
// To remove all images
docker rm -f $(docker images -q)
// To stop running containers
docker stop -f $(docker ps -q)
// To remove images with same tag
const MongoClient = require('mongodb').MongoClient
const faker = require('faker');
if (process.argv[2] === "1") {
var DATA = [];
DATA[0] = {
fname: "AAA",
lname: "BBB",
age: 20,
gender: "M",
const express = require('express');
const bodyParser = require('body-parser');
const app = new express();
var DB;
var MongoClient = require('mongodb').MongoClient
MongoClient.connect('mongodb://localhost:27017/mytest', function (err, db) {
if (err) throw err