Skip to content

Instantly share code, notes, and snippets.

View jbutko's full-sized avatar

Jozef Butko jbutko

View GitHub Profile
@jbutko
jbutko / nginx-letsencrypt-autosetup.md
Last active July 24, 2018 06:46
Auto setup https on nginx with let's encrypt

HTTPS setup on Nginx server with Let's Encrypt

  1. download certbot tool: sudo git clone https://github.com/certbot/certbot /opt/certbot
  2. generate certs: sudo /opt/certbot/certbot-auto --nginx
  3. in the menu select domain for which you want to generate SSL certs
  4. in next menu select if you want http && https access to your site or https exclusively

That's all, your site is now running under https.

If you want to make https connection more secure generate 4096 DHA key (could take almost 20 minutes):

@jbutko
jbutko / bench-test.sh
Created June 6, 2017 08:56
Load balance test with apache ab bench test
# -n number of request to test
# -c number of concurrent requests
# -H authorization header
ab -n 1000 -c 1000 -H "Authorization: someBearerToken" http://localhost:5000/api/v1/someEndpoint
# via https://www.petefreitag.com/item/689.cfm
@jbutko
jbutko / express-ionic-nginx.md
Last active June 2, 2017 06:06
Serve ExpressJS API together with Angular/Ionic static site: Nginx config
  1. create new file: sudo nano /etc/nginx/sites-available/mysite.com.conf and add:
server {            
        # on which port should nginx listen
        listen 80 default_server;                                                                                                     
        listen [::]:80 default_server;                                                                                                
                                        
        # serve client
        root /home/ionic-app/client/www;                                                                               
        index index.html index.htm;
@jbutko
jbutko / readme.MD
Last active April 26, 2017 12:55
Add your ssh public key to authorized_keys on the server
@jbutko
jbutko / readme.md
Last active June 1, 2017 13:49
PM2 cluster mode - fix for ports

When you run an app in cluster mode with PM2 each worker will receive a value in process.env.NODE_APP_INSTANCE which goes from 0 to number of workers-1. Let's say you start your app with pm2 start app.js -i 4, then your workers will receive 0 1 2 3 as NODE_APP_INSTANCE value.

Then in your code you can use that value to set the listen port such as server.listen(8000 + process.env.NODE_APP_INSTANCE)

// Unitech/pm2#1510 (comment)

// pm2 user permission fix Unitech/pm2#837

@jbutko
jbutko / index.js
Last active April 20, 2017 11:34
Generate random string in node
const crypto = require('crypto');
const id = crypto.randomBytes(24).toString('hex');
// via http://stackoverflow.com/questions/23327010/how-to-generate-unique-id-with-node-js#answer-40191779
@jbutko
jbutko / readme.MD
Last active June 24, 2022 10:51
Add deploy keys to gitlab project
@jbutko
jbutko / readme.MD
Last active May 30, 2017 10:27
SSH

create ssh command alias

Host project.stage
  HostName stage.project.com
  User webadmin
  Port 2222
@jbutko
jbutko / mongo_backup.sh
Created April 6, 2017 07:13 — forked from sheharyarn/mongo_backup.sh
Mongodump Shell Script for Cronjob
#!/bin/bash
MONGO_DATABASE="your_db_name"
APP_NAME="your_app_name"
MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
TIMESTAMP=`date +%F-%H%M`
MONGODUMP_PATH="/usr/bin/mongodump"
BACKUPS_DIR="/home/username/backups/$APP_NAME"
@jbutko
jbutko / readme.MD
Created April 5, 2017 18:18
Socket.io: broadcasting to (not only) rooms

Send to the sender and noone else

socket.emit('hello', msg);

Send to everyone including the sender(if the sender is in the room) in the room "my room"

io.to('my room').emit('hello', msg);

Send to everyone except the sender(if the sender is in the room) in the room "my room"

socket.broadcast.to('my room').emit('hello', msg);

Send to everyone in every room, including the sender