elixir

How to perform a case-insensitive file search in Erlang/Elixir

老子叫甜甜 提交于 2019-12-23 20:11:29
问题 Elixir provides Path.wildcard , which uses the Erlang :filelib.wildcard function internally. Matching is case-sensitive, for example, "a" does not match "A". (http://erlang.org/doc/man/filelib.html#wildcard-1) Please is there a case-insensitive alternative? 回答1: There's no built in option to do this, but since the wildcard syntax supports character alternations similar to regex, you can replace every letter with an alternation of its lower and upper case versions, e.g. f0o -> [fF]0[oO] , and

How to perform a case-insensitive file search in Erlang/Elixir

自闭症网瘾萝莉.ら 提交于 2019-12-23 19:50:30
问题 Elixir provides Path.wildcard , which uses the Erlang :filelib.wildcard function internally. Matching is case-sensitive, for example, "a" does not match "A". (http://erlang.org/doc/man/filelib.html#wildcard-1) Please is there a case-insensitive alternative? 回答1: There's no built in option to do this, but since the wildcard syntax supports character alternations similar to regex, you can replace every letter with an alternation of its lower and upper case versions, e.g. f0o -> [fF]0[oO] , and

How to check Phoenix (Elixir framework) installed version?

空扰寡人 提交于 2019-12-23 19:46:25
问题 I would like to check Phoenix framework version from the command line like I check for Elixir (elixir -v) 回答1: I was able to do it with # for >= v1.3 mix phx.new --version # for < v1.3 mix phoenix.new --version after navigating to the folder containing the phoenix app. I got the cue from here. Hope it helps someone facing the same query. 来源: https://stackoverflow.com/questions/50772332/how-to-check-phoenix-elixir-framework-installed-version

Formatting a date-time using Timex

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 17:03:43
问题 I have a date. How can I format it via Times so that it becomes of the format: Wed, 02 Oct 2002 15:00:00 +0200 or Wed, 02 Oct 2002 15:00:00 GMT or Wed, 02 Oct 2002 15:00:00 EST I've tried this: Timex.format!(my_date, "%D, %d %M %Y %H:%i:%s T", :strftime)) but it threw an exception: %Timex.Format.FormatError{message: {:format, "Expected end of input at line 1, column 16"}} (expected a string) while it's getting converted into other, simpler, formats with no errors. 回答1: I believe you're

How does the '&' operator work?

有些话、适合烂在心里 提交于 2019-12-23 15:00:17
问题 I am having trouble understand the '&' operator in the following context. @doc "Marks a task as executed" def put_task(task, project) do item = {task, project} Agent.update(__MODULE__, &MapSet.put(&1, item)) end It seems that in this case the '&1' is referring to the map object itself, but I am curious as to how this works. Is it passing itself in as an argument I looked into this in the docs but couldn't find out if this was exactly what was going on. I would be grateful if somebody could

Not able to connect to a remote SSH server with Elixir

给你一囗甜甜゛ 提交于 2019-12-23 13:22:50
问题 I have been trying for a while to connect to a remote ssh server with elixir. This is what I do in IEX: [Macintosh] elixir/logglycious (master|…)> iex 15-07-20 0:11 Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> :application.start(:crypto) {:error, {:already_started, :crypto}} iex(2)> :application.start(:public_key) {:error, {:not_started, :asn1}} iex(3)>

protocol Phoenix.HTML.Safe not implemented Elixir Phoenix

送分小仙女□ 提交于 2019-12-23 13:21:13
问题 I have an object with such values as %{"Friday" => [], "Monday" => [], "Saturday" => [], "Sunday" => ["3:0-4:0", "6:0-7:0"], "Thursday" => [], "Tuesday" => [], "Wednesday" => []} I wanted to show it in my email template's view, i just stated as <p>Schedule: <%= @schedule %></p> I got this error on it ** (Protocol.UndefinedError) protocol Phoenix.HTML.Safe not implemented for %{"Friday" => [], "Monday" => [], "Saturday" => [], "Sunday" => ["3:0-4:0", "6:0-7:0"], "Thursday" => [], "Tuesday" =>

assign @changeset not available in eex template

半腔热情 提交于 2019-12-23 12:57:07
问题 I am trying to learn the Phoenix's Form system with including the Ecto.Model's but i have encountered a problem that i can't pass. I have created a form: <div class="jumbotron"> <%= form_for @changeset, user_path(@conn, :create), fn f -> %> <label> Login: <%= text_input f, :login %> </label> <label> Password: <%= password_input f, :password %> </label> <label> Name: <%= text_input f, :name %> </label> <label> Surname: <%= text_input f, :name %> </label> <label> Email: <%= email_input f, :name

Find length of Elixir/Erlang in-memory file?

我只是一个虾纸丫 提交于 2019-12-23 12:43:54
问题 In Elixir (or Erlang), if I have an in-memory file, how do I find its length in bytes? {:ok, fd} = :file.open("", [:ram, :read, :write]) :file.write(fd, "hello") 回答1: Not sure if there's a better way, but this is what I did: def get_length(fd) do {:ok, cur} = :file.position(fd, {:cur, 0}) try do :file.position(fd, {:eof, 0}) after :file.position(fd, cur) end end Usage: {:ok, fd} = :file.open("", [:ram, :read, :write]) :ok = :file.write(fd, "hello") {:ok, len} = get_length(fd) 回答2: You can use

How to debug eex template and @ variables?

故事扮演 提交于 2019-12-23 10:06:59
问题 I have this template <%= form_for @changeset, bid_path(@conn, :update, 1), [method: :put], fn f -> %> <% require IEx IEx.pry %> <%= if @changeset.action do %> <div class="alert alert-danger"> <p>Oops, something went wrong! Please check the errors below.</p> </div> <% end %> How can I display @changeset in IEx console? When I'm trying to do this is blows an error: pry(5)> @changeset ** (ArgumentError) cannot invoke @/1 outside module (elixir) lib/kernel.ex:3960: Kernel.assert_module_scope/3