erlang

Elixir processes and no shared heap memory

三世轮回 提交于 2019-12-12 09:07:38
问题 Elixir processes have their own heap. If a process wants to share a data structure with another process, how could that be possible? One answer that comes to my mind is that the process sends a message to the other process containing the data structure. Does that mean that the entire data structure is copied from one heap to the other? And if this is true, isn't it inefficient? 回答1: TL;DR: Yes, it is inefficient. But you'll almost never notice this in practice . Welcome to the world of

How can I make Webmachine and eredis work together?

巧了我就是萌 提交于 2019-12-12 09:07:14
问题 I've been meditating on the question of Redis usage in my Webmachine application for a week. And I haven't enlightened yet. I'm going to use Eredis and here is an example of usage: {ok, Con} = eredis:start_link(). {ok, <<"OK">>} = eredis:q(Con, ["SET", "foo", "bar"]). {ok, <<"bar">>} = eredis:q(Con, ["GET", "foo"]). As I understand eredis:start_link() should be called somewhere only once. But then how can I get Con variable in my resources? 回答1: There are several solutions: register a redis

Writing Excel FIle through Erlang

折月煮酒 提交于 2019-12-12 08:58:41
问题 i am trying to write excel file through erlang. I used the following code to write the excel file -module(excel). -export([start/1]). start(Val)-> case file:open("office-test.xls",[append]) of {ok,Fd} -> io:format(" file created"), io:fwrite(Fd,"~p\t~p\t~p~n", ["Name","Date","Number"]), export(Fd,Val), file:close(Fd); {error,_} -> io:format("~nerror in creation of file") end. export(_,0)-> ok; export(Fd,Val) -> io:fwrite(Fd, "~p\t~p\t~p\t~n" ,["B123","2012/10/11 12:12:12","val"++integer_to

Easy way to break foldl

会有一股神秘感。 提交于 2019-12-12 08:51:52
问题 I need to break from foldl. Here is a dummy example how to break from fold when I count sum of values in a list and meet too big value (i.e. 10) L = [1,2,3,4,10,5,6,7], Res = try lists:foldl( fun(I, Value) -> if (I < 10) -> Value + I; true -> throw({too_big_value, Value}) end end, 0, L) catch throw:{too_big_value, Value} -> Value end, Res. I know this example is artificial but are there any nice method to break out fold (I know that fold always scan the whole structure)? Please note, that i

Erlang - C and Erlang

旧城冷巷雨未停 提交于 2019-12-12 07:59:08
问题 There are certain common library functions in erlang that are much slower than their c equivalent. Is it possible to have c code do the binary parsing and number crunching, and have erlang spawn processes to run the c code? 回答1: Of course C would be faster, in the extreme case, after optimizations. If by faster you mean faster to run. Erlang would be by far, faster to write. Depending on the speed requirements you have Erlang is probably "fast enough", and it will save you days of searching

Erlang : Tuple List into JSON

旧城冷巷雨未停 提交于 2019-12-12 07:57:58
问题 I have a list of tuples which are http headers. I want to convert the list to a JSON object. I try mochijson2 but to no avail. So I have the following : [{'Accept',"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, {'Accept-Charset',"ISO-8859-1,utf-8;q=0.7,*;q=0.7"}, {'Accept-Encoding',"gzip,deflate"}, {'Accept-Language',"en-us,en;q=0.5"}, {'Cache-Control',"max-age=0"}, {'Connection',"close"}, {'Cookie',"uid=CsDbk0y1bKEzLAOzAwZUAg=="}, {'User-Agent',"Mozilla/5.0 (Macintosh; U

Configuring Erlang to work with SSL

吃可爱长大的小学妹 提交于 2019-12-12 07:49:19
问题 Erlang version: R13B01 Currently I'm struggling trying to make Erlang work with SSL. The programming part was easy, but now starting the system SSL-enabled is not. Following the Erlang SSL documentation: 1 - Made the start_ssl.rel file {release, {"OTP APN 181 01","R13B01"}, {erts, "5.7.2"}, [{kernel,"2.13.2"}, {stdlib,"1.16.2"}, {sasl,"2.1.6"}, {os_mon,"2.2.2"}, {ssl,"3.10.3"}]}. 2 - Executed the following command 1> systools:make_script("start_ssl",[]). According to the documentation,

Ejabberd Clustering not working

那年仲夏 提交于 2019-12-12 07:05:33
问题 I have installed ejabberd on two ubuntu servers in the same network using the binary installers, I have copied the .erlang.cookie file from /etc/ejabberd/bin of ejabberd@node1 (The intended master) to /etc/ejabberd/bin of ejabberd@node2 (the intended slave). When I run the command: ejabberdctl join_cluster 'ejabberd@node1' on ejabberd@node2, I get the following error: Error: {no_ping,ejabberd@node1} When I try to ping ejabberd@node1 using erl console I get a pang . The servers on which both

Using the Erlang client library from Riak in Nitrogen

左心房为你撑大大i 提交于 2019-12-12 06:37:59
问题 This question is a continuation of Including the Erlang client lib which was asked before. I was able to include the library by changing: {mimetypes, ".*", {git, "git://github.com/spawngrid/mimetypes", {branch, master}}}, %% Uncomment the following lines and comment the bottom lines with specific %% tags to always pull the latest versions {nitrogen_core, ".*", {git, "git://github.com/nitrogen/nitrogen_core",{branch, master}}}, to: {mimetypes, ".*", {git, "git://github.com/spawngrid/mimetypes"

RabbitMQ work queue is blocking consumers

久未见 提交于 2019-12-12 06:07:24
问题 I'm following the example here https://www.rabbitmq.com/tutorials/tutorial-two-python.html only in Erlang with amqp_client The full code is here https://github.com/jhw/rabbit_worker As I understand it, to get worker- queue style behaviour you need to define your RabbitMQ topology as follows - 'direct' exchange single queue to which multiple consumers (workers) bind routing key equal to queue name workers to ack' each message pre- fetch count of 1 Now I have this working fine, and can see the