anchor.diff:  ensure_binary(Atom) when is_atom(Atom) ->
       atom_to_binary(Atom, utf8).
   
  -
  -%% ensure_list/1
  -%% ====================================================================
  -%% @doc Translates given term to list if needed.
  -%% @end
  +%%--------------------------------------------------------------------
  +%% @doc
  +%% Translates given term to list if needed.
  +%% @end
  +%%--------------------------------------------------------------------
   -spec ensure_list(ListLikeTerm :: atom() | binary() | integer() | string() | list()) -> list().
  -%% ====================================================================
   ensure_list(Binary) when is_binary(Binary) ->
       binary_to_list(Binary);
   ensure_list(Integer) when is_integer(Integer) ->
  
positive.code: %% ===================================================================
  %% @author Konrad Zemek
  %% @copyright (C): 2014, ACK CYFRONET AGH
  %% This software is released under the MIT license
  %% cited in 'LICENSE.txt'.
  %% @end
  %% ===================================================================
  %% @doc This module stores utility functions for use in other modules.
  %% @end
  %% ===================================================================
  -module(utils).
  
  %% API
  -export([binary_join/2, ensure_running/1, pmap/2, pforeach/2, time/0, mtime/0, record_type/1,
           ensure_binary/1, ensure_list/1, ensure_unicode_list/1, ensure_unicode_binary/1, access_token_hash/1, trim_spaces/1,
           ceil/1]).
  
  %% ====================================================================
  %% API functions
  %% ====================================================================
  
  %% binary_join/2
  %% %% ====================================================================
  %% %% @doc Joins bineries with Separator
  %% %% @end
  -spec binary_join(Binaries :: [binary()], Separator :: binary()) -> binary().
  binary_join([], _Sep) ->
      <<>>;
  
negative.code:             <<B/binary, Sep/binary, A/binary>>
          end, Head, Tail).
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Ensures that Application is started. See {@link application}
  %% @end
  %%--------------------------------------------------------------------
  -spec ensure_running(Application :: atom()) -> ok | {error, Reason :: term()}.
  ensure_running(Application) ->
      case application:start(Application) of
          {error, {already_started, Application}} -> ok;
          EverythingElse -> EverythingElse
      end.
  
  %%--------------------------------------------------------------------
  %% @doc
  %% A  parallel version of lists:map/2. See {@link lists:map/2}
  %% @end
  %%--------------------------------------------------------------------
  -spec pmap(Fun :: fun((X :: A) -> B), L :: [A]) -> [B].
  pmap(Fun, L) ->
      Self = self(),
      Ref = erlang:make_ref(),
      PIDs = lists:map(fun(X) -> spawn(fun() -> pmap_f(Self, Ref, Fun, X) end) end, L),
      pmap_gather(PIDs, Ref, []).
  
  %%--------------------------------------------------------------------
  %% @doc
  %% A parallel version of lists:foreach/2. See {@link lists:foreach/2}
  %% @end
  %%--------------------------------------------------------------------
  -spec pforeach(Fun :: fun((X :: A) -> any()), L :: [A]) -> ok.
  pforeach(Fun, L) ->
      Self = self(),
      Ref = erlang:make_ref(),
      lists:foreach(fun(X) -> spawn(fun() -> pforeach_f(Self, Ref, Fun, X) end) end, L),
      pforeach_gather(length(L), Ref).
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Returns hash of given AccessToken. Can be used to confirm user's GlobalId using GlobalRegistry.
  %% @end
  %%--------------------------------------------------------------------
  -spec access_token_hash(AccessToken :: binary()) -> Hash :: binary().
  access_token_hash(AccessToken) ->
      base64:encode(crypto:hash(sha512, AccessToken)).
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Returns time in seconds.
  %% @end
  %%--------------------------------------------------------------------
  -spec time() -> Result :: integer().
  time() ->
      {M, S, _} = now(),
      M * 1000000 + S.
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Returns time in milliseconds.
  %% @end
  %%--------------------------------------------------------------------
  -spec mtime() -> Result :: integer().
  mtime() ->
      {M, S, U} = now(),
      erlang:trunc(M * 1000000000 + S * 1000 + U / 1000).
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Gets record type for given record. Since the is now way of knowing whether
  %% given tuple is record, this method behaviour is unspecified for non-record tuples.
  %% @end
  %%--------------------------------------------------------------------
  -spec record_type(Record :: tuple()) ->
      atom() | no_return().
  record_type(Record) when is_tuple(Record) ->
      element(1, Record).
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Translates given term to binary if needed.
  %% @end
  %%--------------------------------------------------------------------
  -spec ensure_binary(BinLikeTerm :: atom() | binary() | integer() | string() | list()) -> binary().
  ensure_binary(Bin) when is_binary(Bin) ->
      Bin;
  ensure_binary(List) when is_list(List) ->
  