Skip to content

Instantly share code, notes, and snippets.

View maxsimych's full-sized avatar

Max maxsimych

View GitHub Profile
@maxsimych
maxsimych / CORSHeaders.js
Last active February 24, 2019 08:31
Stop CORS errors
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content, Accept, Content-Type, Authorization');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
@maxsimych
maxsimych / server.js
Last active February 24, 2019 07:50
Node server port setting and standard error handler
const normalizePort = val => {
const port = parseInt(val, 10);
if (isNaN(port)) {
return val;
}
if (port >= 0) {
return port;
}
return false;
@maxsimych
maxsimych / README.md
Created March 11, 2019 11:24 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@maxsimych
maxsimych / catchException
Last active July 16, 2019 07:49
Async catch Exception
module.exports = fn => {
return (req, res, next) => {
Promise.resolve(fn(req, res)).catch(next);
}
};
// EXAMPLE OF USAGE:
//const catchException = require('./utils/catchException')
//app.get('/', catchExceptions(async (req, res) => {
// ...
@maxsimych
maxsimych / headerDisable
Created June 17, 2019 19:28
Disable leaks about using Express in production
app.disable("x-powered-by");
@maxsimych
maxsimych / docker get ip
Last active July 19, 2019 08:42 — forked from nerdalert/gistify691462.sh
Get an ip of docker container
### Example #1 ###
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e23d01384ac iperf-v1:latest "/usr/bin/iperf -s" 10 minutes ago Up 10 minutes 5001/tcp, 0.0.0.0:32768->5201/tcp compassionate_goodall
# Append the container ID (CID) to the end of an inspect
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 2e23d01384ac
172.17.0.1
### Example #2 ###
# Add -q to automatically parse and return the last CID created.
@maxsimych
maxsimych / commands
Last active October 15, 2019 07:38
UNIX Terminal helpful commands
Kill-port:
//To list any process listening to the port 8080:
sudo lsof -i:8080
//To kill any process listening to the port 8080:
sudo kill $(lsof -t -i:8080)
//or more violently:
sudo kill -9 $(lsof -t -i:8080)
//(-9 corresponds to the SIGKILL - terminate immediately/hard kill)
On freeze:
@maxsimych
maxsimych / promiseTimeout
Created July 16, 2019 07:56
promisify setTimeout util
module.exports = ms => {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms);
})
}
//EXAMPLE OF USAGE:
//const promuseTimeout = request('./utils/promiseTimeout');
//(async () => {
// await promiseTimeout(1000);
@maxsimych
maxsimych / weeklies.md
Created July 21, 2019 13:36 — forked from cayasso/weeklies.md
List of Weeklies
@maxsimych
maxsimych / favoriteNpms.md
Last active October 10, 2019 06:53
Node.js - My list of packages with link to npmjs