elixir

AJAX request abort on large query string Elixir Plug

 ̄綄美尐妖づ 提交于 2019-12-11 02:12:50
问题 I am sending 2 large query string in AJAX requests, which are basically, a Base64 encoding of a jpeg(s). When the Camera is not a high-resolution one, AJAX request doesn't abort. At first, I thought its a Nginx issue, Because I was getting an error as request entity too large I resolved it, Then I made changes to my Plug as plug Plug.Parsers, parsers: [ :urlencoded, {:multipart, length: 20_000_000}, :json ], pass: ["*/*"], query_string_length: 1_000_000, json_decoder: Poison After defining

Phoenix on Heroku: error R10

懵懂的女人 提交于 2019-12-11 01:59:19
问题 Running into an odd error with Phoenix on Heroku, where it doesn't seem to bind to the port properly. Running into a situation where phoenix is not binding to $PORT. Heroku's log: 2016-03-25T22:22:54.716907+00:00 heroku[web.1]: State changed from crashed to starting 2016-03-25T22:23:03.156662+00:00 heroku[web.1]: Starting process with command mix phoenix.server 2016-03-25T22:23:07.985368+00:00 app[web.1]: [info] Running AppName.Endpoint with Cowboy using http on port 4000 2016-03-25T22:23:10

Rounding a Decimal number in Elixir

雨燕双飞 提交于 2019-12-11 01:38:28
问题 I have this Decimal number Elixir: c1 = Decimal.div(a1, b1) # => #Decimal<0.006453859622556080696687234694> How can I round it to a shorter number with a smaller number of digits after the decimal point? 回答1: As @Dogbert said in comment - the easiest way to just round a number: iex> alias Decimal, as: D nil iex> d = D.div(D.new(1), D.new(3)) #Decimal<0.3333333333333333333333333333> iex> D.round(d, 5) #Decimal<0.33333> EDIT: Below is not entirely true!! Precision is number of digits in

post to slack api with httpotion elixir

房东的猫 提交于 2019-12-11 01:23:30
问题 Just dealing with a syntax error here. Trying to send the payload in the body of the HTTPotion request. Trying to send the data as json, but not really sure where I'm going wrong. HTTPotion.post "https://hooks.slack.com/services/a00000/b0000/XXXXXXX", [body: "{'channel': '#general', 'username': 'thedanotto', 'text': 'Pokemon are scary!', 'icon_emoji': ':ghost:'}", ["Content-Type": "application/json"]] => ** (SyntaxError) iex:1: syntax error before: '[' Any ideas? 回答1: You're missing headers:

Getting user input in an elixir Task

喜欢而已 提交于 2019-12-11 01:04:50
问题 I'm trying to write a simple elixir program that is able to react to user input. My problem is that reading from stdio doesn't seem to work from Tasks. If my whole idea is silly please show me an example on how it's done. I can't find anything in the web I broke my problem down to a simple example: t = Task.async((fn->IO.gets "what?" end)) %Task{owner: #PID<0.65.0>, pid: #PID<0.80.0>, ref: #Reference<0.0.2.135>} The Task is started: iex(4)> pid=Map.get(t, :pid) #PID<0.80.0> iex(5)> Process

Record real IP address on using phoenix in the nginx upstream

别说谁变了你拦得住时间么 提交于 2019-12-11 00:09:50
问题 I have an upstreaming phoenix app, like that: upstream my_app { server localhost:3001; } server { root /var/www/my_app/priv/static; listen 80; location / { proxy_pass http://my_app; } } I want to track real IP address, but I don't know how to do it via standard phoenix conn.remote_ip because its always return 127.0.0.1 (because nginx proxies this query to phoenix). How can I fetch real ip address? 回答1: There is x-forwarded-for header designed especially for that! # nginx proxy_set_header X

Phoenix remove [debug] logging

对着背影说爱祢 提交于 2019-12-10 22:12:53
问题 When running a phoenix server, I am getting [debug] logs which I would like to not have (the logs in blue). How can I alter my config to get rid of these 回答1: You can set the log level in dev to be higher than debug which will make Logger not print any debug messages. The level just above debug is info. You can set that by adding this to config/dev.exs : config :logger, level: :info If you already have a config :logger line, you can just add level: :info at the end of it. You will have to

Referencing piped value in Elixir

最后都变了- 提交于 2019-12-10 22:09:17
问题 I want to count the number of word-occurrences in a string. The implementation is questionable, but lets use it to demonstrate my problem: def count(sentence) do words = String.split(sentence) occurrences = Enum.map(words, fn w -> {w, Enum.count(words, &(&1 == w))} end) Map.new(occurrences) end I would like to achieve the same result as above, but using pipes instead of intermediate result variables: def count(sentence) do sentence |> String.split |> Enum.map(fn w -> {w, Enum.count(???)} end)

Set default application configs for Elixir packages

血红的双手。 提交于 2019-12-10 21:45:46
问题 I'm writing an Elixir package, and I want to specify a default application configuration (that the user can override by specifying custom values in their config.exs ). I was originally putting them in my project's config.exs until I realized that the config file won't be loaded for projects that depend on this library. The config file itself tells you that: This configuration is loaded before any dependency and is restricted to this project. If another project depends on this project, this

HTTP POST multipart with named file

六月ゝ 毕业季﹏ 提交于 2019-12-10 20:38:38
问题 I need to send a (multipart) HTTP request which contains a file which is named. This seems to be harder to achieve than I imagined... I've tried to figure out a way to do it with HTTPoison, but I can't get it to use a name other than "file". I've tried using Hackney directly, but there doesn't appear to be an option, and there definitely isn't a test on either of these which shows this functionality. I've also had a look at ibrowse and HTTPotion but can't find anything which seems useful (my