问:
"Value used here after move" after unpacking account data
In solana after I iterate over the account I want to get the data of stake_info account and modify it.

```<code>let accounts_iter = &mut accounts.iter();
let stake_info = next_account_info(accounts_iter)?;
let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());

if stake_info_account_data.is_ok(){
        let difference = amount - stake_info_account_data?.amount;

        stake_info_account_data?.amount = amount;
        stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.rewards_timeframe) * stake_info_account_data?.rewards_percentage as u64);
        stake_info_account_data?.timestamp = clock.unix_timestamp as u64;

        stake_info_account_data?.pack_into_slice(&mut &mut stake_info.data.borrow_mut()[..]);
</code>```

I'm getting this error:

```<code>error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1052:17
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1031 |             let difference = amount - stake_info_account_data?.amount;
     |                                       ------------------------ `stake_info_account_data` moved due to this method call
...
1052 |                 stake_info_account_data?.amount = amount;
     |                 ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |
note: this function takes ownership of the receiver `self`, which moves `stake_info_account_data`
    --> /Users/fanitrade/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/try_trait.rs:218:15
     |
218  |     fn branch(self) -> ControlFlow<Self::Residual, Self::Output>;
     |               ^^^^

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:17
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.rewards_timeframe) * stake_info_account_data?.re...
     |           ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move                                                                                ------------------------ `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:62
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1052 |                 stake_info_account_data?.amount = amount;
     |                 ------------------------ `stake_info_account_data` moved due to this method call
1053 |                 stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 ...
     |                                                              ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:140
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.t...
     |                                                        ------------------------                                                      ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |                                                        |
     |                                                        `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:176
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.r...
     |                                                                                ------------------------            ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |                                                                                |
     |                                                                                `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:222
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.rewards_timeframe) * stake_info_account_data?.r...
     |                                                                                ------------------------                      ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |                                                                                |
     |                                                                                `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1054:17
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 |                 stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 ...
     |                 ------------------------ `stake_info_account_data` moved due to this method call
1054 |                 stake_info_account_data?.timestamp = clock.unix_timestamp as u64;
     |                 ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1056:17
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1054 |                 stake_info_account_data?.timestamp = clock.unix_timestamp as u64;
     |                 ------------------------ `stake_info_account_data` moved due to this method call
1055 |
1056 |                 stake_info_account_data?.pack_into_slice(&mut &mut stake_info.data.borrow_mut()[..]);
     |                 ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
</code>```

Here is the unpack function:

```<code>fn unpack_from_slice(input: &[u8]) -> Result<Self, ProgramError> {
    if input.len() != Self::LEN {
        msg!("Data length is less than required");
        return Err(ProgramError::InvalidAccountData.into())
    }
    let input = array_ref![input, 0, StakeAccount::LEN];
    #[allow(clippy::ptr_offset_with_cast)]
    let (
        amount,
        rewards_percentage,
        rewards_collected,
        rewards_timeframe,
        owner,
        timestamp,
        bump_seed,
    ) = array_refs![input, 8, 1, 8, 8, 32, 8, 1];
    Ok(Self {
        amount: u64::from_le_bytes(*amount),
        rewards_percentage: u8::from_le_bytes(*rewards_percentage),
        rewards_collected: u64::from_le_bytes(*rewards_collected),
        rewards_timeframe: u64::from_le_bytes(*rewards_timeframe),
        owner: Pubkey::new_from_array(*owner),
        timestamp: u64::from_le_bytes(*timestamp),
        bump_seed: u8::from_le_bytes(*bump_seed),
    })
}
</code>```

答:
You should add ? at the end of this line:

```<code>let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
</code>```

As a result:

If the Result was Err, that Err value would be directly returned to the function caller;

If the Result was Ok:

The stake_info_account_data would be holding the actual value you want to use.

There would be no need for an if with an is_ok() call.

You wouldn't need to use the ? multiple times (which is generally wrong).

Body:
In solana after I iterate over the account I want to get the data of stake_info account and modify it.

let accounts_iter = &mut accounts.iter();
let stake_info = next_account_info(accounts_iter)?;
let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());

if stake_info_account_data.is_ok(){
        let difference = amount - stake_info_account_data?.amount;

        stake_info_account_data?.amount = amount;
        stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.rewards_timeframe) * stake_info_account_data?.rewards_percentage as u64);
        stake_info_account_data?.timestamp = clock.unix_timestamp as u64;

        stake_info_account_data?.pack_into_slice(&mut &mut stake_info.data.borrow_mut()[..]);

I'm getting this error:

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1052:17
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1031 |             let difference = amount - stake_info_account_data?.amount;
     |                                       ------------------------ `stake_info_account_data` moved due to this method call
...
1052 |                 stake_info_account_data?.amount = amount;
     |                 ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |
note: this function takes ownership of the receiver `self`, which moves `stake_info_account_data`
    --> /Users/fanitrade/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/try_trait.rs:218:15
     |
218  |     fn branch(self) -> ControlFlow<Self::Residual, Self::Output>;
     |               ^^^^

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:17
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.rewards_timeframe) * stake_info_account_data?.re...
     |           ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move                                                                                ------------------------ `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:62
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1052 |                 stake_info_account_data?.amount = amount;
     |                 ------------------------ `stake_info_account_data` moved due to this method call
1053 |                 stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 ...
     |                                                              ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:140
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.t...
     |                                                        ------------------------                                                      ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |                                                        |
     |                                                        `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:176
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.r...
     |                                                                                ------------------------            ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |                                                                                |
     |                                                                                `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1053:222
     |
1028 | ...et stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |       ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 | ...       stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 - stake_info_account_data?.timestamp)/stake_info_account_data?.rewards_timeframe) * stake_info_account_data?.r...
     |                                                                                ------------------------                      ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
     |                                                                                |
     |                                                                                `stake_info_account_data` moved due to this method call

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1054:17
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1053 |                 stake_info_account_data?.rewards_collected = stake_info_account_data?.rewards_collected + (((clock.unix_timestamp as u64 ...
     |                 ------------------------ `stake_info_account_data` moved due to this method call
1054 |                 stake_info_account_data?.timestamp = clock.unix_timestamp as u64;
     |                 ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move

error[E0382]: use of moved value: `stake_info_account_data`
    --> src/processor.rs:1056:17
     |
1028 |         let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());
     |             ----------------------- move occurs because `stake_info_account_data` has type `Result<StakeAccount, ProgramError>`, which does not implement the `Copy` trait
...
1054 |                 stake_info_account_data?.timestamp = clock.unix_timestamp as u64;
     |                 ------------------------ `stake_info_account_data` moved due to this method call
1055 |
1056 |                 stake_info_account_data?.pack_into_slice(&mut &mut stake_info.data.borrow_mut()[..]);
     |                 ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move

Here is the unpack function:

fn unpack_from_slice(input: &[u8]) -> Result<Self, ProgramError> {
    if input.len() != Self::LEN {
        msg!("Data length is less than required");
        return Err(ProgramError::InvalidAccountData.into())
    }
    let input = array_ref![input, 0, StakeAccount::LEN];
    #[allow(clippy::ptr_offset_with_cast)]
    let (
        amount,
        rewards_percentage,
        rewards_collected,
        rewards_timeframe,
        owner,
        timestamp,
        bump_seed,
    ) = array_refs![input, 8, 1, 8, 8, 32, 8, 1];
    Ok(Self {
        amount: u64::from_le_bytes(*amount),
        rewards_percentage: u8::from_le_bytes(*rewards_percentage),
        rewards_collected: u64::from_le_bytes(*rewards_collected),
        rewards_timeframe: u64::from_le_bytes(*rewards_timeframe),
        owner: Pubkey::new_from_array(*owner),
        timestamp: u64::from_le_bytes(*timestamp),
        bump_seed: u8::from_le_bytes(*bump_seed),
    })
}

Body:
You should add ? at the end of this line:

let stake_info_account_data = StakeAccount::unpack_from_slice(&stake_info.data.borrow());

As a result:

If the Result was Err, that Err value would be directly returned to the function caller;

If the Result was Ok:

The stake_info_account_data would be holding the actual value you want to use.

There would be no need for an if with an is_ok() call.

You wouldn't need to use the ? multiple times (which is generally wrong).


来源: stackexchange

问:
Copy/clone an entire WPF solution& project and use it under another name
I have a WPF solution & project(written in Visual Studio2019) that I would like to use under another name.

On the other words, I have a project like( EXAMPLE_A ) that I would like to use on my other task (not creating again the entire project) just copy & paste and rename it (EXAMPLE_B) and then I want to exchange the GUI colors and title and logos...

I tried this copy&paste way but some part of code was wrong: VS said some part of code are not included in this project and so on . However, I copied the entire folder. I saw the Save As is not option... Therefore, I ask your help what is the correct process.

The question: have a simple correct way to clone/ copy the solution and use it under another separated name? ( final outcome: have EXAMPLE_A and EXAMPLE_B separately with same program functions, different name and logo)

Thank you for you all support.

答: Export your project as a Template in Visual Studio, then you can create another project and change the name or whatever else you need.</p>

ContentLicense: CC BY-SA 4.0


问:
Vagrant error when running vagrant up on Git Bash on Window 10
I am having trouble with vagrant up on Git Bash.
I'm currently using Vagrant 2.2.19 and VirtualBox 6.1 version.
Whenever I put vagrant up on Bash to be able to open VirtualBox server on Git bash using vagrant ssh, it shows the following error.

```<code>Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/bionic64' version '20200304.0.0' is up to date...
==> default: Setting the name of the VM: profiles-rest-api_default_1644116739589_78823
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 8000 (guest) => 8000 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'unknown' state. Please verify everything is configured
properly and try again.

If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.

The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.

</code>```

What I have done so far

Visualization is enabled from BIOS

Install VirtualBox extension pack

Uninstall and reinstall VirtualBox and Vagrant several times

Also, when I put vagrant ssh after that error, it shows nothing, but the VirtualBox is running as this image. Can you guys help me figure out how to open the VirtualBox server on Bash, please? Thank you!
enter image description here

答:
Welcome to stackoverflow! Please visit this useful link.
-Try to downgrade the vagrant version that you are using and try again.
-Also, try to use the command debug vagrant up in order to have debug logs available for a more precise description of the error message.

Finally, take a look at stackoverflow question too.

Body:
I am having trouble with vagrant up on Git Bash.
I'm currently using Vagrant 2.2.19 and VirtualBox 6.1 version.
Whenever I put vagrant up on Bash to be able to open VirtualBox server on Git bash using vagrant ssh, it shows the following error.

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/bionic64' version '20200304.0.0' is up to date...
==> default: Setting the name of the VM: profiles-rest-api_default_1644116739589_78823
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 8000 (guest) => 8000 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'unknown' state. Please verify everything is configured
properly and try again.

If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.

The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.

What I have done so far

Visualization is enabled from BIOS

Install VirtualBox extension pack

Uninstall and reinstall VirtualBox and Vagrant several times

Also, when I put vagrant ssh after that error, it shows nothing, but the VirtualBox is running as this image. Can you guys help me figure out how to open the VirtualBox server on Bash, please? Thank you!
enter image description here


问:
Cannot install scikit-surprise on my jupyter notebook

I am building a recommendation engine and am not able to install surprise, i thought the problem was because i didn't have a c compiler(since i found some people saying it would solve the problem) so i installed it too but couldn't solve anything. i even tried runing the pip install on my command prompt and it gave an error.

答:
I found the solution for me as to first update all my conda packages and then install scikit-surprise. You can follow the steps as well if it works out for you:

Go to anaconda command prompt

Type conda update --all

Type conda install -c conda-forge scikit-surprise

Also I'm running python 3.8.8.


问:
Python row wise operation without loops
Solved:
Thanks to the help of @mozway I solved my problem.
Basically merged the df's, grouped them up and combined them into one column + deleted the duplicates.

```<code>df2 = df2.merge(df1, how='left', left_on=df2["code2_firstTwoDigits"], right_on=df1["code"])
df2['code'] = df2.groupby(['code2_firstTwoDigits'])['code'].transform(lambda x : ', '.join(x))
df2= df2.drop_duplicates()
</code>```

I want to execute an operation row wise but I read, as a Python newby, that I shouldn't use loops in Python.

I have two dataframes which basically look like this

```<code>df1 =
   code    random_values   code_Values
0   1234    house           3.21
1   2345    car             5.32
2   2342    white           1.00
3   2344    wolf            2.23
4   2345    black           5.00
5   3456    house           5.99
6   3422    car             3.21
7   3666    white           5.32
8   4567    wolf            1.00
9   4511    black           2.23
10  4721    red             5.00

df2 =
   code2   random_values   code2_firstTwoDigits
0   1264    house           12
1   2397    car             23
2   3498    white           34
3   4588    wolf            45
4   6388    black           63
</code>```

I'm probably trying to do too many operations at once and I have a feeling that my brain didn't adjust to Python coming from C#. But what I'm trying to do is:

Create columns "SameCodeStructure" and "SameCodeStructure_SumOfValues" in df2

Iterate through all rows of df2 and search for values in df1["code"] which match with the value of "code2_firstTwoDigits"

Save those values from df1["code"] in df2["SameCodeStructure"]

Add the value from those matching rows into df2["SameCodeStructure_SumOfValues"]

It's hard to explain without getting confused again, so I tried a visual representation of my question how I would love it to look like:

```<code>df3 =
    code2   random_values   code2_firstTwoDigits    SameCodeStructure           SameCodeStructure_SumOfValues
0   1264    house           12                      1234                        3.21
1   2397    car             23                      2345, 2342, 2344, 2345      13.55
2   3498    white           34                      3456, 3422                  9.2
3   4588    wolf            45                      4567, 4511                  3.23
4   6388    black           63                      -                           -

</code>```

I managed to look up the matching codes for a single row (3), but I'm struggling to find a helping hand how to transform this into an overall solution for all rows of df2

```<code>pd.Series(df2[ df2["code2"].str.match (df1.iloc[3]["code_Values"] ) ]["code2"]).str.cat(sep=", ", others=None)
</code>```

And I'm thankful for all the advice.
Python seems to be easier in terms of "the amount of written code" for me, but it's really difficult to think "in less code"

答:
The exact logic of the output is unclear, but you want merge and groupby+agg:

```<code>(df1.merge(df2, left_on=df1['code']//100, right_on='code2_firstTwoDigits', suffixes=('', '_2'))
    .groupby('code2_firstTwoDigits')
    .agg({'code_Values': 'sum',
          'code': list,
          'random_values': 'first'})
)
</code>```

output:

```<code>                      code_Values                      code random_values
code2_firstTwoDigits
12                           3.21                    [1234]         house
23                          13.55  [2345, 2342, 2344, 2345]           car
34                           9.20              [3456, 3422]         house
45                           3.23              [4567, 4511]          wolf
</code>```

Title: Python row wise operation without loops

Body:
Solved:
Thanks to the help of @mozway I solved my problem.
Basically merged the df's, grouped them up and combined them into one column + deleted the duplicates.

df2 = df2.merge(df1, how='left', left_on=df2["code2_firstTwoDigits"], right_on=df1["code"])
df2['code'] = df2.groupby(['code2_firstTwoDigits'])['code'].transform(lambda x : ', '.join(x))
df2= df2.drop_duplicates()

I want to execute an operation row wise but I read, as a Python newby, that I shouldn't use loops in Python.

I have two dataframes which basically look like this

df1 =
   code    random_values   code_Values
0   1234    house           3.21
1   2345    car             5.32
2   2342    white           1.00
3   2344    wolf            2.23
4   2345    black           5.00
5   3456    house           5.99
6   3422    car             3.21
7   3666    white           5.32
8   4567    wolf            1.00
9   4511    black           2.23
10  4721    red             5.00

df2 =
   code2   random_values   code2_firstTwoDigits
0   1264    house           12
1   2397    car             23
2   3498    white           34
3   4588    wolf            45
4   6388    black           63

I'm probably trying to do too many operations at once and I have a feeling that my brain didn't adjust to Python coming from C#. But what I'm trying to do is:

Create columns "SameCodeStructure" and "SameCodeStructure_SumOfValues" in df2

Iterate through all rows of df2 and search for values in df1["code"] which match with the value of "code2_firstTwoDigits"

Save those values from df1["code"] in df2["SameCodeStructure"]

Add the value from those matching rows into df2["SameCodeStructure_SumOfValues"]

It's hard to explain without getting confused again, so I tried a visual representation of my question how I would love it to look like:

df3 =
    code2   random_values   code2_firstTwoDigits    SameCodeStructure           SameCodeStructure_SumOfValues
0   1264    house           12                      1234                        3.21
1   2397    car             23                      2345, 2342, 2344, 2345      13.55
2   3498    white           34                      3456, 3422                  9.2
3   4588    wolf            45                      4567, 4511                  3.23
4   6388    black           63                      -                           -

I managed to look up the matching codes for a single row (3), but I'm struggling to find a helping hand how to transform this into an overall solution for all rows of df2

pd.Series(df2[ df2["code2"].str.match (df1.iloc[3]["code_Values"] ) ]["code2"]).str.cat(sep=", ", others=None)

And I'm thankful for all the advice.
Python seems to be easier in terms of "the amount of written code" for me, but it's really difficult to think "in less code"

Body:
The exact logic of the output is unclear, but you want merge and groupby+agg:

(df1.merge(df2, left_on=df1['code']//100, right_on='code2_firstTwoDigits', suffixes=('', '_2'))
    .groupby('code2_firstTwoDigits')
    .agg({'code_Values': 'sum',
          'code': list,
          'random_values': 'first'})
)

output:

                      code_Values                      code random_values
code2_firstTwoDigits
12                           3.21                    [1234]         house
23                          13.55  [2345, 2342, 2344, 2345]           car
34                           9.20              [3456, 3422]         house
45                           3.23              [4567, 4511]          wolf


问:
Permission denied (publickey) when using Nix's Git
I installed Git via Nix (on Arch Linux).

```<code>[gorre@uplink ~]$ uname -a
Linux uplink 4.16.9-1-ARCH #1 SMP PREEMPT Thu May 17 02:10:09 UTC 2018 x86_64 GNU/Linux
[gorre@uplink ~]$ nix-env -q
erlang-20.3.2
git-2.16.3
go-1.10.1
google-drive-ocamlfuse-0.6.25
nix-2.0.2
</code>```

I have the SSH config file saved in ~/.ssh/config:

```<code>[gorre@uplink ~]$ cat ~/.ssh/config
# Bitbucket.org
Host bitbucket.org
#RSAAuthentication yes
IdentityFile ~/.ssh/bitbucket_id_rsa
IdentitiesOnly yes
</code>```

I'm 100% sure the private/public key set is correct. I use it all the time in SmartGit, but when I try to use Git via the command-line, I'm getting this error:

```<code>[gorre@uplink erlang]$ git pull --rebase
sign_and_send_pubkey: signing failed: agent refused operation
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
</code>```

Is there any way to tell Git (installed via Nix) to refer to my ~/.ssh/config file?

As a proof, this is what happens when I "instruct" the ssh-agent to temporarily use my public key (so you can be certain that I have the correct rights):

```<code>[gorre@uplink erlang]$ ssh-agent sh -c 'ssh-add ~/.ssh/bitbucket_id_rsa; git pull --rebase'
Enter passphrase for /home/gorre/.ssh/bitbucket_id_rsa:
Identity added: /home/gorre/.ssh/bitbucket_id_rsa (/home/gorre/.ssh/bitbucket_id_rsa)
Already up to date.
Current branch master is up to date.
</code>```

...after that, I'm free to fly for a while:

```<code>[gorre@uplink erlang_simple_cache]$ git pull --rebase
Already up to date.
Current branch master is up to date.
</code>```

答:
I encountered the same error message (on Debian) but with a different cause.

The problem was RSA SHA-1 deprecation in OpenSSH 8.8:
https://www.openssh.com/txt/release-8.8 ("Potentially-incompatible changes").

Solved by generating and uploading a new ed25519 key.

Debugging the "Permission denied" error with ssh -v git@... was fruitless because git from /nix uses ssh from /nix, not the system ssh.
GIT_TRACE=1 git ... output showed path to the ssh binary that is actually used.

Body:
I installed Git via Nix (on Arch Linux).

[gorre@uplink ~]$ uname -a
Linux uplink 4.16.9-1-ARCH #1 SMP PREEMPT Thu May 17 02:10:09 UTC 2018 x86_64 GNU/Linux
[gorre@uplink ~]$ nix-env -q
erlang-20.3.2
git-2.16.3
go-1.10.1
google-drive-ocamlfuse-0.6.25
nix-2.0.2

I have the SSH config file saved in ~/.ssh/config:

[gorre@uplink ~]$ cat ~/.ssh/config
# Bitbucket.org
Host bitbucket.org
#RSAAuthentication yes
IdentityFile ~/.ssh/bitbucket_id_rsa
IdentitiesOnly yes

I'm 100% sure the private/public key set is correct. I use it all the time in SmartGit, but when I try to use Git via the command-line, I'm getting this error:

[gorre@uplink erlang]$ git pull --rebase
sign_and_send_pubkey: signing failed: agent refused operation
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Is there any way to tell Git (installed via Nix) to refer to my ~/.ssh/config file?

As a proof, this is what happens when I "instruct" the ssh-agent to temporarily use my public key (so you can be certain that I have the correct rights):

[gorre@uplink erlang]$ ssh-agent sh -c 'ssh-add ~/.ssh/bitbucket_id_rsa; git pull --rebase'
Enter passphrase for /home/gorre/.ssh/bitbucket_id_rsa:
Identity added: /home/gorre/.ssh/bitbucket_id_rsa (/home/gorre/.ssh/bitbucket_id_rsa)
Already up to date.
Current branch master is up to date.

...after that, I'm free to fly for a while:

[gorre@uplink erlang_simple_cache]$ git pull --rebase
Already up to date.
Current branch master is up to date.


问:
Finding the index of an item in a list
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index 1?

答:
List comprehension would be the best option to acquire a compact implementation in finding the index of an item in a list.</p>
```<code>a_list = ["a", "b", "a"]
print([index for (index , item) in enumerate(a_list) if item == "a"])
</code>```

Title: Finding the index of an item in a list

Body:
List comprehension would be the best option to acquire a compact implementation in finding the index of an item in a list.

a_list = ["a", "b", "a"]
print([index for (index , item) in enumerate(a_list) if item == "a"])


问:
Prettier supports for Optional chaining (?.)
In my JavaScript React App I am using prettier for code formatting.

My current rules are working as expected. I saw that Prettier supports also Optional chaining, but when I run prettier --write that does not change for example user.info.name into user?.info?.name

Does someone have an idea what is the problem here?

Here is my .prettierrc:

```<code>module.exports = {
  trailingComma: "none",
  tabWidth: 2,
  semi: true,
  printWidth: 120,
  arrowParens: "avoid"
};
</code>```

Version - "prettier": "2.1.2"

I am using Webstorm IDE

答: Prettier doesn't make make changes that would alter the behavior of your code. Adding in optional chaining everywhere you access object properties would change the behavior, and isn't even desirable, so they don't do that. When prettier says they support optional chaining, they just mean that prettier can parse code that uses optional chaining, instead of throwing exceptions that the syntax isn't recognized.</p>

Body:
In my JavaScript React App I am using prettier for code formatting.

My current rules are working as expected. I saw that Prettier supports also Optional chaining, but when I run prettier --write that does not change for example user.info.name into user?.info?.name

Does someone have an idea what is the problem here?

Here is my .prettierrc:

module.exports = {
  trailingComma: "none",
  tabWidth: 2,
  semi: true,
  printWidth: 120,
  arrowParens: "avoid"
};

Version - "prettier": "2.1.2"

I am using Webstorm IDE


问:
Automatically generate report from DataGrip?
I have to pull-out the same report every week from DataGrip.

Is it possible to automate this process?

答: At the moment - no, but here is feature request, please follow and vote.</p>


问:
cordova build cannot agree on Java version
$ cordova build android –release

When JAVA_HOME points to old C:\Program Files\Java\jdk1.8.0_261 - I get:

Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.

When JAVA_HOME points to new C:\Program Files\Java\jdk-17.0.2 - I get:

Requirements check failed for JDK 8 ('1.8.*')! Detected version: 17.0.2

How do I solve this?

答: You should download the latest version</p>

Body: You should download the latest version


问:
Access gmail email with oauth for intranet webapp
I have a web app deployed on 50 clients (ie 50 servers), let's say each client has 50 end client each (so total end user 2500).

I want to allow the end users retrieved their email on their dashboard, including gmail emails.

I began to follow google instructions about it. I will make my auth full client javascript so I follow these guidelines https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow#js-client-library

Problem, even just reading email seem to be a restricted scope

https://www.googleapis.com/auth/gmail.readonly    Read all resources and their metadata—no write operations.  Restricted

So if I don't submit my app into the verification process, it will be an unverified app so it will suppose to stop working after 100 connections (see https://support.google.com/cloud/answer/7454865) and I read the token will be delete frequently so it will not be convenient for my end user.

The different solutions I might have:

submit my app to the verification process : it seem complicated as f***. moreover, my app is actually deployed on (many) intranet server. so the different url can be https://192.168.1.53:5000, https://myaddress.local,etc.
I don't understand what will be the process on that. Should I create an app (on google dashboard) for each of my client? And make the process of each of them? How can Google verify an app which is not public?

make the app internal only on Google dashboard: actually it's designed for what I need. Problems, it seem it works only with Google workspace account. This last one cost money (a lot, see https://workspace.google.fr/intl/fr/pricing.html) and moreover my end client want to use their personal gmail address, not something related to their organization)

So I ran out solution. It seems crazy that I don't find a simple (and free) solution to allow my end users to import theirs email in my app.

I know their is also the imap solution, actually it's the one I use to import the mails (other than gmail but also gmail), but for make it works with gmail you have to remove security from their gmail account and its not something I can ask to my end users (for security reason, but also because they are not confident with IT tools so I want to make it simple as possible)

I wait for your suggestions if you have any

Thank you !

答:
i don't submit my app into the verification process, it will be an unverified app so it will suppose to stop working after 100 connections

100 users and only one 100 users you wont be able to authorize anyone else.

i read the token will be delete frequently so it will not be convenient for my end user.

Actually its the refresh token that gets revoked after seven days. But if your using Javascript and implicit flow you dont have a refresh token so this shouldn't be an issue for you.

my app is actually deployed on (many) intranet server. so the different url can be https://192.168.1.53:5000, https://myaddress.local,etc.

You cant for starters Google is going to want to see it running so it will need to be a public server, you will also need a public domain to host your TOS, and privacy policies so that google can see it.   It will also cost you between $15k - $75k for the third party security audit of your application.

How google can verify an app which is not public?

You cant

make the app internal only on google dashboard : actually its designed for what i need. problems, it seem it works only with google workspace account. This last one cost money (a lot, see https://workspace.google.fr/intl/fr/pricing.html) and moreover my end client want to use their personal gmail address, not something related to their organization)

This will also mean that all your users have to be on your workspace domain as their personal gmail emails wont work with workspace.  You can only read their emails on the domain.

So i ran out solution. It seem crazy i don't find a simple (and free) solution to allow my end users to import theirs email in my app.

That's because there isnt one.

I know their is also the imap solution, actually its the one i use actually to import the mails (other than gmail but also gmail), but for make it works with gmail you have to remove security from their gmail account and its not something i can ask to my end users (for security reason, but also because they are not confident with IT tools so i want to make it simple as possible)

I would not recommend trying to go though IMAP or SMTP, you would need the passwords to your users gmail accounts and that's a bad idea. Or you would need to use XOauth in which case you need to be verified.

I wait for your suggestions if you have any

My suggestion is decide if you really want this feature in your app. If you do.

Host it on a domain instead of internally.

apply for verification and go though all the hoops required.


问:
A Fence Per Command Allocator or just one fence DirectX12
So I am attempting to dive into DirectX12 synchronization. And I am having a hard time trying to understand why some programs need multiple fences for GPU/CPU synchronization, instead of just one.

In this guide, they have only a single fence and single fence value (that is stored per frame, so that the the value can be checked for a certain frame).

While in this guide they have a a fence for each frame and an array of current values for each frame. (This guide doesn't explain its reasoning for have a fence for each frame)

What is the correct way to do this? (For simplicity just assume it is a single threaded program with 3 back buffers in the swap chain, but if you have the knowledge for a multithreaded program too, that additional information would be helpful). What are the pros and cons of each way if they are both valid approaches?

Also why is it that we use a single fence event instead of one for each frame as well? Like in the below:

    if (fence->GetCompletedValue() < fenceValue)
    {
        ThrowIfFailed(fence->SetEventOnCompletion(fenceValue, fenceEvent));
        ::WaitForSingleObject(fenceEvent, static_cast<DWORD>(duration.count()));
    }
```

(I understand that the signals are appended to the end of command list in the command queues) So are fence events queued up the Windows OS? Is that why we can reuse it or is it because we will only be waiting on one event at a time ever, which is why we only need 1.

Thanks for the help in advanced. I am trying to get a strong understanding of the basics before i move on to more complex synchronization.

Edit: Found this link talking about some more synchronization: link in case people were interested. Doesn't answer the question though

Edit2: This following link is with Vulkan, but also uses a fence per frame in flight. But doesn't give a reason either.

答:
#directxtk does it with a single fence, and a fence value for each frame.

I believe you need fence values for each frame, because you want to know when the next frame is ready, not when the previous frame is completely finished (which would let you use a single global fence value). The call to a fence's GetCompletedValue() will tell you if the fence reached the fence value necessary to consider the next frame ready to be rendered.

Since the frames rotate with the back buffers, you want as many fence values as back buffers. But you don't necessarily need multiple fences. You can make it work with a single fence for a given command allocator.

Any time you need something fenced, you get the current fence value which you'd previously stored for the current back buffer in m_fenceValues[m_backBufferIndex].
Then you increment by 1, and tell the GPU via Signal() to please set the fence to this fence value when all current commands are executed. When you want to check that they've been executed, you compare to this fence value. If it's gone to the new number, then the GPU has done what it needed.
Store that new fence value back in m_fenceValues[m_backBufferIndex] and you're done.

This can be done at any time, within a frame or for moving to the next frame. When you want to move to the next frame, you do the same thing, except that you store the (fence value +1) in the fence value of the current back buffer which, by now, has become the new back buffer.

Here's the relevant code for moving to the next frame:

```
// Prepare to render the next frame.
void DeviceResources::MoveToNextFrame()
{
    // Schedule a Signal command in the queue.
    const UINT64 currentFenceValue = m_fenceValues[m_backBufferIndex];
    ThrowIfFailed(m_commandQueue->Signal(m_fence.Get(), currentFenceValue));

    // Update the back buffer index.
    m_backBufferIndex = m_swapChain->GetCurrentBackBufferIndex();

    // If the next frame is not ready to be rendered yet, wait until it is ready.
    if (m_fence->GetCompletedValue() SetEventOnCompletion(m_fenceValues[m_backBufferIndex], m_fenceEvent.Get()));
        WaitForSingleObjectEx(m_fenceEvent.Get(), INFINITE, FALSE);
    }

    // Set the fence value for the next frame.
    m_fenceValues[m_backBufferIndex] = currentFenceValue + 1;
}
```

If you are multithreading with multiple command allocators, you'll want as many fences as you have command allocators.

Body:
So I am attempting to dive into DirectX12 synchronization. And I am having a hard time trying to understand why some programs need multiple fences for GPU/CPU synchronization, instead of just one.

In this guide, they have only a single fence and single fence value (that is stored per frame, so that the the value can be checked for a certain frame).

While in this guide they have a a fence for each frame and an array of current values for each frame. (This guide doesn't explain its reasoning for have a fence for each frame)

What is the correct way to do this? (For simplicity just assume it is a single threaded program with 3 back buffers in the swap chain, but if you have the knowledge for a multithreaded program too, that additional information would be helpful). What are the pros and cons of each way if they are both valid approaches?

Also why is it that we use a single fence event instead of one for each frame as well? Like in the below:

    if (fence->GetCompletedValue() < fenceValue)
    {
        ThrowIfFailed(fence->SetEventOnCompletion(fenceValue, fenceEvent));
        ::WaitForSingleObject(fenceEvent, static_cast<DWORD>(duration.count()));
    }

(I understand that the signals are appended to the end of command list in the command queues) So are fence events queued up the Windows OS? Is that why we can reuse it or is it because we will only be waiting on one event at a time ever, which is why we only need 1.

Thanks for the help in advanced. I am trying to get a strong understanding of the basics before i move on to more complex synchronization.

Edit: Found this link talking about some more synchronization: link in case people were interested. Doesn't answer the question though

Edit2: This following link is with Vulkan, but also uses a fence per frame in flight. But doesn't give a reason either.

Body:
#directxtk does it with a single fence, and a fence value for each frame.

I believe you need fence values for each frame, because you want to know when the next frame is ready, not when the previous frame is completely finished (which would let you use a single global fence value). The call to a fence's GetCompletedValue() will tell you if the fence reached the fence value necessary to consider the next frame ready to be rendered.

Since the frames rotate with the back buffers, you want as many fence values as back buffers. But you don't necessarily need multiple fences. You can make it work with a single fence for a given command allocator.

Any time you need something fenced, you get the current fence value which you'd previously stored for the current back buffer in m_fenceValues[m_backBufferIndex].
Then you increment by 1, and tell the GPU via Signal() to please set the fence to this fence value when all current commands are executed. When you want to check that they've been executed, you compare to this fence value. If it's gone to the new number, then the GPU has done what it needed.
Store that new fence value back in m_fenceValues[m_backBufferIndex] and you're done.

This can be done at any time, within a frame or for moving to the next frame. When you want to move to the next frame, you do the same thing, except that you store the (fence value +1) in the fence value of the current back buffer which, by now, has become the new back buffer.

Here's the relevant code for moving to the next frame:

// Prepare to render the next frame.
void DeviceResources::MoveToNextFrame()
{
    // Schedule a Signal command in the queue.
    const UINT64 currentFenceValue = m_fenceValues[m_backBufferIndex];
    ThrowIfFailed(m_commandQueue->Signal(m_fence.Get(), currentFenceValue));

    // Update the back buffer index.
    m_backBufferIndex = m_swapChain->GetCurrentBackBufferIndex();

    // If the next frame is not ready to be rendered yet, wait until it is ready.
    if (m_fence->GetCompletedValue() SetEventOnCompletion(m_fenceValues[m_backBufferIndex], m_fenceEvent.Get()));
        WaitForSingleObjectEx(m_fenceEvent.Get(), INFINITE, FALSE);
    }

    // Set the fence value for the next frame.
    m_fenceValues[m_backBufferIndex] = currentFenceValue + 1;
}

If you are multithreading with multiple command allocators, you'll want as many fences as you have command allocators.


问:
How to get Windows 10 to autoload WinUSB as driver using MS_OS_20 BOS descriptor
I am struggling to get Windows to load the default WinUSB driver for my device. Please note that I am looking for a solution that is using BOS descriptor (and not the old 0xEE string index).

The device enumerates and Windows tells me that it is installing the device, but the WinUSB driver is not loaded. I have tried everything that I can think of, but still I can't get Windows to load the driver. I even uninstall the device and delete the USB flags in the registry whenever I re-try, but to no avail. Is there anyone who can help me to get this to work?

I don't want WebUSB capabilities or anything additional. This is a non-composite device.

This is my BOS descriptor (as sent over USB):

```<code>05 0F 21 00 01 1C 10 05 00 DF 60 DD D8 89
45 C7 4C 9C D2 65 9D 9E 64 8A 9F 00 00 03
06 B2 00 01 00
</code>```

And this my BOS descriptor set:

```<code>0A 00 00 00 00 00 03 06 B2 00 08 00 01 00   ..............
00 00 A8 00 08 00 02 00 00 00 A0 00 14 00   ..............
03 00 57 49 4E 55 53 42 00 00 00 00 00 00   ..WINUSB......
00 00 00 00 84 00 04 00 07 00 2A 00 44 00   ..........*.D.
65 00 76 00 69 00 63 00 65 00 49 00 6E 00   e.v.i.c.e.I.n.
74 00 65 00 72 00 66 00 61 00 63 00 65 00   t.e.r.f.a.c.e.
47 00 55 00 49 00 44 00 73 00 00 00 50 00   G.U.I.D.s...P.
7B 00 46 00 37 00 32 00 46 00 45 00 30 00   {.F.7.2.F.E.0.
44 00 34 00 2D 00 43 00 42 00 43 00 42 00   D.4.-.C.B.C.B.
2D 00 34 00 30 00 37 00 44 00 2D 00 38 00   -.4.0.7.D.-.8.
38 00 31 00 34 00 2D 00 39 00 45 00 44 00   8.1.4.-.9.E.D.
36 00 37 00 33 00 44 00 30 00 44 00 44 00   6.7.3.D.0.D.D.
36 00 42 00 7D 00 00 00 00 00               6.B.}.....
</code>```

The layout is:

```<code>typedef struct _SMSOS20DescriptorSet
{
    SDeviceDescSetHeader sDescriptorSetHeader;
    SConfigurationSubsetHeader sConfSubsetHeader;
    SFunctionSubsetHeader sFuncSubsetHeader;
    SDeviceCompatibleIdDescriptor sCompIdDescriptor;
    SDeviceRegDescDeviceInterfaceGUID sRegistryDescDevInterfaceGuid;
} SMSOS20DescriptorSet;
</code>```

I have follewed these guides and doc:

https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb#winusb-device-installation-by-using-the-in-box-winusbinf

MS_OS_2_0_desc.docx

https://thewindowsupdate.com/2018/10/12/how-to-install-winusb-sys-without-a-custom-inf/

https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/winusb-installation#automatic-installation-of--winusb-without-an-inf-file

UPDATE:
when you have a non-composite device that only has a single a configuration, then you are not use any subset headers (neither 'Configuration subset header' nor 'Function subset header'). So, the correct layout in this case is:

```<code>typedef struct _SMSOS20DescriptorSet
{
    SDeviceDescSetHeader sDescriptorSetHeader;
    SDeviceCompatibleIdDescriptor sCompIdDescriptor;
    SDeviceRegDescDeviceInterfaceGUID sRegistryDescDevInterfaceGuid;
} SMSOS20DescriptorSet;
</code>```

答:
UPDATE: when you have a non-composite device that only has a single a configuration, then you are not use any subset headers (neither 'Configuration subset header' nor 'Function subset header'). So, the correct layout in this case is:</p>
```<code>typedef struct _SMSOS20DescriptorSet
{
    SDeviceDescSetHeader sDescriptorSetHeader;
    SDeviceCompatibleIdDescriptor sCompIdDescriptor;
    SDeviceRegDescDeviceInterfaceGUID sRegistryDescDevInterfaceGuid;
} SMSOS20DescriptorSet;
</code>```

Body:
I am struggling to get Windows to load the default WinUSB driver for my device. Please note that I am looking for a solution that is using BOS descriptor (and not the old 0xEE string index).

The device enumerates and Windows tells me that it is installing the device, but the WinUSB driver is not loaded. I have tried everything that I can think of, but still I can't get Windows to load the driver. I even uninstall the device and delete the USB flags in the registry whenever I re-try, but to no avail. Is there anyone who can help me to get this to work?

I don't want WebUSB capabilities or anything additional. This is a non-composite device.

This is my BOS descriptor (as sent over USB):

05 0F 21 00 01 1C 10 05 00 DF 60 DD D8 89
45 C7 4C 9C D2 65 9D 9E 64 8A 9F 00 00 03
06 B2 00 01 00

And this my BOS descriptor set:

0A 00 00 00 00 00 03 06 B2 00 08 00 01 00   ..............
00 00 A8 00 08 00 02 00 00 00 A0 00 14 00   ..............
03 00 57 49 4E 55 53 42 00 00 00 00 00 00   ..WINUSB......
00 00 00 00 84 00 04 00 07 00 2A 00 44 00   ..........*.D.
65 00 76 00 69 00 63 00 65 00 49 00 6E 00   e.v.i.c.e.I.n.
74 00 65 00 72 00 66 00 61 00 63 00 65 00   t.e.r.f.a.c.e.
47 00 55 00 49 00 44 00 73 00 00 00 50 00   G.U.I.D.s...P.
7B 00 46 00 37 00 32 00 46 00 45 00 30 00   {.F.7.2.F.E.0.
44 00 34 00 2D 00 43 00 42 00 43 00 42 00   D.4.-.C.B.C.B.
2D 00 34 00 30 00 37 00 44 00 2D 00 38 00   -.4.0.7.D.-.8.
38 00 31 00 34 00 2D 00 39 00 45 00 44 00   8.1.4.-.9.E.D.
36 00 37 00 33 00 44 00 30 00 44 00 44 00   6.7.3.D.0.D.D.
36 00 42 00 7D 00 00 00 00 00               6.B.}.....

The layout is:

typedef struct _SMSOS20DescriptorSet
{
    SDeviceDescSetHeader sDescriptorSetHeader;
    SConfigurationSubsetHeader sConfSubsetHeader;
    SFunctionSubsetHeader sFuncSubsetHeader;
    SDeviceCompatibleIdDescriptor sCompIdDescriptor;
    SDeviceRegDescDeviceInterfaceGUID sRegistryDescDevInterfaceGuid;
} SMSOS20DescriptorSet;

I have follewed these guides and doc:

https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb#winusb-device-installation-by-using-the-in-box-winusbinf

MS_OS_2_0_desc.docx

https://thewindowsupdate.com/2018/10/12/how-to-install-winusb-sys-without-a-custom-inf/

https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/winusb-installation#automatic-installation-of--winusb-without-an-inf-file

UPDATE:
when you have a non-composite device that only has a single a configuration, then you are not use any subset headers (neither 'Configuration subset header' nor 'Function subset header'). So, the correct layout in this case is:

typedef struct _SMSOS20DescriptorSet
{
    SDeviceDescSetHeader sDescriptorSetHeader;
    SDeviceCompatibleIdDescriptor sCompIdDescriptor;
    SDeviceRegDescDeviceInterfaceGUID sRegistryDescDevInterfaceGuid;
} SMSOS20DescriptorSet;


问:
Core data: Failed to load model
I am new to core data.

What I am trying to DO: I am trying to create a cocoatouch framework that has an app to add employee details and display them in a table view. So that i can add this framework to my main project to work independently.

Issues I face: The frame work builds without any error. I have added the core data stack from swift 3 to the framework. But when i run the main project, the moment the framework loads the log displays "Failed to load model named Simple framework", "fetch failed" and "employee must have a valid entity description". The code that I have used in the framework is as shown below :

```<code>public class CoreDataStack {
    public static let sharedInstance = CoreDataStack()

    lazy var persistentContainer: NSPersistentContainer = {
        let container = NSPersistentContainer(name: "SimpleFramework")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error {
                fatalError("Unresolved error \(error), \(error)")
            }
        })
        return container
    }()

    public func saveContext() {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch let error as NSError {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        }
    }
}

@IBAction func addEmployee(_ sender: Any) {

    //To save the data
    let context = CoreDataStack.sharedInstance.persistentContainer.viewContext
    let employee = Employee(context: context)
    employee.employeeName = nameTextField.text
    employee.employeeAge = Int16(ageTextField.text!)!
    employee.hasVehicle = hasVehicle.isOn
    CoreDataStack.sharedInstance.saveContext()
    navigationController!.popViewController(animated: true)
}

@IBAction func addEmployee(_ sender: Any) {

    //To save the data
    let context = CoreDataStack.sharedInstance.persistentContainer.viewContext
    let employee = Employee(context: context)
    employee.employeeName = nameTextField.text
    employee.employeeAge = Int16(ageTextField.text!)!
    employee.hasVehicle = hasVehicle.isOn
    CoreDataStack.sharedInstance.saveContext()
    navigationController!.popViewController(animated: true)
}
</code>```

答:
If you want to use CoreData in your dynamic framework you have to subclass NSPersistentContainer and use it instead of NSPersistentContainer.

```<code>class PersistentContainer: NSPersistentContainer { }

//...

lazy var container: PersistentContainer = {
    let result = PersistentContainer(name: "Your xcdatamodeld file name here")
    result.loadPersistentStores { (storeDescription, error) in
        if let error = error {
            print(error.localizedDescription)
        }
    }
    return result
}()
</code>```

Title: Core data: Failed to load model

Body:
I am new to core data.

What I am trying to DO: I am trying to create a cocoatouch framework that has an app to add employee details and display them in a table view. So that i can add this framework to my main project to work independently.

Issues I face: The frame work builds without any error. I have added the core data stack from swift 3 to the framework. But when i run the main project, the moment the framework loads the log displays "Failed to load model named Simple framework", "fetch failed" and "employee must have a valid entity description". The code that I have used in the framework is as shown below :

public class CoreDataStack {
    public static let sharedInstance = CoreDataStack()

    lazy var persistentContainer: NSPersistentContainer = {
        let container = NSPersistentContainer(name: "SimpleFramework")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error {
                fatalError("Unresolved error \(error), \(error)")
            }
        })
        return container
    }()

    public func saveContext() {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch let error as NSError {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        }
    }
}

@IBAction func addEmployee(_ sender: Any) {

    //To save the data
    let context = CoreDataStack.sharedInstance.persistentContainer.viewContext
    let employee = Employee(context: context)
    employee.employeeName = nameTextField.text
    employee.employeeAge = Int16(ageTextField.text!)!
    employee.hasVehicle = hasVehicle.isOn
    CoreDataStack.sharedInstance.saveContext()
    navigationController!.popViewController(animated: true)
}

@IBAction func addEmployee(_ sender: Any) {

    //To save the data
    let context = CoreDataStack.sharedInstance.persistentContainer.viewContext
    let employee = Employee(context: context)
    employee.employeeName = nameTextField.text
    employee.employeeAge = Int16(ageTextField.text!)!
    employee.hasVehicle = hasVehicle.isOn
    CoreDataStack.sharedInstance.saveContext()
    navigationController!.popViewController(animated: true)
}

Body:
If you want to use CoreData in your dynamic framework you have to subclass NSPersistentContainer and use it instead of NSPersistentContainer.

class PersistentContainer: NSPersistentContainer { }

//...

lazy var container: PersistentContainer = {
    let result = PersistentContainer(name: "Your xcdatamodeld file name here")
    result.loadPersistentStores { (storeDescription, error) in
        if let error = error {
            print(error.localizedDescription)
        }
    }
    return result
}()


问:
String / label issue
I've got an issue with a label showing a String.

So, basically, I've got a function - (void) didFinishUpdatesSuccessfully. If this function is being called it means that an action has been completed successfully. It creates a time stamp and stores it to NSUserDefaults. All this works like a charme..
Here's the function:

```<code>    - (void) didFinishUpdatesSuccessfully {

        // Create formatted date string
        NSDate *currDate = [NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        [dateFormatter setDateFormat:@"dd/MM/YYYY - hh:mm:ss a"];
        NSString *dateString = [dateFormatter stringFromDate:currDate];

        NSMutableString* lastUpdated;
        lastUpdated = [[NSMutableString stringWithFormat:@"%@",dateString] retain];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:lastUpdated forKey:@"lastUpdated"];
        [defaults synchronize];

        //--- Alert dialog
        NSString *title;
        title = @"All the latest hotspots have now been saved!";
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: title
                                                    message: lastUpdated
                                                   delegate: nil
                                          cancelButtonTitle: [FileUtils appResourceForKey:@"HOTSPOT_GENERAL_BUTTON_TITLE_OK"]
                                          otherButtonTitles: nil];

// ------------------------
//Create label
    UILabel *UpDLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 205, 250, 100)];
    UpDLabel.backgroundColor = [UIColor clearColor]; // [UIColor brownColor];
    UpDLabel.font = [UIFont fontWithName:@"Helvetica" size: 11.0];
    UpDLabel.shadowColor = [UIColor whiteColor];
    UpDLabel.shadowOffset = CGSizeMake(1,1);
    UpDLabel.textColor = [UIColor blackColor];
    UpDLabel.textAlignment = UITextAlignmentRight; // UITextAlignmentCenter, UITextAlignmentLeft
    UpDLabel.lineBreakMode = UILineBreakModeWordWrap;
    NSString *lupdate   = [NSString stringWithFormat: @"Last Update: %@", lastUpdated];

    UpDLabel.text = lupdate;

    [self.view addSubview:UpDLabel];

    [UpDLabel release];
// ------------------------

        [dateFormatter release];
        [lastUpdated release];
        [alert show];
        [alert release];

        //--- remove indicator view
        [self indicatorViewShow:NO];

    }
</code>```

The label with the date string is being displayed. It overrides itself but seems to keep the previous string so it actualy looks like it just adds another layer on top of the previous one. Or in other words, if I perform the - (void) didFinishUpdatesSuccessfully 3 times it will show 3 date strings on top of each other which looks screwed...

What am I doing wrong?

Cheers
Jan

答:
You are recreating and re-adding the UpDLabel to your view every time the didFinishUpdatesSuccesfully method is called.

Instead make UpDLabel a property of your class:

```<code>UILabel *UpDLabel
@property (nonatomic, retain) UILabel *upDLabel
</code>```

And in your code in the didFinishUpdatesSuccesfully do:

```<code>if (!self.upDLabel) {
    self.upDLabel = [[[UILabel alloc] initWithFrame:CGRectMake(50, 205, 250, 100)] autorelease];
    self.upDLabel.backgroundColor = [UIColor clearColor]; // [UIColor brownColor];
    self.upDLabel.font = [UIFont fontWithName:@"Helvetica" size: 11.0];
    self.upDLabel.shadowColor = [UIColor whiteColor];
    self.upDLabel.shadowOffset = CGSizeMake(1,1);
    self.upDLabel.textColor = [UIColor blackColor];
    self.upDLabel.textAlignment = UITextAlignmentRight; // UITextAlignmentCenter, UITextAlignmentLeft
    self.upDLabel.lineBreakMode = UILineBreakModeWordWrap;

    [self.view addSubview:self.upDLabel];

}

NSString *lupdate   = [NSString stringWithFormat: @"Last Update: %@", lastUpdated];
self.upDLabel.text = lupdate;
</code>```

ContentLicense: CC BY-SA 3.0

Title: String / label issue

Body:
I've got an issue with a label showing a String.

So, basically, I've got a function - (void) didFinishUpdatesSuccessfully. If this function is being called it means that an action has been completed successfully. It creates a time stamp and stores it to NSUserDefaults. All this works like a charme..
Here's the function:

    - (void) didFinishUpdatesSuccessfully {

        // Create formatted date string
        NSDate *currDate = [NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        [dateFormatter setDateFormat:@"dd/MM/YYYY - hh:mm:ss a"];
        NSString *dateString = [dateFormatter stringFromDate:currDate];

        NSMutableString* lastUpdated;
        lastUpdated = [[NSMutableString stringWithFormat:@"%@",dateString] retain];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:lastUpdated forKey:@"lastUpdated"];
        [defaults synchronize];

        //--- Alert dialog
        NSString *title;
        title = @"All the latest hotspots have now been saved!";
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: title
                                                    message: lastUpdated
                                                   delegate: nil
                                          cancelButtonTitle: [FileUtils appResourceForKey:@"HOTSPOT_GENERAL_BUTTON_TITLE_OK"]
                                          otherButtonTitles: nil];

// ------------------------
//Create label
    UILabel *UpDLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 205, 250, 100)];
    UpDLabel.backgroundColor = [UIColor clearColor]; // [UIColor brownColor];
    UpDLabel.font = [UIFont fontWithName:@"Helvetica" size: 11.0];
    UpDLabel.shadowColor = [UIColor whiteColor];
    UpDLabel.shadowOffset = CGSizeMake(1,1);
    UpDLabel.textColor = [UIColor blackColor];
    UpDLabel.textAlignment = UITextAlignmentRight; // UITextAlignmentCenter, UITextAlignmentLeft
    UpDLabel.lineBreakMode = UILineBreakModeWordWrap;
    NSString *lupdate   = [NSString stringWithFormat: @"Last Update: %@", lastUpdated];

    UpDLabel.text = lupdate;

    [self.view addSubview:UpDLabel];

    [UpDLabel release];
// ------------------------

        [dateFormatter release];
        [lastUpdated release];
        [alert show];
        [alert release];

        //--- remove indicator view
        [self indicatorViewShow:NO];

    }

The label with the date string is being displayed. It overrides itself but seems to keep the previous string so it actualy looks like it just adds another layer on top of the previous one. Or in other words, if I perform the - (void) didFinishUpdatesSuccessfully 3 times it will show 3 date strings on top of each other which looks screwed...

What am I doing wrong?

Cheers
Jan

Body:
You are recreating and re-adding the UpDLabel to your view every time the didFinishUpdatesSuccesfully method is called.

Instead make UpDLabel a property of your class:

UILabel *UpDLabel
@property (nonatomic, retain) UILabel *upDLabel

And in your code in the didFinishUpdatesSuccesfully do:

if (!self.upDLabel) {
    self.upDLabel = [[[UILabel alloc] initWithFrame:CGRectMake(50, 205, 250, 100)] autorelease];
    self.upDLabel.backgroundColor = [UIColor clearColor]; // [UIColor brownColor];
    self.upDLabel.font = [UIFont fontWithName:@"Helvetica" size: 11.0];
    self.upDLabel.shadowColor = [UIColor whiteColor];
    self.upDLabel.shadowOffset = CGSizeMake(1,1);
    self.upDLabel.textColor = [UIColor blackColor];
    self.upDLabel.textAlignment = UITextAlignmentRight; // UITextAlignmentCenter, UITextAlignmentLeft
    self.upDLabel.lineBreakMode = UILineBreakModeWordWrap;

    [self.view addSubview:self.upDLabel];

}

NSString *lupdate   = [NSString stringWithFormat: @"Last Update: %@", lastUpdated];
self.upDLabel.text = lupdate;


问:
Can't Successfully Run AWS Glue Job That Reads From DynamoDB
I have successfully run crawlers that read my table in Dynamodb and also in AWS Reshift. The tables are now in the catalog.
My problem is when running the Glue job to read the data from Dynamodb to Redshift. It doesnt seem to be able to read from Dynamodb.
The error logs contain this

```<code>2022-02-01 10:16:55,821 WARN [task-result-getter-0] scheduler.TaskSetManager (Logging.scala:logWarning(69)): Lost task 0.0 in stage 0.0 (TID 0) (172.31.74.37 executor 1): java.lang.RuntimeException: Could not lookup table <TABLE-NAME> in DynamoDB.
    at org.apache.hadoop.dynamodb.DynamoDBClient.describeTable(DynamoDBClient.java:143)
    at org.apache.hadoop.dynamodb.read.ReadIopsCalculator.getThroughput(ReadIopsCalculator.java:67)
    at org.apache.hadoop.dynamodb.read.ReadIopsCalculator.calculateTargetIops(ReadIopsCalculator.java:58)
    at org.apache.hadoop.dynamodb.read.AbstractDynamoDBRecordReader.initReadManager(AbstractDynamoDBRecordReader.java:152)
    at org.apache.hadoop.dynamodb.read.AbstractDynamoDBRecordReader.<init>(AbstractDynamoDBRecordReader.java:84)
    at org.apache.hadoop.dynamodb.read.DefaultDynamoDBRecordReader.<init>(DefaultDynamoDBRecordReader.java:24)
    at org.apache.hadoop.dynamodb.read.DynamoDBInputFormat.getRecordReader(DynamoDBInputFormat.java:32)
    at com.amazonaws.services.glue.connections.DynamoConnection.getReader(DynamoConnection.scala:136)
    at com.amazonaws.services.glue.DynamicRecordRDD.compute(DataSource.scala:610)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:373)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:337)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:373)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:337)
    at org.apache.spark.shuffle.ShuffleWriteProcessor.write(ShuffleWriteProcessor.scala:59)
    at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:99)
    at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:52)
    at org.apache.spark.scheduler.Task.run(Task.scala:131)
    at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:497)
    at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1439)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:500)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to dynamodb.us-east-1.amazonaws.com:443 [dynamodb.us-east-1.amazonaws.com/3.218.180.106] failed: connect timed out
    at org.apache.hadoop.dynamodb.DynamoDBFibonacciRetryer.handleException(DynamoDBFibonacciRetryer.java:120)
    at org.apache.hadoop.dynamodb.DynamoDBFibonacciRetryer.runWithRetry(DynamoDBFibonacciRetryer.java:83)
    at org.apache.hadoop.dynamodb.DynamoDBClient.describeTable(DynamoDBClient.java:132)
    ... 23 more
Caused by: com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to dynamodb.us-east-1.amazonaws.com:443 [dynamodb.us-east-1.amazonaws.com/3.218.180.106] failed: connect timed out
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1207)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1153)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:770)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:744)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:704)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:686)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:550)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:530)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:6164)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:6131)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeDescribeTable(AmazonDynamoDBClient.java:2228)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.describeTable(AmazonDynamoDBClient.java:2193)
    at org.apache.hadoop.dynamodb.DynamoDBClient$1.call(DynamoDBClient.java:136)
    at org.apache.hadoop.dynamodb.DynamoDBClient$1.call(DynamoDBClient.java:133)
    at org.apache.hadoop.dynamodb.DynamoDBFibonacciRetryer.runWithRetry(DynamoDBFibonacciRetryer.java:80)
    ... 24 more
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to dynamodb.us-east-1.amazonaws.com:443 [dynamodb.us-east-1.amazonaws.com/3.218.180.106] failed: connect timed out
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
    at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76)
    at com.amazonaws.http.conn.$Proxy20.connect(Unknown Source)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1331)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1145)
    ... 38 more
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:607)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:368)
    at com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.connectSocket(SdkTLSSocketFactory.java:142)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    ... 53 more
</code>```

and the complete logs contain this:

```<code>22/02/01 10:06:07 INFO GlueContext: Glue secret manager integration: secretId is not provided.
</code>```

The role that Glue has been given has administrator access.

Below is the code for the script:

```<code>import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)

# Script generated for node S3 bucket
S3bucket_node1 = glueContext.create_dynamic_frame.from_catalog(
    database="db",
    table_name="db_s3_table",
    transformation_ctx="S3bucket_node1",
)

# Script generated for node ApplyMapping
ApplyMapping_node2 = ApplyMapping.apply(
    frame=S3bucket_node1,
    mappings=[
        ("column1.s", "string", "column1", "string"),
        ("column2.n", "string", "column2", "long"),
        ("column3.s", "string", "column3", "string"),
        ("partition_0", "string", "partition0", "string"),
    ],
    transformation_ctx="ApplyMapping_node2",
)

# Script generated for node Redshift Cluster
RedshiftCluster_node3 = glueContext.write_dynamic_frame.from_catalog(
    frame=ApplyMapping_node2,
    database="db",
    table_name="db_redshift_db_schema_table",
    redshift_tmp_dir=args["TempDir"],
    transformation_ctx="RedshiftCluster_node3",
)

job.commit()
</code>```

答: It seems that you were missing a VPC Endpoint for DynamoDB, since your Glue Jobs run in a private VPC when you write to Redshift.</p>

Body:
I have successfully run crawlers that read my table in Dynamodb and also in AWS Reshift. The tables are now in the catalog.
My problem is when running the Glue job to read the data from Dynamodb to Redshift. It doesnt seem to be able to read from Dynamodb.
The error logs contain this

2022-02-01 10:16:55,821 WARN [task-result-getter-0] scheduler.TaskSetManager (Logging.scala:logWarning(69)): Lost task 0.0 in stage 0.0 (TID 0) (172.31.74.37 executor 1): java.lang.RuntimeException: Could not lookup table
 in DynamoDB.
    at org.apache.hadoop.dynamodb.DynamoDBClient.describeTable(DynamoDBClient.java:143)
    at org.apache.hadoop.dynamodb.read.ReadIopsCalculator.getThroughput(ReadIopsCalculator.java:67)
    at org.apache.hadoop.dynamodb.read.ReadIopsCalculator.calculateTargetIops(ReadIopsCalculator.java:58)
    at org.apache.hadoop.dynamodb.read.AbstractDynamoDBRecordReader.initReadManager(AbstractDynamoDBRecordReader.java:152)
    at org.apache.hadoop.dynamodb.read.AbstractDynamoDBRecordReader.<init>(AbstractDynamoDBRecordReader.java:84)
    at org.apache.hadoop.dynamodb.read.DefaultDynamoDBRecordReader.<init>(DefaultDynamoDBRecordReader.java:24)
    at org.apache.hadoop.dynamodb.read.DynamoDBInputFormat.getRecordReader(DynamoDBInputFormat.java:32)
    at com.amazonaws.services.glue.connections.DynamoConnection.getReader(DynamoConnection.scala:136)
    at com.amazonaws.services.glue.DynamicRecordRDD.compute(DataSource.scala:610)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:373)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:337)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:373)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:337)
    at org.apache.spark.shuffle.ShuffleWriteProcessor.write(ShuffleWriteProcessor.scala:59)
    at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:99)
    at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:52)
    at org.apache.spark.scheduler.Task.run(Task.scala:131)
    at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:497)
    at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1439)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:500)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to dynamodb.us-east-1.amazonaws.com:443 [dynamodb.us-east-1.amazonaws.com/3.218.180.106] failed: connect timed out
    at org.apache.hadoop.dynamodb.DynamoDBFibonacciRetryer.handleException(DynamoDBFibonacciRetryer.java:120)
    at org.apache.hadoop.dynamodb.DynamoDBFibonacciRetryer.runWithRetry(DynamoDBFibonacciRetryer.java:83)
    at org.apache.hadoop.dynamodb.DynamoDBClient.describeTable(DynamoDBClient.java:132)
    ... 23 more
Caused by: com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to dynamodb.us-east-1.amazonaws.com:443 [dynamodb.us-east-1.amazonaws.com/3.218.180.106] failed: connect timed out
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1207)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1153)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:770)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:744)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:704)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:686)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:550)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:530)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:6164)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:6131)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeDescribeTable(AmazonDynamoDBClient.java:2228)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.describeTable(AmazonDynamoDBClient.java:2193)
    at org.apache.hadoop.dynamodb.DynamoDBClient$1.call(DynamoDBClient.java:136)
    at org.apache.hadoop.dynamodb.DynamoDBClient$1.call(DynamoDBClient.java:133)
    at org.apache.hadoop.dynamodb.DynamoDBFibonacciRetryer.runWithRetry(DynamoDBFibonacciRetryer.java:80)
    ... 24 more
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to dynamodb.us-east-1.amazonaws.com:443 [dynamodb.us-east-1.amazonaws.com/3.218.180.106] failed: connect timed out
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
    at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76)
    at com.amazonaws.http.conn.$Proxy20.connect(Unknown Source)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1331)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1145)
    ... 38 more
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:607)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:368)
    at com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.connectSocket(SdkTLSSocketFactory.java:142)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    ... 53 more

and the complete logs contain this:

22/02/01 10:06:07 INFO GlueContext: Glue secret manager integration: secretId is not provided.

The role that Glue has been given has administrator access.

Below is the code for the script:

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)

# Script generated for node S3 bucket
S3bucket_node1 = glueContext.create_dynamic_frame.from_catalog(
    database="db",
    table_name="db_s3_table",
    transformation_ctx="S3bucket_node1",
)

# Script generated for node ApplyMapping
ApplyMapping_node2 = ApplyMapping.apply(
    frame=S3bucket_node1,
    mappings=[
        ("column1.s", "string", "column1", "string"),
        ("column2.n", "string", "column2", "long"),
        ("column3.s", "string", "column3", "string"),
        ("partition_0", "string", "partition0", "string"),
    ],
    transformation_ctx="ApplyMapping_node2",
)

# Script generated for node Redshift Cluster
RedshiftCluster_node3 = glueContext.write_dynamic_frame.from_catalog(
    frame=ApplyMapping_node2,
    database="db",
    table_name="db_redshift_db_schema_table",
    redshift_tmp_dir=args["TempDir"],
    transformation_ctx="RedshiftCluster_node3",
)

job.commit()


问:
How to debug Django while using pipenv and VS Code?
I'm been using VS code and venv for my Django projects and have been able to debug using the tutorial provided by Microsoft here.

https://code.visualstudio.com/docs/python/tutorial-django

However, I have now switched to pipenv instead which I activate using the commmand pipenv shell.

When I now run using the Django debug configuration I get an error.

```<code>Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?
Did you forget to activate a virtual environment?
</code>```

I can't find any resources to guide me on this.

Do I need to change the launch.json file to make it work with pipenv?

答:
you just need to choose an interpreter
in my case, all pipenv interpreters are located in the ~/.virtualenvs folder
here is the screenshot</p>

Body:
I'm been using VS code and venv for my Django projects and have been able to debug using the tutorial provided by Microsoft here.

https://code.visualstudio.com/docs/python/tutorial-django

However, I have now switched to pipenv instead which I activate using the commmand pipenv shell.

When I now run using the Django debug configuration I get an error.

Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?
Did you forget to activate a virtual environment?

I can't find any resources to guide me on this.

Do I need to change the launch.json file to make it work with pipenv?


问:
data limit on chrome.storage.local
It is my understanding that there is no hard limit imposed on saving to

```<code>chrome.storage.local
</code>```

so long as the unlimited storage permission is set.  Is this true?  Doesn't that endanger the sandbox, by allowing a malicious developer to flood someones hard drive merely by asking for an innocent sounding permission?

答:
By default, it is limited to 5 MB in Chrome, but it is true that the limit can be disabled by the unlimitedStorage permission.

To quote the documentation of chrome.storage.local:

```<code>QUOTA_BYTES
</code>```

5242880

The maximum amount (in bytes) of data that can be stored in local storage, as measured by the JSON stringification of every value plus every key's length. This value will be ignored if the extension has the unlimitedStorage permission. Updates that would cause this limit to be exceeded fail immediately and set runtime.lastError.

It is correct that the WebExtension API in combination with unlimitedStorage allows to fill up the disk.
That is why it is recommended to install only trusted extensions. Yet for malicious extensions, I would be more concerned about the data that they could send out (e.g. stealing credentials). Or that they can redirect users to phishing sites. Like malware, which is capable of filling up the disk, but typically chooses other - more harmful - attacks.

Title: data limit on chrome.storage.local

Body:
It is my understanding that there is no hard limit imposed on saving to

chrome.storage.local

so long as the unlimited storage permission is set.  Is this true?  Doesn't that endanger the sandbox, by allowing a malicious developer to flood someones hard drive merely by asking for an innocent sounding permission?

Body:
By default, it is limited to 5 MB in Chrome, but it is true that the limit can be disabled by the unlimitedStorage permission.

To quote the documentation of chrome.storage.local:

QUOTA_BYTES

5242880

The maximum amount (in bytes) of data that can be stored in local storage, as measured by the JSON stringification of every value plus every key's length. This value will be ignored if the extension has the unlimitedStorage permission. Updates that would cause this limit to be exceeded fail immediately and set runtime.lastError.

It is correct that the WebExtension API in combination with unlimitedStorage allows to fill up the disk.
That is why it is recommended to install only trusted extensions. Yet for malicious extensions, I would be more concerned about the data that they could send out (e.g. stealing credentials). Or that they can redirect users to phishing sites. Like malware, which is capable of filling up the disk, but typically chooses other - more harmful - attacks.