Philmont Diary

In the summer of 1978 I got to join other members of Boy Scout Troop 73 of Beaver, Ohio, on a backpacking trip to Philmont Scout Ranch in New Mexico. I took notes. Here they are.

Read more…

Portugal 2025

In April of 2025, Bobi and I traveled to Portugal to visit friends and see the country. These are my notes from the trip.

At the beach with Rick and Laura
At the beach with Rick and Laura

Read more…

Fractional Indexing

A couple of years ago I built a macOS/iOS data logging app for personal use. When I started work on it, I considered using a bespoke server and CRDTs to maintain data consistency among instances of the app. It was fun to learn the basics of CRDTs and to build a few prototypes. But I'm lazy, so I ended up using CloudKit.

Sometimes I come across a blog post that makes me wish I'd pursued the server + CRDT approach. Today the trigger was Bartosz Sypytkowski's Non-interleaving Linear Sequence (LSeq) CRDT.

Read more…

Custom validation messages w. Svelte

Example.svelte

<script lang="ts">
let control: HTMLInputElement
function validate() {
    if (control.validity.valueMissing) {
        control.setCustomValidity('Please provide a date of birth.')
    }
}
<script>
<input
  type="date"
  bind:this="{control}"
  required
  on:invalid="{validate}"
  on:change="{validate}"
  on:input="{validate}"
  title="A required input" />
<style>
  *:required::after {
    font-size: 125%;
    vertical-align: top;
    content: '*';
    color: red;
  }
</style>

Result

Testing SwiftUI Tables

I maintain a macOS SwiftUI app whose user interface contains a Table, one with a bound sortOrder.

The app's Xcode project contains UI tests that exercise the sorting logic, by clicking on the column headers. These tests are really fragile. Odds are good that any new release of macOS, or Xcode, or SwiftUI, will break them.

I'm not sure why they're so fragile. I suspect the way SwiftUI generates the underlying view hierarchy for a Table may still be in flux.

In any case, here is what I'm currently using to click on the column headers of a SwiftUI Table. This is for macOS 13.1, Xcode 14.2, Swift 5.7, SwiftUI 4.2.11.

    private func clickTableColumnHeaders(tableEl: XCUIElement) {
        for column in tableEl.tableColumns.allElementsBoundByIndex {
            let height = column.frame.height
            // Assume the column header lies above the column.
            let y = CGFloat(-10.0)
            let offset = CGVector(dx: 0.5, dy: y / height)
            let coords = column.coordinate(withNormalizedOffset: offset)
            // Click twice to exercise both sort orders.
            coords.click()
            coords.click()
        }
    }

Svelte's Take on ObservableObject

SwiftUI's ObservableObject and @Published make it easy to group related properties into a single class, and to react to changes of individual properties.

I recently complained to my friend, Bobi, that Svelte seemed lacking in this regard. Its tutorials always show components whose exportable state is defined by separate, top-level variable declarations.

    let count = 0;

    $: if (count >= 10) {
        alert('count is dangerously high!');
        ...

She set me straight: if you want to group related, observable properties, just use a writable store whose value is an Object (or if you prefer, a class instance). Whenever any property is changed, interested parties react automatically.

Read more…