如何在IntelliJ IDEA 11.0中使用制表符而不是多个空格进行缩进?
我在"代码样式">"常规">"默认缩进选项"下选中了 "使用制表符".并且还尝试检查"智能标签",但它没有帮助.
从文档:
如果选中此复选框,则使用制表符:
- 按Tab键
- 缩进
- 用于代码重新格式化
否则,使用空格而不是制表符.
我知道可以创建一个struct via %User{ email: 'blah@blah.com' }
.但是,如果我有一个变量params = %{email: 'blah@blah.com'}
,有一种方法可以使用该变量创建该结构,例如,%User{ params }
.
这给出了一个错误,只是想知道你是否可以爆炸它或其他方式?
我搜索了Elixir和Phoenix文档,以及其他一些网站,比如Learn Elixir,没有运气.这是它的样子:
defp update_positions(item_ids) do
item_ids = String.split(item_ids, ",")
|> Enum.map fn item_id -> String.to_integer(item_id) end
items = Repo.all(Item |> where([item], item.id in array(^item_ids, :integer)))
item_hash = Enum.reduce items, %{}, fn item, map -> Map.put(map, item.id, item) end
item_ids
|> Stream.with_index
|> Enum.each fn {item_id, index} ->
item = item_hash[item_id]
Repo.update(%{item | position: index + 1})
end
end
Run Code Online (Sandbox Code Playgroud)
起初我认为它只是一个行继续符号来保持代码可读,但Item |> where
上面的行表示不然.它是列表理解还是指定输入类型的东西?
我可以使用mix来全局安装一些软件包吗?我想类似行为npm
的全局选项或gem
的安装-这可能是因为我到处使用像包有用csv
或yaml
.
有两个string
变量,m
和n
:
#include <string>
string m = "0100700\0"
cout << m.size() << endl; // it prints: 7
string n;
n += "0100700"
n += '\0';
cout << n.size() << endl; // it prints: 8
Run Code Online (Sandbox Code Playgroud)
我猜两个都有8个字符,但m
只有7个字符,n
有8个字符.为什么会这样?
我有一个凤凰路线,我想将一些表格数据发布到,但是表格中有大约4个字段是可选的(表格由最终用户构建,因此这些字段可能不存在于POST有效载荷中)
在路线的凤凰控制器中,您将如何处理?
例如:
我的表格有
Field1,
Field2
Field3 (optional)
Field4 (optional)
Field5 (optional)
Run Code Online (Sandbox Code Playgroud)
POST表单必须始终具有Field1
,Field2
但可以包含其他字段的任意组合.
所以到目前为止我的控制器代码是这样的:
def create(conn, %{"field1" => field1, "field2" => field2) do
end
Run Code Online (Sandbox Code Playgroud)
如何让其他3个可选?如果我将它们全部添加到那时它们将是必需的,我不希望为每个可能提交的表单创建一个函数,因为它似乎有点过分.
我有testSuite
几个Python testCases
.
如果testCase
失败,testSuite
继续下一个testCase
.我希望能够testSuite
在testCase
失败或能够决定是testSuite
继续还是停止时停止.
我真的在与Elixir主管挣扎,并弄清楚如何命名它们以便我可以使用它们.基本上,我只是想开始一个监督Task
,我可以发送消息.
所以我有以下内容:
defmodule Run.Command do
def start_link do
Task.start_link(fn ->
receive do
{:run, cmd} -> System.cmd(cmd, [])
end
end)
end
end
Run Code Online (Sandbox Code Playgroud)
项目入口点为:
defmodule Run do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# Define workers and child supervisors to be supervised
worker(Run.Command, [])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Run.Command]
Supervisor.start_link(children, opts) …
Run Code Online (Sandbox Code Playgroud) 在Elixir中,多个表达式可以用semicolon(;
)分隔.
Elixir在下面的函数定义中抱怨
defmodule Module2 do
def func([c], n), do: IO.inspect(c); c + n
end
Run Code Online (Sandbox Code Playgroud)
有错误
** (CompileError) hello.exs:2: undefined function c/0
(stdlib) lists.erl:1352: :lists.mapfoldl/3
(stdlib) lists.erl:1352: :lists.mapfoldl/3
(stdlib) lists.erl:1353: :lists.mapfoldl/3
Run Code Online (Sandbox Code Playgroud)
但是,Elixir对以下语法感到满意.
defmodule Module1 do
def func([c], n) do
IO.inspect(c); c + n
end
end
Run Code Online (Sandbox Code Playgroud)
我不确定为什么一个在另一个上工作 - 据我所知,两种函数定义的样式都是等价的.
完整的代码供参考
defmodule Module1 do
def func([c], n) do
IO.inspect(c); c + n
end
end
defmodule Module2 do
def func([c], n), do: IO.inspect(c); c + n
end
Module1.func('r', 13)
Module2.func('r', 13)
Run Code Online (Sandbox Code Playgroud) 我需要找到两个纬度/经度点之间的中点.
我试图将我绘制的两个位置之间的地图居中,并且需要找到该点.
我已经从我找到的其他示例中编写了这个函数,但似乎没有用.
public static void midPoint(double lat1, double lon1, double lat2, double lon2, out double lat3_OUT, out double lon3_OUT)
{
//http:// stackoverflow.com/questions/4656802/midpoint-between-two-latitude-and-longitude
double dLon = DistanceAlgorithm.Radians(lon2 - lon1);
//convert to radians
lat1 = DistanceAlgorithm.Radians(lat1);
lat2 = DistanceAlgorithm.Radians(lat2);
lon1 = DistanceAlgorithm.Radians(lon1);
double Bx = Math.Cos(lat2) * Math.Cos(dLon);
double By = Math.Cos(lat2) * Math.Sin(dLon);
double lat3 = Math.Atan2(Math.Sin(lat1) + Math.Sin(lat2), Math.Sqrt((Math.Cos(lat1) + Bx) * (Math.Cos(lat1) + Bx) + By * By));
double lon3 = lon1 + Math.Atan2(By, Math.Cos(lat1) + Bx);
lat3_OUT …
Run Code Online (Sandbox Code Playgroud) elixir ×6
c# ×1
c++ ×1
elixir-mix ×1
erlang-otp ×1
geolocation ×1
indentation ×1
operators ×1
python ×1
stdstring ×1
test-suite ×1
testcase ×1
unit-testing ×1