小编Ann*_*lee的帖子

使用 mocha/chai 进行测试时比较两个日期

我正在使用"chai": "^4.2.0""mocha": "^6.1.4",

assert.equal()用于比较两个日期时,即使这两个日期似乎相同,我也会出错:

在此处输入图片说明

这是我的示例测试:

  it('check if dates are correctly added', async () => {
let dataArr = [{'rating_date':'6/6/2019','impact_on_price':'Low'}]   
let priceServ = new PriceService()

// clear all records
priceServ.clearPriceTable()

// add 1 record
const res = await priceServ.createOrUpdatePrice(dataArr)

// get "all" records from the table that have a certain action attribute
const tableValues = await priceServ.getPricesByField('rating_date')
assert.equal(tableValues[0].rating_date, new Date(dataArr[0].rating_date));
Run Code Online (Sandbox Code Playgroud)

});

任何建议我做错了什么?

我感谢您的回复!

javascript mocha.js chai

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

在heroku上每个cronjob运行casperjs

我在casperjs中创建了一个应用程序,它可以从网站上删除运动数据.

我想在heroku上按照cronjob运行此应用程序,以将运动结果保存在csv,数据库或外部google文档中(尚未确定).

但是,在我开始为heroku实现它之前,我有一个问题:

  • 我发现这个buildpackheroku,其声称,它可以运行casperjsscirpts.但是,我是否需要nodejs运行预定的脚本?或者我可以在heroku上创建一个cronjob吗?

我非常感谢你的回复!

javascript heroku node.js phantomjs casperjs

5
推荐指数
1
解决办法
764
查看次数

在“ Visual Studio代码”中调试单个JavaScript文件

有没有一种方法可以在不启动节点服务器的情况下逐步调试单个javascript文件?

例如knex的种子文件。

绝对需要节点,但是我不知道如何仅使用文件启动VSC调试器。

node.js visual-studio-code

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

mysqli 不能使用 ssh 隧道

我已经Ubuntu 18.04.3 LTS在我的虚拟机上安装了:

在此处输入图片说明

我还通过以下方式创建了一个 ssh 隧道来连接到我的远程数据库:

admin@admin-VirtualBox:~$ ssh -v -v -v root@xx.xx.xxx.xxx -CNL 13306:localhost:3306
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "xx.xx.xxx.xxx" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to xx.xx.xxx.xxx [xx.xx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/admin/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/admin/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or …
Run Code Online (Sandbox Code Playgroud)

php mysql ssh

5
推荐指数
1
解决办法
249
查看次数

FabricJS 将 json 转换为 png

我创建了以下图像作为fabricjs-json:

在此输入图像描述

json 如下所示:

{
    "version": "5.2.1",
    "objects": [
        {
            "type": "circle",
            "version": "5.2.1",
            "originX": "center",
            "originY": "center",
            "left": "100",
            "top": "100",
            "width": "60",
            "height": "60",
            "fill": "#e53e3e",
            "name": "a",
            "radius": "30",
            "stroke": null,
            "padding": "0"
        },
        {
            "type": "triangle",
            "version": "5.2.1",
            "originX": "center",
            "originY": "center",
            "left": "80",
            "top": "229.13",
            "fill": "#e0da2e",
            "name": "b",
            "height": "100",
            "width": "100",
            "stroke": null,
            "padding": "0"
        },
        {
            "type": "rect",
            "version": "5.2.1",
            "originX": "center",
            "originY": "center",
            "left": "303.02",
            "top": "69.96",
            "width": "50",
            "height": "50",
            "fill": …
Run Code Online (Sandbox Code Playgroud)

javascript node.js fabricjs node-canvas

5
推荐指数
1
解决办法
769
查看次数

Grails - 创建和映射视图时出错

我创建了一个名为的视图signIn.gsp.我把它放进了URLMapping.groovy:

class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?(.${format})?"{
            constraints {
                // apply constraints here
            }
        }

        "/"(view:"/index")
        "signIn"(view:'/signIn')
        "500"(view:'/error')
    }
}
Run Code Online (Sandbox Code Playgroud)

我还将它添加到弹簧安全部分Config.groovy:

// Added by the Spring Security Core plugin:
grails.plugin.springsecurity.userLookup.userDomainClassName = 'com.testApplication.secureApplication.Person'
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'com.testApplication.secureApplication.PersonRole'
grails.plugin.springsecurity.authority.className = 'com.testApplication.secureApplication.Role'
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
    '/':                              ['permitAll'],
    '/index':                         ['permitAll'],
    '/signIn':                         ['permitAll'],
    '/index.gsp':                     ['permitAll'],
    '/**/js/**':                      ['permitAll'],
    '/**/css/**':                     ['permitAll'],
    '/**/images/**':                  ['permitAll'],
    '/**/favicon.ico':                ['permitAll']
]
Run Code Online (Sandbox Code Playgroud)

但是,在运行我的应用程序时,我得到:

|Running Grails application
Configuring Spring Security Core ...
... finished configuring Spring Security …
Run Code Online (Sandbox Code Playgroud)

grails grails-2.0

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

获取列表的子列表

我有一个围绕3000元素长的向量。我用 提取了向量中的特定点which(...)。现在我想拥有-120 before这一点和+120 after这一点。

我的清单是这样的:

> testList$Date

     [1] "01.01.2002" "02.01.2002" "03.01.2002" "04.01.2002" "07.01.2002"
       [6] "08.01.2002" "09.01.2002" "10.01.2002" "11.01.2002" "14.01.2002"
      [11] "15.01.2002" "16.01.2002" "17.01.2002" "18.01.2002" "21.01.2002"
      [16] "22.01.2002" "23.01.2002" "24.01.2002" "25.01.2002" "28.01.2002"
      [21] "29.01.2002" "30.01.2002" "31.01.2002" "01.02.2002" "04.02.2002"
      [26] "05.02.2002" "06.02.2002" "07.02.2002" "08.02.2002" "11.02.2002"
      [31] "12.02.2002" "13.02.2002" "14.02.2002" "15.02.2002" "18.02.2002"ect....
Run Code Online (Sandbox Code Playgroud)

我可以做一个for-loop迭代列表并将其保存为子列表。但是,我认为这不是很有效。我如何在 R 中实现它?

我很感激你的回答!

更新 使用时lapply我得到:

> 120BeforeSublist <- lapply(event, function(x) c(x-120, x))
> (120BeforeSublist)
[[1]]
[1] 1875 1995 …
Run Code Online (Sandbox Code Playgroud)

statistics r

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

快速方法将String []与List进行比较

我想将String数组与具有市场对象的列表进行比较.

我实现了这样的代码:

private List<Data> addMarketData(List<Data> list) {
    String[] SEE = new String[]{"Albania", "Bosnia and Herzegovina", "Bulgaria", "Croatia", "Macedonia FYR", "Moldavia", "Montenegro", "Romania", "Serbia", "Slovenia" };
    List<String> seeList = Arrays.asList(SEE);
    String[] CEE = new String[]{"Czech Republic", "Hungary", "Poland", "Slovakia"}; 
    List<String> ceeList = Arrays.asList(CEE);
    for (int i = 0; i < list.size(); i++) {
        for (int j = 0; j < seeList.size(); j++) {
            if(list.get(i).getPropertyCountry().equals(seeList.get(j).toString())) {
                list.get(i).setMarket("SEE");
            }   
        }
        for (int k = 0; k < ceeList.size(); k++) {
            if(list.get(i).getPropertyCountry().equals(ceeList.get(k).toString())) {
                list.get(i).setMarket("CEE"); …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

定期刷新IMPORTXML()电子表格功能

我有一个包含大约30个importxml函数的大表,它们从一个通常每天更新两次的网站获取数据.

我想importxml及时(每8小时)为我的Google电子表格运行该功能,以便将数据保存在另一张表格中.保存已经有效,但更新不行!

我在Google Spreadsheet行更新中读到它可能每2小时运行一次,但我不相信这是真的,因为我将其添加到我的工作表中没有更改或更新,当电子表格未打开时.

我如何importxml以简单的方式"触发" 我的Google电子表格中的功能,因为我有很多importxml功能?

google-sheets google-apps-script

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

在外部标签上附加/前置空格

我想在外部标签上附加/预先添加一个空格。

我尝试了以下方法:

var $elem = $('<span>', {
  'data-function': "addSynonym",
  'data-options': '[ test1, test2, test3]',
  'html': $('<span>', {
    'text': 'test4',
    'css': {
      backgroundColor: 'yellow'
    }
  })
});

$elem.append("&nbsp;")
$elem.prepend("&nbsp;");

console.log($elem[0]);
console.log($elem[0].innerHTML);
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

如您所见,只有内部标签有空格。

但是,我想将它放在外标签上。像下面这样:

&nbsp;<span data-function="addSynonym" data-options="[ test1, test2, test3]"><span style="background-color: yellow;">test4</span></span>&nbsp;

Run Code Online (Sandbox Code Playgroud)

任何建议如何做到这一点?

我感谢您的回复!

javascript jquery

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