Amo Chen

How to Use the depends_on Setting in Docker Compose

When setting up a development environment using Docker Compose, you might encounter service dependency issues. Take a simple example: the database container usually needs to start up first before the API server container can follow. This is because the API server might need to establish a connection pool with the database before it can offer API services; otherwise, errors could occur and cause the container to fail to start.

In this situation, the API server container relies on the database container to function properly, which is what we refer to as service dependency. Without understanding service dependencies, you could frequently experience inconsistent results with docker-compose, sometimes successful and sometimes not, as services might or might not start up in time or be ready.

To address this, Docker Compose provides a solution with the depends_on setting.

This article will guide you on how to use the depends_on setting.

Posted on  Dec 14, 2023  in  Docker  by  Amo Chen  ‐ 6 min read

Chatting About Refactoring and Design Patterns

No matter your position, if you’ve been developing for a while, you’ll come across refactoring or design patterns. Design patterns are solutions to common programming problems. For instance, if your codebase has a lot of repetitive code, or it’s filled with long, smelly functions, or if adding a new feature means changing lots of code, you’re not alone. Others have faced these issues, too, and have come up with various effective solutions.

Posted on  Nov 20, 2023  by  Amo Chen  ‐ 2 min read

The Freelance Path for Programmers — Online Job Opportunities

How do you all find freelance jobs? Through personal connections or Facebook groups? Basically, these channels are still very competitive. The reason being, the domestic market in Taiwan is not large enough. To get a deal, it often ends up in a price war. However, if you look abroad, not only are there more opportunities, but there might also be a chance to increase your rates! (Earn those dollars! If you want to explore different markets, accumulate experience, earn extra income for yourself, or regain control over your life (say, no more commuting, no more on-site), you can try finding freelance jobs online.

Posted on  Sep 29, 2023  by  Amo Chen  ‐ 2 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 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 Recommendations  by  Amo Chen  ‐ 5 min read

Great Article Share - Automating Kubernetes Deployments using Python

The article, “Automating Kubernetes Deployments using Python,” introduces how to automate the control of K8s-related resources using the Python Kubernetes package. It covers five major resources: Deployment, Service, ConfigMap, Secret, and Ingress. These are typically encountered when deploying applications to K8s. If you’re looking to automate the process of deploying applications to K8s with Python, this article is a great starting point and very valuable as a reference. Automating Deployment of Applications using Kubernetes Python SDK

Posted on  Jul 8, 2023  by  Amo Chen  ‐ 1 min read

A Conversational Guide to ULID (Universally Unique Alphabetically Sortable Identifier)

Previously, many people have been using UUIDs to ensure unique Id fields. However, the randomness of UUIDs makes them non-sortable. For example, you might generate a UUID starting with 47 one second, and then the next second it starts with 36. This randomness can lead to efficiency problems in databases like MySQL, which need to update multiple pages, especially when dealing with large amounts of data. Because of this issue, the concept of ULID was introduced.

Posted on  Jul 5, 2023  by  Amo Chen  ‐ 2 min read