问:
Cannot access API view on post request using decorator [AllowAny]
I have a simple function-based @api_view(['POST']) with @permission_classes([AllowAny])
and DRF settings in settings.py are:

```<code>REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
}
</code>```

The documentation says:

The AllowAny permission class will allow unrestricted access,
regardless of if the request was authenticated or unauthenticated.

But I'm getting the following response on making a post request:

```<code>{
    "detail": "Authentication credentials were not provided."
}
</code>```

What might be the problem? Do I have to modify DEFAULT_AUTHENTICATION_CLASSES from the settings? I don't want the permissions to be required while making the request on this @api_view:

```<code>@api_view(['POST'])
@permission_classes([AllowAny])
def reset_password_request(email):
    try:
    #...
</code>```

accounts/urls.py:

```<code>urlpatterns = [
    path('user/<str:pk>/', views.getUserById, name='user'),
    path('user/password_reset_request/',
         views.resetPasswordRequest, name='password_reset_request'),
]
</code>```

答:
If DEFAULT_PERMISSION_CLASSES is not specified, it defaults to allowing unrestricted access.

The problem is in your URL patterns, where password_reset_request satisfies <str:pk> and getUserById with @permission_classes([...]) is called instead.

Either use the uuid path converter:

urlpatterns = [
    # path('user/<str:pk>/', views.getUserById, name='user'),  # Change this
    path('user/<uuid:pk>/', views.getUserById, name='user'),   # to this
    path('user/password_reset_request/',
         views.resetPasswordRequest, name='password_reset_request'),
]
```
<p>Or reorder to match <code>password_reset_request</code> first:</p>
<pre class="lang-py prettyprint-override"><code>urlpatterns = [
    # path('user/<str:pk>/', views.getUserById, name='user'),  # Move this
    path('user/password_reset_request/',
         views.resetPasswordRequest, name='password_reset_request'),
    path('user/<str:pk>/', views.getUserById, name='user'),    # to here
]
</code>```

References:

https://www.django-rest-framework.org/api-guide/permissions/

https://docs.djangoproject.com/en/4.0/topics/http/urls/#path-converters

Body:
I have a simple function-based @api_view(['POST']) with @permission_classes([AllowAny])
and DRF settings in settings.py are:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
}

The documentation says:

The AllowAny permission class will allow unrestricted access,
regardless of if the request was authenticated or unauthenticated.

But I'm getting the following response on making a post request:

{
    "detail": "Authentication credentials were not provided."
}

What might be the problem? Do I have to modify DEFAULT_AUTHENTICATION_CLASSES from the settings? I don't want the permissions to be required while making the request on this @api_view:

@api_view(['POST'])
@permission_classes([AllowAny])
def reset_password_request(email):
    try:
    #...

accounts/urls.py:

urlpatterns = [
    path('user/<str:pk>/', views.getUserById, name='user'),
    path('user/password_reset_request/',
         views.resetPasswordRequest, name='password_reset_request'),
]

Body:
If DEFAULT_PERMISSION_CLASSES is not specified, it defaults to allowing unrestricted access.

The problem is in your URL patterns, where password_reset_request satisfies <str:pk> and getUserById with @permission_classes([...]) is called instead.

Either use the uuid path converter:

urlpatterns = [
    # path('user/<str:pk>/', views.getUserById, name='user'),  # Change this
    path('user/<uuid:pk>/', views.getUserById, name='user'),   # to this
    path('user/password_reset_request/',
         views.resetPasswordRequest, name='password_reset_request'),
]

Or reorder to match password_reset_request first:

urlpatterns = [
    # path('user/<str:pk>/', views.getUserById, name='user'),  # Move this
    path('user/password_reset_request/',
         views.resetPasswordRequest, name='password_reset_request'),
    path('user/<str:pk>/', views.getUserById, name='user'),    # to here
]

References:

https://www.django-rest-framework.org/api-guide/permissions/

https://docs.djangoproject.com/en/4.0/topics/http/urls/#path-converters


来源: stackexchange

问:
Does ActiveMQ Artemis support updating scheduled messages in a last value queue?
In my testing and review of the Artemis LastValueQueue code, it looks like the scheduling delay for a message takes precedence over its evaluation of the "last-value-key".  In other words, if you schedule a message, it is only evaluated for replacing the last-value in the queue at the time it is prepared for delivery.

My question is whether I have correctly understood the code, and if so, if there's a workaround or a feature of ActiveMQ / Artemis that might help meet our requirements.

Our requirements are as follows:

Generate a message, and delay processing of that message to a point in the future (usually 30 seconds out).

If an updated version of the message is generated due to a new external event, replace any existing scheduled message with the new version of the message - the scheduled delivery time should also be updated, in addition to the message payload.

Some other notes:

My current prototype is using Artemis embedded server

Spring-jms JmsTemplate is being used to produce messages

Spring-jms JmsListenerContainerFactory is being used to consume messages

We don't currently use SpringBoot, so you'll see some bean setup below.

ArtemisConfig.java:

```<code>@Configuration
@EnableJms
public class ArtemisConfig {

    @Bean
    public org.apache.activemq.artemis.core.config.Configuration configuration() throws Exception {
        org.apache.activemq.artemis.core.config.Configuration config = new ConfigurationImpl();
        config.addAcceptorConfiguration("in-vm", "vm://0");
        config.setPersistenceEnabled(true);
        config.setSecurityEnabled(false);
        config.setJournalType(JournalType.ASYNCIO);
        config.setCreateJournalDir(true);
        config.setJournalDirectory("/var/mq/journal");
        config.setBindingsDirectory("/var/mq/bindings");
        config.setLargeMessagesDirectory("/var/mq/large-messages");
        config.setJMXManagementEnabled(true);

        QueueConfiguration queueConfiguration = new QueueConfiguration("MYLASTVALUEQUEUE");
        queueConfiguration.setAddress("MYLASTVALUEQUEUE");
        queueConfiguration.setLastValueKey("uniqueJobId");
        queueConfiguration.setDurable(true);
        queueConfiguration.setEnabled(true);
        queueConfiguration.setRoutingType(RoutingType.ANYCAST);

        CoreAddressConfiguration coreAddressConfiguration = new CoreAddressConfiguration();
        coreAddressConfiguration.addQueueConfiguration(queueConfiguration);

        config.addAddressConfiguration(coreAddressConfiguration);

        return config;
    }

    @Bean
    public EmbeddedActiveMQ artemisServer() throws Exception {
        EmbeddedActiveMQ server = new EmbeddedActiveMQ();
        server.setConfiguration(configuration());
        server.start();

        return server;
    }

    @PreDestroy
    public void preDestroy() throws Exception {
        artemisServer().stop();
    }

    @Bean
    public ConnectionFactory activeMqConnectionFactory() throws Exception {
        return ActiveMQJMSClient.createConnectionFactory("vm://0", "artemis-client");
    }

    @Bean
    public JmsListenerContainerFactory<?> jmsListenerContainerFactory() throws Exception {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(activeMqConnectionFactory());
        factory.setSessionTransacted(true);
        factory.setConcurrency("8");
        factory.setMessageConverter(jacksonJmsMessageConverter());
        return factory;
    }

    @Bean
    public MessageConverter jacksonJmsMessageConverter() {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setTargetType(MessageType.TEXT);
        converter.setTypeIdPropertyName("_type");
        return converter;
    }

    @Bean
    public JmsTemplate jmsTemplate() throws Exception {
        JmsTemplate jmsTemplate = new JmsTemplate(activeMqConnectionFactory());
        jmsTemplate.setMessageConverter(jacksonJmsMessageConverter());
        jmsTemplate.setDeliveryPersistent(true);

        return jmsTemplate;
    }

    @Bean
    QueueMessageService queueMessageService() {
        return new QueueMessageService();
    }
}
</code>```

QueueMessageService.java

```<code>public class QueueMessageService {
    @Resource
    private JmsTemplate jmsTemplate;

    public void queueJobRequest(
            final String queue,
            final int priority,
            final long deliveryDelayInSeconds,
            final MyMessage message) {

        jmsTemplate.convertAndSend(queue, jobRequest, message -> {
            message.setJMSPriority(priority);
            if (deliveryDelayInSeconds > 0 && deliveryDelayInSeconds <= 86400) {
                message.setLongProperty(
                        Message.HDR_SCHEDULED_DELIVERY_TIME.toString(),
                        Instant.now().plus(deliveryDelayInSeconds, ChronoUnit.SECONDS).toEpochMilli()
                );
            }
            message.setStringProperty(Message.HDR_LAST_VALUE_NAME.toString(), "uniqueJobId");
            message.setStringProperty("uniqueJobId", jobRequest.getUniqueJobId().toString());
            return message;
        });
    }
}
</code>```

答:
Your understanding about the semantics of scheduled messages with a last-value queue is correct. When a message is scheduled it is not technically on the queue yet. It is not put onto the queue until the scheduled time arrives at which point last-value queue semantics are enforced.

Short of implementing a new feature I don't see how you can implement your desired behavior in any kind of automatic way. My recommendation at this point would be to use the management API (i.e. QueueControl) to manually remove the "old" scheduled message before you send the "new" scheduled message. You can use one of the removeMessage methods for this as they will work on scheduled messages and non-scheduled messages alike.

ContentLicense: CC BY-SA 4.0

Body:
In my testing and review of the Artemis LastValueQueue code, it looks like the scheduling delay for a message takes precedence over its evaluation of the "last-value-key".  In other words, if you schedule a message, it is only evaluated for replacing the last-value in the queue at the time it is prepared for delivery.

My question is whether I have correctly understood the code, and if so, if there's a workaround or a feature of ActiveMQ / Artemis that might help meet our requirements.

Our requirements are as follows:

Generate a message, and delay processing of that message to a point in the future (usually 30 seconds out).

If an updated version of the message is generated due to a new external event, replace any existing scheduled message with the new version of the message - the scheduled delivery time should also be updated, in addition to the message payload.

Some other notes:

My current prototype is using Artemis embedded server

Spring-jms JmsTemplate is being used to produce messages

Spring-jms JmsListenerContainerFactory is being used to consume messages

We don't currently use SpringBoot, so you'll see some bean setup below.

ArtemisConfig.java:

@Configuration
@EnableJms
public class ArtemisConfig {

    @Bean
    public org.apache.activemq.artemis.core.config.Configuration configuration() throws Exception {
        org.apache.activemq.artemis.core.config.Configuration config = new ConfigurationImpl();
        config.addAcceptorConfiguration("in-vm", "vm://0");
        config.setPersistenceEnabled(true);
        config.setSecurityEnabled(false);
        config.setJournalType(JournalType.ASYNCIO);
        config.setCreateJournalDir(true);
        config.setJournalDirectory("/var/mq/journal");
        config.setBindingsDirectory("/var/mq/bindings");
        config.setLargeMessagesDirectory("/var/mq/large-messages");
        config.setJMXManagementEnabled(true);

        QueueConfiguration queueConfiguration = new QueueConfiguration("MYLASTVALUEQUEUE");
        queueConfiguration.setAddress("MYLASTVALUEQUEUE");
        queueConfiguration.setLastValueKey("uniqueJobId");
        queueConfiguration.setDurable(true);
        queueConfiguration.setEnabled(true);
        queueConfiguration.setRoutingType(RoutingType.ANYCAST);

        CoreAddressConfiguration coreAddressConfiguration = new CoreAddressConfiguration();
        coreAddressConfiguration.addQueueConfiguration(queueConfiguration);

        config.addAddressConfiguration(coreAddressConfiguration);

        return config;
    }

    @Bean
    public EmbeddedActiveMQ artemisServer() throws Exception {
        EmbeddedActiveMQ server = new EmbeddedActiveMQ();
        server.setConfiguration(configuration());
        server.start();

        return server;
    }

    @PreDestroy
    public void preDestroy() throws Exception {
        artemisServer().stop();
    }

    @Bean
    public ConnectionFactory activeMqConnectionFactory() throws Exception {
        return ActiveMQJMSClient.createConnectionFactory("vm://0", "artemis-client");
    }

    @Bean
    public JmsListenerContainerFactory<?> jmsListenerContainerFactory() throws Exception {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(activeMqConnectionFactory());
        factory.setSessionTransacted(true);
        factory.setConcurrency("8");
        factory.setMessageConverter(jacksonJmsMessageConverter());
        return factory;
    }

    @Bean
    public MessageConverter jacksonJmsMessageConverter() {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setTargetType(MessageType.TEXT);
        converter.setTypeIdPropertyName("_type");
        return converter;
    }

    @Bean
    public JmsTemplate jmsTemplate() throws Exception {
        JmsTemplate jmsTemplate = new JmsTemplate(activeMqConnectionFactory());
        jmsTemplate.setMessageConverter(jacksonJmsMessageConverter());
        jmsTemplate.setDeliveryPersistent(true);

        return jmsTemplate;
    }

    @Bean
    QueueMessageService queueMessageService() {
        return new QueueMessageService();
    }
}

QueueMessageService.java

public class QueueMessageService {
    @Resource
    private JmsTemplate jmsTemplate;

    public void queueJobRequest(
            final String queue,
            final int priority,
            final long deliveryDelayInSeconds,
            final MyMessage message) {

        jmsTemplate.convertAndSend(queue, jobRequest, message -> {
            message.setJMSPriority(priority);
            if (deliveryDelayInSeconds > 0 && deliveryDelayInSeconds <= 86400) {
                message.setLongProperty(
                        Message.HDR_SCHEDULED_DELIVERY_TIME.toString(),
                        Instant.now().plus(deliveryDelayInSeconds, ChronoUnit.SECONDS).toEpochMilli()
                );
            }
            message.setStringProperty(Message.HDR_LAST_VALUE_NAME.toString(), "uniqueJobId");
            message.setStringProperty("uniqueJobId", jobRequest.getUniqueJobId().toString());
            return message;
        });
    }
}


问:
Tried to update field with a model instance, <SimpleLazyObject:<<>>. Use a value compatible with CharField
I am trying to over ride the save method in my model to store the currently loged in user. I am using the django-current user to get the authenticated user. I wrote this code

```<code>from django_currentuser.middleware import (
    get_current_user, get_current_authenticated_user)

from django_currentuser.db.models import CurrentUserField

 uploaded_by = models.CharField(max_length=255, blank=True, null=True, editable=False)

 def save(self, *args, **kwargs):

     user = get_current_authenticated_user()

     self.uploaded_by = user

     super(Citation, self).save(*args, **kwargs)

</code>```

But I am getting this error

```<code>Tried to update field professional.Citation.uploaded_by with a model instance, <SimpleLazyObject: <CustomUser: staff@gmail.com>>. Use a value compatible with CharField.
</code>```

What should I do? I want to store the currently logged in user in the model save method and also keep this field non editable.

I am getting this error only when the field is being updated. It is working fine wile saving for the first time

答:
Your are getting this error because you are trying to save user object in an char field. Your uploaded_by filed is an  CharField. You can save only string value in this fields.

try this and hope this will solved your problems:

```<code> from django.contrib.auth.models import User #import user model
 # add user ForeignKey fields in your model
 user = models.ForeignKey(User,on_delete=models.CASCADE)
 uploaded_by = models.CharField(max_length=255, blank=True, null=True, editable=False)

    def save(self, *args, **kwargs):

         user = self.user.username

         if not self.uploaded_by:
             self.uploaded_by = user

         super(Citation, self).save(*args, **kwargs)
</code>```

Body:
I am trying to over ride the save method in my model to store the currently loged in user. I am using the django-current user to get the authenticated user. I wrote this code

from django_currentuser.middleware import (
    get_current_user, get_current_authenticated_user)

from django_currentuser.db.models import CurrentUserField

 uploaded_by = models.CharField(max_length=255, blank=True, null=True, editable=False)

 def save(self, *args, **kwargs):

     user = get_current_authenticated_user()

     self.uploaded_by = user

     super(Citation, self).save(*args, **kwargs)

But I am getting this error

Tried to update field professional.Citation.uploaded_by with a model instance, <SimpleLazyObject: <CustomUser: staff@gmail.com>>. Use a value compatible with CharField.

What should I do? I want to store the currently logged in user in the model save method and also keep this field non editable.

I am getting this error only when the field is being updated. It is working fine wile saving for the first time

Body:
Your are getting this error because you are trying to save user object in an char field. Your uploaded_by filed is an  CharField. You can save only string value in this fields.

try this and hope this will solved your problems:

 from django.contrib.auth.models import User #import user model
 # add user ForeignKey fields in your model
 user = models.ForeignKey(User,on_delete=models.CASCADE)
 uploaded_by = models.CharField(max_length=255, blank=True, null=True, editable=False)

    def save(self, *args, **kwargs):

         user = self.user.username

         if not self.uploaded_by:
             self.uploaded_by = user

         super(Citation, self).save(*args, **kwargs)


问:
How can I use post step in Jenkins pipeline with kubernetes plugin
I try to use the post steps with the Jenkins kubernetes plugin. Does anyone has an idea?

```<code>java.lang.NoSuchMethodError: No such DSL method 'post' found among steps
</code>```

My pipeline:

```<code>podTemplate(
        label: 'jenkins-pipeline',
        cloud: 'minikube',
        volumes: [
                hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
        ]) {

    node('jenkins-pipeline') {
        stage('test') {
            container('maven') {
                println 'do some testing stuff'
            }
        }

        post {
            always {
                println "test"
            }
        }
    }
}
</code>```

答:
This example shows how to use the post step using the Kubernetes plugin:</p>
```<code>pipeline {
  agent {
    kubernetes {
      label "my-test-pipeline-${BUILD_NUMBER}"
      containerTemplate {
        name "my-container"
        image "alpine:3.15.0"
        command "sleep"
        args "99d"
      }
    }
  }
  stages {
    stage('Stage 1') {
      steps {
        container('my-container') {
          sh '''
            set -e
            echo "Hello world!"
            sleep 10
            echo "I waited"

            echo "forcing a fail"
            exit 1
          '''
        }
      }
    }
  }
  post {
    unsuccessful {
      container('my-container') {
        sh '''
          set +e
          echo "Cleaning up stuff here"
        '''
      }
    }
  }
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I try to use the post steps with the Jenkins kubernetes plugin. Does anyone has an idea?

java.lang.NoSuchMethodError: No such DSL method 'post' found among steps

My pipeline:

podTemplate(
        label: 'jenkins-pipeline',
        cloud: 'minikube',
        volumes: [
                hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
        ]) {

    node('jenkins-pipeline') {
        stage('test') {
            container('maven') {
                println 'do some testing stuff'
            }
        }

        post {
            always {
                println "test"
            }
        }
    }
}

Body:
This example shows how to use the post step using the Kubernetes plugin:

pipeline {
  agent {
    kubernetes {
      label "my-test-pipeline-${BUILD_NUMBER}"
      containerTemplate {
        name "my-container"
        image "alpine:3.15.0"
        command "sleep"
        args "99d"
      }
    }
  }
  stages {
    stage('Stage 1') {
      steps {
        container('my-container') {
          sh '''
            set -e
            echo "Hello world!"
            sleep 10
            echo "I waited"

            echo "forcing a fail"
            exit 1
          '''
        }
      }
    }
  }
  post {
    unsuccessful {
      container('my-container') {
        sh '''
          set +e
          echo "Cleaning up stuff here"
        '''
      }
    }
  }
}


问:
Android: Base64 Sample issue
currently I'm using kSoap to publish data to C# web services. Now I've come to the part where I need to upload images from my machine using Base64Binary. I searched everywehre internet but couldn't come up with a proper solution.

there is a solution with external Base64 class example but I'm interested in native solution as there is a API from Android 2.2.

Since I'm a newbie I couldn't do it myself. Basically I have a sd card file path of images, I want to convert them into Base64 format to upload.

Hope someone can help me or direct me to proper documents.

Thanks in advance.

答:
I figured out the issue</p>

```<code>String Image64 = null;

        try {
            Image64 = Base64.encodeToString((getBytesFromFile(new File(path))), DEFAULT);

        } catch (IOException e) {
            e.printStackTrace();

        }

//encording
    public static byte[] getBytesFromFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();

        // You cannot create an array using a long type.
        // It needs to be an int type.
        // Before converting to an int type, check
        // to ensure that file is not larger than Integer.MAX_VALUE.
        if (length > Integer.MAX_VALUE) {
            // File is too large
        }

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int)length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file "+file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }
</code>```

Title: Android: Base64 Sample issue

Body:
I figured out the issue

String Image64 = null;

        try {
            Image64 = Base64.encodeToString((getBytesFromFile(new File(path))), DEFAULT);

        } catch (IOException e) {
            e.printStackTrace();

        }

//encording
    public static byte[] getBytesFromFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();

        // You cannot create an array using a long type.
        // It needs to be an int type.
        // Before converting to an int type, check
        // to ensure that file is not larger than Integer.MAX_VALUE.
        if (length > Integer.MAX_VALUE) {
            // File is too large
        }

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int)length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file "+file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }


问:
How to Convert JSON to be readable by Excel (Already Flattened)?
Here is a snippet of the code I have right now:

```<code>  '0_parcel_mapicon': None,
  '0_parcel_mapiconselected': None,
  '0_parcel_sections_0_0_0_buildingId': 123456,
  '0_parcel_sections_0_0_0_id': 123,
  '0_parcel_sections_0_0_0_LandUseCode': 'R00',
  '0_parcel_sections_0_0_0_Neighborhood': 'S110',
  '0_parcel_sections_0_0_0_landUseCodeDescription': 'SINGLE',
  '0_parcel_sections_0_0_0_LandSize': '1 LOT',
  '0_parcel_sections_0_0_0_Exemption': None,
  '0_parcel_sections_0_0_0_Tax_MunDist': 'NYC',
  '0_parcel_sections_0_0_0_SaleDate': '05/10/2021',
...
  '1_parcel_mapicon': None,
  '1_parcel_mapiconselected': None,
  '1_parcel_sections_0_0_0_buildingId': 56789,
  '1_parcel_sections_0_0_0_id': 321,
  '1_parcel_sections_0_0_0_LandUseCode': 'Z00',
  '1_parcel_sections_0_0_0_Neighborhood': 'D110',
  '1_parcel_sections_0_0_0_landUseCodeDescription': 'SINGLE',
  '1_parcel_sections_0_0_0_LandSize': '2 LOT',
  '1_parcel_sections_0_0_0_Exemption': None,
  '1_parcel_sections_0_0_0_Tax_MunDist': 'NYC',
  '1_parcel_sections_0_0_0_SaleDate': '09/10/2021',
...etc
</code>```

This is in JSON format but has been converted to be a "flatter" file, incrementing each section by 1 as it goes down the JSON. I now need to be able to take this file and import into Excel in order to perform more advanced filtering. Unfortunately, Excel does not easily import this and treats each section as if its a new individual column (delimited by a colon).

I have tried to remove the incremeter from the Python code but by doing so it just exported one entity. Below is the code I used to flatten the data:

```<code>import json
import requests

def flatten_json(y):
    out = {}

    def flatten(x, name=''):
        # If the Nested key-value
        # pair is of dict type
        if type(x) is dict:
            for a in x:
                flatten(x[a], name + a + '_')
                # If the Nested key-value
        # pair is of list type
        elif type(x) is list:
            i = 0
            for a in x:
                flatten(a, name + str(i) + '_')
                i += 1
        else:
            out[name[:-1]] = x

    flatten(y)
    return out
</code>```

Is there any way to get this to be more acceptable to Excel?

答:
you can use pandas to convert between the formats:
convert json to dictionary:

```<code>data = json.load('json_file path')
</code>```

and use pandas to save it to excel

```<code>df_dict = pd.DataFrame.from_dict('json converted to dict')
df_dict.to_excel('Path to output excel file', index=False)
</code>```

Body:
Here is a snippet of the code I have right now:

  '0_parcel_mapicon': None,
  '0_parcel_mapiconselected': None,
  '0_parcel_sections_0_0_0_buildingId': 123456,
  '0_parcel_sections_0_0_0_id': 123,
  '0_parcel_sections_0_0_0_LandUseCode': 'R00',
  '0_parcel_sections_0_0_0_Neighborhood': 'S110',
  '0_parcel_sections_0_0_0_landUseCodeDescription': 'SINGLE',
  '0_parcel_sections_0_0_0_LandSize': '1 LOT',
  '0_parcel_sections_0_0_0_Exemption': None,
  '0_parcel_sections_0_0_0_Tax_MunDist': 'NYC',
  '0_parcel_sections_0_0_0_SaleDate': '05/10/2021',
...
  '1_parcel_mapicon': None,
  '1_parcel_mapiconselected': None,
  '1_parcel_sections_0_0_0_buildingId': 56789,
  '1_parcel_sections_0_0_0_id': 321,
  '1_parcel_sections_0_0_0_LandUseCode': 'Z00',
  '1_parcel_sections_0_0_0_Neighborhood': 'D110',
  '1_parcel_sections_0_0_0_landUseCodeDescription': 'SINGLE',
  '1_parcel_sections_0_0_0_LandSize': '2 LOT',
  '1_parcel_sections_0_0_0_Exemption': None,
  '1_parcel_sections_0_0_0_Tax_MunDist': 'NYC',
  '1_parcel_sections_0_0_0_SaleDate': '09/10/2021',
...etc

This is in JSON format but has been converted to be a "flatter" file, incrementing each section by 1 as it goes down the JSON. I now need to be able to take this file and import into Excel in order to perform more advanced filtering. Unfortunately, Excel does not easily import this and treats each section as if its a new individual column (delimited by a colon).

I have tried to remove the incremeter from the Python code but by doing so it just exported one entity. Below is the code I used to flatten the data:

import json
import requests

def flatten_json(y):
    out = {}

    def flatten(x, name=''):
        # If the Nested key-value
        # pair is of dict type
        if type(x) is dict:
            for a in x:
                flatten(x[a], name + a + '_')
                # If the Nested key-value
        # pair is of list type
        elif type(x) is list:
            i = 0
            for a in x:
                flatten(a, name + str(i) + '_')
                i += 1
        else:
            out[name[:-1]] = x

    flatten(y)
    return out

Is there any way to get this to be more acceptable to Excel?

Body:
you can use pandas to convert between the formats:
convert json to dictionary:

data = json.load('json_file path')

and use pandas to save it to excel

df_dict = pd.DataFrame.from_dict('json converted to dict')
df_dict.to_excel('Path to output excel file', index=False)


问:
Is dc.js (used with crossfilter and d3.js) still a good option for Big data visualization on a browser page?
I'm try to build an online dashboard to visualize a large csv dataset and i want to be sure i'm following the right path.

Thank you everybody.

答:
Crossfilter will speedily handle up to around 500K rows of data, maybe more depending on column complexity.

Around that size you also have to consider the time that it will take to download the data to the browser, affecting when the charts will appear in the page.

If your data is bigger than that, and you still want to use dc.js, you have two options:

Pre-aggregate your data: instead of counting rows with group.reduceCount(), use group.reduceSum() and have a column with pre-summed integers. Of course, you will not be able to drill into pre-aggregated data, so this is only effective if you can accept some granularity of the dimensions of your charts.

Use a server-side replacement for crossfilter, such as elastic-dc. There are other solutions floating around but I think Deepak has the most complete solution.


问:
replace values by different conditions in a dataframe
I have a dataframe like this:

```<code>df_test = pd.DataFrame({'ID1':['A','B','C','BA','BA','AB','>','>','>','>'],
                       'ID2':['','','','','','','mh','mh','nn','nn']})
df_test
</code>```

I want to obtain a dataframe like this based on the column 'ID1'(1. if len(ID1)>2: then ID1=ID1[-1](for example 'BA', 'AB' will be replaced with 'A', 'B', respectively); 2. if ID1='>': then ID1=ID2(for example: '>' will be replaced with 'mh','nn',respectively)):

```<code>df_result = pd.DataFrame({'ID1':['A','B','C','A','A','B','mh','mh','nn','nn']})
df_result
</code>```

答:
You can use .str[-1] regardless of the length of the strings in the column to select the last character, and use <column>.where(cond, other_col) to fill in values that don't match cond with those values from other_col:

```<code>df_test['ID1'] = df_test.assign(ID1=df_test['ID1'].str[-1]).pipe(lambda x: x['ID1'].where(x['ID1'] != '>', x['ID2']))
</code>```

Body:
I have a dataframe like this:

df_test = pd.DataFrame({'ID1':['A','B','C','BA','BA','AB','>','>','>','>'],
                       'ID2':['','','','','','','mh','mh','nn','nn']})
df_test

I want to obtain a dataframe like this based on the column 'ID1'(1. if len(ID1)>2: then ID1=ID1[-1](for example 'BA', 'AB' will be replaced with 'A', 'B', respectively); 2. if ID1='>': then ID1=ID2(for example: '>' will be replaced with 'mh','nn',respectively)):

df_result = pd.DataFrame({'ID1':['A','B','C','A','A','B','mh','mh','nn','nn']})
df_result

Body:
You can use .str[-1] regardless of the length of the strings in the column to select the last character, and use <column>.where(cond, other_col) to fill in values that don't match cond with those values from other_col:

df_test['ID1'] = df_test.assign(ID1=df_test['ID1'].str[-1]).pipe(lambda x: x['ID1'].where(x['ID1'] != '>', x['ID2']))


问:
Keycloak Identity Broker: HMACSHA256 Signature not available
I'm running Keycloak 15.0.2 in docker (jboss/keycloak:15.0.2) and use Identity Brokering with an external OpenId Connect Identity Provider

When a login is initialized on keycloak the browser is redirected to the external IDP. After authenticated there the browser is redirected to keycloaks broker endpoint /broker/oidc/endpoint?code=xxx

But then Keycloak throws a Exception caused by

Caused by: java.security.NoSuchAlgorithmException: HMACSHA256 Signature not available

Has someone an idea why this is happening? Should this HMACSHA256 algorithm not already be part of the JRE in the docker-container?

Full stacktrace

```<code>10:43:06,687 ERROR [org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider] (default task-36) Failed to make identity provider oauth callback: java.lang.RuntimeException: org.keycloak.crypto.SignatureException: Signing failed
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.jose.jws.JWSBuilder$EncodingBuilder.sign(JWSBuilder.java:116)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider.authenticateTokenRequest(AbstractOAuth2IdentityProvider.java:408)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider$Endpoint.generateTokenRequest(AbstractOAuth2IdentityProvider.java:576)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.OIDCIdentityProvider$OIDCEndpoint.generateTokenRequest(OIDCIdentityProvider.java:323)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider$Endpoint.authResponse(AbstractOAuth2IdentityProvider.java:500)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:138)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:546)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:435)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:396)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:398)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:365)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:150)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:110)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:141)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:104)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:440)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:245)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:61)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
        at javax.servlet.api@2.0.0.Final//javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
        at org.keycloak.keycloak-wildfly-extensions@15.0.2//org.keycloak.provider.wildfly.WildFlyRequestFilter.lambda$doFilter$0(WildFlyRequestFilter.java:41)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.services.filters.AbstractRequestFilter.filter(AbstractRequestFilter.java:43)
        at org.keycloak.keycloak-wildfly-extensions@15.0.2//org.keycloak.provider.wildfly.WildFlyRequestFilter.doFilter(WildFlyRequestFilter.java:39)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
        at io.undertow.core@2.2.5.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
        at io.undertow.core@2.2.5.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
        at org.jboss.xnio@3.8.4.Final//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.keycloak.crypto.SignatureException: Signing failed
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.crypto.AsymmetricSignatureSignerContext.sign(AsymmetricSignatureSignerContext.java:53)
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.jose.jws.JWSBuilder$EncodingBuilder.sign(JWSBuilder.java:114)
        ... 80 more
Caused by: java.security.NoSuchAlgorithmException: HMACSHA256 Signature not available
        at java.base/java.security.Signature.getInstance(Signature.java:267)
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.crypto.AsymmetricSignatureSignerContext.sign(AsymmetricSignatureSignerContext.java:48)
        ... 81 more
10:43:06,693 WARN  [org.keycloak.events] (default task-36) type=IDENTITY_PROVIDER_LOGIN_ERROR, realmId=Test, clientId=application, userId=null, ipAddress=10.0.0.2, error=identity_provider_login_failure, code_id=10584c92-b25a-4961-b181-8ebcecc236c8, authSessionParentId=10584c92-b25a-4961-b181-8ebcecc236c8, authSessionTabId=Z9JGLzHz2qk
</code>```

答: I had the same issue and could solve it by changing the "Client Assertion Signature Algorithm" from HS256 to RS256 for the identity provider in Keycloak.</p>

Body:
I'm running Keycloak 15.0.2 in docker (jboss/keycloak:15.0.2) and use Identity Brokering with an external OpenId Connect Identity Provider

When a login is initialized on keycloak the browser is redirected to the external IDP. After authenticated there the browser is redirected to keycloaks broker endpoint /broker/oidc/endpoint?code=xxx

But then Keycloak throws a Exception caused by

Caused by: java.security.NoSuchAlgorithmException: HMACSHA256 Signature not available

Has someone an idea why this is happening? Should this HMACSHA256 algorithm not already be part of the JRE in the docker-container?

Full stacktrace

10:43:06,687 ERROR [org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider] (default task-36) Failed to make identity provider oauth callback: java.lang.RuntimeException: org.keycloak.crypto.SignatureException: Signing failed
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.jose.jws.JWSBuilder$EncodingBuilder.sign(JWSBuilder.java:116)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider.authenticateTokenRequest(AbstractOAuth2IdentityProvider.java:408)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider$Endpoint.generateTokenRequest(AbstractOAuth2IdentityProvider.java:576)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.OIDCIdentityProvider$OIDCEndpoint.generateTokenRequest(OIDCIdentityProvider.java:323)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider$Endpoint.authResponse(AbstractOAuth2IdentityProvider.java:500)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:138)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:546)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:435)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:396)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:398)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:365)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:150)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:110)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:141)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:104)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:440)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:245)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:61)
        at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
        at javax.servlet.api@2.0.0.Final//javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
        at org.keycloak.keycloak-wildfly-extensions@15.0.2//org.keycloak.provider.wildfly.WildFlyRequestFilter.lambda$doFilter$0(WildFlyRequestFilter.java:41)
        at org.keycloak.keycloak-services@15.0.2//org.keycloak.services.filters.AbstractRequestFilter.filter(AbstractRequestFilter.java:43)
        at org.keycloak.keycloak-wildfly-extensions@15.0.2//org.keycloak.provider.wildfly.WildFlyRequestFilter.doFilter(WildFlyRequestFilter.java:39)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
        at io.undertow.core@2.2.5.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
        at io.undertow.core@2.2.5.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
        at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
        at io.undertow.core@2.2.5.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
        at io.undertow.core@2.2.5.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
        at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
        at org.jboss.xnio@3.8.4.Final//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.keycloak.crypto.SignatureException: Signing failed
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.crypto.AsymmetricSignatureSignerContext.sign(AsymmetricSignatureSignerContext.java:53)
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.jose.jws.JWSBuilder$EncodingBuilder.sign(JWSBuilder.java:114)
        ... 80 more
Caused by: java.security.NoSuchAlgorithmException: HMACSHA256 Signature not available
        at java.base/java.security.Signature.getInstance(Signature.java:267)
        at org.keycloak.keycloak-core@15.0.2//org.keycloak.crypto.AsymmetricSignatureSignerContext.sign(AsymmetricSignatureSignerContext.java:48)
        ... 81 more
10:43:06,693 WARN  [org.keycloak.events] (default task-36) type=IDENTITY_PROVIDER_LOGIN_ERROR, realmId=Test, clientId=application, userId=null, ipAddress=10.0.0.2, error=identity_provider_login_failure, code_id=10584c92-b25a-4961-b181-8ebcecc236c8, authSessionParentId=10584c92-b25a-4961-b181-8ebcecc236c8, authSessionTabId=Z9JGLzHz2qk


问:
How to wait for full page load using python beautifulsoup
I'm trying to scrape a site using Python with Beautifulsoup, but the site takes a long time to load and the scraping is fast and doesn't recover completely. I would like to know how to wait 5 seconds before retrieving the source code using Beautifulsoup.

I think a code is like this:

```<code>from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import ssl

ssl._create_default_https_context = ssl._create_unverified_context

url = 'https://www.edocente.com.br/pnld/2020/'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}

req = Request(url, headers = headers)
response = urlopen(req)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
soup.findAll('a', class_="btn bold mt-4 px-5")
</code>```

I can't recovery a whole source code because site is slow to load and my tags aren´t recovered. How to wait to recover the whole source code from site?

I would like to get only the text of the href tags, as below:

```<code><a href="/pnld/2020/obra/companhia-das-ciencias-6-ano-saraiva" class="btn bold mt-4 px-5">Ver Obra </a>
<a href="/pnld/2020/obra/companhia-das-ciencias-7-ano-saraiva" class="btn bold mt-4 px-5">Ver Obra </a>
<a href="/pnld/2020/obra/companhia-das-ciencias-8-ano-saraiva" class="btn bold mt-4 px-5">Ver Obra </a>
</code>```

I'd like to recovery:

```<code>/pnld/2020/obra/companhia-das-ciencias-6-ano-saraiva
/pnld/2020/obra/companhia-das-ciencias-7-ano-saraiva
/pnld/2020/obra/companhia-das-ciencias-8-ano-saraiva
</code>```

How to do it?
Thanks

答:
i guess at this url (https://www.edocente.com.br/pnld/2020/) there is a dynamic website. meaning that you cant load dynamic websites with requests or urllib.

for loading dynamic websites and then save them to beautiful soup you need to use a browser to load the website in the background. there are libaries for doing that.

here is a snippet to load dynamic websites

from playwright.sync_api import sync_playwright

def get_dynamic_soup(url: str) -> BeautifulSoup:
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page()
        page.goto(url)
        soup = BeautifulSoup(page.content(), "html.parser")
        browser.close()
        return soup
```
<p>install the python package</p>
<pre class="lang-sh prettyprint-override"><code>pip install playwright
</code>```

then install the chromium browser (in your terminal)

(shell prompt) > playwright install
```

and you are ready to scrape dynamic websites.

Body:
I'm trying to scrape a site using Python with Beautifulsoup, but the site takes a long time to load and the scraping is fast and doesn't recover completely. I would like to know how to wait 5 seconds before retrieving the source code using Beautifulsoup.

I think a code is like this:

from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import ssl

ssl._create_default_https_context = ssl._create_unverified_context

url = 'https://www.edocente.com.br/pnld/2020/'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}

req = Request(url, headers = headers)
response = urlopen(req)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
soup.findAll('a', class_="btn bold mt-4 px-5")

I can't recovery a whole source code because site is slow to load and my tags aren´t recovered. How to wait to recover the whole source code from site?

I would like to get only the text of the href tags, as below:

Ver Obra
Ver Obra
Ver Obra

I'd like to recovery:

/pnld/2020/obra/companhia-das-ciencias-6-ano-saraiva
/pnld/2020/obra/companhia-das-ciencias-7-ano-saraiva
/pnld/2020/obra/companhia-das-ciencias-8-ano-saraiva

How to do it?
Thanks

Body:
i guess at this url (https://www.edocente.com.br/pnld/2020/) there is a dynamic website. meaning that you cant load dynamic websites with requests or urllib.

for loading dynamic websites and then save them to beautiful soup you need to use a browser to load the website in the background. there are libaries for doing that.

here is a snippet to load dynamic websites

from playwright.sync_api import sync_playwright

def get_dynamic_soup(url: str) -> BeautifulSoup:
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page()
        page.goto(url)
        soup = BeautifulSoup(page.content(), "html.parser")
        browser.close()
        return soup

install the python package

pip install playwright

then install the chromium browser (in your terminal)

(shell prompt) > playwright install

and you are ready to scrape dynamic websites.


问:
Remove consecutive elements given a starting key and an ending key
I have an input array with keys representing 24-hour "military" time and values representing 12-hour "am/pm" time.  I want to remove consecutive elements from my array determined by two variables that contain "military" time values.

Here are my input variables:

```<code>$starttime = '5';
$endtime = '17';
$timings = array(
     '0' => '12AM',
     '1' => '1AM',
     '2' => '2AM',
     '3' => '3AM',
     '4' => '4AM',
     '5' => '5AM',
     '6' => '6AM',
     '7' => '7AM',
     '8' => '8AM',
     '9' => '9AM',
     '10' => '10AM',
     '11' => '11AM',
     '12' => '12PM',
     '13' => '1PM',
     '14' => '2PM',
     '15' => '3PM',
     '16' => '4PM',
     '17' => '5PM',
     '18' => '6PM',
     '19' => '7PM',
     '20' => '8PM',
     '21' => '9PM',
     '22' => '10PM',
     '23' => '11PM',
);

foreach ($timings as $t) {

}
</code>```

I would like to iterate the timings in a foreach loop, but before that, I would like to remove the timings between start time and end time.

Here my $starttime key is 5 and my $endtime key is 17.

So I would like to remove 5,6,7,8,9,10,11,12,13,14,15,16,17 from the array and keep the remaining elements.

Can some tell me how to pop those elements out?

答:
I feel that it is necessary to spell out that some techniques will destroy the original keys and other will preserve the original keys.

Codes: (Demo)

Loses Keys

```<code>function spliceKeys($timings, $starttime, $endtime) {
    array_splice($timings, $starttime, $endtime - $starttime);
    return $timings;

}

function sliceKeys($timings, $starttime, $endtime) {
    return array_merge(
              array_slice($timings, 0, $starttime),
              array_slice($timings, $endtime + 1)
           );
}
</code>```

Keeps Keys

```<code>function diffKeys($timings, $starttime, $endtime) {
    return array_diff_key($timings, array_flip(range($starttime, $endtime)));
}

function skipKeys($timings, $starttime, $endtime) {
    $result = [];
    foreach ($timings as $military => $timing) {
        if ($military >= $starttime && $military <= $endtime) {
            continue;
        }
        $result[$military] = $timing;
    }
    return $result;
}

function unsetKeys($timings, $starttime, $endtime) {
    $result = [];
    foreach ($timings as $military => $timing) {
        if ($military >= $starttime && $military <= $endtime) {
            unset($timings[$military]);
        }
    }
    return $timings;
}
</code>```

Body:
I have an input array with keys representing 24-hour "military" time and values representing 12-hour "am/pm" time.  I want to remove consecutive elements from my array determined by two variables that contain "military" time values.

Here are my input variables:

$starttime = '5';
$endtime = '17';
$timings = array(
     '0' => '12AM',
     '1' => '1AM',
     '2' => '2AM',
     '3' => '3AM',
     '4' => '4AM',
     '5' => '5AM',
     '6' => '6AM',
     '7' => '7AM',
     '8' => '8AM',
     '9' => '9AM',
     '10' => '10AM',
     '11' => '11AM',
     '12' => '12PM',
     '13' => '1PM',
     '14' => '2PM',
     '15' => '3PM',
     '16' => '4PM',
     '17' => '5PM',
     '18' => '6PM',
     '19' => '7PM',
     '20' => '8PM',
     '21' => '9PM',
     '22' => '10PM',
     '23' => '11PM',
);

foreach ($timings as $t) {

}

I would like to iterate the timings in a foreach loop, but before that, I would like to remove the timings between start time and end time.

Here my $starttime key is 5 and my $endtime key is 17.

So I would like to remove 5,6,7,8,9,10,11,12,13,14,15,16,17 from the array and keep the remaining elements.

Can some tell me how to pop those elements out?

Body:
I feel that it is necessary to spell out that some techniques will destroy the original keys and other will preserve the original keys.

Codes: (Demo)

Loses Keys

function spliceKeys($timings, $starttime, $endtime) {
    array_splice($timings, $starttime, $endtime - $starttime);
    return $timings;

}

function sliceKeys($timings, $starttime, $endtime) {
    return array_merge(
              array_slice($timings, 0, $starttime),
              array_slice($timings, $endtime + 1)
           );
}

Keeps Keys

function diffKeys($timings, $starttime, $endtime) {
    return array_diff_key($timings, array_flip(range($starttime, $endtime)));
}

function skipKeys($timings, $starttime, $endtime) {
    $result = [];
    foreach ($timings as $military => $timing) {
        if ($military >= $starttime && $military <= $endtime) {
            continue;
        }
        $result[$military] = $timing;
    }
    return $result;
}

function unsetKeys($timings, $starttime, $endtime) {
    $result = [];
    foreach ($timings as $military => $timing) {
        if ($military >= $starttime && $military <= $endtime) {
            unset($timings[$military]);
        }
    }
    return $timings;
}


问:
Which Linux distribution has the most active/recent Ruby support?
I have installed Ubuntu 11.04 and tried to install Ruby as apt-get install ruby. The default version in repositories was 1.8.7, okay, install 1.9.2 manually. Then I'm going for rubygems, download tar file, install rubygems, try to install something with them, zlib-mistake appeared. Found the solution with rvm, didn't help. Now I'm stuck with broken gem command and useless rvm installed.

The question is - which Linux distribution is the most friendly for a Ruby beginner?

答:
Why don't you

```<code>sudo apt-get install ruby1.9.1
</code>```

out of the box? Of course, you can also use a community ppa to get 1.9.2 and some common bindings out-of-the-box (so you can work easily with, say, Rails 3.0):

http://www.humbug.in/2010/launchpad-ppa-for-ruby-1-9-2-and-some-ruby-bindings/

Body:
Why don't you

sudo apt-get install ruby1.9.1

out of the box? Of course, you can also use a community ppa to get 1.9.2 and some common bindings out-of-the-box (so you can work easily with, say, Rails 3.0):

http://www.humbug.in/2010/launchpad-ppa-for-ruby-1-9-2-and-some-ruby-bindings/


问:
Making map in R of Belgium using the tmap library
I would like to make a map of Belgium and its provinces in R using the 'tmap' library, but I need to specify the shape object, but where can I find this data for Belgium?</p>
```<code>tm_shape(Belgium) + tm_polygons()
</code>```

答:
Found it already,</p>
```<code>install.packages('spDataLarge', repos='https://nowosad.github.io/drat/', type='source')
library(spDataLarge)
data(BE_ADMIN_PROVINCE)
tm_shape(BE_ADMIN_PROVINCE) +  tm_polygons()
</code>```

Body:
I would like to make a map of Belgium and its provinces in R using the 'tmap' library, but I need to specify the shape object, but where can I find this data for Belgium?

tm_shape(Belgium) + tm_polygons()

Body:
Found it already,

install.packages('spDataLarge', repos='https://nowosad.github.io/drat/', type='source')
library(spDataLarge)
data(BE_ADMIN_PROVINCE)
tm_shape(BE_ADMIN_PROVINCE) +  tm_polygons()


问:
thread 'main' panicked at 'attempt to add with overflow', test.rs:15:12
I have been learning rust while practicing recursion. So this is just a simple recursive problem and the type is an signed8 and should be working. But I get this error which I am not able to understand why.

The base case is correct and the calls recursive calls are correct as well.

fn main() {
    let num = ways_to_climb(10);
    println!("{}", num);
}

fn ways_to_climb(n: i8) -> i8 {

    println!("{}", n);
    if n == 0 || n == 1 {
        return 1;
    }
    if n < 0 {
        return 0;
    }
    return ways_to_climb(n - 1) + ways_to_climb(n - 2) + ways_to_climb(n - 3);
}

```

答:
Let's add some more logging:

```<code>fn main() {
    let num = ways_to_climb(10);
    println!("{}", num);
}

fn ways_to_climb(n: i8) -> i8 {
    if n == 0 || n == 1 {
        return 1;
    }
    if n < 0 {
        return 0;
    }

    let (a, b, c) = (ways_to_climb(n - 1), ways_to_climb(n - 2), ways_to_climb(n - 3));
    println!("{} + {} + {}", a, b, c);
    return a + b + c;
}
</code>```

As we can see, the operation it panics on is:

```<code>81 + 44 + 24
</code>```

Indeed, that's 149, and an i8 can only hold -128 to +127. 149 is > 127, so we overflowed.

You'll need a bigger type than i8 to calculate ways_to_climb(10).

Body:
Let's add some more logging:

fn main() {
    let num = ways_to_climb(10);
    println!("{}", num);
}

fn ways_to_climb(n: i8) -> i8 {
    if n == 0 || n == 1 {
        return 1;
    }
    if n < 0 {
        return 0;
    }

    let (a, b, c) = (ways_to_climb(n - 1), ways_to_climb(n - 2), ways_to_climb(n - 3));
    println!("{} + {} + {}", a, b, c);
    return a + b + c;
}

As we can see, the operation it panics on is:

81 + 44 + 24

Indeed, that's 149, and an i8 can only hold -128 to +127. 149 is > 127, so we overflowed.

You'll need a bigger type than i8 to calculate ways_to_climb(10).


问:
How do I setup a foreign key relationship in codefirst without using a navigation property?
Say you have an order class with an order status, I want to declare the OrderStatusId inside the OrderStatus class.  However, no foreign key relationship is set-up by default. If I use [ForeignKey] attribute on the column it seems to demand a navigation property which I don't want as this would mean having to carry out joins on the navigation property in all of my queries just to check the status.

How do I accomplish this in EF codefirst?  Define a property as a foreign key without using a navigation property.

```<code>public class Order
{
  public int OrderId;

  public int OrderStatusId;
  // properties...
}

public class OrderStatus
{
  public int OrderStatusId;
  public string Status;
}
</code>```

答: You always need navigation property on at least one side to build a relation. If you don't have navigation properties you have nothing to bind your your foreign key with and it will remain as common column.</p>

Body:
Say you have an order class with an order status, I want to declare the OrderStatusId inside the OrderStatus class.  However, no foreign key relationship is set-up by default. If I use [ForeignKey] attribute on the column it seems to demand a navigation property which I don't want as this would mean having to carry out joins on the navigation property in all of my queries just to check the status.

How do I accomplish this in EF codefirst?  Define a property as a foreign key without using a navigation property.

public class Order
{
  public int OrderId;

  public int OrderStatusId;
  // properties...
}

public class OrderStatus
{
  public int OrderStatusId;
  public string Status;
}


问:
my program window is not responding .why idk?
```<code>
    import psutil
    import time
    from tkinter import *
    def eventc(event):
        while True :
            print(psutil.cpu_stats())
            time.sleep(2)

    def closewin(event):
        exit(0)

    def myevent(event):
        print('okayy')
    window=Tk()
    #button for stats
    btn=Button(window, text="click me for cpu stats", fg='blue')
    btn.place(x=80, y=100)
    btn.bind('<Button>',eventc)
    #btn for closing the window
    winclose=Button(window, text="close window", fg='blue')
    winclose.place(x=95, y=0)
    winclose.bind('<Button>',closewin)
    #for window
    window.title('my \'so called first app\'')
    window.geometry("300x200+10+10")
    window.mainloop()

</code>```

When I click get cpu stats is gives me stats but the window will not respond after that.
and after forcefully ending the window it give me this exit code:Process finished with exit code -805306369 (0xCFFFFFFF)
can you help me why

答:
The while loop inside eventc() will block tkinter mainloop from handling pending events and updates.  Suggest to use .after() to replace the while loop:

def eventc(event=None):
    print(psutil.cpu_stats())
    window.after(2000, eventc) # execute eventc() 2000ms later
```

Body:
    import psutil
    import time
    from tkinter import *
    def eventc(event):
        while True :
            print(psutil.cpu_stats())
            time.sleep(2)

    def closewin(event):
        exit(0)

    def myevent(event):
        print('okayy')
    window=Tk()
    #button for stats
    btn=Button(window, text="click me for cpu stats", fg='blue')
    btn.place(x=80, y=100)
    btn.bind('<Button>',eventc)
    #btn for closing the window
    winclose=Button(window, text="close window", fg='blue')
    winclose.place(x=95, y=0)
    winclose.bind('<Button>',closewin)
    #for window
    window.title('my \'so called first app\'')
    window.geometry("300x200+10+10")
    window.mainloop()

When I click get cpu stats is gives me stats but the window will not respond after that.
and after forcefully ending the window it give me this exit code:Process finished with exit code -805306369 (0xCFFFFFFF)
can you help me why


问:
Postgresql - How to improve low cache hit ratio
If the cache hit ratio for a database is below 50%. Are there other ways than increasing the shared_buffers to improve this ratio</p>

答:
see: Re: Increased shared_buffer setting = lower hit ratio ?

what exactly do you mean by hit ratio - is that the page cache hit
ratio (filesystem cache), or shared buffers hit ratio (measured e.g.
using pg_buffercache)?

Regarding the unexpected decrease of performance after increasing
shared_buffers - that's actually quite common behavior. First, the
management of shared buffers is not free, and the more pieces you need
to manage the more expensive it is. Also, by using larger shared
buffers you make that memory unusable for page cache etc. There are
also other negative consequences - double buffering, accumulating more
changes for a checkpoint etc.

The common wisdom (which some claim to be obsolete) is not to set
shared buffers over ~10GB of RAM. It's however very workload-dependent
so your mileage may vary.

To get some basic idea of the shared_buffers utilization, it's
possible to compute stats using pg_buffercache. Also pg_stat_bgwriter
contains useful data.

BTW, it's difficult to say why a query is slow - can you post explain
analyze of the query with both shared_buffers settings?

And just to check - what kind of hardware/kernel version is this? Do
you have numa / transparent huge pages or similar trouble-indicing
issues?

So why do you want to increase cache hit ratio ?

What do you think is a good ratio?


问:
Spring cron scheduler for every 59 seconds do double run
I need my task to run every 59 seconds from 9am to 6pm, I mean not at 59 seconds of every minute, but 59 seconds after the previous run ends. So i set such a cron to my sheduler */59 * 9-21 * * *

There is a code

```<code>@Scheduled(cron = "*/59 * 9-21 * * *")
public void schedule() {
    try {
        log.info("Scheduler starts!");
    } catch (Exception e) {
        log.error("Error was caught in scheduler", e);
    }
}
</code>```

And that's what I see in log:

```<code>2022-02-09 16:01:00.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:01:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:02:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:02:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:03:00.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:03:59.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:04:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:04:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:05:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:05:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:06:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:06:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:07:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
</code>```

Why does it work in such way and duplicate run at 59 and 00 seconds of each minute? Is my cron wrong?

UPD:
I'm using grails 4.0.1

答:
I think there is a bug in the scheduler.

With the following test code You will see that 2 schedules occur when the current time is in the second 59 on in second 00.

```<code>  Set<String> x = new HashSet<>();
    List<LocalDateTime> y = new ArrayList<>();
    while (true) {

      var expression = CronExpression.parse("*/59 * 9-21 * * *");
      final LocalDateTime now = LocalDateTime.now();
      y.add(now);
      x.add(expression.next(now).toString());
      System.out.println(x);
      Thread.sleep(500);

      if (x.size() > 2){
        break;
      }
    }

    System.out.println(x);
</code>```

I obtained 3 results

[2022-02-09T15:58:59, 2022-02-09T15:59:59, 2022-02-09T15:59]

For the following dates:

I've tested this with Spring Boot version 2.6.3.

Body:
I need my task to run every 59 seconds from 9am to 6pm, I mean not at 59 seconds of every minute, but 59 seconds after the previous run ends. So i set such a cron to my sheduler */59 * 9-21 * * *

There is a code

@Scheduled(cron = "*/59 * 9-21 * * *")
public void schedule() {
    try {
        log.info("Scheduler starts!");
    } catch (Exception e) {
        log.error("Error was caught in scheduler", e);
    }
}

And that's what I see in log:

2022-02-09 16:01:00.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:01:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:02:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:02:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:03:00.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:03:59.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:04:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:04:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:05:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:05:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:06:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:06:59.002 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!
2022-02-09 16:07:00.001 | spring-vault-ThreadPoolTaskScheduler-1 | INFO  | com.app.MyScheduler             [ / ] -       Scheduler starts!

Why does it work in such way and duplicate run at 59 and 00 seconds of each minute? Is my cron wrong?

UPD:
I'm using grails 4.0.1

Body:
I think there is a bug in the scheduler.

With the following test code You will see that 2 schedules occur when the current time is in the second 59 on in second 00.

  Set<String> x = new HashSet<>();
    List<LocalDateTime> y = new ArrayList<>();
    while (true) {

      var expression = CronExpression.parse("*/59 * 9-21 * * *");
      final LocalDateTime now = LocalDateTime.now();
      y.add(now);
      x.add(expression.next(now).toString());
      System.out.println(x);
      Thread.sleep(500);

      if (x.size() > 2){
        break;
      }
    }

    System.out.println(x);

I obtained 3 results

[2022-02-09T15:58:59, 2022-02-09T15:59:59, 2022-02-09T15:59]

For the following dates:

I've tested this with Spring Boot version 2.6.3.


问:
C++ equivalent of Python properties
Is there an equivalent of Python properties in C++? Or would it just be better to do this using getters and setters?</p>

答:
In C++ you're either calling a member function, or you're accessing a data member. Python properties are essentially a way of doing the former using the syntax of the latter and there's no sensible way to do that in C++.

In theory you could hack together something with a macro, #define looks_like_data really_a_function() but it wouldn't be pretty. Or sensible. The only necessary reason to make a function look like data is to maintain compatibility with old calling code back from when it used to be data. But in C++ this won't give you binary compatibility, and it doesn't even really give you source compatibility given that the macro will break calling code that already uses the name looks_like_data for something else in another context. So there's not a lot of point.

Another thing you could do is to create an actual data member that acts as a proxy for the "logical" type of the data:

```<code>struct Proxy {
    Foo *foo;
    Proxy(Foo *foo) : foo(foo) { }
    operator int() const {
        // getter code goes here,
        // use (const Foo*)foo rather than foo
    }
    Proxy &operator=(int a) {
       // setter code goes here
    }
    // optionally also implement boilerplate +=, -=, etc.
};

struct Foo {
    // optionally
    // friend class Proxy;
    Proxy looks_like_data;
    Foo() : looks_like_data(this) { }
};
</code>```

This is almost, but not quite, sensible. Using an implicit conversion still breaks source compatibility, because there's a rule that there can only be one user-defined implicit conversion in a chain, so if a caller has written code back when looks_like_data really was an int, and their code implicitly converts that int to Bar, then once looks_like_data becomes a Proxy it will no longer implicitly convert to Bar and you've broken their code anyway.

So after all that, you're best using getter/setter functions if your class really needs something that looks like a read/write property.

Title: C++ equivalent of Python properties

Body:
In C++ you're either calling a member function, or you're accessing a data member. Python properties are essentially a way of doing the former using the syntax of the latter and there's no sensible way to do that in C++.

In theory you could hack together something with a macro, #define looks_like_data really_a_function() but it wouldn't be pretty. Or sensible. The only necessary reason to make a function look like data is to maintain compatibility with old calling code back from when it used to be data. But in C++ this won't give you binary compatibility, and it doesn't even really give you source compatibility given that the macro will break calling code that already uses the name looks_like_data for something else in another context. So there's not a lot of point.

Another thing you could do is to create an actual data member that acts as a proxy for the "logical" type of the data:

struct Proxy {
    Foo *foo;
    Proxy(Foo *foo) : foo(foo) { }
    operator int() const {
        // getter code goes here,
        // use (const Foo*)foo rather than foo
    }
    Proxy &operator=(int a) {
       // setter code goes here
    }
    // optionally also implement boilerplate +=, -=, etc.
};

struct Foo {
    // optionally
    // friend class Proxy;
    Proxy looks_like_data;
    Foo() : looks_like_data(this) { }
};

This is almost, but not quite, sensible. Using an implicit conversion still breaks source compatibility, because there's a rule that there can only be one user-defined implicit conversion in a chain, so if a caller has written code back when looks_like_data really was an int, and their code implicitly converts that int to Bar, then once looks_like_data becomes a Proxy it will no longer implicitly convert to Bar and you've broken their code anyway.

So after all that, you're best using getter/setter functions if your class really needs something that looks like a read/write property.


问:
Import errors when debugging Python unit tests in VSCode
I'm trying to debug a Python unit test inside Visual Studio Code, but am getting an error while importing dependencies at the top of the file:

```<code>import unittest
from scipy.io import loadmat  # exception thrown here
</code>```

I get a lengthy exception message:

```<code>Exception has occurred: ImportError       (note: full exception trace is shown but execution is paused at: <module>)`
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
...
</code>```

This happens only when debugging.  Any ideas why?  How can I fix this?

答:
Seems like the way around is to open Anaconda Powershell and type:

```<code>cd <my project folder>
conda activate <myenv>
code .
</code>```

This starts VSCode with the correct configuration.  It's an ugly hack, but allows me to run and debug my unit tests.

Body:
I'm trying to debug a Python unit test inside Visual Studio Code, but am getting an error while importing dependencies at the top of the file:

import unittest
from scipy.io import loadmat  # exception thrown here

I get a lengthy exception message:

Exception has occurred: ImportError       (note: full exception trace is shown but execution is paused at: <module>)`
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
...

This happens only when debugging.  Any ideas why?  How can I fix this?

Body:
Seems like the way around is to open Anaconda Powershell and type:

cd <my project folder>
conda activate <myenv>
code .

This starts VSCode with the correct configuration.  It's an ugly hack, but allows me to run and debug my unit tests.


问:
How to merge two pandas columns into one column?
I merged two data frames together and I want to combine two pandas columns as follows:

df1:

```<code>A   B   C
1   3  NaN
2  Nan  2
3   5  NaN
4  NaN  1
</code>```

I want to get a result like the following:

df1:

```<code>A   BC
1   3
2   2
3   5
4   1
</code>```

答:
```<code>import pandas as pd

df = pd.read_csv("df1.csv")
df.fillna(0, inplace=True)
df["BC"] = df["B"] + df["C"]
df.drop(["B", "C"], axis=1, inplace=True)
</code>```

Body:
I merged two data frames together and I want to combine two pandas columns as follows:

df1:

A   B   C
1   3  NaN
2  Nan  2
3   5  NaN
4  NaN  1

I want to get a result like the following:

df1:

A   BC
1   3
2   2
3   5
4   1


问:
Firebase ApiFuture to CompletableFuture in a reactive stack
I am using the Firebase Admin Java SDK in a server side Spring WebFlux environment. The Firebase SDK provides two methods for each operation. A synchronous ".doOperation()" method which returns a result and a ".doOperationAsync()" method which returns an instance of ApiFuture.

The Javadoc for ApiFuture can be found here.

ApiFuture extends from java.util.concurrent.Future, which is no longer supported by Mono.fromFuture().

Is there a way to convert Googles ApiFuture into a Mono?

答:
It's possible to convert ApiFuture to CompletableFuture, which can be used with Mono.fromFuture:</p>
```<code>internal class ApiCompletableFuture<V>(
    private val future: ApiFuture<V>,
    executor: Executor = directExecutor(),
) : CompletableFuture<V>(), ApiFutureCallback<V> {
    init {
        ApiFutures.addCallback(future, this, executor)
    }

    override fun cancel(mayInterruptIfRunning: Boolean): Boolean {
        future.cancel(mayInterruptIfRunning)
        return super.cancel(mayInterruptIfRunning)
    }

    override fun onSuccess(result: V) {
        complete(result)
    }

    override fun onFailure(t: Throwable) {
        completeExceptionally(t)
    }
}
</code>```

Body:
It's possible to convert ApiFuture to CompletableFuture, which can be used with Mono.fromFuture:

internal class ApiCompletableFuture<V>(
    private val future: ApiFuture<V>,
    executor: Executor = directExecutor(),
) : CompletableFuture<V>(), ApiFutureCallback<V> {
    init {
        ApiFutures.addCallback(future, this, executor)
    }

    override fun cancel(mayInterruptIfRunning: Boolean): Boolean {
        future.cancel(mayInterruptIfRunning)
        return super.cancel(mayInterruptIfRunning)
    }

    override fun onSuccess(result: V) {
        complete(result)
    }

    override fun onFailure(t: Throwable) {
        completeExceptionally(t)
    }
}


问:
How to pass string argument to the python script saving quotes in it
I am having trouble with passing a string argument to a Python script.

I need to pass a string in this format: "{"test_key_1": [1, 3], "test_key_2": [5]}"

but when I am doing this:

```<code>test_script.py --test_arg "{"test_key_1": [1, 3], "test_key_2": [5]}"
</code>```

I am getting this string inside the script:

```<code>'{test_key_1: [1, 3], test_ket_2: [5]}'
</code>```

Why did my double quotes disappear?

I need to do json.loads(string_argument) after I get the argument, but it fails because of the wrong format.

答:
Either escape the inner quotes or use single quotes as the delimiter:</p>
```<code>test_script.py --test_arg '{"test_key_1": [1, 3], "test_key_2": [5]}'
</code>```

Body:
I am having trouble with passing a string argument to a Python script.

I need to pass a string in this format: "{"test_key_1": [1, 3], "test_key_2": [5]}"

but when I am doing this:

test_script.py --test_arg "{"test_key_1": [1, 3], "test_key_2": [5]}"

I am getting this string inside the script:

'{test_key_1: [1, 3], test_ket_2: [5]}'

Why did my double quotes disappear?

I need to do json.loads(string_argument) after I get the argument, but it fails because of the wrong format.

Body:
Either escape the inner quotes or use single quotes as the delimiter:

test_script.py --test_arg '{"test_key_1": [1, 3], "test_key_2": [5]}'