小编Ada*_*hip的帖子

reinterpret_cast指向指针的迭代器

我有一个东西的迭代器.如果我想将当前项转换为指向该项的指针,为什么这样做:

thing_pointer = &(*it);
Run Code Online (Sandbox Code Playgroud)

但这不是:

thing_pointer = reinterpret_cast<Thing*>(it);
Run Code Online (Sandbox Code Playgroud)

这是我想要理解的编译器错误:http://msdn.microsoft.com/en-us/library/sy5tsf8z(v = vs.90).aspx

以防万一,迭代器的类型是 std::_Vector_iterator<std::_Vector_val<Thing,std::allocator<Thing> > >

c++ iterator reinterpret-cast

4
推荐指数
1
解决办法
1134
查看次数

Elixir 从shoutcast 中获取元数据

我想制作一个程序,该程序将显示来自互联网广播流(SomaFM)的当前正在播放的歌曲。我在 Elixir 中使用 HTTPoison 库。但我没有得到回应。它只是挂起。

我正在使用以下代码:

HTTPoison.start
url = "http://ice1.somafm.com/lush-128-mp3"
headers = [{"Icy-Metadata", "1"}]
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(url, headers) do
  body |> Poison.decode! |> IO.inspect
  else
    {:error, %HTTPoison.Error{reason: reason}} ->
      IO.inspect reason  
  end
end
Run Code Online (Sandbox Code Playgroud)

我实际上对 elixir 很陌生,所以如果有人能帮助我,我将非常感激。

shoutcast elixir httpoison

4
推荐指数
1
解决办法
298
查看次数

用于在Elixir中构造带有查询字符串的URI的习惯用法

我想知道最常用的方法是URI将查询字符串添加到Elixir中的基本URI.

我现在正在做这样的事情:

iex(1)> base = "http://example.com/endpoint"
"http://example.com/endpoint"

iex(2)> query_string = URI.encode_query(foo: "bar")
"foo=bar"

iex(3)> uri_string = URI.parse(base) |> Map.put(:query, query_string) |> URI.to_string
"http://example.com/endpoint?foo=bar"
Run Code Online (Sandbox Code Playgroud)

但是想知道是否有更简洁的方法来设置查询字符串.我知道URI.merge/2,但我不认为查询字符串是一个有效的URI,因此这里可能不合适(?不会添加).

我也可以这样做:

uri_string = %URI{ URI.parse(base) | query: query_string } |> URI.to_string
Run Code Online (Sandbox Code Playgroud)

但我想知道我错过了一种更简单或更清晰的方法.

uri elixir query-string

4
推荐指数
2
解决办法
774
查看次数

Elixir中的模运算符

如何在Elixir中使用模运算符?

例如,在Ruby中,您可以执行以下操作:

5 % 2 == 0
Run Code Online (Sandbox Code Playgroud)

它与Ruby的模运算符有何不同?

elixir modulo

4
推荐指数
3
解决办法
1980
查看次数

从 .ckpt 和 .meta 文件中获取输入和输出节点名称 tensorflow

我有张量流模型的 .meta 和 .ckpt 文件。我想知道确切的输入和输出节点名称,但我通过遵循获取节点名称列表。

当我有一个冻结的 protobuf 模型时,我使用以下代码将输入节点名称和输出节点名称作为列表的开头和结尾:

import tensorflow as tf
from tensorflow.python.platform import gfile
GRAPH_PB_PATH = 'frozen_model.pb'
with tf.Session() as sess:
   print("load graph")
   with gfile.FastGFile(GRAPH_PB_PATH,'rb') as f:
       graph_def = tf.GraphDef()
   graph_def.ParseFromString(f.read())
   sess.graph.as_default()
   tf.import_graph_def(graph_def, name='')
   graph_nodes=[n for n in graph_def.node]
   names = []
   for t in graph_nodes:
      names.append(t.name)
   print(names)
Run Code Online (Sandbox Code Playgroud)

我可以为 .ckpt 或 .meta 文件做类似的事情吗?

python deep-learning tensorflow

4
推荐指数
1
解决办法
9923
查看次数

ElixirLS 无需 OTP EEP48 文档即可编译

最近我遇到了无法解决的问题。这是关于 Elixir LS 的,当我运行语言服务器时,它显示以下消息:

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS v0.12.0","type":3}}

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"ElixirLS built with elixir \"1.14.2\" on OTP \"25\"","type":3}}

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Running on elixir \"1.14.2 (compiled with Erlang/OTP 25)\" on OTP \"25\"","type":3}}

{"jsonrpc":"2.0","method":"window/showMessage","params":{"message":"OTP compiled without EEP48 documentation chunks","type":2}}

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"OTP compiled without EEP48 documentation chunks. Language features for erlang modules will run in limited mode. Please reinstall or rebuild OTP with approperiate flags.","type":2}}

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Elixir sources not found (checking in /home/build/elixir). Code navigation to Elixir modules disabled.","type":3}}
Run Code Online (Sandbox Code Playgroud)

ElixirLS 无法正确编译,正如它所说,它在没有 EEP48 文档的情况下编译。我按照 ElixirLS 安装指南进行操作,但无法使其工作。Erlang 和 elixir 是随 asdf 安装的,我在 …

erlang elixir erlang-otp language-server-protocol asdf-vm

4
推荐指数
1
解决办法
1513
查看次数

将单字符字符串转换为其代码点

我知道我可以使用语法获取字符的代码点?a

iex> ?a
97
Run Code Online (Sandbox Code Playgroud)

但是什么时候a是二进制呢"a"?在这种情况下如何获取代码点?

elixir

3
推荐指数
1
解决办法
753
查看次数

Elixir Enum.map vs For comprehension

I have a map and I am modifying each element on it, I am confused which approach is better(faster) to do it with Enum.map and then Enum.into(%{}) or to use for comprehension like

for {key, value} <- my_map, into: %{} do
  {key, new_value}
end
Run Code Online (Sandbox Code Playgroud)

functional-programming elixir

3
推荐指数
1
解决办法
264
查看次数

Elixir MapSet 与 Enum.member?

我只需要保留唯一值,但我很困惑应该使用哪种数据结构。稍后我只会阅读整个数据结构。

  • 一种方法是使用MapSet仅包含唯一元素的which。
  • 第二种方法是每次检查Enum.member?一个项目是否已经存在 - 但我可以通过 轻松保证这一点MapSet

我不确定在这种情况下使用哪种方法更好。哪个更有效,哪个是更好的做法?

elixir

3
推荐指数
1
解决办法
855
查看次数

Elixir 配置提供程序

我的任务是读取应用程序运行时的 JSON 文件并将其存储在配置中。我已经浏览过https://hexdocs.pm/elixir/master/Config.Provider.html

现在我的配置提供程序代码是

defmodule JSONConfigProvider do
  @behaviour Config.Provider

  # Let's pass the path to the JSON file as config
  def init(path) when is_binary(path), do: path

  def load(config, path) do
    # We need to start any app we may depend on.
    {:ok, _} = Application.ensure_all_started(:jason)

    json = path |> File.read!() |> Jason.decode!()

    json
  end
end
Run Code Online (Sandbox Code Playgroud)

当我尝试通过 iex 运行它时,一切看起来都很好

JSONConfigProvider.load([existing: :config, app: [:appname]],"file_path")
Run Code Online (Sandbox Code Playgroud)

下一步是然后在指定您的发布时,您可以在发布配置中指定提供者

我没有混合版本。有什么方法可以将其存储在配置(dev.ex)中吗?

elixir

3
推荐指数
1
解决办法
955
查看次数