Skip to content

Instantly share code, notes, and snippets.

View jaeyson's full-sized avatar
🎯
Focusing

Jaeyson Anthony Y. ⚗️ jaeyson

🎯
Focusing
View GitHub Profile
@lucian
lucian / mostly-erlang-019-elixir-with-jose-valim-20131007.txt
Last active April 10, 2024 20:05
transcript for Mostly Erlang - episode 019 Elixir With José Valim / October 7, 2013
# --------------------------------------------------------------------------------------------
# Mostly Erlang - episode 019 Elixir With José Valim / October 7, 2013
#
# guests:
# - Joe Armstrong (@joeerl)
# - Robert Virding (@rvirding)
# - Jose Valim (@josevalim)
# - Fred Hebert (@mononcqc)
# - Eric Merit (@ericbmerritt)
#
defmodule MarkdownConverter do
import Phoenix.Component
def convert(filepath, body, _attrs, opts) do
convert_body(Path.extname(filepath), body, opts)
end
defp convert_body(extname, body, opts) when extname in [".md", ".markdown", ".livemd"] do
html =
Earmark.as_ast!(body, annotations: "%%")
@mxgrn
mxgrn / lv_modal_close_confirm.md
Last active June 15, 2024 14:18
LiveView modal close confirmation on dirty form
@29decibel
29decibel / livemd
Last active December 27, 2023 09:45
Extract donimant colors using dominant_colors in Elixir Livebook
# Extract dominant colors from image
```elixir
Mix.install([
{:kino, "~> 0.11.3"},
{:dominant_colors, "~> 0.1.4"}
])
```
defmodule SchemaChecker do
def find_field_discrepancies do
schema_modules()
|> Enum.map(fn mod ->
{mod.__schema__(:source), check_module(mod)}
end)
end
defp schema_modules do
{:ok, modules} = :application.get_key(:core, :modules)
@T-Dark0
T-Dark0 / what_as_does.md
Last active June 29, 2025 08:56
What `as` does

as does a huge number of things. Probably too many. Here's a comprehensive list of everything it can do. Entries in italics are the names of functions that actually exist in the standard library, while all entries attempt to have a descriptive name for what a function that does the same thing as that particular as would do.

  • int <-> int
    • zero_extend: unsigned int -> bigger unsigned int. Pads the number with leading zeroes. This preserves the numeric value.
    • sign_extend: signed int -> bigger signed int. Pads the number with leading zeroes if positive, and leading ones if negative. This preserves the numeric value.
    • truncate: bigger int -> smaller int (regardless of signedness). Throws away the high bits of the number.
    • reinterpret_sign: int -> int of the same size and opposite signedness. Does nothing to the bits.
  • int <-> float
  • cast_saturate_to_infinity: Yields the float closest to the specified integer. Yields infinity if the integer is out of boun
@epfahl
epfahl / unification.ex
Last active March 9, 2025 21:11
Unification algorithm in Elixir.
# Discussed in https://www.ericpfahl.com/from-pattern-matching-to-unification/
defmodule Var do
alias Var
@type t :: %Var{id: any}
defstruct [:id]
@spec new(any) :: Var.t()
def new(id), do: %Var{id: id}
@LostKobrakai
LostKobrakai / form_live.ex
Last active June 3, 2025 14:28
Phoenix LiveView form with nested embeds and add/delete buttons
defmodule NestedWeb.FormLive do
use NestedWeb, :live_view
require Logger
defmodule Form do
use Ecto.Schema
import Ecto.Changeset
embedded_schema do
field :name, :string
@PJUllrich
PJUllrich / big-o.md
Last active May 28, 2025 20:29
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for <= 32 elements, O(log n) for > 32 elements [2]
Deletion O(n) for <= 32 elements, O(log n) for > 32 elements