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 Exflow do | |
@behaviour :gen_fsm | |
def start_link(code) do | |
IO.puts "starting fsm" | |
:gen_fsm.start_link({:local, Exflow}, Exflow, :lists.reverse(code), []) | |
end | |
def button(digit) 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
defmodule DemoBe.Router do | |
use Phoenix.Router | |
pipeline :browser do | |
plug :accepts, ~w(html) | |
plug :fetch_session | |
plug :fetch_flash | |
plug :protect_from_forgery | |
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
~/C/S/p/router_bug_faster > time mix compile | |
Compiled src/dict.erl | |
Compiled src/erl_lint.erl | |
Compiled lib/router_bug.ex | |
Compiled web/controllers/page_controller.ex | |
Compiled lib/router_bug/endpoint.ex | |
Compiled web/view.ex | |
Compiled web/views/error_view.ex | |
Compiled web/views/layout_view.ex | |
Compiled web/views/page_view.ex |
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
# this creates an incorrect query b/c it joins account, account_user and user_api_key to client | |
# as it is piped through | |
query = DemoApp.Client | |
|> join(:inner, [c], b0 in assoc(c, :account)) | |
|> join(:inner, [b0], b1 in assoc(b0, :account_user)) | |
|> join(:inner, [b1], b2 in assoc(b1, :user_api_key)) | |
|> where([b1, b0], b1.id == ^user_id and b0.id == ^account_id) | |
|> preload([b0, b1, b2], [account: {b0, account_user: {b1, user_api_key: b2}}]) | |
|> select([c, b0, b1, b2], {c, b0, b1, b2}) | |
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
# (arity 0) | |
root@deleteme:~/foo# bin/foo rpc Foo bar | |
RPC to '[email protected]' failed: {'EXIT', | |
{undef, | |
[{'Foo',bar,[],[]}, | |
{rpc,'-handle_call_call/6-fun-0-',5, | |
[{file,"rpc.erl"},{line,205}]}]}} | |
root@deleteme:~/foo# bin/foo rpc Elixir.Foo bar | |
yeah! |
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 Meh do | |
def main do | |
"foo" | |
|> (&foo(&2, &1)).("yoyo") | |
end | |
def hard_coded do | |
"foo" | |
|> (&foo("quux", &1)).() | |
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 Clockout.MyViewHelpers do | |
def display_name(:client, id) do | |
Clockout.Client |> display_name_by_id(id) | |
end | |
def display_name(:person, id) do | |
Clockout.Person |> display_name_by_id(id) | |
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 Permutations do | |
@moduledoc """ | |
An answer to the problem from: http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/20/can-you-do-the-maths-puzzle-for-vietnamese-eight-year-olds-that-has-stumped-parents-and-teachers | |
iex> Permutations.main parallel: false | |
iex> Permutations.main parallel: true | |
""" |
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
vagrant@vagrant-ubuntu-trusty-64:~/irr/irr$ mix deps.compile | |
==> gen_smtp (compile) | |
Compiling src/smtp_rfc822_parse.yrl failed: | |
ERROR: compile failed while processing /home/vagrant/irr/irr/deps/gen_smtp: rebar_abort | |
** (Mix) Could not compile dependency gen_smtp, /home/vagrant/.mix/rebar command failed. If you want to recompile this dependency, please run: mix deps.compile gen_smtp |
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 Benum do | |
defimpl Enumerable, for: BitString do | |
def count(collection) when is_binary(collection) do | |
{:ok, Enum.reduce(collection, 0, fn v, acc -> acc + 1 end)} | |
end | |
def count(collection) do | |
{:error, __MODULE__} | |
end | |
def member?(collection, value) when is_binary(collection) do | |
{:ok, Enum.any?(collection, fn v -> value == v end)} |