问:
SSIS runs a package multiple times in parallel
I have a package that does a job with the configuration from a table.

right now I can create a [foreach loop] and it will work fine and do the process for each row.
but since it will run in serial and my processes are independent I want my [foreach loop] runs all of the packages in parallel.
does anyone know how to do that?

(image for visualization so don't mind the red errors)

答:
I've been able to get that to work with a Exec SQL statement. As soon as the SQL fires successfully and starts the package then it moves to the next loop.

```<code>Declare @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'Package.dtsx',
    @execution_id=@execution_id OUTPUT,
    @folder_name=N'Deployed Projects',
      @project_name=N'Integration Services Project1',
    @use32bitruntime=False,
      @reference_id=Null
Select @execution_id
DECLARE @var0 smallint = 1
EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id,
    @object_type=50,
      @parameter_name=N'LOGGING_LEVEL',
      @parameter_value=@var0
EXEC [SSISDB].[catalog].[start_execution] @execution_id
GO
</code>```

Here's the Microsoft link:

https://learn.microsoft.com/en-us/sql/integration-services/ssis-quickstart-run-tsql-ssms?view=sql-server-ver15

Setting parameters uses a different object type that you need to google.

Body:
I've been able to get that to work with a Exec SQL statement. As soon as the SQL fires successfully and starts the package then it moves to the next loop.

Declare @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'Package.dtsx',
    @execution_id=@execution_id OUTPUT,
    @folder_name=N'Deployed Projects',
      @project_name=N'Integration Services Project1',
    @use32bitruntime=False,
      @reference_id=Null
Select @execution_id
DECLARE @var0 smallint = 1
EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id,
    @object_type=50,
      @parameter_name=N'LOGGING_LEVEL',
      @parameter_value=@var0
EXEC [SSISDB].[catalog].[start_execution] @execution_id
GO

Here's the Microsoft link:

https://learn.microsoft.com/en-us/sql/integration-services/ssis-quickstart-run-tsql-ssms?view=sql-server-ver15

Setting parameters uses a different object type that you need to google.


来源: stackexchange

问:
How to pull typings in Deno
I am checking out Deno and have found one of the starter examples very elegant:

```<code>import { serve } from "https://deno.land/x/std@v0.2.10/http/server.ts";
const s = serve("0.0.0.0:8000");

void async function main() {
  for await (const req of s) {
     req.respond({ body: new TextEncoder().encode("Hello World\n") });
  }
}()
</code>```

I am using VS Code to author Deno scripts, but I am not sure how I can make the editor aware of typings for the imported functions, such as serve. I think it may be too soon for IDE support with Deno, but in case there is a solution or a workaround, I'd like to know about it.

Do I need to install a @types package or something like that? import or reference some .d.ts declaration files? How do I make VS Code offer code completion suggestions and display type annotations when using the serve function in this example and any imported scripts in Deno in general?

答:
tldr

Install denoland.vscode-deno extension 1. Then enable Deno in a particular project, like

<proj-root>/.vscode/settings.json:
```<code>{
  "deno.enable": true, // enables extension
  "deno.lint": true, // inline deno lint diagnostics, requires `deno.unstable`
  "deno.unstable": true // also provides unstable type declarations in VS Code
}
</code>```

Starting with v2.3.0, you can also use the deno: Init wizard 2:

To integrate a TS workspace version instead of VS Code built-in one, take a look at linked docs.

1 This one is deprecated.

2 Note: In a new empty project, at least one source file needs to exist before the wizard works properly.

More details

What does the extension do?

permits explicit .ts extensions in VS Code

resolves URL import specifiers like "https://deno.land/std@0.56.0/http/server.ts"

integrates Deno runtime types (e.g. Deno.writeFile)

How to resolve types for .ts modules

With above extension, VS Code permits .ts file extensions for imports and resolves URL imports to a local disk cache. The compiler can use these cached type definitions to do checks. Last, fetch all sources and restart TS server / reload VS Code:

deno cache https://deno.land/std/http/server.ts # fetch and compile from URL
# or main project file
deno cache <your main file>.ts # fetches all its dependencies
```
<p><code>server.ts</code> is part of the Standard Library, which is just a more strictly maintained collection of remote <code>.ts</code> modules, so it also will be typed correctly.</p>
<h2>How to resolve types for <code>.js</code> modules</h2>
<p>Deno provides additional ways to reference <code>.d.ts</code> files for <code>.js</code> files.</p>
Specify type definition at import code location:
```// @deno-types="./foo.d.ts"
import * as foo from "./foo.js";
```
Specify type definition at host code location:
```/// <reference types="./foo.d.ts" />
export const foo = "foo";
```
<p>Alternative: Deno can read a custom <code>X-TypeScript-Types</code> HTTP header from remote imports.</p>
<h2>How to use a custom <code>tsconfig.json</code></h2>
A given <code>tsconfig.json</code> file in a project is merged with the Deno default config, e.g.:
```{
  "compilerOptions": {
    // set a custom, deviant value
    "noImplicitAny": false // deno default is true
    // (this is just an example - use strong types, whenever possible)
  }
}
```
Include <code>-c</code> option, so VS Code and Deno CLI have the same compiler settings:
```deno run -c ./tsconfig.json main.ts
```
<h2>How to use <code>--unstable</code> types</h2>
<p>The easiest option is to set <code>"deno.unstable": true</code> (PR) in <code>settings.json</code> and restart VS Code, see the <code>tldr</code> section.</p>
<h3>Manual alternative</h3>
<pre class="lang-sh prettyprint-override"><code>cd <your-project>
deno types --unstable > deno.runtime.d.ts
touch tsconfig.json # (1); jsconfig.json for JS projects also possible
</code>```

VS Code automatically includes deno.runtime.d.ts with an existent tsconfig.json (1).

Breaking Changes

vscode-deno v1.26.0

The extension needs to be explicitly enabled by "deno.enable": true in .vscode/settings.json of the project (default is false). Before, the default had been true.

vscode-deno < 1.25.0

Install Deno types in every case (stable and unstable) - see "How to use --unstable types".

ContentLicense: CC BY-SA 4.0

Title: How to pull typings in Deno

Body:
I am checking out Deno and have found one of the starter examples very elegant:

import { serve } from "https://deno.land/x/std@v0.2.10/http/server.ts";
const s = serve("0.0.0.0:8000");

void async function main() {
  for await (const req of s) {
     req.respond({ body: new TextEncoder().encode("Hello World\n") });
  }
}()

I am using VS Code to author Deno scripts, but I am not sure how I can make the editor aware of typings for the imported functions, such as serve. I think it may be too soon for IDE support with Deno, but in case there is a solution or a workaround, I'd like to know about it.

Do I need to install a @types package or something like that? import or reference some .d.ts declaration files? How do I make VS Code offer code completion suggestions and display type annotations when using the serve function in this example and any imported scripts in Deno in general?

Body:
tldr

Install denoland.vscode-deno extension 1. Then enable Deno in a particular project, like

<proj-root>/.vscode/settings.json:

{
  "deno.enable": true, // enables extension
  "deno.lint": true, // inline deno lint diagnostics, requires `deno.unstable`
  "deno.unstable": true // also provides unstable type declarations in VS Code
}

Starting with v2.3.0, you can also use the deno: Init wizard 2:

To integrate a TS workspace version instead of VS Code built-in one, take a look at linked docs.

1 This one is deprecated.

2 Note: In a new empty project, at least one source file needs to exist before the wizard works properly.

More details

What does the extension do?

permits explicit .ts extensions in VS Code

resolves URL import specifiers like "https://deno.land/std@0.56.0/http/server.ts"

integrates Deno runtime types (e.g. Deno.writeFile)

How to resolve types for .ts modules

With above extension, VS Code permits .ts file extensions for imports and resolves URL imports to a local disk cache. The compiler can use these cached type definitions to do checks. Last, fetch all sources and restart TS server / reload VS Code:

deno cache https://deno.land/std/http/server.ts # fetch and compile from URL
# or main project file
deno cache <your main file>.ts # fetches all its dependencies

server.ts is part of the Standard Library, which is just a more strictly maintained collection of remote .ts modules, so it also will be typed correctly.

How to resolve types for .js modules

Deno provides additional ways to reference .d.ts files for .js files.

Specify type definition at import code location:

// @deno-types="./foo.d.ts"
import * as foo from "./foo.js";

Specify type definition at host code location:

/// <reference types="./foo.d.ts" />
export const foo = "foo";

Alternative: Deno can read a custom X-TypeScript-Types HTTP header from remote imports.

How to use a custom tsconfig.json

A given tsconfig.json file in a project is merged with the Deno default config, e.g.:

{
  "compilerOptions": {
    // set a custom, deviant value
    "noImplicitAny": false // deno default is true
    // (this is just an example - use strong types, whenever possible)
  }
}

Include -c option, so VS Code and Deno CLI have the same compiler settings:

deno run -c ./tsconfig.json main.ts

How to use --unstable types

The easiest option is to set "deno.unstable": true (PR) in settings.json and restart VS Code, see the tldr section.

Manual alternative

cd <your-project>
deno types --unstable > deno.runtime.d.ts
touch tsconfig.json # (1); jsconfig.json for JS projects also possible

VS Code automatically includes deno.runtime.d.ts with an existent tsconfig.json (1).

Breaking Changes

vscode-deno v1.26.0

The extension needs to be explicitly enabled by "deno.enable": true in .vscode/settings.json of the project (default is false). Before, the default had been true.

vscode-deno < 1.25.0

Install Deno types in every case (stable and unstable) - see "How to use --unstable types".


问:
How to get server id and channel id in discord.js using command?
I was trying to save guild id and channel id using one command, using lowdb but I when I'm using var server = client.guilds.get(message.guild.id).id;  I get error that says, Cannot read property 'get' of undefined. And I don't know why.

```<code>var server = client.guilds.get(message.guild.id).id;
var channel = client.guilds.get(message.channel.id).id;

db.get('posts')
  .push({ id: server, title: channel})
  .write();
</code>```

There's all code I made, and I define everything on start of code

```<code>const client = require('<there's path but I don't want to show it cuz there's my name>/my_bot.js');
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')

const adapter = new FileSync('db.json')
const db = low(adapter)
</code>```

If you know what's wrong please help

答:
If you're using discord.js@v12 then you should remember that you should go through the .cache property for your code to work. You can check that by yourself by looking at the docs for Client.guilds.

Also, you don't need to get the channel and the guild from their IDs, since you already have them stored as message properties.

Here's how I would do it:

let server = message.guild.id, // ID of the guild the message was sent in
  channel = message.channel.id // ID of the channel the message was sent in
```

To be fair, I wouldn't be able to explain why you get that error.

Body:
I was trying to save guild id and channel id using one command, using lowdb but I when I'm using var server = client.guilds.get(message.guild.id).id;  I get error that says, Cannot read property 'get' of undefined. And I don't know why.

var server = client.guilds.get(message.guild.id).id;
var channel = client.guilds.get(message.channel.id).id;

db.get('posts')
  .push({ id: server, title: channel})
  .write();

There's all code I made, and I define everything on start of code

const client = require('<there's path but I don't want to show it cuz there's my name>/my_bot.js');
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')

const adapter = new FileSync('db.json')
const db = low(adapter)

If you know what's wrong please help

Body:
If you're using discord.js@v12 then you should remember that you should go through the .cache property for your code to work. You can check that by yourself by looking at the docs for Client.guilds.

Also, you don't need to get the channel and the guild from their IDs, since you already have them stored as message properties.

Here's how I would do it:

let server = message.guild.id, // ID of the guild the message was sent in
  channel = message.channel.id // ID of the channel the message was sent in

To be fair, I wouldn't be able to explain why you get that error.


问:
on languages that can link to c++
As I was reflecting on this subject, it seemed to me that if a language is implemented in C++, it might well have a mechanism for linking to C++. As I recall, Java is this way through JNI, though I don't really remember if it goes through C++ or plain C.

However, it seems that in general languages don't link to C++, and are accessible to C++ only through C for various reasons.

So, out of curiosity,

What languages are there that can link to C++ and how and to what extent?

(No credit for the aforementioned C bridge unless it is done in an elegant or interesting way, like Boost.Python)

答:
Note: the ABI includes name-mangling as well as the calling convention, environment requirements, etc.  The EABI (not covered here) is platform-specific but is usually standardized for each platform (though this is not guaranteed) and does not suffer from the problems of a variadic EABI (because it doesn't change much).  Consult ABI on Wikipedia for a bit more on the subject.

Linking to C++ is unlikely because the ABI is undefined.  Thus, the names of symbols can change at the will of the compiler vendor.  GCC does it differently from MS's compiler, for example.  Even with the same compiler ABI's may be different between versions (as is the case with some GCC versions).

However, linking to C++ is not impossible.  It's common for C++ programs to link to other C++ programs because both are compiled by the same compiler (or at least compilers which use the same ABI).  If the ABI is known, non-C++ applications can link to C++ ones.

Linking to C is easy.  This is because C's ABI is more stable than C++'s ABI for most platforms.  This is due to C's simplicity compared to C++.  Because C++ can export C symbols, bypassing the problem with C++'s ABI, you sometimes see C++ libraries export C symbols which allow interaction with the underlying C++ objects without the problems of name mangling, link compatability, and future-proofing.  However, doing this prevents you from easily using the C++ library via the C interface with the C++ interface.

But you can use the C++ interface by using the C exports.  The library can provide some classes in header files which wrap the C exports for you.  This is more work on the library writers (and can cause some problems because DRY usually isn't practiced with this technique) but provides much benefit for library users (which can choose between both interfaces without worrying about linking issues!).  For other languages the library writers can provide interfaces like the C++ header files which deal with the C exports themselves.  (You then have the advantage of using native classes and such.)

OwnerDisplayName: Ellery Newcomer

ContentLicense: CC BY-SA 2.5

Title: on languages that can link to c++

OwnerDisplayName: strager

LastEditorDisplayName: strager


问:
Query for the value of a field matched only if a specific set of rows exist
That is, let's say I have a table of people and the items they carry -- let's call the columns id, personid, and itemid.  I want to find only the people who carry all of a given set of items; that is, the personids of those with rows having itemids of a given set of values.

What's a good way I might do this?

答:
Just to give this proper closure, here's onedaywhen's answer comment as a regular 'answer':

http://www.simple-talk.com/sql/t-sql-programming/divided-we-stand-the-sql-of-relational-division/

ContentLicense: CC BY-SA 3.0


问:
Convert Dat Data To Data Frame
I'm reading data data and trying to convert it to data frame to save it into readable format. However no clue about converting the dat data. A bit beginner to R. Any help will be highly appreciated.

Code so Far:

```<code>data <- readLines("Day8.dat")

print(data)
</code>```

Output So Far:

```<code>[1] "<d2lm:d2LogicalModel extensionVersion=\"2.0\" extensionName=\"NTIS Published Services\"
modelBaseVersion=\"2\" xmlns:ns4=\"http://www.thalesgroup.com/NTIS/Datex2Extensions/1.0Beta1\"
xmlns:ns3=\"http://datex2.eu/schema/2/2_0/inrix\" xmlns:d2lm=\"http://datex2.eu/schema/2/2_0\">
<d2lm:exchange><d2lm:supplierIdentification><d2lm:country>gb</d2lm:country>
<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier></d2lm:supplierIdentification></d2lm:exchange>
<d2lm:payloadPublication xsi:type=\"d2lm:SituationPublication\" lang=\"en\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d2lm:feedType>Event Data</d2lm:feedType>
<d2lm:publicationTime>2020-05-10T00:00:44.778+01:00</d2lm:publicationTime><d2lm:publicationCreator>
<d2lm:country>gb</d2lm:country><d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>
</d2lm:publicationCreator><d2lm:situation version=\"\" id=\"2922904\"><d2lm:headerInformation>
<d2lm:areaOfInterest>national</d2lm:areaOfInterest>
....
</code>```

Thanks

答:
It all depends on what you want to do with the data, i.e., how you want to process it.
For example, let's assume your interest is in parsing all XML tags as separate strings, then you can extract the tags using regular expression and the function str_extract:

```<code>library(stringr)
str_extract_all(dat, "<(d2lm:[^>]*)>.*</\\1>|<d2lm:[^>]*>")
</code>```

This regex works even if the XML element names are variable:

```<code>str_extract_all(dat, "<([^>]*)>.*</\\1>|<[^>]*>")
</code>```

The result is a list:

```<code>[[1]]
 [1] "<d2lm:d2LogicalModel extensionVersion=\"2.0\" extensionName=\"NTIS Published Services\" \nmodelBaseVersion=\"2\" xmlns:ns4=\"http://www.thalesgroup.com/NTIS/Datex2Extensions/1.0Beta1\" \nxmlns:ns3=\"http://datex2.eu/schema/2/2_0/inrix\" xmlns:d2lm=\"http://datex2.eu/schema/2/2_0\">"
 [2] "<d2lm:exchange>"
 [3] "<d2lm:supplierIdentification>"
 [4] "<d2lm:country>gb</d2lm:country>"
 [5] "<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>"
 [6] "<d2lm:payloadPublication xsi:type=\"d2lm:SituationPublication\" lang=\"en\" \nxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
 [7] "<d2lm:feedType>Event Data</d2lm:feedType>"
 [8] "<d2lm:publicationTime>2020-05-10T00:00:44.778+01:00</d2lm:publicationTime>"
 [9] "<d2lm:publicationCreator>"
[10] "<d2lm:country>gb</d2lm:country>"
[11] "<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>"
[12] "<d2lm:situation version=\"\" id=\"2922904\">"
[13] "<d2lm:headerInformation>"
[14] "<d2lm:areaOfInterest>national</d2lm:areaOfInterest>"
</code>```

To turn the list into a dataframe:

```<code>datDF <- data.frame(tags = unlist(str_extract_all(dat, "<(d2lm:[^>]*)>.*</\\1>|<d2lm:[^>]*>")))
</code>```

EDIT:

If you want to have a dataframe with the text values between XML start tag and XML end tag, you can extract these tags and values along these lines:

```<code>datDF <- data.frame(
  tags = unlist(str_extract_all(dat, "<([^>]*)>(?=[^>]*</\\1>)")),
  values = unlist(str_extract_all(dat, "(?<=<([^>]{1,100})>).*(?=</\\1>)"))
)
datDF
                       tags                        values
1            <d2lm:country>                            gb
2 <d2lm:nationalIdentifier>                          NTIS
3           <d2lm:feedType>                    Event Data
4    <d2lm:publicationTime> 2020-05-10T00:00:44.778+01:00
5            <d2lm:country>                            gb
6 <d2lm:nationalIdentifier>                          NTIS
7     <d2lm:areaOfInterest>                      national
</code>```

Is this--roughly--what you had in mind?

DATA:

```<code>dat <- '<d2lm:d2LogicalModel extensionVersion=\"2.0\" extensionName=\"NTIS Published Services\"
modelBaseVersion=\"2\" xmlns:ns4=\"http://www.thalesgroup.com/NTIS/Datex2Extensions/1.0Beta1\"
xmlns:ns3=\"http://datex2.eu/schema/2/2_0/inrix\" xmlns:d2lm=\"http://datex2.eu/schema/2/2_0\">
<d2lm:exchange><d2lm:supplierIdentification><d2lm:country>gb</d2lm:country>
<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier></d2lm:supplierIdentification></d2lm:exchange>
<d2lm:payloadPublication xsi:type=\"d2lm:SituationPublication\" lang=\"en\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d2lm:feedType>Event Data</d2lm:feedType>
<d2lm:publicationTime>2020-05-10T00:00:44.778+01:00</d2lm:publicationTime><d2lm:publicationCreator>
<d2lm:country>gb</d2lm:country><d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>
</d2lm:publicationCreator><d2lm:situation version=\"\" id=\"2922904\"><d2lm:headerInformation>
<d2lm:areaOfInterest>national</d2lm:areaOfInterest>'
</code>```

Title: Convert Dat Data To Data Frame

Body:
I'm reading data data and trying to convert it to data frame to save it into readable format. However no clue about converting the dat data. A bit beginner to R. Any help will be highly appreciated.

Code so Far:

data <- readLines("Day8.dat")

print(data)

Output So Far:

[1] "<d2lm:d2LogicalModel extensionVersion=\"2.0\" extensionName=\"NTIS Published Services\"
modelBaseVersion=\"2\" xmlns:ns4=\"http://www.thalesgroup.com/NTIS/Datex2Extensions/1.0Beta1\"
xmlns:ns3=\"http://datex2.eu/schema/2/2_0/inrix\" xmlns:d2lm=\"http://datex2.eu/schema/2/2_0\">
<d2lm:exchange><d2lm:supplierIdentification><d2lm:country>gb</d2lm:country>
<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier></d2lm:supplierIdentification></d2lm:exchange>
<d2lm:payloadPublication xsi:type=\"d2lm:SituationPublication\" lang=\"en\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d2lm:feedType>Event Data</d2lm:feedType>
<d2lm:publicationTime>2020-05-10T00:00:44.778+01:00</d2lm:publicationTime><d2lm:publicationCreator>
<d2lm:country>gb</d2lm:country><d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>
</d2lm:publicationCreator><d2lm:situation version=\"\" id=\"2922904\"><d2lm:headerInformation>
<d2lm:areaOfInterest>national</d2lm:areaOfInterest>
....

Thanks

Body:
It all depends on what you want to do with the data, i.e., how you want to process it.
For example, let's assume your interest is in parsing all XML tags as separate strings, then you can extract the tags using regular expression and the function str_extract:

library(stringr)
str_extract_all(dat, "<(d2lm:[^>]*)>.*</\\1>|<d2lm:[^>]*>")

This regex works even if the XML element names are variable:

str_extract_all(dat, "<([^>]*)>.*</\\1>|<[^>]*>")

The result is a list:

[[1]]
 [1] "<d2lm:d2LogicalModel extensionVersion=\"2.0\" extensionName=\"NTIS Published Services\" \nmodelBaseVersion=\"2\" xmlns:ns4=\"http://www.thalesgroup.com/NTIS/Datex2Extensions/1.0Beta1\" \nxmlns:ns3=\"http://datex2.eu/schema/2/2_0/inrix\" xmlns:d2lm=\"http://datex2.eu/schema/2/2_0\">"
 [2] "<d2lm:exchange>"
 [3] "<d2lm:supplierIdentification>"
 [4] "<d2lm:country>gb</d2lm:country>"
 [5] "<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>"
 [6] "<d2lm:payloadPublication xsi:type=\"d2lm:SituationPublication\" lang=\"en\" \nxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
 [7] "<d2lm:feedType>Event Data</d2lm:feedType>"
 [8] "<d2lm:publicationTime>2020-05-10T00:00:44.778+01:00</d2lm:publicationTime>"
 [9] "<d2lm:publicationCreator>"
[10] "<d2lm:country>gb</d2lm:country>"
[11] "<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>"
[12] "<d2lm:situation version=\"\" id=\"2922904\">"
[13] "<d2lm:headerInformation>"
[14] "<d2lm:areaOfInterest>national</d2lm:areaOfInterest>"

To turn the list into a dataframe:

datDF <- data.frame(tags = unlist(str_extract_all(dat, "<(d2lm:[^>]*)>.*</\\1>|<d2lm:[^>]*>")))

EDIT:

If you want to have a dataframe with the text values between XML start tag and XML end tag, you can extract these tags and values along these lines:

datDF <- data.frame(
  tags = unlist(str_extract_all(dat, "<([^>]*)>(?=[^>]*</\\1>)")),
  values = unlist(str_extract_all(dat, "(?<=<([^>]{1,100})>).*(?=</\\1>)"))
)
datDF
                       tags                        values
1            <d2lm:country>                            gb
2 <d2lm:nationalIdentifier>                          NTIS
3           <d2lm:feedType>                    Event Data
4    <d2lm:publicationTime> 2020-05-10T00:00:44.778+01:00
5            <d2lm:country>                            gb
6 <d2lm:nationalIdentifier>                          NTIS
7     <d2lm:areaOfInterest>                      national

Is this--roughly--what you had in mind?

DATA:

dat <- '<d2lm:d2LogicalModel extensionVersion=\"2.0\" extensionName=\"NTIS Published Services\"
modelBaseVersion=\"2\" xmlns:ns4=\"http://www.thalesgroup.com/NTIS/Datex2Extensions/1.0Beta1\"
xmlns:ns3=\"http://datex2.eu/schema/2/2_0/inrix\" xmlns:d2lm=\"http://datex2.eu/schema/2/2_0\">
<d2lm:exchange><d2lm:supplierIdentification><d2lm:country>gb</d2lm:country>
<d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier></d2lm:supplierIdentification></d2lm:exchange>
<d2lm:payloadPublication xsi:type=\"d2lm:SituationPublication\" lang=\"en\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d2lm:feedType>Event Data</d2lm:feedType>
<d2lm:publicationTime>2020-05-10T00:00:44.778+01:00</d2lm:publicationTime><d2lm:publicationCreator>
<d2lm:country>gb</d2lm:country><d2lm:nationalIdentifier>NTIS</d2lm:nationalIdentifier>
</d2lm:publicationCreator><d2lm:situation version=\"\" id=\"2922904\"><d2lm:headerInformation>
<d2lm:areaOfInterest>national</d2lm:areaOfInterest>'


问:
One liner to remove all occurrences of sub-strings in array with filter?
The title pretty much explains the question. I'd like to filter through an array and remove all occurrences of substrings. Similiar to how can be done by matching entire strings to remove like this

```<code>const x = ["don't delete", "delete", "delete", "don't delete", "delete", "don't delete"]
x= x.filter(i => i !== 'delete me');

> console.log(x)
["don't delete", "don't delete", "don't delete"]
</code>```

So let's say I want to just remove all the occurances of ' so every don't becomes dont, or maybe I just want to remove the every don't all together. I know you can match substrings with includes() but not sure how to implement it with a filter.

How could I go about this in a one liner? Thanks

答:
If I understood your question, you can do:

const x = ["don't delete", "delete", "delete", "don't delete", "delete", "don't delete"]
  .filter(i => i.includes("don't")).map(s => s.replace("'", ""));

console.log(x);```

So using a map() after the filter() will do the job.

Body:
The title pretty much explains the question. I'd like to filter through an array and remove all occurrences of substrings. Similiar to how can be done by matching entire strings to remove like this

const x = ["don't delete", "delete", "delete", "don't delete", "delete", "don't delete"]
x= x.filter(i => i !== 'delete me');

> console.log(x)
["don't delete", "don't delete", "don't delete"]

So let's say I want to just remove all the occurances of ' so every don't becomes dont, or maybe I just want to remove the every don't all together. I know you can match substrings with includes() but not sure how to implement it with a filter.

How could I go about this in a one liner? Thanks

Body:
If I understood your question, you can do:

const x = ["don't delete", "delete", "delete", "don't delete", "delete", "don't delete"]
  .filter(i => i.includes("don't")).map(s => s.replace("'", ""));

console.log(x);

So using a map() after the filter() will do the job.


问:
FFMPEG - Green cast with Splash image in video
I'm using FFMPEG to produce a video consisting of a single monchrome JPG image:

```<code>ffmpeg -y -loop 1 -framerate 30 -t 5 -i SplashBW.jpg Splash.mp4
</code>```

There are two issues with the resulting video:

When viewed with VLC it has a green cast

When viewed with "Film and TV" (I suspect this is the Windows 10
viewer - the association for MP4 files seems to have been hijacked
on my PC) it has a green cast and a predominant flickering every
0.5 seconds or so.

When viewed with Irfan View it looks fine.  I don't know whether the issue is with the original JPG, the FFMPEG command, or the viewers.  Naturally, I want it to render properly on all outputs.

The first two links below look fine in my browser (Chrome) when I open them.  The third link is a screen recording of what I see when I try to play the video with the Film and TVapp.

B&W image

Resulting video

screen grab of video playing on my PC

A log of the FFMPEG run:

```<code>C:\Users\Raymond\Desktop\Chorus\Videos\Virtual Choir>call ffmpeg -y -loglevel verbose -loop 1 -framerate 30 -t 5 -i SplashBW.jpg Splash.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libope
ncore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --
enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuv
id --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[AVIOContext @ 000001e6f6ccdd00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccde80] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6d59b00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccde40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccdf00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccdfc0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cce180] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cce240] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd33c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd3480] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd3640] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd3700] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 19 times
Input #0, image2, from 'SplashBW.jpg':
  Duration: 00:00:00.03, start: 0.000000, bitrate: 38348 kb/s
    Stream #0:0: Video: mjpeg (Baseline), 1 reference frame, gray(bt470bg/unknown/unknown, center), 1920x1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 30 tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 000001e6f6cd2ec0] w:1920 h:1080 pixfmt:gray tb:1/30 fr:30/1 sar:1/1 sws_param:flags=2
[libx264 @ 000001e6f6d57100] using SAR=1/1
[libx264 @ 000001e6f6d57100] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001e6f6d57100] profile High, level 4.0, 4:0:0, 8-bit
[libx264 @ 000001e6f6d57100] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chro
ma_me=0 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weigh
tb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'Splash.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), gray(center), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[AVIOContext @ 000001e6f8b98e00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5980] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeksspeed=   0x
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks1.0kbits/s speed=0.359x
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks0.3kbits/s speed=0.828x
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks0.2kbits/s speed=1.16x
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 2 times
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5980] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
No more output streams to write to, finishing.
frame=  150 fps= 51 q=-1.0 Lsize=     142kB time=00:00:04.90 bitrate= 237.8kbits/s speed=1.65x
video:140kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.855892%
Input file #0 (SplashBW.jpg):
  Input stream #0:0 (video): 151 packets read (24127535 bytes); 151 frames decoded;
  Total: 151 packets (24127535 bytes) demuxed
Output file #0 (Splash.mp4):
  Output stream #0:0 (video): 150 frames encoded; 150 packets muxed (143004 bytes);
  Total: 150 packets (143004 bytes) muxed
[AVIOContext @ 000001e6f6d59240] Statistics: 2 seeks, 4 writeouts
[libx264 @ 000001e6f6d57100] frame I:1     Avg QP:18.13  size:131209
[libx264 @ 000001e6f6d57100] frame P:38    Avg QP:16.03  size:    87
[libx264 @ 000001e6f6d57100] frame B:111   Avg QP:24.33  size:    70
[libx264 @ 000001e6f6d57100] consecutive B-frames:  1.3%  0.0%  0.0% 98.7%
[libx264 @ 000001e6f6d57100] mb I  I16..4:  1.8% 96.0%  2.2%
[libx264 @ 000001e6f6d57100] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:99.9%
[libx264 @ 000001e6f6d57100] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%  L0:21.7% L1:78.3% BI: 0.0%
[libx264 @ 000001e6f6d57100] 8x8 transform intra:96.0% inter:98.7%
[libx264 @ 000001e6f6d57100] coded y intra: 94.7% inter: 0.0%
[libx264 @ 000001e6f6d57100] i16 v,h,dc,p: 24% 37%  5% 34%
[libx264 @ 000001e6f6d57100] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 46% 22% 11%  3%  3%  3%  4%  3%  5%
[libx264 @ 000001e6f6d57100] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 79%  9%  2%  1%  2%  1%  4%  1%  1%
[libx264 @ 000001e6f6d57100] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 000001e6f6d57100] Weighted P-Frames: Y:0.0%
[libx264 @ 000001e6f6d57100] ref P L0: 96.6%  0.7%  1.3%  1.3%
[libx264 @ 000001e6f6d57100] ref B L0: 96.9%  2.1%  1.0%
[libx264 @ 000001e6f6d57100] ref B L1: 94.8%  5.2%
[libx264 @ 000001e6f6d57100] kb/s:227.72
[AVIOContext @ 000001e6f6ccb880] Statistics: 32768 bytes read, 0 seeks
</code>```

答:
Your input image has only one component channel - luminance. Most players deal with H.264 streams containing three component channels - luminance or 'brightness' (Y) and two for chroma or 'color' (U & V). When the H.264 encoder encodes a luma-only stream, it stores it using a syntax which many players don't handle well. So, we tell ffmpeg to add chroma components which will have neutral values (since there's no color valence in the source) before sending it to the encoder. We'll add the most common form of YUV encoding - yuv420p.

So,

```<code>ffmpeg -y -loop 1 -framerate 30 -t 5 -i SplashBW.jpg -pix_fmt yuv420p Splash.mp4
</code>```

Body:
I'm using FFMPEG to produce a video consisting of a single monchrome JPG image:

ffmpeg -y -loop 1 -framerate 30 -t 5 -i SplashBW.jpg Splash.mp4

There are two issues with the resulting video:

When viewed with VLC it has a green cast

When viewed with "Film and TV" (I suspect this is the Windows 10
viewer - the association for MP4 files seems to have been hijacked
on my PC) it has a green cast and a predominant flickering every
0.5 seconds or so.

When viewed with Irfan View it looks fine.  I don't know whether the issue is with the original JPG, the FFMPEG command, or the viewers.  Naturally, I want it to render properly on all outputs.

The first two links below look fine in my browser (Chrome) when I open them.  The third link is a screen recording of what I see when I try to play the video with the Film and TVapp.

B&W image

Resulting video

screen grab of video playing on my PC

A log of the FFMPEG run:

C:\Users\Raymond\Desktop\Chorus\Videos\Virtual Choir>call ffmpeg -y -loglevel verbose -loop 1 -framerate 30 -t 5 -i SplashBW.jpg Splash.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libope
ncore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --
enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuv
id --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[AVIOContext @ 000001e6f6ccdd00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccde80] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6d59b00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccde40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccdf00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6ccdfc0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cce180] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cce240] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd33c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd3480] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd3640] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd3700] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 19 times
Input #0, image2, from 'SplashBW.jpg':
  Duration: 00:00:00.03, start: 0.000000, bitrate: 38348 kb/s
    Stream #0:0: Video: mjpeg (Baseline), 1 reference frame, gray(bt470bg/unknown/unknown, center), 1920x1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 30 tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 000001e6f6cd2ec0] w:1920 h:1080 pixfmt:gray tb:1/30 fr:30/1 sar:1/1 sws_param:flags=2
[libx264 @ 000001e6f6d57100] using SAR=1/1
[libx264 @ 000001e6f6d57100] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001e6f6d57100] profile High, level 4.0, 4:0:0, 8-bit
[libx264 @ 000001e6f6d57100] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chro
ma_me=0 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weigh
tb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'Splash.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), gray(center), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[AVIOContext @ 000001e6f8b98e00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5980] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeksspeed=   0x
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks1.0kbits/s speed=0.359x
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks0.3kbits/s speed=0.828x
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd51c0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5580] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5840] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks0.2kbits/s speed=1.16x
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 2 times
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5300] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5440] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5700] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5980] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
    Last message repeated 1 times
[AVIOContext @ 000001e6f6cd5040] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd4f00] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5c40] Statistics: 159785 bytes read, 0 seeks
[AVIOContext @ 000001e6f6cd5ac0] Statistics: 159785 bytes read, 0 seeks
No more output streams to write to, finishing.
frame=  150 fps= 51 q=-1.0 Lsize=     142kB time=00:00:04.90 bitrate= 237.8kbits/s speed=1.65x
video:140kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.855892%
Input file #0 (SplashBW.jpg):
  Input stream #0:0 (video): 151 packets read (24127535 bytes); 151 frames decoded;
  Total: 151 packets (24127535 bytes) demuxed
Output file #0 (Splash.mp4):
  Output stream #0:0 (video): 150 frames encoded; 150 packets muxed (143004 bytes);
  Total: 150 packets (143004 bytes) muxed
[AVIOContext @ 000001e6f6d59240] Statistics: 2 seeks, 4 writeouts
[libx264 @ 000001e6f6d57100] frame I:1     Avg QP:18.13  size:131209
[libx264 @ 000001e6f6d57100] frame P:38    Avg QP:16.03  size:    87
[libx264 @ 000001e6f6d57100] frame B:111   Avg QP:24.33  size:    70
[libx264 @ 000001e6f6d57100] consecutive B-frames:  1.3%  0.0%  0.0% 98.7%
[libx264 @ 000001e6f6d57100] mb I  I16..4:  1.8% 96.0%  2.2%
[libx264 @ 000001e6f6d57100] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:99.9%
[libx264 @ 000001e6f6d57100] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%  L0:21.7% L1:78.3% BI: 0.0%
[libx264 @ 000001e6f6d57100] 8x8 transform intra:96.0% inter:98.7%
[libx264 @ 000001e6f6d57100] coded y intra: 94.7% inter: 0.0%
[libx264 @ 000001e6f6d57100] i16 v,h,dc,p: 24% 37%  5% 34%
[libx264 @ 000001e6f6d57100] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 46% 22% 11%  3%  3%  3%  4%  3%  5%
[libx264 @ 000001e6f6d57100] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 79%  9%  2%  1%  2%  1%  4%  1%  1%
[libx264 @ 000001e6f6d57100] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 000001e6f6d57100] Weighted P-Frames: Y:0.0%
[libx264 @ 000001e6f6d57100] ref P L0: 96.6%  0.7%  1.3%  1.3%
[libx264 @ 000001e6f6d57100] ref B L0: 96.9%  2.1%  1.0%
[libx264 @ 000001e6f6d57100] ref B L1: 94.8%  5.2%
[libx264 @ 000001e6f6d57100] kb/s:227.72
[AVIOContext @ 000001e6f6ccb880] Statistics: 32768 bytes read, 0 seeks

Body:
Your input image has only one component channel - luminance. Most players deal with H.264 streams containing three component channels - luminance or 'brightness' (Y) and two for chroma or 'color' (U & V). When the H.264 encoder encodes a luma-only stream, it stores it using a syntax which many players don't handle well. So, we tell ffmpeg to add chroma components which will have neutral values (since there's no color valence in the source) before sending it to the encoder. We'll add the most common form of YUV encoding - yuv420p.

So,

ffmpeg -y -loop 1 -framerate 30 -t 5 -i SplashBW.jpg -pix_fmt yuv420p Splash.mp4


问:
angular 5 - redirect the previous page after sign in
Angular 5 redirect to previous page after sign in.

When I am hitting a url manually, if it is not logged in, it will redirect
to login page but after login, it should redirect to url which entered but now I just can redirect to homepage by using this:

```<code>this.router.navigate(['/homepage']);
</code>```

Have some ideas?

答:
FOR ANGULAR 7+

Since Angular 7.2 you could use the state object to set the last url before linking to the login page:

@Component({ ... })
class SomePageComponent {
  constructor(private router: Router) {}

  checkLogin() {
    if (!this.auth.loggedIn()) {
      this.router.navigate(['login'], { state: { redirect: this.router.url } });
    }
  }
}
```

<pre class="lang-js prettyprint-override"><code>@Component({...})
class LoginComponent {
  constructor(private router: Router) {}

  backToPreviousPage() {
    const { redirect } = window.history.state;

    this.router.navigateByUrl(redirect || '/homepage');
  }
}
</code>```

Body:
Angular 5 redirect to previous page after sign in.

When I am hitting a url manually, if it is not logged in, it will redirect
to login page but after login, it should redirect to url which entered but now I just can redirect to homepage by using this:

this.router.navigate(['/homepage']);

Have some ideas?

Body:
FOR ANGULAR 7+

Since Angular 7.2 you could use the state object to set the last url before linking to the login page:

@Component({ ... })
class SomePageComponent {
  constructor(private router: Router) {}

  checkLogin() {
    if (!this.auth.loggedIn()) {
      this.router.navigate(['login'], { state: { redirect: this.router.url } });
    }
  }
}

@Component({...})
class LoginComponent {
  constructor(private router: Router) {}

  backToPreviousPage() {
    const { redirect } = window.history.state;

    this.router.navigateByUrl(redirect || '/homepage');
  }
}


问:
How to scroll recyclerView programmatically?
I have a horizontal recyclerView, When I first open the activity I want to make all the items in recyclerview scroll to the bottom (to the right in this case) and back to the top (to the left). Kinda like an animation. Scroll behavior should be visible to the user.

I tried to do it like:

```<code>Animation slideRight = AnimationUtils.loadAnimation(this, R.anim.slide_right);
        Animation slideLeft = AnimationUtils.loadAnimation(this, R.anim.slide_left);
        slideRight.setDuration(1000);
        slideLeft.setDuration(1000);
        slideRight.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                recyclerView.startAnimation(slideLeft);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        recyclerView.startAnimation(slideRight);
</code>```

anim slide left:

```<code><set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="200"
        android:fromXDelta="-100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>
</code>```

anim slide right:

```<code><translate
    android:duration="200"
    android:fromXDelta="100%"
    android:fromYDelta="0%"
    android:toXDelta="0%"
    android:toYDelta="0%" />
</code>```

it works however it just slides the recyclerview as a whole, I just want to scroll(slide) the items. How can I do this?

答:
Not working after trying other things?

This excellent piece of code worked for me

```<code>private void scrollToBottom(final RecyclerView recyclerView) {
    // scroll to last item to get the view of last item
    final LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    final RecyclerView.Adapter adapter = recyclerView.getAdapter();
    final int lastItemPosition = adapter.getItemCount() - 1;

    layoutManager.scrollToPositionWithOffset(lastItemPosition, 0);
    recyclerView.post(new Runnable() {
        @Override
        public void run() {
            // then scroll to specific offset
            View target = layoutManager.findViewByPosition(lastItemPosition);
            if (target != null) {
                int offset = recyclerView.getMeasuredHeight() - target.getMeasuredHeight();
                layoutManager.scrollToPositionWithOffset(lastItemPosition, offset);
            }
        }
    });
}
</code>```

You can modifyline, if you want to jump to some other listitem & not last

final int lastItemPosition = adapter.getItemCount() - 1;

Source

Body:
I have a horizontal recyclerView, When I first open the activity I want to make all the items in recyclerview scroll to the bottom (to the right in this case) and back to the top (to the left). Kinda like an animation. Scroll behavior should be visible to the user.

I tried to do it like:

Animation slideRight = AnimationUtils.loadAnimation(this, R.anim.slide_right);
        Animation slideLeft = AnimationUtils.loadAnimation(this, R.anim.slide_left);
        slideRight.setDuration(1000);
        slideLeft.setDuration(1000);
        slideRight.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                recyclerView.startAnimation(slideLeft);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        recyclerView.startAnimation(slideRight);

anim slide left:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="200"
        android:fromXDelta="-100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>

anim slide right:

<translate
    android:duration="200"
    android:fromXDelta="100%"
    android:fromYDelta="0%"
    android:toXDelta="0%"
    android:toYDelta="0%" />

it works however it just slides the recyclerview as a whole, I just want to scroll(slide) the items. How can I do this?

Body:
Not working after trying other things?

This excellent piece of code worked for me

private void scrollToBottom(final RecyclerView recyclerView) {
    // scroll to last item to get the view of last item
    final LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    final RecyclerView.Adapter adapter = recyclerView.getAdapter();
    final int lastItemPosition = adapter.getItemCount() - 1;

    layoutManager.scrollToPositionWithOffset(lastItemPosition, 0);
    recyclerView.post(new Runnable() {
        @Override
        public void run() {
            // then scroll to specific offset
            View target = layoutManager.findViewByPosition(lastItemPosition);
            if (target != null) {
                int offset = recyclerView.getMeasuredHeight() - target.getMeasuredHeight();
                layoutManager.scrollToPositionWithOffset(lastItemPosition, offset);
            }
        }
    });
}

You can modifyline, if you want to jump to some other listitem & not last

final int lastItemPosition = adapter.getItemCount() - 1;

Source


问:
Swift UI: Update view with random element from array
I'm trying to update a view in Swift and I can't figure out how to make it work. My app has questions, which are loaded from Core data. From there, a random question should be displayed at the top. After saving the answer (by pressing the Button with action: save), a new random question should be displayed.

```<code>struct RecordView: View {
@Environment(\.managedObjectContext) var moc

@FetchRequest(entity: Question.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Question.question, ascending: false)])
var questions: FetchedResults<Question>
var currentQuestion: String { return questions.randomElement()!.question! }

@State private var newEntryText = ""

    var body: some View {
         VStack {
            Section(header: Text(currentQuestion)){
                       TextField("New entry", text: self.$newEntryText)
                        .padding(100)

                       HStack {
                           SwiftSpeech.RecordButton().scaleEffect(0.8).swiftSpeechToggleRecordingOnTap(locale: Locale(identifier: "de"), animation: .spring(response: 0.3, dampingFraction: 0.5, blendDuration: 0))
                               .onRecognize(update: self.$newEntryText)

                        Button(action: save)
                           {
                            Image(systemName: "plus.circle.fill").foregroundColor(.green).imageScale(.large).scaleEffect(2.0)
                               }

                       }
                   }.automaticEnvironmentForSpeechRecognition()
    }
}

    func save() {
        let newEntry = Entry(context: self.moc)
             newEntry.text = self.newEntryText
             newEntry.createdAt = Date()
        do {
            try self.moc.save()
        }catch{
            print(error)
        }
        self.newEntryText = ""
        print(currentQuestion)

    }
</code>```

What I tried:

1) @State var currentQuestion: String = questions.randomElement()!.question!-> Cannot use instance member 'questions' within property initializer; property initializers run before 'self' is available. Here the problems seems to be that the questions array has to be loaded first.

2) var currentQuestion: String { return questions.randomElement()!.question! } -> Here the currentQuestion is recomputed every time it is accessed, but the View does not update. Same thing if I move the questions.randomElement()!.question! to the Text() component.

3) lazy var currentQuestion = questions.randomElement()!.question!-> Cannot use mutating getter on immutable value: 'self' is immutable (at the Text() component). The lazy part should have solved the problem I have at the 1) solution, but then I cannot use it at the Text() component.

... and some other minor variations. I'm a Swift/Swift UI Beginner, and I am running out of ideas how to update the displayed current question everytime the button is pressed. Does anyone has an idea for this?

Many thanks!

答:
Try the following (scratchy)</p>

```<code>@State var currentQuestion: String = "" // as state !!

var body: some View {
    VStack {
        Section(header: Text(currentQuestion)){

           // ... other your code here

        }.automaticEnvironmentForSpeechRecognition()
    }.onAppear {
        self.nextQuestion()    // << here !!
    }
}

...

func save() {
    // ... other your code here

   self.nextQuestion()         // << here !!
}

private func nextQuestion() {
   self.currentQuestion = questions.randomElement()?.question ?? ""
}
</code>```

Body:
I'm trying to update a view in Swift and I can't figure out how to make it work. My app has questions, which are loaded from Core data. From there, a random question should be displayed at the top. After saving the answer (by pressing the Button with action: save), a new random question should be displayed.

struct RecordView: View {
@Environment(\.managedObjectContext) var moc

@FetchRequest(entity: Question.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Question.question, ascending: false)])
var questions: FetchedResults<Question>
var currentQuestion: String { return questions.randomElement()!.question! }

@State private var newEntryText = ""

    var body: some View {
         VStack {
            Section(header: Text(currentQuestion)){
                       TextField("New entry", text: self.$newEntryText)
                        .padding(100)

                       HStack {
                           SwiftSpeech.RecordButton().scaleEffect(0.8).swiftSpeechToggleRecordingOnTap(locale: Locale(identifier: "de"), animation: .spring(response: 0.3, dampingFraction: 0.5, blendDuration: 0))
                               .onRecognize(update: self.$newEntryText)

                        Button(action: save)
                           {
                            Image(systemName: "plus.circle.fill").foregroundColor(.green).imageScale(.large).scaleEffect(2.0)
                               }

                       }
                   }.automaticEnvironmentForSpeechRecognition()
    }
}

    func save() {
        let newEntry = Entry(context: self.moc)
             newEntry.text = self.newEntryText
             newEntry.createdAt = Date()
        do {
            try self.moc.save()
        }catch{
            print(error)
        }
        self.newEntryText = ""
        print(currentQuestion)

    }

What I tried:

1) @State var currentQuestion: String = questions.randomElement()!.question!-> Cannot use instance member 'questions' within property initializer; property initializers run before 'self' is available. Here the problems seems to be that the questions array has to be loaded first.

2) var currentQuestion: String { return questions.randomElement()!.question! } -> Here the currentQuestion is recomputed every time it is accessed, but the View does not update. Same thing if I move the questions.randomElement()!.question! to the Text() component.

3) lazy var currentQuestion = questions.randomElement()!.question!-> Cannot use mutating getter on immutable value: 'self' is immutable (at the Text() component). The lazy part should have solved the problem I have at the 1) solution, but then I cannot use it at the Text() component.

... and some other minor variations. I'm a Swift/Swift UI Beginner, and I am running out of ideas how to update the displayed current question everytime the button is pressed. Does anyone has an idea for this?

Many thanks!

Body:
Try the following (scratchy)

@State var currentQuestion: String = "" // as state !!

var body: some View {
    VStack {
        Section(header: Text(currentQuestion)){

           // ... other your code here

        }.automaticEnvironmentForSpeechRecognition()
    }.onAppear {
        self.nextQuestion()    // << here !!
    }
}

...

func save() {
    // ... other your code here

   self.nextQuestion()         // << here !!
}

private func nextQuestion() {
   self.currentQuestion = questions.randomElement()?.question ?? ""
}


问:
Update\Insert data from grafana to mysql
Is is possible to update data or insert data from grafana to mysql. I have a requirement to insert/update information in mysql using a UI. Now I am already using grafana so wanted to know if there is any way we can use grafana to update or insert information</p>

答:
There is no input panel for taking user input and inserting that data to MySQL or any other. (Grafana v7.0)
For very minimalist input data you can use grafana variables as a hack.

Create example table for storing input in MySQL

```<code>CREATE TABLE `grafana_variable` (`variable` VARCHAR(64)) ENGINE = InnoDb;
</code>```

In Grafana dashboard click settings icon:

then click:

add variable:

return to dashboard and you should see at the top:

create a new visualization panel or add another query in any already existing panel and add SQL query:

```<code>INSERT INTO `grafana_variable` VALUES ('${myvar}');
</code>```

now every time you type into that field

and click away from it or use ie tab key  the data will be inserted to the MySQL database.

```<code>mysql> select * from grafana_variable;
+---------------------+
| variable            |
+---------------------+
| this is just a test |
+---------------------+
1 row in set (0.08 sec)
</code>```

The downside of this hack is that the visualization tile will have in its upper left corner error icon:

with information (when you hover over it):

Found no column named time or time_sec

because the sql query of the visualization tile is inserting data instead of selecting it from database therefore there is no time or time_sec data.
Grafana also does not handle multiple MySQL statements so you cannot repair that by adding before or after the INSERT INTO ... statement second one with SELECT FROM. Maybe this could be somehow patched by using sub queries or something similar but I did not investigate that further.

Because the error as above can be due to multiple reasons not related to the hack it will be better to use the hack query in separate visualization tile - the one that you will remember (or even give descriptive panel tile) so you know that the error there is nothing unusual.

See grafana varialbes for more info about variables.
There is also useful list of already existing variables you can use same way as myvar I created. See section MACROS here For eg:

```<code>$__timeFrom()
</code>```

and

```<code>$__timeTo()
</code>```

have the start and the end of displayed time range.

Permissions and Security

The whole hack works because the MySQL user that grafana uses is allowed to execute INSERT statement, but if grafana is able to execute ANY statement then make sure that MySQL user that grafana uses is not allowed for example to execute statements like DROP ... or any other that is not related to INSERT data into the grafana_variable table as in example.

If you use MySQL as datasource for displaying data the grafana user should also be able to execute SELECT statements.

But nothing else than that.

Read about MySQL user premissions

Body:
There is no input panel for taking user input and inserting that data to MySQL or any other. (Grafana v7.0)
For very minimalist input data you can use grafana variables as a hack.

Create example table for storing input in MySQL

CREATE TABLE `grafana_variable` (`variable` VARCHAR(64)) ENGINE = InnoDb;

In Grafana dashboard click settings icon:

then click:

add variable:

return to dashboard and you should see at the top:

create a new visualization panel or add another query in any already existing panel and add SQL query:

INSERT INTO `grafana_variable` VALUES ('${myvar}');

now every time you type into that field

and click away from it or use ie tab key  the data will be inserted to the MySQL database.

mysql> select * from grafana_variable;
+---------------------+
| variable            |
+---------------------+
| this is just a test |
+---------------------+
1 row in set (0.08 sec)

The downside of this hack is that the visualization tile will have in its upper left corner error icon:

with information (when you hover over it):

Found no column named time or time_sec

because the sql query of the visualization tile is inserting data instead of selecting it from database therefore there is no time or time_sec data.
Grafana also does not handle multiple MySQL statements so you cannot repair that by adding before or after the INSERT INTO ... statement second one with SELECT FROM. Maybe this could be somehow patched by using sub queries or something similar but I did not investigate that further.

Because the error as above can be due to multiple reasons not related to the hack it will be better to use the hack query in separate visualization tile - the one that you will remember (or even give descriptive panel tile) so you know that the error there is nothing unusual.

See grafana varialbes for more info about variables.
There is also useful list of already existing variables you can use same way as myvar I created. See section MACROS here For eg:

$__timeFrom()

and

$__timeTo()

have the start and the end of displayed time range.

Permissions and Security

The whole hack works because the MySQL user that grafana uses is allowed to execute INSERT statement, but if grafana is able to execute ANY statement then make sure that MySQL user that grafana uses is not allowed for example to execute statements like DROP ... or any other that is not related to INSERT data into the grafana_variable table as in example.

If you use MySQL as datasource for displaying data the grafana user should also be able to execute SELECT statements.

But nothing else than that.

Read about MySQL user premissions


问:
Linked List Queue in C: Exception thrown: read access violation. temp was 0x740069
I was making simple Linked list Queue program using C and i get this exception from my print function.

Exception thrown: read access violation. temp was 0x740069.

I'm still a beginner when it comes to C language so I don't getting use to managing memory and using pointers yet. So I'm not sure if the cause comes from my push function or my print function.

So i would like to ask what is the cause of this exception and how to fix it.

My code are as follow

```<code>struct node_struct {
    char *data;
    struct node_struct *next;
};

typedef struct node_struct Node;

struct queue_struct {
    Node *head, *tail;
};

typedef struct queue_struct Queue;

void push(Queue *q, char *word)
{
    // IMPLEMENT
    Node* temp = (Node*)malloc(sizeof(Node));
    temp->data = (char*)malloc(sizeof(char));
    temp->data = word;
    temp->next = NULL;
    if (q->head == NULL )
    {
        q->head= temp;
    }
    else
    {
        q->tail->next = temp;
    }
    q->tail = temp;
    q->tail->next = q->head;
}

char *pop(Queue *q)
{
    // IMPLEMENT
    Node* temp = q->head;
    char n = q->head->data;
    q->head = q->head->next;
    free(temp);
    return(n);
}

void print(Queue *q)
{
    // IMPLEMENT
    if (q == NULL)
    {
        printf("No Items\n");
    }
    else
    {
        //Node* temp = (Node*)malloc(sizeof(Node));
        Node* temp = q->head;
        while (temp != NULL)
        {
            printf("%c\n", temp->data);
            temp = temp->next;
        }
    }
}

void print(Queue *q)
{
    // IMPLEMENT
    if (q == NULL || isEmpty(q))
    {
        printf("No Items\n");
    }
    else
    {
        //Node* temp = (Node*)malloc(sizeof(Node));
        Node* temp = q->head;
        while (temp != NULL)
        {
            printf("%c\n", temp->data);
            temp = temp->next;
        }
    }
}

int isEmpty(Queue *q)
{
    // IMPLEMENT
    if (q->head == NULL)
        return 1;
    return 0;
}

void delete(Queue *q)
{
    // IMPLEMENT
    Node* temp;
    while (q->head != NULL)
    {
        temp = q->head;
        q->head = q->head->next;
        delete(temp);
    }
    q->tail = NULL;
}

int main(int argc, char **argv)
{
    Queue *q = NULL;

    // print the queue
    print(q);

    // push items
    push(&q, "a");
    push(&q, "b");
    push(&q, "c");
    print(q);
}
</code>```

And the output is in image below

Current output of my Queue

答:
There are several errors in your code. Many would have been caught if you had warnings of your compiler turned on.

In push: you want to receive a pointer to your queue. But in main you pas a double pointer. In main you also declare your queue as an empty pointer, Queue *q = NULL; so there is no queue (not even an empty queue). You can do two things:

receive the double pointer in push and allocate an empty queue that you return in the pointer;

declare the queue in main not as pointer but as an empty queue, Queue q = {0}; and now call push(&q, "a");

In push you also make an error in allocating the data.
With temp->data = (char*)malloc(sizeof(char)); you allocate only ONE char.
Then with temp->data = word;
you throw it away. You should do:

```<code>temp->data = malloc(strlen(word)+1);
strcpy(temp->data, word);
</code>```

Body:
I was making simple Linked list Queue program using C and i get this exception from my print function.

Exception thrown: read access violation. temp was 0x740069.

I'm still a beginner when it comes to C language so I don't getting use to managing memory and using pointers yet. So I'm not sure if the cause comes from my push function or my print function.

So i would like to ask what is the cause of this exception and how to fix it.

My code are as follow

struct node_struct {
    char *data;
    struct node_struct *next;
};

typedef struct node_struct Node;

struct queue_struct {
    Node *head, *tail;
};

typedef struct queue_struct Queue;

void push(Queue *q, char *word)
{
    // IMPLEMENT
    Node* temp = (Node*)malloc(sizeof(Node));
    temp->data = (char*)malloc(sizeof(char));
    temp->data = word;
    temp->next = NULL;
    if (q->head == NULL )
    {
        q->head= temp;
    }
    else
    {
        q->tail->next = temp;
    }
    q->tail = temp;
    q->tail->next = q->head;
}

char *pop(Queue *q)
{
    // IMPLEMENT
    Node* temp = q->head;
    char n = q->head->data;
    q->head = q->head->next;
    free(temp);
    return(n);
}

void print(Queue *q)
{
    // IMPLEMENT
    if (q == NULL)
    {
        printf("No Items\n");
    }
    else
    {
        //Node* temp = (Node*)malloc(sizeof(Node));
        Node* temp = q->head;
        while (temp != NULL)
        {
            printf("%c\n", temp->data);
            temp = temp->next;
        }
    }
}

void print(Queue *q)
{
    // IMPLEMENT
    if (q == NULL || isEmpty(q))
    {
        printf("No Items\n");
    }
    else
    {
        //Node* temp = (Node*)malloc(sizeof(Node));
        Node* temp = q->head;
        while (temp != NULL)
        {
            printf("%c\n", temp->data);
            temp = temp->next;
        }
    }
}

int isEmpty(Queue *q)
{
    // IMPLEMENT
    if (q->head == NULL)
        return 1;
    return 0;
}

void delete(Queue *q)
{
    // IMPLEMENT
    Node* temp;
    while (q->head != NULL)
    {
        temp = q->head;
        q->head = q->head->next;
        delete(temp);
    }
    q->tail = NULL;
}

int main(int argc, char **argv)
{
    Queue *q = NULL;

    // print the queue
    print(q);

    // push items
    push(&q, "a");
    push(&q, "b");
    push(&q, "c");
    print(q);
}

And the output is in image below

Current output of my Queue

Body:
There are several errors in your code. Many would have been caught if you had warnings of your compiler turned on.

In push: you want to receive a pointer to your queue. But in main you pas a double pointer. In main you also declare your queue as an empty pointer, Queue *q = NULL; so there is no queue (not even an empty queue). You can do two things:

receive the double pointer in push and allocate an empty queue that you return in the pointer;

declare the queue in main not as pointer but as an empty queue, Queue q = {0}; and now call push(&q, "a");

In push you also make an error in allocating the data.
With temp->data = (char*)malloc(sizeof(char)); you allocate only ONE char.
Then with temp->data = word;
you throw it away. You should do:

temp->data = malloc(strlen(word)+1);
strcpy(temp->data, word);


问:
Dereferencing char * array[] and storing in char ** array[] (C)
Edit. Sorry for the minimal information included previously

Say I have the following code:

```<code>    char ** a[16];
    a[15] = '\0';

    int i;
    for (i = 0; i < 5; i++) {

        char * b[3];
        b[2] = '\0';

        b[0] = "foo";
        b[1] = "bar";

        if (i == 4) {
            b[0] = "hello";
            b[1] = "world";
        }

        a[i] = b;
    }
</code>```

Straight after the for loop, if I include the following two lines:

```<code>printf("%s %s\n", a[0][0], a[0][1]);
printf("%s %s\n", a[4][0], a[4][1]);
</code>```

I want the output to be:

```<code>foo bar
hello world
</code>```

However it is instead:

```<code>hello world
hello world
</code>```

I am aware this is because of my declaration, a[i] = b;, where b is an array of char pointers. Each loop, the character pointers pointed to by b[0] and b[1] are changed.

In the final loop they are set to "hello" and "world" respectively. Since I assigned b to a[i], every index of a now points to the same thing.

What I would like to do is dereference b, such that a[i] is given the value b points to rather than b itself. Therefore after the loop all indexes of a are not the same.

I tried using the following but both resulted in segmentation faults:

*a[i] = *b
and
**a[i] = **b

Any help would be much appreciated, as I'm totally lost. Thank you :)

答:
What I would like to do is dereference b, such that a[i] is given the value b points to rather than b itself. Therefore after the loop all indexes of a are not the same.

Note that b itself is an array, so you cannot just assign value b points to rather than b itself because b does not point to a single value.

To really do this (not sure why you would want this) replace the line:

a[i] = b;

```<code>a[i][0] = b[0];
a[i][1] = b[1];
a[i][2] = b[2];
</code>```

Body:
Edit. Sorry for the minimal information included previously

Say I have the following code:

    char ** a[16];
    a[15] = '\0';

    int i;
    for (i = 0; i < 5; i++) {

        char * b[3];
        b[2] = '\0';

        b[0] = "foo";
        b[1] = "bar";

        if (i == 4) {
            b[0] = "hello";
            b[1] = "world";
        }

        a[i] = b;
    }

Straight after the for loop, if I include the following two lines:

printf("%s %s\n", a[0][0], a[0][1]);
printf("%s %s\n", a[4][0], a[4][1]);

I want the output to be:

foo bar
hello world

However it is instead:

hello world
hello world

I am aware this is because of my declaration, a[i] = b;, where b is an array of char pointers. Each loop, the character pointers pointed to by b[0] and b[1] are changed.

In the final loop they are set to "hello" and "world" respectively. Since I assigned b to a[i], every index of a now points to the same thing.

What I would like to do is dereference b, such that a[i] is given the value b points to rather than b itself. Therefore after the loop all indexes of a are not the same.

I tried using the following but both resulted in segmentation faults:

*a[i] = *b
and
**a[i] = **b

Any help would be much appreciated, as I'm totally lost. Thank you :)

Body:
What I would like to do is dereference b, such that a[i] is given the value b points to rather than b itself. Therefore after the loop all indexes of a are not the same.

Note that b itself is an array, so you cannot just assign value b points to rather than b itself because b does not point to a single value.

To really do this (not sure why you would want this) replace the line:

a[i] = b;

a[i][0] = b[0];
a[i][1] = b[1];
a[i][2] = b[2];


问:
Don't let a user to use same item for different select inputs
I'm developing an OTC trading interface and a request for quote interface for that with Vue.js. My goal is to don't let user use same item for two different select inputs.

Select input:

```<code><v-select
 v-model="yousendselect"
 :items="items"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>
</code>```

Select input 2:

```<code><v-select
 v-model="yougetselect"
 :items="items"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>
</code>```

Items:

```<code>items: [
 'Bitcoin',
 'Ethereum',
 'Litecoin',
 'Ripple',
],
</code>```

If an user selects Bitcoin for v-model="yousendselect", user won't be able to select Bitcoin for v-model="yougetselect".

答:
You could do something like this

```<code>computed: {
  itemsYouSend() {
    return this.item.filter(s => s !== this.yousendget)
  },
  itemsYouGet() {
    return this.item.filter(s => s !== this.yousendselect)
  }
}
</code>```

Select input:

```<code><v-select
 v-model="yousendselect"
 :items="itemsYouSend"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>

<v-select
 v-model="yougetselect"
 :items="itemsYouGet"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>
</code>```

Body:
I'm developing an OTC trading interface and a request for quote interface for that with Vue.js. My goal is to don't let user use same item for two different select inputs.

Select input:

<v-select
 v-model="yousendselect"
 :items="items"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>

Select input 2:

<v-select
 v-model="yougetselect"
 :items="items"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>

Items:

items: [
 'Bitcoin',
 'Ethereum',
 'Litecoin',
 'Ripple',
],

If an user selects Bitcoin for v-model="yousendselect", user won't be able to select Bitcoin for v-model="yougetselect".

Body:
You could do something like this

computed: {
  itemsYouSend() {
    return this.item.filter(s => s !== this.yousendget)
  },
  itemsYouGet() {
    return this.item.filter(s => s !== this.yousendselect)
  }
}

Select input:

<v-select
 v-model="yousendselect"
 :items="itemsYouSend"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>

<v-select
 v-model="yougetselect"
 :items="itemsYouGet"
 :rules="[v => !!v || 'Item is required']"
 label="You get"
 required
></v-select>


问:
SymPy: lambdify with 2-D inputs
I'm computing a square matrix V, each element of which is an integral that I compute with sympy. I compute only one definite integral V_nm, the result of which is a numerical expression with symbolic indices m and n. Say V_nm looks like this:

```<code>>>> V_nm
sin(3*n)*cos(m)
</code>```

Now I wish to make a 2-D numerical (not symbolic!) matrix out of V_nm using m and n as indices of the array. Say for a 2 x 2 matrix, the result for the given V_nm would be:

```<code>[[sin(3)cos(1) sin(3)cos(2)]
 [sin(6)cos(1) sin(6)cos(2)]]
</code>```

i.e., n specifies the column and m specifies the rows. (Note: I start m and n at 1 and not 0, but that's no concern).

How do I achieve this?

I know I can use V_nm.subs([(n, ...), (m, ...)]) in a list comprehension followed by evalf() but that's the long route. I wish to achieve this using lambdify. I know how to use lambdify for 1-D arrays. Can you please tell me how to implement it for 2-D arrays?

答:
What you're asking doesn't look like a standard functionality. But in two steps it's possible. First lambdify the expression, and then create a function that generates the intended 2D array via numpy's broadcasting:

from sympy import sin, cos, lambdify
from sympy.abc import m, n
import numpy as np

V_mn = sin(3 * n) * cos(m)

V_mn_np = lambdify((m, n), V_mn)
# using list comprehension:
# V_mn_np2D = lambda m, n: np.array([[V_mn_np(i, j) for j in range(n)] for i in range(m)])
# using numpy's broadcasting (faster for large arrays):
V_mn_np2D = lambda m, n: V_mn_np(np.arange(m)[:, None], np.arange(n))

V_mn_np2D(2, 2)
```

<p>To have the numbering start at 1 instead of 0, use <code>np.arange(1, m+1)</code> and <code>np.arange(1, n+1)</code>.</p>

<p>As a test, a function such as <code>100 * m + n</code> makes it easy to verify that the approach works as intended.</p>

<pre class="lang-py prettyprint-override"><code>W_mn = 100 * m + n

W_mn_np = lambdify((m, n), W_mn)
W_mn_np2D = lambda m, n: W_mn_np(np.arange(1, m+1)[:, None], np.arange(1, n+1))

W_mn_np2D(2, 3)
</code>```

Output:

```<code>array([[101, 102, 103],
       [201, 202, 203]])
</code>```

Title: SymPy: lambdify with 2-D inputs

Body:
I'm computing a square matrix V, each element of which is an integral that I compute with sympy. I compute only one definite integral V_nm, the result of which is a numerical expression with symbolic indices m and n. Say V_nm looks like this:

>>> V_nm
sin(3*n)*cos(m)

Now I wish to make a 2-D numerical (not symbolic!) matrix out of V_nm using m and n as indices of the array. Say for a 2 x 2 matrix, the result for the given V_nm would be:

[[sin(3)cos(1) sin(3)cos(2)]
 [sin(6)cos(1) sin(6)cos(2)]]

i.e., n specifies the column and m specifies the rows. (Note: I start m and n at 1 and not 0, but that's no concern).

How do I achieve this?

I know I can use V_nm.subs([(n, ...), (m, ...)]) in a list comprehension followed by evalf() but that's the long route. I wish to achieve this using lambdify. I know how to use lambdify for 1-D arrays. Can you please tell me how to implement it for 2-D arrays?

Body:
What you're asking doesn't look like a standard functionality. But in two steps it's possible. First lambdify the expression, and then create a function that generates the intended 2D array via numpy's broadcasting:

from sympy import sin, cos, lambdify
from sympy.abc import m, n
import numpy as np

V_mn = sin(3 * n) * cos(m)

V_mn_np = lambdify((m, n), V_mn)
# using list comprehension:
# V_mn_np2D = lambda m, n: np.array([[V_mn_np(i, j) for j in range(n)] for i in range(m)])
# using numpy's broadcasting (faster for large arrays):
V_mn_np2D = lambda m, n: V_mn_np(np.arange(m)[:, None], np.arange(n))

V_mn_np2D(2, 2)

To have the numbering start at 1 instead of 0, use np.arange(1, m+1) and np.arange(1, n+1).

As a test, a function such as 100 * m + n makes it easy to verify that the approach works as intended.

W_mn = 100 * m + n

W_mn_np = lambdify((m, n), W_mn)
W_mn_np2D = lambda m, n: W_mn_np(np.arange(1, m+1)[:, None], np.arange(1, n+1))

W_mn_np2D(2, 3)

Output:

array([[101, 102, 103],
       [201, 202, 203]])