elixir

Many-to-Many with ECTO and put_assoc/4

与世无争的帅哥 提交于 2019-12-21 21:42:18
问题 I try associate 2 existing Many-to-Many records with ECTO and put_assoc/4 but won't remove elements when try update. Basically i have projects and users . for manage the access of users to projects i have the table "user_project". def Project do schema "project" do ... # users (if user_type is :admin) many_to_many( :users, User, join_through: "user_project" ) ... end end def User do schema "user" do ... # users (if user_type is :admin) many_to_many( :projects, User, join_through: "user

Elixir Hound wait for page to load

我们两清 提交于 2019-12-21 17:52:26
问题 I'm submitting a login form and trying to capture the HTML afterwards using elixir / hound. After submitting I run page_source and get nothing. If I wait for a second (for the page to finish loading) then I get back the html. Is there a way to make hound wait till the page is finished loading? I'm currently doing: :timer.sleep(2000) as a work around, hoping for a better way :/ 回答1: This is what I do: Create a function that repeatedly checks for a test condition every 100ms, in this case I'm

How do I load an elixir library in a simple elixir script?

谁说胖子不能爱 提交于 2019-12-21 11:34:09
问题 In ruby scripts, I could simply do: require 'some-gem' SomeGem.do_something! How can I do something similar in elixir exs scripts without creating a brand new mix project? So far I've searched google on ways to do this, and read a few blog posts (such as this), but can't figure out a proper (read 'simple') way to do this. Specifically, I want to use HTTPoison in my elixir script. 回答1: There are no global package installs in Elixir like there are in Ruby. While it might be technically possible

Elixir mix auto acknowledge

无人久伴 提交于 2019-12-21 08:17:59
问题 I want to run tests of my Phoenix app on Travis-CI. Log excerpt: $ MIX_ENV=test mix do deps.get, compile, test Could not find hex, which is needed to build dependency :phoenix Shall I install hex? [Yn] When it comes to fetching and installing dependencies, it asks if it should install hex . I was wondering if I can pass a --yes option to mix so that it doesn't ask but just installs? 回答1: As with any unix command, you could pipe yes into the mix command: yes | MIX_ENV=test mix do deps.get,

How to get minimum and maximum value of each type in elixir

别来无恙 提交于 2019-12-21 07:57:18
问题 How to get minimum and maximum value of each type in elixir? for example an integer, float and maximum possible length of a string. I know that in C it's defined in limits.h as INT_MIN , INT_MAX and so on. Where the documentation about the limit of those types in elixir? 回答1: Elixir (Erlang actually) uses bignum arithmetic, which is a kind of arithmentic used in computer science where (quoting Wikipedia) calculations are performed on numbers whose digits of precision are limited only by the

How to post a collection of ids with multiple select form field with phoenix_html

﹥>﹥吖頭↗ 提交于 2019-12-21 06:49:15
问题 I’m trying to get multiple select to work with the phoenix_html form helpers <%= select f, :challenge_ids, ["foo": "1","bar": "2","baz": "3"], class: "form-control", multiple: "" %> but only the id of the last selected item gets sent to the server in the params %{"challenge_ids" => "3", "content" => "", "name" => ""} I have also tried changing :challeng_ids to :"challenge_ids[]" trying to get something similar to a rails output for a multiple select tag, but this didn't make any difference

How do I used matched arguments in elixir functions

扶醉桌前 提交于 2019-12-21 05:07:29
问题 Say I have two use cases for a function. Do something with users that have a subscription and something with users that don't have a subscriptions. def add_subscription(subscription_id, %User{subscription: nil}) # Do something with user here. And def add_subscription(subscription_id, user) How do I do pattern matching like this and also still use the user in the first function? Thanks! 回答1: You can bind the function argument to a variable: def add_subscription(subscription_id, %User

How to get the memory location of a variable in Elixir?

Deadly 提交于 2019-12-21 04:55:13
问题 A fact that we know about Elixir is that data structures that lives in memory are immutable, and variables are just pointers to those data structures. Is there a way for us to get the memory address of a variable is pointing to, instead of the content in that memory location (i.e. the dereferenced value of the variable)? For me, the purpose of doing so is that we can learn about how Elixir/Erlang manages memory when dealing with duplicated values, like two same character lists, or especially

Access project version within elixir application

自古美人都是妖i 提交于 2019-12-21 03:18:22
问题 I have an elixir project with a defined version. How can I access this from within the running application. in mix.exs def project do [app: :my_app, version: "0.0.1"] end I would like to be access this version number in the application so I can add it to the returned message. I looking for something in the env hash like the following __ENV__.version # => 0.0.1 回答1: Here's a similar approach to retrieve the version string. It also relies on the :application module, but is maybe a bit more

Elixir call Axis2 Java SOAP Web Service with detergentex and detergent

☆樱花仙子☆ 提交于 2019-12-20 18:07:01
问题 From Elixir, I am trying to call a SOAP Web Service with detergentex, which is a wrapper around the Erlang library detergent. I can call the SOAP Web Service in the example on the detergent home page with no problems: http://www.webservicex.net/convertVolume.asmx?WSDL Parameters: wsdl_url = "http://www.webservicex.net/convertVolume.asmx?WSDL" action = "ChangeVolumeUnit" parameters = ["100","dry","centiliter"] However when trying to call an Axis2 Java SOAP Web Service I am having some problems