sudo adduser tonytan
chmod -R 640 /etc/sudoers
sudo vim /etc/sudoers
chmod -R 440 /etc/sudoers
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # -*- coding: utf-8 -*- | |
| # 14-8-20 | |
| # create by: snower | |
| import os | |
| import time | |
| import struct | |
| import fcntl | |
| from logging.handlers import RotatingFileHandler, TimedRotatingFileHandler | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import logging | |
| import gunicorn.app.base | |
| from fastapi import FastAPI | |
| from loguru import logger | |
| class InterceptHandler(logging.StreamHandler): | |
| def emit(self, record): | |
| # Get corresponding Loguru level if it exists | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ Snippet that demonstrates how to use Gunicorn with Uvicorn workers in code. | |
| Feel free to run: | |
| - `python main.py` - to use uvicorn. | |
| - `ENV=prod python main.py` - to use gunicorn with uvicorn workers. | |
| Reference: https://docs.gunicorn.org/en/stable/custom.html | |
| """ | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import loguru_logger | |
| logger = loguru_logger.get_logger() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # https://pawamoy.github.io/posts/unify-logging-for-a-gunicorn-uvicorn-app/ | |
| import sys | |
| import logging | |
| from loguru import logger | |
| __all__ = ("setup_logging",) | |
| _LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss} <lvl>| {level: ^6} |</> {message}" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Okay so here's the setup: | |
| [-] The primary server API is exposed via Flask (Python) and all static files, including all html, css, js is served by nginx. | |
| [-] Python is exposing an API at url http://domain.com/api/download/<file_id>, where file_id is a database id for the file that we're interested in downloading. | |
| 1. User wants to download a file, so we spawn a new window with the url '/api/download/<file_id>' | |
| 2. Nginx intercepts the request, sees that it starts with /api/, and then forwards the request to Flask, which is being served on port 5000. | |
| 3. Flask routes the request to its download method, retrieves the pertinent data from the file_id, and constructs additional header settings to make nginx happy and to force the browser to see the file stream as a download request instead of the browser just trying to open the file in a new window. Flask then returns the modified header stream to nginx | |
| 4. Nginx is finally ready to do some work. While parsing the headers for the incoming request, it encounters "X | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """Configure handlers and formats for application loggers.""" | |
| import logging | |
| import sys | |
| from pprint import pformat | |
| # if you dont like imports of private modules | |
| # you can move it to typing.py module | |
| from loguru import logger | |
| from loguru._defaults import LOGURU_FORMAT | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!python3 | |
| """ | |
| Convert a requirements.txt file to a Poetry project. | |
| Just place in the root of your working directory and run! | |
| """ | |
| sourceFile = "./requirements.txt" | |
| import re | |
| import os | 
🔠 Glossary
mongosh