RUID vs EUID

In a UNIX system, one can easily become confused by the concepts of RUID and EUID. This note aims to clarify and differentiate between them to help users identify these identifiers more easily. Environment Setup To explore these concepts further, we will need to create an executable file and a plain-text file to observe how they behave in various scenarios. We can utilize the functions getpid, getuid, geteuid, getgid, and getegid to obtain information about the running process, including its PID, RUID, RGID, EUID, and EGID....

October 15, 2024

On Enforcing Commit Size

Software engineers battle complexity throughout their entire careers. Even when considering details like the Way of Working (WoW), they invest as much thought as they do in selecting technical solutions. One controversial topic is whether to restrict the size of commits, which can further extend to limit the line of code (LOC). While some people argue that limiting commit size leads to a more effective review process, critics often question its enforceability....

September 21, 2024

Making your data strucutre more friendly using the "in" keyword

A thought recently occurred to me: Wouldn’t it be convenient to have a Tree object Tree() that supports the “in” keyword in Python? This way, I could simply do tree = Tree.from_list([1,2,3,4,5]) ... if val in tree: ... The good news is, we can actually do that! To make the class Tree compatible with the “in” method, we need to implement the __iter__ method. This method should recursively yield its children, enabling us to traverse the entire tree....

March 10, 2024

Python's Modules for Parallel Programming

Recently, I have been reviewing concurrent programming. Since I mainly use Python daily, I decided to learn by studying and practicing with it. This article does not touch on the principles and implementation of multithreading and its synchronization. There are many books, articles, and videos on the Internet. I am here mainly to discuss the modules provided in Python’s Standard Library and their usage. This article may be difficult to extract if you don’t understand threads and haven’t heard of the Producer–consumer problem....

December 10, 2022

Understanding Rust's None and Some(T)

The Rust language doesn’t have values like NULL, None, null, nil, values that represent “nothing”, so how does Rust represent and handle “nothing”? When comparing objects, you need to check whether the two exist. Take this following Python code as an example def inorder(p, q): if p is None and q is None: return true if p is None or q is None: return False if not inorder(p.left, q.left): return False if p....

December 3, 2022

The Ownership in Rust

It is a pity that I have never seriously learned a low-level language. In the past few years, the most popular low-level language is Rust. It is said that Linux officials also recognize this language, hoping to use this language to replace some C language modules. I have been thinking to learn a low-level language seriously. Following the trend of Rust, I read The Rust Programming Language. Among the chapters, the ownership attracted me....

November 27, 2022

The Floor Division and Modulus in Python

If you think // and % in Python would give you the same result as that in the static languages like C++ or Java, then you may be wrong about it. Here, I am going to explain it with C++. In C++, if you do cout << (167 / 12) << endl; The ouptut is 13, where the fractional part is discarded, even though the nature result 13.9166 is pretty close to 14, it just won’t round up....

October 22, 2022

Nginx, WSGI, Gevent, and Flask

Beginners are always obscured about why Flask needs Nginx and WSGI server and how much performance they increase. I used Flask for small projects that do not care much about production, so whether to use these frameworks was not a big problem for me. Recently, I’ve been working on some projects that required serious attention on them. After doing some research, I thought It was great to note it down....

September 18, 2022

Byte, Rune, and String

Our topic for today is to identify these three. In short, byte includes all ASCII characters, while rune is able to represent all UTF-8 encoding characters. Interestingly, the inventor of Golang and UTF-8 are the same person – Ken Tompson, he is also the inventor of Unix. Back to our topic, byte is a basic type, it is the same as int8. // builtin.go // ... // byte is an alias for uint8 and is equivalent to uint8 in all ways....

October 31, 2021

How to use fork(), wait(), and exec()

“Glimpse of the Lepoard” is a literal translation of an idiom from Chinese “管中窥豹”. Which states that through looking at one single spot on a leopard, one is able to understand the whole creature. I wish to explain the usage of these three functions and give you a good understanding of system calls. The Linux system is written in C and assembly language, and the system calls are encapsulated in the C language library....

October 10, 2021