• Embedded Programming Notes

    Embedded Programming Interview Prep

    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"
    
    
    [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
    

    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 →

  • Launch Elixir app with mix

    0.5 definemain.ex, usemix run main.ex(duplicates with 2.)

    main.ex:

    defmodule Main do
      Server.main()
    end
    

    server.ex:

    defmodule Server do
      # no need to import 
      def main do
        path = Path.join(File.cwd!(), "title.yaml")
        yaml_list = YamlElixir.read_from_file(path)
        IO.inspect(yaml_list)
      end
    end
    

    output

    server > mix run main.ex
    Compiling 1 file (.ex)
    Generated server app
    {:ok,
     %{
    

    1. Use iex -S mix or mix run -e

    Read on →