问:
How can I dynamically create and add tags in PowerShell script during Invoke-Pester command?
I have several Describe/It tests in a ps1 file called Behavior.Tests.ps1. Each test, however, can only run successfully on systems with specific hardware.
I am aware that I can use tags like this in the Invoke-Pester command:

```<code>Invoke-Pester $path -Tag "Acceptance" -ExcludeTag "Flaky", "Slow", "LinuxOnly"
</code>```

But I cannot count on the user to know the specifics of their hardware and choose the correct -Tag and -ExcludeTag to include. What I would rather do for my workflow is simply have Invoke-Pester .\Behavior.Tests.ps1, and then in the script have code like this that would get hardware info and build the right list of Tags and ExcludeTags:

```<code>if ($currentHardware -in $HardwareList) {
    $ExcludeTag += $TagFlaky
}
</code>```

Then I would have a list of Tags and ExcludeTags before the first Describe/It that would run the right tests in the entire ps1 file. Is this possible in v5 Pester? I tried to debug and find the argument -Tag to modify it, but I could not find it.

答:
You could create a wrapper PowerShell script that determines the tags prior to calling Invoke-Pester and then you can use that to Invoke Pester with the required tags.

For example:

```<code>$ComputerInfo = Get-ComputerInfo

$OS = switch ($ComputerInfo.WindowsProductName) {
    { $_ -match 'Windows 10' } { 'Win10' }
    { $_ -match 'Windows 8' { { 'Win8' }
    { $_ -match 'Linux' } { 'Linux' }
}

$Processor = switch ($ComputerInfo.CsProcessors.Name) {
    { $_ -match 'Intel' } { 'Intel' }
    { $_ -match 'ARM' } { 'ARM' }
}

Invoke-Pester $Path -Tag $OS,$Processor
</code>```

Body:
I have several Describe/It tests in a ps1 file called Behavior.Tests.ps1. Each test, however, can only run successfully on systems with specific hardware.
I am aware that I can use tags like this in the Invoke-Pester command:

Invoke-Pester $path -Tag "Acceptance" -ExcludeTag "Flaky", "Slow", "LinuxOnly"

But I cannot count on the user to know the specifics of their hardware and choose the correct -Tag and -ExcludeTag to include. What I would rather do for my workflow is simply have Invoke-Pester .\Behavior.Tests.ps1, and then in the script have code like this that would get hardware info and build the right list of Tags and ExcludeTags:

if ($currentHardware -in $HardwareList) {
    $ExcludeTag += $TagFlaky
}

Then I would have a list of Tags and ExcludeTags before the first Describe/It that would run the right tests in the entire ps1 file. Is this possible in v5 Pester? I tried to debug and find the argument -Tag to modify it, but I could not find it.

Body:
You could create a wrapper PowerShell script that determines the tags prior to calling Invoke-Pester and then you can use that to Invoke Pester with the required tags.

For example:

$ComputerInfo = Get-ComputerInfo

$OS = switch ($ComputerInfo.WindowsProductName) {
    { $_ -match 'Windows 10' } { 'Win10' }
    { $_ -match 'Windows 8' { { 'Win8' }
    { $_ -match 'Linux' } { 'Linux' }
}

$Processor = switch ($ComputerInfo.CsProcessors.Name) {
    { $_ -match 'Intel' } { 'Intel' }
    { $_ -match 'ARM' } { 'ARM' }
}

Invoke-Pester $Path -Tag $OS,$Processor


来源: stackexchange

问:
Shared Server (Laravel + Angular) - Laravel API routes work but get 404 on everything else
I've been at this for a little while and can't seem to find the issue.
I have deployed a Laravel application which uses angular on the frontend, all works locally as intended.
Since I have deployed it to a shared hosting service on hostinger, I get a 404 on all routes other then the /api/.
It's like it can't locate the home blade. I have updated the autloader, I have tried several different htaccess's, I have updated all routes to use the new domain, I have updated the env file, all to no success.

I have attached some screenshots below of the set-up. Any help with this would be greatly appreciated.

File structure

public_html

htaccess

retromize_folder

答: It ended up being how the route was setup in my Web API. I was filtering based on the /API which was causing issues. Removing the filter got it working.</p>

ContentLicense: CC BY-SA 4.0


问:
OData accent-insensitive filter
How can I apply a filter accent-insensitive? In OData the "eq" operator is case and accent sensitive. The case is easy to fix, because the "tolower" but relative to the accent I'm not getting a simple solution. I know contains is supposed to be accent-insensitive but if I use contains filtering by "São José" I am only getting these responses "São José" and "São José dos Campos", it is missing "Sao Jose".

The following example filtering by "Florianopolis" is expected to return "Florianópolis", but it does not:

url: api/cidades/get?$filter=contains(nome, 'Florianopolis')

```<code>[HttpGet]
[EnableQuery]
public ActionResult<IQueryable<CidadeDTO>> Get()
{
    try
    {
        return Ok(_mapper.Map<IEnumerable<CidadeDTO>>(_db.Cidades));
    }
    catch (System.Exception e)
    {
        return BadRequest(e.GetBaseException().Message);
    }
}
</code>```

It should bring  aswell, like entity framework.

答:
If your OData model was mapped directly to EF models AND an IQueryable<T> expression was passed into OK() then the query is explicitly passed through to the database engine as SQL:

```<code>SELECT * FROM Cidades WHERE nome LIKE '%Florianopolis%'
</code>```

When that occurs, the Collation settings in the database connection will determine the comparison matching logic.

When your database collation is case and accent insensitive, but your data is still filtered as if it was not, then this is an indication that an IEnumerable<T> has been passed into OK() and the comparison logic is being evaluated in C# which by default in insensitive to both case and accent. Unfortunately this means that it is very likely that the entire data table has been loaded into memory first so that the filter can be applied.

In your case the OData model is mapped to DTO expressions that are mapped to the EF models via AutoMapper and that is where the generated query can break down. By calling Map() you are loading ALL records from the EF table and leaving the $filter criteria to be applied by the EnableQueryAttribute

For OData query conventions to be applied automatically you must return an IQueryable<T> from your method, or atleast pass an IQueryable<T> into the OK() response handler. With AutoMapper, you can use the Queryable Extensions to satisfy the IQueryable<T> requirement:

Queryable Extensions

When using an ORM such as NHibernate or Entity Framework with AutoMapper’s standard mapper.Map functions, you may notice that the ORM will query all the fields of all the objects within a graph when AutoMapper is attempting to map the results to a destination type.

...

ProjectTo must be the last call in the chain. ORMs work with entities, not DTOs. So apply any filtering and sorting on entities and, as the last step, project to DTOs.

In OData the last requirement (about ProjectTo) is still problematic because the EnableQueryAttribute will append the query options to the IQueryable<T> response, which will still end up materializing the entire table into memory first (IEnumerable<T>) and then apply the filter, which is still incredibly inefficient. It is this behaviour that is generally observed when someone complains about poor performance from an OData implementation, it is not always AutoMapper, but usually the pattern that the data source is loaded into memory in its entirety and then filtered. Following the default guidance for AutoMapper will lead you in this direction.

Instead we need to use an additional package: AutoMapper.Extensions.ExpressionMapping that will give us access to the UseAsDataSource extension method.

UseAsDataSource

Mapping expressions to one another is a tedious and produces long ugly code.

UseAsDataSource().For<DTO>() makes this translation clean by not having to explicitly map expressions. It also calls ProjectTo<TDO>() for you as well, where applicable.

This changes your implementation to the following:

```<code>[HttpGet]
[EnableQuery]
public ActionResult<IQueryable<CidadeDTO>> Get()
{
    return Ok(_db.Cidades.UseAsDataSource().For<CidadeDTO>());
}
</code>```

Don't fall into the trap of assuming that AutoMapper is necessary or best practice for an OData API implementation. If you are not using the unique features that AutoMapper provides then adding an additional abstraction layer can end up over-complicating your solution.

I'm not against AutoMapper, I use it a lot for Integrations, ETL, GraphQL and non-DDD style data schemas where the DTO models are significantly different to the underlying EF/data storage models. But it is a maintenance and performance overhead that a simple DDD data model and OData API based solution can easily do without.

Don't hire an excavator when a simple shovel will do the job.

AutoMapper is a convention based ORM that can be useful when you want to change the structure between implementation layers in your code, traditionally you might map Business Domain models that may represent aggregates or have flattened structures to highly normalised Database models.

OData is also a convention based ORM. It was designed to facilitate many of the same operations that AutoAmpper provides with the exception of Flattening and Unflattening models. These operations are deferred to the EF engine. The types exposed via OData mapping are DTOs

If your DTO models are the same relational structure as your EF models, then you would generally not use AutoMapper at all, the OData Edm mapping is optimised specifically to manage this type of workload and is designed to be and has been integrated directly into the serialization layer, making the Edm truely Data Transfer Objects that only exist over the wire and in the client.

Title: OData accent-insensitive filter

Body:
How can I apply a filter accent-insensitive? In OData the "eq" operator is case and accent sensitive. The case is easy to fix, because the "tolower" but relative to the accent I'm not getting a simple solution. I know contains is supposed to be accent-insensitive but if I use contains filtering by "São José" I am only getting these responses "São José" and "São José dos Campos", it is missing "Sao Jose".

The following example filtering by "Florianopolis" is expected to return "Florianópolis", but it does not:

url: api/cidades/get?$filter=contains(nome, 'Florianopolis')

[HttpGet]
[EnableQuery]
public ActionResult<IQueryable<CidadeDTO>> Get()
{
    try
    {
        return Ok(_mapper.Map<IEnumerable<CidadeDTO>>(_db.Cidades));
    }
    catch (System.Exception e)
    {
        return BadRequest(e.GetBaseException().Message);
    }
}

It should bring  aswell, like entity framework.

Body:
If your OData model was mapped directly to EF models AND an IQueryable<T> expression was passed into OK() then the query is explicitly passed through to the database engine as SQL:

SELECT * FROM Cidades WHERE nome LIKE '%Florianopolis%'

When that occurs, the Collation settings in the database connection will determine the comparison matching logic.

When your database collation is case and accent insensitive, but your data is still filtered as if it was not, then this is an indication that an IEnumerable<T> has been passed into OK() and the comparison logic is being evaluated in C# which by default in insensitive to both case and accent. Unfortunately this means that it is very likely that the entire data table has been loaded into memory first so that the filter can be applied.

In your case the OData model is mapped to DTO expressions that are mapped to the EF models via AutoMapper and that is where the generated query can break down. By calling Map() you are loading ALL records from the EF table and leaving the $filter criteria to be applied by the EnableQueryAttribute

For OData query conventions to be applied automatically you must return an IQueryable<T> from your method, or atleast pass an IQueryable<T> into the OK() response handler. With AutoMapper, you can use the Queryable Extensions to satisfy the IQueryable<T> requirement:

Queryable Extensions

When using an ORM such as NHibernate or Entity Framework with AutoMapper’s standard mapper.Map functions, you may notice that the ORM will query all the fields of all the objects within a graph when AutoMapper is attempting to map the results to a destination type.

...

ProjectTo must be the last call in the chain. ORMs work with entities, not DTOs. So apply any filtering and sorting on entities and, as the last step, project to DTOs.

In OData the last requirement (about ProjectTo) is still problematic because the EnableQueryAttribute will append the query options to the IQueryable<T> response, which will still end up materializing the entire table into memory first (IEnumerable<T>) and then apply the filter, which is still incredibly inefficient. It is this behaviour that is generally observed when someone complains about poor performance from an OData implementation, it is not always AutoMapper, but usually the pattern that the data source is loaded into memory in its entirety and then filtered. Following the default guidance for AutoMapper will lead you in this direction.

Instead we need to use an additional package: AutoMapper.Extensions.ExpressionMapping that will give us access to the UseAsDataSource extension method.

UseAsDataSource

Mapping expressions to one another is a tedious and produces long ugly code.

UseAsDataSource().For<DTO>() makes this translation clean by not having to explicitly map expressions. It also calls ProjectTo<TDO>() for you as well, where applicable.

This changes your implementation to the following:

[HttpGet]
[EnableQuery]
public ActionResult<IQueryable<CidadeDTO>> Get()
{
    return Ok(_db.Cidades.UseAsDataSource().For<CidadeDTO>());
}

Don't fall into the trap of assuming that AutoMapper is necessary or best practice for an OData API implementation. If you are not using the unique features that AutoMapper provides then adding an additional abstraction layer can end up over-complicating your solution.

I'm not against AutoMapper, I use it a lot for Integrations, ETL, GraphQL and non-DDD style data schemas where the DTO models are significantly different to the underlying EF/data storage models. But it is a maintenance and performance overhead that a simple DDD data model and OData API based solution can easily do without.

Don't hire an excavator when a simple shovel will do the job.

AutoMapper is a convention based ORM that can be useful when you want to change the structure between implementation layers in your code, traditionally you might map Business Domain models that may represent aggregates or have flattened structures to highly normalised Database models.

OData is also a convention based ORM. It was designed to facilitate many of the same operations that AutoAmpper provides with the exception of Flattening and Unflattening models. These operations are deferred to the EF engine. The types exposed via OData mapping are DTOs

If your DTO models are the same relational structure as your EF models, then you would generally not use AutoMapper at all, the OData Edm mapping is optimised specifically to manage this type of workload and is designed to be and has been integrated directly into the serialization layer, making the Edm truely Data Transfer Objects that only exist over the wire and in the client.


问:
Showing content in Jquery modal dialog doesn't work
I have this simple form:

```<code><form id="data_form">
    [.....]
    <div id="messages_box" class="messages_box">
        <p id="messages_label"></p>
    </div>
</form>
</code>```

where I put a div for dialog messages. And I have this code:

```<code>$data_complete = __('Data are completed. Please login with account just registered!','xxxxxxxxxxx');
?>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            $("#messages_label").text('<?php $data_complete; ?>');
            $('#messages_box').dialog({
                modal: true,
                title: 'Success',
                overflow:"auto",
                closeOnEscape: false,
                buttons: { Ok: function() {
                                    $( this ).dialog( "close" );
                                    $("#data_form").find('input,select').val('');
                                }
                        },
                open: function(event, ui) {
                    $(event.target).dialog('widget').css({ position: 'fixed' }).position({ my: 'center', at: 'center', of: window });
                    $(".ui-dialog-titlebar-close", ui.dialog || ui).hide();
                }
            });
        });
    </script>
<?php
</code>```

where I pass correctly some content to the

 identified with id as messages_label with

```<code>$("#messages_label").text('<?php $data_complete; ?>');
</code>```

but when I show the dialog messages_label's content doesn't show.... Maybe I missed something?

Thanks in advance!
Cheers!

答:
At the end , I solved the problem using an external plugin, Zebra dialog box and now I am satisfied to see an elegant modal message box.... Thanks to everyone anyway!
Cheers!</p>

Body:
I have this simple form:

<form id="data_form">
    [.....]

</form>

where I put a div for dialog messages. And I have this code:

$data_complete = __('Data are completed. Please login with account just registered!','xxxxxxxxxxx');
?>

<?php

where I pass correctly some content to the

 identified with id as messages_label with

$("#messages_label").text('<?php $data_complete; ?>');

but when I show the dialog messages_label's content doesn't show.... Maybe I missed something?

Thanks in advance!
Cheers!


问:
Vert.x worker instances non Round-Robin message processing
Based on the documentation and some testing, I am seeing that Vert.x queues messages in round-robin manner for instances of a Vertical e.g. if I have 2 instances of "notification" worker vertical and 10 messages are incoming,

Instance #1 processes - message # 1,3,5,7,9

Instance #2 processes - message # 2,4,6,8,10

Even if Instance #1 completes processing of all it's messages faster (due to some decision flow), still it does not receive messages pending for Instance #2. It seems like the default queueing behavior.

Is there a way to change this to dynamic queuing instead of simple round-robin at message arrival?

答:
What you are looking for is a work-stealing pool, and I don't think Vert.x supports it for the moment.

From the top of my head, it may be because of the thread-safety guarantees Vert.x has, as in that all the handlers of a request should run on the same event loop.


问:
Unzip the specific folder in NodeJS
Is there any way I can unzip the specific folder from the zip file via NodeJS.

I tried this

```<code>const unzipper = require('unzipper');
const fs = require('fs');

fs.createReadStream('path/to/archive.zip') // Your zip file
  .pipe(unzipper.Parse())
  .on('entry', function (entry) {
    const fileName = entry.path;
    const type = entry.type; // 'Directory' or 'File'
    // file_name1, file_name1 are files which you are looking for
    if (type === 'File' && ['file_name1', 'file_name1'].indexOf(fileName) >= 0) {
      entry.pipe(fs.createWriteStream('output/path/' + fileName)); // Output folder of unzip process
    } else {
      entry.autodrain();
    }
 });
</code>```

But this work only for files. I want to look for specifc folder and unzip that.

答:
```<code>var filename = req.files[0].filenam
var zippath = __dirname + "../../../../../public/uploads/pages/zip/"
var unzippath = __dirname + "../../../../../public/uploads/pages/"
fs.createReadStream(zippath + filename).pipe(unzipper.Extract({ path: unzippath }))
</code>```

Title: Unzip the specific folder in NodeJS

Body:
Is there any way I can unzip the specific folder from the zip file via NodeJS.

I tried this

const unzipper = require('unzipper');
const fs = require('fs');

fs.createReadStream('path/to/archive.zip') // Your zip file
  .pipe(unzipper.Parse())
  .on('entry', function (entry) {
    const fileName = entry.path;
    const type = entry.type; // 'Directory' or 'File'
    // file_name1, file_name1 are files which you are looking for
    if (type === 'File' && ['file_name1', 'file_name1'].indexOf(fileName) >= 0) {
      entry.pipe(fs.createWriteStream('output/path/' + fileName)); // Output folder of unzip process
    } else {
      entry.autodrain();
    }
 });

But this work only for files. I want to look for specifc folder and unzip that.


问:
MutationObserver.observe: Argument 1 is not an object
I wanna display a console message when a value of a span attribute (data-value) is changed. The span got no ID so I iterate each class out of it. But when I tried to run, it always displayed an error. Here is the HTML:

and here is the JS:

```<code>var target = document.querySelectorAll('.wpsl-selected-item');
for (var i = 0; i < target.length; i++) {
    create(target[i]);
}

var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
    console.log('heya')
    });
});

var config = {
    attributes: true,
    attributeFilter: ['data-value']
};

observer.observe(target[i], config);
</code>```

The error message is: Uncaught TypeError: MutationObserver.observe: Argument 1 is not an object. and I'm working on firefox

Any help would be very much appreciated, thank you!

答:
does this work for you?</p>
```<code>var target = document.querySelectorAll('.wpsl-selected-item');
if (target.length > 0) {
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            console.log('heya')
        });
    });

    var config = {
        attributes: true,
        attributeFilter: ['data-value']
    };

    for(var i = 0; i < target.length; i++) {
        observer.observe(target[i], config);
    }
}
</code>```

Body:
I wanna display a console message when a value of a span attribute (data-value) is changed. The span got no ID so I iterate each class out of it. But when I tried to run, it always displayed an error. Here is the HTML:

and here is the JS:

var target = document.querySelectorAll('.wpsl-selected-item');
for (var i = 0; i < target.length; i++) {
    create(target[i]);
}

var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
    console.log('heya')
    });
});

var config = {
    attributes: true,
    attributeFilter: ['data-value']
};

observer.observe(target[i], config);

The error message is: Uncaught TypeError: MutationObserver.observe: Argument 1 is not an object. and I'm working on firefox

Any help would be very much appreciated, thank you!

Body:
does this work for you?

var target = document.querySelectorAll('.wpsl-selected-item');
if (target.length > 0) {
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            console.log('heya')
        });
    });

    var config = {
        attributes: true,
        attributeFilter: ['data-value']
    };

    for(var i = 0; i < target.length; i++) {
        observer.observe(target[i], config);
    }
}


问:
SSIS Derived Column Expression to skip null/blank value and take the next digits of string value
I am very new to SSIS and I am performing a task where I have to take the flat-file text document and then derive the columns with specific digit lengths. For eg, lines in the text document are:

```<code>101001A00000000000000309493020111139                                     112
101001A00000000000000309493020111139112
</code>```

I am writing derived columns such that certain digit lengths become my columns

Expression
Derived Column Name

substring([column 0],1,3)
record1

substring([column 0],4,6)
record1

I want to skip the null values here in order to take the value 112
how do write an expression for this?
For a non-null scenario, I can proceed with the same substring function but I want to handle these blank spaces or null values too.

Can someone please help?

答:
You should use two derived column transformations in that scenario:

The first is to remove extra blank, you can use the following expression:

```<code>REPLACE([column 0]," ","")
</code>```

If the word NULL is written as a text, you can use the following expression:

```<code>REPLACE(REPLACE([column 0]," ",""),"null","")
</code>```

The second derived column transformation takes that output and split the lines into separate columns.

Body:
I am very new to SSIS and I am performing a task where I have to take the flat-file text document and then derive the columns with specific digit lengths. For eg, lines in the text document are:

101001A00000000000000309493020111139                                     112
101001A00000000000000309493020111139112

I am writing derived columns such that certain digit lengths become my columns

Expression
Derived Column Name

substring([column 0],1,3)
record1

substring([column 0],4,6)
record1

I want to skip the null values here in order to take the value 112
how do write an expression for this?
For a non-null scenario, I can proceed with the same substring function but I want to handle these blank spaces or null values too.

Can someone please help?

Body:
You should use two derived column transformations in that scenario:

The first is to remove extra blank, you can use the following expression:

REPLACE([column 0]," ","")

If the word NULL is written as a text, you can use the following expression:

REPLACE(REPLACE([column 0]," ",""),"null","")

The second derived column transformation takes that output and split the lines into separate columns.


问:
Subset groups in a data.table using conditions on two columns
I have a data.table with a high number of groups. I would like to subset whole groups (not just rows) based on the conditions on multiple columns. Consider the following data.table:

```<code>DT <- structure(list(id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L),
                 group = c("A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C", "C"),
                 y = c(14, 19, 16, 10, 6, 8, 14, 19, 10, 9, 6, 8),
                 x = c(3, 3, 2, 3, 3, 3, 3, 2, 2, 3, 3, 3)),
            row.names = c(NA, -12L),
            class = c("data.table", "data.frame"))
>DT

    id group  y x
 1:  1     A 14 3
 2:  2     A 19 3
 3:  3     A 16 2
 4:  4     A 10 3
 5:  5     B  6 3
 6:  6     B  8 3
 7:  7     B 14 3
 8:  8     B 19 2
 9:  9     C 10 2
10: 10     C  9 3
11: 11     C  6 3
12: 12     C  8 3
</code>```

I would like to keep groups that have y=6 and x=3 in the same row. So that I would have only class B and C (preferably using data.table package in R):

```<code>    id group  y x
 1:  5     B  6 3
 2:  6     B  8 3
 3:  7     B 14 3
 4:  8     B 19 2
 5:  9     C 10 2
 6: 10     C  9 3
 7: 11     C  6 3
 8: 12     C  8 3
</code>```

All my attempts gave me only those rows containing y=6 and x=3, which I do not want:

```<code>    id group  y x
 1:  5     B  6 3
 2: 11     C  6 3
</code>```

答:
With data.table:

```<code>DT[,.SD[any(x == 3 & y == 6)], by=group]

    group    id     y     x
   <char> <int> <num> <num>
1:      B     5     6     3
2:      B     6     8     3
3:      B     7    14     3
4:      B     8    19     2
5:      C     9    10     2
6:      C    10     9     3
7:      C    11     6     3
8:      C    12     8     3

</code>```

Another possibly faster option:

```<code>DT[, if (any(x == 3 & y == 6)) .SD, by=group]
</code>```

Body:
I have a data.table with a high number of groups. I would like to subset whole groups (not just rows) based on the conditions on multiple columns. Consider the following data.table:

DT <- structure(list(id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L),
                 group = c("A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C", "C"),
                 y = c(14, 19, 16, 10, 6, 8, 14, 19, 10, 9, 6, 8),
                 x = c(3, 3, 2, 3, 3, 3, 3, 2, 2, 3, 3, 3)),
            row.names = c(NA, -12L),
            class = c("data.table", "data.frame"))
>DT

    id group  y x
 1:  1     A 14 3
 2:  2     A 19 3
 3:  3     A 16 2
 4:  4     A 10 3
 5:  5     B  6 3
 6:  6     B  8 3
 7:  7     B 14 3
 8:  8     B 19 2
 9:  9     C 10 2
10: 10     C  9 3
11: 11     C  6 3
12: 12     C  8 3

I would like to keep groups that have y=6 and x=3 in the same row. So that I would have only class B and C (preferably using data.table package in R):

    id group  y x
 1:  5     B  6 3
 2:  6     B  8 3
 3:  7     B 14 3
 4:  8     B 19 2
 5:  9     C 10 2
 6: 10     C  9 3
 7: 11     C  6 3
 8: 12     C  8 3

All my attempts gave me only those rows containing y=6 and x=3, which I do not want:

    id group  y x
 1:  5     B  6 3
 2: 11     C  6 3

Body:
With data.table:

DT[,.SD[any(x == 3 & y == 6)], by=group]

    group    id     y     x
   <char> <int> <num> <num>
1:      B     5     6     3
2:      B     6     8     3
3:      B     7    14     3
4:      B     8    19     2
5:      C     9    10     2
6:      C    10     9     3
7:      C    11     6     3
8:      C    12     8     3

Another possibly faster option:

DT[, if (any(x == 3 & y == 6)) .SD, by=group]


问:
Spark requests for more core than asked when calling POST livy batch api in azure synapse
I have an azure synapse spark cluster with 3 nodes of 4 vCores and 32 GB memory each. I am trying to submit a spark job using azure synapse Livy batch APIs. The request looks like this,

```<code>curl --location --request POST 'https://<synapse-workspace>.dev.azuresynapse.net/livyApi/versions/2019-11-01-preview/sparkPools/<pool-name>/batches?detailed=true' `
--header 'cache-control: no-cache' `
--header 'Authorization: Bearer <Token>' `
--header 'Content-Type: application/json' `
--data-raw '{
    "name": "T1",
    "file": "folder/file.py",
    "driverMemory": "1g",
    "driverCores": 1,
    "executorMemory": "1g",
    "executorCores":1,
    "numExecutors": 3
}'
</code>```

The response I get is this,

```<code>{
    "TraceId": "<some-guid>",
    "Message": "Your Spark job requested 16 vcores. However, the pool has a 12 core limit. Try reducing the numbers of vcores requested or increasing your pool size."
}
</code>```

I cannot figure out why is it asking for 16 cores. Shouldn't it ask for 4 (3 * 1 + 1) cores?

Update:
I tried changing the node pool size to 3 nodes each of 8 vCores and 64 GB memory. And, with this configuration,

```<code>{
    "name": "T1",
    "file": "folder/file.py",
    "driverMemory": "1g",
    "driverCores": 1,
    "executorMemory": "1g",
    "executorCores": 1,
    "numExecutors": 6
}
</code>```

It requests for 28 cores (even for executorCores 2,3,4). And if I change executorCores to 5,6,7 or 8, it will request for 56 cores.

答:
From the portal there is no way to do what you are trying to do.

But you can still submit spark job by specifying driver (core and memory) and executor (core and memory). For example with something like this: Submit Spark job in Azure Synapse from Java

Using the above code, I am able to submit 9 concurrent jobs (with 1 driver and 1 executor, both consuming a single core) in 3 node Medium instances (8 cores each, though only 7 are available for use as 1 is reserved for hadoop daemon).

Body:
I have an azure synapse spark cluster with 3 nodes of 4 vCores and 32 GB memory each. I am trying to submit a spark job using azure synapse Livy batch APIs. The request looks like this,

curl --location --request POST 'https://<synapse-workspace>.dev.azuresynapse.net/livyApi/versions/2019-11-01-preview/sparkPools/<pool-name>/batches?detailed=true' `
--header 'cache-control: no-cache' `
--header 'Authorization: Bearer <Token>' `
--header 'Content-Type: application/json' `
--data-raw '{
    "name": "T1",
    "file": "folder/file.py",
    "driverMemory": "1g",
    "driverCores": 1,
    "executorMemory": "1g",
    "executorCores":1,
    "numExecutors": 3
}'

The response I get is this,

{
    "TraceId": "<some-guid>",
    "Message": "Your Spark job requested 16 vcores. However, the pool has a 12 core limit. Try reducing the numbers of vcores requested or increasing your pool size."
}

I cannot figure out why is it asking for 16 cores. Shouldn't it ask for 4 (3 * 1 + 1) cores?

Update:
I tried changing the node pool size to 3 nodes each of 8 vCores and 64 GB memory. And, with this configuration,

{
    "name": "T1",
    "file": "folder/file.py",
    "driverMemory": "1g",
    "driverCores": 1,
    "executorMemory": "1g",
    "executorCores": 1,
    "numExecutors": 6
}

It requests for 28 cores (even for executorCores 2,3,4). And if I change executorCores to 5,6,7 or 8, it will request for 56 cores.


问:
keytool error: java.io.IOException: keystore password was incorrect
Created a Certificate for Tomcat, trying to get it installed in new keystore, and getting error (Edit: ran it with -v option, now getting more info):

```<code>keytool error: java.io.IOException: keystore password was incorrect
java.io.IOException: keystore password was incorrect
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2015)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at sun.security.tools.keytool.Main.loadSourceKeyStore(Main.java:1894)
    at sun.security.tools.keytool.Main.doImportKeyStore(Main.java:1926)
    at sun.security.tools.keytool.Main.doCommands(Main.java:1021)
    at sun.security.tools.keytool.Main.run(Main.java:340)
    at sun.security.tools.keytool.Main.main(Main.java:333)
Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry: java.io.IOException: getSecretKey failed: Password is not ASCII
</code>```

Sadly, it's correct, the passphrase has two "®".  So, given what I've done (the private key has the non-ASCII password), how much of a pain will it be to recover from this?:

```<code>1: Create a passphrase file: vi .kp
2: Make CSR:
A: Generate a 2048 bit private key:
openssl genpkey -algorithm RSA -outform PEM -out mike.privateKey.pass.pem -pkeyopt rsa_keygen_bits:2048 -pass file:.kp
B: Make the CSR:
openssl req -new -sha256 -key mike.privateKey.pass.pem -out mike.ike.com.cert.csr
Note: CSR has different "challenge password" than in the passphrase file, if that matters
3: Submit CSR to Comodo
4: Get certificate file mike_ike_com.cer & Comodo trust chain files: COMODORSAOrganizationValidationSecureServerCA.crt, COMODORSAAddTrustCA.crt, AddTrustExternalCARoot.crt
5: Convert the Certificates:
A: Convert to PEM:
openssl x509 -inform DER -in COMODORSAOrganizationValidationSecureServerCA.crt -out COMODORSAOrganizationValidationSecureServerCA.pem -outform PEM
openssl x509 -inform DER -in COMODORSAAddTrustCA.crt -out COMODORSAAddTrustCA.pem -outform PEM
openssl x509 -inform DER -in AddTrustExternalCARoot.crt -out AddTrustExternalCARoot.pem -outform PEM
B: Concat into a single file:
cat COMODORSAOrganizationValidationSecureServerCA.pem COMODORSAAddTrustCA.pem AddTrustExternalCARoot.pem > Comodo.root.crt
C: Use openssl to create a pkcs12 file:
openssl pkcs12 -export -in mike_ike_com.cer -inkey mike.privateKey.pass.pem -passin file:.kp -out mike_ike.p12 -name tomcat -caname root -chain -CAfile Comodo.root.crt
Note: when it asks "Enter Export Password" I give it the pw from .kp
6: Use keytool to create the keystore file:
$JAVA_HOME/bin/keytool -importkeystore -deststorepass:file .kp -destkeypass:file .kp -destkeystore .keystore -srckeystore mike_ike.p12 -srcstoretype PKCS12 -srcstorepass:file .kp -alias tomcat
</code>```

The file ".keystore" does not exist.  I am assuming that keytool will create it

答:
I would like to add another possible cause:

This error message can be misleading because it also occurs when the keystore is in an unsupported format.

ContentLicense: CC BY-SA 3.0

Body:
Created a Certificate for Tomcat, trying to get it installed in new keystore, and getting error (Edit: ran it with -v option, now getting more info):

keytool error: java.io.IOException: keystore password was incorrect
java.io.IOException: keystore password was incorrect
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2015)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at sun.security.tools.keytool.Main.loadSourceKeyStore(Main.java:1894)
    at sun.security.tools.keytool.Main.doImportKeyStore(Main.java:1926)
    at sun.security.tools.keytool.Main.doCommands(Main.java:1021)
    at sun.security.tools.keytool.Main.run(Main.java:340)
    at sun.security.tools.keytool.Main.main(Main.java:333)
Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry: java.io.IOException: getSecretKey failed: Password is not ASCII

Sadly, it's correct, the passphrase has two "®".  So, given what I've done (the private key has the non-ASCII password), how much of a pain will it be to recover from this?:

1: Create a passphrase file: vi .kp
2: Make CSR:
A: Generate a 2048 bit private key:
openssl genpkey -algorithm RSA -outform PEM -out mike.privateKey.pass.pem -pkeyopt rsa_keygen_bits:2048 -pass file:.kp
B: Make the CSR:
openssl req -new -sha256 -key mike.privateKey.pass.pem -out mike.ike.com.cert.csr
Note: CSR has different "challenge password" than in the passphrase file, if that matters
3: Submit CSR to Comodo
4: Get certificate file mike_ike_com.cer & Comodo trust chain files: COMODORSAOrganizationValidationSecureServerCA.crt, COMODORSAAddTrustCA.crt, AddTrustExternalCARoot.crt
5: Convert the Certificates:
A: Convert to PEM:
openssl x509 -inform DER -in COMODORSAOrganizationValidationSecureServerCA.crt -out COMODORSAOrganizationValidationSecureServerCA.pem -outform PEM
openssl x509 -inform DER -in COMODORSAAddTrustCA.crt -out COMODORSAAddTrustCA.pem -outform PEM
openssl x509 -inform DER -in AddTrustExternalCARoot.crt -out AddTrustExternalCARoot.pem -outform PEM
B: Concat into a single file:
cat COMODORSAOrganizationValidationSecureServerCA.pem COMODORSAAddTrustCA.pem AddTrustExternalCARoot.pem > Comodo.root.crt
C: Use openssl to create a pkcs12 file:
openssl pkcs12 -export -in mike_ike_com.cer -inkey mike.privateKey.pass.pem -passin file:.kp -out mike_ike.p12 -name tomcat -caname root -chain -CAfile Comodo.root.crt
Note: when it asks "Enter Export Password" I give it the pw from .kp
6: Use keytool to create the keystore file:
$JAVA_HOME/bin/keytool -importkeystore -deststorepass:file .kp -destkeypass:file .kp -destkeystore .keystore -srckeystore mike_ike.p12 -srcstoretype PKCS12 -srcstorepass:file .kp -alias tomcat

The file ".keystore" does not exist.  I am assuming that keytool will create it


问:
Choropleth: animation_frame does not working to create the graph on colab
I am facing a problem with Cloropleth when I try to use the animation_frame and geojson together.
If I run my code using the geojson on the colab, it generates the graph. However, if I try to animate it, the colab runs out of time and does not generate the graph. I ready tried the solution proposed here, but it does not work for me. I am creating my code based on this tutorial.
Did someone have the same problem?

I am using this code:

```<code>import pandas as pd
import plotly.express as px
import json
from urllib.request import urlopen

df_corona_brio_clean = pd.read_csv('https://raw.githubusercontent.com/Yuri-Nassar/public_datasets/master/coronavirus/source_brasil_io/caso_covid_brio_filtered.csv', sep=';')
df_corona_brio_clean['date_str'] = df_corona_brio_clean['date'].apply(lambda x: str(x))
df_corona_brio_clean['date'] = pd.to_datetime(df_corona_brio_clean['date'], format = '%Y-%m-%d')

df_agrupado_date_state = df_corona_brio_clean_2.groupby(['date_str','state_name'])['confirmed', 'deaths', 'estimated_population'].sum().reset_index()
df_agrupado_date_state.sort_values(by=['date_str','confirmed'], ascending=True)

with urlopen('https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/brazil-states.geojson') as response:
  Brazil = json.load(response) # Javascrip object notation

state_id_map = {}
for feature in Brazil ['features']:
  feature['id'] = feature['properties']['name']
  state_id_map[feature['properties']['sigla']] = feature['id']

fig = px.choropleth(df_agrupado_date_state,
                    locations='state_name',
                    geojson = Brazil,
                    color= df_agrupado_date_state['confirmed'],
                    color_continuous_scale= 'Reds',
                    hover_name='state_name',
                    hover_data=['confirmed', 'deaths'],
                    title='Number of cases over the time',
                    #animation_frame= 'date_str'
                    #animation_group= 'date_str'

                    #animation_frame= df_agrupado_date_state['date'].dt.strftime('%Y-%m-%d'),
                    #animation_group= df_agrupado_date_state['date'].dt.strftime('%Y-%m-%d')
                  )
fig.update_geos(fitbounds = "locations", visible = False)
fig.show()
</code>```

I tried both datetime and str type for the date variable. I got the following fig without using animate_frame:

However, if I try any of these types, they will not generate any graph, and the colab disconnects to restart. I got the following log on colab while it tries to build the graph:

Somebody can help me with any idea?
Tkx

答:
there is a resource issue if you attempt to create animation frames for all dates.

Have limited to last dates using a constant

if you simplify the geometry the resource usage reduces significantly.  Have used geopandas to do this

have aggregated data using named aggregations

have use featureidkey to eliminate need to manipulate geojson

have added mapbox solution too.  It's resource usage also depends highly on complexity of geometry

```<code>import pandas as pd
import plotly.express as px
import json
from urllib.request import urlopen

df_corona_brio_clean = pd.read_csv(
    "https://raw.githubusercontent.com/Yuri-Nassar/public_datasets/master/coronavirus/source_brasil_io/caso_covid_brio_filtered.csv",
    sep=";",
)
df_corona_brio_clean["date_str"] = df_corona_brio_clean["date"].apply(lambda x: str(x))
df_corona_brio_clean["date"] = pd.to_datetime(
    df_corona_brio_clean["date"], format="%Y-%m-%d"
)

with urlopen(
    "https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/brazil-states.geojson"
) as response:
    Brazil = json.load(response)  # Javascrip object notation

SIMPLIFY=True
if SIMPLIFY:
    import geopandas as gpd
    gdf = gpd.GeoDataFrame.from_features(Brazil, crs="epsg:4326")
    gdf["geometry"] = gdf.to_crs(gdf.estimate_utm_crs()).simplify(5000).to_crs("epsg:4326")
    Brazil = gdf.__geo_interface__

df_agrupado_date_state = (
    df_corona_brio_clean.groupby(["date", "state"], as_index=False)
    .agg(
        **{
            **{c: (c, "first") for c in ["date_str", "state_name"]},
            **{c: (c, "sum") for c in ["confirmed", "deaths", "estimated_population"]},
        }
    )
    .sort_values(["date", "confirmed"])
)

MAX_DATES = 15
fig = px.choropleth(
    df_agrupado_date_state.loc[
        lambda d: d["date"].isin(d["date"].unique()[-MAX_DATES:])
    ],
    locations="state",
    geojson=Brazil,
    featureidkey="properties.sigla",
    color="confirmed",
    color_continuous_scale="Reds",
    hover_name="state_name",
    hover_data=["confirmed", "deaths"],
    title="Number of cases over the time",
    animation_frame="date_str",
)
fig.update_geos(fitbounds="locations", visible=False).update_layout(margin={"l":0,"r":0,"t":30,"b":0})
</code>```

mapbox

```<code>fig = px.choropleth_mapbox(
    df_agrupado_date_state.loc[
        lambda d: d["date"].isin(d["date"].unique()[-MAX_DATES:])
    ],
    locations="state",
    geojson=Brazil,
    featureidkey="properties.sigla",
    color="confirmed",
    color_continuous_scale="Reds",
    hover_name="state_name",
    hover_data=["confirmed", "deaths"],
    title="Number of cases over the time",
    animation_frame="date_str",
)
fig.update_layout(
    margin={"l": 0, "r": 0, "t": 30, "b": 0},
    mapbox={
        "style": "carto-positron",
        "zoom": 2,
        "center": {"lat": -14.2350, "lon": -51.9253},
    },
)
</code>```

data sourcing

in comments you note you are not getting each state for each date

clearly not your data source does not support this

change to this source which has cases by state in Brazil https://github.com/wcota/covid19br

```<code>
df_corona_brio_clean = pd.read_csv("https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv")
df_corona_brio_clean = df_corona_brio_clean.loc[lambda d: d["state"].ne("TOTAL")]
df_corona_brio_clean["date"] = pd.to_datetime(df_corona_brio_clean["date"])
df_corona_brio_clean["date_str"] = df_corona_brio_clean["date"].dt.strftime("%Y-%m-%d")
df_agrupado_date_state = df_corona_brio_clean
MAX_DATES = 15
fig = px.choropleth(
    df_agrupado_date_state.loc[
        lambda d: d["date"].isin(d["date"].unique()[-MAX_DATES:])
    ],
    locations="state",
    geojson=Brazil,
    featureidkey="properties.sigla",
    color="newCases",
    color_continuous_scale="Reds",
    hover_name="state",
    hover_data=["newCases", "newDeaths"],
    title="Number of cases over the time",
    animation_frame="date_str",
)
fig.update_geos(fitbounds="locations", visible=False).update_layout(margin={"l":0,"r":0,"t":30,"b":0})
</code>```

Body:
I am facing a problem with Cloropleth when I try to use the animation_frame and geojson together.
If I run my code using the geojson on the colab, it generates the graph. However, if I try to animate it, the colab runs out of time and does not generate the graph. I ready tried the solution proposed here, but it does not work for me. I am creating my code based on this tutorial.
Did someone have the same problem?

I am using this code:

import pandas as pd
import plotly.express as px
import json
from urllib.request import urlopen

df_corona_brio_clean = pd.read_csv('https://raw.githubusercontent.com/Yuri-Nassar/public_datasets/master/coronavirus/source_brasil_io/caso_covid_brio_filtered.csv', sep=';')
df_corona_brio_clean['date_str'] = df_corona_brio_clean['date'].apply(lambda x: str(x))
df_corona_brio_clean['date'] = pd.to_datetime(df_corona_brio_clean['date'], format = '%Y-%m-%d')

df_agrupado_date_state = df_corona_brio_clean_2.groupby(['date_str','state_name'])['confirmed', 'deaths', 'estimated_population'].sum().reset_index()
df_agrupado_date_state.sort_values(by=['date_str','confirmed'], ascending=True)

with urlopen('https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/brazil-states.geojson') as response:
  Brazil = json.load(response) # Javascrip object notation

state_id_map = {}
for feature in Brazil ['features']:
  feature['id'] = feature['properties']['name']
  state_id_map[feature['properties']['sigla']] = feature['id']

fig = px.choropleth(df_agrupado_date_state,
                    locations='state_name',
                    geojson = Brazil,
                    color= df_agrupado_date_state['confirmed'],
                    color_continuous_scale= 'Reds',
                    hover_name='state_name',
                    hover_data=['confirmed', 'deaths'],
                    title='Number of cases over the time',
                    #animation_frame= 'date_str'
                    #animation_group= 'date_str'

                    #animation_frame= df_agrupado_date_state['date'].dt.strftime('%Y-%m-%d'),
                    #animation_group= df_agrupado_date_state['date'].dt.strftime('%Y-%m-%d')
                  )
fig.update_geos(fitbounds = "locations", visible = False)
fig.show()

I tried both datetime and str type for the date variable. I got the following fig without using animate_frame:

However, if I try any of these types, they will not generate any graph, and the colab disconnects to restart. I got the following log on colab while it tries to build the graph:

Somebody can help me with any idea?
Tkx

Body:
there is a resource issue if you attempt to create animation frames for all dates.

Have limited to last dates using a constant

if you simplify the geometry the resource usage reduces significantly.  Have used geopandas to do this

have aggregated data using named aggregations

have use featureidkey to eliminate need to manipulate geojson

have added mapbox solution too.  It's resource usage also depends highly on complexity of geometry

import pandas as pd
import plotly.express as px
import json
from urllib.request import urlopen

df_corona_brio_clean = pd.read_csv(
    "https://raw.githubusercontent.com/Yuri-Nassar/public_datasets/master/coronavirus/source_brasil_io/caso_covid_brio_filtered.csv",
    sep=";",
)
df_corona_brio_clean["date_str"] = df_corona_brio_clean["date"].apply(lambda x: str(x))
df_corona_brio_clean["date"] = pd.to_datetime(
    df_corona_brio_clean["date"], format="%Y-%m-%d"
)

with urlopen(
    "https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/brazil-states.geojson"
) as response:
    Brazil = json.load(response)  # Javascrip object notation

SIMPLIFY=True
if SIMPLIFY:
    import geopandas as gpd
    gdf = gpd.GeoDataFrame.from_features(Brazil, crs="epsg:4326")
    gdf["geometry"] = gdf.to_crs(gdf.estimate_utm_crs()).simplify(5000).to_crs("epsg:4326")
    Brazil = gdf.__geo_interface__

df_agrupado_date_state = (
    df_corona_brio_clean.groupby(["date", "state"], as_index=False)
    .agg(
        **{
            **{c: (c, "first") for c in ["date_str", "state_name"]},
            **{c: (c, "sum") for c in ["confirmed", "deaths", "estimated_population"]},
        }
    )
    .sort_values(["date", "confirmed"])
)

MAX_DATES = 15
fig = px.choropleth(
    df_agrupado_date_state.loc[
        lambda d: d["date"].isin(d["date"].unique()[-MAX_DATES:])
    ],
    locations="state",
    geojson=Brazil,
    featureidkey="properties.sigla",
    color="confirmed",
    color_continuous_scale="Reds",
    hover_name="state_name",
    hover_data=["confirmed", "deaths"],
    title="Number of cases over the time",
    animation_frame="date_str",
)
fig.update_geos(fitbounds="locations", visible=False).update_layout(margin={"l":0,"r":0,"t":30,"b":0})

mapbox

fig = px.choropleth_mapbox(
    df_agrupado_date_state.loc[
        lambda d: d["date"].isin(d["date"].unique()[-MAX_DATES:])
    ],
    locations="state",
    geojson=Brazil,
    featureidkey="properties.sigla",
    color="confirmed",
    color_continuous_scale="Reds",
    hover_name="state_name",
    hover_data=["confirmed", "deaths"],
    title="Number of cases over the time",
    animation_frame="date_str",
)
fig.update_layout(
    margin={"l": 0, "r": 0, "t": 30, "b": 0},
    mapbox={
        "style": "carto-positron",
        "zoom": 2,
        "center": {"lat": -14.2350, "lon": -51.9253},
    },
)

data sourcing

in comments you note you are not getting each state for each date

clearly not your data source does not support this

change to this source which has cases by state in Brazil https://github.com/wcota/covid19br

df_corona_brio_clean = pd.read_csv("https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv")
df_corona_brio_clean = df_corona_brio_clean.loc[lambda d: d["state"].ne("TOTAL")]
df_corona_brio_clean["date"] = pd.to_datetime(df_corona_brio_clean["date"])
df_corona_brio_clean["date_str"] = df_corona_brio_clean["date"].dt.strftime("%Y-%m-%d")
df_agrupado_date_state = df_corona_brio_clean
MAX_DATES = 15
fig = px.choropleth(
    df_agrupado_date_state.loc[
        lambda d: d["date"].isin(d["date"].unique()[-MAX_DATES:])
    ],
    locations="state",
    geojson=Brazil,
    featureidkey="properties.sigla",
    color="newCases",
    color_continuous_scale="Reds",
    hover_name="state",
    hover_data=["newCases", "newDeaths"],
    title="Number of cases over the time",
    animation_frame="date_str",
)
fig.update_geos(fitbounds="locations", visible=False).update_layout(margin={"l":0,"r":0,"t":30,"b":0})


问:
aws api-gateway - cdk stage deployment setup - updating without drift
I want to setup an api gateway using cdk - with RestApi, Resource, Method and Stage - all included in the cdk stack.

To create the Stage construct in the cdk stack, it required a Deployment, so I defined this in the cdk stack.

```<code>deployment = apigateway_v1.Deployment(self, "Deployment", api=rest_api)

stage = apigateway_v1.Stage(
    self,
    "test",
    deployment=deployment,
    stage_name="test"
)
</code>```

However, when I later make a change to the Resource Method definition - and re-deploy the cdk stack, the api-gateway is not updating.  So I end up either redeploying the api-gateway either via the aws console or the aws-cli create-deployment

But now when I check for cloudformation stack drift, it shows the Stage has drifted.

How can I prevent stack drift while keeping the Stage in the cdk stack?

答:
Found some suggestion to add a unique identifier to the deployment construct id from the following links:

https://github.com/aws/aws-cdk/issues/13134
https://stackoverflow.com/a/66377831/1211547

a disadvantage is the deployment will be recreated with every cdk deploy even if there are no changes

Body:
I want to setup an api gateway using cdk - with RestApi, Resource, Method and Stage - all included in the cdk stack.

To create the Stage construct in the cdk stack, it required a Deployment, so I defined this in the cdk stack.

deployment = apigateway_v1.Deployment(self, "Deployment", api=rest_api)

stage = apigateway_v1.Stage(
    self,
    "test",
    deployment=deployment,
    stage_name="test"
)

However, when I later make a change to the Resource Method definition - and re-deploy the cdk stack, the api-gateway is not updating.  So I end up either redeploying the api-gateway either via the aws console or the aws-cli create-deployment

But now when I check for cloudformation stack drift, it shows the Stage has drifted.

How can I prevent stack drift while keeping the Stage in the cdk stack?


问:
Ember - Loading an URL dynamically for button
New to ember, I wonder what is the best way to go about this:

```<code>component.js
import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({
  ajax: service(),

  url: '',

  async fetchUrl() {
    try {
      let result = await this.ajax.request(
        `api/urlgenerator`
      );
      this.url = result.link;
    } catch (err) {
      this.errorHandler.handle(err);
    }
  },

  init() {
    this._super(...arguments);
    this.fetchUrl();
  },
});

</code>```

and my template

```<code>{{#card/banner}}
  <Banner
    @text="Template Button"
    @action={{hash
      text="Enable Launcher"
      onAction=(track-action
        (route-action "openUrl" this.url)
      )
    }}
  />
{{/card/banner}}

</code>```

openUrl is simple a global method responsible for opening an external URL

--

Not too sure if this is the right way to go about it, right now it is not working, since maybe due to ember component lifecycle, the variable gets rendered with the initial value only (empty '')

However, If I hardcode the url for example, it works fine.

Can someone give me some advice on it?

答:
In classic component style you would use this.set('url', result.link) instead of this.url = result.link. However in modern ember I would do it like this:

export default class MyComponent extends Component {
  @service ajax;

  @tracked url = '';

  constructor() {
    super(...arguments);
    this.fetchUrl();
  }
  async fetchUrl() {
    try {
      let result = await this.ajax.request(
        `api/urlgenerator`
      );
      this.url = result.link;
    } catch (err) {
      this.errorHandler.handle(err);
    }
  }
}
```

notice url must be @tracked.

Body:
New to ember, I wonder what is the best way to go about this:

component.js
import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({
  ajax: service(),

  url: '',

  async fetchUrl() {
    try {
      let result = await this.ajax.request(
        `api/urlgenerator`
      );
      this.url = result.link;
    } catch (err) {
      this.errorHandler.handle(err);
    }
  },

  init() {
    this._super(...arguments);
    this.fetchUrl();
  },
});

and my template

{{#card/banner}}
  <Banner
    @text="Template Button"
    @action={{hash
      text="Enable Launcher"
      onAction=(track-action
        (route-action "openUrl" this.url)
      )
    }}
  />
{{/card/banner}}

openUrl is simple a global method responsible for opening an external URL

--

Not too sure if this is the right way to go about it, right now it is not working, since maybe due to ember component lifecycle, the variable gets rendered with the initial value only (empty '')

However, If I hardcode the url for example, it works fine.

Can someone give me some advice on it?

Body:
In classic component style you would use this.set('url', result.link) instead of this.url = result.link. However in modern ember I would do it like this:

export default class MyComponent extends Component {
  @service ajax;

  @tracked url = '';

  constructor() {
    super(...arguments);
    this.fetchUrl();
  }
  async fetchUrl() {
    try {
      let result = await this.ajax.request(
        `api/urlgenerator`
      );
      this.url = result.link;
    } catch (err) {
      this.errorHandler.handle(err);
    }
  }
}

notice url must be @tracked.


问:
Cannot import Three.js into my project: server returns with an error of 404 (three.js)
I was checking my portfolio, which was working fine a few weeks ago, and i found out that my three.js model isn't showing anymore (I haven't modified anything since it was working fine.), and when I checked the errors in the console, it gave me this error: Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../"..
 I was importing three.js in a main.js file like this:
import * as THREE from 'https://cdn.skypack.dev/three', so I changed the import to: import * as THREE from '../node_modules/three/build/three.js', but now it returns an error of 404. what should I do?
This is my file structure:

答:
The proper way to install three.js is described here:

https://threejs.org/docs/#manual/en/introduction/Installation

should be like so:

import * as THREE from 'three';


问:
Can't access form data in PHP
I'm not a novice, but I'm not an expert either; I'm a keen learner.

Problem (minimalised) - I have a basic form which posts a name to another page which is supposed to receive name and print name. Code of both forms is below.

Form:

```<code><?php
    echo "Hello, World!";
    echo "
        <form action='CFAcomments.php' method='POST'>
            <table style='width: 50%;' border='0'>
                <tbody>
                    <tr>
                        <td><label for='name'>name: </label></td>
                        <td><input type='Text' name='name' value='anon' /></td>
                    </tr>
                    <tr>
                        <td><input type='submit' name='send' value='Send' /></td>
                    </tr>
                </tbody>
            </table>
        </form>
    ";
?>
</code>```

Form Process:

```<code><?php
    echo "Hello, World 1!";
    echo "<br/>";
    var_dump($_POST);
    $name = $_POST("name");
    echo "Hello $name!";
?>
</code>```

Result:

```<code>Hello, World 1!
array(2) { ["name"]=> string(11) "anon" ["send"]=> string(4) "Send" }
</code>```

Problem:

Even though var_dump($_POST) shows data being sent, echo $name print nothing. Changing echo $name to echo "test" prints nothing too. The code seems to stop executing at $name = $_post("name");. If I remove this line echo "anything" works.

I've used PHP and forms for the last two years and never come across this. Any help would be appreciated.

答:
This needs to be

```<code>$name = $_POST["name"];
</code>```

Note the square brackets, because $_POST is an array, not a function.

Title: Can't access form data in PHP

Body:
I'm not a novice, but I'm not an expert either; I'm a keen learner.

Problem (minimalised) - I have a basic form which posts a name to another page which is supposed to receive name and print name. Code of both forms is below.

Form:

<?php
    echo "Hello, World!";
    echo "
        <form action='CFAcomments.php' method='POST'>

                        name:
                        <input type='Text' name='name' value='anon' />

                        <input type='submit' name='send' value='Send' />

        </form>
    ";
?>

Form Process:

<?php
    echo "Hello, World 1!";
    echo "
";
    var_dump($_POST);
    $name = $_POST("name");
    echo "Hello $name!";
?>

Result:

Hello, World 1!
array(2) { ["name"]=> string(11) "anon" ["send"]=> string(4) "Send" }

Problem:

Even though var_dump($_POST) shows data being sent, echo $name print nothing. Changing echo $name to echo "test" prints nothing too. The code seems to stop executing at $name = $_post("name");. If I remove this line echo "anything" works.

I've used PHP and forms for the last two years and never come across this. Any help would be appreciated.

Body:
This needs to be

$name = $_POST["name"];

Note the square brackets, because $_POST is an array, not a function.


问:
Capacitor Camera to not show prompt dialogue
I am using the camera plugin from Capacitor with angular in order to save images locally from both desktop and tablet.
I want to be able to use the CameraSource to directly open the camera or open the file gallery and to not show the prompt.

My code looks like this:

My A.html

```<code><button (click)="addPhoto('Camera')">Capture Image</button>
<button (click)="addPhoto('Photos')">Choose from Gallery</button>
</code>```

A.ts

```<code>import { CameraDirection, CameraResultType, CameraSource, Plugins } from '@capacitor/core';

const { Camera } = Plugins;

async addPhoto(source) {
  if (source === 'Camera') {
      const image = await Camera.getPhoto({
      quality: 90,
      source: CameraSource.Camera
      resultType: CameraResultType.Uri
    });
  } else if ( source === 'Photos') {
      const image = await Camera.getPhoto({
      quality: 90,
      source: CameraSource.Photos
      resultType: CameraResultType.Uri
    });
  }
}
</code>```

Somehow Capacitor ingores my source property.
Is my desired behaviour even possible?

答: You might be missing a comma after the source parameter</p>

Body:
I am using the camera plugin from Capacitor with angular in order to save images locally from both desktop and tablet.
I want to be able to use the CameraSource to directly open the camera or open the file gallery and to not show the prompt.

My code looks like this:

My A.html

<button (click)="addPhoto('Camera')">Capture Image</button>
<button (click)="addPhoto('Photos')">Choose from Gallery</button>

A.ts

import { CameraDirection, CameraResultType, CameraSource, Plugins } from '@capacitor/core';

const { Camera } = Plugins;

async addPhoto(source) {
  if (source === 'Camera') {
      const image = await Camera.getPhoto({
      quality: 90,
      source: CameraSource.Camera
      resultType: CameraResultType.Uri
    });
  } else if ( source === 'Photos') {
      const image = await Camera.getPhoto({
      quality: 90,
      source: CameraSource.Photos
      resultType: CameraResultType.Uri
    });
  }
}

Somehow Capacitor ingores my source property.
Is my desired behaviour even possible?


问:
Installing docker on Ubuntu 16.10
The installation instructions go up to Xenial... https://docs.docker.com/engine/installation/linux/ubuntulinux/ . Any idea how to install it on Yakkety?</p>

答:
#Update the apt package index and install packages

sudo apt-get update

sudo apt-get install

ca-certificates

curl

gnupg

lsb-release

#Add Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

#Use the following command to set up the stable repository.
echo

"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu

$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

#Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Title: Installing docker on Ubuntu 16.10


问:
How to disable Redis in Laravel for dev version
I have a Laravel API that I need to test locally. How can I disable Redis cache on a local Laravel server? I can't disable it manually deleting all Redis::connection cases.

答:
You can change "Default Cache Store" in config/cache.php file in your project.

By default you should have this 'default' => env('CACHE_DRIVER', 'file'),

You have a few solutions depending on what you have there:

if you already have changed default cache driver on that file, just change it to 'file' (not recommended!)

better would be change to default value 'default' => env('CACHE_DRIVER', 'file'), but add appropriate value in .env file CACHE_DRIVER=file


问:
java.lang.ClassCastException: CommonsMultipartFile cannot be cast to oracle.sql.BFILE
I am working on a screen which will upload a file to oracle table as BFILE type. I am using spring3 and hibernate3.

The BO class look like:

```<code>@Entity
@Table(name="abc_manuals")
public class ManualBo implements Serializable {

/* Persistent Fields */
@Id
@Column(name="id", nullable=false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long  mId;

@Column(name="guide")
@Type(type="com.bo.entity.BFILEType")
private BFILE guide;

public Long getMlId() {
    return mlId;
}
public void setMId(Long manualId) {
    this.mId = mId;
}

public BFILE getGuide() {
    return guide;
}
public void setGuide(BFILE guide) {
    guide = guide;
}

}
</code>```

I have defined a BFILE userType:

```<code>public class BFILEType implements UserType, Serializable {

@SuppressWarnings("unused")
private static final String MARK_EMPTY = "<EmptyString/>";
private static final int[] TYPES = { OracleTypes.BFILE  };

public int[] sqlTypes() {
    return TYPES;
}

@SuppressWarnings("rawtypes")
public Class returnedClass() {
    return BFILE.class;
}

public boolean equals(Object x, Object y) {
    if (x==y) return true;
    if (x==null || y==null) return false;
    return x.equals(y);
}

public Object deepCopy(Object x) {
    return x;
}

public boolean isMutable() { return false; }

   public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws
   HibernateException, SQLException {
    BFILE bfile = (BFILE)rs.getObject(names[0]);
    return bfile;
}

public void nullSafeSet(PreparedStatement st, Object value, int index) throws
     HibernateException, SQLException {
    if(value==null)
        st.setObject(index, null);
    else
        st.setObject(index, value, OracleTypes.BFILE);
}

public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
    return deepCopy(arg0);
}

public Serializable disassemble(Object value) {
    return (Serializable) deepCopy(value);
}

public int hashCode(Object arg0) throws HibernateException {
    return arg0.hashCode();
}

public Object replace(Object arg0, Object arg1, Object arg2) throws
     HibernateException {
    return deepCopy(arg0);
}
</code>```

}

Problem is when I am trying to setFile in controller

manual.setGuide((oracle.sql.BFILE) form.getFile());

it is compiling well but when I upload file from screen it is giving following exception

java.lang.ClassCastException: org.springframework.web.multipart.commons.CommonsMultipartFile cannot be cast to oracle.sql.BFILE

How to solve this?

Solved :

I tried :

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
        if (value == null) {
            st.setObject(index, null);
        } else {

```<code>        OracleConnection oc = (OracleConnection) st.getConnection();
        OraclePreparedStatement opst = (OraclePreparedStatement) st;

        OracleCallableStatement ocs = (OracleCallableStatement) oc.prepareCall("{? = call BFILENAME('" + directory + "', '"+ filename + "')}");

        ocs.registerOutParameter(1, OracleTypes.BFILE);
        ocs.execute();
        BFILE bfile = ocs.getBFILE(1);
        opst.setBFILE(index, bfile);
    }
}
</code>```

and its working fine.

Thanks!

答:
java.lang.ClassCastException:
  org.springframework.web.multipart.commons.CommonsMultipartFile cannot
  be cast to oracle.sql.BFILE

That is correct, the two classes don't share a type hierarchy, there's no way to cast one to the other. Instead of casting the types, you should concentrate on transferring the contents.

This should be the code you need:

```<code>BFILE bfile = new BFILE();
bfile.setBytes(form.getFile().getBytes());
manual.setGuide(bfile);
</code>```

UPDATE: It turns out it's not that easy, as a BFILE can't just be constructed. Here's an Oracle tutorial for working with BFILES in Java.

Body:
I am working on a screen which will upload a file to oracle table as BFILE type. I am using spring3 and hibernate3.

The BO class look like:

@Entity
@Table(name="abc_manuals")
public class ManualBo implements Serializable {

/* Persistent Fields */
@Id
@Column(name="id", nullable=false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long  mId;

@Column(name="guide")
@Type(type="com.bo.entity.BFILEType")
private BFILE guide;

public Long getMlId() {
    return mlId;
}
public void setMId(Long manualId) {
    this.mId = mId;
}

public BFILE getGuide() {
    return guide;
}
public void setGuide(BFILE guide) {
    guide = guide;
}

}

I have defined a BFILE userType:

public class BFILEType implements UserType, Serializable {

@SuppressWarnings("unused")
private static final String MARK_EMPTY = "<EmptyString/>";
private static final int[] TYPES = { OracleTypes.BFILE  };

public int[] sqlTypes() {
    return TYPES;
}

@SuppressWarnings("rawtypes")
public Class returnedClass() {
    return BFILE.class;
}

public boolean equals(Object x, Object y) {
    if (x==y) return true;
    if (x==null || y==null) return false;
    return x.equals(y);
}

public Object deepCopy(Object x) {
    return x;
}

public boolean isMutable() { return false; }

   public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws
   HibernateException, SQLException {
    BFILE bfile = (BFILE)rs.getObject(names[0]);
    return bfile;
}

public void nullSafeSet(PreparedStatement st, Object value, int index) throws
     HibernateException, SQLException {
    if(value==null)
        st.setObject(index, null);
    else
        st.setObject(index, value, OracleTypes.BFILE);
}

public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
    return deepCopy(arg0);
}

public Serializable disassemble(Object value) {
    return (Serializable) deepCopy(value);
}

public int hashCode(Object arg0) throws HibernateException {
    return arg0.hashCode();
}

public Object replace(Object arg0, Object arg1, Object arg2) throws
     HibernateException {
    return deepCopy(arg0);
}

}

Problem is when I am trying to setFile in controller

manual.setGuide((oracle.sql.BFILE) form.getFile());

it is compiling well but when I upload file from screen it is giving following exception

java.lang.ClassCastException: org.springframework.web.multipart.commons.CommonsMultipartFile cannot be cast to oracle.sql.BFILE

How to solve this?

Solved :

I tried :

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
        if (value == null) {
            st.setObject(index, null);
        } else {

        OracleConnection oc = (OracleConnection) st.getConnection();
        OraclePreparedStatement opst = (OraclePreparedStatement) st;

        OracleCallableStatement ocs = (OracleCallableStatement) oc.prepareCall("{? = call BFILENAME('" + directory + "', '"+ filename + "')}");

        ocs.registerOutParameter(1, OracleTypes.BFILE);
        ocs.execute();
        BFILE bfile = ocs.getBFILE(1);
        opst.setBFILE(index, bfile);
    }
}

and its working fine.

Thanks!

Body:
java.lang.ClassCastException:
  org.springframework.web.multipart.commons.CommonsMultipartFile cannot
  be cast to oracle.sql.BFILE

That is correct, the two classes don't share a type hierarchy, there's no way to cast one to the other. Instead of casting the types, you should concentrate on transferring the contents.

This should be the code you need:

BFILE bfile = new BFILE();
bfile.setBytes(form.getFile().getBytes());
manual.setGuide(bfile);

UPDATE: It turns out it's not that easy, as a BFILE can't just be constructed. Here's an Oracle tutorial for working with BFILES in Java.


问:
How to get max open?
I am trying to get the highest open between day, week and month.
So far I have success when I'm on daily but when intraday, it is not showing correctly the highest open, but only today's open.
Can anyone please help me get it to work correctly on intraday?
Here's the code handling that:</p>
```<code>dopen = security(syminfo.tickerid, "D", open, barmerge.gaps_off, lookahead=barmerge.lookahead_on)
wopen = security(syminfo.tickerid, "W", open, lookahead=barmerge.lookahead_on)
mopen = security(syminfo.tickerid, "M", open, lookahead=barmerge.lookahead_on)

maxOpen = max(highest(security(syminfo.tickerid, "D", open, barmerge.gaps_off, lookahead=barmerge.lookahead_on), dayofweek-1), wopen, mopen)
plot(onePlot and maxOpen ? maxOpen : na, title="Highest Open", color= maxOpen != maxOpen[1] ? na : color.new( color.green, 0), style=plot.style_line,linewidth = 2)
</code>```

答:
You can use the following algorithm for the intraday bars.

Have a var that keeps track of the highest open price

Reset this variable when it is a new day

If the current bar's open price is bigger than this variable, update its value

Code:

```<code>//@version=5
indicator("My script", overlay=true)

var highest_open = 10e-10

is_new_day = dayofweek[1] != dayofweek

if (is_new_day)
    highest_open := open
else
    if (open > highest_open)
        highest_open := open

bgcolor(is_new_day ? color.new(color.blue, 80) : na)
plot(highest_open, "Open", color.green, 2, plot.style_circles)
</code>```

Title: How to get max open?

Body:
I am trying to get the highest open between day, week and month.
So far I have success when I'm on daily but when intraday, it is not showing correctly the highest open, but only today's open.
Can anyone please help me get it to work correctly on intraday?
Here's the code handling that:

dopen = security(syminfo.tickerid, "D", open, barmerge.gaps_off, lookahead=barmerge.lookahead_on)
wopen = security(syminfo.tickerid, "W", open, lookahead=barmerge.lookahead_on)
mopen = security(syminfo.tickerid, "M", open, lookahead=barmerge.lookahead_on)

maxOpen = max(highest(security(syminfo.tickerid, "D", open, barmerge.gaps_off, lookahead=barmerge.lookahead_on), dayofweek-1), wopen, mopen)
plot(onePlot and maxOpen ? maxOpen : na, title="Highest Open", color= maxOpen != maxOpen[1] ? na : color.new( color.green, 0), style=plot.style_line,linewidth = 2)

Body:
You can use the following algorithm for the intraday bars.

Have a var that keeps track of the highest open price

Reset this variable when it is a new day

If the current bar's open price is bigger than this variable, update its value

Code:

//@version=5
indicator("My script", overlay=true)

var highest_open = 10e-10

is_new_day = dayofweek[1] != dayofweek

if (is_new_day)
    highest_open := open
else
    if (open > highest_open)
        highest_open := open

bgcolor(is_new_day ? color.new(color.blue, 80) : na)
plot(highest_open, "Open", color.green, 2, plot.style_circles)


问:
How to pass data between github workflow jobs
How do I pass the release number in the create_release job to the deploy job?

...
jobs:
  create_release:
    name: Create release
    needs: run_tests
    runs-on: ubuntu-latest
    outputs:
      release_id: ${{ steps.set_release_number.outputs.release_number }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set release number
        id: set_release_number
        run: |
          RELEASE_NUMBER=$(date +%Y-%m-%d)-${{ github.ref_name }}-${{ github.run_id }}
          chmod +x ./scripts/github-workflow/set-release-number.sh
          ./scripts/github-workflow/set-release-number.sh \
            -e ${{ github.event.inputs.environment }} \
            -n $RELEASE_NUMBER
          echo "::set-output name=release_number::$RELEASE_NUMBER"
      - name: Build and upload release
        env:
          DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
          DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
        run: |
          chmod +x ./scripts/github-workflow/build-and-publish-release.sh
          ./scripts/github-workflow/build-and-publish-release.sh
  deploy:
    name: Deploy release
    needs: create_release
    if: (needs.create_release.result == 'success') && (github.event.inputs.should_auto_deploy == 'true')
    uses: Aplanke/ApiBackend/.github/workflows/deployment.yml@main
    with:
      environment: ${{ github.event.inputs.environment }}
      release_number: ${{ needs.create_release.outputs.release_id }}
```
<p><strong>EDIT: Add deploy pipeline snippet</strong></p>
<pre class="lang-yaml prettyprint-override"><code>  workflow_call:
    inputs:
      environment:
        description: Environment to deploy to
        required: true
        type: string
        default: prod
      release_number:
        description: Release number/ID to deploy
        required: true
        type: string

jobs:
  deployment:
    steps:
      - name: Set release number
        run: |
          chmod +x ./scripts/github-workflow/set-release-number.sh
          ./scripts/github-workflow/set-release-number.sh \
            -e ${{ github.event.inputs.environment }} \
            -n ${{ github.event.inputs.release_number }}
</code>```

Screenshot of the failed job

答:
The example you posted it's working fine:

https://github.com/grzegorzkrukowski/stackoverflow_tests/runs/5155488550?check_suite_focus=true#step:2:4

The problem must be somewhere in how you generate RELEASE_NUMBER or how you handle input in your customs scripts we don't see.
The GitHub Workflow part is working just fine.

Body:
How do I pass the release number in the create_release job to the deploy job?

...
jobs:
  create_release:
    name: Create release
    needs: run_tests
    runs-on: ubuntu-latest
    outputs:
      release_id: ${{ steps.set_release_number.outputs.release_number }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set release number
        id: set_release_number
        run: |
          RELEASE_NUMBER=$(date +%Y-%m-%d)-${{ github.ref_name }}-${{ github.run_id }}
          chmod +x ./scripts/github-workflow/set-release-number.sh
          ./scripts/github-workflow/set-release-number.sh \
            -e ${{ github.event.inputs.environment }} \
            -n $RELEASE_NUMBER
          echo "::set-output name=release_number::$RELEASE_NUMBER"
      - name: Build and upload release
        env:
          DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
          DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
        run: |
          chmod +x ./scripts/github-workflow/build-and-publish-release.sh
          ./scripts/github-workflow/build-and-publish-release.sh
  deploy:
    name: Deploy release
    needs: create_release
    if: (needs.create_release.result == 'success') && (github.event.inputs.should_auto_deploy == 'true')
    uses: Aplanke/ApiBackend/.github/workflows/deployment.yml@main
    with:
      environment: ${{ github.event.inputs.environment }}
      release_number: ${{ needs.create_release.outputs.release_id }}

EDIT: Add deploy pipeline snippet

  workflow_call:
    inputs:
      environment:
        description: Environment to deploy to
        required: true
        type: string
        default: prod
      release_number:
        description: Release number/ID to deploy
        required: true
        type: string

jobs:
  deployment:
    steps:
      - name: Set release number
        run: |
          chmod +x ./scripts/github-workflow/set-release-number.sh
          ./scripts/github-workflow/set-release-number.sh \
            -e ${{ github.event.inputs.environment }} \
            -n ${{ github.event.inputs.release_number }}

Screenshot of the failed job


问:
Count character in specific cell and add that character a specified amount of times
I am working on 16s data and try to format an OTU table to upload it to a different tool.

Here is my TSV table:

It is supposed to look like this:

So I need R to count the number of semicolons ";" in each cell in column "taxonomy" and if the number is smaller than 6 I need R to add the required number of semincolons to make it six semicolons per cell.
I am new to the bioinformatics field so any help would be much appreciated!

I tried

```<code>ifelse(str_count(ASV$taxonomy, ";") >= 6, ASV$taxonomy, paste0(ASV$taxonomy, " ;"))
</code>```

But I don´t know how I can tell R to add so many semicolons that it makes 6 semicolons in each cell.

Thank you in advance,
Lea

答:
Since I don't have your dataset, I just made an example dataframe.

Next time when you ask, make sure you don't post image of codes/dataset, you should use dput(your_data) and paste the result in the question.

Input

```<code>library(tidyverse)
library(stringr)

df <- tibble(Name = LETTERS[1:4],
             OTU = c("A;", "A; B;", "A; B; C; D; E; F;", "A; B; C; D; E;"))

df
# A tibble: 4 x 2
  Name  OTU
  <chr> <chr>
1 A     A;
2 B     A; B;
3 C     A; B; C; D; E; F;
4 D     A; B; C; D; E;
</code>```

Code and output

First count the number of ";" in the column, if it's fewer than 6, add some more at the end of the string in OTU. If it is not fewer than 6, use the original OTU value.

This will entirely replace the original OTU column.

```<code>df %>% mutate(OTU = ifelse(str_count(OTU, ";") < 6,
                           paste(OTU, str_dup("; ", 6 - str_count(OTU, ";"))),
                           OTU))

# A tibble: 4 x 2
  Name  OTU
  <chr> <chr>
1 A     "A; ; ; ; ; ; "
2 B     "A; B; ; ; ; ; "
3 C     "A; B; C; D; E; F;"
4 D     "A; B; C; D; E; ; "
</code>```

Body:
I am working on 16s data and try to format an OTU table to upload it to a different tool.

Here is my TSV table:

It is supposed to look like this:

So I need R to count the number of semicolons ";" in each cell in column "taxonomy" and if the number is smaller than 6 I need R to add the required number of semincolons to make it six semicolons per cell.
I am new to the bioinformatics field so any help would be much appreciated!

I tried

ifelse(str_count(ASV$taxonomy, ";") >= 6, ASV$taxonomy, paste0(ASV$taxonomy, " ;"))

But I don´t know how I can tell R to add so many semicolons that it makes 6 semicolons in each cell.

Thank you in advance,
Lea

Body:
Since I don't have your dataset, I just made an example dataframe.

Next time when you ask, make sure you don't post image of codes/dataset, you should use dput(your_data) and paste the result in the question.

Input

library(tidyverse)
library(stringr)

df <- tibble(Name = LETTERS[1:4],
             OTU = c("A;", "A; B;", "A; B; C; D; E; F;", "A; B; C; D; E;"))

df
# A tibble: 4 x 2
  Name  OTU
  <chr> <chr>
1 A     A;
2 B     A; B;
3 C     A; B; C; D; E; F;
4 D     A; B; C; D; E;

Code and output

First count the number of ";" in the column, if it's fewer than 6, add some more at the end of the string in OTU. If it is not fewer than 6, use the original OTU value.

This will entirely replace the original OTU column.

df %>% mutate(OTU = ifelse(str_count(OTU, ";") < 6,
                           paste(OTU, str_dup("; ", 6 - str_count(OTU, ";"))),
                           OTU))

# A tibble: 4 x 2
  Name  OTU
  <chr> <chr>
1 A     "A; ; ; ; ; ; "
2 B     "A; B; ; ; ; ; "
3 C     "A; B; C; D; E; F;"
4 D     "A; B; C; D; E; ; "


答:
We could use separate with the fill argument from tidyr package and
then paste them all together and finally replace NA by ""

```<code>library(tidyverse)

df %>%
  separate(col1, c("a","b","c","d","e","f","g"), fill = "right", sep = ";") %>%
  mutate(col1 = paste(a,b,c,d,e,f,g, sep = "; "), .keep="unused") %>%
  mutate(col1 = str_replace_all(col1, "NA", ""))

</code>```
```<code>   col1
   <chr>
 1 "Bacteria;  Proteobacteria;  Gammaproteobacteria; ; ; ; "
 2 "Bacteria;  Proteobacteria;  Gammaproteobacteria; ; ; ; "
 3 "Bacteria;  Actinobacteria;  Rubrobacteria;  Rubrobacterales;  Rubrobacteraceae;  Rubrobacter; "
 4 "Bacteria;  Gemmatimonadetes;  Gemm-1; ; ; ; "
 5 "Bacteria;  Proteobacteria;  Gammaproteobacteria;  Chromatiales; ; ; "
 6 "Bacteria;  Actinobacteria;  Nitriliruptoria;  Nitriliruptorales;  Nitriliruptoraceae; ; "
 7 "Bacteria;  Proteobacteria;  Gammaproteobacteria;  Chromatiales; ; ; "
 8 "Bacteria;  Actinobacteria;  Thermoleophilia;  Solirubrobacterales; ; ; "
 9 "Bacteria;  Proteobacteria;  Gammaproteobacteria;  Chromatiales; ; ; "
10 "Bacteria;  Proteobacteria;  Alphaproteobacteria;  Sphingomonadales;  Sphingomonadaceae;  Kaistobacter; "
11 "Bacteria;  Actinobacteria;  Thermoleophilia;  Solirubrobacterales; ; ; "
12 "Bacteria;  Proteobacteria;  Betaproteobacteria;  Burkholderiales;  Oxalobacteraceae;  Ralstonia; "
13 "Bacteria;  Actinobacteria;  Actinobacteria;  Actinomycetales;  Pseudonocardiaceae; ; "
14 "Bacteria;  Actinobacteria;  Actinobacteria;  Actinomycetales;  Micrococcaceae;  Arthrobacter; "
</code>```

data:

```<code>structure(list(col1 = c("Bacteria; Proteobacteria; Gammaproteobacteria;",
"Bacteria; Proteobacteria; Gammaproteobacteria;", "Bacteria; Actinobacteria; Rubrobacteria; Rubrobacterales; Rubrobacteraceae; Rubrobacter;",
"Bacteria; Gemmatimonadetes; Gemm-1;", "Bacteria; Proteobacteria; Gammaproteobacteria; Chromatiales;",
"Bacteria; Actinobacteria; Nitriliruptoria; Nitriliruptorales; Nitriliruptoraceae;",
"Bacteria; Proteobacteria; Gammaproteobacteria; Chromatiales;",
"Bacteria; Actinobacteria; Thermoleophilia; Solirubrobacterales;",
"Bacteria; Proteobacteria; Gammaproteobacteria; Chromatiales;",
"Bacteria; Proteobacteria; Alphaproteobacteria; Sphingomonadales; Sphingomonadaceae; Kaistobacter;",
"Bacteria; Actinobacteria; Thermoleophilia; Solirubrobacterales;",
"Bacteria; Proteobacteria; Betaproteobacteria; Burkholderiales; Oxalobacteraceae; Ralstonia;",
"Bacteria; Actinobacteria; Actinobacteria; Actinomycetales; Pseudonocardiaceae;",
"Bacteria; Actinobacteria; Actinobacteria; Actinomycetales; Micrococcaceae; Arthrobacter;"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-14L))
</code>```

Title: Count character in specific cell and add that character a specified amount of times

Body:
We could use separate with the fill argument from tidyr package and
then paste them all together and finally replace NA by ""

library(tidyverse)

df %>%
  separate(col1, c("a","b","c","d","e","f","g"), fill = "right", sep = ";") %>%
  mutate(col1 = paste(a,b,c,d,e,f,g, sep = "; "), .keep="unused") %>%
  mutate(col1 = str_replace_all(col1, "NA", ""))

   col1
   <chr>
 1 "Bacteria;  Proteobacteria;  Gammaproteobacteria; ; ; ; "
 2 "Bacteria;  Proteobacteria;  Gammaproteobacteria; ; ; ; "
 3 "Bacteria;  Actinobacteria;  Rubrobacteria;  Rubrobacterales;  Rubrobacteraceae;  Rubrobacter; "
 4 "Bacteria;  Gemmatimonadetes;  Gemm-1; ; ; ; "
 5 "Bacteria;  Proteobacteria;  Gammaproteobacteria;  Chromatiales; ; ; "
 6 "Bacteria;  Actinobacteria;  Nitriliruptoria;  Nitriliruptorales;  Nitriliruptoraceae; ; "
 7 "Bacteria;  Proteobacteria;  Gammaproteobacteria;  Chromatiales; ; ; "
 8 "Bacteria;  Actinobacteria;  Thermoleophilia;  Solirubrobacterales; ; ; "
 9 "Bacteria;  Proteobacteria;  Gammaproteobacteria;  Chromatiales; ; ; "
10 "Bacteria;  Proteobacteria;  Alphaproteobacteria;  Sphingomonadales;  Sphingomonadaceae;  Kaistobacter; "
11 "Bacteria;  Actinobacteria;  Thermoleophilia;  Solirubrobacterales; ; ; "
12 "Bacteria;  Proteobacteria;  Betaproteobacteria;  Burkholderiales;  Oxalobacteraceae;  Ralstonia; "
13 "Bacteria;  Actinobacteria;  Actinobacteria;  Actinomycetales;  Pseudonocardiaceae; ; "
14 "Bacteria;  Actinobacteria;  Actinobacteria;  Actinomycetales;  Micrococcaceae;  Arthrobacter; "

data:

structure(list(col1 = c("Bacteria; Proteobacteria; Gammaproteobacteria;",
"Bacteria; Proteobacteria; Gammaproteobacteria;", "Bacteria; Actinobacteria; Rubrobacteria; Rubrobacterales; Rubrobacteraceae; Rubrobacter;",
"Bacteria; Gemmatimonadetes; Gemm-1;", "Bacteria; Proteobacteria; Gammaproteobacteria; Chromatiales;",
"Bacteria; Actinobacteria; Nitriliruptoria; Nitriliruptorales; Nitriliruptoraceae;",
"Bacteria; Proteobacteria; Gammaproteobacteria; Chromatiales;",
"Bacteria; Actinobacteria; Thermoleophilia; Solirubrobacterales;",
"Bacteria; Proteobacteria; Gammaproteobacteria; Chromatiales;",
"Bacteria; Proteobacteria; Alphaproteobacteria; Sphingomonadales; Sphingomonadaceae; Kaistobacter;",
"Bacteria; Actinobacteria; Thermoleophilia; Solirubrobacterales;",
"Bacteria; Proteobacteria; Betaproteobacteria; Burkholderiales; Oxalobacteraceae; Ralstonia;",
"Bacteria; Actinobacteria; Actinobacteria; Actinomycetales; Pseudonocardiaceae;",
"Bacteria; Actinobacteria; Actinobacteria; Actinomycetales; Micrococcaceae; Arthrobacter;"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-14L))


问:
Is there any way to prevent multiple the same API calls in NextJS?
For example: I have 10 pages. And for 8 of them, I need to have the same data. So in the getStaticProps method I doing API calls. But they are the same! I don't want to do the same calls 8 times to get the same data. I want to do one call and have access to this data from anywhere.

Are we have some solutions for this?

答: You can share data across all pages in build time by implementing a simple file system cache, when you get data from your api you can saving it in a file with specific name as key , for next time you can first check if there is a file with that key and get the data from it.</p>


问:
Failed to run MSBuild command on pip
I am installing the scikit-survival package in Python. When I run

```<code>pip install scikit-survival
</code>```

I get an error on msbuild, I attach the elements of interest below:

```<code>
PS C:\WINDOWS\system32> pip install scikit-survival

..
Building wheels for collected packages: qdldl
Building wheel for qdldl (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [24 lines of output]
running bdist_wheel
running build
running build_ext
-- Selecting Windows SDK version  to target Windows 10.0.22000.
CMake Error at CMakeLists.txt:4 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
Impossibile trovare il file specification
-- Configuring incomplete, errors occurred!
See also "C:/Users/xyz/AppData/Local/Temp/pip-install-
uyja9anj/qdldl_c05b02902dbe43b69e2860ddcf14a11a/c/build/CMakeFiles/CMak
eOutput.log".
Impossibile trovare il file specification
CMake Error: Generator: execution of make failed. Make command was:
MSBuild.exe qdldlamd.vcxproj /p:Configuration=Release /p:Platform=x64
/p:VisualStudioVersion=14.0 /v:m &&
building 'qdldl' extension
cl : warning della riga di comando D9002 : l'opzione sconosciuta '-
std=c++11' verr… ignorata                            qdldl.cpp
c\qdldl/include/qdldl.h(5): fatal error C1083: Non Š possibile aprire
il file inclusione: 'qdldl_types.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual
Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x
64\\cl.exe' failed with exit code 2
[end of output]
...
```

The issue is with MSbuild.exe. Do you know how it can be solved? I have installed both Visual Studio Community with Python extensions and Visual Studio Build Tools.

答:
It seems to be that your're using the wrong VisualStudio version. As mentioned in the Make command error VisualStudioVersion should be 14.0 (which is Visual Studio 2015), your Visual Studio Version is 2022 (VisualStudioVersion=22.X).

CMake and the different VS Versions as well as the different SDKs are a little bit confusing.

What helped me:

In the Visual Studio Installer, Modify your VisualStudio Installation as mentioned in the top comment of this. (Desktop development with C++ > Optional > MSVC v140 - VS 2015, should be at the bottom of the list)

If you're running in another error (which happened to me) you might have to install Windows SDK 8.1

There might be a way to change the Visual Studio Version for CMake, since the steps above helped me I haven't had a look at another solution.

Please let me know if this helps or if there is another problem.

Cheers.

Title: Failed to run MSBuild command on pip

Body:
I am installing the scikit-survival package in Python. When I run

pip install scikit-survival

I get an error on msbuild, I attach the elements of interest below:

PS C:\WINDOWS\system32> pip install scikit-survival

..
Building wheels for collected packages: qdldl
Building wheel for qdldl (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [24 lines of output]
running bdist_wheel
running build
running build_ext
-- Selecting Windows SDK version  to target Windows 10.0.22000.
CMake Error at CMakeLists.txt:4 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
Impossibile trovare il file specification
-- Configuring incomplete, errors occurred!
See also "C:/Users/xyz/AppData/Local/Temp/pip-install-
uyja9anj/qdldl_c05b02902dbe43b69e2860ddcf14a11a/c/build/CMakeFiles/CMak
eOutput.log".
Impossibile trovare il file specification
CMake Error: Generator: execution of make failed. Make command was:
MSBuild.exe qdldlamd.vcxproj /p:Configuration=Release /p:Platform=x64
/p:VisualStudioVersion=14.0 /v:m &&
building 'qdldl' extension
cl : warning della riga di comando D9002 : l'opzione sconosciuta '-
std=c++11' verr… ignorata                            qdldl.cpp
c\qdldl/include/qdldl.h(5): fatal error C1083: Non Š possibile aprire
il file inclusione: 'qdldl_types.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual
Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x
64\\cl.exe' failed with exit code 2
[end of output]
...

The issue is with MSbuild.exe. Do you know how it can be solved? I have installed both Visual Studio Community with Python extensions and Visual Studio Build Tools.


问:
Upload to google drive using The files get uploaded, but, only in the root and are always named "Untitled"
I am trying to upload files to Google drive using a REST API

Everything is working fine, but files are uploading into Google Drive only in the root, and with "Untitled" as their name.

public class UploadTODrive {

    public static DriveFiles UploadFileTODrive(String accessToken, MultipartFile files) throws IOException {

        RestTemplate restTemplate = new RestTemplate();
        String requestUri = "https://www.googleapis.com/upload/drive/v2/files";
        System.out.println("ContentType==============: " + files.getContentType());
        byte[] s=files.getBytes();
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", files.getContentType());
        headers.setContentLength(0);
        //headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        headers.add("Authorization", "Bearer " + accessToken);
            HttpEntity<byte[]> requestEntity = new HttpEntity<>(s, headers);
            ResponseEntity<String> response = restTemplate.exchange(requestUri, HttpMethod.POST, requestEntity,
                    String.class);
            System.out.println("=====>Response: " + response);
            Gson gson = new Gson();
            DriveFiles driveFiles = gson.fromJson(response.getBody(), DriveFiles.class);

        return driveFiles;
    }

}
```

答:
Files are uploaded to google drive in two parts.

The first part is the meta data of the file, this being the name and the mimetype most often and occasionally containing a parent directory.

The second part is the upload of the actual file stream.

It seams that you are uploading the file stream but you have forgotten to post the file metadata.  This is posted in the body of your request

This is your HTTP Post request. You need to figure out how to add a post body to this. This is the documentation link to the writable fields that you can post insert#request-body

```<code>ResponseEntity<String> response = restTemplate.exchange(requestUri, HttpMethod.POST, requestEntity,
            String.class);
</code>```

Update

found this with a bit of googling

```<code>RESTRequest1.AddBody('{"title": "Capture.jpg"}', TRESTContentType.ctAPPLICATION_JSON);
</code>```

Body:
Files are uploaded to google drive in two parts.

The first part is the meta data of the file, this being the name and the mimetype most often and occasionally containing a parent directory.

The second part is the upload of the actual file stream.

It seams that you are uploading the file stream but you have forgotten to post the file metadata.  This is posted in the body of your request

This is your HTTP Post request. You need to figure out how to add a post body to this. This is the documentation link to the writable fields that you can post insert#request-body

ResponseEntity<String> response = restTemplate.exchange(requestUri, HttpMethod.POST, requestEntity,
            String.class);

Update

found this with a bit of googling

RESTRequest1.AddBody('{"title": "Capture.jpg"}', TRESTContentType.ctAPPLICATION_JSON);


问:
What is the easiest way to generate a String of n repeated characters?
Given a character c and a number n, how can I create a String that consists of n repetitions of c? Doing it manually is too cumbersome:

```<code>StringBuilder sb = new StringBuilder(n);
for (int i = 0; i < n; ++i)
{
    sb.append(c);
}
String result = sb.toString();
</code>```

Surely there is some static library function that already does this for me?

答:
Here is an O(logN) method, based on the standard binary powering algorithm:

```<code>public static String repChar(char c, int reps) {
    String adder = Character.toString(c);
    String result = "";
    while (reps > 0) {
        if (reps % 2 == 1) {
            result += adder;
        }
        adder += adder;
        reps /= 2;
    }
    return result;
}
</code>```

Negative values for reps return the empty string.

Body:
Given a character c and a number n, how can I create a String that consists of n repetitions of c? Doing it manually is too cumbersome:

StringBuilder sb = new StringBuilder(n);
for (int i = 0; i < n; ++i)
{
    sb.append(c);
}
String result = sb.toString();

Surely there is some static library function that already does this for me?

Body:
Here is an O(logN) method, based on the standard binary powering algorithm:

public static String repChar(char c, int reps) {
    String adder = Character.toString(c);
    String result = "";
    while (reps > 0) {
        if (reps % 2 == 1) {
            result += adder;
        }
        adder += adder;
        reps /= 2;
    }
    return result;
}

Negative values for reps return the empty string.