How to pass an anonymous function to the pipe in Elixir
It will look bit weird but must work: def boundary do :crypto.rand_bytes(8) |> Base.encode16 |> (&(“——–FormDataBoundary” <> &1)).() end
It will look bit weird but must work: def boundary do :crypto.rand_bytes(8) |> Base.encode16 |> (&(“——–FormDataBoundary” <> &1)).() end
You can use Ecto.Adapters.SQL.to_sql/3: iex> Ecto.Adapters.SQL.to_sql(:all, Repo, Post) {“SELECT p.id, p.title, p.inserted_at, p.created_at FROM posts as p”, []} This function is also available under the repository with name to_sql if you’re using a SQL based adapter: iex> Repo.to_sql(:all, Post) {“SELECT p.id, p.title, p.inserted_at, p.created_at FROM posts as p”, []} The query can be any struct … Read more
On Ecto 2.0 (beta) with Postgres, you can use Ecto.Adapters.SQL.query() (current docs, 2.0-beta2 docs) to execute arbitrary SQL; in addition to a list of the rows themselves (“rows“), it happens to return a list of column names (“columns“). In the below example, I run a custom query with no parameters, convert the result’s column names … Read more
Protocol is type/data based polymorphism. When I call Enum.each(foo, …), the concrete enumeration is determined from the type of foo. Behaviour is a typeless plug-in mechanism. When I call GenServer.start(MyModule), I explicitly pass MyModule as a plug-in, and the generic code from GenServer will call into this module when needed.
You have to name your nodes and use the same cookie on both nodes. In machine 1: iex –name node1@machine1.com –cookie a_cookie_string In machine 2: iex –name node2@machine2.com –cookie a_cookie_string Now the two machines can communicate. To test it, you can do something like this, on machine1: iex(node1@machine1.com)1> Node.connect :”node2@machine2.com” true iex(node1@machine1.com)2> print_node_name = fn … Read more
You’ve already given a pretty good summary of the differences, so in any conditions where one of those things is important it should help you decide on which to use. The way to think about it is that Lists are open-ended data structures and their size can vary at runtime while Tuples have a constant … Read more
You can now do that with Ecto.Migration.rename/3: rename table(:posts), :title, to: :summary
The get_env function is part of the Application module from the Elixir/Erlang core. This function returns the value for a specific key in the app’s environment. Considering your configuration, you would access the title property this way: Application.get_env(:my, My.Endpoint)[:title] The third parameter is for passing a default value when the config key doesn’t exist.
In versions of Elixir prior to 1.2 when using functions in a pipeline, you would either have to use a monad library or nest case statements (which could be refactored using private functions, but still would end up being verbose). with/1 allows a different way to solve this problem. Here is an example from the … Read more
Ah, the famous pokemon route: get “/*path” You will find the paths inside conn.params[“path”] or as conn.path_info.