Skip to content

Instantly share code, notes, and snippets.

@cloud8421
cloud8421 / ai-server.md
Last active July 17, 2026 05:36
Atuin AI Server review

Revision: https://github.com/atuinsh/atuin-ai-server/commit/63329e065dc73f2f6af8270928c003525c1befe1

Router - Tracking duration

Instead of diffing times, one can use :timer.tc/1 to track duration. Even better, one could use :telemetry.span/3 to track duration and publish a metric.

Router - State management

Instead of doing State.get/0 inside the body of each route, resolving the state can be moved to a separate plug invoked before routes are matched, and stored into a assign. This simplifies testing, as it removes state from the body of the route.

@cloud8421
cloud8421 / Ci.yml
Created December 19, 2024 12:57
GitHub CI with Fly deploy
name: Test & Deploy
on: push
jobs:
test:
name: Test
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
@cloud8421
cloud8421 / README.md
Last active January 4, 2017 14:11
JSON schema based validator with automatic code and docs generation

This module requires the following dependencies:

    [{:ex_doc, "~> 0.14.3", only: :dev},
     {:poison, "~> 3.0"},
     {:ex_json_schema, "~> 0.5.2"}]

Note that ex_doc is optional as you can still use iex-based documentation.

@cloud8421
cloud8421 / rebar.lock
Created September 15, 2016 10:18
Rebar.lock diff
diff --git a/rebar.lock b/rebar.lock
index 1c484c5..ce009d3 100644
--- a/rebar.lock
+++ b/rebar.lock
@@ -3,17 +3,14 @@
{<<"cowboy_swagger">>,{pkg,<<"cowboy_swagger">>,<<"1.1.0">>},1},
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.2">>},2},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.8">>},3},
- {<<"iso8601">>,{pkg,<<"inaka_iso8601">>,<<"1.1.2">>},1},
+ {<<"inaka_iso8601">>,{pkg,<<"inaka_iso8601">>,<<"1.1.2">>},1},
@cloud8421
cloud8421 / ms_test.exs
Created August 10, 2016 14:38
Maps and match specs in elixir
defmodule MsTest do
use ExUnit.Case
doctest Ms
@bob %{name: "Bob", job: "developer"}
@alice %{name: "Alice", job: "musician"}
@john %{name: "John", job: "musician"}
@ada %{name: "Ada", job: "developer"}
@alan %{name: "Alan", job: "developer"}
@table :users

A few considerations in case you need to work on performance even further (you may not even need them, but it's worth knowing).

  • Using the GenServer flow to read data may become a bottleneck (as it happens inside the GenServer process)
  • If you don't care about duplicates, you may set the table as duplicate_bag. This speeds up writes, as it doesn't have to check for dupes.

It may also be interesting to read directly from the table instead of going through the GenServer. That's possible by creating the table as public and named_table, giving it __MODULE__ as name. In addition, as the table would be mostly reads, it can be marked as read_concurrency (which optimizes reads over writes).

ets.new(__MODULE__, [:named_table, :duplicate_bag, :public, :read_concurrency])

@cloud8421
cloud8421 / README.md
Last active September 9, 2015 12:38
Docker shell helpers

This assumes a working copy of in your PATH

@cloud8421
cloud8421 / ideas.md
Last active August 29, 2015 14:19
Elixir libraries/apps ideas

Tcp client pool

A generic tcp client pool. You give it a protocol to use to decode/encode messages and it handles connection management for you, including reconnecting, closing, maintaining connections. The use case is to provide a solid infrastructure to connect to tcp services like memcached, redis, etc.

Web based observer

A deployable observer application that can target a node or self and provides the same information (or better) as the native observer gui

Real time load heatmap

A tool capable of generatic a heatmap of running processes, where color shows the inbox length for each process. Useful to find bottlenecks (can also be part of the web observer).

Pluggable Logger reporting tools

@cloud8421
cloud8421 / count
Created April 22, 2015 13:40
Count query in Ecto
# Given a Message model with a body column
from(m in Message, select: count(m.body)) |> Repo.one
@cloud8421
cloud8421 / query.sql
Created March 5, 2015 10:19
yesql problematic query
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc -> 'tags' ? 'qui';