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
%% Use the following function as onresponse callback when creating the | |
%% cowboy listener environment to log HTTP requests in common log format. | |
-define(HDR_X_FORWARDED_FOR, "x-forwarded-for"). | |
-spec common_http_log(cowboy:status(), cowboy:headers(), iodata(), cowboy_req:req()) -> cowboy_req:req(). | |
common_http_log(Status, _Headers, Body, Req0) -> | |
%% 127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 | |
[Method, Version, Path, Qs0] = cowboy_req:get([method, version, path, qs], Req0), | |
{{IpAddr, _Port}, Req1} = cowboy_req:peer(Req0), | |
Addr = inet:ntoa(IpAddr), |
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
# Map over a tuple in normal order | |
def tuple_map1(tuple, function), do: | |
tuple_map(tuple, function, 0, []) | |
def tuple_map1(tuple, function, index, acc) when index < tuple_size(tuple) do | |
item = function.(elem(tuple, index)) | |
tuple_map1(tuple, function, index + 1, [item | acc]) | |
end | |
def tuple_map1(tuple, function, index, acc) do | |
Enum.reverse(acc) |
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
# Given a module defined in this way: | |
defmodule HL7.Composite do | |
# [...] | |
defmodule EI do | |
use HL7.Composite.Def | |
composite do | |
component :id, type: :binary, default: "" | |
component :namespace_id, type: :binary, default: "" | |
component :universal_id, type: :binary, default: "" |
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
%% Script that add the CloudI Erlang applications from an installed instance to | |
%% rebar's lib_dirs configuration setting (code path). | |
%% If the 'CLOUDI_DIR' environment variable is set, then we add its "lib" | |
%% subdirectory to the code path. If not, we check for the CloudI directory in the | |
%% /usr/local/lib path. | |
LibDir = case os:getenv("CLOUDI_DIR") of | |
Dir when Dir =:= false; Dir =:= "" -> | |
%% Look for the CloudI directory in /usr/local/lib | |
case os:type() of | |
{unix, _Osname} -> |
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
%% @doc Join a a list of elements adding a separator between | |
%% each of them. | |
-spec join(iolist(), Sep :: term()) -> iolist(). | |
join([Head | Tail], Sep) -> | |
join_list_sep(Tail, Sep, [Head]); | |
join([], _Sep) -> | |
[]. | |
-spec join_list_sep(iolist(), Sep :: term(), Acc :: iolist()) -> iolist(). | |
join_list_sep([Head | Tail], Sep, Acc) -> |
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
-module(netutil). | |
-author('Juan Jose Comellas <[email protected]>'). | |
%% API | |
-export([get_local_ip_from_subnet/1, get_ip_from_subnet/2, | |
cidr_network/1, cidr_netmask/1]). | |
%% @type ipv4() = {integer(), integer(), integer(), integer()} | |