Skip to content

Commit

Permalink
[#3] Renamed modules. Moved katana fns to their own modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Aug 12, 2014
1 parent 5eba242 commit a242028
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 58 deletions.
57 changes: 0 additions & 57 deletions src/katana.erl

This file was deleted.

21 changes: 21 additions & 0 deletions src/ktn_code.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-module(ktn_code).

-export([
beam_to_erl/2
]).

%% @doc If the beam was not compiled with debug_info
%% the code generated by this function will look really ugly
%% @end
-spec beam_to_erl(string(), string()) -> ok.
beam_to_erl(BeamPath, ErlPath) ->
case beam_lib:chunks(BeamPath, [abstract_code]) of
{ok, {_, [{abstract_code, {raw_abstract_v1,Forms}}]}} ->
Src =
erl_prettypr:format(erl_syntax:form_list(tl(Forms))),
{ok, Fd} = file:open(ErlPath, [write]),
io:fwrite(Fd, "~s~n", [Src]),
file:close(Fd);
Error ->
Error
end.
15 changes: 15 additions & 0 deletions src/ktn_date.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-module(ktn_date).

-export([
now_human_readable/0
]).

%% @doc Returns the current date in a human readable format binary.
-spec now_human_readable() -> binary().
now_human_readable() ->
TimeStamp = os:timestamp(),
{{Year, Month, Day},
{Hour, Minute, Second}} = calendar:now_to_universal_time(TimeStamp),
DateList = io_lib:format("~p-~p-~pT~p:~p:~pZ",
[Year, Month, Day, Hour, Minute, Second]),
list_to_binary(DateList).
33 changes: 33 additions & 0 deletions src/ktn_process.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-module(ktn_process).

-export([
wait_for/2,
wait_for/4,
wait_for_success/1,
wait_for_success/3
]).

wait_for(Task, ExpectedAnswer) ->
wait_for(Task, ExpectedAnswer, 200, 10).

wait_for(Task, ExpectedAnswer, SleepTime, Retries) ->
wait_for_success(fun() ->
ExpectedAnswer = Task()
end, SleepTime, Retries).

wait_for_success(Task) ->
wait_for_success(Task, 200, 10).

wait_for_success(Task, SleepTime, Retries) ->
wait_for_success(Task, undefined, SleepTime, Retries).

wait_for_success(_Task, Exception, _SleepTime, 0) ->
{error, {timeout, Exception}};
wait_for_success(Task, _Exception, SleepTime, Retries) ->
try
Task()
catch
_:NewException ->
timer:sleep(SleepTime),
wait_for_success(Task, NewException, SleepTime, Retries - 1)
end.
2 changes: 1 addition & 1 deletion src/katana_random.erl → src/ktn_random.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(katana_random).
-module(ktn_random).
-behaviour(gen_server).

-export([
Expand Down

0 comments on commit a242028

Please sign in to comment.