Skip to content

Instantly share code, notes, and snippets.

View derrh's full-sized avatar

Derrick Hathaway derrh

View GitHub Profile
@derrh
derrh / you_couldve_invented_openclaw.md
Created February 12, 2026 02:50 — forked from dabit3/you_couldve_invented_openclaw.md
You Could've Invented OpenClaw

What makes OpenClaw powerful is surprisingly simple: it's a gateway that connects an AI agent to your messaging apps, gives it tools to interact with your computer, and lets it remember who you are across conversations.

The complexity comes from handling multiple channels simultaneously, managing persistent sessions, coordinating multiple agents, and making the whole thing reliable enough to run 24/7 on your machine.

In this post, I'll start from scratch and build up to OpenClaw's architecture step by step, showing how you could have invented it yourself from first principles, using nothing but a messaging API, an LLM, and the desire to make AI actually useful outside the chat window.

End goal: understand how persistent AI assistants work, so you can build your own.

First, let's establish the problem

@derrh
derrh / SwiftUI+GraphQL.md
Created October 16, 2023 19:53
GraphQL + SwiftUI: Declarative Data and Declarative UI

Imagining what the future might be like with direct support for GraphQL in SwiftUI.

Rationale

SwiftUI and GraphQL both represent new paradigms, these new paradigms—when paired together—offer an unparalleled, streamlined, client development experience. Today the most widely used and robust Swift GraphQL clients lack direct SwiftUI support, as well as support for #8 and #9 of Jordan Eldridge's "GraphQL Maturity Model".

Goals

  • Each View declares it's data requirements using Fragments
  • Each View observes it's fragment data from the GraphQL normalized cache, limiting large-tree re-renders
  • Sensible defaults for cache policies and other configuration cover most cases, but can be overridden in intuitive ways
  • As Views are decomposed into subviews, queries are decomposed into fragments
type RouteLeaf = string | number | bigint | boolean | null | undefined
// there's probably a tidier way to get around TS's lack of support for recursive `type`'s
type RouteBranch<SubBranch = RouteLeaf> = Record<string | number | symbol, RouteLeaf | SubBranch>
type RouteComponent =
| RouteLeaf
| RouteBranch<RouteBranch>
| RouteBranch<RouteBranch<RouteBranch>>
| RouteBranch<RouteBranch<RouteBranch<RouteBranch>>>
| RouteBranch<RouteBranch<RouteBranch<RouteBranch<RouteBranch>>>>
@derrh
derrh / Interview.tsx
Created January 7, 2020 17:07
Device Orientation
import React from 'react';
import { Orientation } from 'react-native-device-orientation';
// Orientation.addSubscriber(callback: (orientation: 'portrait' | 'landscape') => {})
// Orientation.removeSubscriber(callback)
@derrh
derrh / Optional.swift
Created May 2, 2018 23:32
Hello, Silicon Slopes!
func format(date: Date) -> String { ... }
let dueDate = Date?
print("""
Assignment
--
due: \(dueDate.map(format(date:)) ?? "none")
"""
@derrh
derrh / PolymorphicValueTypes.swift
Created December 13, 2016 06:06
Polymorphism with Swift Value Types: Mind Blown
protocol Thing {
func foo()
}
extension Thing {
func foo() {
print("just a thing")
}
}
Process: carthage [25835]
Path: /usr/local/bin/carthage
Identifier: carthage
Version: 0
Code Type: X86-64 (Native)
Parent Process: bash [21316]
Responsible: Terminal [21310]
User ID: 1745180192
Date/Time: 2015-05-26 10:54:31.718 -0600
//
// NSManagedObjectContext+Project.swift
//
// Created by Derrick Hathaway on 2/22/15.
// Copyright (c) 2015 The Best Bits LLC.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
import UIKit
func +<A,B>(lhs: [A:B], rhs: [A:B]) -> [A:B] {
var dict : [A:B] = [:]
for (key, value) in lhs {
dict[key] = value
}
for (key, value) in rhs {
dict[key] = value
@derrh
derrh / CategoryProperty.h
Created June 25, 2013 20:21
Synthesize + objc_get/setAssociatedObject
#import <objc/runtime.h>
#define SYNTHESIZE(class, getter, setter) \
static const void *getter##PropertyKey = &getter##PropertyKey;\
- (type *)getter { \
return objc_getAssociatedObject(self, getter##PropertyKey); \
} \
\
- (void)setter:(class *object) { \
objc_setAssociatedObject(self, getter##PropertyKey, object, OBJC_ASSOCIATION_RETAIN);\