elixir

Remove a substring/ string pattern of a string in Erlang

笑着哭i 提交于 2020-01-05 10:02:29
问题 I have an xml string like S = "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3/></B>". I want to remove the end tag </B> S2 = "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3/>" How can I achieve this? 回答1: If you only want to remove the specific string literal </B> then getting a sublist will do the trick: S = "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3\"/></B>", lists:sublist(S, 1, length(S) - 4). %%= "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3\"/>"

Why can't I get IEx.pry to work on Windows?

巧了我就是萌 提交于 2020-01-05 07:28:56
问题 I am trying to make IEx.pry work with the following code example: require IEx; defmodule Example do def double_sum(x, y) do IEx.pry hard_work(x, y) end end Example.double_sum(1, 2) When I run it I get the following error: Cannot pry #PID<0.106.0> at lib/example.ex:5. Is an IEx shell running? If you are Windows, you may need to start IEx with the --werl flag. In response I launched iex with --werl and it opened the erlang shell. In the erlang shell I tried to change directories so that I can

Phoenix CSRF token not matching

怎甘沉沦 提交于 2020-01-05 05:26:14
问题 Trying to get ajax working the Phoenix. I get the csrf token by doing the following so i have it: <input type="hidden" id="_csrf_token" name="_csrf_token" value="<%= get_csrf_token() %>"> Then use it like so: $.ajax({ type: "POST", url: "<%= lesson_path @conn, :create %>", beforeSend: function(xhr) { token = $('#_csrf_token').val(); xhr.setRequestHeader('_csrf_token', token ); }, data: data, success: function(data, textStatus, jqXHR) { alert(textStatus); } }); The issue is that the token i

Make Ecto queries more efficient

本秂侑毒 提交于 2020-01-04 14:05:26
问题 I'm trying to see if my current user's teams overlap with the passed in user's teams. I have something that works but I'm curious if it could me more efficient. Here is what I have: user_teams = from( t in MyApp.Team, left_join: a in assoc(t, :accounts), where: p.owner_id == ^user.id or (a.user_id == ^user.id and t.id == a.project_id) ) |> Repo.all current_user_teams = from( t in MyApp.Team, left_join: a in assoc(t, :accounts), where: t.owner_id == ^current_user.id or (a.user_id == ^current

function is undefined or private while should be accessible

我怕爱的太早我们不能终老 提交于 2020-01-04 07:48:20
问题 I'm trying to reach a method from my Accounts domain. I'm able to use any method from the Accounts domain in iex except for the mark_as_admin/1 (the last one). here is the domain defmodule Storex.Accounts do import Ecto.Query, warn: false alias Storex.Repo alias Storex.Accounts.User def create_user(attrs \\ %{}) do %User{} |> User.changeset(attrs) |> Repo.insert() end def get_user!(id) do Repo.get!(User, id) end def new_user() do User.changeset(%User{}, %{}) end def authenticate_user(email,

Elixir GenServer parallel handle_call

≯℡__Kan透↙ 提交于 2020-01-04 06:51:14
问题 There is an application on the Phoenix Framework. There is a need for GenServer, which will check some values. Validation of these values is started from the controller (a request comes from the client, the GenServer value checks, the client receives a response). Once handle_call is synchronous, then what happens when 10 clients call 10 calls handle_call at a time? All 10 calls will be processed in parallel or in the order of the queue? 回答1: GenServer will process only single call other

Elixir GenServer parallel handle_call

≡放荡痞女 提交于 2020-01-04 06:50:10
问题 There is an application on the Phoenix Framework. There is a need for GenServer, which will check some values. Validation of these values is started from the controller (a request comes from the client, the GenServer value checks, the client receives a response). Once handle_call is synchronous, then what happens when 10 clients call 10 calls handle_call at a time? All 10 calls will be processed in parallel or in the order of the queue? 回答1: GenServer will process only single call other

Docker container is killed after ~1 minute

家住魔仙堡 提交于 2020-01-04 01:58:14
问题 I made a very small Phoenix Framework app (only slightly modified from what you get when you run: mix phoenix.new). I've been trying to deploy it in a Docker container. It works fine while the container is running, but it always dies within a minute of startup with a message of "Killed." Whether I make requests to it or not does not seem to matter. I tried watching the docker events, and got the following: $ docker events 2016-04-09T16:24:02.538602484-04:00 container create

Best practice to pass data from Phoenix to Javascript

此生再无相见时 提交于 2020-01-03 17:32:09
问题 I see 3 ways of doing this. Using <%= %> inside <script> in *.html.eex Use channels to pass data to Javascript Build a json api #1 seems the easiest but I couldn't find or think of a good way to do it yet. Note: real-time update is not my requirement. 回答1: I would never use a <script></script> for that, in my projects I have this pattern: <!-- Layout --> <div id="config" data-environment="..." ></div> I always provide the current environment in the master layout, I have a config.js file with

Best practice to pass data from Phoenix to Javascript

被刻印的时光 ゝ 提交于 2020-01-03 17:32:06
问题 I see 3 ways of doing this. Using <%= %> inside <script> in *.html.eex Use channels to pass data to Javascript Build a json api #1 seems the easiest but I couldn't find or think of a good way to do it yet. Note: real-time update is not my requirement. 回答1: I would never use a <script></script> for that, in my projects I have this pattern: <!-- Layout --> <div id="config" data-environment="..." ></div> I always provide the current environment in the master layout, I have a config.js file with