Skip to content

Instantly share code, notes, and snippets.

@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 ->
@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 / 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 / day16.ex
Created December 16, 2021 22:33
defmodule Aoe.Y21.Day16 do
alias Aoe.Input, warn: false
@type input_path :: binary
@type file :: input_path | %Aoe.Input.FakeFile{}
@type part :: :part_one | :part_two
@type input :: binary | File.Stream.t()
@type problem :: any
require Record
@lud
lud / heat.exs
Last active November 16, 2022 10:21
Heat the computer
#!/usr/bin/env elixir
Mix.install([:jason])
defmodule Heater do
import Kernel, except: [spawn_link: 1]
def spawn_link() do
Kernel.spawn_link(fn -> init() end)
end
@lud
lud / heat.exs
Last active January 21, 2021 09:52
defmodule Heater do
import Kernel, except: [spawn_link: 1]
def spawn_link() do
Kernel.spawn_link(fn -> init() end)
end
defp init() do
send(self(), :heat)
loop_idle()
@lud
lud / demo.ex
Created July 29, 2020 07:12
Elixir uppercase constants with macros
defmodule Constants.Compiler do
@moduledoc false
defmacro __using__(_) do
quote do
Module.register_attribute(__MODULE__, :const_def, accumulate: true)
import unquote(__MODULE__), only: [const: 2]
@before_compile unquote(__MODULE__)
end
end
---
Disease-it:
url: "http://disease-it.jeuweb.org/"
image: "https://img.itch.zone/aW1nLzMxMTA5ODQucG5n/original/zO55Li.png"
description:
email: [email protected]
id_thread: 12568
"L'ile du coeur":
url: http://www.ile-du-coeur.com/
defmodule Day4 do
def run(range_str) do
[from, to] =
range_str
|> String.split("-")
|> Enum.map(&String.to_integer/1)
Range.new(from, to)
|> Stream.map(&to_charlist/1)
|> Stream.filter(&has_increasing_digits/1)
@lud
lud / update-spatial-indexes.sql
Created June 19, 2014 15:18
Recreate Oracle Spatial indexes
DECLARE
TYPE curs IS REF CURSOR;
c curs;
q varchar2(200);
idx VARCHAR(200);
tab VARCHAR(200);
col VARCHAR(200);
BEGIN
q := 'select index_name,table_name,column_name from user_sdo_index_info';
OPEN c FOR q;