Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bun
"use strict";
const fs = require("fs");
const { execSync } = require("child_process");
const path = require("path");
// ANSI color constants
const c = {
cy: '\033[36m', // cyan

The Ultimate Guide to Gleam's Typed Actors

How Gleam builds type-safe concurrent programming on the BEAM

The BEAM virtual machine (which runs Erlang, Elixir, and now Gleam) is renowned for its actor model concurrency. But traditionally, message passing has been untyped - any process can send any message to any other process, leading to runtime crashes when unexpected messages arrive.

Gleam changes this game entirely by building a sophisticated type-safe layer on top of BEAM's primitives. In this deep dive, we'll explore exactly how Gleam achieves compile-time type safety for concurrent programming, revealing the elegant implementation strategies that make it all work.

The Foundation: BEAM Processes and Raw Message Passing

defmodule Task do
defp await_one(tasks, timeout \\ 5_000) when is_list(tasks) do
awaiting =
Map.new(tasks, fn %Task{ref: ref, owner: owner} = task ->
if owner != self() do
raise ArgumentError, invalid_owner_error(task)
end
{ref, true}
end)
@thmsmlr
thmsmlr / elixir-coding-guidelines.mdc
Created May 25, 2025 15:05
My cursorrules for elixir coding styles
When writing Elixir code, perfer the following style guidlines:
1. Elixir developers tend to create many small functions in their modules. I DO NOT LIKE THIS. Instead create functions that fully capture a conceptual task, even if it makes that function longer. A good rule of thumb is, if a private function is only called once within a module, it should've been inlined.
For example:
DON'T DO THIS:
```elixir
@steipete
steipete / terminator.scpt
Last active May 22, 2025 08:21
Hasta la *vista, shell — the T-800 that babysits (and occasionally obliterates) your Terminal tabs. Built to kill hung jobs, not humans. Helps Cursor to keep the loop! Copy this into .cursor/scripts/terminator.scpt (or similar) and point Cursor/Windsurf to that file and prompt it with the comment below.
Moved to https://github.com/steipete/Terminator
@thmsmlr
thmsmlr / wait_for.ex
Created December 26, 2024 21:20
ExUnit helper function to wait up to a timeout to determine whether a set of assertions completes. Perfect for testing async code
@default_timeout 100
@check_interval 10
# Test Helpers
defp wait_for(fun, timeout \\ @default_timeout) do
start_time = System.monotonic_time(:millisecond)
ref = make_ref()
try do
Mix.install(
[
{:phoenix_playground, "~> 0.1.0"},
{:openai, "~> 0.6.1"},
{:makeup, "~> 1.1.2"},
{:makeup_elixir, "~> 0.14"}
],
config: [
openai: [
api_key: System.get_env("OPENAI_API_KEY"),
@nyku
nyku / resize_convert.sh
Last active August 1, 2024 22:38
Resize & Convert image -> webp
#!/bin/bash
# Usage:
# ./resize_and_convert.sh ~/Desktop/folder-with-images
# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 source_path"
exit 1
fi
@aeons
aeons / config.exs
Last active April 1, 2025 00:33
Erlang 27 :json module in Phoenix
config :phoenix, :json_library, ErlJson
@rsms
rsms / macos-distribution.md
Last active July 11, 2025 06:35
macOS distribution — code signing, notarization, quarantine, distribution vehicles