Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / playwright.ex
Created April 21, 2026 22:25
Simple Elixir Playwright integration
defmodule Integration.Playwright do
@moduledoc """
Runs Playwright scripts with sandbox metadata injection.
Uses a persistent browser server for efficiency - browser contexts are cheap
(~50ms) while browser launches are expensive (~1-2s).
## Setup
Call `Playwright.start()` once in integration/test_helper.exs.
@ityonemo
ityonemo / browser_case.ex
Created March 16, 2026 20:55
integration browser case
defmodule Integration.BrowserCase do
@moduledoc """
This module defines the setup for browser integration tests.
It sets up the Ecto sandbox and provides sandbox metadata to Playwright
so browser requests can share the test transaction.
Tests using this module must be tagged with `@moduletag :integration`.
"""
@ityonemo
ityonemo / playwright.ex
Created March 16, 2026 20:27
Elixir - Async playwright "integration" testing
defmodule Integration.Playwright do
@moduledoc """
Runs Playwright scripts with sandbox metadata injection using MuonTrap.
MuonTrap ensures Node/Playwright processes are killed when tests exit.
## Usage
Include `userId` in the context to automatically authenticate before running the script:
Playwright.run!(~S\"""
@ityonemo
ityonemo / wishlist.md
Created September 8, 2024 18:33
Ziglang Wishlist

We're currently using ziglang in-prod at https://positron.ai.

Uses the zigler package to interface with elixir for robust and resilient layer on top of unreliable and pre-alpha grade hardware (talk coming soon!).

We heavily use AVX-512 instructions for token picking. http://antirez.com/news/142 and we use a highly optimized sorter in place of what you would see in that code (np.argsort).

The plan is to move away from shipping fp32 values at the interface to shipping bf16 values, so bf16 support at the type-level in zig would be amazing. It seems like the ML industry has settled on

@ityonemo
ityonemo / numa_pages.zig
Last active August 30, 2024 16:50
numa - aware allocation in zig
const std = @import("std");
const posix = std.posix;
const numaif = @cImport({
@cInclude("numaif.h");
@cInclude("errno.h");
});
extern threadlocal var errno: c_int;
fn numa_alloc(size: usize, node: ?u1) ![]align(std.mem.page_size) u8 {
@ityonemo
ityonemo / enterprise_curl.exs
Last active August 25, 2024 12:57
Enterprise LibCurl with Zigler
Mix.install([
{:zigler, "~> 0.13"}
])
Logger.configure(level: :warning)
defmodule Main do
use Zig,
otp_app: :zigler,
c: [link_lib: {:system, "curl"}],
@ityonemo
ityonemo / improver.ex
Created December 1, 2023 00:04
Some crazy shit I wrote using EEx + GPT
defmodule RockE.DynamicImprover do
alias OpenAI
require EEx
EEx.function_from_string(:defp, :prompt, """
<% assigns = Map.from_struct(round) %>
Hi ChatGPT! I'm trying to prompt ChatGPT 3.5 to perform a function call.
However, the function call often makes mistakes in the passed argument:
The current accuracy is <%= @accuracy %> I'd love to see the accuracy go up to 90%.
@ityonemo
ityonemo / nx_ext.ex
Last active November 18, 2023 20:07
Floating point to GPTQ in Nx
defmodule NxExt do
import Nx.Defn
@bitshift Nx.tensor([[1], [16]], type: {:u, 8})
@doc """
Takes an N-vector of floats (arbitrarily typed) and converts it into 4-bit gptq, which has
a range of -8..-7. Should be compacted into two "floats" per byte, with the lower indexed
value in the less significant nybble
@ityonemo
ityonemo / guide.md
Last active September 15, 2023 20:41
Elixir-Guide

Elixir Guide

This guide is a quick set of guidelines for reading or writing elixir code. It's designed to get you through stuff that is different from Elixir relative to other programming languages you might be used to, and which you might miss while learning elixir.

Up and running

Linux

defmodule Aaa do
# terminal condition. If we've gotten through the whole pattern we're done.
def matches(<<>>, <<>>), do: true
# If the first character matches and has a question mark we must make an
# epsilon transition. We have to try both "universes". In one "universe"
# we proceed as if we consumed the optional match, and the other we proceed
# as if we didn't. The success of either means the match succeeds. This
# means for this branch we don't get TCO =( but this should be relatively rare.
def matches(<<char, ??, rest1 :: binary>>, string = <<char, rest2 :: binary>>) do