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
-- Mirá Berna... acá hasta le podés dar formatito bonito.
fib :: Int -> Int
fib 0 = 1
fib 1 = 1
fib n = (fib (n-1) + fib (n-2))
@elbrujohalcon
elbrujohalcon / ewh samples.md
Created April 3, 2011 14:34
Samples for the different zones on ewh

NOTE: Samples may be not completely displayed on the browser. Use the raw version of this gist to check them properly.

This gist describes the format we use to get information from our different sources. The samples are obtained using the words API, note that format may differ (and in fact it does in almost every case) when using the items API. eWebHunter consumes three services for each provider:

  • words: To search for items related to keywords
  • users: To follow particular users
  • items: To describe specific items
@elbrujohalcon
elbrujohalcon / gen_event_repeater.erl
Created September 20, 2011 20:11
gen_event_repeater
%%%-------------------------------------------------------------------
%%% @author Fernando Benavides <fernando.benavides@inakanetworks.com>
%%% @copyright (C) 2011 Inaka Networks S.R.L.
%%% @doc It listens and just repeats...
%%% @end
%%%-------------------------------------------------------------------
-module(gen_event_repeater).
-author('Fernando Benavides <fernando.benavides@inakanetworks.com>').
-behaviour(gen_event).
@elbrujohalcon
elbrujohalcon / record.erl
Created October 31, 2011 17:41
Tricky stuff with records
-module(record).
-record(rec, {field1, field2}).
-export([test1/0, test2/0, test3/0, test4/0]).
%% First I wrote something like this...
test1() -> [#rec{field1 = 1, field2 = 1}
#rec{field1 = 2, field2 = 2}].
%% ...this compiles without a warning and then, when I run it...
%% > record:test1().
%% [#rec{field1 = 2,field2 = 2}]
@elbrujohalcon
elbrujohalcon / linking_processes.erl
Created June 19, 2012 14:03
Linked processes in Erlang… when do they die?
20> P1 = spawn(fun() -> receive stop -> io:format("P1 ended~n") end end).
<0.61.0>
21> P2 = spawn(fun() -> link(P1), receive stop -> io:format("P2 ended~n") end end).
<0.63.0>
22> {erlang:is_process_alive(P1), erlang:is_process_alive(P2)}.
{true,true}
23> P1 ! stop.
P1 ended
stop
24> {erlang:is_process_alive(P1), erlang:is_process_alive(P2)}.
@elbrujohalcon
elbrujohalcon / analyze_test.erl
Last active December 10, 2015 18:48
Dialyzer Magic
%% @doc If you run dyalizer on this module it will complain saying
%% <pre>analyze_test.erl:11: The variable _ can never match since previous clauses completely covered the type []</pre>
%% It took me a while to figure out what it was doing...
%% It's not complaining that I call a function that returns [pid()] inside a function that should return [atom()].
%% It says: "that function is fine... as long as it always return []" (which is both a list of pids and a list of atoms)
-module(analyze_test).
-export([exists/0]).
-spec list_of_atoms() -> [atom()].
@elbrujohalcon
elbrujohalcon / my_life.erl
Last active August 29, 2015 14:03
My Life
-module(my_life).
-export ([my_life/1]).
-record(place, {id, moments}).
-record(moment, {id, friends, lovers, meaning}).
-record(person, {id, love_level}).
-author(john).
-author(paul).
-author(george).
@elbrujohalcon
elbrujohalcon / elvis.md
Created September 8, 2014 13:21
elvis on cowboy

Using this elvis.config file:

$ cat elvis.config
[
 {
   elvis,
   [
    {config,
      #{src_dirs => ["src"],
        rules    => [{elvis_style, line_length, [80]},
@elbrujohalcon
elbrujohalcon / case_vs_if.erl
Created September 8, 2014 19:28
case vs. if
%% I would argue that
HTTP11Headers = case {Transport, Version} of
{cowboy_spdy, 'HTTP/1.1'} ->
[{<<"connection">>, atom_to_connection(Connection)}];
{_, _} ->
[]
end
%% is clearer and more flexible for future improvement if needed than
HTTP11Headers = if
@elbrujohalcon
elbrujohalcon / another_partial_application.erl
Created October 15, 2014 12:20
Another partial application
%% I like this way…
1> MultiplePrint = partial(fun lists:zipwith/3, [fun io:format/2]).
#Fun<erl_eval.12.90072148>
2> Salute = partial(MultiplePrint, [["hello ~s!~n", "goodbye ~s!~n"]]).
#Fun<erl_eval.6.90072148>
3> Salute([["@bipthelin"], ["@elbrujohalcon"]]).
hello @bipthelin!
goodbye @elbrujohalcon!
[ok,ok]