我想在postgresql中测量一些SQL查询的运行时间.使用BASH内置时间,我可以执行以下操作:
$ time (echo "SELECT * FROM sometable" | psql)
Run Code Online (Sandbox Code Playgroud)
我喜欢GNU时间,它提供更多格式.但是我不知道怎么用管道做.为简单起见,我ls | wc在以下示例中使用:
$ /usr/bin/time -f "%es" (ls | wc)
-bash: syntax error near unexpected token `('
$ /usr/bin/time -f "%es" "ls | wc"
/usr/bin/time: cannot run ls | wc: No such file or directory
Run Code Online (Sandbox Code Playgroud)
如果我不以任何方式对管道进行分组,它不会抱怨:
$ /usr/bin/time -f "%es" ls | wc
0.00s
Run Code Online (Sandbox Code Playgroud)
但显然,这仅测量管道的第一部分,如下一个示例所示
$ /usr/bin/time -f "%es" ls | sleep 20
0.00s
Run Code Online (Sandbox Code Playgroud)
那么问题是GNU Time与管道的正确语法是什么?
我有一个在GitHub上托管的开源maven项目.假设网址是https://github.com/foo/bar.
现在我想将它上传到Sonatype OSS Maven资源库.我检查了他们对groupId(https://docs.sonatype.org/display/Repository/Choosing+your+Coordinates)有严格的规定.
groupId将在所有项目中唯一地标识您的项目,因此我们需要强制执行命名模式.它必须遵循包名称规则,这意味着必须至少作为您控制的域名,并且您可以根据需要创建任意数量的子组.例如.org.apache.maven,org.apache.commons确定groupId粒度的一个好方法是使用项目结构.也就是说,如果当前项目是一个多模块项目,它应该将新标识符附加到父项的groupId.例如.org.apache.maven,org.apache.maven.plugins,org.apache.maven.reporting
问题是,对于在GitHub上托管的项目,什么是正确的问题?
由于用户生成的网站有域名foo.github.io,我至少有以下两个选项:
我使用sympy和numpy来解决以下问题:
给定点(x0,y0)和曲线y = a*x**2 + b*x + c,计算(x0,y0)到(x,y)的最小距离.
from sympy.core.symbol import symbols
from sympy.solvers.solvers import solve
from sympy.utilities.lambdify import lambdify
x, y = symbols('x y')
a,b,c, x0, y0 = symbols('a b c x0 y0')
y = a*x**2 + b*x + c
dist2 = (x-x0)**2 + (y-y0)**2
sol = solve(dist2.diff(x), x)
dist2_diff_solve = lambdify( (x0,y0,a,b,c), solve(dist2.diff(x),x), modules='numpy')
Run Code Online (Sandbox Code Playgroud)
到现在为止,一切都很好.我甚至可以得到一些结果:
dist2_diff_solve(1, 1, 1, 1, 1)
[0.31718264650678707, (-0.9085913232533936-0.8665105933073626j),
(-0.9085913232533936+0.8665105933073626j)]
Run Code Online (Sandbox Code Playgroud)
但是,使用另一组参数,我遇到了问题:
dist2_diff_solve(664515.9375, 3998106.0, 0.053674994761459802, -71340.561832823907, 23709057427.266102)
*** ValueError: negative number cannot be raised to a …Run Code Online (Sandbox Code Playgroud) 在 PostgreSQL 中,可以创建一个包含元素的数组 ( https://www.postgresql.org/docs/current/functions-array.html ):
SELECT ARRAY[1,2,3,4] AS indexes;
Run Code Online (Sandbox Code Playgroud)
是否有通过指定开始和结束来生成数组的函数?喜欢
SELECT array_from_to(1, 4) AS indexes
Run Code Online (Sandbox Code Playgroud) Google Guava中的Joiner(谷歌收藏的超集)非常酷.我的问题是,有一种简单的方法来处理嵌套集合吗?例如,我有一个矩阵,它是一个行列表,每行都是一个数字列表:
List<ArrayList<Integer>> matrix = Lists.newArrayList( //
Lists.newArrayList(1, 2, 3), //
Lists.newArrayList(4, 5, 6), //
Lists.newArrayList(7, 8, 9));
Run Code Online (Sandbox Code Playgroud)
我想通过使用新行作为行分隔符和","作为数字的分隔符来输出此矩阵.那是:
1, 2, 3
4, 5, 6
7, 8, 9
Run Code Online (Sandbox Code Playgroud)
如果它只是一行,我可以简单地使用一些代码,如"Joiner.on(",").nums".对于这个嵌套的情况,我必须循环所有行.
有更优雅的方式吗?
谢谢!