erlang

Erlang and PostgreSQL

左心房为你撑大大i 提交于 2019-12-11 10:12:34
问题 I try to execute simple PostgreSQL query with erlang and epgsql. I do: {ok, C} = pgsql:connect("localhost", "shk", "qwerty", [{database, "mydb"}]). >> {ok,<0.34.0>} Then: {ok, Cols, Rows} = pgsql:squery(C, "select * from users"). But i got error: =ERROR REPORT==== 27-Apr-2012::17:58:23 === ** State machine <0.34.0> terminating ** Last message in was {'EXIT',<0.32.0>, {{badmatch, {error, {error,'ð\236ð¨ð\230ð\221ð\232ð\220',<<"42P01">>, <<208,190,209,130,208,189,208,190,209,136,208,181, 208

Why do we need simple_one_for_one?

巧了我就是萌 提交于 2019-12-11 10:04:18
问题 Somebody told me that simple_one_for_one is very useful for chat applications, because each chat client is a server process (gen_server). Is this right? And I wonder why do we need it? Why not create only one center server (gen_server) to handle all chat client communication? Because maybe the number of chat clients is very large so only one server couldn't handle fast, make the system slow down? I think maybe creating too many servers like simple_one_for_one may take too much system resource

Ejabberd: error in simple module to handle offline messages

吃可爱长大的小学妹 提交于 2019-12-11 09:26:06
问题 I have an Ejabberd 17.01 installation where I need to push a notification in case a recipient is offline. This seems the be a common task and solutions using a customized Ejabberd module can be found everywhere. However, I just don't get it running. First, here's me script: -module(mod_offline_push). -behaviour(gen_mod). -export([start/2, stop/1]). -export([push_message/3]). -include("ejabberd.hrl"). -include("logger.hrl"). -include("jlib.hrl"). start(Host, _Opts) -> ?INFO_MSG("mod_offline

Will the file get automatically closed, when opening process terminates

本小妞迷上赌 提交于 2019-12-11 09:17:45
问题 I have a process, which opens the file by using file:open. Will this file get automatically closed, when my process will terminate? 回答1: Yes. From the documentation of file:open/2: Returns: {ok, IoDevice} The file has been opened in the requested mode. IoDevice is a reference to the file. [...] IoDevice is really the pid of the process which handles the file. This process is linked to the process which originally opened the file. If any process to which the IoDevice is linked terminates, the

Erlang - map each “erlang process” to new kernel thread

前提是你 提交于 2019-12-11 08:54:16
问题 I am studying an erlang based system, and trying to analyze the sequence of events that take place in the system. Is there a way to force erlang run-time or the elang vm to create a new kernel thread, each time "spawn" is called. This would make the system slower, but it would make the study a lot easier. I have tried the +S flag, and enabled smp already, but I suspect the system is still mapping multiple processes to one kernel thread, or erlang scheduler. Are there any inputs/configuration

Elixir / Erlang Dialyzer : Why behaviour callback's param type should be subtype instead of supertype?

£可爱£侵袭症+ 提交于 2019-12-11 08:48:48
问题 I have a behaviour X and a callback function with parameter type: %{a: any} Module Y implements behaviour X and the callback function in implementing module Y has parameter type: %{a: any, b: any} Dialyzer doesn't like that and complains: (#{'a':=_, 'b':=_, _=>_}) is not a supertype of #{'a':=_} This implies dialyzer attempts to determine if callback parameter's type in implementing module Y is a supertype of param type in behaviour X. In other words, it asks: Is behaviour X's callback param

INFO_MSG method fails in ejabberd

自闭症网瘾萝莉.ら 提交于 2019-12-11 08:46:53
问题 I am trying to write a custom module in ejabberd XMPP server. This is the erl module i'v written. -module(mod_wish). -behavior(gen_mod). -include("logger.hrl"). -export([ start/2, stop/1 ]). start(_Host, _Opt) -> ?INFO_MSG("Loading module 'mod_wish' ", []), ok. stop(_Host) -> ok. I can compile it without any errors. But after i add this module to config file and restart the ejabberd server, serve does not start. it says C(<0.38.0>:gen_mod:75) : Problem starting the module mod_wish for host

Follow the end Url in Erlang

半世苍凉 提交于 2019-12-11 08:16:12
问题 I'm trying to follow a Url which is in a RSS to find the end URL! so for example I have this URL "http://coder.io/~a27983554a" and the result of following this will be "http://ferd.ca/code-janitor-nobody-s-dream-everyone-s-job-and-how-erlang-can-help.html" The end URL is saved in the header of the first URL, but the problem is I need to send a request to that URL to get response containing the end result for me! I'm using this command {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =

Erlang error on send to registered process

蹲街弑〆低调 提交于 2019-12-11 07:34:39
问题 I'm trying to make Erlang program that finds prime numbers with processes (ineffective, I know, but hey, it's just for fun :) ) - something along the lines of numbersimulation.com. On each "tick" the server spawns new process ("number") that increments its counter. If counter == that number, it's a factor, so we let server know. If server doesn't get any messages, it's a prime number. On small numbers (primes upto N, the server(50,L) line) it's okay, but on the bigger ones it crashes with:

How does a loop simulation works?

[亡魂溺海] 提交于 2019-12-11 07:13:39
问题 -module(prac). -export([len/1]). len([]) -> 0; len([_|T]) -> 1 + len(T). So I have this code and it works, but I dont know how to simulate it properly. 回答1: Okay, if you're looking for an explanation of why the code works the way it does, it goes something like this. Given the following code: len([]) -> 0; len([_|T]) -> 1 + len(T). If you were to call len/1 like len([a,b,c]) , then you can think of it executing like: call len([a,b,c]) does [a,b,c] match [] ? no does [a,b,c] match [_|T] ? yes,