问:
How to reflect updates in a loop?
I have a migration run. At each iteration i can update several rows. But how can i skip already updated rows? Changes inside the loop are not visible to the outside (yes I know - stable result) - but how can i change that? I want, that if a person already has a graph_id --> SKIP</p>
```<code>DROP TABLE IF EXISTS persons_2_persons, persons, graph;

CREATE TABLE graph (id SERIAL PRIMARY KEY);
CREATE TABLE persons (id SERIAL PRIMARY KEY, graph_id INTEGER REFERENCES graph(id));
CREATE TABLE persons_2_persons("from" INTEGER NOT NULL REFERENCES persons(id), "to" INTEGER NOT NULL REFERENCES persons(id));

INSERT INTO persons (graph_id) VALUES (NULL), (NULL), (NULL);

INSERT INTO persons_2_persons VALUES
(1,2),(2,1),
(2,3),(3,2);

-- Table has about 18 Mio records. 30-40 persons are connected --> goal: give each graph/cluster an graph_id
-- I also tried with CURSORs

DO $x$
DECLARE
  var_record RECORD;
  var_graph_id INTEGER;
BEGIN

    FOR var_record IN SELECT * FROM persons -- Reevaluate after each iteration
    LOOP
        IF var_record.graph_id IS NULL THEN -- this should be false at the 2nd and 3nd iteration because we updated the data in 1st iteration
          INSERT INTO graph DEFAULT VALUES RETURNING id INTO var_graph_id;
          RAISE NOTICE '%', var_graph_id;

          UPDATE persons SET graph_id = var_graph_id WHERE id IN (1,2,3); -- (1,2,3) is found by a RECURESIVE CTE. This are normally 30-40 persons

        END IF;
    END LOOP;
END;
$x$;

SELECT * FROM persons;
</code>```

答:
Make the first command in the loop refresh that individual record:</p>
```<code>select * from persons into var_record where id=var_record.id;
</code>```

Title: How to reflect updates in a loop?

Body:
I have a migration run. At each iteration i can update several rows. But how can i skip already updated rows? Changes inside the loop are not visible to the outside (yes I know - stable result) - but how can i change that? I want, that if a person already has a graph_id --> SKIP

DROP TABLE IF EXISTS persons_2_persons, persons, graph;

CREATE TABLE graph (id SERIAL PRIMARY KEY);
CREATE TABLE persons (id SERIAL PRIMARY KEY, graph_id INTEGER REFERENCES graph(id));
CREATE TABLE persons_2_persons("from" INTEGER NOT NULL REFERENCES persons(id), "to" INTEGER NOT NULL REFERENCES persons(id));

INSERT INTO persons (graph_id) VALUES (NULL), (NULL), (NULL);

INSERT INTO persons_2_persons VALUES
(1,2),(2,1),
(2,3),(3,2);

-- Table has about 18 Mio records. 30-40 persons are connected --> goal: give each graph/cluster an graph_id
-- I also tried with CURSORs

DO $x$
DECLARE
  var_record RECORD;
  var_graph_id INTEGER;
BEGIN

    FOR var_record IN SELECT * FROM persons -- Reevaluate after each iteration
    LOOP
        IF var_record.graph_id IS NULL THEN -- this should be false at the 2nd and 3nd iteration because we updated the data in 1st iteration
          INSERT INTO graph DEFAULT VALUES RETURNING id INTO var_graph_id;
          RAISE NOTICE '%', var_graph_id;

          UPDATE persons SET graph_id = var_graph_id WHERE id IN (1,2,3); -- (1,2,3) is found by a RECURESIVE CTE. This are normally 30-40 persons

        END IF;
    END LOOP;
END;
$x$;

SELECT * FROM persons;

Body:
Make the first command in the loop refresh that individual record:

select * from persons into var_record where id=var_record.id;


来源: stackexchange

问:
How to generate SOAP 1.2 Version endpoint with JAX-WS and Maven
So I am trying to consume a WSDL with SOAP version 1.2 with JAX-WS, however it will only generate version 1.1. I am using Maven to consume the WSDL. The POM file consuming of the WSDL looks as follows.

```<code>   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.10</version>

    <executions>
      <execution>
       <goals>
          <goal>wsimport</goal>
        </goals>
        <configuration>
          <wsdlFiles>
            <wsdlFile>MEAI_OnlineServices.webServices.Volubill_selfCare_04.wsdl</wsdlFile>
          </wsdlFiles>
          <bindingDirectory>${basedir}/src/wsdl</bindingDirectory>
          <extension>true</extension>
          <protocol>Xsoap1.2</protocol>
        </configuration>
      </execution>

    </executions>

  </plugin>
</code>```

The following are snippets from the WSDL

```<code>   <wsdl:definitions name="selfCare" targetNamespace="http://eaidev.mobinil.com/MEAI_OnlineServices/webServices/Volubill/selfCare"
   xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:soapjms="http://www.w3.org/2008/07/soap/bindings/JMS/"
   xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
   xmlns:tns="http://eaidev.mobinil.com/MEAI_OnlineServices/webServices/Volubill/selfC
   are" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
   xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
</code>```

Then when declaring the oeperations I have the following.

```<code>    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="deleteBucket">
  <soap12:operation soapAction="MEAI_OnlineServices_webServices_Volubill_selfCare_Binder_deleteBucket" style="document"/>
  <wsdl:input>
    <soap12:body parts="parameters" use="literal"/>
  </wsdl:input>
  <wsdl:output>
    <soap12:body parts="parameters" use="literal"/>
  </wsdl:output>
</wsdl:operation>
</code>```

I cannot manage to get this building a 1.2 version. I have 2 bindings files as follows that will prevent parts of the WSDL generating void methods instead of return methods.

jaxb-binding.xml

```<code>   <?xml version="1.0" encoding="UTF-8"?>
   <!-- Prevent any Strings being changed to a JAXBE<String> element -->
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jaxb:globalBindings generateElementProperty="false" />
</jaxb:bindings>
</code>```

And bindings.xml

```<code>  <?xml version="1.0" encoding="UTF-8"?>
   <bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="MEAI_OnlineServices.webServices.Volubill_selfCare_04.wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<!-- Disable default wrapper style -->
<enableWrapperStyle>false</enableWrapperStyle>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint binding="http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/"/>
</endpoints>
</code>```

The endpoints in the bindings class were an attempt to get it to generate SOAP 1.2 but I was met with no success.

Does anyway have an idea of how to fix this? If more code is needed just let me know. Thanks in advance.

答:
The following config worked for me:</p>
```<code>      <plugin>
            <groupId>com.helger.maven</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.6.1</version>
            <executions>
                <execution>
                    <id>periodictableaccessws</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlDirectory>src/main/resources</wsdlDirectory>
                        <wsdlFiles>
                            <wsdlFile>your_wsdl.wsdl</wsdlFile>
                        </wsdlFiles>
                        <packageName>your.target.package
                        </packageName>
                        <target>2.1</target>
                        <keep>true</keep>
                        <verbose>true</verbose>
                        <extension>true</extension>
                    </configuration>
                </execution>
            </executions>
        </plugin>
</code>```

ContentLicense: CC BY-SA 3.0

Body:
So I am trying to consume a WSDL with SOAP version 1.2 with JAX-WS, however it will only generate version 1.1. I am using Maven to consume the WSDL. The POM file consuming of the WSDL looks as follows.

   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.10</version>

    <executions>
      <execution>
       <goals>
          <goal>wsimport</goal>
        </goals>
        <configuration>
          <wsdlFiles>
            <wsdlFile>MEAI_OnlineServices.webServices.Volubill_selfCare_04.wsdl</wsdlFile>
          </wsdlFiles>
          <bindingDirectory>${basedir}/src/wsdl</bindingDirectory>
          <extension>true</extension>
          <protocol>Xsoap1.2</protocol>
        </configuration>
      </execution>

    </executions>

  </plugin>

The following are snippets from the WSDL

   <wsdl:definitions name="selfCare" targetNamespace="http://eaidev.mobinil.com/MEAI_OnlineServices/webServices/Volubill/selfCare"
   xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:soapjms="http://www.w3.org/2008/07/soap/bindings/JMS/"
   xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
   xmlns:tns="http://eaidev.mobinil.com/MEAI_OnlineServices/webServices/Volubill/selfC
   are" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
   xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">

Then when declaring the oeperations I have the following.

    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="deleteBucket">
  <soap12:operation soapAction="MEAI_OnlineServices_webServices_Volubill_selfCare_Binder_deleteBucket" style="document"/>
  <wsdl:input>
    <soap12:body parts="parameters" use="literal"/>
  </wsdl:input>
  <wsdl:output>
    <soap12:body parts="parameters" use="literal"/>
  </wsdl:output>
</wsdl:operation>

I cannot manage to get this building a 1.2 version. I have 2 bindings files as follows that will prevent parts of the WSDL generating void methods instead of return methods.

jaxb-binding.xml

   <?xml version="1.0" encoding="UTF-8"?>

<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jaxb:globalBindings generateElementProperty="false" />
</jaxb:bindings>

And bindings.xml

  <?xml version="1.0" encoding="UTF-8"?>
   <bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="MEAI_OnlineServices.webServices.Volubill_selfCare_04.wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">

<enableWrapperStyle>false</enableWrapperStyle>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint binding="http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/"/>
</endpoints>

The endpoints in the bindings class were an attempt to get it to generate SOAP 1.2 but I was met with no success.

Does anyway have an idea of how to fix this? If more code is needed just let me know. Thanks in advance.

Body:
The following config worked for me:

      <plugin>
            <groupId>com.helger.maven</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.6.1</version>
            <executions>
                <execution>
                    <id>periodictableaccessws</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlDirectory>src/main/resources</wsdlDirectory>
                        <wsdlFiles>
                            <wsdlFile>your_wsdl.wsdl</wsdlFile>
                        </wsdlFiles>
                        <packageName>your.target.package
                        </packageName>
                        <target>2.1</target>
                        <keep>true</keep>
                        <verbose>true</verbose>
                        <extension>true</extension>
                    </configuration>
                </execution>
            </executions>
        </plugin>

ContentLicense: CC BY-SA 4.0


问:
Kafka, change broker ip without changing broker id
I have a 8 node kafka cluster (broker.id range 1 to 8) on AWS ec2 instances distributed among 2 AZs (1a and 1b). In order to have multi AZ cluster, I need to migrate 4 brokers into remaining two AZs (1c and 1d).

If I create a new ec2 instance in 1c, I will definitely get a new ip address.
My question here is, Can I use same broker.id for the new node after removing older node which had same broker.id

Example :
broker.id = 1, IP = 1.1.1.1, AZ = 1a

Now, I want to move this node to 1c, so I stop broker service on (1.1.1.1) and spin up a new node in 1c with an empty disk

broker.id = 1, IP = 2.2.2.2, AZ = 1c

Now, I will just start the broker service on new node. Will this create any issues in kafka cluster, since we are changing the node without changing the broker.id?

答:
There is a generated meta.properties file on the broker that holds a clusterId, which might cause you to run into issues.

Otherwise, the old broker information is still maintained in Zookeeper for partition replicas, and without also moving the topic data, then replication will need to happen after the new broker starts correctly (e.g. the inter-broker listeners are configured to communicate across regions)

The safer approach would be to use kafka-reassign-partitions tool to move partitions off the brokers you want to migrate to a broker with another ID, then shutdown and install new servers with a new ID, then run the tool again to move the partitions back to those new IDs.


问:
Socialite not reconize
i have tried everythings i found online but nothing seems to work.. Here is my problem: I tried to implement authentification with google in laravel using socialite but i have follewed thoses steps describes: here

here is my composer.json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "jeroennoten/laravel-adminlte": "^3.7",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/socialite": "^5.5",
        "laravel/tinker": "^2.5",
        "laravel/ui": "^3.4"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}```
</div>
</div>

here is my file config/app.php:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>    'providers' => [
//...
        Laravel\Socialite\SocialiteServiceProvider::class,
//...

    ],</code>```

 'aliases' => [

//..
        'Socialite' => Laravel\Socialite\Facades\Socialite::class,
      //...

    ],```
</div>
</div>
</p>
<p>here is my controller, that's where i get my error, on this line "Socialite::driver($provider)->redirect()":</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Socialite;

class SocialiteController extends Controller
{
    protected $providers = ["google"];
    public function loginRegister(){
        return view ("socialite.login-register");
    }

    public function redirect (Request $rq){
        $provider = $rq->provider;
        if(in_array($provider,$this->providers)){
            return Socialite::driver($provider)->redirect();
        }
    }
}</code>```

here is a screenshoot of the error:

laravel doesn't find anywhere the facade socialite even when i tried to import it manually like that =>"Laravel\Socialite\Facades\Socialite" ..
i tried to download again the package and  tried also some cmd like composer dump-autoload.., to try regenerates the list of all classes that need to be included in the project but it' won't work. Thanks in advance for any advices and help.

答:
As the error says, it does not find the package Socialite.
Try to add the use of the package at the beginning of your controller:</p>
```<code>use Laravel\Socialite\Facades\Socialite;
</code>```

Title: Socialite not reconize

Body:
i have tried everythings i found online but nothing seems to work.. Here is my problem: I tried to implement authentification with google in laravel using socialite but i have follewed thoses steps describes: here

here is my composer.json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "jeroennoten/laravel-adminlte": "^3.7",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/socialite": "^5.5",
        "laravel/tinker": "^2.5",
        "laravel/ui": "^3.4"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

here is my file config/app.php:

    'providers' => [
//...
        Laravel\Socialite\SocialiteServiceProvider::class,
//...

    ],

 'aliases' => [

//..
        'Socialite' => Laravel\Socialite\Facades\Socialite::class,
      //...

    ],

here is my controller, that's where i get my error, on this line "Socialite::driver($provider)->redirect()":

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Socialite;

class SocialiteController extends Controller
{
    protected $providers = ["google"];
    public function loginRegister(){
        return view ("socialite.login-register");
    }

    public function redirect (Request $rq){
        $provider = $rq->provider;
        if(in_array($provider,$this->providers)){
            return Socialite::driver($provider)->redirect();
        }
    }
}

here is a screenshoot of the error:

laravel doesn't find anywhere the facade socialite even when i tried to import it manually like that =>"Laravel\Socialite\Facades\Socialite" ..
i tried to download again the package and  tried also some cmd like composer dump-autoload.., to try regenerates the list of all classes that need to be included in the project but it' won't work. Thanks in advance for any advices and help.

Body:
As the error says, it does not find the package Socialite.
Try to add the use of the package at the beginning of your controller:

use Laravel\Socialite\Facades\Socialite;


问:
When boto3 downloads an encrypted S3 object, does the object get decrypted as well?
```<code> s3.Bucket(bucket_name).download_file(key, destination)
</code>```

I use the above boto3 code to download an S3 object.

The object on S3 that I'm trying to download using the code above is encrypted using KMS encryption.

Will download_file decrypt the object as well while it downloads the same?

答:
If it is using S3 server side encryption, then yes S3 will decrypt it and you download a decrypted file. The download will happen over SSL/TLS so it will be protected by encryption in transit. Note that the IAM role performing the download will need to have decrypt permission on the KMS key as well.

If the file was encrypted using client side encryption, then you would have to decrypt it after download.

Body:
 s3.Bucket(bucket_name).download_file(key, destination)

I use the above boto3 code to download an S3 object.

The object on S3 that I'm trying to download using the code above is encrypted using KMS encryption.

Will download_file decrypt the object as well while it downloads the same?


问:
Accessibility: Can I add content between a label and its associated input?
I have a  associated with an <input> (for="inputID").

Would I have an accessibility problem if, for example, I added a link between  and <input> ?

Example:

    Label
    Link
    <input id="input-1" type="text" placeholder="Placeholder">

```

Thanks.

答:
It's not a technical WCAG (accessibility) failure.  You have the label associated with the <input> by using the for attribute.  This allows the label to be announced when a screen reader user tabs to the input field, so that's great.  It also allows mouse user to click on the label text and have the focus automatically move to the input field.

However, it's a little odd to have a link between the two.  A similar layout is somewhat common for checkboxes (not input fields), especially with "agree to terms and conditions" type of checkboxes.  The "terms" is often a link contained within the label whereas in your example, the link is outside the label.

```<code><input type="checkbox" id="mycheck">
<label for="mycheck">Agree to <a href="terms.html">terms and conditions</a></label>
</code>```

Similar to your example, a screen reader user will hear the label when they tab to the checkbox ("agree to terms and conditions, checkbox, unchecked").  If they tab again, they'll hear "terms and conditions, link".  If they click on the non-link part of the label, the checkbox will toggle.  If they click on the link part of the label, the link will navigate to the "terms" page and the checkbox will not toggle.  It's a little funky but doesn't fail WCAG.

So back to your example, should the link be part of the label or should it be outside the label?  Either way it's not an accessibility failure.  You have to decide which behavior you want.  If you need the link to be announced as part of the input field's label then the link should be embedded in the label (a child element of the ).

Body:
I have a  associated with an <input> (for="inputID").

Would I have an accessibility problem if, for example, I added a link between  and <input> ?

Example:

    Label
    Link
    <input id="input-1" type="text" placeholder="Placeholder">

Thanks.

Body:
It's not a technical WCAG (accessibility) failure.  You have the label associated with the <input> by using the for attribute.  This allows the label to be announced when a screen reader user tabs to the input field, so that's great.  It also allows mouse user to click on the label text and have the focus automatically move to the input field.

However, it's a little odd to have a link between the two.  A similar layout is somewhat common for checkboxes (not input fields), especially with "agree to terms and conditions" type of checkboxes.  The "terms" is often a link contained within the label whereas in your example, the link is outside the label.

<input type="checkbox" id="mycheck">
<label for="mycheck">Agree to <a href="terms.html">terms and conditions</a></label>

Similar to your example, a screen reader user will hear the label when they tab to the checkbox ("agree to terms and conditions, checkbox, unchecked").  If they tab again, they'll hear "terms and conditions, link".  If they click on the non-link part of the label, the checkbox will toggle.  If they click on the link part of the label, the link will navigate to the "terms" page and the checkbox will not toggle.  It's a little funky but doesn't fail WCAG.

So back to your example, should the link be part of the label or should it be outside the label?  Either way it's not an accessibility failure.  You have to decide which behavior you want.  If you need the link to be announced as part of the input field's label then the link should be embedded in the label (a child element of the <label>).


问:
Adb daemon doesn't start automatically
Since upgrading to Android Studio Bumblebee, the adb demon doesn't start automatically when launching AS. I have to manually start it with adb start-server every time I launch AS in order to run/debug projects. That wasn't the case before the upgrade.

The setting is set to automatically start:

Is there a way to start it automatically when launching Android Studio?

答:
I don't know a way too but i helped me with a simple batch file.
The code of this file is:

C:\Users\ 'user'\AppData\Local\Android\Sdk\platform-tools\adb.exe start-server

start /d "C:\Program Files\Android\Android Studio\bin" studio64.exe

Of course you have to look if the path is the same on your computer.
If you save this code in a txt-file and change the ending from ".txt" to ".bat" it should work. At least it does at my computer.

I hope that could help because in my case it works now... Isn't a quite beautiful solution but at least it works.

Title: Adb daemon doesn't start automatically


问:
How to use boost tests with SFML and cmake?
I'm writing a simple game in C++ with use of SFML. I want to use boost tests, but when i try to i get undefined reference in every place i use SFML features (the game itself works fine, it's just the test that don't). Sample test:

```<code>#include <boost/test/unit_test.hpp>
#include "Sentry.h"

BOOST_AUTO_TEST_SUITE(BasicModelTestSuite)

BOOST_AUTO_TEST_CASE(testLamp_10BulbsWithPower10_ExpectedPower)
    {
        sf::Texture projectileTexture;
        sf::Texture sentryTexture;
        std::vector<std::shared_ptr<Sentry>> foes;
        sentryTexture.loadFromFile("../GameResources/sentry_image.png");
        projectileTexture.loadFromFile("../GameResources/projectile_animation.png");
        foes.push_back(std::make_shared<Sentry>(Sentry(&sentryTexture, sf::Vector2u(1,2), 0.2f, sf::Vector2f(140,200), projectileTexture, true)));
        foes.push_back(std::make_shared<Sentry>(Sentry(&sentryTexture, sf::Vector2u(1,2), 0.2f, sf::Vector2f(200,200), projectileTexture, false)));
        BOOST_REQUIRE_EQUAL(foes.size(), 2);
    }

BOOST_AUTO_TEST_SUITE_END()
</code>```

And the test portion of cmakelist.txt:

```<code>ind_package(Boost 1.65 COMPONENTS "unit_test_framework" REQUIRED)

include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${Boost_INCLUDE_DIRS}
)

set(SOURCE_TEST_FILES
        test/master.cpp test/master.cpp test/baseTest.cpp
        main.cpp src/Level.cpp include/Level.h src/Game.cpp include/Game.h src/Platform.cpp include/Platform.h src/Item.cpp include/Item.h src/Life.cpp include/Life.h src/Coin.cpp include/Coin.h src/Collider.cpp include/Collider.h src/Enemy.cpp include/Enemy.h src/MrStrawberry.cpp include/MrStrawberry.h src/Animation.cpp include/Animation.h src/MrBerry.cpp include/MrBerry.h src/Projectile.cpp include/Projectile.h src/Sentry.cpp include/Sentry.h)

add_executable(TestProject ${SOURCE_TEST_FILES})

target_include_directories(TestProject PUBLIC include)

target_link_libraries(TestProject
        ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

enable_testing()

add_test(NAME Test COMMAND TestProject
        --report_level=detailed
        --log_level=all
        --color_output=yes)

add_custom_target(check ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 BOOST_TEST_LOG_LEVEL=all
        ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> --verbose
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
</code>```

I have no clue why it throws undefined reference to everything, like this:

```<code>/usr/bin/ld: /home/student/CLionProjects/oop21_ww2_14/BerryGame/src/Projectile.cpp:8: undefined reference to `sf::RectangleShape::setSize(sf::Vector2<float> const&)'
/usr/bin/ld: /home/student/CLionProjects/oop21_ww2_14/BerryGame/src/Projectile.cpp:9: undefined reference to `sf::Shape::setTexture(sf::Texture const*, bool)'
</code>```

答:
TestProject is missing the SFML library in the link options (see also What is an undefined reference/unresolved external symbol error and how do I fix it?). Your main executable apparently does have it, but you don't show it.

Look for something like

```<code> LINK_LIBRARIES(sfml-system sfml-window sfml-graphics sfml-audio)
</code>```

Or target_link_libraries instead. If LINK_LIBRARIES is used, I suppose the target might need to be defined after that point.

Body:
I'm writing a simple game in C++ with use of SFML. I want to use boost tests, but when i try to i get undefined reference in every place i use SFML features (the game itself works fine, it's just the test that don't). Sample test:

#include <boost/test/unit_test.hpp>
#include "Sentry.h"

BOOST_AUTO_TEST_SUITE(BasicModelTestSuite)

BOOST_AUTO_TEST_CASE(testLamp_10BulbsWithPower10_ExpectedPower)
    {
        sf::Texture projectileTexture;
        sf::Texture sentryTexture;
        std::vector<std::shared_ptr<Sentry>> foes;
        sentryTexture.loadFromFile("../GameResources/sentry_image.png");
        projectileTexture.loadFromFile("../GameResources/projectile_animation.png");
        foes.push_back(std::make_shared<Sentry>(Sentry(&sentryTexture, sf::Vector2u(1,2), 0.2f, sf::Vector2f(140,200), projectileTexture, true)));
        foes.push_back(std::make_shared<Sentry>(Sentry(&sentryTexture, sf::Vector2u(1,2), 0.2f, sf::Vector2f(200,200), projectileTexture, false)));
        BOOST_REQUIRE_EQUAL(foes.size(), 2);
    }

BOOST_AUTO_TEST_SUITE_END()

And the test portion of cmakelist.txt:

ind_package(Boost 1.65 COMPONENTS "unit_test_framework" REQUIRED)

include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${Boost_INCLUDE_DIRS}
)

set(SOURCE_TEST_FILES
        test/master.cpp test/master.cpp test/baseTest.cpp
        main.cpp src/Level.cpp include/Level.h src/Game.cpp include/Game.h src/Platform.cpp include/Platform.h src/Item.cpp include/Item.h src/Life.cpp include/Life.h src/Coin.cpp include/Coin.h src/Collider.cpp include/Collider.h src/Enemy.cpp include/Enemy.h src/MrStrawberry.cpp include/MrStrawberry.h src/Animation.cpp include/Animation.h src/MrBerry.cpp include/MrBerry.h src/Projectile.cpp include/Projectile.h src/Sentry.cpp include/Sentry.h)

add_executable(TestProject ${SOURCE_TEST_FILES})

target_include_directories(TestProject PUBLIC include)

target_link_libraries(TestProject
        ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

enable_testing()

add_test(NAME Test COMMAND TestProject
        --report_level=detailed
        --log_level=all
        --color_output=yes)

add_custom_target(check ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 BOOST_TEST_LOG_LEVEL=all
        ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> --verbose
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

I have no clue why it throws undefined reference to everything, like this:

/usr/bin/ld: /home/student/CLionProjects/oop21_ww2_14/BerryGame/src/Projectile.cpp:8: undefined reference to `sf::RectangleShape::setSize(sf::Vector2<float> const&)'
/usr/bin/ld: /home/student/CLionProjects/oop21_ww2_14/BerryGame/src/Projectile.cpp:9: undefined reference to `sf::Shape::setTexture(sf::Texture const*, bool)'

Body:
TestProject is missing the SFML library in the link options (see also What is an undefined reference/unresolved external symbol error and how do I fix it?). Your main executable apparently does have it, but you don't show it.

Look for something like

 LINK_LIBRARIES(sfml-system sfml-window sfml-graphics sfml-audio)

Or target_link_libraries instead. If LINK_LIBRARIES is used, I suppose the target might need to be defined after that point.


问:
"You may need an additional loader to handle the result of these loaders."
I am currently trying to build a State Management Library for ReactJs. But as soon as I implement it into my React project (created with create-react-app), it starts dropping this error:

Failed to compile.

path/to/agile/dist/runtime.js 116:104
Module parse failed: Unexpected token (116:104)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|       if (subscriptionContainer instanceof sub_1.CallbackContainer) subscriptionContainer.callback(); // If Component based subscription call the updateMethod which every framework has to define
|
>       if (subscriptionContainer instanceof sub_1.ComponentContainer) if (this.agileInstance.integration?.updateMethod) this.agileInstance.integration?.updateMethod(subscriptionContainer.component, Runtime.formatChangedPropKeys(subscriptionContainer));
|     }); // Log Job
|
```
<p>If I comment out the highlighted lines of code  mentioned in the error, it jumps to another point and complains there. But it can't be a syntax error because then TypeScript would complain in the IDE, too.</p>
<p><strong>How the tool works:</strong>
At the start you have to define a framework, in this case React. Then you can create a State and subscribe this State to a React Functional Component via a Hook.
The Hook used to bind the State to the React Component simply creates a callback which triggers a re-render (via mutating a <code>useReducer</code>) and assigns this callback to the subscribed State.</p>
<p>If you want to know more checkout this repo:
https://github.com/agile-ts/agile</p>
<p><strong>Dependencies:</strong></p>
<p>Third Party State Management library:</p>
```  "dependencies": {
    "@types/chai": "^4.2.12",
    "@types/mocha": "^8.0.2",
    "chai": "^4.2.0",
    "eslint-config-prettier": "^6.11.0",
    "mocha": "^8.1.1",
    "prettier": "2.0.5",
    "ts-node": "^8.10.2",
    "tsc-watch": "^4.1.0",
    "tslib": "^2.0.0",
    "typescript": "^3.9.7"
  }
```
<ul>
<li>Node: <code>v14.8.0</code></li>
</ul>
<p>React Project:</p>
```"dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3",
    "typescript": "~3.7.2",
    "agile-framework": "file:../../"
  },
```

React: 16.13.1

NPM: 6.14.7

答:
In case you are not the author of the library, or you don't want to change it as the accepted answer suggests, you can do as follows:

change browserslist as @adlerer suggests:

```<code>"browserslist": [
  ">0.2%",
  "not dead",
  "not op_mini all"
],
</code>```

(make sure you don't have special config for development in browserslist)

clear npm cache:

```<code>npm cache clean --force
</code>```

reinstall things like @Gel suggests:

```<code>rm -rf node_modules && rm -f package-lock.json && npm i
</code>```

This is what helped me after hours of research and trials.

Body:
I am currently trying to build a State Management Library for ReactJs. But as soon as I implement it into my React project (created with create-react-app), it starts dropping this error:

Failed to compile.

path/to/agile/dist/runtime.js 116:104
Module parse failed: Unexpected token (116:104)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|       if (subscriptionContainer instanceof sub_1.CallbackContainer) subscriptionContainer.callback(); // If Component based subscription call the updateMethod which every framework has to define
|
>       if (subscriptionContainer instanceof sub_1.ComponentContainer) if (this.agileInstance.integration?.updateMethod) this.agileInstance.integration?.updateMethod(subscriptionContainer.component, Runtime.formatChangedPropKeys(subscriptionContainer));
|     }); // Log Job
|

If I comment out the highlighted lines of code  mentioned in the error, it jumps to another point and complains there. But it can't be a syntax error because then TypeScript would complain in the IDE, too.

How the tool works:
At the start you have to define a framework, in this case React. Then you can create a State and subscribe this State to a React Functional Component via a Hook.
The Hook used to bind the State to the React Component simply creates a callback which triggers a re-render (via mutating a useReducer) and assigns this callback to the subscribed State.

If you want to know more checkout this repo:
https://github.com/agile-ts/agile

Dependencies:

Third Party State Management library:

  "dependencies": {
    "@types/chai": "^4.2.12",
    "@types/mocha": "^8.0.2",
    "chai": "^4.2.0",
    "eslint-config-prettier": "^6.11.0",
    "mocha": "^8.1.1",
    "prettier": "2.0.5",
    "ts-node": "^8.10.2",
    "tsc-watch": "^4.1.0",
    "tslib": "^2.0.0",
    "typescript": "^3.9.7"
  }

Node: v14.8.0

React Project:

"dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3",
    "typescript": "~3.7.2",
    "agile-framework": "file:../../"
  },

React: 16.13.1

NPM: 6.14.7

Body:
In case you are not the author of the library, or you don't want to change it as the accepted answer suggests, you can do as follows:

change browserslist as @adlerer suggests:

"browserslist": [
  ">0.2%",
  "not dead",
  "not op_mini all"
],

(make sure you don't have special config for development in browserslist)

clear npm cache:

npm cache clean --force

reinstall things like @Gel suggests:

rm -rf node_modules && rm -f package-lock.json && npm i

This is what helped me after hours of research and trials.


问:
how do I insert unicode characters into mysql with an insert statement?
I'm doing this directly in the mysql client.  I want to do the following:

```<code>INSERT INTO MYTABLE VALUES(1,12,'\u5c40\u5c42');
</code>```

So it would insert the two unicode characters.  I'd like to do this without using some other programming language if possible, I'd like to just paste my insert statements right into mysql client.

答:
In my case, I needed to insert Arabic characters into MySql server through C# form application. The only way that worked for me is as follows:

First: In your code, specify character set in the connection string as follows:

```<code>MySqlConnection mysqlConn = new MySqlConnection("Server= serverName; Port=3306; Database= dbName;  Uid = userName; Pwd=password; charset=utf8");
</code>```

Second: In phpMyAdmin console, click on your database name link, then head to "operations" tab and go to "Collation" at the bottom and select "utf8_unicode_ci" and check the options below and finally click on "Go"

Steps here

Body:
I'm doing this directly in the mysql client.  I want to do the following:

INSERT INTO MYTABLE VALUES(1,12,'\u5c40\u5c42');

So it would insert the two unicode characters.  I'd like to do this without using some other programming language if possible, I'd like to just paste my insert statements right into mysql client.

Body:
In my case, I needed to insert Arabic characters into MySql server through C# form application. The only way that worked for me is as follows:

First: In your code, specify character set in the connection string as follows:

MySqlConnection mysqlConn = new MySqlConnection("Server= serverName; Port=3306; Database= dbName;  Uid = userName; Pwd=password; charset=utf8");

Second: In phpMyAdmin console, click on your database name link, then head to "operations" tab and go to "Collation" at the bottom and select "utf8_unicode_ci" and check the options below and finally click on "Go"

Steps here


问:
Get profile problems
I've created the FB application on sandbox mode.
I use C# SDK
i'm tring to get current user profile on server side like

```<code>var me = api.Get("/me");
</code>```

for all users who used my application i got my own profile not them. Why is it happening ?
How to get current user profile for user on server side ?

Thanks.

答: me is a special Facebook graph identifier that refers to the currently logged in and connected user. If you are logged in and triggering var me = api.Get("/me"); then the var me will contain a JSONObject with your user data. If you want to get another users data you'll need to store their user ids and use them to get the information you want - you'll probably need the offline access extended permission. Assuming you have adequate permissions, you can get other user data using var user = api.Get("/OTHER_USERS_ID");

Title: Get profile problems

Body:
I've created the FB application on sandbox mode.
I use C# SDK
i'm tring to get current user profile on server side like

var me = api.Get("/me");

for all users who used my application i got my own profile not them. Why is it happening ?
How to get current user profile for user on server side ?

Thanks.


问:
The argument type 'void Function(int)' can't be assigned to the parameter type 'void Function(int?)?'
Hello for all I have problem so I want to best solution for this code
enter image description here

It shows The argument type

'void Function(int)' can't be assigned to the parameter type 'void Function(int?)?'.

答:
Update:

```<code>(int newColor) {...}
</code>```

to

```<code>(int? newColor) {...}
</code>```

Body:
Update:

(int newColor) {...}

to

(int? newColor) {...}


问:
Best C++ RPC library for Windows/Visual Studio
I know this kind of question is asked a lot but I have a set of requirements:
1. Be able to compile and develop in Visual Studio on Windows.
2. Be somewhat modern - Async/threaded, clean.
3. C++

I've looked at thrift, messagepack, and even protobuf+RPC. All of them have massive issues in Windows.

FYI - I'm no pro programmer so asking me to apply out-dated patches to untested code is a pretty big ask. I know thrift has some patches available, but their >2MB big for old versions of thrift, with other patches thrown on top. God knows how well that'll work.

答: Did you consider using Protobuf together with Boost asio? Of course it is not an RPC library, so that part you would have to do at your own, but it would be asynchronous and fast.</p>


问:
Group together individuals based on commonalities(direct or indirect) in two other columns for 7.5 million dataset in python
I have a dataframe which contains

```<code>cust_id|phone|email
1   678   a
2   NaN   c
3   987   b
4   456   NaN
5   NaN   d
7   456   c
</code>```

All the cust_ids with either matching phone or email are directly related.eg.cust_id 1 is directly related to 2 and 2 is directly related to 3.

Cust_id 1 is indirectly related to 3- they don't have same phone or email but are related through 2.

I want to club and give a unique number to a group which is directly related or is indirectly related

Desired output:

```<code>Cust_id|phone|email | group_no
1     678   a   1
2     NaN   c   2
3     987   b   3
4     456   NaN 2
5     NaN   d   4
7     456   c   2
</code>```

Obtained output:

```<code>Cust_id|phone|email | group_no

1     678   a    1
2     NaN   c    2
3     987   b    3
4     456   NaN  2
5     NaN   d    2
7     456   c    2
</code>```

how do i do this for a dataset that has 7.5 million rows without compromising on speed.

I used the following code in the picture.

答:
This looks like the perfect case for using a graph database. If you are interested in that, download Neo4j desktop and we will take it from there. You could google

neo4j-admin bulk import tool

With your database size, I expect it will take about 1 min.

Body:
I have a dataframe which contains

cust_id|phone|email
1   678   a
2   NaN   c
3   987   b
4   456   NaN
5   NaN   d
7   456   c

All the cust_ids with either matching phone or email are directly related.eg.cust_id 1 is directly related to 2 and 2 is directly related to 3.

Cust_id 1 is indirectly related to 3- they don't have same phone or email but are related through 2.

I want to club and give a unique number to a group which is directly related or is indirectly related

Desired output:

Cust_id|phone|email | group_no
1     678   a   1
2     NaN   c   2
3     987   b   3
4     456   NaN 2
5     NaN   d   4
7     456   c   2

Obtained output:

Cust_id|phone|email | group_no

1     678   a    1
2     NaN   c    2
3     987   b    3
4     456   NaN  2
5     NaN   d    2
7     456   c    2

how do i do this for a dataset that has 7.5 million rows without compromising on speed.

I used the following code in the picture.


问:
How to check which Tensorflow version is compatible to Tensorflow Model Garden?
In order to use a pre-trained model with Tensorflow, we clone the Model Garden for TensorFlow, then choose a model in Model Zoo, for example, Detection Model Zoo: EfficientDet D0 512x512.

Is there anyway to detect the right version of Tensorflow, e.g. 2.7.0, or 2.7.1, or 2.8.0, that will surely work with the aforementioned setup?

The documentation (README.md) doesn't seem to mention this requirement. Maybe it is implied somehow?

I checked setup.py for Object Detection, but there is still no clue!

```<code>\models\research\object_detection\packages\tf2\setup.py
</code>```
```<code>REQUIRED_PACKAGES = [
    # Required for apache-beam with PY3
    'avro-python3',
    'apache-beam',
    'pillow',
    'lxml',
    'matplotlib',
    'Cython',
    'contextlib2',
    'tf-slim',
    'six',
    'pycocotools',
    'lvis',
    'scipy',
    'pandas',
    'tf-models-official>=2.5.1',
    'tensorflow_io',
    'keras'
]
</code>```

答:
I am not aware of a formal/quick way to determine the right Tensorflow version, given a specific Model Garden version, master branch. However, here is my workaround:

In the REQUIRED_PACKAGES above, we see tf-models-official>=2.5.1.

Checking the package history on pypi.org, the latest version, as of 03.02.2022, is 2.8.0.

So when installing this \models\research\object_detection\packages\tf2\setup.py file, pip will naturally fetch the latest version of tf-models-official, which is 2.8.0, thanks to >= symbol.

However, given tf-models-official, v2.8.0, its required packages are defined in tf-models-official-2.8.0\tf_models_official.egg-info\requires.txt (Note: download the package and extract it, using the link.)

Here, we find out:

```<code>tensorflow~=2.8.0
</code>```

...meaning the required Tensorflow version is 2.8.*.

This may not be desired, e.g. in CoLab, currently, the version is 2.7.0.

To workaround, we should use tf-models-official, v2.7.0. Notice it matches the Tensorflow version. In this version 2.7.0's requires.txt, we should see tensorflow>=2.4.0, which is already satisfied by CoLab's default Tensorflow version (2.7.0).

To make this workaround possible, the \models\research\object_detection\packages\tf2\setup.py should be modified from, e.g. 'tf-models-official>=2.5.1' to 'tf-models-official==2.7.0'.

Caveat: I think this hack doesn't affect the functionality of the Object Detection API because it originally demands any tf-models-official >= 2.5.1. We just simply fix it to ==2.7.0 instead.

Body:
In order to use a pre-trained model with Tensorflow, we clone the Model Garden for TensorFlow, then choose a model in Model Zoo, for example, Detection Model Zoo: EfficientDet D0 512x512.

Is there anyway to detect the right version of Tensorflow, e.g. 2.7.0, or 2.7.1, or 2.8.0, that will surely work with the aforementioned setup?

The documentation (README.md) doesn't seem to mention this requirement. Maybe it is implied somehow?

I checked setup.py for Object Detection, but there is still no clue!

\models\research\object_detection\packages\tf2\setup.py

REQUIRED_PACKAGES = [
    # Required for apache-beam with PY3
    'avro-python3',
    'apache-beam',
    'pillow',
    'lxml',
    'matplotlib',
    'Cython',
    'contextlib2',
    'tf-slim',
    'six',
    'pycocotools',
    'lvis',
    'scipy',
    'pandas',
    'tf-models-official>=2.5.1',
    'tensorflow_io',
    'keras'
]

Body:
I am not aware of a formal/quick way to determine the right Tensorflow version, given a specific Model Garden version, master branch. However, here is my workaround:

In the REQUIRED_PACKAGES above, we see tf-models-official>=2.5.1.

Checking the package history on pypi.org, the latest version, as of 03.02.2022, is 2.8.0.

So when installing this \models\research\object_detection\packages\tf2\setup.py file, pip will naturally fetch the latest version of tf-models-official, which is 2.8.0, thanks to >= symbol.

However, given tf-models-official, v2.8.0, its required packages are defined in tf-models-official-2.8.0\tf_models_official.egg-info\requires.txt (Note: download the package and extract it, using the link.)

Here, we find out:

tensorflow~=2.8.0

...meaning the required Tensorflow version is 2.8.*.

This may not be desired, e.g. in CoLab, currently, the version is 2.7.0.

To workaround, we should use tf-models-official, v2.7.0. Notice it matches the Tensorflow version. In this version 2.7.0's requires.txt, we should see tensorflow>=2.4.0, which is already satisfied by CoLab's default Tensorflow version (2.7.0).

To make this workaround possible, the \models\research\object_detection\packages\tf2\setup.py should be modified from, e.g. 'tf-models-official>=2.5.1' to 'tf-models-official==2.7.0'.

Caveat: I think this hack doesn't affect the functionality of the Object Detection API because it originally demands any tf-models-official >= 2.5.1. We just simply fix it to ==2.7.0 instead.


问:
updateCheckboxGroupInput behaves differently depending on previous added/deleted updateRadioButtons
In short, the issue I have is the following: Depending on whether I update or leave empty Radio buttons "previously" shown to users of my Shiny App, the CheckboxGroup will update correctly or not.
I added a reproducible example below.

My goal is to allow our research assistants to enter data for specific parties. We have the data set stored in the background, and it might be that RAs have already started working on some of the parties. So they can, at first, choose the country, the party and indicate whether they have already worked on the party previously. In the latter case, their previous codings shall be updated and shown on the "next pages". What is shown on the "next pages" (hiding and showing parts of the shiny app) in our online version is shown below the vertical line.

However, the following issue puzzles me to great extent: When ignoring the lines 69-71 as it is now done, the CheckboxGroupInput behaves as expected; once all relevant meta data is selected, it shows a list of ethnic groups to choose from for the respective country chosen. If RAs have already started coding these parties, the previously selected choices are again selected. But, of course, the previously added data for religious claims are not shown, because they are not (yet) updated.

When I run all lines, including lines 69-71, the Shiny App updates the information on the religious claims correctly, but only shows all possible choices for ethnic groups per country if and only if the party data is sub-setted to the ones previously coded. If RAs choose "No" and then any combination of party ids and countries, they only see the choice selections "Other..." and "Don't know". However, if they choose "Yes" and any combination of party ids and countries, they do get the full list of ethnic groups plus their previous entered data.

Obviously, I would like my app to update both the religious claims and the ethnic groups selection, irrespective of any of the selections made regarding previously coded data, party id and country.

```<code>library(shiny)
library(dplyr)
library(stringr)

party_data <- data.frame(country_name=c("Austria","Austria","Belgium","Belgium","Austria","Austria","Belgium","Belgium"),
                         party_id=c(100,101,100,101,100,101,100,101),
                         rel_claim_flag=c(rep(NA,4), rep("Yes",4)),
                         eth_base_group=c(rep(NA,4), rep("Germans|Czech",2), rep("French|Flemings",2)),
                         coded=c(rep("No",4),rep("Yes",4)),
                         stringsAsFactors = F)
party_data$eth_base_group <- str_split(string=party_data$eth_base_group, pattern="\\|")
ethnicgroups <- data.frame(country_name=c(rep("Austria",3), rep("Belgium",3)),
                           groupname=c("Germans","Czech","French","French","Flemings","Dutch"),
                           stringsAsFactors = F)

ui <- fluidPage(

  ############## Country /party selection #####
  div(id="choose_country_and_party",
      div(id="preselect",
          selectInput("coded", "Has the data already been coded?",
                      choices=c("Yes","No",""),
                      selected=""),
          selectInput("country_name", "Select country",
                      choices=c(party_data$country_name,""),
                      selected=""),
          selectInput("party_id", "Select party ID",
                      choices=c(party_data$party_id,0),
                      selected=0)),
  ),
  hr(),

  ############## Ethnic page #####
  div(id="data_entry_ethnic",

      h3("Religious claims and base"),
      radioButtons("rel_claim_flag", "Religious claim and base:", choices=c("Yes","No","Don't know"),
                   selected=character(0)),

      h3("Ethnic base group"),
      checkboxGroupInput("eth_base_group", "Please select:",
                         choices=c(unique(ethnicgroups$groupname),"Other (please specify below)","Don't know"),
                         selected=character(0))
  )
)

server <- function(input, output, session) {

  selectedData <- reactive({
    if (input$coded=="Yes") {
      selected <- party_data %>%
        filter(coded=="Yes" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    } else {
      selected <- party_data %>%
        filter(coded=="No" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    }
  })

  # 3.4 Religion, language and ethnicity ####
  observe({
    selected <- selectedData()
#    updateRadioButtons(session,
#                        inputId="rel_claim_flag",
#                        selected=selected$rel_claim_flag)
    updateCheckboxGroupInput(session,
                             inputId="eth_base_group",
                             choices=c(ethnicgroups$groupname[ethnicgroups$country_name%in%selected$country_name],
                                       "Other (please specify below)","Don't know"),
                             selected = unlist(selected$eth_base_group))
  })

}

shinyApp(ui=ui, server=server)
</code>```

I am especially confused here because from my understanding, updating the radio buttons should neither affect the data in the background, nor is it in any way linked to the checkboxGroupInput element. Any suggestions on how to move forward here so that I can update both input elements would be highly appreciated.

Thank you!

P.S. I do not care for the following issues with this minimal reproducible example, because in the final version, they will not be problematic / solved: Sometimes, the input objects only get updated, once.

答:
This is what now seems to work, at least in this minimal reproducible example, although I am not sure why:</p>
```<code>library(shiny)
library(dplyr)
library(stringr)

party_data <- data.frame(country_name=c("Austria","Austria","Belgium","Belgium","Austria","Austria","Belgium","Belgium"),
                         party_id=c(100,101,100,101,100,101,100,101),
                         rel_claim_flag=c(rep(NA,4), rep("Yes",4)),
                         eth_base_group=c(rep(NA,4),
                                          "Germans|Czech","Germans|French", "French|Flemings","French|Dutch"),
                         coded=c(rep("No",4),rep("Yes",4)),
                         stringsAsFactors = F)
party_data$eth_base_group <- str_split(string=party_data$eth_base_group, pattern="\\|")
ethnicgroups <- data.frame(country_name=c(rep("Austria",3), rep("Belgium",3)),
                           groupname=c("Germans","Czech","French","French","Flemings","Dutch"),
                           stringsAsFactors = F)

ui <- fluidPage(

  ############## Country /party selection #####
  div(id="choose_country_and_party",
      div(id="preselect",
          selectInput("coded", "Has the data already been coded?",
                      choices=c("Yes","No",""),
                      selected=""),
          selectInput("country_name", "Select country",
                      choices=c(party_data$country_name),
                      selected=NULL),
          selectInput("party_id", "Select party ID",
                      choices=c(party_data$party_id),
                      selected=NULL)
  )),
  hr(),

  ############## Ethnic page #####
  div(id="data_entry_ethnic",

      h3("Religious claims and base"),
      radioButtons("rel_claim_flag", "Religious claim and base:",
                   choices=c("Yes","No","Don't know", ""),
                   selected=""),

      h3("Ethnic base group"),
      checkboxGroupInput("eth_base_group", "Please select:",
                         choices=c(unique(ethnicgroups$groupname),"Other (please specify below)","Don't know",""),
                         selected="")
  )
)

server <- function(input, output, session) {

  selectedData <- reactive({
    if (input$coded=="Yes") {
      selected <- party_data %>%
        filter(coded=="Yes" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    } else {
      selected <- party_data %>%
        filter(coded=="No" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    }
  })

  # 3.4 Religion, language and ethnicity ####
  observe({
    selected <- selectedData()
    updateRadioButtons(session,
                        inputId="rel_claim_flag",
                        choices=c("Yes","No","Don't know"),
                        selected=ifelse(is.na(selected$rel_claim_flag), "", selected$rel_claim_flag))
    updateCheckboxGroupInput(session,
                             inputId="eth_base_group",
                             choices=c(ethnicgroups$groupname[ethnicgroups$country_name%in%selected$country_name],
                                       "Other (please specify below)","Don't know"),
                             selected = ifelse(is.na(unlist(selected$eth_base_group)), "", unlist(selected$eth_base_group)))
  })

}

shinyApp(ui=ui, server=server)
</code>```

Body:
In short, the issue I have is the following: Depending on whether I update or leave empty Radio buttons "previously" shown to users of my Shiny App, the CheckboxGroup will update correctly or not.
I added a reproducible example below.

My goal is to allow our research assistants to enter data for specific parties. We have the data set stored in the background, and it might be that RAs have already started working on some of the parties. So they can, at first, choose the country, the party and indicate whether they have already worked on the party previously. In the latter case, their previous codings shall be updated and shown on the "next pages". What is shown on the "next pages" (hiding and showing parts of the shiny app) in our online version is shown below the vertical line.

However, the following issue puzzles me to great extent: When ignoring the lines 69-71 as it is now done, the CheckboxGroupInput behaves as expected; once all relevant meta data is selected, it shows a list of ethnic groups to choose from for the respective country chosen. If RAs have already started coding these parties, the previously selected choices are again selected. But, of course, the previously added data for religious claims are not shown, because they are not (yet) updated.

When I run all lines, including lines 69-71, the Shiny App updates the information on the religious claims correctly, but only shows all possible choices for ethnic groups per country if and only if the party data is sub-setted to the ones previously coded. If RAs choose "No" and then any combination of party ids and countries, they only see the choice selections "Other..." and "Don't know". However, if they choose "Yes" and any combination of party ids and countries, they do get the full list of ethnic groups plus their previous entered data.

Obviously, I would like my app to update both the religious claims and the ethnic groups selection, irrespective of any of the selections made regarding previously coded data, party id and country.

library(shiny)
library(dplyr)
library(stringr)

party_data <- data.frame(country_name=c("Austria","Austria","Belgium","Belgium","Austria","Austria","Belgium","Belgium"),
                         party_id=c(100,101,100,101,100,101,100,101),
                         rel_claim_flag=c(rep(NA,4), rep("Yes",4)),
                         eth_base_group=c(rep(NA,4), rep("Germans|Czech",2), rep("French|Flemings",2)),
                         coded=c(rep("No",4),rep("Yes",4)),
                         stringsAsFactors = F)
party_data$eth_base_group <- str_split(string=party_data$eth_base_group, pattern="\\|")
ethnicgroups <- data.frame(country_name=c(rep("Austria",3), rep("Belgium",3)),
                           groupname=c("Germans","Czech","French","French","Flemings","Dutch"),
                           stringsAsFactors = F)

ui <- fluidPage(

  ############## Country /party selection #####
  div(id="choose_country_and_party",
      div(id="preselect",
          selectInput("coded", "Has the data already been coded?",
                      choices=c("Yes","No",""),
                      selected=""),
          selectInput("country_name", "Select country",
                      choices=c(party_data$country_name,""),
                      selected=""),
          selectInput("party_id", "Select party ID",
                      choices=c(party_data$party_id,0),
                      selected=0)),
  ),
  hr(),

  ############## Ethnic page #####
  div(id="data_entry_ethnic",

      h3("Religious claims and base"),
      radioButtons("rel_claim_flag", "Religious claim and base:", choices=c("Yes","No","Don't know"),
                   selected=character(0)),

      h3("Ethnic base group"),
      checkboxGroupInput("eth_base_group", "Please select:",
                         choices=c(unique(ethnicgroups$groupname),"Other (please specify below)","Don't know"),
                         selected=character(0))
  )
)

server <- function(input, output, session) {

  selectedData <- reactive({
    if (input$coded=="Yes") {
      selected <- party_data %>%
        filter(coded=="Yes" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    } else {
      selected <- party_data %>%
        filter(coded=="No" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    }
  })

  # 3.4 Religion, language and ethnicity ####
  observe({
    selected <- selectedData()
#    updateRadioButtons(session,
#                        inputId="rel_claim_flag",
#                        selected=selected$rel_claim_flag)
    updateCheckboxGroupInput(session,
                             inputId="eth_base_group",
                             choices=c(ethnicgroups$groupname[ethnicgroups$country_name%in%selected$country_name],
                                       "Other (please specify below)","Don't know"),
                             selected = unlist(selected$eth_base_group))
  })

}

shinyApp(ui=ui, server=server)

I am especially confused here because from my understanding, updating the radio buttons should neither affect the data in the background, nor is it in any way linked to the checkboxGroupInput element. Any suggestions on how to move forward here so that I can update both input elements would be highly appreciated.

Thank you!

P.S. I do not care for the following issues with this minimal reproducible example, because in the final version, they will not be problematic / solved: Sometimes, the input objects only get updated, once.

Body:
This is what now seems to work, at least in this minimal reproducible example, although I am not sure why:

library(shiny)
library(dplyr)
library(stringr)

party_data <- data.frame(country_name=c("Austria","Austria","Belgium","Belgium","Austria","Austria","Belgium","Belgium"),
                         party_id=c(100,101,100,101,100,101,100,101),
                         rel_claim_flag=c(rep(NA,4), rep("Yes",4)),
                         eth_base_group=c(rep(NA,4),
                                          "Germans|Czech","Germans|French", "French|Flemings","French|Dutch"),
                         coded=c(rep("No",4),rep("Yes",4)),
                         stringsAsFactors = F)
party_data$eth_base_group <- str_split(string=party_data$eth_base_group, pattern="\\|")
ethnicgroups <- data.frame(country_name=c(rep("Austria",3), rep("Belgium",3)),
                           groupname=c("Germans","Czech","French","French","Flemings","Dutch"),
                           stringsAsFactors = F)

ui <- fluidPage(

  ############## Country /party selection #####
  div(id="choose_country_and_party",
      div(id="preselect",
          selectInput("coded", "Has the data already been coded?",
                      choices=c("Yes","No",""),
                      selected=""),
          selectInput("country_name", "Select country",
                      choices=c(party_data$country_name),
                      selected=NULL),
          selectInput("party_id", "Select party ID",
                      choices=c(party_data$party_id),
                      selected=NULL)
  )),
  hr(),

  ############## Ethnic page #####
  div(id="data_entry_ethnic",

      h3("Religious claims and base"),
      radioButtons("rel_claim_flag", "Religious claim and base:",
                   choices=c("Yes","No","Don't know", ""),
                   selected=""),

      h3("Ethnic base group"),
      checkboxGroupInput("eth_base_group", "Please select:",
                         choices=c(unique(ethnicgroups$groupname),"Other (please specify below)","Don't know",""),
                         selected="")
  )
)

server <- function(input, output, session) {

  selectedData <- reactive({
    if (input$coded=="Yes") {
      selected <- party_data %>%
        filter(coded=="Yes" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    } else {
      selected <- party_data %>%
        filter(coded=="No" &
                 country_name==input$country_name &
                 party_id==input$party_id)
    }
  })

  # 3.4 Religion, language and ethnicity ####
  observe({
    selected <- selectedData()
    updateRadioButtons(session,
                        inputId="rel_claim_flag",
                        choices=c("Yes","No","Don't know"),
                        selected=ifelse(is.na(selected$rel_claim_flag), "", selected$rel_claim_flag))
    updateCheckboxGroupInput(session,
                             inputId="eth_base_group",
                             choices=c(ethnicgroups$groupname[ethnicgroups$country_name%in%selected$country_name],
                                       "Other (please specify below)","Don't know"),
                             selected = ifelse(is.na(unlist(selected$eth_base_group)), "", unlist(selected$eth_base_group)))
  })

}

shinyApp(ui=ui, server=server)


问:
gitlab-ci.yml: 'script: -pytest cannot find any tests to check'
I'm having trouble implementing a toy example that runs pytest within .gitlab-ci.yml

gitlab_ci is a repo containing a single file test_hello.py

```<code>gitlab_ci/
    test_hello.py
</code>```

test_hello.py

# test_hello.py

import pytest

def hello():
    print("hello")

def hello_test():
    assert hello() == 'hello'

```

<p><strong>.gitlab-ci.yml</strong></p>

```# .gitlab-ci.yml

pytest:
  image: python:3.6
  script:
    - apt-get update -q -y
    - pip install pytest
    - pytest # if this is removed, the job outputs 'Success'

```

<p><strong>CI/CD terminal output</strong></p>

```$ pytest
=== test session starts ===
platform linux -- Python 3.6.9, pytest-5.2.0, py-1.8.0, pluggy-0.13.0
rootdir: /builds/kunov/gitlab_ci
collected 0 items

=== no tests ran in 0.02s ===
ERROR: Job failed: exit code 1
```

<p>I'm not sure why the test did not run... pytest does not seem to recognize <code>test_hello.py</code></p>

<hr>

<p><strong>Solution</strong></p>

<p>Put the python file inside the newly creared <strong>tests</strong> folder:</p>

```gitlab_ci/
    .gitlab-ci.yml
    tests/
        test_hello.py
```

<p>Modify <strong>gitlab-ci.yml</strong> in the following manner:</p>

```# .gitlab-ci.yml

pytest:
  image: python:3.6
  script:
  - apt-get update -q -y
  - pip install pytest
  - pwd
  - ls -l
  - export PYTHONPATH="$PYTHONPATH:."
  - python -c "import sys;print(sys.path)"
  - pytest

```

And test_hello.py would stay the same as before.

答:
Manipulation of the PYTHONPATH variable is considered by some to be a bad practice  (see e.g., this answer on stackoverflow or this Level Up Coding post). While this is possible not a huge issue in the scope of a GitLab CI job, here is a solution based on Alberto Mardegan's comment at the mentioned blog post without the need to fiddle with PYTHONPATH (also somewhat cleaner):

```<code>pytest:
  stage: Test
  script:
  - pwd
  - ls -l
  - python -m pytest
</code>```

Why does this work? From the pytest docs:

You can invoke testing through the Python interpreter from the command
line:

```<code>python -m pytest [...]
</code>```

This is almost equivalent to invoking the
command line script pytest [...] directly, except that calling via
python will also add the current directory to sys.path.

Body:
I'm having trouble implementing a toy example that runs pytest within .gitlab-ci.yml

gitlab_ci is a repo containing a single file test_hello.py

gitlab_ci/
    test_hello.py

test_hello.py

# test_hello.py

import pytest

def hello():
    print("hello")

def hello_test():
    assert hello() == 'hello'

.gitlab-ci.yml

# .gitlab-ci.yml

pytest:
  image: python:3.6
  script:
    - apt-get update -q -y
    - pip install pytest
    - pytest # if this is removed, the job outputs 'Success'

CI/CD terminal output

$ pytest
=== test session starts ===
platform linux -- Python 3.6.9, pytest-5.2.0, py-1.8.0, pluggy-0.13.0
rootdir: /builds/kunov/gitlab_ci
collected 0 items

=== no tests ran in 0.02s ===
ERROR: Job failed: exit code 1

I'm not sure why the test did not run... pytest does not seem to recognize test_hello.py

Solution

Put the python file inside the newly creared tests folder:

gitlab_ci/
    .gitlab-ci.yml
    tests/
        test_hello.py

Modify gitlab-ci.yml in the following manner:

# .gitlab-ci.yml

pytest:
  image: python:3.6
  script:
  - apt-get update -q -y
  - pip install pytest
  - pwd
  - ls -l
  - export PYTHONPATH="$PYTHONPATH:."
  - python -c "import sys;print(sys.path)"
  - pytest

And test_hello.py would stay the same as before.

Body:
Manipulation of the PYTHONPATH variable is considered by some to be a bad practice  (see e.g., this answer on stackoverflow or this Level Up Coding post). While this is possible not a huge issue in the scope of a GitLab CI job, here is a solution based on Alberto Mardegan's comment at the mentioned blog post without the need to fiddle with PYTHONPATH (also somewhat cleaner):

pytest:
  stage: Test
  script:
  - pwd
  - ls -l
  - python -m pytest

Why does this work? From the pytest docs:

You can invoke testing through the Python interpreter from the command
line:

python -m pytest [...]

This is almost equivalent to invoking the
command line script pytest [...] directly, except that calling via
python will also add the current directory to sys.path.


问:
Pyspark s3 error : java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException
I think I'm encountering jar incompatibility.  I'm using the following jar files to build a spark cluster:

spark-2.4.7-bin-hadoop2.7.tgz

aws-java-sdk-1.11.885.jar

hadoop:hadoop-aws-2.7.4.jar

```<code>from pyspark.sql import SparkSession, SQLContext
from pyspark.sql.types import *
from pyspark.sql.functions import *
import sys

spark = (SparkSession.builder
         .appName("AuthorsAges")
         .appName('SparkCassandraApp')
         .getOrCreate())

spark._jsc.hadoopConfiguration().set("fs.s3a.access.key", "access-key")
spark._jsc.hadoopConfiguration().set("fs.s3a.secret.key", "secret-key")
spark._jsc.hadoopConfiguration().set("fs.s3a.impl","org.apache.hadoop.fs.s3a.S3AFileSystem")
spark._jsc.hadoopConfiguration().set("com.amazonaws.services.s3.enableV4", "true")
spark._jsc.hadoopConfiguration().set("fs.s3a.aws.credentials.provider","org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider")
spark._jsc.hadoopConfiguration().set("fs.s3a.endpoint", "")

input_file='s3a://spark-test-data/Fire_Department_Calls_for_Service.csv'

file_schema = StructType([StructField("Call_Number",StringType(),True),
        StructField("Unit_ID",StringType(),True),
        StructField("Incident_Number",StringType(),True),
...
...
# Read file into a Spark DataFrame
input_df = (spark.read.format("csv") \
            .option("header", "true") \
            .schema(file_schema) \
            .load(input_file))

</code>```

The code fails when it starts to execute the spark.read.format.  It appears that it can't find the class.  java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException.

My spark-defaults.conf is configured as follows:

```<code>spark.jars.packages                com.amazonaws:aws-java-sdk:1.11.885,org.apache.hadoop:hadoop-aws:2.7.4
</code>```

I would appreciate if someone can help me.  Any ideas?

```<code>Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/usr/local/spark/spark-3.0.1-bin-hadoop2.7/python/pyspark/sql/readwriter.py", line 178, in load
    return self._df(self._jreader.load(path))
  File "/usr/local/lib/python3.6/site-packages/py4j/java_gateway.py", line 1305, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "/usr/local/spark/spark-3.0.1-bin-hadoop2.7/python/pyspark/sql/utils.py", line 128, in deco
    return f(*a, **kw)
  File "/usr/local/lib/python3.6/site-packages/py4j/protocol.py", line 328, in get_return_value
    format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o51.load.
: java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.hadoop.conf.Configuration.getClassByNameOrNull(Configuration.java:2134)
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2099)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2195)
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2654)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2667)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:94)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2703)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2685)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:373)
    at org.apache.hadoop.fs.Path.getFileSystem(Path.java:295)
    at org.apache.spark.sql.execution.streaming.FileStreamSink$.hasMetadata(FileStreamSink.scala:46)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:366)
    at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:297)
    at org.apache.spark.sql.DataFrameReader.$anonfun$load$2(DataFrameReader.scala:286)
    at scala.Option.getOrElse(Option.scala:189)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:286)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:232)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.amazonaws.AmazonServiceException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 30 more
</code>```

答:
I encountered the same problem and I was able to resolve it thanks to https://notadatascientist.com/running-apache-spark-and-s3-locally/

steps to follow:

check hadoop version installed with spark (in spar jars)

download hadoop-aws jar with the same version of hadoop.

download aws-java-sdk jar (check which version was used when
hadoop-aws was developped)

Body:
I think I'm encountering jar incompatibility.  I'm using the following jar files to build a spark cluster:

spark-2.4.7-bin-hadoop2.7.tgz

aws-java-sdk-1.11.885.jar

hadoop:hadoop-aws-2.7.4.jar

from pyspark.sql import SparkSession, SQLContext
from pyspark.sql.types import *
from pyspark.sql.functions import *
import sys

spark = (SparkSession.builder
         .appName("AuthorsAges")
         .appName('SparkCassandraApp')
         .getOrCreate())

spark._jsc.hadoopConfiguration().set("fs.s3a.access.key", "access-key")
spark._jsc.hadoopConfiguration().set("fs.s3a.secret.key", "secret-key")
spark._jsc.hadoopConfiguration().set("fs.s3a.impl","org.apache.hadoop.fs.s3a.S3AFileSystem")
spark._jsc.hadoopConfiguration().set("com.amazonaws.services.s3.enableV4", "true")
spark._jsc.hadoopConfiguration().set("fs.s3a.aws.credentials.provider","org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider")
spark._jsc.hadoopConfiguration().set("fs.s3a.endpoint", "")

input_file='s3a://spark-test-data/Fire_Department_Calls_for_Service.csv'

file_schema = StructType([StructField("Call_Number",StringType(),True),
        StructField("Unit_ID",StringType(),True),
        StructField("Incident_Number",StringType(),True),
...
...
# Read file into a Spark DataFrame
input_df = (spark.read.format("csv") \
            .option("header", "true") \
            .schema(file_schema) \
            .load(input_file))

The code fails when it starts to execute the spark.read.format.  It appears that it can't find the class.  java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException.

My spark-defaults.conf is configured as follows:

spark.jars.packages                com.amazonaws:aws-java-sdk:1.11.885,org.apache.hadoop:hadoop-aws:2.7.4

I would appreciate if someone can help me.  Any ideas?

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/usr/local/spark/spark-3.0.1-bin-hadoop2.7/python/pyspark/sql/readwriter.py", line 178, in load
    return self._df(self._jreader.load(path))
  File "/usr/local/lib/python3.6/site-packages/py4j/java_gateway.py", line 1305, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "/usr/local/spark/spark-3.0.1-bin-hadoop2.7/python/pyspark/sql/utils.py", line 128, in deco
    return f(*a, **kw)
  File "/usr/local/lib/python3.6/site-packages/py4j/protocol.py", line 328, in get_return_value
    format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o51.load.
: java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.hadoop.conf.Configuration.getClassByNameOrNull(Configuration.java:2134)
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2099)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2195)
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2654)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2667)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:94)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2703)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2685)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:373)
    at org.apache.hadoop.fs.Path.getFileSystem(Path.java:295)
    at org.apache.spark.sql.execution.streaming.FileStreamSink$.hasMetadata(FileStreamSink.scala:46)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:366)
    at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:297)
    at org.apache.spark.sql.DataFrameReader.$anonfun$load$2(DataFrameReader.scala:286)
    at scala.Option.getOrElse(Option.scala:189)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:286)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:232)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.amazonaws.AmazonServiceException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 30 more


问:
Stripe "no such price"
I created a product with tiered pricing in my Stripe dashboard. I copied the price API IDs and put them in my app's frontend. When I run my code, the backend generates the error: No such price: 'PRICE_1HPYAGLJZYBC5S5KGBKT8UDY'. This price id matches one of the prices on my Stripe dashboard, but I never set the product so I'm wondering if that's the issue. Here is my client js:

```<code>function createSubscription({ customerId, paymentMethodId, priceId }) {
  return (
    fetch('/create-subscription', {
      method: 'post',
      headers: {
        'Content-type': 'application/json',
      },
      body: JSON.stringify({
        customerId: customerId,
        paymentMethodId: paymentMethodId,
        priceId: priceId,
      }),
    })
      .then((response) => {
        return response.json();
      })
      // If the card is declined, display an error to the user.
      .then((result) => {
        if (result.error) {
          // The card had an error when trying to attach it to a customer
          throw result;
        }
        return result;
      })
      // Normalize the result to contain the object returned
      // by Stripe. Add the addional details we need.
      .then((result) => {
        console.log("RETURNING SUBSCRIPTION")
        return {
          // Use the Stripe 'object' property on the
          // returned result to understand what object is returned.
          subscription: result,
          paymentMethodId: paymentMethodId,
          priceId: priceId,
        };
      })
  );
}
</code>```

And here is my backend code:

```<code>app.post('/create-subscription', async function(req, res) {
  console.log(req.body);
  User.findOne({"_id": req.session.auth_user._id}, async function(err, user) {
    if (user.stripe_id) {
      console.log("RETRIEVING CUSTOMER");
      var customer = await stripe.customers.retrieve(user.stripe_id);
      if (user.stripe_subscription) {
        console.log("RETRIEVING SUBSCRIPTION");
        var subscription = await stripe.subscriptions.retrieve(user.stripe_subscription);
        update_customer(customer, subscription);
      }
      else {
        console.log("CREATING SUBSCRIPTION");
        var subscription = await stripe.subscriptions.create({
          customer: customer.id,
          items: [{
            price: req.body.priceId,
          }]
        });
        user.stripe_subscription = subscription.id;
        user.save(function(err) {
          update_customer(customer, subscription);
        })
      }
    }
    else {
      console.log("CREATING CUSTOMER");
      var customer = await stripe.customers.create({
        email: req.body.email,
      });
      user.stripe_id = customer.id;
      user.save( async function(err, user) {
        if (user.stripe_subscription) {
          console.log("RETRIEVING SUBSCRIPTION");
          var subscription = await stripe.subscriptions.retrieve(user.stripe_subscription);
          update_customer(customer, subscription);
        }
        else {
          console.log("CREATING SUBSCRIPTION");
          var subscription = await stripe.subscriptions.create({
            customer: customer.id,
            items: [{
              price: req.body.priceId,
            }]
          });
          user.stripe_subscription = subscription.id;
          user.save(function(err) {
            update_customer(customer, subscription);
          });
        }
      });
    }
  });

  async function update_customer(customer, subscription) {
    const paymentMethod = await stripe.paymentMethods.attach(
      req.body.paymentMethodId,
      {customer: customer.id}
    );

    console.log(subscription);
    res.send(subscription);
  }
});
</code>```

答:
Incase anyone faces this issue in the future. I had the same issue, but mine was caused by the stripe secret being wrong.

It's wise to:

Double check the price,

Trim the string,

Check your config keys all through

Hope this helps someone

Title: Stripe "no such price"

Body:
I created a product with tiered pricing in my Stripe dashboard. I copied the price API IDs and put them in my app's frontend. When I run my code, the backend generates the error: No such price: 'PRICE_1HPYAGLJZYBC5S5KGBKT8UDY'. This price id matches one of the prices on my Stripe dashboard, but I never set the product so I'm wondering if that's the issue. Here is my client js:

function createSubscription({ customerId, paymentMethodId, priceId }) {
  return (
    fetch('/create-subscription', {
      method: 'post',
      headers: {
        'Content-type': 'application/json',
      },
      body: JSON.stringify({
        customerId: customerId,
        paymentMethodId: paymentMethodId,
        priceId: priceId,
      }),
    })
      .then((response) => {
        return response.json();
      })
      // If the card is declined, display an error to the user.
      .then((result) => {
        if (result.error) {
          // The card had an error when trying to attach it to a customer
          throw result;
        }
        return result;
      })
      // Normalize the result to contain the object returned
      // by Stripe. Add the addional details we need.
      .then((result) => {
        console.log("RETURNING SUBSCRIPTION")
        return {
          // Use the Stripe 'object' property on the
          // returned result to understand what object is returned.
          subscription: result,
          paymentMethodId: paymentMethodId,
          priceId: priceId,
        };
      })
  );
}

And here is my backend code:

app.post('/create-subscription', async function(req, res) {
  console.log(req.body);
  User.findOne({"_id": req.session.auth_user._id}, async function(err, user) {
    if (user.stripe_id) {
      console.log("RETRIEVING CUSTOMER");
      var customer = await stripe.customers.retrieve(user.stripe_id);
      if (user.stripe_subscription) {
        console.log("RETRIEVING SUBSCRIPTION");
        var subscription = await stripe.subscriptions.retrieve(user.stripe_subscription);
        update_customer(customer, subscription);
      }
      else {
        console.log("CREATING SUBSCRIPTION");
        var subscription = await stripe.subscriptions.create({
          customer: customer.id,
          items: [{
            price: req.body.priceId,
          }]
        });
        user.stripe_subscription = subscription.id;
        user.save(function(err) {
          update_customer(customer, subscription);
        })
      }
    }
    else {
      console.log("CREATING CUSTOMER");
      var customer = await stripe.customers.create({
        email: req.body.email,
      });
      user.stripe_id = customer.id;
      user.save( async function(err, user) {
        if (user.stripe_subscription) {
          console.log("RETRIEVING SUBSCRIPTION");
          var subscription = await stripe.subscriptions.retrieve(user.stripe_subscription);
          update_customer(customer, subscription);
        }
        else {
          console.log("CREATING SUBSCRIPTION");
          var subscription = await stripe.subscriptions.create({
            customer: customer.id,
            items: [{
              price: req.body.priceId,
            }]
          });
          user.stripe_subscription = subscription.id;
          user.save(function(err) {
            update_customer(customer, subscription);
          });
        }
      });
    }
  });

  async function update_customer(customer, subscription) {
    const paymentMethod = await stripe.paymentMethods.attach(
      req.body.paymentMethodId,
      {customer: customer.id}
    );

    console.log(subscription);
    res.send(subscription);
  }
});


问:
spark java how to select newly added column using withcolumn
I am trying to create java spark program and trying to add anew column using

```<code>qdf.withColumn("newColumn", functions.lit("newCOlumn_val"))
</code>```

and when I am trying to select with

```<code>qdf.withColumn("newColumn", functions.lit("newColumn_val")).select(qdf.col("xyz"),qdf.col("newColumn")).show();
</code>```

its saying Cannot reslove column name newColumn. Can some one please help me how to do this in Java?

答:
qdf is the dataframe before you added the newColumn which is why you are unable to select it with qdf.col("newColumn").

To get a handle on it you can use functions.col("newColumn") e.g.

```<code>qdf.withColumn("newColumn", functions.lit("newColumn_val"))
    .select(functions.col("xyz"),functions.col("newColumn"))
    .show();
</code>```

Alternatively you can store the dataframe after calling withColumn and it should then be accessible e.g.

final var qdf2 = qdf.withColumn("newColumn", functions.lit("newColumn_val"));

qdf2.select(qdf2.col("xyz"), qdf2.col("newColumn")).show();
```

Or you can use raw strings as in Srinivas's answer.

Body:
I am trying to create java spark program and trying to add anew column using

qdf.withColumn("newColumn", functions.lit("newCOlumn_val"))

and when I am trying to select with

qdf.withColumn("newColumn", functions.lit("newColumn_val")).select(qdf.col("xyz"),qdf.col("newColumn")).show();

its saying Cannot reslove column name newColumn. Can some one please help me how to do this in Java?

Body:
qdf is the dataframe before you added the newColumn which is why you are unable to select it with qdf.col("newColumn").

To get a handle on it you can use functions.col("newColumn") e.g.

qdf.withColumn("newColumn", functions.lit("newColumn_val"))
    .select(functions.col("xyz"),functions.col("newColumn"))
    .show();

Alternatively you can store the dataframe after calling withColumn and it should then be accessible e.g.

final var qdf2 = qdf.withColumn("newColumn", functions.lit("newColumn_val"));

qdf2.select(qdf2.col("xyz"), qdf2.col("newColumn")).show();

Or you can use raw strings as in Srinivas's answer.


问:
How to fetch data from a specific JSON file?
I have one issue with fetching data from a json file.

The json file has some sub arrays and I want to map it. I created a codesandbox page and need help for mapping the related data: https://codesandbox.io/s/json-data-fetch-c00rf

When you open the link you will see that I have used React fetching with useEffect but it is not restricted with that, that means you can use another thing.

The json data coming from here: https://web-coding-challenge.vercel.joyn.de/api/blocks

Here is the code as well:

```<code>import "./styles.css";
import React, { useState, useEffect } from "react";

export default function App() {
  const [todos, setTodos] = React.useState<any[]>([]);

  React.useEffect(() => {
    fetch(`https://web-coding-challenge.vercel.joyn.de/api/blocks`)
      .then((results) => results.json())
      .then((data) => {
        setTodos(data);
      });
  }, []);

  return (
    <div className="App">
      {todos.map((post: any) => (
        <div>
          <h1>{post.id}</h1>
          <h2>{post.assets.primaryImage.url}</h2>
        </div>
      ))}
    </div>
  );
}

</code>```

答:
You can map through the post.assets and return your required jsx

For an example here I'm listing all the urls in a list

    return (

      {todos.length && todos.map((post: any) => (

{post.id}

          {post.assets.map((asset: any, index: number)=>{
            return (

{asset.primaryImage.url}

            )
          })}

      ))}

  );
```

sandbox

Body:
I have one issue with fetching data from a json file.

The json file has some sub arrays and I want to map it. I created a codesandbox page and need help for mapping the related data: https://codesandbox.io/s/json-data-fetch-c00rf

When you open the link you will see that I have used React fetching with useEffect but it is not restricted with that, that means you can use another thing.

The json data coming from here: https://web-coding-challenge.vercel.joyn.de/api/blocks

Here is the code as well:

import "./styles.css";
import React, { useState, useEffect } from "react";

export default function App() {
  const [todos, setTodos] = React.useState<any[]>([]);

  React.useEffect(() => {
    fetch(`https://web-coding-challenge.vercel.joyn.de/api/blocks`)
      .then((results) => results.json())
      .then((data) => {
        setTodos(data);
      });
  }, []);

  return (

      {todos.map((post: any) => (

{post.id}

{post.assets.primaryImage.url}

      ))}

  );
}

Body:
You can map through the post.assets and return your required jsx

For an example here I'm listing all the urls in a list

    return (
    <div className="App">
      {todos.length && todos.map((post: any) => (
        <div>
          <h2>{post.id}</h2>
          <ul>
          {post.assets.map((asset: any, index: number)=>{
            return (
              <li key={index}>{asset.primaryImage.url}</li>
            )
          })}
          </ul>
        </div>
      ))}
    </div>
  );

sandbox


问:
How to split with comma skipping comma between '?
I have that string :

```<code>a = "Hello, my name is Peter, John"
</code>```

I tried to split such as :

```<code>a.split(",")
</code>```

But I got that :

```<code>["Hello", "my name is Peter", "John"]
</code>```

But I would like to get that :

```<code>["Hello", "my name is Peter, John"]
</code>```

答:
You can use the second argument of the split function to define how many times you want the string to be spitted (counting from the beginning). Setting it to 1 should solve your problem:

```<code>a.split(",", 1)
</code>```

Body:
I have that string :

a = "Hello, my name is Peter, John"

I tried to split such as :

a.split(",")

But I got that :

["Hello", "my name is Peter", "John"]

But I would like to get that :

["Hello", "my name is Peter, John"]

Body:
You can use the second argument of the split function to define how many times you want the string to be spitted (counting from the beginning). Setting it to 1 should solve your problem:

a.split(",", 1)


问:
Silverlight website
I am looking for develop a website in silverlight 4.
I am confused  about which silver light template in VS 2010 is best for creating silver light website[internet application]?
Which is best design pattern[mvc or mvvm] to implement the same silver light website.
please give your valuable suggestion . so i can move further.

Thanks in advance!!

答:
If you have everything installed correctly, you should have a project template called Silverlight Application available:

The other application project templates are also valid, the only difference is they automatically reference specific libraries for you, and have certain directory structures and initial files, all aimed at getting you underway faster.

As for whether to use MVC or MVVM - you can use either approach, they are simply patterns for abstracting and decoupling the UI from the code and business logic. MVVM may be a good choice - it was designed by Microsoft specifically with WPF and Silverlight in mind, and there are many MVVM frameworks you can pick up and use to make the job a little easier.

Title: Silverlight website