Skip to content

Instantly share code, notes, and snippets.

@lud
lud / oxford.exs
Created January 31, 2025 15:23
Oxford word scrambler
defmodule Tool do
def tokenize(str) do
tokenize(str, [], [], :whitespace)
end
@special_chars ~c"\"'.,;:!?()[]{} \n\t\r/\\*_@$“”"
def tokenize(<<c::utf8, rest::binary>>, token_acc, acc, :whitespace)
when c in @special_chars do
tokenize(rest, [c | token_acc], acc, :whitespace)
@lud
lud / demo.exs
Created July 10, 2025 21:28
Oaskit/JSV demo
# :jsv is automatically pulled with :oaskit but since we are going to use it,
# let's be explicit about the deps!
Mix.install(
[
{:oaskit, "~> 0.3"},
{:jsv, "~> 0.10"},
{:plug_cowboy, "~> 2.5"},
{:jason, "~> 1.0"},
{:phoenix, "~> 1.8.0-rc.3"}
@lud
lud / decode.exs
Created July 21, 2025 08:09
How to decode a Phoenix.Token manually
data = "hello"
salt = "foo"
token = Phoenix.Token.sign(PotsWeb.Endpoint, salt, data)
IO.inspect(token, limit: :infinity, label: "token")
# How to manipulate token to get back "hello" from it without using
# Phoenix.Token functions
decode_token = fn token ->