小编err*_*ata的帖子

使用yarn在Visual Studio Code中运行NodeJS项目

我有一个NodeJS项目,我可以从命令行启动yarn start命令.我package.json看起来像这样:

{
  "name": "projectname",
  "version": "0.0.1",
  "description": "",
  "author": "My Name",
  "license": "",
  "scripts": {
    "start": "yarn dev",
    "dev": "yarn stop && pm2 start pm2-dev.yaml && webpack-dev-server --progress",
    "prod": "yarn stop && yarn build && pm2 start pm2-prod.yaml",
    "build": "rimraf dist lib && babel src -d lib --ignore test.js && cross-env NODE_ENV=production webpack -p --progress",
    "stop": "rimraf logs/* && pm2 delete all || true"
  },
  "dependencies": {
    "body-parser": "~1.16.0",
    "ejs": "2.5.5",
    "express": "^4.14.1",
    "pg": "^6.1.2", …
Run Code Online (Sandbox Code Playgroud)

node.js visual-studio-code yarnpkg

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

从命令行启用/禁用 Windows 10 中的设备

我有一个特定的硬件,我想在每次 Windows 重新启动时禁用并重新启用它。我创建了一个批处理脚本,应该这样做,然后运行我的程序:

cd %~dp0
devcon.exe disable "PCI\VEN_1002&DEV_687F"
timeout /t 3
devcon.exe enable "PCI\VEN_1002&DEV_687F"

runMyWindows.exe --totally-not-virus
Run Code Online (Sandbox Code Playgroud)

首先我不确定这是否devcon.exe是一个合适的应用程序,因为我根本没有编写 Windows 脚本的经验。

但是,我注意到这些命令并不能很好地完成工作,因为runMyWindows.exe在我转到 Windows 设备管理器并手动禁用和重新启用此设备之前,我的程序无法正常工作。

我在这台机器上只有 1 个用户,它在“管理员”组中,除了双击.bat文件外,我没有以任何特殊方式运行此脚本,或者在重新启动的情况下,它是从启动文件夹 ( C:\Users\oxxo\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)运行的。

有没有办法在我的批处理脚本中正确执行此操作,该脚本应在 Windows 启动时自动运行?

windows batch-file device-manager devcon windows-10

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

样式Bootstrap的btn-group-justified,添加边距和垂直大小

我想btn-group-justified用无线电input字段设置原始Bootstrap的样式(http://getbootstrap.com/javascript/#buttons-examples).

原始样式如下所示:
在此输入图像描述

但是我想把每个按钮都做成方形按钮,并在它们之间给它们一些空白.像这样的东西:
在此输入图像描述

我尝试使用Bootstrap示例中的一些修改过的html标记

[data-toggle="buttons"] .btn>input[type="radio"] {
  display: none;
}

.category-select .btn-container {
  position: relative;
  width: 19%;
  padding-bottom: 19%;
  float: left;
  height: 0;
  margin: 1%;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.btn-container .btn,
.btn-container .btn input {
  max-width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="btn-group-justified category-select" data-toggle="buttons">
  <div class="btn-container">
    <label class="btn category category-one">
          <input type="radio" name="options" id="option1"> One
        </label>
  </div>
  <div class="btn-container">
    <label class="btn category category-two">
          <input type="radio" name="options" id="option2"> Two
        </label>
  </div>
  <div class="btn-container">
    <label class="btn category …
Run Code Online (Sandbox Code Playgroud)

html css css3 twitter-bootstrap twitter-bootstrap-3

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

使用一组值重复 GitHub 操作工作流程中的一个步骤

我正在尝试创建一个 GitHub Actions 工作流程,该工作流程将收集在上次提交中更改的特定路径,并为每个收集的路径(如果有)运行一个步骤。

目前,在我的工作流程中,我正在创建一个路径数组,但我不确定如何处理我的数组:

name: Test

on:
  push

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      # This step will create "an array" of strings, e.g. "path1 path2 path3"
      - name: array
        id: arr
        run: |
          arr=()
          for i in "$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }})"
          do
            if [[ $i == *"path1"* ]]; then
              arr+=("path1")
            fi
            if [[ $i == *"path2"* ]]; then
              arr+=("path2")
            fi
          done
          echo ::set-output name=arr::${arr[@]}

      # How to run this step by iterating …
Run Code Online (Sandbox Code Playgroud)

workflow yaml github-actions

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

在OpenAPI(Swagger)中使用HMAC-SHA256身份验证测试API路由

我正在尝试为需要HMAC-SHA256身份验证的API路由生成OpenAPI(Swagger)文档。这意味着我必须Authorization为每个请求包含标头,每个标头由API密钥和生成的HMAC签名组成,并用冒号分隔(例如Authorization: API_KEY:GENERATED_SIGNATURE)。

我可以使用JavaScript轻松生成所需的签名,但无法弄清楚如何在Swagger-UI“授权”弹出窗口中添加“密钥”和“秘密”输入字段,以及如何最终将其添加到Authorization每个请求的标头中。

OpenAPI Specification v3完全可以实现这样的功能吗?

javascript authorization hmac swagger swagger-ui

7
推荐指数
1
解决办法
547
查看次数

Swift结构:为单个属性处理多种类型

我正在使用Swift 4并尝试解析一些JSON数据,这些数据显然在某些情况下可以为同一个键具有不同的类型值,例如:

{
    "type": 0.0
}
Run Code Online (Sandbox Code Playgroud)

{
    "type": "12.44591406"
}
Run Code Online (Sandbox Code Playgroud)

我实际上坚持定义我,struct因为我无法弄清楚如何处理这种情况,因为

struct ItemRaw: Codable {
    let parentType: String

    enum CodingKeys: String, CodingKey {
        case parentType = "type"
    }
}
Run Code Online (Sandbox Code Playgroud)

投掷"Expected to decode String but found a number instead.",当然,

struct ItemRaw: Codable {
    let parentType: Float

    enum CodingKeys: String, CodingKey {
        case parentType = "type"
    }
}
Run Code Online (Sandbox Code Playgroud)

因此投掷"Expected to decode Float but found a string/data instead.".

在定义我的时候如何处理这个(和类似的)情况struct呢?

json data-structures swift swift-structs swift4

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

使用BeautifulSoup选择特定的<tr>标签

我用这段代码用BeautifulSoup获取一些html表行:

from bs4 import BeautifulSoup
import urllib2
import re

page = urllib2.urlopen('www.something.bla')
soup = BeautifulSoup(page)
rows = soup.findAll('tr', attrs={'class': re.compile('class1.*')})
Run Code Online (Sandbox Code Playgroud)

这就是我得到的结果:

<tr class="class1 class2 class3">...</tr>
<tr class="class1 class2 class3">...</tr>
<tr class="class1 class5">...</tr>
<tr class="class1_a class5_a">...</tr>
<tr class="class1 class5">...</tr>
<tr class="class1_a class5_a">...</tr>
<!-- etc. -->
Run Code Online (Sandbox Code Playgroud)

但是,我想排除(或者不首先选择它们)那些具有class1 class2 class3属性的行.

我怎样才能做到这一点?
感谢帮助!

python beautifulsoup

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

仅从另一个数组的值创建关联数组-PHP

我有一个简单的数组,其中key 总是后面跟着值:

Array (
    [0] => x
    [1] => foo
    [2] => y
    [3] => bar
)
Run Code Online (Sandbox Code Playgroud)

我想将其转换为关联的:

Array (
    [x] => foo
    [y] => bar
)
Run Code Online (Sandbox Code Playgroud)

最简单,最优雅的方法是什么?

php arrays dictionary associative-array

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

在PHPunit中测试异常总是失败

我在PHP中有很少的自定义异常:

class MainException extends Exception {};
class ExceptionOne extends MainException {};
class ExceptionTwo extends MainException {};
Run Code Online (Sandbox Code Playgroud)

我用两种简单的方法在课堂上使用它们:

public function firstFunction($param) {
    if ($some_condition) {
        // do whatever
    } else {
        throw new ExceptionOne();
    }
}

public function secondFunction($param) {
    if ($some_condition) {
        // do whatever
    } else {
        throw new ExceptionTwo();
    }
}
Run Code Online (Sandbox Code Playgroud)

我还对两个异常进行了PHPUnit测试,类似于:

public function testFirstException() {
    try {
        // anything
    } catch (Exception $e) {
        $this->assertType('ExceptionOne', $e);
        $this->assertType('MainException', $e);
    }
}
public function testSecondException() {
    try {
        // …
Run Code Online (Sandbox Code Playgroud)

php phpunit exception

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

在 openpyxl 生成的 XLSX 文件中正确渲染新行

我正在使用openpyxl打开一个 .xlsx 文件,更新其中的一些值并将其另存为不同的 .xlsx 文件。我正在尝试添加一个带有新行的页脚:

# example code
wb = openpyxl.load_workbook('file.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')
sheet.header_footer.left_footer.font_size = 7
sheet.header_footer.left_footer.text = '&BSome text&B\nMore text\nEven more'
sheet.header_footer.right_footer.font_size = 7
sheet.header_footer.right_footer.text = 'Page &P of &N'
wb.save('new_file.xlsx')
Run Code Online (Sandbox Code Playgroud)

但是当我打开新创建的文件并查看页脚时,\n会以一种奇怪的方式被替换:

Some text^lMore text^pEven more
Run Code Online (Sandbox Code Playgroud)

我还注意到,如果我尝试在 libreoffice 的帮助下将其转换为 PDF,例如像这样:

os.system('libreoffice --headless --invisible --convert-to pdf --outdir /path/on/disk new_file.xlsx')
Run Code Online (Sandbox Code Playgroud)

生成的 PDF 再次将其呈现为不同的内容:

Some text_x000D_More text_x000D_Even more
Run Code Online (Sandbox Code Playgroud)

如何在页脚中正确生成新行?
(可能值得一提的是,我在 Ubuntu 14.04 上使用带有 Python 3.4 的 openpyxl 2.3.3。LibreOffice 的版本是 5.0.5.2)

python excel python-3.x openpyxl

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