erlang

Pagination search in Erlang Mnesia

柔情痞子 提交于 2019-12-06 07:11:39
For example, given record -record(item, { id, time, status}). I want to search the 1000 to 1100 items, ordered by time and status =:= <<"finished">> Any suggestions? It depends on what your queries look like. If you need to order by lots of different columns, then I'd consider using SQL instead of Mnesia. But if you only need the kind of query you described, you should be able to use the ordered_set type of table to handle the ordering and mnesia:select/4 to handle pagination and the constraint. Here's some untested code to give you the gist: % time goes first because it's our primary sort key

Erlang Node to Node Messaging Throughput, Timeouts and guarantees

我是研究僧i 提交于 2019-12-06 06:49:59
问题 Now, suppose we are designing an application, consists of 2 Erlang Nodes. On Node A, will be very many processes, in the orders of thousands. These processes access resources on Node B by sending a message to a registered process on Node B. At Node B, lets say you have a process started by executing the following function: start_server()-> register(zeemq_server,spawn(?MODULE,server,[])),ok. server()-> receive {{CallerPid, Ref}, {Module, Func, Args}} -> Result = (catch erlang:apply(Module,

What alternatives are there to parameterised modules in Erlang?

限于喜欢 提交于 2019-12-06 06:24:58
问题 I can see why parameterised modules are used so much, as they allow us to do things like: X = y:new("param"). X:action1(). X.get_property(): : which feels very OO. However, this is only an experimental feature in Erlang and I hear it may be removed, so I need to find an alternative. 回答1: Parametrised modules are nothing but a shortcut on the first argument of a function. See these two examples: -module(y, [Name,Age]). -compile(export_all). action1() -> io:format("Hello, ~p!~n",[Name]). get

Ejabberd Clustering understanding

流过昼夜 提交于 2019-12-06 06:22:41
Let assume I have two ejabberd server consider X and Y which has the same source and i did ejabberd clustering for those server by using this . Now consider A and B are user and those are connected in X server . Both A and B are in ONLINE state and those are connected via X server . If suppose X server is get shutdown or crashed by some issue. In this sceneraio whether the A and B are get OFFLINE state or A and B are in ONLINE state which is handle by Y server. I don't know whether my thought is right or not. If any one give me the suggestion about it. If you have nodes in different physical

How to handle WebSocket messages in an appmod using Yaws?

戏子无情 提交于 2019-12-06 06:18:58
I have created a simple appmod that sends back the same message as it receives. But I get an error message at the command prompt and the WebSocket connection is closed. If I send a message with 3 chars I get this error message: =ERROR REPORT==== 8-Feb-2012::05:09:14 === Error in process <0.59.0> with exit value: {undef,[{mywebsocket,handle_message,[ {text,<<3 bytes>>}],[]},{lists,map,2,[{file,"lists.erl"},{line,1173}]},{yaws_web sockets,loop,4,[{file,"yaws_websockets.erl"},{line,151}]}]} What am I doing wrong? The handle uses text , and it doesn't work if I use binary either. Here is my HTML

why doesn't this erlang code work?

最后都变了- 提交于 2019-12-06 06:00:58
fib(N)-> P1 = spawn(fun concFib:conFib/0), P2 = spawn(fun concFib:conFib/0), X=rpc(P1,N-2),Y=rpc(P2,N-1),X+Y. conFib()-> receive {Client,N} -> Client ! regfib(N) end. rpc(Pid,Request)-> case erlang:is_process_alive(Pid) of true -> begin Pid ! {self(),Request}, receive {Pid,Respond} -> Respond end end; false -> io:format("~w process is dead.",[Pid]) end. regfib(N)-> case N<2 of true -> 1; false -> regfib(N,1,1,1) end. regfib(N,N,X,_)-> X ; regfib(N,M,X,Y)-> regfib(N,M+1,X+Y,X). The idea is to divide the fib(N) process into two process one calculates fib(N-2) and the other one calc. fib(N-1)

Generate permutations iteratively without recursion or stack with Ruby/Erlang

China☆狼群 提交于 2019-12-06 05:55:59
问题 I would like to generate all permutations of a list, but I would like to filter out some of the permutations before they are added to the stack or stored anywhere. I will filter out the permutations based on some custom ad-hoc rules. In other words, I would like to generate a list of permutations of a large list (50-300 elements), but I would like to throw out most of the generated permutations right during the process (I know that the full number of permutations is N! ). I have tried Ruby

Erlang Mysql: How to prevent SQL Injections

喜欢而已 提交于 2019-12-06 05:54:17
I'm very new to erlang and I need to code something which inserts rows in a MySQL Database. How can I prevent SQL Injections with Erlang? Is there also something like prepared statements in other Languages or how should I do it? Thanks for your replies. This answer depends on the driver you are using. Erlang ODBC has a function param_query that binds a set of parameters to the query and it might also escape all the SQL special characters. erlang-mysql-driver has prepared statements: %% Register a prepared statement mysql:prepare(update_developer_country, <<"UPDATE developer SET country=? where

Erlang - Random Number Generator

核能气质少年 提交于 2019-12-06 05:45:02
问题 I am using the following to generate a near random number. 3> erlang:ref_to_list(make_ref()). "#Ref<0.0.0.36>" What I want is 00036 Well it was what I had been informed I could do in a previous post. It occurred to me that it is not so easy to extract the numbers from make ref. Can anyone show how it is easily done, or possibly recommend another solution. Keep in mind that using random:seed() is not random when called within the same few nano seconds. Regards 回答1: Note: from OTP 18 erlang:now

Apple Push Notification in Erlang (or improved in Ruby?)

让人想犯罪 __ 提交于 2019-12-06 05:44:48
问题 I currently have an Apple Push Notification running on my server in Ruby. I'd like to get one going in Erlang as I'd like to use a supervisor to keep watch over it. Does anyone have any code that they could help me with? Here's my Ruby code. One thing I do not like about this current implementation is that it does not seem to stay connected - it disconnects 2-3 times a day, and it seems after I reconnect that the first push will not go through: context = OpenSSL::SSL::SSLContext.new context