erlang

how do we efficiently handle time related constraints on mnesia records?

℡╲_俬逩灬. 提交于 2019-12-05 06:49:12
问题 i am writing records into mnesia which should be kept there only for an allowed time (24 hours). after 24 hours, before a user modifies part of them, the system should remove them automatically. forexample, a user is given free airtime (for voice calls) which they should use in a given time. if they do not use it, after 24 hours, the system should remove these resource reservation from the users record. Now, this has brought in timers. an example of a record structure is: -record(free_airtime

Erlang: priority receive

感情迁移 提交于 2019-12-05 06:42:51
Priority receive in Erlang can easily be implemented as follows: prio() -> receive {priority, X} -> X after 0 -> receive X -> X end end. I am reading a paper called Priority Messaging made Easy in which they describe the following problem: The main problem with the [code] example [above], is that we do not take into consideration that when evaluation is resumed from the inner blocking receive we may have more than one message in the mailbox. In a worst case scenario, all but the first, of potentially a huge number, of elements could be priority messages. In this scenario we would actually have

Erlang : Mnesia : Updating a single field value in a row

一世执手 提交于 2019-12-05 05:47:07
I have an mnesia table with three fields, i, a and b, created using the record -record(rec, {i, a,b}). Now I insert a row into the table as: mnesia:transaction( fun() -> mnesia:write("T", #rec{i=1, a=2, b=3}, write) end ). Now what do I do if I want to update this row, and change only the value of a to 10, while leaving i and b with the same values? Is there any SQL equivalent like " UPDATE T SET a=10 WHERE i=1 "? If I do something like this: mnesia:transaction( fun() -> mnesia:write("T", #rec{i=1, a=10}, write) end ) The row is stored as: {rec,1,10,undefined} The value of this function will

How do I modify a record in erlang?

孤街浪徒 提交于 2019-12-05 05:12:32
I to need modify the values {place} and {other_place} in the op record. #op{ action = [walk, from, {place}, to, {other_place}], preconds = [[at, {place}, me], [on, floor, me], [other_place, {place}, {other_place}]], add_list = [[at, {other_place}, me]], del_list = [[at, {place}, me]] } But erlang don´t allow modifying variables. Is there a data type for that? erlang doesn't let you modify variables it is true. But nothing prevents you from making modified copies of a variable. Given your record: Rec = #op{ action = [walk, from, {place}, to, {other_place}], preconds = [[at, {place}, me], [on,

Escript: setting code path relative to script directory

夙愿已清 提交于 2019-12-05 04:35:12
When I try to set a relative code path in a escript with -pz like this #!/usr/bin/env escript %% -*- erlang -*- %%! -pz ../dir-of-some-beams The path is interpreted relative to the directory from where I run the escript from, which renders it useless for setting the path relative to the script location. My current "workaround" is using a absolute path which is annoying since all this is part of a repository and I don't want it to be location dependent. So how can I set the code path relative to the directory the escript is located in? Just found it out myself: At the beginning of main add code

A good OpenID implementation in Erlang?

穿精又带淫゛_ 提交于 2019-12-05 04:15:27
问题 I'm looking for a good (Or at least working) implementation of OpenID in erlang. I've looked at several different solutions, but non of them are working 100%. 回答1: Have your tried eopenid? http://github.com/etnt/eopenid You can contact Tobbe via his blog if you find some problems with it: http://www.redhoterlang.com/entry/be023e5181553216197369bbe32c4039 回答2: So far as I know, eopenid supports only OpenID 1.1. I have some code for doing OpenID 2.0, parts of which are based on eopenid, at http

How to develop custom functions on top of Ejabberd?

て烟熏妆下的殇ゞ 提交于 2019-12-05 03:27:09
I'm developing a real time chat app. After searching around for a while, I found Ejabberd and Erlang is a good option. The question is the Ejabberd is not providing all the functions I need. I need some custom features such as location based matching and anonymous login. So how to development custom functions on top of Ejabberd? write modules for it? or develop another standalone server app (web or other kind of server app) to interact with it? update: another concern is the way we add custom functions/features should be scalable. You can write your custom modules which hook up to events in

Why use OTP with erlang?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 03:24:00
As the question said: What benefits brings using the OTP design principles when developing with erlang? (I am developing a server which will just receive commands and send responses) OTP is a battle-hardened set of design elements and idioms used in the creation of, as Jonas said, fault-tolerant systems among other things (like flexibility, live updates, etc.). In brief you want to use it for these environments, or environments that may grow into these, because a lot of the blood, sweat and tears of creating reliable, stable systems in Erlang is baked into the OTP behaviours and architecture.

how to execute system command in erlang and get results - unreliable os:cmd/1

血红的双手。 提交于 2019-12-05 03:14:36
问题 When I try to execute following command that returns error or doesn't exit on Windows - I always get empty list instead of error returned as string so for example: I get: [] = os:cmd("blah"). instead of something like "command not found" = os:cmd("blah"). In linux - everything works as expected so I get "/bin/sh: line 1: blah: command not found\n" Therefore I cannot rely on that function when I need to know how execution finished etc. Please suggest some general way how to execute command and

RabbitMQ搭建过程-基于Ubuntu16.04

╄→гoц情女王★ 提交于 2019-12-05 03:14:36
安装参考:官方文档 http://www.rabbitmq.com/install-debian.html#apt Installing Erlang Packages Signing Key In order to use the repository, add a key used to sign RabbitMQ releases to apt-key: wget -O - 'https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc' | sudo apt-key add - This will instruct apt to trust packages signed by that key. Source List File As with all 3rd party Apt (Debian) repositories, a file describing the repository must be placed under the /etc/apt/sources.list.d/ directory. /etc/apt/sources.list.d/bintray.erlang.list is the recommended location. The file should have