Skip to content

Instantly share code, notes, and snippets.

@uucidl
uucidl / traverse_children.ion
Last active December 9, 2018 09:48
Traversing Hierarchies
// Depth first traversal algorithm.
//
// (credit to Alexander Stepanov in Elements Of Programming)
//
// One of the benefits is that the visitor can implement pre or post traversal algorithms, and combine them in one single piece.
//
// @generic in T, the node value type
func traverse_children_recursively(tree_root: T*, step_visitor: func(step: TraversalStep, node: T*))
{
step_visitor(TraversalStep_PRE, tree_root);

Problem Domains For Which Many Create and Publish Their Own Solution

I find that certain problems attract the creation of many solutions. We are overwhelmed with slightly similar yet incompatible and potentially incomplete solutions.

Why is that so? Which domains show this pattern?

My hypothesis is that these problems seem easy to approach from one idiosyncratic perspective while at the same time being hard to complete. Therefore no-one’s satisfied or able to judge existing solutions and end up creating yet another one.

In certain domains, incumbent solutions also may appear bloated, and therefore it’s easy to think one can do better, because the 50% solution appears leaner. Problem is, the remaining 50% is where the necessary risk mitigation, adaptation is. An example of that is the appearance of poorly made (but lean) databases in the age of NoSQL, which claimed to be leaner just because they did not discover yet all the things their historical competitors had discovered they had to do.

#include <stdio.h>
// Shows how to iterate backwards in C. (Counter version)
int main(int argc, char** argv)
{
{ int c = argc; while (c--) {
printf("%s%s", argv[c], c == 0 ? "\n" : ", ");
} }
}

Sophistication in programming languages has diminishing returns.

I treat programming language features like I treat drugs. They come with side-effects, which I want to be aware off before even thinking of putting them into use. And if in doubt, I’d rather not use them.

For an alternative take, legions of programmers write online about the features they want to have in their language. Is it based on actual experience rather than wishful thinking? Is it based on their own introspection of what’s producing defects or harming progress?

@uucidl
uucidl / bitwise-notes-62.md
Created February 20, 2019 10:24
bitwise-notes.md

Bitwise Day 62: Indexed Arrays

Per worked 20h since Day 61.

How do we get a good story for dynamic arrays? What we called stretchy bufs (buf_... API)

Added many new intrinsics to gen_intrinsic:

  • apush, kadd, kdget, kdel
  • hget, hdel
@uucidl
uucidl / wm.el
Created April 5, 2020 09:12 — forked from pervognsen/wm.el
Dynamic tiling window manager for Emacs (inspired by dwm/awesome/xmonad for Linux)
(require 'cl)
(defstruct wm-window buffer (point 0) (start 0) (hscroll 0) dedicated)
(defvar wm-windows)
(defvar wm-windows-alist)
(defvar wm-focus)
(defvar wm-workspace 0)
(defvar wm-workspaces nil)
(defvar wm-layout 0)
@uucidl
uucidl / real_mode_boot.c
Last active May 23, 2020 08:56
legacy bios bootsector
// -*- mode: c ; c-file-style: "k&r" -*-
// x86 boot sector.
//
// Once you execute this program you will get a series of disk images, which you can try in qemu:
// qemu -drive file=boot.img,format=raw
//
// and burn to a usb stick using something like rufus or dd
#include <assert.h>
#include <stdlib.h>
@uucidl
uucidl / IOKit.org
Last active May 27, 2020 22:46
IOKit

The IOKit framework is Apple’s base framework to interact with devices. This is your go to when for instance working with USB devices.

There is a way in IOKit to register notifications to discover devices as they are plugged by our users. The API seems easy enough (see IOKitLib header)

However I was puzzled for quite long why my notifications were not processed. It turns out you have to process the iterator immediately after calling IOServiceAddMatchingNotification, otherwise notifications won’t be

@uucidl
uucidl / 01_materials.md
Last active August 5, 2020 09:10
Let's make a simple USB audio driver for xHCI hosts and Audio Class 1.0

If you develop drivers (Software) for USB peripherals then you may only need to read chapters, 4 - Architectural Overview 5 - USB Data Flow Model 9 - USB Device Frame Work, and 10 - USB Host Hardware and Software.

You probably also need to know xHCI. The host-side USB spec.

@uucidl
uucidl / uu-re-link.el
Last active October 10, 2020 19:20
Let Emacs simulate Acme by creating clickable regexp links in the buffer.