elixir

GenServer with 1 HTTP request per second

核能气质少年 提交于 2021-01-29 17:12:40
问题 I have made this genserver defmodule Recorder do use GenServer def start_link(args) do id = Map.get(args, :id) GenServer.start_link(__MODULE__, args, name: id) end def init(state) do schedule_fetch_call() {:ok, state} end def handle_info(:jpeg_fetch, state) do spawn(fn -> IO.inspect("I am being called") IO.inspect(DateTime.utc_now()) Fincher.request(:get, state.url) |> IO.inspect() end) schedule_fetch_call() {:noreply, Map.put(state, :run, true)} end defp schedule_fetch_call do Process.send

Elixir: Configure a mix project to always print charlists as lists?

老子叫甜甜 提交于 2021-01-29 11:27:30
问题 In testing my Phoenix app, I keep running into situations where I'm comparing lists of expected versus actual record IDs. Errors are tedious to interpret because Elixir keeps printing the integer lists as charlists, so my test output looks like: Assertion with == failed code: assert H.sort(Enum.map(list1, &(&1.id()))) == H.sort(Enum.map(list2, &(&1.id()))) left: 'stu' right: 'st' This is nudging me to rewrite my tests to avoid comparing lists of integers, which is tolerable, but it's a shame

Location for a Phoenix helper in a hex package

僤鯓⒐⒋嵵緔 提交于 2021-01-29 09:45:54
问题 I created an alternative phx.gen.html which creates templates with TailwindCSS. It works fine. I'd like to share it by creating a Hex package phx_tailwind_generators . Here is what I have so fare: $ phx_tailwind_generators:main> tree . ├── README.md ├── lib │ ├── phx_tailwind_generators.ex ├── mix.exs ├── priv │ └── templates │ └── tailwind.gen.html │ ├── controller.ex │ ├── controller_test.exs │ ├── edit.html.eex │ ├── form.html.eex │ ├── index.html.eex │ ├── new.html.eex │ ├── show.html.eex

Running mix deps.get throws :erlang.binary_to_atom argument error

狂风中的少年 提交于 2021-01-29 09:31:58
问题 I'm building a Nerves project and am attempting to verify my custom firmware will be built with the main Nerves application following the instructions here. I've set up a UI project with Phoenix and have the custom image in its own directory under a project directory. The main Nerves project is here and the custom firmware is here I've set my MIX_TARGET equal to the custom image name (rpi0_wiringPi) and when running: mix deps.get I get the error * (ArgumentError) argument error :erlang.binary

Why does for x <- 3..4, do: x * 3 return '\t\f' in Elixir? [duplicate]

余生长醉 提交于 2021-01-29 06:41:50
问题 This question already has answers here : Elixir lists interpreted as char lists (3 answers) Closed last month . In Elixir, why does the comprehension for x <- 3..4, do: x * 2 result in [6, 8] but for x <- 3..4, do: x * 3 results in '\t\f' ? I'm executing this in the iex repl. 回答1: This is one of the most confusing gotchas in Elixir: the "humanizing" of charlists. See this post for a question revolving around this same issue. Charlists are lists of integer codepoints, used to represent un

Elixir - find sub-bitstring within larger bitstring

久未见 提交于 2021-01-28 20:34:05
问题 How would I go about finding if a sub-bitstring is present with another bitstring in Elixir? I need to verify that bitstring X exists somewhere within bitstring Y for testing purposes. Is there a simple way to do this with existing functions? x = "bar" y = "foo bar baz" some_substring_function(x, y) with some_substring_function returning a truthy value. Thanks in advance! 回答1: You can use the =~ operator: iex> "hello world" =~ "hello" true The String module also has some convenience functions

could not compile dependency :salty, “mix compile” failed

…衆ロ難τιáo~ 提交于 2021-01-28 11:54:09
问题 I am compiling my application with mix compile and there an error is occurring for the dependency salty . I have already added the dependency salty and libsodium . But still error is not resolved. this is my mix.exs file with all the dependencies. defp deps do [ {:poison, "~> 3.0", override: true}, {:syndicate, in_umbrella: true}, {:xarango, "~> 0.7.0"}, {:ecto, "~> 3.1"}, {:phoenix, "~> 1.4.0"}, {:gettext, "~> 0.11"}, {:cowboy, "~> 2.6"}, {:joken, "~> 2.0"}, {:ecto_sql, "~> 3.0"}, {:jason, "

Using fragment & group_by together with postgres & ecto?

假如想象 提交于 2021-01-28 09:33:49
问题 I'm struggling to get this to work with Postgres and Ecto. The query below works fine without the group_by, but I need to group on the fragment field, which it can't seem to see. Any idea what's wrong with it? def query_clicks do from(Click) |> select( [c], [ fragment("date_trunc('hour',?) as hour", c.inserted_at), c.link_id] ) |> group_by([c], c.hour) |> Repo.all end Result: iex(1)> recompile; Shortr.LinkContext.query_clicks [debug] QUERY ERROR source="clicks" db=1.2ms queue=4.9ms SELECT

Using fragment & group_by together with postgres & ecto?

删除回忆录丶 提交于 2021-01-28 09:30:46
问题 I'm struggling to get this to work with Postgres and Ecto. The query below works fine without the group_by, but I need to group on the fragment field, which it can't seem to see. Any idea what's wrong with it? def query_clicks do from(Click) |> select( [c], [ fragment("date_trunc('hour',?) as hour", c.inserted_at), c.link_id] ) |> group_by([c], c.hour) |> Repo.all end Result: iex(1)> recompile; Shortr.LinkContext.query_clicks [debug] QUERY ERROR source="clicks" db=1.2ms queue=4.9ms SELECT

In Elixir/Phoenix, after template change, “cannot define module MyApp.PageView because it is currently being defined”

时光总嘲笑我的痴心妄想 提交于 2021-01-28 03:50:49
问题 I just changed an image path in a template in my Phoenix app and reloaded the page. This error message appeared in the browser: CompilationError at GET / Showing console output == Compilation error on file web/views/page_view.ex == ** (CompileError) web/views/page_view.ex:1: cannot define module Youli.PageView because it is currently being defined in web/views/page_view.ex:1 (stdlib) erl_eval.erl:657: :erl_eval.do_apply/6 Running mix compile in the terminal made the problem go away, but isn't