Skip to content

Instantly share code, notes, and snippets.

View greggy's full-sized avatar

Grigory Fateyev (aka greg) greggy

View GitHub Profile
%%%-------------------------------------------------------------------
%%% @author greg <>
%%% @copyright (C) 2012, greg
%%% @doc
%%%
%%% @end
%%% Created : 29 Nov 2012 by greg <>
%%%-------------------------------------------------------------------
-module(ring).
start(ProcNum, MsgNum, Message) ->
init(#state{num_procs=ProcNum, msg_num=MsgNum, msg=Message}).
%% first process
init(#state{proc_num=Proc, msg=Message}=State) when Proc == 1 ->
Pid = spawn(ring, loop, [Proc]),
Pid ! Message,
init(State#state{proc_num=Proc+1, first_pid=Pid});
%% last process
start(ProcNum, MsgNum, Message) ->
start(ProcNum, MsgNum, Message, 0, 0, 1).
start(ProcNum, MsgNum, Message, PrevPid, FirstPid, Num) when ProcNum == Num ->
spawn(ring, loop, [Num, FirstPid, MsgNum, Message]);
start(ProcNum, MsgNum, Message, PrevPid, FirstPid, 1) ->
Pid = spawn(ring, loop, [1, PrevPid, MsgNum, Message]),
start(ProcNum, MsgNum, Message, Pid, Pid, 2),
Pid ! Message;
start(ProcNum, MsgNum, Message, PrevPid, FirstPid, Num) ->
def stdDevOfLengths(L):
"""
L: a list of strings
returns: float, the standard deviation of the lengths of the strings,
or NaN if L is empty.
"""
if L:
mean = float(sum([len(s) for s in L]))/float(len(L))
stdDiv = 0.0
function sumup_time(t1, t2){
if (t2.split(':').length == 2){
t2 = '00:'+t2;
}
var d1 = new Date(0);
var d2 = new Date(0);
if (parse_time(t1).hh != '00'){
d1.setHours(parse_time(t1).hh);
} else {
> pgsql:equery(C2, "INSERT INTO app_test (test1, test2, test3) VALUES ($1, $2, $3) RETURNING id", ["TEST1", 127, pgsql_binary:encode(timestamptz, {{2012,7,2},{17,12,10}})]).
** exception exit: {noproc,{gen_fsm,sync_send_event,
[<0.3800.0>,
{parse,[],
"INSERT INTO app_test (test1, test2, test3) VALUES ($1, $2, $3) RETURNING id",
[]},
infinity]}}
in function gen_fsm:sync_send_event/3 (gen_fsm.erl, line 214)
in call from pgsql:equery/3 (src/pgsql.erl, line 44)
(proxy@silver_proxy.stream.lan)1> proxy_sup:start_proxy(122, 211).
2011-12-08 13:46:54:344798 proxy:88:debug [<0.87.0>]->[init_start]: Start proxy: 211
2011-12-08 13:46:54:348767 proxy_gw:79:debug [<0.88.0>]->[]: Start proxy gw
2011-12-08 13:46:54:350000 =PROGRESS REPORT=======
supervisor: {local,proxy_sup}
started: [{pid,<0.87.0>},
{name,'RTMPProxy_211'},
{mfargs,{proxy,start_link,[122,211,'RTMPProxy_211']}},
{restart_type,transient},
{shutdown,2000},
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
start_proxy(SessionPid, ChannelID) ->
Name = list_to_atom(ChannelID),
supervisor:terminate_child(proxy_sup, Name),
supervisor:delete_child(proxy_sup, Name),
SpecProxy = {Name, {proxy, start_link, [SessionPid, ChannelID, Name]},
transient, 2000, worker, [Name]},
case supervisor:start_child(?SERVER, SpecProxy) of
count_viewers() ->
[
[lists:flatten(io_lib:format("Node: ~p, Channel: ~p, Viewers: ~p",
[Node, ChannelId,
case rpc:call(Node, proxy, count_viewers, [ChannelId]) of
{badrpc, _} -> "Not proxy";
Res -> Res
end
]))
|| ChannelId <- utils:get_sessions_id(global:registered_names())]
diff --git a/README.txt b/README.txt
index 8ac5719..136cf76 100644
--- a/README.txt
+++ b/README.txt
@@ -19,6 +19,17 @@ Run the appropriate script:
This script will compile the .erl files in the Misultin src directory and save the compiled files into the
ebin directory.
+ 1.1 Dependents
+