• The Broken Parity Fable by TD Lee

    Tsung-Dao Lee and Chen Ning Yang won the Nobel Prize in Physics in 1957, for their work on the violation of the parity law in weak interactions, which Chien-Shiung Wu experimentally proved.

    In the article Broken Parity, TD Lee wrote about his relationship with CN Yang, regarding the eventual breakup of their companionship, for the disagreement on who discovered the violation of the parity first. At the very start of that article, there’s an interesting short fable written by Lee about the discovery of the theory. For a long time I couldn’t find the original English version of it, with the arrival of TD Lee’s Selected Papers Volume 3 Random Lattices to Gravity, it’s finally unveiled to me. Here’s the original version of the fable.

    Read on →

  • Embedded Programming Notes

    Embedded Programming Interview Prep

    C programming

    • Keywords

    volatile: Prevents optimization restrict: Allows optimization but while preventing pointer aliasing const: Restricts writing

    • Signed integer + left shift («) is chaotic, mostly because overflowing

    Read on →

  • Automating the Howard Chu Homepage

    This is done via github webhook and systemd. When github receives a push (likely from local branch), it notifies the remote server that it should pull. The remote server pulls from github, and runs docker build to build the website, and serves it with nginx.

    The auto-build program is a Flask script managed by systemd, setup by generating a systemd service file using the auto-build-setup.sh shell script.

    service="[Unit]
    Description=howard-chu-www auto build daemon
    
    [Service]
    Type=simple
    WorkingDirectory=$(pwd)
    ExecStart=$(pwd)/.venv/bin/flask run --host 0.0.0.0 --port 5000
    Restart=on-failure
    RestartSec=3
    KillSignal=SIGKILL
    Environment="FLASK_ENV=production"
    Environment="PYTHONUNBUFFERED=1"
    User=root
    
    
    [Install]
    WantedBy=multi-user.target"
    
    echo "$service" > /etc/systemd/system/howard-chu-www.service
    sudo systemctl daemon-reload
    sudo systemctl enable howard-chu-www
    sudo systemctl start howard-chu-www
    

    User=root needed for git pull’s stored credentials

    Read on →

  • Study notes on the C++ template

    overload > specialization > general template

    specialization:

    // special version of compare to handle pointers to character arrays
    template <>
    int compare(const char* const &p1, const char* const &p2)
    {
    return strcmp(p1, p2);
    }
    
    // this is also specialization:
    template <class T>
    struct ValidityError;
    template <>
    struct ValidityError<core::Signal*> {
      enum { value = HSA_STATUS_ERROR_INVALID_SIGNAL };
    };
    
    template <>
    struct ValidityError<core::Agent*> {
      enum { value = HSA_STATUS_ERROR_INVALID_AGENT };
    };
    

    Read on →

  • Using lldb to read C++ standard library

    C++ standard library can be hard to read, using a debugger to help with learning can be a good approach.

    My machine is a mac so this will be clang’s std library. And I’m using lldb because it’s better supported than gdb. Here’s how to do it.

    Install lldb, typically use

    xcode-select --install
    

    Read on →

  • How to contribute to perf

    TL;DR:

    1. Clone the repo:
    git clone https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/
    
    # switch to perf-tools-next branch
    git checkout perf-tools-next
    
    # cd into the perf's directory
    cd tools/perf
    

    Read on →

  • perf trace: Add support for enum arguments

    perf trace now supports pretty printing for enum arguments

    Well, that been said, there is only one argument that can be pretty printed in all syscalls, which is enum landlock_rule_type rule_type from syscall landlock_add_rule.

    This feature is implemented using the BPF Type Format.

    Here is perf trace before:

    perf $ ./perf trace -e landlock_add_rule
         0.000 ( 0.008 ms): ldlck-test/438194 landlock_add_rule(rule_type: 2)                                       = -1 EBADFD (File descriptor in bad state)
         0.010 ( 0.001 ms): ldlck-test/438194 landlock_add_rule(rule_type: 1)                                       = -1 EBADFD (File descriptor in bad state)
    

    Read on →

  • Shared vim clipboard when using SSH

    1. For Windows, download MobaXterm or Xming; for Mac, download XQuartz as the X server. After downloading, open the application.

      Note that on Mac XQuartz works after I uncheck the Enable Syncing, and check it back again. Link And tmux doesn’t work well on Mac’s default Terminal.app. For sharing clipboard you need to install tmux-yank plugin

    2. In the server’s SSH configuration file located at /etc/ssh/sshd_config, enable X11Forwarding yes.
    3. Based on personal experience, use the X server address provided in MobaXterm and set the Windows environment variable $env:DISPLAY to that address. This can be done in Edit System Environment Variables.

    Read on →