This file contains 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
Assembly: https://discord.com/invite/Km5VzKj | |
Elixir: https://discord.gg/NzSUHekD3t | |
Ballerina: https://discord.com/invite/wAJYFbMrG2 | |
Beef: https://discord.gg/rnsc9YP | |
Backlang: https://discord.com/invite/36SsV3vy4p | |
Caramel: https://discord.com/invite/yvCcjNmCcY | |
Idris: https://discord.com/invite/YXmWC5yKYM | |
R: https://discord.gg/GfAzp8umH8 | |
Reason: https://discord.com/invite/reasonml | |
Ruby: https://discord.gg/mk7mBwadub |
This file contains 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 Binary do | |
def write(text, filename) do | |
binary = :erlang.term_to_binary(text) | |
File.write(filename, binary) | |
end | |
def read(filename) do | |
case File.read(filename) do | |
{:ok, binary} -> :erlang.binary_to_term(binary) | |
{:error, _reason} -> "The file does not exist." |
This file contains 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 TodoList do | |
use GenServer | |
@moduledoc """ | |
A TodoList add, list, find, update & remove. | |
""" | |
def start do | |
{:ok, state} = GenServer.start_link(__MODULE__, []) | |
state | |
end |
This file contains 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 Main do | |
def print, do: "Hello from Main" | |
end | |
defmodule Other do | |
defdelegate hello, to: Main, as: :print | |
end | |
IO.puts(Other.hello) |
This file contains 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 Number do | |
def format(input, separator \\ ",") do | |
prefix_size = rem(byte_size(input), 3) | |
{prefix, rest} = String.split_at(input, prefix_size) | |
segments = for <<chunk::binary-size(3) <- rest>>, do: chunk | |
Enum.join([prefix | segments], separator) | |
end | |
end |
This file contains 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 Utils.WordCount do | |
@doc """ | |
Count the number of words in the sentence. | |
Words are compared case-insensitively. | |
"hello there" | |
hello: 5 | |
friends: 7 | |
""" | |
@spec count(String.t()) :: map |
This file contains 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 Utils.SpaceAge do | |
@type planet :: | |
:mercury | |
| :venus | |
| :earth | |
| :mars | |
| :jupiter | |
| :saturn | |
| :uranus | |
| :neptune |
This file contains 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 BirdCount do | |
def today([]), do: nil | |
def today(list), do: hd(list) | |
def increment_day_count([]), do: [1] | |
def increment_day_count([h | t]), do: [h + 1 | t] | |
def has_day_without_birds?([]), do: false | |
def has_day_without_birds?([0 | _]), do: true | |
def has_day_without_birds?([_ | t ]), do: has_day_without_birds?(t) |
This file contains 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 Heart do | |
def first_letter(name) do | |
name | |
|> String.trim() | |
|> String.first() | |
end | |
def initial(name) do | |
name | |
|> first_letter() |
This file contains 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 KitchenCalculator do | |
def get_volume(volume_pair) do | |
elem(volume_pair, 1) | |
end | |
def to_milliliter({:milliliter, volume}), do: {:milliliter, volume} | |
def to_milliliter({:cup, volume}), do: {:milliliter, volume * 240} | |
def to_milliliter({:fluid_ounce, volume}), do: {:milliliter, volume * 30} | |
def to_milliliter({:teaspoon, volume}), do: {:milliliter, volume * 5} |
OlderNewer