Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / gunicorn_app.service
Created July 20, 2020 03:20
Systemd service file for a Gunicorn WSGI application
# /etc/systemd/system/gunicorn_app.service
# sudo python3 -m pip install gunicorn
[Unit]
Description=My WSGI app
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=/var/www/my_wsgi_ap
@NanoDano
NanoDano / require_root_user.sh
Created July 20, 2020 03:17
Require script to be run by root user
#!/usr/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script needs escalated privs. Exiting"
exit 1
fi
@NanoDano
NanoDano / gen_self_signed_cert.py
Last active November 6, 2024 23:01
Generate a self-signed SSL certificate with Python OpenSSL
# pip install pyopenssl
from OpenSSL import crypto, SSL
from socket import gethostname
from pprint import pprint
from time import gmtime, mktime
CERT_FILE = "cert.pem"
KEY_FILE = "key.pem"
def create_self_signed_cert():
@NanoDano
NanoDano / django_backup_db.py
Last active August 11, 2020 05:13
Django management command to database backup, upload over FTP, and rotate files
# appname/management/commands/django_backup_db.py
# Then run with manage.py django_backup_db
from ftplib import FTP_TLS
from glob import glob
from os import system, remove
from os.path import join, getmtime, exists
from socket import gethostname
from django.core.management import BaseCommand, call_command
from django.utils.datetime_safe import datetime