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
| box: trenpixster/elixir:1.2.5 | |
| services: | |
| - id: postgres | |
| env: | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_USER: postgres | |
| build: | |
| steps: |
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 SubarraySum do | |
| def run([], val), do: false | |
| def run([ _ | rest ] = arr, val) do | |
| run(arr, val, 0) || run(rest, val) | |
| end | |
| def run(_, val, val), do: true | |
| def run([], _val, _res), do: false | |
| def run(_, val, res) when(val < res), do: false |
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
| # ... | |
| def index(conn, params) do | |
| model = | |
| Enum.map(vendor_ids, fn(vendor_id) -> | |
| Task.async(fn() -> | |
| Cabs.find_with_fare(params, vendor_id) | |
| # [ %Cab{price: 1, distance: 2},..] | |
| # Does some calculation based on results from different tables. | |
| 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 Hydra do | |
| use GenServer | |
| def run(data) do | |
| {:ok, pid} = GenServer.start(__MODULE__, data, []) | |
| GenServer.cast(pid, :process) | |
| end | |
| def init(data) do | |
| {:ok, data} |
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 Foo do | |
| def find(word) do | |
| find(IO.getn(""), word, word) | |
| end | |
| def find(_char, "", word) do | |
| IO.puts "Found #{word}" | |
| end | |
| def find(char, << char :: binary-size(1), rest :: binary >>, word) 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 Prime do | |
| def run(number) do | |
| max = :math.sqrt(number) |> round | |
| result = Enum.to_list(2..number) | |
| run(max, result, {result, []}) | |
| end | |
| def run(0, _, {res, sieve}) do | |
| Enum.reverse(sieve) ++ res | |
| end | |
| def run(max, [ head | _ ], {result, sieve}) 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 Frequent do | |
| def number( [num | tail] ) do | |
| number({num, 1}, tail, {num, 1}) | |
| end | |
| def number({num, count}, [ num | tail ], max) do | |
| number({num, count + 1}, tail, max) | |
| end | |
| def number({_num, count} = current, [ diff | tail ], {_, max_count} = max) 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 Any do | |
| def remove(str, char) do | |
| remove("", str, char) | |
| end | |
| def remove(newstr, << char :: binary-size(1), rest :: binary >>, char) do | |
| remove(newstr, rest, char) | |
| end | |
| def remove(newstr, << first :: binary-size(1), rest :: binary >>, char) do | |
| remove(newstr <> first, rest, char) | |
| 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 Palindrome do | |
| def check(<< first :: binary-size(1), rest :: binary >> = actual) do | |
| check(first, rest, actual) | |
| end | |
| def check(newstr, << next_letter :: binary-size(1), rest :: binary >>, actual) do | |
| check(next_letter <> newstr, rest, actual) | |
| end | |
| def check(reverse, <<>>, actual), do: reverse === actual |
NewerOlder