mochiweb

How to use application:get_env() in Erlang/OTP?

浪尽此生 提交于 2019-12-24 01:08:32
问题 I created a mochiweb instance src/ |-- Makefile |-- room.erl |-- myserver.app |-- myserver.erl |-- myserver_app.erl |-- myserver_deps.erl |-- myserver_sup.erl |-- myserver_web.erl `-- uuid.erl in myserver_web.erl I am able to access the application config {ok, "0.0.1"} = application:get_key(vsn), However in room.erl , I am not able to access the application config (specifically the env list). undefined = application:get_key(vsn), The supervisor does not start the room, nor do I want it too. I

Mochiweb: Include and compile other libraries

北城余情 提交于 2019-12-13 08:32:20
问题 My app uses Mochiweb. I have noticed that Mochiweb files reside in the myapp/deps/mochiweb directory and rebar compiles them when I run make in the myapp directory. I wanted to add ibrowse to write a few tests which make http requests to my app. So I cloned ibrowse from github to myapp/deps/ibrowse directory. But it seems that Erlang does not know where to get the .beam files for ibrowse and therefore all my tests that use the ibrowse module fail: myapp ebin %%compiled tests reside here,

How to use mochijson to encode data structure in erlang?

梦想与她 提交于 2019-12-12 10:44:52
问题 I am using mochiweb and I don't know how to use its json encoder to deal with complex data structure. What's the differences between mochijson and mochijson2? Is there any good example? I always get the following errors: 46> T6={struct,[{hello,"asdf"},{from,"1"},{to,{a,"aa"}}]}. {struct,[{hello,"asdf"},{from,"1"},{to,{a,"aa"}}]} 47> mochijson2:encode(T6). ** exception exit: {json_encode,{bad_term,{a,"aa"}}} in function mochijson2:json_encode/2 in call from mochijson2:'-json_encode_proplist/2

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

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

Parsing the result obtained from mochiweb_html

纵然是瞬间 提交于 2019-12-06 09:31:59
问题 I would like to parse some content from an html file (no xml). At the moment I retrieve the structure to parse using mochiweb_html: 1> inets:start(). 2> {ok, {Status, Headers, Body}} = httpc:request("http://www.google.com"). 3> {String, Attributes, Other} = mochiweb_html:parse(Body). and the result is something like: {<<"html">>, [{<<"itemscope">>,<<"itemscope">>}, {<<"itemtype">>,<<"http://schema.org/WebPage">>}], [{<<"head">>,[], [{<<"meta">>, [{<<"itemprop">>,<<"image">>}, {<<"content">>,<

mochijson2 or mochijson

我只是一个虾纸丫 提交于 2019-12-05 23:03:45
问题 I'm encoding some data using mochijson2. But I found that it behaves strange on strings as lists. Example: mochijson2:encode("foo"). [91,"102",44,"111",44,"111",93] Where "102", "111", "111" are $f, $o, $o encoded as strings 44 are commas and 91 and 93 are square brakets. Of course if I output this somewhere I'll get string "[102,111,111]" which is obviously not that what I what. If i try mochijson2:encode(<<"foo">>). [34,<<"foo">>,34] So I again i get a list of two doublequotes and binary

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

CouchDB as a part of an Erlang release

▼魔方 西西 提交于 2019-12-04 21:12:06
问题 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

Parsing the result obtained from mochiweb_html

大城市里の小女人 提交于 2019-12-04 15:29:48
I would like to parse some content from an html file (no xml). At the moment I retrieve the structure to parse using mochiweb_html: 1> inets:start(). 2> {ok, {Status, Headers, Body}} = httpc:request("http://www.google.com"). 3> {String, Attributes, Other} = mochiweb_html:parse(Body). and the result is something like: {<<"html">>, [{<<"itemscope">>,<<"itemscope">>}, {<<"itemtype">>,<<"http://schema.org/WebPage">>}], [{<<"head">>,[], [{<<"meta">>, [{<<"itemprop">>,<<"image">>}, {<<"content">>,<<"/images/google_favicon_128.png">>}], []}, {<<"title">>,[],[<<"Google">>]}, .... What is the best way