小编Naj*_*aji的帖子

如何模拟 pdf Blob

试图创建一个有效的 pdf blob 没有运气...

const blob = new Blob(["testing"], { type: "application/pdf" });
console.log(blob);
Run Code Online (Sandbox Code Playgroud)

我这样做是因为打字稿输入new Blob()告诉我第一个参数是一个数组BlobParts,它可以是一个字符串。

给我这个错误:

Error {
      name: 'InvalidPDFException',
      message: 'Invalid PDF structure'
}
Run Code Online (Sandbox Code Playgroud)

作为参考,我试图在单元测试中模拟一个有效的 pdf blob

javascript pdf unit-testing reactjs jestjs

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

从一个 Bash 脚本运行多个 Docker 镜像

我有一个 bash 文件,可以使用运行我的应用程序 docker 映像docker run -it --network test_network -p 8000:8000 testApp,但我还需要使用运行我的 mysql 映像docker run -it --network test_network -p 3308:3308 mysql/mysql-server

通常我会手动打开一个单独的终端窗口来运行每个窗口,但我正在尝试编辑 bash 脚本,以便它可以为我执行这两项操作。但不确定如何?

macos bash terminal ios docker

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

使用React,Jest,React-Testing-Library测试失败的案例

我有一个React组件,当编程错误时会抛出一个错误。例如,组件Component采用所需的prop data,我有:

if (!data) { throw new Error("data is not provided") }

写在我的组件中以处理此错误。使用jest我的测试说:

test("throw invalid component error", () => {
    mockConsole();
    const { container } = render(<Component />);
    expect(container).toThrowError();
});
Run Code Online (Sandbox Code Playgroud)

当我运行测试时,Jest说测试失败,然后它指向我throw new Error(...)编写代码的那一行。我在开玩笑地想做些什么吗?

javascript unit-testing reactjs jestjs

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

git log 说我有一个叉子,但我没有

由于某种原因,我的 git 日志显示我有一个fork/main分支,如下所示:

~ git log
commit abc123abc123 (HEAD -> main, origin/main, origin/HEAD)
Author: Me
...

commit xyz789xyz789 (fork/main)
Author: Me
...
Run Code Online (Sandbox Code Playgroud)

但在本地,我只有 1 个分支(主分支),并且在我的私人 github 存储库上Forks显示0. 这是什么东西以及我如何摆脱它/理解它?

可能相关,但当我这样做时gh pr create,它会两次为我提供我的仓库作为选项。我的其他私人仓库不会发生这种情况:

? Where should we push the 'testing' branch?  [Use arrows to move, type to filter]
> me/my-private-repo
  me/my-private-repo
  Skip pushing the branch
  Cancel
Run Code Online (Sandbox Code Playgroud)

更新:

~ git remote -vv
fork    https://github.com/me/my-repo.git (fetch)
fork    https://github.com/me/my-repo.git (push)
origin  https://github.com/me/my-repos-old-name.git (fetch)
origin  https://github.com/me/my-repos-old-name.git (push)

~ …
Run Code Online (Sandbox Code Playgroud)

git github

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

Dockerized Django can't connect to MySQL

Using this tutorial https://semaphoreci.com/community/tutorials/dockerizing-a-python-django-web-application, I'm dockering my Django application in a VirtualBox using docker-machine. Everything has gone splendidly until I go to my browser and my application says that it's having issues with MySQL.

Then i found this documentation for dockerizing an instance of mysql https://github.com/mysql/mysql-docker which I followed, creating the image in the same development VirtualBox that I created. The error I was originally getting was

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Run Code Online (Sandbox Code Playgroud)

My Django …

python mysql django docker docker-machine

0
推荐指数
1
解决办法
1564
查看次数

无法在赋值中使用单词(类型接口 {})作为类型字符串:需要类型断言

我是 Go 新手,由于某种原因我所做的事情对我来说似乎不太直接。

这是我的代码:

for _, column := range resp.Values {
  for _, word := range column {

    s := make([]string, 1)
    s[0] = word
    fmt.Print(s, "\n")
  }
}
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Cannot use word (type interface {}) as type string in assignment: need type assertion

resp.Values是一个数组的数组,所有数组都填充有字符串。

reflect.TypeOf(resp.Values)返回[][]interface {},

reflect.TypeOf(resp.Values[0])(即column)返回[]interface {}

reflect.TypeOf(resp.Values[0][0])(即word)返回string

我的最终目标是让每个单词都有自己的数组,所以不要:

[[Hello, Stack], [Overflow, Team]], 我会: [[[Hello], [Stack]], [[Overflow], [Team]]]

arrays types interface go type-assertion

0
推荐指数
1
解决办法
6914
查看次数

从每列中选择不同的值

有没有一种方法可以从 MYSQL 数据库中的每一列获取 Distinct 值,而不必SELECT DISTINCT为每一列执行多个语句?

现在在我的 Rails 控制器中我用来.pluck()运行:

@first = User.distinct.pluck(:first_name)
@last = User.distinct.pluck(:last_name)
@city = User.distinct.pluck(:city)
@state = User.distinct.pluck(:state)
@age = User.distinct.pluck(:age)

@info = {
        'first' => @first,
        'last' => @last,
        'city' => @city,
        'state' => @state,
        'age' => @age
    }

respond_with @info
Run Code Online (Sandbox Code Playgroud)

它创建了一个对象,其中包含我的两个唯一数组,但需要大约 7.7 秒(我的表有 320 万行完全填充的行)并运行两个单独的 SQL 查询。

我尝试了这种方法,但这给了我每个独特组合的数组:

@info = User.distinct.select(:first_name, :last_name, :city, :state, :age)

respond_with @info
Run Code Online (Sandbox Code Playgroud)

ruby mysql sql ruby-on-rails

0
推荐指数
1
解决办法
4154
查看次数