Author | Logan

  1. Django: Count Aggregates with Conditions

    In Django, One-to-Many relations are modeled by the ForeignKey. Under some circumstances, we may wish to collect some information (e.g. count, min, max, avg, etc) from related objects. For example, in a blog app, we may wish to build a table which lists the title and the number of …


  2. Manage Chroot Environments with Schroot

    Schroot allows users to switch between different Linux distributions or releases conveniently. As a software developer, I have to test software between different Debian and Ubuntu releases. Schroot perfectly fits my use case.

    Besides, schroot has good balance between isolation and convenience. By default, it will mount the home directory …


  3. Build qemu-user-static from source code

    qemu-user-static is an important tool for cross-architecture developers. It allows developers to create a chroot environment and run the cross-compiled programs. For example, a developer may run an AArch64 executable without the overhead of system-level emulation.

    I usually install the qemu-user-static binaries from Ubuntu apt repository. However, I encountered some …


  4. Find Undefined Behavior with Clang UBSan

    Two weeks ago, I came across an interesting bug. The convert() function below returns 0x80000001 when p points to 0x01, 0x00, 0x00, 0x80, but the expected return value is 0x00000001 instead.

    int32_t convert(const uint8_t *restrict p) {
      uint32_t x = (                  p[0] +
                    256 *             p[1] +
                    256 * 256 *       p …


  5. POSIX Shared Memory

    POSIX shared memory is an inter-process communication (IPC) mechanism defined in POSIX specification. After setting up the shared memory, two (or more) processes may read from and write to the shared memory region. Compared to other IPC mechanisms (e.g. pipe, socket, etc), POSIX shared memory does not impose copy …


  6. Full-text Search with Django and PostgreSQL

    Django has several PostgreSQL database functions to support full-text search. If you are using PostgreSQL as the database backend, then it is easy to add full-text search to your Django app.

    In this post, I would like to build an demo app with full-text search. This post covers several PostgreSQL-specific …


  7. Introduction to qemu-debootstrap

    User-mode QEMU translates the instructions and the system calls. To run a static executable, you may wrap the command line with qemu-${arch}. For example, you may wrap an ARM64 static executable with qemu-aarch64:

    $ qemu-aarch64 /path/to/static-executable

    However, running a dynamically linked executable requires more efforts. To run a …


  8. Django ORM and Updating Counters

    Counters are common in website development. Most websites collect the number of page views with counters. E-commerce websites keep track of the quantity of a commodity with counters. However, it is hard to implement a correct counter with Django ORM.

    In this post, I would like to cover three ways …


  9. Python Property Decorator

    Recently, I was tracing the source code of PyPy, and a special decorator named @property caught my attention. It seems to be a mechanism for Python programmers to create a getter, a setter, and a deleter for an instance variable. For example, how could we intercept the access to a …


Page 1 / 7 Next »