尝试Pipfile为特定的 Python 版本创建一个,但 pipenv 无法检测到已安装的 Python 版本存在。使用asdf安装和管理 Python 版本。
? python --version
Python 3.6.6
? pipenv --python 3.6.6
Warning: Python 3.6.6 was not found on your system…
You can specify specific versions of Python with:
$ pipenv --python path/to/python
? asdf current python
3.6.6 (set by /Users/dennis/some/project/.tool-versions)
Run Code Online (Sandbox Code Playgroud) 我的根目录中有一个.exs脚本,我希望能够在命令行上执行elixir my_script.exs.在我的项目中初始化Mix之前,我的脚本正在运行,但现在它不起作用.我可以看到Mix将.beam文件放在ebin/目录中,但显然我的脚本没有在那里查找.
将自定义模块加载到.exs脚本的正确方法是什么?
假设我有一个像二进制符号表示的数字,如下所示:
<<0:1, 0:1, 0:1, 0:1, 0:1, 1:1, 1:1, 1:1>>
Run Code Online (Sandbox Code Playgroud)
这是数字7的二进制表示法,在shell中评估它甚至产生7:
<<7>>
Run Code Online (Sandbox Code Playgroud)
我如何将这个二进制转换为Erlang整数?我可以将二进制文件转换为列表,并获取其中的单个整数值,但这不会对需要多个字节的大数字起作用,因为列表将包含二进制文件中每个字节的项.
我使用 asdf + asdf-erlang 作为 Erlang 的版本管理器。一切似乎都运行良好,只是打字会erl -man mnesia导致No manual entry for mnesia.
我已经安装了 asdf-erlang github 页面上提到的所有依赖项。我还安装了 xsltproc 和 fop。不幸的是,位于下面的“man”文件夹~/.asdf/installs/erlang/18.3/lib/erlang/erts-73/是空的。我还没有发现在其他地方生成手册页。
我试图找到构建日志,但我也没有成功。
我使用的是 64 位 Ubuntu 16.10 和 16.04。
我想确保字符串具有ip地址的格式.我不需要太具体的东西.我只想检查.字符串中是否有三个.我可以检查那里是否.有这样的:
str.include? '.'
Run Code Online (Sandbox Code Playgroud)
但是如何检查多个.?
谢谢!
我需要像这样使用DSL:
defmodule SomeModule do
use SomeMacros
# sample shipping DSL
rule is_north_america do
calculate_shipping_cost_with usps
end
rule is_north_america and november_or_december do
calculate_shipping_cost_with ups
end
rule is_south_america do
calculate_shipping_cost_with fedex
end
rule is_somewhere_else do
calculate_shipping_cost_with dhl
end
end
Run Code Online (Sandbox Code Playgroud)
并将每个调用转换为规则宏(我已经定义)并让它在SomeModule模块中定义一个函数.像这样:
def is_north_america_rule(Address[continent: "North America"] = address) do
# do something
end
Run Code Online (Sandbox Code Playgroud)
我想对传递给宏生成的函数的参数使用模式匹配.我已经看到了如何在宏中定义自定义函数,但我不确定如何在宏生成的函数中实现模式匹配和保护.
提前致谢!
我什么时候应该使用Erlang记录而不是元组?或者,反之亦然,何时不需要Erlang记录?我对Erlang相对较新,我不确定我是否正确使用记录和元组.我从我读过的内容中了解到,记录实际上是作为元组存储在幕后.
我通常使用记录来处理将在应用程序中传递或在某处持久化的数据.我使用元组之类的东西,比如函数的返回值,函数的参数,以及特定于函数体的东西.
我正确使用记录和元组吗?是否有文档概述何时应该使用另一种类型?
有没有办法检查变量是否是Erlang中的自定义类型?
假设我在.hrl文件中定义了一些记录和类型:
-record(custom_record, {
attr1 :: list(),
attr2 :: binary(),
attr3 :: tuple()
}).
-record(another_record, {
attr1 :: list(),
attr2 :: binary(),
}).
-type custom_record() :: #custom_record{}.
-type another_record() :: #another_record{}.
-type custom_records() :: custom_record() | another_record().
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来检查记录是否custom_record在我的Erlang代码中?像这样的东西会很好:
is_custom_type(CustomRecord, custom_records). %=> true
Run Code Online (Sandbox Code Playgroud)
我查看了文档,没有看到任何内置函数执行此操作.
我正在使用一个简单的命令行工具,我发现默认的Usage消息有点缺乏.我想定义自己的,我认为我正在做正确的我指的是这个例子.
我注释掉了我编写的大部分代码,因此包含main函数的文件现在看起来像这样:
package main
import (
"flag"
"fmt"
"os"
)
func main() {
// set the custom Usage function
setupFlags(flag.CommandLine)
// define flags...
// then parse flags
flag.Parse()
// custom code that uses flag values...
}
func setupFlags(f *flag.FlagSet) {
f.Usage = func() {
fmt.Println("foo bar")
}
}
Run Code Online (Sandbox Code Playgroud)
看起来这应该有效,但事实并非如此.运行时,<binary> -h我得到默认用法消息,而不是我foo bar在自定义函数中定义的自定义消息.我在OSX上使用Go 1.3.3版.我发现了这个提交,但它适用于Go 1.4rc2.
我究竟做错了什么?
在Capybara集成测试中取消选中复选框的正确方法是什么?我有一个复选框列表,我需要取消选中.我选择它们全部使用all:
checkboxes = all("input[type='checkbox']")
Run Code Online (Sandbox Code Playgroud)
为了取消选中我使用的每一个each.根据我在StackOverflow上找到的信息,取消选中一个复选框应该有三种方法:
uncheck(field)
field.click
field.set(false)
Run Code Online (Sandbox Code Playgroud)
为了测试这些不同的方法我是否创建了以下测试(每个测试都在同一页面的单独场景中):
使用uncheck它成功:
checkboxes = all("input[type='checkbox']")
checkboxes.each { |field| expect(field.checked?).to eq("checked") }
checkboxes.each { |field| uncheck(field[:id]) }
checkboxes.each { |field| expect(field.checked?).to eq(nil) }
puts page.body
save_and_open_page
Run Code Online (Sandbox Code Playgroud)
使用click它失败了,所以我认为这是取消选中该字段的不正确方法:
checkboxes = all("input[type='checkbox']")
checkboxes.each { |field| expect(field.checked?).to eq("checked") }
checkboxes.each { |field| field.click }
checkboxes.each { |field| expect(field.checked?).to eq(nil) }
puts page.body
save_and_open_page
Run Code Online (Sandbox Code Playgroud)
使用set(false)它成功:
checkboxes = all("input[type='checkbox']")
checkboxes.each { |field| expect(field.checked?).to eq("checked") }
checkboxes.each { |field| …Run Code Online (Sandbox Code Playgroud)