小编Tho*_*ggi的帖子

哪种写回调更好?

只是通过看到我现在写的东西,我可以看到一个更小,所以在代码 方面,高尔夫Option 2是更好的选择,但就哪个更清洁,我更喜欢Option 1.我真的很喜欢社区对此的意见.

选项1

something_async({
    success: function(data) {
        console.log(data);
    },
    error: function(error) {
        console.log(error);
    }
});
Run Code Online (Sandbox Code Playgroud)

选项2

something_async(function(error,data){
    if(error){
        console.log(error);
    }else{
        console.log(data);
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous callback

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

strip_tags()函数黑名单而不是白名单

我最近发现了一个strip_tags()函数,它接受一个字符串和一个接受的html标签列表作为参数.

让我们说我想摆脱字符串中的图像这里是一个例子:

$html = '<img src="example.png">';
$html = '<p><strong>This should be bold</strong></p>';
$html .= '<p>This is awesome</p>';
$html .= '<strong>This should be bold</strong>';

echo strip_tags($html,"<p>");
Run Code Online (Sandbox Code Playgroud)

返回:

<p>This should be bold</p>
<p>This is awesome</p>
This should be bold
Run Code Online (Sandbox Code Playgroud)

因此我通过<strong>也许<em>将来摆脱了格式化.

我想要一种黑名单的方法,而不是像白名单那样的白名单:

echo blacklist_tags($html,"<img>");
Run Code Online (Sandbox Code Playgroud)

返回:

<p><strong>This should be bold<strong></p>
<p>This is awesome</p>
<strong>This should be bold<strong>
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

php

6
推荐指数
1
解决办法
1805
查看次数

没有提交就推

我有一个git repo,我把它推到服务器上.然后我在服务器上设置了一个post-receive挂钩.我想检查它是否有效.我必须再次承诺,看它是否有效?我真的想在我试图建立这个设置时强行推动,而不是继续进行没有实际价值的提交.它不起作用,我只是不明白.

$ git push --force origin master
Everything up-to-date
Run Code Online (Sandbox Code Playgroud)

git

6
推荐指数
1
解决办法
4500
查看次数

POST请求应该呈现HTML还是重定向?

POST请求应该呈现HTML还是重定向?

我讨厌你在页面上刷新并让浏览器告诉你,你将再次发布数据.

post http

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

从凉亭组件中删除符号链接或复制文件

我需要一种方法来定义我需要的凉亭组件文件.在bower.json组件中,我需要的文件未在main设置中指定.我想要一种方法来将文件符号链接或复制到bower的另一个目录资产目录中.我使用Grunt而我找不到任何有用的东西.我喜欢通过某种方式定义所有文件json.

抱歉,如果这不是完全stackoverflow值得,但我真的很想找到存在的东西,而不是重新发明轮子.

我在这里找到了这段代码,我不知道如何使用它.这将是理想的.

"dependencies": {
  "font-awesome": ">= 3.2.1"
},
"overrides": {
  "font-awesome": {
    "main": [
      "css/font-awesome.min.css",
      "font/FontAwesome.otf",
      "font/fontawesome-webfont.eot",
      "font/fontawesome-webfont.svg",
      "font/fontawesome-webfont.ttf",
      "font/fontawesome-webfont.woff"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

json gruntjs bower

6
推荐指数
1
解决办法
4688
查看次数

检测Node.js中的硬链接

如何判断文件系统路径是否是与Node.js的硬链接?该功能fs.lstat提供了一个stats对象,给予时硬链接将为返回true stats.isDirectory()stats.isFile()分别.fs.lstat不提供任何注意正常filedirectory链接之间差异的内容.

If my understanding of how linking (ln) works is correct, then a linked file points to the same place on the disk as the original file. This would mean that both the original and linked version are identical, and there is no way to tell the difference between the original file and the linked.

The functionality I'm looking for is as follows:

This …

javascript filesystems hardlink node.js

6
推荐指数
1
解决办法
600
查看次数

限制正在运行的承诺的并发性

我正在寻找一个promise函数包装器,它可以在给定的promise运行时限制/限制,以便在给定的时间只运行一定数量的promise.

在下面的情况下delayPromise,永远不应该同时运行,它们应该以先来先服务的顺序一次运行一个.

import Promise from 'bluebird'

function _delayPromise (seconds, str) {
  console.log(str)
  return Promise.delay(seconds)
}

let delayPromise = limitConcurrency(_delayPromise, 1)

async function a() {
  await delayPromise(100, "a:a")
  await delayPromise(100, "a:b")
  await delayPromise(100, "a:c")
}

async function b() {
  await delayPromise(100, "b:a")
  await delayPromise(100, "b:b")
  await delayPromise(100, "b:c")
}

a().then(() => console.log('done'))

b().then(() => console.log('done'))
Run Code Online (Sandbox Code Playgroud)

关于如何获得像这样的队列设置的任何想法?

我有精彩的"去抖"功能Benjamin Gruenbaum.我需要修改它来根据它自己的执行而不是延迟来限制一个承诺.

export function promiseDebounce (fn, delay, count) {
  let working = 0
  let queue = []
  function work () { …
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise bluebird

6
推荐指数
1
解决办法
5001
查看次数

问题为承诺率限制功能创建有效的测试用例

我正在尝试为promiseRateLimit下面的函数创建一个有效的测试用例.该promiseRateLimit函数的工作方式是使用a queue来存储传入的promises并将delay它们放在它们之间.

import Promise from 'bluebird'

export default function promiseRateLimit (fn, delay, count) {
  let working = 0
  let queue = []
  function work () {
    if ((queue.length === 0) || (working === count)) return
    working++
    Promise.delay(delay).tap(() => working--).then(work)
    let {self, args, resolve} = queue.shift()
    resolve(fn.apply(self, args))
  }
  return function debounced (...args) {
    return new Promise(resolve => {
      queue.push({self: this, args, resolve})
      if (working < count) work()
    })
  }
}
Run Code Online (Sandbox Code Playgroud)

以下是该功能的实例.

async function …
Run Code Online (Sandbox Code Playgroud)

javascript promise bluebird

6
推荐指数
1
解决办法
119
查看次数

所有测试都通过 100% 覆盖率,但 jest 返回退出代码 1

我研究过--detectLeaks--detectOpenHandles,它确实引发了一些错误,但输出中没有明显的问题。

\n\n

我有一个 monorepo,我正在 docker/管道中的 jenkins 中运行 jest。

\n\n
> abide@1.0.0 jest /var/jenkins_home/workspace/abide\n> jest --coverage --no-cache --runInBand\n\n[BABEL] Note: The code generator has deoptimised the styling of "/var/jenkins_home/workspace/abide/node_modules/lodash/lodash.js" as it exceeds the max of "500KB".\nPASS packages/help.parse-argv/index.test.js (10.842s)\n[BABEL] Note: The code generator has deoptimised the styling of "/var/jenkins_home/workspace/abide/node_modules/text-encoding/lib/encoding-indexes.js" as it exceeds the max of "500KB".\nhello\nnpm notice created a lockfile as package-lock.json. You should commit this file.\n+ example-working@0.0.1\nadded 2 packages from 2 contributors and audited 2 packages in 2.837s\nfound …
Run Code Online (Sandbox Code Playgroud)

jestjs

6
推荐指数
1
解决办法
5195
查看次数

Typescript lint“no-unused-vars”与声明的元组

我有一行代码,如下所示:

const [full, text, url] = markdownLink.exec(match) || [null, null, '']
Run Code Online (Sandbox Code Playgroud)

但是我没有使用full,并且 linter 给了我一个警告。

第 28 行:“full”被赋值但从未使用过

我想像这样声明元组,但我不需要full。有没有一种语法方法可以通过跳过完整来解决这个问题?

tuples typescript eslint tslint

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