我遇到以下问题。我已经使用一个名为 的模型工作了一段时间Location,但现在我发现 Angular 也有这样一个模型,所以我在一个组件中发生了以下碰撞,而我需要这两个模型:
import { Location } from 'src/app/core/models/location.model';
import { Location } from '@angular/common';
Run Code Online (Sandbox Code Playgroud)
是否有任何解决方法,例如为库提供别名?
当前的问题:
重复的标识符“位置”.ts(2300)
我正在尝试显示图像的直方图并仅显示一些颜色。我已经用 JFreeChart 和 createXYLineChart 做到了这一点,并通过遍历所有像素来获取所有数据。
为了加快速度,我正在尝试使用“createHistogram”来实现。我遵循了这个代码。
要使用新值更新图表,我使用了这两种方法:
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDataset(setHistogram(red, green, blue));
Run Code Online (Sandbox Code Playgroud)
作为 setHistogram 一个返回 HistogramDataset 的方法取决于哪个复选框被激活(布尔红色、绿色和蓝色)。
这按预期正常工作。
当我这样做时,我必须做的第二件事是更新每个系列的颜色,否则它们将获得默认值。我按照与值大致相同的程序进行了操作:
private void setHistogramColors(boolean red, boolean green, boolean blue) {
XYPlot plot = (XYPlot) chart.getPlot();
XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
renderer.setBarPainter(new StandardXYBarPainter());
Paint[] paintArray = null;
if (red) {
if (green) {
if (blue) {
paintArray = new Paint[3];
paintArray[0] = new Color(0x80ff0000, true);// translucent red, green & blue
paintArray[1] = new Color(0x8000ff00, true);
paintArray[2] = new …Run Code Online (Sandbox Code Playgroud) 您好,我正在使用在线正则表达式模拟器来测试我所写的内容是否正确:我想从以下文本中提取信息:
Test23242asdsa 800,03 23.05.19 22.05.19
Tdsadas,tsadsa test 1.020,03 23.05.19 22.05.19
Test,23242 0,03 23.05.19 22.05.19
Run Code Online (Sandbox Code Playgroud)
我尝试在 perl 中使用相同的代码:
use strict;
my $entry = 'Test23242asdsa 0,03 23.05.19 22.05.19';
my ($name, $expense, $date_expense, $date_paid) = $1, $2, $3, $4 if ($entry =~ m/^(.+)\s((?:\d+\.)?\d{1,3},\d{2})\s(\d{2}\.\d{2}\.\d{2})\s(\d{2}\.\d{2}\.\d{2})$/);
print "Name: '$name', Expense: '$expense', Date: '$date_expense', Date Paid: '$date_paid' \n";
Run Code Online (Sandbox Code Playgroud)
如果我在这里使用相同的正则表达式:
https://regex101.com/
^(.+)\s((?:\d+\.)?\d{1,3},\d{2})\s(\d{2}\.\d{2}\.\d{2})\s(\d{2}\.\d{2}\.\d{2})$
Run Code Online (Sandbox Code Playgroud)
它正确检测 de regex。我虽然 python 和 perl 使用相同的正则表达式语法,所以我不明白发生了什么。
我一直在查看 perl 的一些模块,我发现t在扩展名为.t.
这些脚本可以直接使用perl <test>.t.
我想做一个小框架来测试一个应用程序。我想进行许多简单的测试。然后是一个主脚本,它调用这个测试来一次验证所有内容,但仍然能够单独运行小测试,而无需手动禁用主脚本中的其他测试。
我的问题是我应该怎么做这个电话?正如如何从 Perl 脚本中运行 Perl 脚本中所建议的那样?应该避免这种进程间通信,而是使用模块,但这将无法直接运行测试。
我的猜测是做如下事情。在我需要在 selenium 脚本中提供一些参数的示例中,这是文件夹结构:
??? main_script.pl
??? t
??? 00-Test_1.t
??? 01-Test_2.t
??? 02-Test_3.t
??? 03-Test_4.t
Run Code Online (Sandbox Code Playgroud)
我会这样称呼他们:
??? main_script.pl
??? t
??? 00-Test_1.t
??? 01-Test_2.t
??? 02-Test_3.t
??? 03-Test_4.t
Run Code Online (Sandbox Code Playgroud)
每个测试都会有这样的东西:
system($^X, "./t/00-Test_1.t", "-b $browser", "-s $server", "-d $debug");
my $results = capture($^X, "./t/00-Test_1.t", "-b $browser", "-s $server", "-d $debug";
$log->info("Result is $results");
Run Code Online (Sandbox Code Playgroud)
这是一种正确的方法还是有更适合使用模块的方法?
如果可能的话,我想在一行中进行以下分配,但又不要太长:
my $variable = defined($self->{_some_thing_stored_here}) ? $self->{_some_thing_stored_here} : new some_function(@with_some_parameters);
Run Code Online (Sandbox Code Playgroud)
是否有可能以类似的方式类似于使用“ $ _”在循环中获取变量以获取if条件的参数,因此它看起来像这样:
my $variable = defined($self->{_some_thing_stored_here}) ? $_ : new some_function(@with_some_parameters);
Run Code Online (Sandbox Code Playgroud)
PD:我知道可以将条件放入变量中,但是我想知道是否可以将其做得更短。
我想利用这个库来漂亮地打印我的测试的差异,Test::Differences;但我不想把它算在我的计划中,因为这只是在我的用例中用于调试。
所以我创建了这个问题的一个最小示例来重现这个问题,我知道这样做不是“正确的”,但是很好地说明了这个问题。
use strict;
use warnings;
use utf8::all;
use open ':std', ':encoding(UTF-8)';
use Test::Differences;
use Test::Deep::NoTest qw(cmp_details deep_diag);
use Test::More tests => 2;
use JSON;
my $context = 1;
my $extracted_ref = {
a => '1',
b => '2',
c => '3',
d => '4',
};
my $reference_ref = {
a => '1',
b => '3',
c => '3',
d => '4',
};
my ($is_compare_ok, $stack) = cmp_details($extracted_ref,$reference_ref);
my $json_reference = JSON->new->canonical->encode($reference_ref);
my $json_extracted = JSON->new->canonical->encode($extracted_ref);
ok(1);
if …Run Code Online (Sandbox Code Playgroud) 我想发送一个命令,例如,执行ping:
ping google.es -n 500
Run Code Online (Sandbox Code Playgroud)
我可以用以下命令执行命令:
my $command = "ping google.es -n 500";
system($command);
Run Code Online (Sandbox Code Playgroud)
我会在运行时打印输出.
我可以将它存储到变量中:
my $command = "ping google.es -n 500";
my $output = `$command`;
Run Code Online (Sandbox Code Playgroud)
但是如何获取命令的输出WHILE它正在运行,然后在变量中使用输出?
我看到这样的解决方案,但它不起作用.它运行脚本,完成后将打印结果:
my $variable = '';
open my $command_pipe, "-|", $command or die "Pipe from $command failed: $!";
while (<$command_pipe>) {
print $_;
$variable . = $_;
}
Run Code Online (Sandbox Code Playgroud)
更新:显示问题的示例.我有2个perl脚本,一个调用另一个:
test.pl:
use strict;
use warnings;
my $command = 'perl test2.pl';
print "Localtime: " . localtime() . "\n";
my $variable …Run Code Online (Sandbox Code Playgroud) 我想使用 firebase 处理一些图像,并根据结果在图像上打印一些内容,但我不想使用 imagepicker 中的图像,而是在相机实时运行时执行此操作。
使用默认插件可以吗?我已经搜索了几个小时,但找不到任何可以逐帧交互的内容。
我已经花了几天时间在类似问题中研究这个问题,但无法找到解决方案。这应该很简单,我有一个模型:
model.py
class Item(models.Model):
"""Class to represent an item..."""
label = models.TextField(null=True)
name = models.TextField()
category = models.ForeignKey( "Category", on_delete=models.SET_NULL,
null=True, default=DEFAULT_CATEGORY_ID)
class Category(models.Model):
"""Class to represent the category of an Item. Like plants, bikes..."""
name = models.TextField()
description = models.TextField(null=True)
Run Code Online (Sandbox Code Playgroud)
view.py
class ItemViewset(viewsets.ModelViewSet): # pylint: disable=too-many-ancestors
"""API Endpoint to return the list of items"""
queryset = Item.objects.all()
serializer_class = ItemSerializer
Run Code Online (Sandbox Code Playgroud)
serializer.py
class ItemSerializer(serializers.ModelSerializer):
"""Serializer for Item."""
category = CategorySerializer(read_only=True)
class Meta: # pylint: disable=too-few-public-methods
"""Class to represent metadata of …Run Code Online (Sandbox Code Playgroud)