elixir

Nerves Project Circuits SPI Clock not initialised

笑着哭i 提交于 2021-01-05 07:23:04
问题 I cannot get the SPI to work. I am trying to interface an IC mcp2515. It is an SPI to CAN interface. I probed the CE pins (GPIO 8 and GPIO 7) and SCLK (GPIO 11) with the oscilloscope but got nothing. these are deps defp deps do [ {:nerves, "~> 1.6.3", runtime: false}, {:shoehorn, "~> 0.6.0"}, {:ring_logger, "~> 0.8.1"}, {:toolshed, "~> 0.2.13"}, {:vintage_net_wizard, "~> 0.4.0"}, {:circuits_uart, "~> 1.4"}, {:circuits_gpio, "~> 0.4.6"}, {:nerves_leds, "~> 0.8.1"}, {:circuits_spi, "~> 0.1.5"},

Elixir comprehension returning a star character '*'

允我心安 提交于 2021-01-05 06:24:10
问题 I have a list of Persona models being returned in p.followings and I want to extract the followed_id field from this list of models into a separate list. p.followings returns... [ %Poaster.Personas.Following{ __meta__: #Ecto.Schema.Metadata<:loaded, "followings">, followed: %Poaster.Personas.Persona{ __meta__: #Ecto.Schema.Metadata<:loaded, "personas">, background_image_url: nil, bio: "ASDF", followings: #Ecto.Association.NotLoaded<association :followings is not loaded>, id: 42, inserted_at:

What does “&1” mean in elixir function?

孤街醉人 提交于 2021-01-02 23:03:24
问题 Given this function, what does &1 refer to? Enum.map [1, 2, 3, 4], &(&1 * 2) 回答1: &1 refers to the first argument the callback function would receive. The ampersand by itself ( & ) is a shorthand for a captured function. This is how you could expand that function. Enum.map([1, 2, 3, 4], fn x -> x * 2 end) fn -> is equal to &(... x -> x is equal to ...(&1 A quick reference can be found here 回答2: The &(1 + &1) syntax in elixir is simply another way to write an anonymous function . So given the

What does “&1” mean in elixir function?

泄露秘密 提交于 2021-01-02 22:59:16
问题 Given this function, what does &1 refer to? Enum.map [1, 2, 3, 4], &(&1 * 2) 回答1: &1 refers to the first argument the callback function would receive. The ampersand by itself ( & ) is a shorthand for a captured function. This is how you could expand that function. Enum.map([1, 2, 3, 4], fn x -> x * 2 end) fn -> is equal to &(... x -> x is equal to ...(&1 A quick reference can be found here 回答2: The &(1 + &1) syntax in elixir is simply another way to write an anonymous function . So given the

What does “&1” mean in elixir function?

懵懂的女人 提交于 2021-01-02 22:57:13
问题 Given this function, what does &1 refer to? Enum.map [1, 2, 3, 4], &(&1 * 2) 回答1: &1 refers to the first argument the callback function would receive. The ampersand by itself ( & ) is a shorthand for a captured function. This is how you could expand that function. Enum.map([1, 2, 3, 4], fn x -> x * 2 end) fn -> is equal to &(... x -> x is equal to ...(&1 A quick reference can be found here 回答2: The &(1 + &1) syntax in elixir is simply another way to write an anonymous function . So given the

Get output of a specific step in github actions

Deadly 提交于 2020-12-30 08:46:36
问题 I have this file of GitHub action which runs tests, but now I am integrating slack notification in it. I want to get the output of the Run tests step and send it as a message in the slack step - name: Run tests run: | mix compile --warnings-as-errors mix format --check-formatted mix ecto.create mix ecto.migrate mix test env: MIX_ENV: test PGHOST: localhost PGUSER: postgres - name: Slack Notification uses: rtCamp/action-slack-notify@master env: SLACK_MESSAGE: Run tests output SLACK_TITLE: CI

Why doesn't the file_input in the form on a Phoenix LiveView return a %Plug.Upload{}?

爱⌒轻易说出口 提交于 2020-12-30 07:58:25
问题 I have a form in a Phoenix LiveView that contains a file_input . I want to use it to allow a user to upload an image. I'm having trouble understanding what the form is sending to my backend, and what I can do with it. I expected a %Plug.Upload{} representation of the image file, as described in documentation, but instead I just get "[object File]" . Note that I am not backing the form with a changeset, because I am not using Ecto: <%= f = form_for :post, "#", phx_submit: :create_post, phx

Elixir Jason encode struct with tuple

白昼怎懂夜的黑 提交于 2020-12-30 06:42:49
问题 I have a struct which already has @derive Jason.Encoder but some fields in that struct are tuples, and for this reason cannot encode the struct, how can I fix that :/ UPDATE I have used the approach that mentioned below with implementing a protocol. One important thing to note about this approach is that it will change the encoding for the whole project, just be careful with that ! 回答1: Have a look at the documentation for how you need to implement the encode/2 function: https://hexdocs.pm

Phoenix Framework - page titles per route

拥有回忆 提交于 2020-12-29 06:23:53
问题 In the Phoenix Framework is there a common technique for setting a page title based on a route/path. Or is this just a matter of calling assign(:page_title, "fred") at the right point inside my routed function? Update I ended up implementing a variation of @michalmuskala's solution. I pass up the action name instead of @view_template : <title><%= @view_module.title(action_name(@conn), assigns) %></title> Then in the view module the code looks like this: def title(:show, assigns), do: assigns

Add interval to timestamp using Ecto Fragments

倖福魔咒の 提交于 2020-12-23 14:20:49
问题 I want to write the following query in a phoenix application using Ecto fragments: select * from ( select id, inserted_at + interval '1 day' * expiry as deadline from friend_referral_code ) t where localtimestamp at time zone 'UTC' > deadline The value of expiry is an integer value that represents number of days. What I've got so far is something like this: query = from frc in FriendReferralCode, where: fragment("localtimestamp at time zone 'UTC'") > fragment("? + INTERVAL '1' * ?", frc