This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Demonstrates that PostgreSQL's 1600-column-per-table limit also counts | |
| # DROPPED columns: attribute numbers are never reused, so repeatedly | |
| # adding and dropping a column eventually makes ALTER TABLE ... ADD COLUMN fail. | |
| # | |
| # Run: docker compose up -d && elixir postgres_limiter.exs | |
| # | |
| # compose.yml: | |
| # services: | |
| # postgres: | |
| # image: 'postgres:17.4' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Recursively fetch & rebase all git repos under a directory. | |
| # | |
| # Usage: git-update-all.sh [directory] | |
| # | |
| # If no directory is given, the current working directory is used. Repos are | |
| # discovered up to MAX_DEPTH levels deep (default: 2). Both normal repositories | |
| # and linked worktrees (created with `git worktree add`) are discovered. | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function tin | |
| if not set -q TMUX | |
| echo "Error: not in a tmux session. Please run tmux first." | |
| return 1 | |
| end | |
| set current_dir (pwd) | |
| # Split vertically first (creates bottom pane) | |
| tmux split-window -v -c "$current_dir" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S ERL_FLAGS=+B elixir | |
| Mix.install([{:httpoison, "~> 2.3"}]) | |
| defmodule Lights do | |
| import Config | |
| require Logger | |
| @selfname Path.basename(__ENV__.file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule PortsEx.Basic do | |
| use GenServer | |
| require Logger | |
| @command "./bin/long.rb" | |
| def start_link(opts \\ []), | |
| do: GenServer.start_link(__MODULE__, nil, opts) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule RegistryEts do | |
| use GenServer | |
| def register(key, pid \\ self()), | |
| do: GenServer.call(__MODULE__, {:register, key, pid}) | |
| def whereis(key) do | |
| case :ets.lookup(__MODULE__, key) do | |
| [{^key, pid}] -> pid | |
| _ -> nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mix.install([:benchee]) | |
| defmodule ResistorColor do | |
| @color_map %{ | |
| black: 0, | |
| brown: 1, | |
| red: 2, | |
| orange: 3, | |
| yellow: 4, | |
| green: 5, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mix.install([:benchee]) | |
| # Compare access times to the elements in a Tuple, a Map, or a List containers. | |
| # | |
| # At first, we generate some input that is being used in the access_* functions: | |
| # they go over each element and check if it is what we put there. One by one. | |
| defmodule Accessor do | |
| @elements_n 10_000 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mix.install([:benchee]) | |
| defmodule LuhnChecksum do | |
| defguard is_even(x) when rem(x, 2) == 0 | |
| def with_reverse(digits) do | |
| digits | |
| |> Enum.reverse() | |
| |> Enum.with_index(1) | |
| |> Enum.map(fn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mix.install([:benchee]) | |
| defmodule StringPerf do | |
| def concat([]), do: "" | |
| def concat([head | tail]), do: head <> concat(tail) | |
| def interpol([]), do: "" | |
| def interpol([head | tail]), do: "#{head}#{interpol(tail)}" | |
| def joiner(input), do: Enum.join(input, "") |
NewerOlder