Skip to content

Instantly share code, notes, and snippets.

@NanoDano
NanoDano / example.uwsgi.ini
Last active July 20, 2020 03:32
uWSGI example INI file
# /etc/uwsgi.d/uwsgi_example.ini
# Make sure the uwsgi file+dir has right permissions (Read by uwsgi)
[uwsgi]
plugins=python3
chdir=/srv/myapp
module=myapp.wsgi:application
env='DJANGO_SETTINGS_MODULE=myapp.settings'
home=/srv/myapp/venv
pidfile=/run/uwsgi/myapp.pid
socket=127.0.0.1:8001
@NanoDano
NanoDano / example.net.nginx.conf
Last active July 20, 2020 03:31
Example Nginx config for Python WSGI app with LetsEncrypt SSL, HTTP basic auth protected dev, and forced HTTPS+WWW
###############################
## DEFAULT CATCH ALL SERVERS ##
###############################
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
}
server {
@NanoDano
NanoDano / gen_self_signed_cert.sh
Last active August 9, 2020 04:32
Create self-signed SSL certificate with OpenSSL command-line tool
#!/usr/bin/bash
openssl \
req \
-newkey rsa:2048 -nodes \
-keyout self-signed.key \
-x509 -days 36500 -out self-signed.cert \
-subj "/C=US/ST=NRW/L=Earth/O=CompanyName/OU=IT/CN=www.example.com/[email protected]"
@NanoDano
NanoDano / rebind-caps-to-escape.ahk
Created August 1, 2020 19:42
Rebind CapsLock to Escape Windows AutoHotkey
; Rebind caps to escape
; Press `WindowsKey+R` and run `shell:startup` and put this file there
Capslock::Esc
@NanoDano
NanoDano / ssh_config
Created August 1, 2020 20:24
SSH config example
# Example ~/.ssh/config
# Connect using ``ssh sandbox`` or ``scp sandbox:* .``
Host sandbox
HostName sandbox.local
User myusername
IdentityFile ~/.ssh/id_rsa
Port 22
ServerAliveInternal 30
ProxyJump jumphost.local
@NanoDano
NanoDano / add_system_user.sh
Created August 3, 2020 03:07
Add system user in Linux
# Adds a system user account with no home dir amd no login shell
sudo useradd --system --no-create-home --shell=/sbin/nologin my_custom_username
@NanoDano
NanoDano / open-firewall-port.sh
Created August 3, 2020 03:43
Open Firewall port in Fedora/CentOS/RedHat with firewall-cmd
# Open a TCP port
firewall-cmd --add-port=8009/tcp --permanent
firewall-cmd --reload
# Inspect current rules and zones
firewall-cmd --list-all
firewall-cmd --list-ports
firewall-cmd --list-services
firewall-cmd --list-all-zones
@NanoDano
NanoDano / waitress-serve.py
Created August 3, 2020 03:45
Run a Python WSGI app with Waitress
# pip install waitress
import os
from waitress import serve
from my_wsgi_project import app # Import your app
# Run from the same directory as this script
this_files_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(this_files_dir)
# `url_prefix` is optional, but useful if you are serving app on a sub-dir
@NanoDano
NanoDano / waitress-serve-local.sh
Created August 3, 2020 03:45
Run a Python WSGI app with waitress-serve command-line
# pip install waitress
waitress-serve --listen=127.0.0.1:8001 my_wsgi_project:app --url-prefix=/my-app
@NanoDano
NanoDano / nssm_create_service.bat
Created August 3, 2020 03:48
Create Windows Service with Non-Sucking Service Manager NSSM
REM http://nssm.cc
nssm.exe install "MyCustomService" "C:\Users\nanodano\venv\Scripts\python.exe" "C:\Users\nanodano\myscript.py"
nssm.exe start MyCustomService
nssm.exe stop MyCustomService
nssm.exe remove "MyCustomService"