Skip to content

Instantly share code, notes, and snippets.

View huw's full-sized avatar
🌸
gardening

huw huw

🌸
gardening
View GitHub Profile
@huw
huw / LocalAi.ts
Created October 27, 2023 09:18
Cloudflare Workers AI Local Polyfill
/**
* @file A polyfill for `@cloudflare/ai` that connects to live services in local environments via the Cloudflare API instead of direct bindings.
*
* This only implements embeddings for now, but could be expanded to other models just by extending the types (and adding streaming support).
*/
type ModelName = "@cf/baai/bge-small-en-v1.5" | "@cf/baai/bge-base-en-v1.5" | "@cf/baai/bge-large-en-v1.5";
interface AiTextEmbeddingsInput {
text: string | string[];
@huw
huw / README.md
Last active March 12, 2024 21:32
Remix, Sentry & Cloudflare Workers

How to integrate Remix, Sentry, and Cloudflare Workers (incl. tracing)

The code above is just a sample—I have adapted it from a production codebase and I can't guarantee it will work as-is. It's just here to illustrate what a solution should look like.

The main things you need to do to get everything hooked up are:

  1. Rewrite instrumentBuild to accept a passed-through Hub instance, rather than using getCurrentHub() (including, perniciously, in helper functions such as hasTracingEnabled())
  2. In server/index.ts, create a root transaction from the current route’s name and wrap the loaders and actions in spans via instrumentBuild.
  3. In root.tsx, pass through your tracing & baggage into the meta function.
  4. In root.tsx, include the current domain in tracePropagationTargets (because Remix fetchers will fetch from the entire URL rather than / root, which will confuse Sentry)
  5. (Remix v2) In root.tsx, create an ErrorBoundary component (with the v2_errorBoundary flag set if you're
@huw
huw / TypedDurableObjectStorage.ts
Created August 29, 2022 12:20
Typed Durable Object Storage
import type { Jsonify } from "type-fest";
// Define new storage types here and below and the storage below will automatically use them.
// prettier-ignore
type TypedDurableObjectStorageValue<Key extends string> = Jsonify<
| Key extends "simple" ? boolean : never
| Key extends "complex" ? { age: number } | { name: string } : never
| Key extends `template:type:known` ? number : never
| Key extends `template:type:${string}` ? string | number : never
>;
@huw
huw / README.md
Last active June 16, 2023 18:54
How to run Notion in desktop mode on iPadOS Safari

How to run Notion in desktop mode on iPadOS Safari

Since iPadOS 13, Notion should show in desktop mode on iPadOS Safari, which is more fully-featured and pretty much fine for touch/pointer input.

In case you're from Notion and reading this, the things I generally don't like about that interface are:

  • Animations are oddly laggy
  • Full-screen popover modal menus instead of popping over contextually
  • Less hover states
  • Larger UI elements (I don't personally need these since I use a trackpad)
  • Small missing features or different UI (in particular around the settings panel)
@huw
huw / LICENSE.md
Created November 21, 2021 05:15
iA Writer Variable Fonts (Woff2-compressed & Base64-converted for use with Obsidian)

iA Writer Typeface

Copyright © 2018 Information Architects Inc. with Reserved Font Name "iA Writer"

Based on IBM Plex Typeface

Copyright © 2017 IBM Corp. with Reserved Font Name "Plex"

License

@huw
huw / keybase.md
Last active September 4, 2015 14:07
keybase.md

Keybase proof

I hereby claim:

  • I am huw on github.
  • I am huw (https://keybase.io/huw) on keybase.
  • I have a public key whose fingerprint is 6A97 CFEE 1CB5 BEB4 D2F2 7B89 D70C 1F1A DB90 C8B7

To claim this, I am signing this object:

@huw
huw / runes.py
Last active March 16, 2024 00:42
import string
def find_position(char):
for set_num in range(len(table)):
if char in table[set_num]:
return set_num
return False
def forge_offsets(key, direction, offset):
if type(key) is str: