-
Notifications
You must be signed in to change notification settings - Fork 3
/
gs_util.erl
70 lines (61 loc) · 2.14 KB
/
gs_util.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%%
%% ----------------------------------------------------------------------------
%% "THE BEER-WARE LICENSE" (Revision 42.1):
%% <gustav.simonsson@gmail.com> wrote this file.
%% As long as you retain this notice you
%% can do whatever you want with this stuff. If we meet some day, and you think
%% this stuff is worth it, you can buy me a beer in return.
%% ----------------------------------------------------------------------------
%%
%%%-------------------------------------------------------------------
%%% @author Gustav Simonsson <gustav.simonsson@gmail.com>
%%% @doc
%%%
%%% Miscellaneous Erlang function collection.
%%%
%%% @end
%%% Created : 29 Nov 2011 by Gustav Simonsson <gustav.simonsson@gmail.com>
%%%-------------------------------------------------------------------
-module(gs_util).
-compile(export_all).
words(Words) ->
lists:flatten([0|| _X <- lists:seq(1, Words div 2)]).
substrings(S) ->
Slen = length(S),
[string:sub_string(S,B,E) ||
B <- lists:seq(1, Slen), E <- lists:seq(B, Slen)].
get_file_lines(F) ->
get_file_lines_acc(F, []).
get_file_lines_acc(F, Acc) ->
case file:read_line(F) of
eof ->
Acc;
{ok, Data} ->
get_file_lines_acc(F, [Data | Acc])
end.
p(S, S2) ->
io:format("~n~p:~n~p~n", [S, S2]).
int_to_month(Int) ->
lists:nth(Int, [jan, feb, mar, apr, may, jun, jul, aug,
sep, oct, nov, dec]).
fat_processes() ->
fat_processes(10).
fat_processes(C) ->
L = lists:sort([{proplists:get_value(heap_size,L),
P,
proplists:get_value(initial_call, L),
proplists:get_value(current_function, L)}
||{L,P} <- [{process_info(P), P} || P <- processes()]]),
lists:reverse(lists:nthtail(length(L) - C, L)).
t(Mod, Fun, Args) ->
dbg:stop_clear(),
dbg:start(),
dbg:tracer(),
dbg:p(all,c),
dbg:tpl(Mod, Fun, Args).
intervals(Start, Stop, _) when Start > Stop ->
[];
intervals(Start, Stop, N) when Start == Stop; (Start + N) > Stop ->
[{Start, Stop}];
intervals(Start, Stop, N) ->
[{Start, Start + N} | intervals(Start + N + 1, Stop, N)].