elixir

HTTPoison post request Timeouts Eixir

走远了吗. 提交于 2019-12-24 03:44:06
问题 We are using a filesystem written in Go, seaweedfs. It's being used a REST API on port 8888 to post Files. The issue we are having is HTTPoison timeouts. We post to a file, again and again, we get HTTPoison request timeout. Few facts: File do get updated on seaweedfs we can see the modified date. HTTPoison request response is always timeout I have tried with curl POST. for ((i=1;i<=100;i++)); do curl -F file=@00_13_000.jpg -X POST http://188.xx.xx.xx.217:8888/everc-dupzo/snapshots/recordings

How exactly Erlang receive expression works?

你说的曾经没有我的故事 提交于 2019-12-24 01:51:31
问题 Why receive expression is sometimes called selective receive? What is the "save queue"? How the after section works? 回答1: There is a special "save queue" involved in the procedure that when you first encounter the receive expression you may ignore its presence. Optionally, there may be an after-section in the expression that complicates the procedure a little. The receive expression is best explained with a flowchart: receive pattern1 -> expressions1; pattern2 -> expressions2; pattern3 ->

Use HTTPoison to initialize a module attribute

无人久伴 提交于 2019-12-24 01:46:08
问题 I am trying to do initialize a module attribute like this response = HTTPoison.get! url {:ok, response} = Poison.decode(response.body) @attr response I have done it before with a file, something like this: @external_resource file = Path.join([__DIR__, "file.txt"]) Module.register_attribute __MODULE__, :attr, accumulate: true for line <- File.stream!(file, [], :line) do @attr line ... Is not possible to do the same with HTTPoison and fetching the response of an API? I am receiving this error:

elixir+hex - getting hex error for ranch_proxy_protocol ssl:ssl_accept 3 deprecated

无人久伴 提交于 2019-12-24 01:10:37
问题 enter code here I am running below command mix ecto.create && mix ecto.migrate which gives an error ===> Compiling ranch_proxy_protocol ===> Compiling src/ranch_proxy_ssl.erl failed src/ranch_proxy_ssl.erl:90: ssl:ssl_accept/3: deprecated; use ssl:handshake/3 instead ** (Mix) Could not compile dependency :ranch_proxy_protocol, "/Users/a5634160/.mix/rebar3 bare compile --paths "/Users/a5634160/Documents/parc_web/pfom/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency

Elixir doctest fails for function that returns random values

萝らか妹 提交于 2019-12-24 01:07:05
问题 I have a function in Elixir that produces three random RGB tuples in a list. defmodule Color do @doc """ Create three random r,g,b colors as a list of three tuples ## Examples iex> colors = Color.pick_color() iex> colors [{207, 127, 117}, {219, 121, 237}, {109, 101, 206}] """ def pick_color() do color = Enum.map((0..2), fn(x)-> r = Enum.random(0..255) g = Enum.random(0..255) b = Enum.random(0..255) {r, g, b} end) end When I run my tests, my doctests fail. The resulting list of tuples are

Poison.Encoder how to preload associations?

我们两清 提交于 2019-12-24 00:59:58
问题 I have the Ecto model below. When I try to render I get an error. How can I modify the @derive so it will preload? Or do I have to write out the implementation? What is the recommended way of dealing with this? ** (RuntimeError) cannot encode association :tilemap_layers from MyProject.Tilemap to JSON because the association was not loaded. Please make sure you have preloaded the association or remove it from the data to be encoded The model is here: defmodule MyProject.Tilemap do use

Bootstrap styled button not being applied to Phoenix delete link

瘦欲@ 提交于 2019-12-24 00:54:49
问题 Elixir version: 1.3.2 Phoenix version: 1.2.1 NodeJS version: 4.4.6 NPM version: 3.10.6 Brunch version: 2.7.4 Operating system: Mac OSX I am trying to create what suppose to be a simple link using Phoenix's link helper function. <li><%= link "Logout", to: session_path(@conn, :delete, user), method: :delete %></li> renders <form action="/logout/1" class="link" method="post"> <input name="_method" type="hidden" value="delete"> <input name="_csrf_token" type="hidden" value="VhxiLApJElIS...removed

Get a list of all elixir modules in IEx

一世执手 提交于 2019-12-24 00:43:57
问题 To get a list of all functions on a module in IEx I can run: Map.__info__(:functions) # or Enum.__info__(:functions) Using the {Module}.__info__(:functions) format. How can I get a list of all the standard lib modules? 回答1: From IEx you can type : + Tab to get a list of all available modules. 回答2: If you want to get all loaded Elixir modules, without erlang modules, run the following in a clean IEx shell: :code.all_loaded() |> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end) |> Enum.map

Phoenix Channels - broadcasting from controller - how to find current_user?

大城市里の小女人 提交于 2019-12-24 00:34:16
问题 I have an app where I broadcast some submissions for forms in the submission_controller, like this: Formerer.Endpoint.broadcast("forms:#{form.id}", "new_submission", payload) However, what I try to do now, is to make sure that only the current_user has access to the submissions broadcasted for its forms. (eg, current_user will have no way to see the submission for "forms:2" if form 2 belongs to another user). I manage to do this in the channel join action by filtering the forms only for the

How do I call an anonymous function inside Enum.map

本小妞迷上赌 提交于 2019-12-23 23:52:05
问题 I am learning Elixir and I am working on Project Euler to try to strengthen my skills in Elixir. Right now I have this code fib = fn a,b,0 -> a a,b,n -> fib.(b, a+b, n-1) end IO.puts Enum.sum(Enum.filter(Enum.map(1..50, fn n -> fib.(0,1,n) end), even and fn(x) -> x < 4000000 end)) But when I run this code I get: undefined function fib/0 (elixir) src/elixir_fn.erl:33: anonymous fn/3 in :elixir_fn.expand/3 (stdlib) lists.erl:1238: :lists.map/2 (stdlib) lists.erl:1238: :lists.map/2 (elixir) src