Skip to content

Instantly share code, notes, and snippets.

View elbrujohalcon's full-sized avatar
🇪🇸
Working from Catalunya

Brujo Benavides elbrujohalcon

🇪🇸
Working from Catalunya
View GitHub Profile
@elbrujohalcon
elbrujohalcon / jaime.erl
Last active August 2, 2016 10:56
Jaime
-module(jaime).
-behaviour(gen_server).
-export([ start/0
, carry/1
, deliver/0
, trip/0
]).
-export([ init/1
@elbrujohalcon
elbrujohalcon / dia.erl
Created July 26, 2016 13:25
Second version of the dialyzer runner
do_run(Options) ->
Warnings = dialyzer:run(Options),
Msg = [dialyzer:format_warning(Warning, basename) || Warning <- Warnings],
io:format("~s", [Msg]).
@elbrujohalcon
elbrujohalcon / dia.erl
Last active July 26, 2016 12:31
dialyzer runner
-module(dia).
-export([run/1, plt/0]).
-spec plt() -> ok.
plt() ->
Options =
[ {analysis_type, 'plt_build'}
, {get_warnings, true}
, {output_plt, "dia.plt"}
$ iex -S mix
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Compiling 1 file (.ex)
== Compilation error on file lib/wat.ex ==
** (SyntaxError) lib/wat.ex:9: syntax error before: ','
(elixir) lib/kernel/parallel_compiler.ex:116: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1
@elbrujohalcon
elbrujohalcon / good_people.erl
Created June 21, 2016 04:14
Good people for my blog post
-spec count(country(), [group()]) -> non_neg_integer().
count(Country, Groups) ->
lists:sum(
lists:map(
fun (#{country := C, members := Members}) when C == Country ->
length(Members);
(_) ->
0
end, Groups)).
@elbrujohalcon
elbrujohalcon / ugly_people.erl
Created June 21, 2016 04:07
More people for my blog post
-spec count(country(), [group()]) -> non_neg_integer().
count(Country, Groups) ->
lists:sum(
[ length(Members)
|| #{country := Country, members := Members} <- Groups
]).
@elbrujohalcon
elbrujohalcon / bad_people.erl
Created June 21, 2016 03:36
people:count/2 for my blog post
-spec count(country(), [group()]) -> non_neg_integer().
count(Country, Groups) ->
lists:sum(
lists:map(
fun (#{country := Country, members := Members}) ->
length(Members);
(_) ->
0
end, Groups)).
@elbrujohalcon
elbrujohalcon / people.erl
Created June 21, 2016 03:26
people module for my blog post
-module(people).
-export([count/2]).
-export([test/0]).
-type user() :: binary().
-type country() :: atom().
-type group() :: #{ country => country()
, members => [user()]
}.
@elbrujohalcon
elbrujohalcon / hello.erl
Created June 10, 2016 17:55
Compiler-crashing Hello World
-module(hello).
-export([world/0, f/0, '-f/0-fun-0-'/0]).
world() ->
F = f(),
F = f(),
io:format("~s~n", [F()]).
f() -> fun() -> "Hello, world!" end.
@elbrujohalcon
elbrujohalcon / hello.erl
Created June 10, 2016 16:55
Hello module with exported fun
-module(hello).
-export([world/0, f/0]).
world() ->
F = f(),
F = f(),
io:format("~s~n", [F()]).
f() -> fun() -> "Hello, world!" end.