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 Mix.TasksServer do | |
@moduledoc false | |
use GenServer.Behaviour | |
def start_link() do | |
:gen_server.start_link({ :local, __MODULE__ }, __MODULE__, :ok, []) | |
end | |
def clear_tasks() do | |
call :clear_tasks |
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
diff --git a/lib/gen_event.ex b/lib/gen_event.ex | |
index bc2a34f..07ca53f 100644 | |
--- a/lib/gen_event.ex | |
+++ b/lib/gen_event.ex | |
@@ -468,8 +468,12 @@ defimpl Enumerable, for: GenEvent do | |
send mon_pid, { :UP, mon_ref, self() } | |
receive do | |
- { :UP, ^mon_ref, manager_pid } -> { mon_ref, mon_pid, manager_pid } | |
- { :DOWN, ^mon_ref, _, _, reason } -> exit(reason) |
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
defmodule Interleave do | |
def interleave(a, b) do | |
af = Seq.impl_for(a) | |
bf = Seq.impl_for(b) | |
do_interleave_1(af, a, bf, b, []) |> :lists.reverse() | |
end | |
defp do_interleave_1(af, a, bf, b, acc) do | |
case af.next(a) do | |
{ :next, i, a } -> |
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
# Elixir v1.0 | |
defmodule Rules do | |
defmacro __using__(_) do | |
quote do | |
import unquote(__MODULE__) | |
@before_compile unquote(__MODULE__) | |
@rules [] | |
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
% from my unit tests | |
foo = 10 | |
assert 10 == my_macro(:foo) | |
assert 10 == my_macro("foo") | |
% macro | |
defmacro my_macro(some_var) when is_atom(some_var) 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 Dict.Behaviour do | |
# It is assumed that the client module implements following functions: | |
# | |
# size/1, fetch/2, put/3, reduce/3, update/4, delete/2 | |
# | |
defmacro __using__(_) do | |
quote do | |
# Following are exact copies of HashDict: | |
def get(dict, key, default // nil) 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 ExCoder do | |
vars = [ { "	", " " }, | |
{ "!", "!" }, | |
{ "" "", "\"" }, | |
{ "#", "#" }, | |
{ "$", "$" }, | |
{ "%", "%" }, | |
{ "& &", "&" }, | |
{ "'", "'" }, | |
{ "(", "(" }, |
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
Warden::Manager.after_authentication do |record, warden, options| | |
warden.request.session.try(:delete, :_csrf_token) | |
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 next_state do | |
(board, x, y) -> | |
cell = cell_at(board, x, y) | |
live_count = live_neighbors(board, x, y) | |
next_state(cell, live_count) | |
(_, x, y) when (x < 0 or y < 0) -> | |
"." | |
end | |
def next_state do |