Blog

Explanation of MongoDB Write Concern and Read Concern

Understanding MongoDB Write Concern and Read Concern is essential when working with MongoDB cluster environments. Lack of familiarity with these two crucial concepts may lead to unexpected operations and even result in bugs.

This article aims to introduce MongoDB Write Concern and Read Concern in an easy-to-understand manner.

Posted on  Jan 11, 2024  by  Amo Chen  ‐ 8 min read

Python - Learning the weakref Module Through Examples

Python is a programming language equipped with a garbage collection (GC) mechanism, which is essentially an automated memory management system. In essence, it reclaims memory spaces that are no longer in use by the program, releasing them to prevent the problems associated with steadily decreasing available memory, such as program errors or failure to execute processes.

The GC mechanism is designed to lessen the burden on developers. In contrast, languages like C require manual memory deallocation (further details can be found in the free() function), and failure to release memory often leads to memory leaks. By relying on GC, developers can avoid worrying about memory management issues, thus improving development efficiency and reducing the likelihood of errors.

Python implements its garbage collection mechanism using a technique known as reference counting.

Last updated on  Jul 28, 2024  by  Amo Chen  ‐ 9 min read

Introduction to a Handy Python Package - structlog

When starting with Python’s logging module, many of us have encountered confusion, as with the following code example:

import logging

log = logging.getLogger(__name__)
log.info('Hello')

We might expect this code to print the string Hello, but it doesn’t.

This is because the default log level for Python’s logging module is WARNING, so only messages at WARNING, ERROR, or CRITICAL levels are displayed.

To properly use the logging module, setting it up is necessary, which often means consulting the Python documentation. This isn’t a problem with Python per se, but rather a design philosophy difference.

So, is there a package more intuitive and easier to use than the built-in logging module?

The answer is “yes,” and that is the structlog package, which this article introduces.

Posted on  Aug 30, 2023  in  Python Module/Package Recommendations , Python Programming - Beginner Level  by  Amo Chen  ‐ 4 min read

Introduction to the Python Package - JMESPath (A JSON Query Language Similar to jq)

JMESPath is a Python package with functions similar to jq, enabling Python developers to query and restructure JSON data with a syntax akin to jq. This is done by converting JSON into Python’s native data types using the json module. Proper use of JMESPath can simplify code and enhance readability.

This article will introduce the methods for using JMESPath.

Posted on  Jul 12, 2023  in  Python Module/Package Recommendations  by  Amo Chen  ‐ 5 min read

Python Module Tutorial - dataclasses

Python’s dataclasses is a new module added in Python 3.7, mainly used to define structured data in the form of classes.

The dataclasses module provides some convenient features to help automatically generate commonly used class methods such as __init__, __repr__, __eq__, etc., saving developers time in writing repetitive code.

Using dataclasses can make Python programs more concise and improve code readability.

Are you ready to show off your skills using dataclasses in your Python code?

Posted on  Feb 1, 2023  in  Python Programming - Intermediate Level  by  Amo Chen  ‐ 8 min read

How to Use the Built-in VNC Client on macOS

Sometimes for work, you might need to connect to a remote server’s desktop using VNC (Virtual Network Computing) to view its display. Often, this means installing tools like TeamViewer, TightVNC, or VNC Viewer.

However, macOS actually has a built-in VNC client that you can use. If you require a simple VNC client for work, you can use the built-in VNC client on macOS.

Posted on  Dec 25, 2022  in  macOS  by  Amo Chen  ‐ 1 min read

Designed for Counting - Python Counter Class

The Python collections module provides several convenient classes for developers to use, among which the Counter class (a subclass of dict) can be applied in counting-related scenarios:

A Counter is a dict subclass for counting hashable objects.

This article will introduce the usage of the Counter class and compare its performance with dict and defaultdict.

Posted on  Apr 19, 2022  in  Python Programming - Beginner Level  by  Amo Chen  ‐ 5 min read

Docker multi-stage builds tutorial

The size of Docker images is also quite important in production environments.

If the Docker image is too large, not only will it occupy the transmission bandwidth, but it will also prolong the deployment time, so how to optimize the size of the Docker image is an important issue.

There are several ways to optimize the size of a Docker image, one of which is multi-stage build. However, the multi-stage builds example provided by the Docker official document does not work properly.

Last updated on  Dec 30, 2022  in  Docker  by  Amo Chen  ‐ 5 min read