Text-heavy articles about tech, including Python, Git, Linux/WSL, and Jupyter.
Read from the list of recent posts below, or use the “all posts” menu in the navigation bar to filter by post type. This blog consists of 2 types:
Recent Posts
-
Python context manager for working with lists
Related: File() context manager The ListProtect() context manager will ensure an operation on a Python list does not crash your program. Using ListProtect(), you can perform list operations like .append() safely, returning…
-
Python context manager for working with files
Python’s stdlib has a module called contextlib, which has utilities for defining context managers in Python. RealPython has a good article explaining what a context manager is and how to use them.…
-
Parse a Pydantic model to a SQLAlchemy-compatible model
A Pydantic model can be parsed to a SQLAlchemy-compatible model using the parse_pydantic_schema() function. Simply pass a class initialized from a Pydantic model to this class, and it will be converted to…
-
Python snippet: break a large list into smaller lists
If you are working with a very large list of objects in Python and finding operations are using a lot of memory or crashing your kernel (i.e. if using Jupyter in a…
-
Fix frozen/suspended WSL after computer goes to sleep
There is a known issue with WSL/WSL2, where when a computer goes to sleep or hibernates and then later wakes up, the WSL service hangs, preventing all WSL operations (including wsl –shutdown).…
-
Backup & restore WSL distributions
Assumptions: Backup a WSL distribution Command explanation: Restore a WSL distribution Command explanation:
-
Configure WSL to use host’s git
You can configure your WSL distributions to use the Windows host’s git and git config manger (GCM). This is useful when cloning from, for example, Azure DevOps. Instead of cloning on the…
-
Enable systemd in WSL
By default, WSL distributions do not use the systemd init system. This means systemctl command don’t work in WSL. Luckily, enabling systemd as your WSL distribution’s init system is easy! In the…
-
Set WSL user
By default, WSL uses the root user. It is good practice to create a non-root Linux user and give them root rights with sudo. With WSL, you can configure the user the…
-
Configure WSL allowed memory usage
By default, a WSL distribution is allowed to use 50% of total memory on Windows or 8GB, whichever is less (Source: Microsoft WSL Docs). While this may be plenty of memory usage…