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 Enchainer.Command do | |
| @callback do_call(term) :: {:ok, term} | {:error, term} | |
| @callback on_success(term, term) :: term | |
| @callback on_failure(term, term) :: term | |
| @callback on_revert(term) :: term | |
| defmacro __using__(_params) do | |
| quote do | |
| @behaviour Enchainer.Command |
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 Taskie do | |
| def pbump(n) do | |
| chunk_size = div(n, 10) | |
| 1..n | |
| |> Enum.chunk(chunk_size, chunk_size, []) | |
| |> Enum.map(fn(chunk) -> | |
| chunk | |
| |> Enum.map(fn(v) -> Task.async(fn() -> Process.sleep(1000); bump(v) end)end) | |
| |> Enum.map(fn(t) -> Task.await(t) 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
| defmodule CoffeeFsm do | |
| @name :coffee_fsm | |
| @timeout 30_000 | |
| def start_link do | |
| :gen_fsm.start_link({:local, @name}, __MODULE__, [], []) | |
| end | |
| def init([]) do | |
| Hw.reboot() |
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 CoffeeMachine do | |
| @name :coffee_machine | |
| def start_link do | |
| spawn_link(__MODULE__, :init, []) | |
| end | |
| def init do | |
| Process.register(self, @name) | |
| Hw.reboot() |
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 MyDb do | |
| ## Public API | |
| def start do | |
| pid = spawn(__MODULE__, :init, []) | |
| Process.register(pid, :my_db) | |
| {:ok, pid} | |
| end | |
| def stop, do: cast(:stop) |
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 MutexTest do | |
| use ExUnit.Case, async: false | |
| doctest Mutex | |
| setup do | |
| Mutex.start | |
| on_exit fn -> | |
| Mutex.stop | |
| 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
| defmodule Db do | |
| def new, do: [] | |
| def destroy(_db), do: :ok | |
| def write([], key, element) do | |
| [{key, element}] | |
| end | |
| def write([{key, _value} | db], key, element) do | |
| [{key, element} | db] |
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 Frequency do | |
| def start() do | |
| pid = spawn(Frequency, :init, []) | |
| Process.register(pid, :frequency) | |
| end | |
| def init() do | |
| frequencies = {get_frequencies(), []} | |
| loop(frequencies) |
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 ProcessRing do | |
| @moduledoc """ | |
| Documentation for ProcessRing. | |
| """ | |
| def start(name) do | |
| spawn(ProcessRing, :init, [name]) | |
| end | |
| def init(name) 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
| # HI! I'm Ju. You can find me online as @arkh4m | |
| # Download Sonic PI here: http://sonic-pi.net | |
| def p(note, s: 1) | |
| play note, release: s, cutoff: rrand(80,110) | |
| sleep s | |
| end | |
| def fra_martino |