-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from inaka/jfacorro.3.rename.to.ktn
[#3] Renamed modules.
- Loading branch information
Showing
5 changed files
with
70 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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. |
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
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). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(katana_random). | ||
-module(ktn_random). | ||
-behaviour(gen_server). | ||
|
||
-export([ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-module(ktn_task). | ||
|
||
-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. |