How to create and debug Ruby gem with C (native) extension

This article explains how to create a minimum Ruby gem with native extension written in C and debug it with gdb. I uploaded complete code to GitHub. Tested with: Ubuntu 20.04 (with self-built Linux kernel 5.11.22+) Ruby 2.7.4 Warning Using Ruby version 2.7.4 is strongly recommended at the first time of doing this tutorial. I think making Ruby-C-extensions has a high probability of encountering errors – for instance, as of 2021-08-14, with Ruby 3.

Sort Scrapbox JSON (Auto Project Backup) by title for git

Pages in Scrapbox can be exported in JSON format as “Auto Project Backup” (https://scrapbox.io/projects/PROJECT_NAME/settings/backup). When managing it with git, on every time exporting and git-adding, diff will be too large because the order of pages is totally changed. It’s solved by sorting by title: 1 2 3 4 cp ~/Downloads/wataash_20060102_150405.json ./scrapbox.json git diff ./scrapbox.json # too large diff! jq <~/Downloads/wataash_20060102_150405.json '.pages = (.pages | sort_by(.title))' > ./scrapbox.json git diff .