Quick Tips
How to Auto Generate & Deploy Docs for a Flask App with Sphinx AutoAPI on GitHub Pages
This post assumes you have all your Flask blueprints and other modules in the /app directory. If not, revise these snippets accordingly. 1. Install the Sphinx, with a theme and the autoapi extension: pip install sphinx sphinx-rtd-theme sphinx-autoapi 2. Create and navigate into the docs directory: mkdir docs cd docs 3. Run Sphinx quick start:…
Shallow Copy vs Deep Copy in JavaScript and Python
The issue of preventing future mutation of the copied original exists both in JavaScript and Python. In Python, both lists and dictionaries are mutable reference types, similar to arrays and objects in JavaScript. When you copy these structures, you must be aware of whether you are making a shallow or deep copy. Deep Copy vs…
Troubleshooting Web Applications Deployed with CapRover in Docker Containers
Jump into the terminal of a CapRover app named testapp. Use Ctrl + P, then Ctrl + Q to exit that terminal without killing the container. Logs of the deployed application (–follow keeps retrieving the latest events): CapRover logs: Logs for Docker itself (if your application keeps getting respawned in new containers, the answer may…
SFTP File Operations with Python Using an SSH Key
Below are some functions to read, write, and delete a file, list a directory, and check if a file exists in a remote SFTP server with Python. I have written these specifically for working with CSV files and pandas data frames. The argument file in the functions below should be the full path to the…
12 Principles for Building Software as a Service Apps
The Twelve Factors: # Factor Description I Codebase There should be exactly one codebase for a deployed service with the codebase being used for many deployments. II Dependencies All dependencies should be declared, with no implicit reliance on system tools or libraries. III Config The configuration that varies between deployments should be stored in the…
How to Take a Screenshot of a Website in Python Silently with Selenium
The code below will make a browser 1920px wide, and as long as the page and take its screenshot: If the page needs to load asynchronously to complete building the DOM, you may need to give it a few seconds before taking the screenshot: If the page requires scrolling down to load the rest of…
Changing the Directory Used by Docker
If you want to have the docker images kept in another directory, such as a mounted volume: Then place the following after updating “/mnt” with your target path. Restart Docker: The old Docker directory will not be used anymore so you can remove it by:
Downloading All Files in a Directory from a Jupyter Notebook Server
Problem When you are following a tutorial with exercises on a Jupyter Notebook Server, you may want to download and work with those files locally, but there is no obvious way to download all files as the Download button disappears when multiple files/folders are selected. Solution Step 1 Click on the Jupyter logo on the…
Splitting Flask Routing Functions into Different Modules
We can put group-related routing functions into separate modules to keep a big project organized and avoid having one long views.py in your project. For example, we can take the login and sign-up-related functions from views.py and move them into a module named auth.py. In auth.py, we need to register a new blueprint: In auth.py:…
Installing GeoPandas with Its Dependencies, without installing Microsoft Visual C++
The Problem If you try to install GeoPandas with pip install geopandas, you may get an error like below. Since you don’t have the dependency GDAL installed, the installer cannot find the config and exits. Then you try installing gdal with pip install gdal and you get another error saying: The Solution Christoph Gohlke from…