mochiweb

How can I make Webmachine and eredis work together?

青春壹個敷衍的年華 提交于 2019-12-04 15:28:52
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? There are several solutions: register a redis connection locally or globally use a process register like gproc keep the pid of the connection in the

Decode JSON with mochijson2 in Erlang

ⅰ亾dé卋堺 提交于 2019-12-04 12:33:19
问题 I have a var that has some JSON data: A = <<"{\"job\": {\"id\": \"1\"}}">>. Using mochijson2, I decode the data: Struct = mochijson2:decode(A). And now I have this: {struct,[{<<"job">>,{struct,[{<<"id">>,<<"1">>}]}}]} I am trying to read (for example), "job" or "id". I tried using struct.get_value but it doesn't seem to work. Any ideas? 回答1: The data is in {struct, proplist()} format, so here's what you do: {struct, JsonData} = Struct, {struct, Job} = proplists:get_value(<<"job">>, JsonData),

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

点点圈 提交于 2019-12-03 20:51:24
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, { reference_no, timer_object, %% value returned by timer:apply_after/4 amount }). The timer object in

CouchDB as a part of an Erlang release

一个人想着一个人 提交于 2019-12-03 13:25:26
I would like to build and deploy an application which has Django as frontend, YAWS ( appmods ) or Mochiweb/Webmachine as a backend and CouchDB as a datastore. Furthermore, I plan to extensively use CouchDB's ability to replicate in order to provide high fault tolerance for the whole application. I tend to think that in order to achieve this, I must create a single OTP release which has YAWS and CouchDB as Erlang/OTP applications. Does this approach seem to be correct? How can I organize YAWS and CouchDB in terms of OTP applications in order to create a solid production setup? Are there any

Erlang : Tuple List into JSON

孤人 提交于 2019-12-03 12:51:23
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; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"}] And would like this ( a

Decode JSON with mochijson2 in Erlang

不问归期 提交于 2019-12-03 08:16:10
I have a var that has some JSON data: A = <<"{\"job\": {\"id\": \"1\"}}">>. Using mochijson2, I decode the data: Struct = mochijson2:decode(A). And now I have this: {struct,[{<<"job">>,{struct,[{<<"id">>,<<"1">>}]}}]} I am trying to read (for example), "job" or "id". I tried using struct.get_value but it doesn't seem to work. Any ideas? The data is in {struct, proplist()} format, so here's what you do: {struct, JsonData} = Struct, {struct, Job} = proplists:get_value(<<"job">>, JsonData), Id = proplists:get_value(<<"id">>, Job), You can read more about proplists at: http://www.erlang.org/doc

XForwardedSupport for https play! support on Heroku failing

一个人想着一个人 提交于 2019-11-29 04:35:54
I am deploying an app on Heroku and trying to determine whether the request coming in is secure (request.secure). This is initially returning false on heroku because nginx handles the SSL work and communicates over plain http to the app server. So to let play read the headers that let is know it's a secure request I add: XForwardedSupport=127.0.0.1 To application.conf as recommended in the play message boards. However, then all requests (except for images) fail with no error. It seems to be something fundamental happening before it hits the play logs. Has anyone experienced this? I don't think

Introduction to Erlang/OTP production applications deployment

五迷三道 提交于 2019-11-28 16:51:41
问题 I would like to develop and deploy an Erlang/OTP application into production on a VPS. I am pretty familiar with developing Erlang code on a local machine and my question is about deployment. Basically, I would like to know what steps I should take in order to move Erlang code from a local machine to a production server and make it run, i.e. be available for users. Note: I have read some documentation about Erlang and command line, Erlang code module, Erlang releases, but I am still not sure

XForwardedSupport for https play! support on Heroku failing

倖福魔咒の 提交于 2019-11-27 22:29:53
问题 I am deploying an app on Heroku and trying to determine whether the request coming in is secure (request.secure). This is initially returning false on heroku because nginx handles the SSL work and communicates over plain http to the app server. So to let play read the headers that let is know it's a secure request I add: XForwardedSupport=127.0.0.1 To application.conf as recommended in the play message boards. However, then all requests (except for images) fail with no error. It seems to be