小编Ada*_*tan的帖子

行为:用动态示例编写场景大纲

小黄瓜/行为Examples

Gherkin 语法功能使用示例进行自动化测试

Feature: Scenario Outline (tutorial04)

  Scenario Outline: Use Blender with <thing>
    Given I put "<thing>" in a blender
    When I switch the blender on
    Then it should transform into "<other thing>"

    Examples: Amphibians
        | thing         | other thing |
        | Red Tree Frog | mush        |
        | apples        | apple juice |

    Examples: Consumer Electronics
        | thing         | other thing |
        | iPhone        | toxic waste |
        | Galaxy Nexus  | toxic waste |
Run Code Online (Sandbox Code Playgroud)

测试套件将运行四次,每个示例运行一次,给出类似于以下内容的结果: …

cucumber gherkin python-behave

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

Makefile:在不同的目标上使用不同的参数运行相同的命令

请考虑以下makefile片段:

COMMIT := $(shell git rev-parse HEAD)

build:
    docker build -f Dockerfile --no-cache=false -t $(COMMIT) .
rebuild:
    docker build -f Dockerfile --no-cache=true  -t $(COMMIT) .
Run Code Online (Sandbox Code Playgroud)

问题

build和之间唯一的区别rebuild--no-cache参数的值.显然,略微改变重写相同的命令是一种不好的做法; 它打破了DRY原则,如果我需要更改命令中的其他内容 - 例如,值的-t- 我将不得不在所有相关目标中更改它.

我有这样的想法:

COMMIT := $(shell git rev-parse HEAD)
NO_CACHE := false

build:
    docker build -f Dockerfile --no-cache=$(NO_CACHE) -t $(COMMIT) .
rebuild:
    NO-CACHE = true
    make build
Run Code Online (Sandbox Code Playgroud)

我试着玩变量,没有运气.

我的问题

docker build一次编写命令并让每个目标改变其参数的优雅方法是什么?

makefile

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

zsh:别名与$(命令)参数

我的目标

我经常使用以下命令:

vim $(fzf)
Run Code Online (Sandbox Code Playgroud)

它使用模糊查找来搜索文件列表,然后在vim中打开突出显示的文件.

在此输入图像描述

我的问题

我想别名vim $(fzf),但是当我添加alias v="vim $(fzf)".zshrc,fzf每当我打开一个新shell时都会执行.

我的问题

如何设置只在zsh执行$(command)别名命令时执行?

zsh

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

检查正在运行的程序中的可用RAM量

在求职面试中,我的一位朋友被要求编写一个测量可用内存量的程序.预期的答案是以malloc()二进制搜索方式使用:分配更大和更大的内存部分,直到获得失败消息,减小部分大小,并总计分配的内存量.

我相信这种方法可以测量虚拟内存量,而不是物理内存量.但我对此事感到好奇.

有没有办法告诉程序中的可用RAM量,而不使用exec(dmesg |grep -i memory)

memory malloc

2
推荐指数
1
解决办法
334
查看次数

我可以使用Facebook凭据让用户访问我的网站吗?

我开始在一个与相应的Facebook应用程序紧密相连的网站上工作.我希望所有人都可以免费查看内容,但只有注册用户才能编辑它(实际上与serverfault非常相似).

由于我认为我的大多数用户都将登录到facebook,我真的想使用他们的facebook凭据登录我的网站 - 就像Open-Id注册在这里工作一样.

可以这样做吗?

谢谢,

乌迪帕斯蒙

openid facebook login identity-management

2
推荐指数
1
解决办法
1532
查看次数

快速算法,用于检查Perl中大(x,y)坐标中一对数的成员关系

我有一个排序坐标列表(让我们称之为xycord.txt),如下所示:

chr1    10003486        10043713
chr1    10003507        10043106
chr2    10003486        10043713
chr2    10003507        10043162
chr2    10003532        10042759
Run Code Online (Sandbox Code Playgroud)

实际上,这个文件非常大,有10 ^ 7行.

我想要做的是给出另一个两点坐标,我想检查它们是否落在xycord.txt文件中的任何坐标之间.

我目前的方法是超级慢.因为对于这个大xycord.txt文件还有许多其他两点坐标.

有快速的方法吗?

#!/usr/bin/perl -w

my $point_to_check_x = $ARGV[0] || '10003488';
my $point_to_check_y = $ARGV[1] || '10003489';
my $chrid = $ARGV[2] || "chr1";

my %allxycordwithchr;   
# skip file opening construct
while (<XYCORD_FILE>) {
  my ($chr,$tx,$ty) = split(/\s+/,$_);
  push @{$allxycordwithchr{$chr}},$tx."-".$ty;
}


 my @chosenchr_cord = @{$allxycordwithchr{$chrid}};

 for my $chro_cords (@chosenchr_cord){

  my ($repox,$repoy) = split("-",$chro_cord);
   my $stat = …
Run Code Online (Sandbox Code Playgroud)

algorithm perl search

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

如何生成拇指图像?

我有一个大约20000张图像的文件夹,我需要为它们生成拇指图像.

做这项工作的最快方法是什么?

我知道我可以使用一些图像大小调整库来做到这一点.但我想知道可能已经有一个工具或代码片段可以完成这项工作.

resize image-manipulation image imagemagick image-resizing

2
推荐指数
1
解决办法
369
查看次数

Pythonic从配置文件中读取

我有一个python类,它使用ConfigParser读取配置文件:

配置文件:

[geography]
Xmin=6.6
Xmax=18.6
Ymin=36.6
YMax=47.1
Run Code Online (Sandbox Code Playgroud)

Python代码:

class Slicer:
    def __init__(self, config_file_name):
        config = ConfigParser.ConfigParser()
        config.read(config_file_name)
        # Rad the lines from the file
        self.x_min = config.getfloat('geography', 'xmin')
        self.x_max = config.getfloat('geography', 'xmax')
        self.y_min = config.getfloat('geography', 'ymin')
        self.y_max = config.getfloat('geography', 'ymax')
Run Code Online (Sandbox Code Playgroud)

我觉得最后四行是重复的,并且应该以某种方式压缩到一个Pythonic线,这将self.item为该部分中的每个项创建一个变量.

有任何想法吗?

亚当

更新:

根据您的回答,我已将我的代码修改为:

    for item in config.items('geography'):
        setattr(self, '_'+item[0], float(item[1]))
Run Code Online (Sandbox Code Playgroud)

现在,

   print self.__dict__
   >>> {'_xmax': 18.600000000000001, '_ymax': 47.100000000000001, 
        '_ymin': 36.600000000000001, '_xmin': 6.5999999999999996}
Run Code Online (Sandbox Code Playgroud)

python coding-style dry configparser

2
推荐指数
1
解决办法
583
查看次数

PostgreSQL:选择所有字段,过滤一些

在我们的一个数据库中,有一个包含数十列的表,其中一列是几何列.

我想SELECT从表中的行,几何转换为另一个SRID.我想使用类似的东西:

`SELECT *`
Run Code Online (Sandbox Code Playgroud)

为了避免:

SELECT col_a, col_b, col_c, col_d, col_e, col_f, 
       col_g, col_h, transform(the_geom, NEW_SRID), ..., col_z
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

亚当

sql postgresql geometry

2
推荐指数
1
解决办法
2260
查看次数

使用psycopg2的参数化查询:来自Python列表的SELECT

给定Python中一个大的(~10,000)整数列表,如何有效地SELECT从列表中id的表中的所有项目?

我试过了:

>>> lst2
[{'id': 97600167}, {'id': 97600168}, {'id': 97611194}]
>>> cur.executemany("SELECT id, parent_id FROM my_table WHERE id=%(id)s", lst2)
>>> cur.fetchall()
[(97611194, 10020688), (None, None), (None, None)]
Run Code Online (Sandbox Code Playgroud)

第二个和第三个id(97600168,97611194)确实存在于表中.

python psycopg2 sql-parametrized-query

2
推荐指数
1
解决办法
3626
查看次数