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
def async_query(pid, statement, params) do | |
message = {:query, statement, params} | |
process = GenServer.whereis(pid) | |
monitor = Process.monitor(process) | |
from = {self(), monitor} | |
:ok = Connection.cast(pid, {message, from}) | |
%Task{ref: monitor} | |
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 KVServer do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec | |
children = [ | |
supervisor(Task.Supervisor, [[name: KVServer.TaskSupervisor]]), | |
worker(Task, [KVServer, :accept, [4040]]) | |
] |
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 BasicBench do | |
use Benchfella | |
@num :random.uniform(999_999_999_999) | |
bench "interpolation" do | |
@num | |
|> NumToWordsString.say | |
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
def concurrent_factorial(range, worker_pool_by_nodenames \\ worker_pool_by_nodenames) | |
def concurrent_factorial(%Range{first: start, last: finish}, worker_pool_by_nodenames) do | |
pmap(split_range_of_numbers(start..finish), fn(range) -> range |> Enum.reduce(&(&1*&2)) end, worker_pool_by_nodenames) |> | |
Enum.reduce(&(&1*&2)) | |
end | |
def concurrent_factorial(n, worker_pool_by_nodenames) when is_integer(n) and n > 0 do | |
concurrent_factorial(1..n, worker_pool_by_nodenames) |
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
File.read("match.exs") |> (fn({:ok, bin}) -> bin end).() |> String.length | |
#=> 156 | |
s = """ | |
id;name;value | |
1;foo;hi | |
2;bar;bye | |
""" | |
s |
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
@proto_version "1.0" | |
def process_options(opts) do | |
env_args() | |
|> (&process_in(opts, &1)).() | |
|> (&process_err(opts, &1)).() | |
|> (&process_dir(opts, &1)).() | |
end | |
defp process_in(opts, args) do |
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
=ERROR REPORT==== 12-Jun-2014::15:23:03 === | |
** Task <0.38.0> terminating │ | |
** Started by local_name_or_pid │ | |
** When Function == #Fun<erlang.hd.1> │ | |
** Arguments == [[]] | |
** Reason for termination == | |
** {badarg,[{erlang,hd,[[]],[]}, | |
{'Elixir.Agent.Server',handle_call,3, | |
[{file,"lib/agent/server.ex"},{line,11}]}, | |
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,580}]}, |
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 FibAgent do | |
def start_link do | |
cache = Enum.into([{0, 0}, {1, 1}], HashDict.new) | |
Agent.start_link(fn -> cache end) | |
end | |
def fib(pid, n) when n >= 0 do | |
Agent.get_and_update(pid, &do_fib(&1, n)) | |
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 MyReceive do | |
defmacro my_receive(do: clauses) do | |
extra = quote do | |
other -> IO.puts "got #{inspect other}" | |
end | |
quote do | |
receive do: unquote(clauses ++ extra) | |
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
-module(pecypc_session). | |
-author('Vladimir Dronnikov <[email protected]>'). | |
%% ----------------------------------------------------------------------------- | |
%% API exports | |
%% ----------------------------------------------------------------------------- | |
-export([ | |
add/1, | |
add/2, |
NewerOlder