Skip to content

Instantly share code, notes, and snippets.

View abhi11210646's full-sized avatar
🙂
Focusing

Abhisekh Kumar Singh abhi11210646

🙂
Focusing
View GitHub Profile
@abhi11210646
abhi11210646 / Promises: Async-await.js
Last active May 21, 2018 15:14
Promise methods like all. race, reject, resolve etc. And Async/Await functionality
/*
Async: -"When an async function is called, it returns a Promise. When the async function returns a value,
the Promise will be resolved with the returned value.When the async function throws an exception or some value,
the Promise will be rejected with the thrown value.An async function can contain an await expression,
that pauses the execution of the async function and waits for the passed Promise's resolution,
and then resumes the async function's execution and returns the resolved value."
Await:- "The await expression causes async function execution to pause until a Promise is fulfilled or rejected,
and to resume execution of the async function after fulfillment. When resumed, the value of the await expression is
that of the fulfilled Promise.If the Promise is rejected, the await expression throws the rejected value.
@abhi11210646
abhi11210646 / MongoDB: Aggregation Framework.js
Last active May 21, 2018 15:29
All possible question's answer by aggregation framework of mongoDB for Movies DATASET. movies data | data science | aggregation | mongoDB
#### Format of Dataset
# Movies
{
"_id" : ObjectId("5aa7d4496b7a5451ba8ce741"),
"movie_id" : 1,
"title" : "Toy Story (1995)",
"genres" : "Animation|Children's|Comedy"
}
# Ratings
{
@abhi11210646
abhi11210646 / Docker: Container
Last active May 21, 2018 15:10
Docker basic commands
#Running docker container nginix images(new container)
> docker container run --publish 80:80 --detach nginix // --detach(-d) to run in background // --publish(-p) defines port forwarding
> docker container run --publish HOST_PORT:CONTAINER_PORT --detach --name nginx_server nginix // --name to provide unique name to container
#List docker container
> docker container ls -a // -a to list all running or stopped containers
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
@abhi11210646
abhi11210646 / Shell script: .bashrc
Last active May 21, 2018 15:28
Shell script for connecting to EC2 instance and pulling code from github
#Make life easier by aliasing daily used commands
### edit .bashrc file
Step 1:- Move to home directory by typing.
>CD
Step 2:- Open .bashrc file.
>vim .bashrc
or
>nano .bashrc
@abhi11210646
abhi11210646 / nginx: Reverse Proxy
Last active May 21, 2018 18:13
nginx configuration
#
server {
listen 80;
server_name example2.com www.example2.com xyz.example.com;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
# SETUP APACHE ON WINDOW
> Path can be different for your xampp server so look for file location accordingly.
**Step:1** C:/xampp/apache/conf/httpd.conf
Search for “proxy_http_module” and uncomment it.
**Step:2** C:/xampp/apache/conf/extra/httpd-vhosts.conf
# If you accidentally deleted your server's ".ssh/authorized_keys" then follow below steps
# lost key instance => lost_ec2
# new launched instance => new_ec2
step 1: launch new ec2 instance and generate new .pem(new_pem.pem) file.
step 2: stop lost_ec2 instance and dettache volume.
step 3: attach lost_ec2 volume to new_ec2 volume.
step 4: log in to new_ec2 using new_pem.pem file.
Step-1: create git directory (/home/ubuntu/site.git).
$/home/ubuntu/site.git> git init --bare
Step-2: your deployment path (/home/ubuntu/www) from where site will be served.
Step-3: Inside site.git folder move to hooks folder and create a file named post-receive.
paste below code inside it.
#!/bin/bash
deploy="yes"
const http = require("http");
const server = http.createServer((req,res)=>{
console.log("request came", req.url);
// faking 1 sec amount of work
setTimeout(()=>{
console.log("response sent", req.url);
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('okay');
},1000);
const http = require("http");
let keepAliveAgent = new http.Agent({
keepAlive: true,
maxSockets: 5,
keepAliveMsecs: 60000
});
let name;