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 LogLevel do | |
def to_label(level, legacy?) do | |
cond do | |
level == 0 and not legacy? -> :trace | |
level == 1 -> :debug | |
level == 2 -> :info | |
level == 3 -> :warning | |
level == 4 -> :error | |
level == 5 and not legacy? -> :fatal | |
true -> :unknown |
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 Rates do | |
def daily_rate(hourly_rate) do | |
hourly_rate * 8.0 | |
end | |
def apply_discount(before_discount, discount) do | |
before_discount * (100 - discount) / 100 | |
end | |
def monthly_rate(hourly_rate, discount) 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
defmodule Rules do | |
def eat_ghost?(power_pellet_active, touching_ghost) do | |
power_pellet_active and touching_ghost | |
end | |
def score?(touching_power_pellet, touching_dot) do | |
touching_power_pellet or touching_dot | |
end | |
def lose?(power_pellet_active, touching_ghost) 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
defmodule Benchmarker do | |
def run(title, module, function, size \\ 1024, iterations \\ 100) do | |
times = for (_ <- 1 .. iterations) do | |
data = :crypto.strong_rand_bytes(size) | |
{duration, _value} = :timer.tc fn -> | |
apply(module, function, [data]) | |
end | |
duration | |
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
import fs from "fs"; | |
import path from "path"; | |
/** | |
* Recursively read all files in a directory. | |
* @param {fs.PathLike} dirPath The path to the directory that will be recursively traversed. | |
* @param {Array} arrayOfFiles The array that all files will be recursively pushed to. | |
* @returns Returns an array of files. | |
*/ |
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
-module(spam_pids). | |
-export([main/0]). | |
main() -> | |
Pids = lists:map(fun(_) -> spawn(fun() -> ok end) end, lists:seq(1, 1000)), | |
lists:foreach(fun(Pid) -> exit(Pid, normal) end, Pids). |
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
-module(list_sort). | |
-export([main/0]). | |
main() -> | |
L = lists:map(fun(_) -> rand:uniform(1000) end, lists:seq(1, 1000)), | |
Sorted = bubble_sort(L), | |
io:format("~p~n", [Sorted]). | |
bubble_sort(L) -> | |
bubble_sort(L, []). |
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
-module(ids). | |
-export([main/0]). | |
main() -> | |
Pid = spawn(fun() -> | |
Ids = lists:map(fun(_) -> rand:uniform(1000) end, lists:seq(1, 1000)), | |
io:format("~p~n", [lists:sort(Ids)]) | |
end), | |
exit(Pid, normal). |
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
select | |
left(md5(i::text), 10), | |
md5(random()::text), | |
md5(random()::text), | |
left(md5(random()::text), 4) | |
from generate_series(1, 1000000) s(i); |
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 Web.MainController do | |
use YourWeb, :controller | |
@moduledoc """ | |
Triggered once a user enters the basic url, without endpoint. | |
Automatically redirects to the given URL. | |
""" | |
@github_url "https://github.com/vKxni" |