A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| #!/usr/local/bin/python | |
| # -*- coding: utf-8 -*- | |
| import logging | |
| logging.debug('debug message') | |
| logging.info('info message') | |
| logging.warn('warn message') | |
| logging.error('error message') | |
| logging.critical('critical message') |
| ## Setup Docker | |
| NETWORK_NAME=${1:-my-mongo-cluster} | |
| REPLICASET_NAME=${2:-my-mongo-set} | |
| # Disconnect old container if has. | |
| docker network disconnect -f $NETWORK_NAME mongo0 | |
| docker network disconnect -f $NETWORK_NAME mongo1 | |
| docker network disconnect -f $NETWORK_NAME mongo2 | |
| # Remove old network if has. | |
| docker network rm $NETWORK_NAME |
| #!/bin/bash | |
| CONTAINER_INDEX=$1 | |
| CONTAINER_NAME="mongo"$1 | |
| DATA_VOLUME="mongo-data-volume"$1 | |
| mkdir $CONTAINER_NAME | |
| DB_PORT=$((30000+$CONTAINER_INDEX)) | |
| HTTP_PORT=$((28017+$CONTAINER_INDEX)) | |
| NETWORK_NAME=$2 | |
| REPLICASET_NAME=$3 |
| def import_from_string(val): | |
| """ | |
| Attempt to import a class from a string representation. | |
| From: https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/settings.py | |
| """ | |
| try: | |
| # Nod to tastypie's use of importlib. | |
| parts = val.split('.') | |
| module_path, class_name = '.'.join(parts[:-1]), parts[-1] |
| server { | |
| listen 80; | |
| server_name localhost; | |
| access_log /var/log/nginx/access.log; | |
| error_log /var/log/nginx/error.log; | |
| add_header 'Access-Control-Allow-Origin' '*'; |
| """ | |
| https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size | |
| >>> sizeof_fmt(168963795964) | |
| '157.4GiB' | |
| """ | |
| def sizeof_fmt(num, suffix='B'): | |
| for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: | |
| if abs(num) < 1024.0: |
| type Node[K any, V any] struct { | |
| Key K | |
| Value V | |
| Red bool | |
| Left *Node[K, V] | |
| Right *Node[K, V] | |
| Parent *Node[K, V] | |
| } | |
| type RedBlackTree[K any, V any] struct { |
This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.
Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).