Skip to content

Instantly share code, notes, and snippets.

Alexander saniaky

View GitHub Profile
@saniaky
saniaky / websocket.js
Created Mar 1, 2020
Express Websockets + PassportJS
View websocket.js
const logger = require('../../../config/logger');
const WebSocket = require('ws');
const {uuid} = require('uuidv4');
const makeActionHandler = require('./chatEventsHandler');
//const sessionParser = require('../../../../config/session');
/**
* Initialize the WebSocket server instance
*/
const wss = new WebSocket.Server({clientTracking: true, noServer: true});
@saniaky
saniaky / Readme.md
Last active Jun 7, 2020
Docker + nginx-proxy + let's encrypt + watchtower + fail2ban
View Readme.md

Complete solution for websites hosting

This gist contains example of how you can configure nginx reverse-proxy with autmatic container discovery, SSL certificates generation (using Let's Encrypt) and auto updates.

Features:

  • Automatically detect new containers and reconfigure nginx reverse-proxy
  • Automatically generate/update SSL certificates for all specified containers.
  • Watch for new docker images and update them.
  • Ban bots and hackers who are trying to bruteforce your website or do anything suspicious.
@saniaky
saniaky / panopto_dl.py
Last active Apr 18, 2020 — forked from DavidBuchanan314/panopto_dl.py
Panopto video downloader
View panopto_dl.py
import os
import requests
import youtube_dl
"""
Change the following values to yours one
"""
PANOPTO_BASE = "https://YOUR_WEBSITE.hosted.panopto.com"
TOKEN = "put .ASPAUTH token here"
@saniaky
saniaky / README.md
Last active Apr 9, 2019
Automatic backup of all MySQL databases to AWS S3 + restore script that downloads latest backup and imports it
View README.md
  1. Create S3 bucket db-backup
  2. Specify Expire Policty to remove old backups
    Open Bucket Settings -> Management -> Add lifecycle rule -> Expiration tab
    Select Expire current version of object. Use 30 days.
    Select Permanently delete previous versions. Use 1 day.
  3. Create user db-backup-user, assign inline permission policy:
    {
        "Version": "2012-10-17",
        "Statement": [
    
@saniaky
saniaky / mysql-docker.sh
Last active Aug 26, 2019
Backup and restore a ALL MySQL databases from a running Docker MySQL container.
View mysql-docker.sh
CONTAINER=db
# Backup
docker exec $CONTAINER sh -c \
'mysqldump --all-databases --quick --single-transaction --skip-lock-tables --flush-privileges -uroot -p"$MYSQL_ROOT_PASSWORD"' \
| gzip > ./backup.sql.gz
# Restore
gunzip ./backup.sql.gz
cat backup.sql | docker exec -i $CONTAINER sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD"'
@saniaky
saniaky / custom_proxy_settings.conf
Last active Dec 1, 2018
Docker + Wordpress + Nginx Proxy + Let's encrypt + Watcher
View custom_proxy_settings.conf
client_max_body_size 64m;
@saniaky
saniaky / instructions.txt
Last active Dec 1, 2018
Initial Server Setup CentOS + Docker
View instructions.txt
# ============ Create separate user ============
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos-7
https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-centos-quickstart
local$ ssh root@server_ip_address
# adduser username
# passwd username
# usermod -aG wheel username
# ============ Copy your SSH key to server ============
@saniaky
saniaky / YoutubeVimeoUrlParser.js
Last active Oct 21, 2018 — forked from yangshun/youtube-vimeo-url-parser.js
YouTube Vimeo URL Parser ES6 Class
View YoutubeVimeoUrlParser.js
class YoutubeVimeoUrlParser {
/**
* Creates an instance of YoutubeVimeoUrlParser.
*
* @constructor
* @this {YoutubeVimeoUrlParser}
*/
constructor() {
this.pattern = /(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(&\S+)?/;
@saniaky
saniaky / package.json
Last active Sep 1, 2018
Reverse proxy server for API + create-react-app (CRA)
View package.json
{
"name": "test",
"version": "0.1.0",
"private": true,
"scripts": {
"app": "concurrently \"node proxy-middleware.js\" \"npm start\"",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
@saniaky
saniaky / Messages.java
Created Dec 5, 2017
Example of using message resources in Spring Boot service layer code, in as simple way.
View Messages.java
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Component;
import java.util.Locale;
/**
* @author saniaky
* @since 12/5/17
*/
You can’t perform that action at this time.