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
import { useCallback, useEffect, useMemo, useState } from 'react'; | |
import dayjs, { Dayjs, duration } from 'dayjs'; | |
import { Duration } from 'dayjs/plugin/duration'; | |
type Status = 'idle' | 'running' | 'paused'; | |
type TimerState = { | |
status: Status; | |
startedAt: Dayjs | null; | |
elapsed: Duration; |
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([ | |
{:bandit, "~> 1.6"}, | |
{:phoenix, "~> 1.7.0"}, | |
{:phoenix_live_view, "~> 1.0.10"}, | |
{:phoenix_ecto, "~> 4.6"}, | |
{:ecto_sql, "~> 3.12"}, | |
{:postgrex, ">= 0.0.0"}, | |
{:testcontainers, "~> 1.12"} | |
]) |
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 TermStorage do | |
use Task | |
def start_link(args \\ []) do | |
Task.start_link(fn -> | |
table_name = Keyword.get(args, :table_name, __MODULE__) | |
{:ok, _table} = :dets.open_file(table_name, auto_save: to_timeout(second: 1)) | |
Process.hibernate(Function, :identity, [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([:dataloader, :absinthe]) | |
defmodule User do | |
defstruct [:id, :name] | |
def get(id) do | |
Enum.find(list(), &(&1.id == id)) | |
end | |
def list do |
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([:dataloader]) | |
defmodule User do | |
defstruct [:id, :name] | |
def list do | |
[ | |
%__MODULE__{id: 1, name: "John"}, | |
%__MODULE__{id: 2, name: "Alice"}, | |
%__MODULE__{id: 3, name: "Bob"} |
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 MySQL do | |
defmacro __using__(_opts \\ []) do | |
quote do | |
defoverridable insert_all: 3 | |
def insert_all(schema_or_source, entries, opts) when is_list(entries) do | |
{returning, opts} = Keyword.pop(opts, :returning) | |
if returning do | |
import Ecto.Query |
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 Queue do | |
defstruct value: :queue.new() | |
def new do | |
%Queue{} | |
end | |
def new(enumerable) do | |
list = Enum.to_list(enumerable) | |
%Queue{value: :queue.from_list(list)} |
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 Test do | |
def str_to_int(str) do | |
Enum.reduce(String.to_charlist(str), 0, &(&1 - ?0 + &2 * 10)) | |
end | |
end |
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([ | |
{:ecto_sql, "~> 3.11"}, | |
{:myxql, "~> 0.6.4"}, | |
{:testcontainers, "~> 1.8"} | |
]) | |
alias Testcontainers.MySqlContainer | |
{:ok, _} = Testcontainers.start_link() | |
{:ok, container} = Testcontainers.start_container(MySqlContainer.with_image(MySqlContainer.new(), "mysql:8.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
defmacro delegate_functions_for(module, functions) do | |
for {fun_name, fun_arity} <- functions do | |
fun_args = Macro.generate_arguments(fun_arity, Macro.expand_literals(module, __CALLER__)) | |
quote do | |
defdelegate unquote(fun_name)(unquote_splicing(fun_args)), to: unquote(module) | |
end | |
end | |
end |
NewerOlder