Origin: https://appunite.com/blog/let-the-force-be-with-livebook
Save this as .livemd and open with running Livebook server to evaluate.
| defmodule Clusty.Application do | |
| use Application | |
| @topologies local_epmd: [strategy: Cluster.Strategy.LocalEpmd] | |
| @impl true | |
| def start(_type, _args) do | |
| children = [ | |
| {Cluster.Supervisor, [@topologies, [name: ClusterSupervisor]]}, | |
| Pidgy |
| Mix.install([:benchee]) | |
| defmodule Proteins do | |
| @stop "STOP" | |
| @err_msg "invalid codon" | |
| @codons %{ | |
| "UGU" => "Cysteine", | |
| "UGG" => "Tryptophan", | |
| "UUU" => "Phenylalanine", |
| name: Elixir CI | |
| on: | |
| push: | |
| branches: ["master"] | |
| pull_request: | |
| branches: ["master"] | |
| env: | |
| MIX_ENV: test |
| Mix.install([ | |
| {:benchee, "~> 1.0"} | |
| ]) | |
| defmodule Cruncher do | |
| def async(n) do | |
| 1..n | |
| |> Task.async_stream(&(&1 ** 2)) | |
| |> Enum.reduce(0, fn {:ok, s}, acc -> s + acc end) | |
| end |
| Mix.install([ | |
| {:benchee, "~> 1.0"} | |
| ]) | |
| defmodule BirdCond do | |
| def busy_days(list) do | |
| cond do | |
| list == [] -> 0 | |
| hd(list) < 5 -> busy_days(tl(list)) | |
| true -> 1 + busy_days(tl(list)) |
| # Origin: https://blog.sequin.io/how-we-used-elixirs-observer-to-hunt-down-bottlenecks/ | |
| defmodule Overload do | |
| # Define a CPU-intenstive work function, which can call itself | |
| # recursively (forever) | |
| def recursive do | |
| :public_key.generate_key({:rsa, 4096, 65537}) | |
| recursive() | |
| end | |
| end |
| % Read more: | |
| % - https://joearms.github.io/published/2013-11-21-My-favorite-erlang-program.html | |
| % - https://ferd.ca/my-favorite-erlang-container.html | |
| % | |
| % How to run: | |
| % $ erl | |
| % > c(uni). | |
| % {ok,uni} | |
| % > uni:test(). | |
| % 30414093201713378043612608166064768844377641568960512000000000000 |
Origin: https://appunite.com/blog/let-the-force-be-with-livebook
Save this as .livemd and open with running Livebook server to evaluate.
| defmodule Reader do | |
| defmodule SensorHub do | |
| @moduledoc """ | |
| Opens the first I2C bus ("i2c-1") and reads from SensorHub device address (0x17). | |
| Updates its internal state periodically (every second in the example below). | |
| Below you can find a table of registers, that we found on their website: | |
| https://wiki.52pi.com/index.php/DockerPi_Sensor_Hub_Development_Board_SKU:_EP-0106 |
| `sudo purge` | |
| memory_by_process = Hash.new(0) | |
| processes = `ps aux` | |
| m_bytes = processes.split("\n").reduce(0) { |memo, prc| | |
| fields = prc.split(/\s+/) | |
| mem_bytes = fields[5].to_i | |
| prc_name = fields[10...fields.length].join(' ') |