elixir

Generating initials avatar with Elixir [closed]

拥有回忆 提交于 2019-12-22 09:59:51
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I am working on Elixir and looking to make an avatar service. If the user doesn't have an avatar, want to make one with their initials on it, like so: I really haven't the slightest idea where to start or how to do this. 回答1: You can use ImageMagick to do this. Simply call the

Parametrizing node name in Elixir Exrm

只谈情不闲聊 提交于 2019-12-22 07:09:33
问题 I want to use Exrm with Erlang distributed on a single machine. I need to create multiple releases that differ only with node name. I know, I can configure node name in rel/vm.args , but it will be static. Can I somehow generate multiple releases with different node name? 回答1: I am researching the same issue. A possible approach: The rel/vm.args supports OS environment variables parametrization. So you can do something like ## Name of the node -name ${MY_NODE_NAME} ## Cookie for distributed

Socket won't connect to Endpoint

故事扮演 提交于 2019-12-22 06:56:19
问题 var socket = new Socket("localhost:4000") socket.connect() Returns WebSocket connection to 'ws://localhost:4000/ws' failed: Error during WebSocket handshake: Unexpected response code: 404 But I do have the socket on the /ws endpoint, right? defmodule Sapphire.Endpoint do use Phoenix.Endpoint, otp_app: :sapphire socket "/ws", Sapphire.MomentSocket plug Plug.Static, at: "/", from: :sapphire, gzip: false, only: ~w(css fonts images js favicon.ico robots.txt) if code_reloading? do socket "/phoenix

Phoenix channels: send push to a particular client

点点圈 提交于 2019-12-22 06:48:10
问题 Hi I am trying to reimplement whatsapp functionality using elixir phoenix. I am having a problem figuring out the following: if all people in the chat room has received the message, I want to send the owner of the message status "received" so that he can show double tick sign. However how do you broadcast to one particular client? 回答1: You can solve this via topic per user, this can be easily implemented by pattern matching, notice the security validation also: def join("users:" <> user_id,

Does Elixir support introspection to show function origins?

荒凉一梦 提交于 2019-12-22 06:09:25
问题 If a module import s multiple other modules, it may not be obvious where a given function came from. For example: defmodule Aimable do import Camera import Gun def trigger do shoot # which import brought it in? end end I know there are ways to minimize this kind of confusion: good naming, focused modules, targeted imports like import Gun, only: [:shoot] , etc. But if I come across code like this, is there a way to inspect Aimable and see the origins of the function shoot ? 回答1: You can do

How to use Geo library to create valid Ecto Model changeset?

烈酒焚心 提交于 2019-12-22 04:39:20
问题 I'm trying to use Geo library to store Geo.Point via Phoenix model changeset. My params are: {coordinates: [49.44, 17.87]} or more prefer would be {coordinates: {latitude: 49.44, longitude: 17.87}} In iex console I tried: iex(5)> changeset = Place.changeset(%Place{}, %{coordinates: [49.44, 17.87]}) %Ecto.Changeset{action: nil, changes: %{}, constraints: [], errors: [coordinates: "is invalid"], filters: %{} model: %Myapp.Place{__meta__: #Ecto.Schema.Metadata<:built>, coordinates: nil, id: nil,

How To Negate A Boolean In A Pipeline?

余生长醉 提交于 2019-12-22 04:26:29
问题 Consider the following code: defmodule T do def does_not_contain?(s, t) do s |> not(String.contains?(t)) end end This gives the following error on compilation: ** (CompileError) iex:3: undefined function not/2 I also tried a construct like this: defmodule T do def does_not_contain?(s, t) do s |> String.contains?(t) |> not end end That gives me this error: ** (SyntaxError) iex:4: unexpected token: end I can do something like this which works: defmodule T do def does_not_contain?(s, t) do does

Elixir case on a single line

家住魔仙堡 提交于 2019-12-22 04:06:04
问题 I would like to have the following case on a single line: case s do :a -> :b :b -> :a end The macro case is defined as case(condition, clauses) . The following quote do case s do :a -> :b :b -> :a end end gives: {:case, [], [{:s, [], Elixir}, [do: [{:->, [], [[:a], :b]}, {:->, [], [[:b], :a]}]]]} and from here should be possible to go back to case(s, ???) 回答1: There are two possible ways to do this. One from the answer above is to inline the do end calls obtaining: case s do :a -> :b; :b ->

How to get a variable value from Environment files in Phoenix?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 02:21:11
问题 I'm deploying my first Phoenix Application, and I've specified the values of a variable in my Environment Files ( dev.exs and prod.exs ). Now I'm trying to figure out how to access them in my Controllers. # config/dev.exs config :my_app, MyApp.Endpoint, http: [port: 4000], debug_errors: true, cache_static_lookup: false, my_var: "DEVELOPMENT VALUE" # config/prod.exs config :my_app, MyApp.Endpoint, http: [port: {:system, "PORT"}], url: [host: "example.com"], my_var: "PRODUCTION VALUE" 回答1: Okay

elixir Logger for lists, tuples, etc

*爱你&永不变心* 提交于 2019-12-22 01:40:44
问题 I can use the elixir logger for inspecting strings > str = "string" > Logger.info "Here is a #{str}" [info] Here is a string But when I log a list, it doesn't look pretty > list = [1,2,3,4,5] > Logger.info "Here is a list: #{list}" [info] Here is a list: ^A^B^C^D^E^F When I log keyword list, it errors > kwl = [a: "apple", b: "banana"] > Logger.info "Here is a keyword list: #{kwl}" ** (ArgumentError) argument error (stdlib) :unicode.characters_to_binary([a: "apple", b: "banana"]) (elixir) lib