Skip to content

Instantly share code, notes, and snippets.

@NguyenTrungTin
NguyenTrungTin / nginxproxy.md
Created June 13, 2019 07:09 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@NguyenTrungTin
NguyenTrungTin / docker-cleanup-resources.md
Created June 6, 2019 13:55 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@NguyenTrungTin
NguyenTrungTin / mongodb-s3-backup.sh
Created June 6, 2019 13:54 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh
@NguyenTrungTin
NguyenTrungTin / docker-without-sudo.md
Created April 22, 2019 06:56
Run Docker commands without sudo

Run Docker commands without sudo

1. Add the docker group if it doesn't already exist
$ sudo groupadd docker
2. Add the connected user $USER to the docker group
@NguyenTrungTin
NguyenTrungTin / arrayToSingleObject.js
Created April 20, 2019 19:50
Convert array of objects to single object
let arrayToObject = (arr) => {
return arr.reduce(
(obj, item) => Object.assign(obj, { ...item }),
{}
);
}
let arr = [
{
@NguyenTrungTin
NguyenTrungTin / debug.js
Created April 16, 2019 08:02
Nodejs - errorHandlers Middleware
const chalk = require('chalk');
// Declare the debug module
let debug = {};
debug.log = message => console.log(chalk.magenta.bgYellow.underline(message));
debug.info = message => console.log(chalk.blue(message));
debug.warn = message => console.log(chalk.yellow(message));
@NguyenTrungTin
NguyenTrungTin / debug.js
Created April 16, 2019 04:59
Debug make easy with colors when logging to Terminal in Nodejs
const chalk = require('chalk');
// Declare the debug module
let debug = {};
debug.log = message => console.log(chalk.magenta.bgYellow.underline(message));
debug.info = message => console.log(chalk.blue(message));
debug.warn = message => console.log(chalk.yellow(message));
@NguyenTrungTin
NguyenTrungTin / rootPath.js
Last active April 16, 2019 04:58 — forked from antonlvovych/root.js
Get root path of node.js application
var path = require('path');
module.exports = (function () {
return path.dirname(require.main.filename || process.mainModule.filename);
})();
// Example of usage:
var rootPath = require('rootPath'); // In root will be absolute path to your application
@NguyenTrungTin
NguyenTrungTin / tmux-cheatsheet.markdown
Created April 13, 2019 07:50 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@NguyenTrungTin
NguyenTrungTin / postgreSQL-change-password.md
Last active April 11, 2019 05:33
Change postgreSQL user password

1/ Solution 1:

sudo -u postgres psql
\password postgres