我对elixir很新,并且没有erlang经验(或功能性的东西),但很快就会变得明显.. - >
iex(2)> :inets.start()
:ok
iex(3)> :httpc.request(["http://www.erlang.org"])
{:error, :no_scheme}
Run Code Online (Sandbox Code Playgroud)
我不知道是什么:no_scheme意味着什么.我用谷歌搜索了no_scheme和东西,我确信它很明显,但我没有发现任何真的.我在erlang文档中找到的唯一模糊相关的东西是 - >
iex(4)> :http_uri.scheme_defaults
[http: 80, https: 443, ftp: 21, ssh: 22, sftp: 22, tftp: 69]
Run Code Online (Sandbox Code Playgroud)
或者我可能不符合RFC2616或其他......我没有想法(现在).
Elixir和Erlang超级超级棒,但是任何帮助我的旅程都会受到赞赏.
谢谢你的帮助!
我在erl中尝试过.
1> inets:start().
ok
2> httpc:request("http://www.erlang.org").
{ok,{{"HTTP/1.1",200,"OK"},
[{"date","Wed, 20 Nov 2013 23:15:45 GMT"},
{"server","inets/5.7.1"},
{"content-length","10385"},
{"content-type","text/html; charset=utf-8"},
{"set-cookie",
"eptic_cookie=erlangorg@hades-3680318586833850369; path=/"}],
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE htm
etc...
Run Code Online (Sandbox Code Playgroud)
好吧,我最大的问题是我是双引用"http://www.erlang.org"字符串而我猜elixir - > erlang将它们引入像parrotys一样的单引号'http://www.erlang.org'.
no_scheme仍然很神秘.我能找到的只是与重定向和RFC实现相关的东西.我刚刚决定将它视为一般错误,与url有关..
这里有一篇博客文章,有人解释得很好.链接
像数据库这样的Erlang原子成为:数据库和Erlang版本中的PgConn之类的局部变量在Elixir中成为pg_conn.
当它们是Erlang函数的参数时,我们需要单引号字符串文字.如果您有一个存储在Elixir变量中的UTF-8字符串,您可以使用binary_to_list/1函数将其转换为char列表.
具有讽刺意味的是,几小时前发布的名为"HTTP客户端"的最新Elixir Sip涵盖了我的整个问题.看看有人遇到这个是未来!
在elixir中,我们可以连接,列表就像这样
ex(52)> [1,2,3,4] ++ [5,6,7]
[1, 2, 3, 4, 5, 6, 7]
Run Code Online (Sandbox Code Playgroud)
我们还可以连接元组吗?像这样的东西?
iex(53)> {1,2,3,4} ++ {5,6,7}
** (ArgumentError) argument error
:erlang.++({1, 2, 3, 4}, {5, 6, 7})
Run Code Online (Sandbox Code Playgroud)
我能想到的唯一另一件事是将元组转换为列表,然后使用to_list和to_tuple函数转换回元组.但那太笨拙了.
这是我尝试过的.
date = Ecto.DateTime.from_erl(:calendar.universal_time())
query |> where([record], record.deadline >= ^date)
Run Code Online (Sandbox Code Playgroud)
我也试过了
date = Ecto.DateTime.from_erl(:calendar.universal_time())
query = from m in MyApp.SomeModel,
where: m.deadline >= ^date,
select: m
Run Code Online (Sandbox Code Playgroud)
两者都返回相同的消息
value `%Ecto.DateTime{..}` in `where` cannot be cast to type :datetime in query
Run Code Online (Sandbox Code Playgroud)
根据我的理解,我应该在我的查询中使用Ecto.DateTime.也许我错过了一些明显的东西?谢谢!
我发现编译时警告非常有用,但我偶尔可能会错过它们,特别是如果它是在一个测试在CI服务器上运行的pull请求中.
理想情况下,我会在项目组合文件中指定一些会使编译器更严格的内容.
我希望这对所有混合任务都有效,我不想将标志传递给命令,因为这很容易忘记.
例如,对于带有编译器警告的项目,此命令应该失败
mix clean && mix compile
Run Code Online (Sandbox Code Playgroud)
应该是这个
mix clean && mix test
Run Code Online (Sandbox Code Playgroud) 我目前正在Elixir写一个小试飞员.我想使用模式匹配来评估文件是否是规范格式(以"_spec.exs"结尾).有很多关于如何在字符串的开头进行模式匹配的教程,但是这不知道如何在字符串结尾处起作用:
defp filter_spec(file <> "_spec.exs") do
run_spec(file)
end
defp run_spec(file) do
...
end
Run Code Online (Sandbox Code Playgroud)
这总是在编译错误中结束:
== Compilation error on file lib/monitor.ex ==
** (CompileError) lib/monitor.ex:13: a binary field without size is only allowed at the end of a binary pattern
(stdlib) lists.erl:1337: :lists.foreach/2
(stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
Run Code Online (Sandbox Code Playgroud)
那有什么解决方案吗?
请考虑以下代码:
defmodule T do
def does_not_contain?(s, t) do
s |> not(String.contains?(t))
end
end
Run Code Online (Sandbox Code Playgroud)
这会在编译时出现以下错误:
** (CompileError) iex:3: undefined function not/2
Run Code Online (Sandbox Code Playgroud)
我也试过这样的结构:
defmodule T do
def does_not_contain?(s, t) do
s |> String.contains?(t) |> not
end
end
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误:
** (SyntaxError) iex:4: unexpected token: end
Run Code Online (Sandbox Code Playgroud)
我可以做这样的工作:
defmodule T do
def does_not_contain?(s, t) do
does_contain = s |> String.contains?(t)
not(does_contain)
end
end
Run Code Online (Sandbox Code Playgroud)
但尝试将整个事情保持在管道中是非常有吸引力的.有没有办法在管道中否定一个布尔值?
如何使用插头对凤凰的具体操作.想要使用插件进行某些操作的场景,或者相反,不希望在某些操作中使用插件
我知道几种退出的方法,iex但我喜欢在其他REPL中使用ctrl-D(例如node,irb.)
如何自定义iex才能执行此操作?
我想处理一个application/json内容类型的传入POST .我只是试图返回发布的JSON作为对此测试的响应:
WebhookController控制器
pipeline :api do
plug :accepts, ["json"]
end
def handle(conn, params) do
{:ok, body, conn} = Plug.Conn.read_body(conn)
json(conn, %{body: body})
end
Run Code Online (Sandbox Code Playgroud)
router.ex
scope "/webhook", MyApp do
pipe_through :api
post "/handle", WebhookController, :handle
end
Run Code Online (Sandbox Code Playgroud)
如果传入的帖子具有内容类型application/json,则body为空.如果内容类型是text或text/plain,则body具有内容.
解析传入application/json请求正文的正确方法是什么?
我正在使用Phoenix 1.2
我有一个kubernetes集群.
我可以轻松连接到远程容器,并运行连接到live production erlang节点的shell节点:
$ kubectl exec myapp-2431125679-cwqvt -i -t -- iex --name debugging@127.0.0.1 --remsh myliveapp@127.0.0.1 --cookie my_secret_cookie
Erlang/OTP 18 [erts-7.3.1] [source] [64-bit] [smp:2:2] [async-threads:10] [kernel-poll:false]
Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(myliveapp@127.0.0.1)1>
Run Code Online (Sandbox Code Playgroud)
我需要的,虽然是要能够运行:observer针对远程现场制作的Erlang节点.
我也可以这样做:
杀死本地epmd进程:
killall epmd
Run Code Online (Sandbox Code Playgroud)将选定的远程端口转发到本地计算机:
kubectl port-forward myapp-2431125679-cwqvt 35609 4369
Run Code Online (Sandbox Code Playgroud)
我知道我的应用程序在远程容器上的端口35609上epmd运行,默认情况下4369是端口运行,这是我的远程容器的情况.
跑:
iex --name debugging@127.0.0.1 --cookie marketplace -e ':observer.start()'
Run Code Online (Sandbox Code Playgroud)从顶部菜单中选择我感兴趣的应用程序:observer.
我的问题是:
最终,我可以将此过程变为单行或将其转换为shell脚本吗?
现在杀人 …