Skip to content

Instantly share code, notes, and snippets.

@uucidl
uucidl / language-pitfalls.org
Last active December 22, 2020 13:43
Language Specific Pitfalls And Things Not To Do Again

Python2

Don’t create generators with side effects:

import contextlib

@contextlib.contextmanager
def my_nice_context():
    try:
@uucidl
uucidl / 00ctztree.md
Last active December 22, 2020 08:31
Octave Tree

CTZTree

A tree can be produced by counting the number of trailing zeros from an input integer index.

This count ('c') of trailing zeros (or position of the lowest bit) comes back every 2^c sample, i.e. corresponds to a frequency of 2^-c

Furthermore every sample corresponds with one and only one octave.

@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.
@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 / 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 / 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 / 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 / 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

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?

#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" : ", ");
} }
}