问:
Ensuring the currentState of GlobalKey is Initialized in Flutter
I have a StatelessWidget as below:

class StatelessStreamPage extends StatelessWidget {
  final _formKey = GlobalKey<FormBuilderState>(); // (a)

  StatelessStreamPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Stateless Stream Page'),
      ),
      body: FormBuilder(
        key: _formKey,
        child: Column(
          children: [
            FormBuilderTextField(name: 'textField'),
            StreamBuilder<FormBuilderFields>(
              stream: _formKey.currentState?.onChanged, // (b)
              builder: (context, snapshot) {
                return Text(snapshot.data.toString());
              },
            ),
          ],
        ),
      ),
    );
  }
}
```
<p>On line (a), I initialize a <code>GlobalKey</code> with type <code>FormBuilderState</code>. I also need to use a <code>StreamBuilder</code>. On line (b), I use <code>currentState</code> on <code>_formKey</code>, but <code>currentState</code> is guaranteed to be <code>null</code> on the first render. And <code>StatelessWidget</code>s render once.</p>
<p>So, my question is: How can I make sure <code>currentState</code> of a <code>GlobalKey</code> is initialized (not null) in a <code>StatelessWidget</code>, which renders once?</p>
<p>Thanks in advance.</p>
<hr />
<h1>Environment</h1>
<p>I use flutter_form_builder and I am currently implementing this PR.</p>
<p>Flutter Doctor with verbose flag:</p>
```[✓] Flutter (Channel stable, 3.3.9, on Fedora Linux 36 (KDE Plasma) 6.0.17-200.fc36.x86_64, locale en_US.UTF-8)
    • Flutter version 3.3.9 on channel stable at /home/erayerdin/.local/lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (7 weeks ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /home/erayerdin/.sdks/android/
    • Platform android-33, build-tools 33.0.0
    • ANDROID_SDK_ROOT = /home/erayerdin/.sdks/android
    • Java binary at: /var/lib/snapd/snap/android-studio/125/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 14.0.5 (Fedora 14.0.5-2.fc36)
    • cmake version 3.25.1
    • ninja version 1.10.2
    • pkg-config version 1.8.0

[✓] Android Studio (version 2021.3)
    • Android Studio at /var/lib/snapd/snap/android-studio/125/android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.56.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Fedora Linux 36 (KDE Plasma) 6.0.17-200.fc36.x86_64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 108.0.5359.124

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
```

Body:
I have a StatelessWidget as below:

class StatelessStreamPage extends StatelessWidget {
  final _formKey = GlobalKey<FormBuilderState>(); // (a)

  StatelessStreamPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Stateless Stream Page'),
      ),
      body: FormBuilder(
        key: _formKey,
        child: Column(
          children: [
            FormBuilderTextField(name: 'textField'),
            StreamBuilder<FormBuilderFields>(
              stream: _formKey.currentState?.onChanged, // (b)
              builder: (context, snapshot) {
                return Text(snapshot.data.toString());
              },
            ),
          ],
        ),
      ),
    );
  }
}

On line (a), I initialize a GlobalKey with type FormBuilderState. I also need to use a StreamBuilder. On line (b), I use currentState on _formKey, but currentState is guaranteed to be null on the first render. And StatelessWidgets render once.

So, my question is: How can I make sure currentState of a GlobalKey is initialized (not null) in a StatelessWidget, which renders once?

Thanks in advance.

Environment

I use flutter_form_builder and I am currently implementing this PR.

Flutter Doctor with verbose flag:

[✓] Flutter (Channel stable, 3.3.9, on Fedora Linux 36 (KDE Plasma) 6.0.17-200.fc36.x86_64, locale en_US.UTF-8)
    • Flutter version 3.3.9 on channel stable at /home/erayerdin/.local/lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (7 weeks ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /home/erayerdin/.sdks/android/
    • Platform android-33, build-tools 33.0.0
    • ANDROID_SDK_ROOT = /home/erayerdin/.sdks/android
    • Java binary at: /var/lib/snapd/snap/android-studio/125/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 14.0.5 (Fedora 14.0.5-2.fc36)
    • cmake version 3.25.1
    • ninja version 1.10.2
    • pkg-config version 1.8.0

[✓] Android Studio (version 2021.3)
    • Android Studio at /var/lib/snapd/snap/android-studio/125/android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.56.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Fedora Linux 36 (KDE Plasma) 6.0.17-200.fc36.x86_64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 108.0.5359.124

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!


来源: stackexchange

问:
react native application metro errors
I am building a react native application and I started getting some random metro errors with seemingly no source.

There also seems to be lots of warnings spammed into the metro console:

```<code>transform[stderr]: The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding
transform[stderr]:      ["@babel/plugin-proposal-private-methods", { "loose": true }]
transform[stderr]: to the "plugins" section of your Babel config.
</code>```

I have tried a number of things such as:

deleting node_modules folder and re-downloading

cleaning android build

Adding the plugins to babel config as mentioned in the above console log

My current package.json is:

```<code>{
  "name": "MyApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/plugin-proposal-private-methods": "^7.18.6",
    "@babel/plugin-proposal-private-property-in-object": "^7.20.5",
    "@babel/preset-env": "^7.20.2",
    "@babel/preset-stage-2": "^7.8.3",
    "@react-native-community/async-storage": "^1.12.1",
    "@react-navigation/core": "6.2.2",
    "@react-navigation/drawer": "^6.5.0",
    "@react-navigation/native": "6.0.6",
    "@react-navigation/stack": "6.0.11",
    "@reduxjs/toolkit": "^1.8.5",
    "@types/react": "^18.0.21",
    "axios": "0.26.0",
    "deprecated-react-native-prop-types": "^2.3.0",
    "moment": "^2.29.4",
    "patch-package": "^6.4.7",
    "react": "18.1.0",
    "react-native": "0.70.2",
    "react-native-camera": "^4.2.1",
    "react-native-document-picker": "^8.1.1",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.7.0",
    "react-native-input-prompt": "^1.0.0",
    "react-native-paper": "^4.12.5",
    "react-native-popup-menu": "^0.16.1",
    "react-native-reanimated": "^2.12.0",
    "react-native-safe-area-context": "^4.4.1",
    "react-native-screens": "^3.18.0",
    "react-native-uuid": "^2.0.1",
    "react-native-vector-icons": "^9.2.0",
    "react-redux": "^8.0.4",
    "rn-fetch-blob": "^0.12.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "0.72.3",
    "react-test-renderer": "18.1.0"
  },
  "jest": {
    "preset": "react-native"
  }
}
</code>```

My babel config:

```<code>module.exports = {
  presets: ['module:metro-react-native-babel-preset', '@babel/preset-env'],
  plugins: ['react-native-reanimated/plugin']
};
</code>```

Any thoughts?

ContentLicense: CC BY-SA 4.0

Title: react native application metro errors

Body:
I am building a react native application and I started getting some random metro errors with seemingly no source.

There also seems to be lots of warnings spammed into the metro console:

transform[stderr]: The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding
transform[stderr]:      ["@babel/plugin-proposal-private-methods", { "loose": true }]
transform[stderr]: to the "plugins" section of your Babel config.

I have tried a number of things such as:

deleting node_modules folder and re-downloading

cleaning android build

Adding the plugins to babel config as mentioned in the above console log

My current package.json is:

{
  "name": "MyApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/plugin-proposal-private-methods": "^7.18.6",
    "@babel/plugin-proposal-private-property-in-object": "^7.20.5",
    "@babel/preset-env": "^7.20.2",
    "@babel/preset-stage-2": "^7.8.3",
    "@react-native-community/async-storage": "^1.12.1",
    "@react-navigation/core": "6.2.2",
    "@react-navigation/drawer": "^6.5.0",
    "@react-navigation/native": "6.0.6",
    "@react-navigation/stack": "6.0.11",
    "@reduxjs/toolkit": "^1.8.5",
    "@types/react": "^18.0.21",
    "axios": "0.26.0",
    "deprecated-react-native-prop-types": "^2.3.0",
    "moment": "^2.29.4",
    "patch-package": "^6.4.7",
    "react": "18.1.0",
    "react-native": "0.70.2",
    "react-native-camera": "^4.2.1",
    "react-native-document-picker": "^8.1.1",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.7.0",
    "react-native-input-prompt": "^1.0.0",
    "react-native-paper": "^4.12.5",
    "react-native-popup-menu": "^0.16.1",
    "react-native-reanimated": "^2.12.0",
    "react-native-safe-area-context": "^4.4.1",
    "react-native-screens": "^3.18.0",
    "react-native-uuid": "^2.0.1",
    "react-native-vector-icons": "^9.2.0",
    "react-redux": "^8.0.4",
    "rn-fetch-blob": "^0.12.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "0.72.3",
    "react-test-renderer": "18.1.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

My babel config:

module.exports = {
  presets: ['module:metro-react-native-babel-preset', '@babel/preset-env'],
  plugins: ['react-native-reanimated/plugin']
};

Any thoughts?


问:
What are the possible failed test cases and how to solve

def is_prime(string):

    string=string.split()
    length=len(string)
    list1=[]
    total=0

    for char in string:
        if char==0 or char==1:
            list1=list1+char
            print(list1)
        count=0

        for j in range(1,int(char)+1):
            if int(char)%j==0:
                count=count+1

        if count<=2:
            total=total+int(char)

    print(total)

string=input()
```

I want  possible failed test cases and how to solve with same code i have provided,i wa the same code back with changes

Body:
def is_prime(string):

    string=string.split()
    length=len(string)
    list1=[]
    total=0

    for char in string:
        if char==0 or char==1:
            list1=list1+char
            print(list1)
        count=0

        for j in range(1,int(char)+1):
            if int(char)%j==0:
                count=count+1

        if count<=2:
            total=total+int(char)

    print(total)

string=input()

I want  possible failed test cases and how to solve with same code i have provided,i wa the same code back with changes


问:
Getting Axios error in my code...can anyone help me to solve this error
POST http://localhost:5000/user/signup 500 (Internal Server Error)

AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}code: "ERR_BAD_RESPONSE"config: {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}message: "Request failed with status code 500"name: "AxiosError"request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}response: {data: 'Something went wrong...', status: 500, statusText: 'Internal Server Error', headers: AxiosHeaders, config: {…}, …}stack: "AxiosError: Request failed with status code 500\n    at settle (http://localhost:3000/static/js/bundle.js:55089:12)\n    at XMLHttpRequest.onloadend (http://localhost:3000/static/js/bundle.js:53797:66)"[[Prototype]]: Error

api/index.js

```<code>import axios from 'axios'

const API = axios.create({ baseURL: 'http://localhost:5000'})

export const logIn = (authData) => API.post('/user/login',authData);
export const signUp = (authData) => API.post('/user/signup',authData);

</code>```

actions/auth.js

```<code>import * as api from '../api'

export const signup = (authData, navigate) => async (dispatch) => {
    try{
        const { data } = await api.signUp(authData)
        dispatch({ type: 'AUTH',data})
        navigate('/')
    }catch(error){
        console.log(error)
    }
}

export const login = (authData, navigate) => async (dispatch) => {
    try{
        const { data } = await api.signUp(authData)
        dispatch({ type: 'AUTH',data})
        navigate('/')
    }catch(error){
        console.log(error)
    }
}
</code>```

src/index.js

```<code>import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose} from 'redux'
import thunk from 'redux-thunk'
import Reducers from './reducers'

const store = createStore( Reducers, compose(applyMiddleware(thunk)))

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <Provider store={store}>
  <React.StrictMode>
    <App />
  </React.StrictMode>
  </Provider>,
);

</code>```

reducers/auth.js

```<code>const authReducer = (state = {data:null}, action) => {
    switch (action.type){
        case 'AUTH':
            localStorage.setItem('Profile', JSON.stringify({...action?.data}))
            return {...state, data: action?.data }
        default:
            return state;
    }
}

export default authReducer
</code>```

reducers/index.js

```<code>import { combineReducers } from "redux";
import authReducer from "./auth";

export default combineReducers({
    authReducer
})

</code>```

server/users.js

```<code>import express from 'express';

import { login, signup} from '../controllers/auth.js'

const router = express.Router();

router.post('/signup',signup)
router.post('/login',login)

export default router
</code>```

server/index.js

```<code>import express from 'express'
import mongoose from 'mongoose'
import cors from 'cors'

import userRoutes from './routes/users.js'

const app = express();
app.use(express.json({limit: "30mb", extended: true}))
app.use(express.urlencoded({limit: "30mb", extended: true}))
app.use(cors());

app.get('/',(req,res) => {
    res.send("This is a Stack Overflow clone API")
})

app.use('/user', userRoutes)

const PORT = process.env.PORT || 5000

const CONNECTION_URL = "mongodb+srv://admin:admin@stack-overflow-clone.wuh9b1v.mongodb.net/?retryWrites=true&w=majority"

mongoose.connect( CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true})
    .then(() => app.listen(PORT, () => {console.log(`server running on port ${PORT}`)}))
    .catch((err) => console.log(err.message))
</code>```

Body:
POST http://localhost:5000/user/signup 500 (Internal Server Error)

AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}code: "ERR_BAD_RESPONSE"config: {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}message: "Request failed with status code 500"name: "AxiosError"request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}response: {data: 'Something went wrong...', status: 500, statusText: 'Internal Server Error', headers: AxiosHeaders, config: {…}, …}stack: "AxiosError: Request failed with status code 500\n    at settle (http://localhost:3000/static/js/bundle.js:55089:12)\n    at XMLHttpRequest.onloadend (http://localhost:3000/static/js/bundle.js:53797:66)"[[Prototype]]: Error

api/index.js

import axios from 'axios'

const API = axios.create({ baseURL: 'http://localhost:5000'})

export const logIn = (authData) => API.post('/user/login',authData);
export const signUp = (authData) => API.post('/user/signup',authData);

actions/auth.js

import * as api from '../api'

export const signup = (authData, navigate) => async (dispatch) => {
    try{
        const { data } = await api.signUp(authData)
        dispatch({ type: 'AUTH',data})
        navigate('/')
    }catch(error){
        console.log(error)
    }
}

export const login = (authData, navigate) => async (dispatch) => {
    try{
        const { data } = await api.signUp(authData)
        dispatch({ type: 'AUTH',data})
        navigate('/')
    }catch(error){
        console.log(error)
    }
}

src/index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose} from 'redux'
import thunk from 'redux-thunk'
import Reducers from './reducers'

const store = createStore( Reducers, compose(applyMiddleware(thunk)))

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <Provider store={store}>
  <React.StrictMode>
    <App />
  </React.StrictMode>
  </Provider>,
);

reducers/auth.js

const authReducer = (state = {data:null}, action) => {
    switch (action.type){
        case 'AUTH':
            localStorage.setItem('Profile', JSON.stringify({...action?.data}))
            return {...state, data: action?.data }
        default:
            return state;
    }
}

export default authReducer

reducers/index.js

import { combineReducers } from "redux";
import authReducer from "./auth";

export default combineReducers({
    authReducer
})

server/users.js

import express from 'express';

import { login, signup} from '../controllers/auth.js'

const router = express.Router();

router.post('/signup',signup)
router.post('/login',login)

export default router

server/index.js

import express from 'express'
import mongoose from 'mongoose'
import cors from 'cors'

import userRoutes from './routes/users.js'

const app = express();
app.use(express.json({limit: "30mb", extended: true}))
app.use(express.urlencoded({limit: "30mb", extended: true}))
app.use(cors());

app.get('/',(req,res) => {
    res.send("This is a Stack Overflow clone API")
})

app.use('/user', userRoutes)

const PORT = process.env.PORT || 5000

const CONNECTION_URL = "mongodb+srv://admin:admin@stack-overflow-clone.wuh9b1v.mongodb.net/?retryWrites=true&w=majority"

mongoose.connect( CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true})
    .then(() => app.listen(PORT, () => {console.log(`server running on port ${PORT}`)}))
    .catch((err) => console.log(err.message))


问:
NOTICE: relation "_data" already exists, skipping
I am loading tables with limit/offset with the PG gem in Ruby, and for large tables with "pages" in the hundreds are producing this message in the log:

NOTICE: relation "_data" already exists, skipping

The data seems to be loading just fine, but I am a little uneasy about this, I wonder if its just some internal stuff of postgres or the gem, or I am doing something wrong and maybe losing rows.

I am not defining this _data anywhere, that is why I think, it is something pg does internally.
The code that produces this looks like this:

```<code>conn.exec("INSERT INTO #{table_name} (#{column_list}, id_orig)
                SELECT * FROM dblink('conn_#{table_name}',
                  'SELECT #{column_list}, id as id_orig
                   FROM #{table_name}
                   ORDER BY id ASC
                   LIMIT #{BATCH_SIZE} OFFSET #{page * BATCH_SIZE}') AS t(#{table_def}, id_orig bigint);") do |result|
      result.each do |record|
        print record
      end
    end
</code>```

Body:
I am loading tables with limit/offset with the PG gem in Ruby, and for large tables with "pages" in the hundreds are producing this message in the log:

NOTICE: relation "_data" already exists, skipping

The data seems to be loading just fine, but I am a little uneasy about this, I wonder if its just some internal stuff of postgres or the gem, or I am doing something wrong and maybe losing rows.

I am not defining this _data anywhere, that is why I think, it is something pg does internally.
The code that produces this looks like this:

conn.exec("INSERT INTO #{table_name} (#{column_list}, id_orig)
                SELECT * FROM dblink('conn_#{table_name}',
                  'SELECT #{column_list}, id as id_orig
                   FROM #{table_name}
                   ORDER BY id ASC
                   LIMIT #{BATCH_SIZE} OFFSET #{page * BATCH_SIZE}') AS t(#{table_def}, id_orig bigint);") do |result|
      result.each do |record|
        print record
      end
    end


问:
json errors after rails upgrade
I upgraded from rails 3.0.4 to 3.1.0. Then I started getting these error messages when running rails server, I had to change a couple of initializers like this:from wrap_parameters format: [:json] to wrap_parameters :format => [:json]

Now WEBrick does start up but I get A LOT of these messages: syntax error, unexpected ':', expecting '=' ...er json: @page.errors, status: :unprocessable_entity }

ContentLicense: CC BY-SA 3.0

Title: json errors after rails upgrade


问:
Linkedin OAuth2
I'm testing the usability of Oauth.io. Wokking with for example twitter goes well, but I can't get Linkedin Oauth2 to work. Get an 'internal error'. If I debug I find "Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'done')". I guess the problem is in the code:

```<code>OAuth.initialize("jYfu7aahkO52Qc4lGA6jGVfeim0");

//Example with Google
OAuth.redirect("Linkedin (OAuth2)", "https://atforce.nl");

//in your callback page (can be the same page)
OAuth.callback("Linkedin (OAuth2)")
    .done(function (LinkedinOAuth2) {
//make API calls with `google`
    })
        .fail(function (err) {
        console.log("Something went wrong!!!");
//todo when the OAuth flow failed
  });
</code>```

Someone to help me out?

René

Tried to replace the 'function(LinkedinOAuth2)' with different parms.

Title: Linkedin OAuth2

Body:
I'm testing the usability of Oauth.io. Wokking with for example twitter goes well, but I can't get Linkedin Oauth2 to work. Get an 'internal error'. If I debug I find "Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'done')". I guess the problem is in the code:

OAuth.initialize("jYfu7aahkO52Qc4lGA6jGVfeim0");

//Example with Google
OAuth.redirect("Linkedin (OAuth2)", "https://atforce.nl");

//in your callback page (can be the same page)
OAuth.callback("Linkedin (OAuth2)")
    .done(function (LinkedinOAuth2) {
//make API calls with `google`
    })
        .fail(function (err) {
        console.log("Something went wrong!!!");
//todo when the OAuth flow failed
  });

Someone to help me out?

René

Tried to replace the 'function(LinkedinOAuth2)' with different parms.


问:
Is it possible to add text in the background of a google document?
I would like to make template whith text in the background. So that you can type over it with new Text. The text in the background will have a very light color, the text in the background will be black.

Easiest would be something like two layers but I can't find a way to do this (without using an image as background).


问:
Why using the code way is slower than using create ml
I use create ml to train the image classification model.

With the iteration of the function, I need to use the code to train to achieve the automation process.

However, when I use the code to train the model, the same data, the same parameters, but the executable file generated by the code, the training is very slow.

Create ml may only take tens of seconds, while the code often takes more than 20 minutes.

Here is code and pictures.

```<code>class CreateMLManager : NSObject {
    open var dataPath: String?
    open var outPath: String?

    public func training() -> Int {
        guard let dataPath = dataPath else {
            return 1
        }
        guard let outPath = outPath else {
            return 1
        }
        do {
            let aumentation : MLImageClassifier.ImageAugmentationOptions = [.crop, .rotation, .blur, .exposure, .noise, .flip];
            let parameters = MLImageClassifier.ModelParameters(validation: .split(strategy: .automatic),maxIterations: 11,augmentation: aumentation,algorithm: .transferLearning(featureExtractor: .scenePrint(revision: 1), classifier: .logisticRegressor))

            let out_path = outPath + "/test.mlmodel"
            let model = try MLImageClassifier(trainingData: .labeledDirectories(at: URL(fileURLWithPath: dataPath)), parameters:parameters)
            try model.write(to: URL(fileURLWithPath: out_path))
            return 0
        } catch {
            return 1
        }
    }
}
</code>```

Current working dir: /Users/wbw/Library/Developer/Xcode/DerivedData/mlmodelTransition-cdfkslvlaufvnagpypknnofdmgkv/Build/Products/Debug
2023-01-10 18:02:09.670712+0800 mlmodelTransition[1435:1935624] 训练数据:/Users/wbw/Desktop/Rashomon/work/company_library/ArWeb/web/ml_platform/temp/xjy
2023-01-10 18:02:09.671074+0800 mlmodelTransition[1435:1935624] 存储路径:/Users/wbw/Desktop/Rashomon/work/company_library/ArWeb/web/ml_platform/resource/training_model/xjy
4 augmented images by 'crop' to be generated.
4 augmented images by 'rotation' to be generated.
4 augmented images by 'blur' to be generated.
1 augmented images by 'exposure' to be generated.
1 augmented images by 'noise' to be generated.
1 augmented images by 'flip' to be generated.
Extracting augmented image features from training data.
Analyzing and extracting image features.
+----------------------+------------------+--------------+------------------+
Raw Images Processed | Augmented Images | Elapsed Time | Percent Complete |
+----------------------+------------------+--------------+------------------+
2023-01-10 18:02:11.132922+0800 mlmodelTransition[1435:1936088] Metal API Validation Enabled
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.212669+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.233004+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.252051+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.276394+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.297000+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.318678+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.340412+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.360359+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.379907+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 63687 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.397403+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 81029 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.416585+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.

create ml param

create ml training process

When I run the code, I keep getting warnings.

This warning is about cikernel's. I guess it has something to do with image processing, but I checked Apple's documentation and found no solution. I found a question about this error on stackoverflow, but I have no idea to solve the slow problem.

cikernel's warning.

I really don't know the difference between code training and program training

Body:
I use create ml to train the image classification model.

With the iteration of the function, I need to use the code to train to achieve the automation process.

However, when I use the code to train the model, the same data, the same parameters, but the executable file generated by the code, the training is very slow.

Create ml may only take tens of seconds, while the code often takes more than 20 minutes.

Here is code and pictures.

class CreateMLManager : NSObject {
    open var dataPath: String?
    open var outPath: String?

    public func training() -> Int {
        guard let dataPath = dataPath else {
            return 1
        }
        guard let outPath = outPath else {
            return 1
        }
        do {
            let aumentation : MLImageClassifier.ImageAugmentationOptions = [.crop, .rotation, .blur, .exposure, .noise, .flip];
            let parameters = MLImageClassifier.ModelParameters(validation: .split(strategy: .automatic),maxIterations: 11,augmentation: aumentation,algorithm: .transferLearning(featureExtractor: .scenePrint(revision: 1), classifier: .logisticRegressor))

            let out_path = outPath + "/test.mlmodel"
            let model = try MLImageClassifier(trainingData: .labeledDirectories(at: URL(fileURLWithPath: dataPath)), parameters:parameters)
            try model.write(to: URL(fileURLWithPath: out_path))
            return 0
        } catch {
            return 1
        }
    }
}

Current working dir: /Users/wbw/Library/Developer/Xcode/DerivedData/mlmodelTransition-cdfkslvlaufvnagpypknnofdmgkv/Build/Products/Debug
2023-01-10 18:02:09.670712+0800 mlmodelTransition[1435:1935624] 训练数据:/Users/wbw/Desktop/Rashomon/work/company_library/ArWeb/web/ml_platform/temp/xjy
2023-01-10 18:02:09.671074+0800 mlmodelTransition[1435:1935624] 存储路径:/Users/wbw/Desktop/Rashomon/work/company_library/ArWeb/web/ml_platform/resource/training_model/xjy
4 augmented images by 'crop' to be generated.
4 augmented images by 'rotation' to be generated.
4 augmented images by 'blur' to be generated.
1 augmented images by 'exposure' to be generated.
1 augmented images by 'noise' to be generated.
1 augmented images by 'flip' to be generated.
Extracting augmented image features from training data.
Analyzing and extracting image features.
+----------------------+------------------+--------------+------------------+
Raw Images Processed | Augmented Images | Elapsed Time | Percent Complete |
+----------------------+------------------+--------------+------------------+
2023-01-10 18:02:11.132922+0800 mlmodelTransition[1435:1936088] Metal API Validation Enabled
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.212669+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.233004+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.252051+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.276394+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.297000+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.318678+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.340412+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.360359+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.379907+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 63687 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.397403+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 81029 pixels because a CIKernel's ROI function did not allow tiling.
2023-01-10 18:02:11.416585+0800 mlmodelTransition[1435:1936088] [api] -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] Failed to render part of the image because memory requirement of -1 too big
Failed to render 89401 pixels because a CIKernel's ROI function did not allow tiling.

create ml param

create ml training process

When I run the code, I keep getting warnings.

This warning is about cikernel's. I guess it has something to do with image processing, but I checked Apple's documentation and found no solution. I found a question about this error on stackoverflow, but I have no idea to solve the slow problem.

cikernel's warning.

I really don't know the difference between code training and program training


问:
Function that, given a list with the quality scores of a fastq file, gives the average quality per base position
The main problem with my code is that it takes too long to create the dataset with the quality scores. It works perfectly for small files but not for big files, which are most fastq files. I reckon the problem is that I have too many "for" loops, but I don't know how to get rid of them or how to substitute them with something more efficient that does the same job, so calculating the average quality score (so you first have to convert the ASCII character into its code) per base position.</p>
```<code>def listtodf(qual_list, reads_c, maxl):
    col = list(range(0, maxl))

### I create an empty list with numbers from 0 to the maximum length of the reads. This will be the title of my columns

    df = pd.DataFrame(columns=col)

### I create an empty df that will be filled with all quality scores (in number). The number of rows will be the same as reads_c (so last row will have # reads_c-1) and the number of columns will be the same as maxl (so last column will have # maxl-1)

    for i in range (0, reads_c):

### I iterate from 0 to the total number of reads to get one string at a time

        strofint = qual_list[i]

### I take each string

        chlist = [(ord(i)-33) for i in strofint]

### I create a list with the numbers corresponding to the ASCII code of the quality score of each line

        chlist = pd.Series(chlist)

### I transform it into a series so that I can merge them together to form the df

        df.loc[len(df)] = chlist

### I add each chlist to the dataframe as a row (= I add it at the end) so that I get the whole df

    print(df)
    return(df)
</code>```

Body:
The main problem with my code is that it takes too long to create the dataset with the quality scores. It works perfectly for small files but not for big files, which are most fastq files. I reckon the problem is that I have too many "for" loops, but I don't know how to get rid of them or how to substitute them with something more efficient that does the same job, so calculating the average quality score (so you first have to convert the ASCII character into its code) per base position.

def listtodf(qual_list, reads_c, maxl):
    col = list(range(0, maxl))

### I create an empty list with numbers from 0 to the maximum length of the reads. This will be the title of my columns

    df = pd.DataFrame(columns=col)

### I create an empty df that will be filled with all quality scores (in number). The number of rows will be the same as reads_c (so last row will have # reads_c-1) and the number of columns will be the same as maxl (so last column will have # maxl-1)

    for i in range (0, reads_c):

### I iterate from 0 to the total number of reads to get one string at a time

        strofint = qual_list[i]

### I take each string

        chlist = [(ord(i)-33) for i in strofint]

### I create a list with the numbers corresponding to the ASCII code of the quality score of each line

        chlist = pd.Series(chlist)

### I transform it into a series so that I can merge them together to form the df

        df.loc[len(df)] = chlist

### I add each chlist to the dataframe as a row (= I add it at the end) so that I get the whole df

    print(df)
    return(df)


问:
How to figure out what kind of encryption or what the pseudocode is doing?
I am trying to analyse a ransomware sample and through IDA-Pro I came across this function which seemed to be doing some sort of string copying and memory management, which could possibly be leading to encryption. Here is the code snippet:

```<code>__int64 __fastcall dk_what_it_means_but_note(__int64 a1, __int64 a2, __int64 a3)
{
  int v3; // eax
  int v4; // r9d
  int v5; // edx
  __int64 v6; // r8
  int v7; // r10d
  unsigned __int64 v8; // rsi
  unsigned __int64 v9; // rdx
  int v10; // eax
  bool v11; // sf
  int v12; // edx
  int v13; // eax
  signed int v14; // edx
  char v15; // r10

  *(_QWORD *)(a1 + 256) = a2;
  *(_QWORD *)(a1 + 264) = a3;
  *(_OWORD *)a1 = xmmword_140035E60;
  *(_OWORD *)(a1 + 16) = xmmword_140035E70;
  qmemcpy((void *)(a1 + 32), " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmno", 80);// copying that srting into memory
  *(_OWORD *)(a1 + 112) = xmmword_140035ED0;
  *(_OWORD *)(a1 + 128) = xmmword_140035EE0;
  *(_OWORD *)(a1 + 144) = xmmword_140035EF0;
  *(_OWORD *)(a1 + 160) = xmmword_140035F00;
  *(_OWORD *)(a1 + 176) = xmmword_140035F10;
  *(_OWORD *)(a1 + 192) = xmmword_140035F20;
  *(_OWORD *)(a1 + 208) = xmmword_140035F30;
  *(_OWORD *)(a1 + 224) = xmmword_140035F40;
  *(_OWORD *)(a1 + 240) = xmmword_140035F50;
  *(_QWORD *)(a1 + 272) = 0i64;
  v3 = 0;
  v4 = 255;
  v5 = 0;
  while ( 1 )
  {
    v6 = v3;
    v7 = v5 + *(unsigned __int8 *)(a1 + v3);
    v8 = *(_QWORD *)(a1 + 264);
    v9 = (v8 | v3) >> 32 ? v3 % v8 : v3 % (unsigned int)v8;
    v10 = *(unsigned __int8 *)(*(_QWORD *)(a1 + 256) + v9);
    v11 = v10 + v7 < 0;
    v12 = v10 + v7;
    v13 = v7 + v10 + 255;
    if ( !v11 )
      v13 = v12;
    v14 = v12 - (v13 & 0xFFFFFF00);
    *(_DWORD *)(a1 + 276) = v14;
    v15 = *(_BYTE *)(a1 + v6);
    *(_BYTE *)(a1 + v6) = *(_BYTE *)(a1 + v14);
    *(_BYTE *)(a1 + v14) = v15;
    v3 = *(_DWORD *)(a1 + 272) + 1;
    *(_DWORD *)(a1 + 272) = v3;
    if ( !v4 )
      break;
    v5 = *(_DWORD *)(a1 + 276);
    --v4;
  }
  *(_QWORD *)(a1 + 272) = 0i64;
  return a1;
}
</code>```

it is kind of hard to keep track of the variables and how they are working but I understand that a1 is some big array and we are copying some data into it? I also dont quite understand some of these data types so any help on that like "xmmword" would be great too

I have been trying to analyse what this piece of code exactly does and I am not sure I am on the right track or this code is even relevant at all.

Body:
I am trying to analyse a ransomware sample and through IDA-Pro I came across this function which seemed to be doing some sort of string copying and memory management, which could possibly be leading to encryption. Here is the code snippet:

__int64 __fastcall dk_what_it_means_but_note(__int64 a1, __int64 a2, __int64 a3)
{
  int v3; // eax
  int v4; // r9d
  int v5; // edx
  __int64 v6; // r8
  int v7; // r10d
  unsigned __int64 v8; // rsi
  unsigned __int64 v9; // rdx
  int v10; // eax
  bool v11; // sf
  int v12; // edx
  int v13; // eax
  signed int v14; // edx
  char v15; // r10

  *(_QWORD *)(a1 + 256) = a2;
  *(_QWORD *)(a1 + 264) = a3;
  *(_OWORD *)a1 = xmmword_140035E60;
  *(_OWORD *)(a1 + 16) = xmmword_140035E70;
  qmemcpy((void *)(a1 + 32), " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmno", 80);// copying that srting into memory
  *(_OWORD *)(a1 + 112) = xmmword_140035ED0;
  *(_OWORD *)(a1 + 128) = xmmword_140035EE0;
  *(_OWORD *)(a1 + 144) = xmmword_140035EF0;
  *(_OWORD *)(a1 + 160) = xmmword_140035F00;
  *(_OWORD *)(a1 + 176) = xmmword_140035F10;
  *(_OWORD *)(a1 + 192) = xmmword_140035F20;
  *(_OWORD *)(a1 + 208) = xmmword_140035F30;
  *(_OWORD *)(a1 + 224) = xmmword_140035F40;
  *(_OWORD *)(a1 + 240) = xmmword_140035F50;
  *(_QWORD *)(a1 + 272) = 0i64;
  v3 = 0;
  v4 = 255;
  v5 = 0;
  while ( 1 )
  {
    v6 = v3;
    v7 = v5 + *(unsigned __int8 *)(a1 + v3);
    v8 = *(_QWORD *)(a1 + 264);
    v9 = (v8 | v3) >> 32 ? v3 % v8 : v3 % (unsigned int)v8;
    v10 = *(unsigned __int8 *)(*(_QWORD *)(a1 + 256) + v9);
    v11 = v10 + v7 < 0;
    v12 = v10 + v7;
    v13 = v7 + v10 + 255;
    if ( !v11 )
      v13 = v12;
    v14 = v12 - (v13 & 0xFFFFFF00);
    *(_DWORD *)(a1 + 276) = v14;
    v15 = *(_BYTE *)(a1 + v6);
    *(_BYTE *)(a1 + v6) = *(_BYTE *)(a1 + v14);
    *(_BYTE *)(a1 + v14) = v15;
    v3 = *(_DWORD *)(a1 + 272) + 1;
    *(_DWORD *)(a1 + 272) = v3;
    if ( !v4 )
      break;
    v5 = *(_DWORD *)(a1 + 276);
    --v4;
  }
  *(_QWORD *)(a1 + 272) = 0i64;
  return a1;
}

it is kind of hard to keep track of the variables and how they are working but I understand that a1 is some big array and we are copying some data into it? I also dont quite understand some of these data types so any help on that like "xmmword" would be great too

I have been trying to analyse what this piece of code exactly does and I am not sure I am on the right track or this code is even relevant at all.


问:
ExcelCreator need 1.4 GB RAM when open 14MB Excel file
I am using the ExcelCreator library to process a 14MB Excel file. However, it takes up 1.4GB of RAM when opening it.

How to reduce memory?
When opening the file with Microsoft Excel, it only takes up 300MB of RAM

```<code>public void open(string filepath)
        {
            creator = new Creator();
            creator.OpenBookEx(filepath, "", ref info);
        }
</code>```

Body:
I am using the ExcelCreator library to process a 14MB Excel file. However, it takes up 1.4GB of RAM when opening it.

How to reduce memory?
When opening the file with Microsoft Excel, it only takes up 300MB of RAM

public void open(string filepath)
        {
            creator = new Creator();
            creator.OpenBookEx(filepath, "", ref info);
        }


问:
How do I use all cores of my CPU in reinforcement learning with TF Agents?
I work with an RL algorithm. I'm using tensorflow and tf-agents and training a DQN. My problem is that only one core of the CPU is used when calculating the 10 episodes in the environment for data collection.

My training function looks like this:

def train_step(self, n_steps):

    env_steps = tf_metrics.EnvironmentSteps()
    #num_episodes = tf_metrics.NumberOfEpisodes()
    rew = TFSumOfRewards()
    action_hist = tf_metrics.ChosenActionHistogram(
        name='ChosenActionHistogram', dtype=tf.int32, buffer_size=1000
        )

    #add reply buffer and metrict to the observer
    replay_observer = [self.replay_buffer.add_batch]
    train_metrics = [env_steps, rew]

    self.replay_buffer.clear()

    driver = dynamic_episode_driver.DynamicEpisodeDriver(
        self.train_env, self.collect_policy, observers=replay_observer + train_metrics, num_episodes=self.collect_episodes)

    final_time_step, policy_state = driver.run()

    print('Number of Steps: ', env_steps.result().numpy())

    for train_metric in train_metrics:
        train_metric.tf_summaries(train_step=self.global_step, step_metrics=train_metrics)

    # Convert the replay buffer to a tf.data.Dataset
    # Dataset generates trajectories with shape [Bx2x...]
    AUTOTUNE = tf.data.experimental.AUTOTUNE
    dataset = self.replay_buffer.as_dataset(
        num_parallel_calls=AUTOTUNE,
        sample_batch_size=self.batch_size,
        num_steps=(self.train_sequence_length + 1)).prefetch(AUTOTUNE)

    iterator = iter(dataset)

    train_loss = None
    for _ in range(n_steps):
        # Sample a batch of data from the buffer and update the agent's network.
        experience, unused_info = next(iterator)
        train_loss = self.agent.train(experience)

def train_agent(self, n_epoch):
    for i in range(n_epoch):
        self.train_step(int(self.replay_buffer.num_frames().numpy()/self.batch_size))
        if(self.IsAutoStoreCheckpoint == True):
            self.store_check_point()
    pass
```

As already written above, num_episodes = 10. So it would make sense to calculate 10 episodes in parallel before the network is trained.
If I set the value num_parallel_calls to e.g. 10 nothing changes. What do I have to do to use all cores of my CPU (Ryzen 9 5950x with 16 cores)?

Thanks!

masterkey

Body:
I work with an RL algorithm. I'm using tensorflow and tf-agents and training a DQN. My problem is that only one core of the CPU is used when calculating the 10 episodes in the environment for data collection.

My training function looks like this:

def train_step(self, n_steps):

    env_steps = tf_metrics.EnvironmentSteps()
    #num_episodes = tf_metrics.NumberOfEpisodes()
    rew = TFSumOfRewards()
    action_hist = tf_metrics.ChosenActionHistogram(
        name='ChosenActionHistogram', dtype=tf.int32, buffer_size=1000
        )

    #add reply buffer and metrict to the observer
    replay_observer = [self.replay_buffer.add_batch]
    train_metrics = [env_steps, rew]

    self.replay_buffer.clear()

    driver = dynamic_episode_driver.DynamicEpisodeDriver(
        self.train_env, self.collect_policy, observers=replay_observer + train_metrics, num_episodes=self.collect_episodes)

    final_time_step, policy_state = driver.run()

    print('Number of Steps: ', env_steps.result().numpy())

    for train_metric in train_metrics:
        train_metric.tf_summaries(train_step=self.global_step, step_metrics=train_metrics)

    # Convert the replay buffer to a tf.data.Dataset
    # Dataset generates trajectories with shape [Bx2x...]
    AUTOTUNE = tf.data.experimental.AUTOTUNE
    dataset = self.replay_buffer.as_dataset(
        num_parallel_calls=AUTOTUNE,
        sample_batch_size=self.batch_size,
        num_steps=(self.train_sequence_length + 1)).prefetch(AUTOTUNE)

    iterator = iter(dataset)

    train_loss = None
    for _ in range(n_steps):
        # Sample a batch of data from the buffer and update the agent's network.
        experience, unused_info = next(iterator)
        train_loss = self.agent.train(experience)

def train_agent(self, n_epoch):
    for i in range(n_epoch):
        self.train_step(int(self.replay_buffer.num_frames().numpy()/self.batch_size))
        if(self.IsAutoStoreCheckpoint == True):
            self.store_check_point()
    pass

As already written above, num_episodes = 10. So it would make sense to calculate 10 episodes in parallel before the network is trained.
If I set the value num_parallel_calls to e.g. 10 nothing changes. What do I have to do to use all cores of my CPU (Ryzen 9 5950x with 16 cores)?

Thanks!

masterkey


问:
How do I see the name of the referenced library in the Isabelle 2020 version
I am running the validation script of sel4, because it runs on Isabelle 2020 version, but it reports an error "Bad theory import HOL-Library.Word", I don't know how to solve this error, please help, thank you.

I found in my browser that "HOL-Word" has been changed to "HOL-Library.Word" in the 2021 version, but I tried and failed


问:
send notification from background worker
am using ABP to build my project
I have a module to generate big size files using background worker, and after each successful file generated I need to send notification, but is not working !

I've put the background job in the core project and the queue in the engine project,
the DB notification tables are updated successfully (new record inserted so the pull notification will work fine !), but the browser doesn't receive the notification (so I can inform him that his file is ready), but there is no errors and no any notification send to the browser.

here is the worker class:

```<code> public class GeneratedFileWorker : BackgroundWorkerBase, ISingletonDependency
{
.
.
.

    [UnitOfWork]
    [AutomaticRetry(Attempts = 0)]
    public override async System.Threading.Tasks.Task ExecuteAsync()
    {
        var notificationData = new NotificationData();
        notificationData["URL"] = "app/main/data/generatedfiles";

        using (AbpSession.Use(TenantConsts.DefaultTenantId, TenantConsts.UserServiceId))
        {

            GetDownloadArticleInput getDownloadArticleInput = new GetDownloadArticleInput();

            if (pendingRequest is not null)
            {
                var entityType = _lookupItemManager.Get(pendingRequest.EntityTypeId).Code;
                dynamic Args = JsonConvert.DeserializeObject<GetDownloadArticleInput>(String.Empty);

                switch (entityType)
                {
                    case "Article":
                        Args = JsonConvert.DeserializeObject<GetDownloadArticleInput>(pendingRequest.ExtensionData);
                        break;
                    case "ArticlesList":
                        Args = JsonConvert.DeserializeObject<GetDownloadArticlesInput>(pendingRequest.ExtensionData);
                        break;

                };

                GeneratedFile generatedFileDto = new GeneratedFile();
                try
                {

                    generatedFileDto = await _generateFile.Generate(Args);

                    await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value),string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsNotready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Error);
                else
                    await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value), string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Success);
                }
                catch (Exception ex)
                {
                    pendingRequest.CurrentStateId = _lookupItemManager.GetByCode(LookupCategories.GeneratedFileStatus, "Failed").Id;
                    pendingRequest.OperationResult = ex.ToString();
                    await _generatedFileRepository.UpdateAsync(pendingRequest);
                    await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value), string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsNotready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Error);
                }
            }
    }
}
</code>```

I have 2 cases here:
first one working when I define the queue in the host project, and
second one not working when I define the queue in the engine project

Body:
am using ABP to build my project
I have a module to generate big size files using background worker, and after each successful file generated I need to send notification, but is not working !

I've put the background job in the core project and the queue in the engine project,
the DB notification tables are updated successfully (new record inserted so the pull notification will work fine !), but the browser doesn't receive the notification (so I can inform him that his file is ready), but there is no errors and no any notification send to the browser.

here is the worker class:

 public class GeneratedFileWorker : BackgroundWorkerBase, ISingletonDependency
{
.
.
.

    [UnitOfWork]
    [AutomaticRetry(Attempts = 0)]
    public override async System.Threading.Tasks.Task ExecuteAsync()
    {
        var notificationData = new NotificationData();
        notificationData["URL"] = "app/main/data/generatedfiles";

        using (AbpSession.Use(TenantConsts.DefaultTenantId, TenantConsts.UserServiceId))
        {

            GetDownloadArticleInput getDownloadArticleInput = new GetDownloadArticleInput();

            if (pendingRequest is not null)
            {
                var entityType = _lookupItemManager.Get(pendingRequest.EntityTypeId).Code;
                dynamic Args = JsonConvert.DeserializeObject<GetDownloadArticleInput>(String.Empty);

                switch (entityType)
                {
                    case "Article":
                        Args = JsonConvert.DeserializeObject<GetDownloadArticleInput>(pendingRequest.ExtensionData);
                        break;
                    case "ArticlesList":
                        Args = JsonConvert.DeserializeObject<GetDownloadArticlesInput>(pendingRequest.ExtensionData);
                        break;

                };

                GeneratedFile generatedFileDto = new GeneratedFile();
                try
                {

                    generatedFileDto = await _generateFile.Generate(Args);

                    await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value),string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsNotready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Error);
                else
                    await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value), string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Success);
                }
                catch (Exception ex)
                {
                    pendingRequest.CurrentStateId = _lookupItemManager.GetByCode(LookupCategories.GeneratedFileStatus, "Failed").Id;
                    pendingRequest.OperationResult = ex.ToString();
                    await _generatedFileRepository.UpdateAsync(pendingRequest);
                    await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value), string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsNotready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Error);
                }
            }
    }
}

I have 2 cases here:
first one working when I define the queue in the host project, and
second one not working when I define the queue in the engine project


问:
Should classes inheriting from MarshalByRefObject remove such inheritance after migrated to .NET 5+?
Im migrating a WPF app onto .NET5+, and I see some classes have inherited from MarshalByRefObject class.

Indeed, im not sure how it was used previously, and I myself have no practical experience using this.
I saw InitializeLifetimeService() has been overriden to simply return null, but I dont know what's the purpose of it also.

I had done some study/search and it seems that this class is here for remoting (but I don't see anywhere in the codebase using multiple app domains), which remoting itself no longer exists in .NET5+ (core) world.

While I have marked InitializeLifetimeService() obsolete for now to make my app compile,
question is:

Wonder if I should/can completely remove the inheritance from MarshalByRefObject?

or should I keep the class inherited from MarshalByRefObject and just remove any InitializeLifetimeService()/GetLifetimeService() (not sure if MarshalByRefObject still enable some functionality?)

Thanks for help!


问:
Read Excel file from OneDrive / Sharepoint - error code: File is not a zip file
I am trying to read an excel file from SharePoint to python and my first error message was that I should define an engine manually, so I defined the engine = 'openpyxl' and now the following error message comes up: File is not a ZIP File

From the previous Q&As it was often talked about if the Excel - file is a real Excel file or some text file with a fake xlsx extension.

The excel file was created using Microsoft Excel and its stored in a shared OneDrive folder (Team - Sharepoint). Does it affect the error message?

How can i solve this?

Many thanks in advance!

My Code:

```<code>from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File

url_sp = 'https://company.sharepoint.com/teams/TeamE'
username_sp = 'MyUsername'
password_sp = 'MyPassword'
folder_url_sp = '/Shared%20Documents/02%20Team%20IAP/06_Da-An/Data/E/Edate.xlsx'

#Authentication
ctx_auth = AuthenticationContext(url_sp)
if ctx_auth.acquire_token_for_user(username_sp, password_sp):
    ctx = ClientContext(url_sp, ctx_auth)
    web = ctx.web
    ctx.load(web)
    ctx.execute_query()
    print('Authentication sucessfull')

else:
    print(ctx_auth.get_last_error())

import io

response = File.open_binary(ctx,folder_url_sp)

bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0)

data = pd.read_excel(bytes_file_obj,sheet_name = None, engine = 'openpyxl')
</code>```

The Error:

```<code>BadZipFile                                Traceback (most recent call last)
Cell In[29], line 32
     29 bytes_file_obj.write(response.content)
     30 bytes_file_obj.seek(0)
---> 32 data = pd.read_excel(bytes_file_obj, sheet_name= None, engine = 'openpyxl')

File ~\Anaconda3\lib\site-packages\pandas\util\_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    305 if len(args) > num_allow_args:
    306     warnings.warn(
    307         msg.format(arguments=arguments),
    308         FutureWarning,
    309         stacklevel=stacklevel,
    310     )
--> 311 return func(*args, **kwargs)

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py:457, in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, decimal, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
    455 if not isinstance(io, ExcelFile):
    456     should_close = True
--> 457     io = ExcelFile(io, storage_options=storage_options, engine=engine)
    458 elif engine and engine != io.engine:
    459     raise ValueError(
    460         "Engine should not be specified when passing "
    461         "an ExcelFile - ExcelFile already has the engine set"
    462     )

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py:1419, in ExcelFile.__init__(self, path_or_buffer, engine, storage_options)
   1416 self.engine = engine
   1417 self.storage_options = storage_options
-> 1419 self._reader = self._engines[engine](self._io, storage_options=storage_options)

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_openpyxl.py:525, in OpenpyxlReader.__init__(self, filepath_or_buffer, storage_options)
    514 """
    515 Reader using openpyxl engine.
    516
   (...)
    522     passed to fsspec for appropriate URLs (see ``_get_filepath_or_buffer``)
    523 """
    524 import_optional_dependency("openpyxl")
--> 525 super().__init__(filepath_or_buffer, storage_options=storage_options)

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py:518, in BaseExcelReader.__init__(self, filepath_or_buffer, storage_options)
    516 self.handles.handle.seek(0)
    517 try:
--> 518     self.book = self.load_workbook(self.handles.handle)
    519 except Exception:
    520     self.close()

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_openpyxl.py:536, in OpenpyxlReader.load_workbook(self, filepath_or_buffer)
    533 def load_workbook(self, filepath_or_buffer: FilePath | ReadBuffer[bytes]):
    534     from openpyxl import load_workbook
--> 536     return load_workbook(
    537         filepath_or_buffer, read_only=True, data_only=True, keep_links=False
    538     )

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:315, in load_workbook(filename, read_only, keep_vba, data_only, keep_links)
    288 def load_workbook(filename, read_only=False, keep_vba=KEEP_VBA,
    289                   data_only=False, keep_links=True):
    290     """Open the given filename and return the workbook
    291
    292     :param filename: the path to open or a file-like object
   (...)
    313
    314     """
--> 315     reader = ExcelReader(filename, read_only, keep_vba,
    316                         data_only, keep_links)
    317     reader.read()
    318     return reader.wb

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:124, in ExcelReader.__init__(self, fn, read_only, keep_vba, data_only, keep_links)
    122 def __init__(self,  fn, read_only=False, keep_vba=KEEP_VBA,
    123               data_only=False, keep_links=True):
--> 124     self.archive = _validate_archive(fn)
    125     self.valid_files = self.archive.namelist()
    126     self.read_only = read_only

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:96, in _validate_archive(filename)
     89             msg = ('openpyxl does not support %s file format, '
     90                    'please check you can open '
     91                    'it with Excel first. '
     92                    'Supported formats are: %s') % (file_format,
     93                                                    ','.join(SUPPORTED_FORMATS))
     94         raise InvalidFileException(msg)
---> 96 archive = ZipFile(filename, 'r')
     97 return archive

File ~\Anaconda3\lib\zipfile.py:1266, in ZipFile.__init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
   1264 try:
   1265     if mode == 'r':
-> 1266         self._RealGetContents()
   1267     elif mode in ('w', 'x'):
   1268         # set the modified flag so central directory gets written
   1269         # even if no files are added to the archive
   1270         self._didModify = True

File ~\Anaconda3\lib\zipfile.py:1333, in ZipFile._RealGetContents(self)
   1331     raise BadZipFile("File is not a zip file")
   1332 if not endrec:
-> 1333     raise BadZipFile("File is not a zip file")
   1334 if self.debug > 1:
   1335     print(endrec)

BadZipFile: File is not a zip file

```
```

Body:
I am trying to read an excel file from SharePoint to python and my first error message was that I should define an engine manually, so I defined the engine = 'openpyxl' and now the following error message comes up: File is not a ZIP File

From the previous Q&As it was often talked about if the Excel - file is a real Excel file or some text file with a fake xlsx extension.

The excel file was created using Microsoft Excel and its stored in a shared OneDrive folder (Team - Sharepoint). Does it affect the error message?

How can i solve this?

Many thanks in advance!

My Code:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File

url_sp = 'https://company.sharepoint.com/teams/TeamE'
username_sp = 'MyUsername'
password_sp = 'MyPassword'
folder_url_sp = '/Shared%20Documents/02%20Team%20IAP/06_Da-An/Data/E/Edate.xlsx'

#Authentication
ctx_auth = AuthenticationContext(url_sp)
if ctx_auth.acquire_token_for_user(username_sp, password_sp):
    ctx = ClientContext(url_sp, ctx_auth)
    web = ctx.web
    ctx.load(web)
    ctx.execute_query()
    print('Authentication sucessfull')

else:
    print(ctx_auth.get_last_error())

import io

response = File.open_binary(ctx,folder_url_sp)

bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0)

data = pd.read_excel(bytes_file_obj,sheet_name = None, engine = 'openpyxl')

The Error:

BadZipFile                                Traceback (most recent call last)
Cell In[29], line 32
     29 bytes_file_obj.write(response.content)
     30 bytes_file_obj.seek(0)
---> 32 data = pd.read_excel(bytes_file_obj, sheet_name= None, engine = 'openpyxl')

File ~\Anaconda3\lib\site-packages\pandas\util\_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    305 if len(args) > num_allow_args:
    306     warnings.warn(
    307         msg.format(arguments=arguments),
    308         FutureWarning,
    309         stacklevel=stacklevel,
    310     )
--> 311 return func(*args, **kwargs)

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py:457, in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, decimal, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
    455 if not isinstance(io, ExcelFile):
    456     should_close = True
--> 457     io = ExcelFile(io, storage_options=storage_options, engine=engine)
    458 elif engine and engine != io.engine:
    459     raise ValueError(
    460         "Engine should not be specified when passing "
    461         "an ExcelFile - ExcelFile already has the engine set"
    462     )

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py:1419, in ExcelFile.__init__(self, path_or_buffer, engine, storage_options)
   1416 self.engine = engine
   1417 self.storage_options = storage_options
-> 1419 self._reader = self._engines[engine](self._io, storage_options=storage_options)

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_openpyxl.py:525, in OpenpyxlReader.__init__(self, filepath_or_buffer, storage_options)
    514 """
    515 Reader using openpyxl engine.
    516
   (...)
    522     passed to fsspec for appropriate URLs (see ``_get_filepath_or_buffer``)
    523 """
    524 import_optional_dependency("openpyxl")
--> 525 super().__init__(filepath_or_buffer, storage_options=storage_options)

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py:518, in BaseExcelReader.__init__(self, filepath_or_buffer, storage_options)
    516 self.handles.handle.seek(0)
    517 try:
--> 518     self.book = self.load_workbook(self.handles.handle)
    519 except Exception:
    520     self.close()

File ~\Anaconda3\lib\site-packages\pandas\io\excel\_openpyxl.py:536, in OpenpyxlReader.load_workbook(self, filepath_or_buffer)
    533 def load_workbook(self, filepath_or_buffer: FilePath | ReadBuffer[bytes]):
    534     from openpyxl import load_workbook
--> 536     return load_workbook(
    537         filepath_or_buffer, read_only=True, data_only=True, keep_links=False
    538     )

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:315, in load_workbook(filename, read_only, keep_vba, data_only, keep_links)
    288 def load_workbook(filename, read_only=False, keep_vba=KEEP_VBA,
    289                   data_only=False, keep_links=True):
    290     """Open the given filename and return the workbook
    291
    292     :param filename: the path to open or a file-like object
   (...)
    313
    314     """
--> 315     reader = ExcelReader(filename, read_only, keep_vba,
    316                         data_only, keep_links)
    317     reader.read()
    318     return reader.wb

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:124, in ExcelReader.__init__(self, fn, read_only, keep_vba, data_only, keep_links)
    122 def __init__(self,  fn, read_only=False, keep_vba=KEEP_VBA,
    123               data_only=False, keep_links=True):
--> 124     self.archive = _validate_archive(fn)
    125     self.valid_files = self.archive.namelist()
    126     self.read_only = read_only

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:96, in _validate_archive(filename)
     89             msg = ('openpyxl does not support %s file format, '
     90                    'please check you can open '
     91                    'it with Excel first. '
     92                    'Supported formats are: %s') % (file_format,
     93                                                    ','.join(SUPPORTED_FORMATS))
     94         raise InvalidFileException(msg)
---> 96 archive = ZipFile(filename, 'r')
     97 return archive

File ~\Anaconda3\lib\zipfile.py:1266, in ZipFile.__init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
   1264 try:
   1265     if mode == 'r':
-> 1266         self._RealGetContents()
   1267     elif mode in ('w', 'x'):
   1268         # set the modified flag so central directory gets written
   1269         # even if no files are added to the archive
   1270         self._didModify = True

File ~\Anaconda3\lib\zipfile.py:1333, in ZipFile._RealGetContents(self)
   1331     raise BadZipFile("File is not a zip file")
   1332 if not endrec:
-> 1333     raise BadZipFile("File is not a zip file")
   1334 if self.debug > 1:
   1335     print(endrec)

BadZipFile: File is not a zip file

```


问:
Kestrel ASP.Net Core 6.0 handling of expired client certificates - different behaviour when CustomTrustStore is used
I am using a self-hosted Kestrel Asp Net Core web server and am testing the behaviour when a client sends an expired certificate. The test is peformed with two scenarios, one with the root certificate imported into the Windows certificate store, and one using an application internal custom certificate store. The server uses a pfx file to construct a X509Certificate2 object.
Here is the code sample:

```<code>private void InitServices(WebApplicationBuilder builder, bool useCustomCertificateStore)
{
    var webBuilder = builder.WebHost;

    // load certificate from pfx file
    var rootCert = new X509Certificate2(rootCertPfxFilePath, rootCertPfxFilePassword);

    webBuilder.ConfigureKestrel(o =>
    {
        if (useCustomCertificateStore)
        {
            o.ConfigureHttpsDefaults(o =>
            {
                o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
                o.AllowAnyClientCertificate();
                o.CheckCertificateRevocation = false;
            });
        }
        else
        {
            o.ConfigureHttpsDefaults(o =>
            {
                o.ServerCertificate = rootCert;
                o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
            });
        }
    });

    webBuilder.UseKestrel(o =>
    {
        o.Listen(IPAddress.Parse(hostSettings.HttpsEndPoint.IpAddr), hostSettings.HttpsEndPoint.Port,
            listenOptions =>
            {
                HttpsConnectionAdapterOptions httpsConnectionAdapterOptions = null;
                if (useCustomCertificateStore)
                {
                    httpsConnectionAdapterOptions = new HttpsConnectionAdapterOptions()
                    {
                        ClientCertificateMode = ClientCertificateMode.RequireCertificate,
                        ServerCertificate = rootCert
                    };
                    httpsConnectionAdapterOptions.AllowAnyClientCertificate();
                }
                else
                {
                    httpsConnectionAdapterOptions = new HttpsConnectionAdapterOptions()
                    {
                        ClientCertificateMode = ClientCertificateMode.RequireCertificate,
                        SslProtocols = System.Security.Authentication.SslProtocols.None,
                        ServerCertificate = rootCert,
                        ClientCertificateValidation = (x509Cert, x509Chain, sslErrors) =>
                        {
                            logger.LogInformation($"Certificate validation request");

                            if (sslErrors == SslPolicyErrors.None)
                            {
                                return true;
                            }
                            else
                            {
                                logger.LogError($"Certificate validation failed because of SslPolicyErrors <{sslErrors.ToString()}>");
                            }

                            return false;
                        }
                    };
                }
                listenOptions.UseHttps(httpsConnectionAdapterOptions);
            });
    });

    var services = builder.Services;

    services
        .AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
        .AddCertificate(options =>
        {
            options.AllowedCertificateTypes = CertificateTypes.All;

            // custom certificate store, if windows certificate store should not be used!
            if (useCustomCertificateStore)
            {
                options.ChainTrustValidationMode = X509ChainTrustMode.CustomRootTrust;
                options.CustomTrustStore = new X509Certificate2Collection { rootCert };
                options.RevocationMode = X509RevocationMode.NoCheck;
            }

            options.Events = new CertificateAuthenticationEvents
            {
                OnCertificateValidated = context =>
                {
                    return Task.CompletedTask;
                },
                OnAuthenticationFailed = context =>
                {
                    logger?.LogError($"OnAuthenticationFailed with <{context.Exception.Message}> (host <{context.Request.Host}>, method <{context.Request.Method}>, path <{context.Request.Path}>)");
                    context.Fail("invalid cert");
                    return Task.CompletedTask;
                }
            };
        });

    // add authorization to require auth by default for all routes
    services.AddAuthorization(options =>
    {
        options.FallbackPolicy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .Build();
    });
.....
}

</code>```

I am using curl to call different endpoints on the web server. The tests with valid certificates are executed successfully. The tests with an expired certificate show a different behaviour of the kestrel web server, dependently if the custom certificate store is used or not (in this case the windows certificate store contains the certificate).
If the PC where the kestrel web server is running has the root certificate imported into the Windows Certificate Store, the kestrel web server sends an error message pertaining to the TLS handshake -> TLS alert certificate expired, and no http response is sent at all.
If the kestrel web server uses a custom certificate store, the kestrel web server sends a 403 http response.
Why is the behaviour different ? Can the kestrel web server be configured to always send a 403 http response in such scenarios?

Body:
I am using a self-hosted Kestrel Asp Net Core web server and am testing the behaviour when a client sends an expired certificate. The test is peformed with two scenarios, one with the root certificate imported into the Windows certificate store, and one using an application internal custom certificate store. The server uses a pfx file to construct a X509Certificate2 object.
Here is the code sample:

private void InitServices(WebApplicationBuilder builder, bool useCustomCertificateStore)
{
    var webBuilder = builder.WebHost;

    // load certificate from pfx file
    var rootCert = new X509Certificate2(rootCertPfxFilePath, rootCertPfxFilePassword);

    webBuilder.ConfigureKestrel(o =>
    {
        if (useCustomCertificateStore)
        {
            o.ConfigureHttpsDefaults(o =>
            {
                o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
                o.AllowAnyClientCertificate();
                o.CheckCertificateRevocation = false;
            });
        }
        else
        {
            o.ConfigureHttpsDefaults(o =>
            {
                o.ServerCertificate = rootCert;
                o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
            });
        }
    });

    webBuilder.UseKestrel(o =>
    {
        o.Listen(IPAddress.Parse(hostSettings.HttpsEndPoint.IpAddr), hostSettings.HttpsEndPoint.Port,
            listenOptions =>
            {
                HttpsConnectionAdapterOptions httpsConnectionAdapterOptions = null;
                if (useCustomCertificateStore)
                {
                    httpsConnectionAdapterOptions = new HttpsConnectionAdapterOptions()
                    {
                        ClientCertificateMode = ClientCertificateMode.RequireCertificate,
                        ServerCertificate = rootCert
                    };
                    httpsConnectionAdapterOptions.AllowAnyClientCertificate();
                }
                else
                {
                    httpsConnectionAdapterOptions = new HttpsConnectionAdapterOptions()
                    {
                        ClientCertificateMode = ClientCertificateMode.RequireCertificate,
                        SslProtocols = System.Security.Authentication.SslProtocols.None,
                        ServerCertificate = rootCert,
                        ClientCertificateValidation = (x509Cert, x509Chain, sslErrors) =>
                        {
                            logger.LogInformation($"Certificate validation request");

                            if (sslErrors == SslPolicyErrors.None)
                            {
                                return true;
                            }
                            else
                            {
                                logger.LogError($"Certificate validation failed because of SslPolicyErrors <{sslErrors.ToString()}>");
                            }

                            return false;
                        }
                    };
                }
                listenOptions.UseHttps(httpsConnectionAdapterOptions);
            });
    });

    var services = builder.Services;

    services
        .AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
        .AddCertificate(options =>
        {
            options.AllowedCertificateTypes = CertificateTypes.All;

            // custom certificate store, if windows certificate store should not be used!
            if (useCustomCertificateStore)
            {
                options.ChainTrustValidationMode = X509ChainTrustMode.CustomRootTrust;
                options.CustomTrustStore = new X509Certificate2Collection { rootCert };
                options.RevocationMode = X509RevocationMode.NoCheck;
            }

            options.Events = new CertificateAuthenticationEvents
            {
                OnCertificateValidated = context =>
                {
                    return Task.CompletedTask;
                },
                OnAuthenticationFailed = context =>
                {
                    logger?.LogError($"OnAuthenticationFailed with <{context.Exception.Message}> (host <{context.Request.Host}>, method <{context.Request.Method}>, path <{context.Request.Path}>)");
                    context.Fail("invalid cert");
                    return Task.CompletedTask;
                }
            };
        });

    // add authorization to require auth by default for all routes
    services.AddAuthorization(options =>
    {
        options.FallbackPolicy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .Build();
    });
.....
}

I am using curl to call different endpoints on the web server. The tests with valid certificates are executed successfully. The tests with an expired certificate show a different behaviour of the kestrel web server, dependently if the custom certificate store is used or not (in this case the windows certificate store contains the certificate).
If the PC where the kestrel web server is running has the root certificate imported into the Windows Certificate Store, the kestrel web server sends an error message pertaining to the TLS handshake -> TLS alert certificate expired, and no http response is sent at all.
If the kestrel web server uses a custom certificate store, the kestrel web server sends a 403 http response.
Why is the behaviour different ? Can the kestrel web server be configured to always send a 403 http response in such scenarios?


问:
@TestInstance vs @DirtiesContext
Junit5 has introduced @TestInstance annotation to manage the lifecycle and reuse of application context.

How does this relate to the existing @DirtiesContext mechanism?

I couldn't find anything that compares the practical use of these two.

Is @TestInstance meant to replace the @DirtiesContext?

Is it using @DirtiesContext under the hood?

Title: @TestInstance vs @DirtiesContext


问:
How to create shape using clipper in flutter?
Unable to create such curvy shape like in image attachment using CustomClipper. Can anyone can help?

```<code>class Customshape extends CustomClipper<Path>{
  @override
  Path getClip(Size size) {
    double height = size.height;
    double width = size.width;

    var path = Path();
    path.lineTo(0, height-50);
    path.quadraticBezierTo(width/2, height, width, height-50);
    path.lineTo(width, 0);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return true;
  }

}
</code>```

CustomWidget.dart

```<code>return Scaffold(
  appBar:  AppBar(
    toolbarHeight: 130,
    backgroundColor: Colors.transparent,
    elevation: 0.0,
    flexibleSpace: ClipPath(
      clipper: Customshape(),
      child: Container(
        height: 250,
        width: MediaQuery.of(context).size.width,
        color: Colors.green,
        child: Center(child: Text("CustomClipper test", style: TextStyle(fontSize: 40, color: Colors.white),)),
      ),
    ),
  ),
   body: Container(),
);
</code>```

Body:
Unable to create such curvy shape like in image attachment using CustomClipper. Can anyone can help?

class Customshape extends CustomClipper<Path>{
  @override
  Path getClip(Size size) {
    double height = size.height;
    double width = size.width;

    var path = Path();
    path.lineTo(0, height-50);
    path.quadraticBezierTo(width/2, height, width, height-50);
    path.lineTo(width, 0);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return true;
  }

}

CustomWidget.dart

return Scaffold(
  appBar:  AppBar(
    toolbarHeight: 130,
    backgroundColor: Colors.transparent,
    elevation: 0.0,
    flexibleSpace: ClipPath(
      clipper: Customshape(),
      child: Container(
        height: 250,
        width: MediaQuery.of(context).size.width,
        color: Colors.green,
        child: Center(child: Text("CustomClipper test", style: TextStyle(fontSize: 40, color: Colors.white),)),
      ),
    ),
  ),
   body: Container(),
);


问:
redux-persist whitelist not working with rtk
I am using the createSlice function from the rtk library to create multiple reducers in my Redux store. I am also trying to use redux-persist to save certain slices to local storage.
this store.js code is working well:

```<code>import { combineReducers, configureStore } from "@reduxjs/toolkit";
import betSlice from "./features/betSlice";
import configSlice from "./features/configSlice";
import eventSlice from "./features/eventSlice";
import userDataSlice from "./features/userDataSlice";
import wsSlice from "./features/wsSlice";
import storage from "redux-persist/lib/storage";
import { persistReducer, persistStore } from "redux-persist";
import thunk from "redux-thunk";
import modalsSlice from "./features/modalsSlice";

const persistConfig = {
  key: "root",
  storage,
};

const presistedReducers = combineReducers({
  wsSlice: persistReducer(persistConfig, wsSlice),
  eventSlice: persistReducer(persistConfig, eventSlice),
  betSlice: persistReducer(persistConfig, betSlice),
  configSlice: persistReducer(persistConfig, configSlice),
  userDataSlice: persistReducer(persistConfig, userDataSlice),
  modalsSlice: persistReducer(persistConfig, modalsSlice),
});
export const store = configureStore({
  reducer: presistedReducers,
  middleware: [thunk],
});

export const persistor = persistStore(store);
</code>```

I am having trouble using the whitelist\blacklist options provided by redux-persist. when I try to use a whitelist to only persist the configSlice reducer like this:

```<code>const persistConfig = {
  key: "root",
  storage,
  whitelist: ["configSlice"],
};
</code>```

nothing is saved to local storage.

Similarly, when I try to use a blacklist, all of the reducers are saved to local storage.

All of the slices in my project are structured in the same way, using the createSlice function in this format:

```<code>import { createSlice } from '@reduxjs/toolkit';

const initialState = {};
const nameSlice = createSlice({
name: 'nameSlice',
initialState,
reducers: {},
});

export const {} = nameSlice.actions;
export default nameSlice.reducer;
</code>```

Can anyone explain why the whitelist and blacklist options are not working as expected, and how I can correctly configure redux-persist to only save certain slices to local storage?

Body:
I am using the createSlice function from the rtk library to create multiple reducers in my Redux store. I am also trying to use redux-persist to save certain slices to local storage.
this store.js code is working well:

import { combineReducers, configureStore } from "@reduxjs/toolkit";
import betSlice from "./features/betSlice";
import configSlice from "./features/configSlice";
import eventSlice from "./features/eventSlice";
import userDataSlice from "./features/userDataSlice";
import wsSlice from "./features/wsSlice";
import storage from "redux-persist/lib/storage";
import { persistReducer, persistStore } from "redux-persist";
import thunk from "redux-thunk";
import modalsSlice from "./features/modalsSlice";

const persistConfig = {
  key: "root",
  storage,
};

const presistedReducers = combineReducers({
  wsSlice: persistReducer(persistConfig, wsSlice),
  eventSlice: persistReducer(persistConfig, eventSlice),
  betSlice: persistReducer(persistConfig, betSlice),
  configSlice: persistReducer(persistConfig, configSlice),
  userDataSlice: persistReducer(persistConfig, userDataSlice),
  modalsSlice: persistReducer(persistConfig, modalsSlice),
});
export const store = configureStore({
  reducer: presistedReducers,
  middleware: [thunk],
});

export const persistor = persistStore(store);

I am having trouble using the whitelist\blacklist options provided by redux-persist. when I try to use a whitelist to only persist the configSlice reducer like this:

const persistConfig = {
  key: "root",
  storage,
  whitelist: ["configSlice"],
};

nothing is saved to local storage.

Similarly, when I try to use a blacklist, all of the reducers are saved to local storage.

All of the slices in my project are structured in the same way, using the createSlice function in this format:

import { createSlice } from '@reduxjs/toolkit';

const initialState = {};
const nameSlice = createSlice({
name: 'nameSlice',
initialState,
reducers: {},
});

export const {} = nameSlice.actions;
export default nameSlice.reducer;

Can anyone explain why the whitelist and blacklist options are not working as expected, and how I can correctly configure redux-persist to only save certain slices to local storage?