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 / hello.erl
Created June 10, 2016 16:41
Convoluted Hello World for my blog post
-module(hello).
-export([world/0]).
world() ->
F = fun() -> "Hello, world!" end,
F = fun() -> "Hello, world!" end,
io:format("~s~n", [F()]).
@elbrujohalcon
elbrujohalcon / dumb_math.erl
Created May 18, 2016 16:07
For my post @ Medium
-module(dumb_math).
-export([dup/1, init/1]).
dup(X) ->
case gen_server:start_link(dumb_math, X, []) of
{ok, Pid} -> sys:get_state(Pid);
{error, Reason} -> Reason
end.
init(X) when is_number(X) -> {ok, X * 2};
@elbrujohalcon
elbrujohalcon / dumb_math.erl
Last active May 18, 2016 15:40
For my post on Medium
-module(dumb_math).
-export([dup/1, init/1]).
dup(X) ->
{ok, Pid} = gen_server:start_link(dumb_math, X, []),
sys:get_state(Pid).
init(X) -> {ok, X * 2}.
@elbrujohalcon
elbrujohalcon / pattern-match-funs.erl
Created October 2, 2015 17:57
One does not simply pattern match funs
3> Fun = fun() -> ok end,
3> Fun = fun() -> ok end.
** exception error: no match of right hand side value #Fun<erl_eval.20.54118792>
4> Fun = fun() -> ok end.
#Fun<erl_eval.20.54118792>
5> Fun = fun() -> ok end.
#Fun<erl_eval.20.54118792>

Keybase proof

I hereby claim:

  • I am elbrujohalcon on github.
  • I am elbrujohalcon (https://keybase.io/elbrujohalcon) on keybase.
  • I have a public key whose fingerprint is CD9E 3C5B 5E58 3B30 5B30 6345 0550 3C28 3EA2 012F

To claim this, I am signing this object:

@elbrujohalcon
elbrujohalcon / what.erl
Created March 5, 2015 19:27
What's going on here?
Bad = [67,108,111,110,105,110,103,32,105,110,116,111,32,39,47,112,114,105,118,97,116,101,47,116,109,112,47,103,97,100,103,101,116,47,103,97,100,103,101,116,45,116,101,115,116,47,111,114,103,45,114,101,112,111,47,48,48,48,49,52,50,53,45,48,53,56,51,51,51,56,45,48,52,48,48,55,49,53,47,100,101,112,115,47,101,112,101,114,39,46,46,46,10,67,108,111,110,105,110,103,32,105,110,116,111,32,39,47,112,114,105,118,97,116,101,47,116,109,112,47,103,97,100,103,101,116,47,103,97,100,103,101,116,45,116,101,115,116,47,111,114,103,45,114,101,112,111,47,48,48,48,49,52,50,53,45,48,53,56,51,51,51,56,45,48,52,48,48,55,49,53,47,100,101,112,115,47,115,121,110,99,39,46,46,46,10,67,108,111,110,105,110,103,32,105,110,116,111,32,39,47,112,114,105,118,97,116,101,47,116,109,112,47,103,97,100,103,101,116,47,103,97,100,103,101,116,45,116,101,115,116,47,111,114,103,45,114,101,112,111,47,48,48,48,49,52,50,53,45,48,53,56,51,51,51,56,45,48,52,48,48,55,49,53,47,100,101,112,115,47,107,97,116,97,110,97,39,46,46,46,10,67,108,111,110,105,110,103,32,10
@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]
@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 / 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 / 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).