Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
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
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)
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
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 } ->
# Elixir v1.0
defmodule Rules do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@rules []
end
end
% 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
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
defmodule ExCoder do
vars = [ { "	", " " },
{ "!", "!" },
{ "" "", "\"" },
{ "#", "#" },
{ "$", "$" },
{ "%", "%" },
{ "& &", "&" },
{ "'", "'" },
{ "(", "(" },
Warden::Manager.after_authentication do |record, warden, options|
warden.request.session.try(:delete, :_csrf_token)
end
@josevalim
josevalim / def.exs
Last active December 20, 2015 08:19 — forked from avdi/def.exs
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