问:
Sometimes get "cURL error 35: Unknown SSL protocol error" when connecting to twitter API
We are trying to link a user to their twitter account letting that user tweet from our site.  We get the "cURL error 35" error, but only sometimes.  The error directs us to a page that states we should see what is in the error buffer but because we are using socialite, I am unsure how to access that?

I have discovered various cURL options to enable more output, but can't for the life of me determine how to get socialite to use those?  It seems that a vendor package (socialite) is calling a vendor package (guzzle) that is calling curlFactory and I need to tell that last vendor package to output more verbose errors, to some log file somewhere?

Currently using: Laravel 5.4, laravel-socialite 3, socialiteproviders/twitter 3.

The full error:

cURL error 35: Unknown SSL protocol error in connection to api.twitter.com:443 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Any assistance would be greatly appreciated.

[EDIT]
We have narrowed this issue down to a server side configuration.  Running this command:

```<code>curl 'https://api.twitter.com/oauth2/token'
</code>```

from the server eventually leads to the cURL 35 error.  But!  We run the same command from inside our vagrant machines and it works 100% of the time.

cURL version is 7.38 on the production server, but is 7.35 inside my vagrant machine.

[UPDATE]

Our Server admin has been dealing with this on and off for the past few days.  He reports that he still cannot get this to work.  He even downgraded to 7.35, which worked on our previous server to no avail.  It seems that the cURL packages in general are not playing nice with Debian 8 and php7.

Does anyone, in the whole wide world, and any ET's out there spying on us have any idea what is going on??  We are trying to work with Social Networks and it is a huge pain when EVERYONE says use cURL.

[UPDATE 2]

I have found similar posts on the twitter developer forums.  From a twitter staff member:

```<code>Twitter supports TLS 1.2 - SSLv3 was withdrawn some time ago3. I doubt
this is the specific reason for the error you are seeing - that's more
likely to be possibly related to routing between datacenters, I
imagine. Hard to say what the specific issue here is. 7 out of 10
failing calls does sound unusually high, but then the timeouts are a
bit surprising too.
</code>```

Honestly would have been great if these forum posts showed in google when searching for this error.

While we wait for our server guy to look into TLS, we are making attempts to contact twitter.  Will update this post if anything comes of either of these routes.

[UPDATE 3]

This post is officially a month old and no luck!  Here are the latest steps our server admin has tried:

```<code>Updated all root certs in our server

Added twitter specific digi-cert (downloaded and added as files, made the SSL system look for it)

confirmed our cipher match twitters requested ciphers

Scanned our server with ssllabs.com (scans entire system and outputs details about cypers and ssl cert.) - We passed no issues found

CLI output says SHA2, the error in the Laravel stack trace says SHA1

DNS Caching issue, added DNS caching to server (there wasn't any before)

way to tell curl what cert to use, manually told it to use twitters cert, no clear problem reported, wasn't getting expected responses though.

insured certs are not expired.

3 common SSL issues with cURL:  destination does not like cypher, does not like protocol, private key has expired.

Sever admin went through all twitter dev info.  (https://developer.twitter.com/en/docs/basics/authentication/guides/tls)
</code>```

We have ran cURL in the CLI with verbose mode on, when it PASSES the output looks like:

curl -v 'https://api.twitter.com/oauth2/token'

```<code>* Hostname was NOT found in DNS cache
*   Trying 104.244.42.130...
* Connected to api.twitter.com (104.244.42.130) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* Unknown SSL protocol error in connection to api.twitter.com:443
* Closing connection 0
curl: (35) Unknown SSL protocol error in connection to api.twitter.com:443
</code>```

And when it passes, it looks like:

```<code>* Hostname was NOT found in DNS cache
*   Trying 104.244.42.2...
* Connected to api.twitter.com (104.244.42.2) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
*    subject: C=US; ST=California; L=San Francisco; O=Twitter, Inc.; OU=Twitter Security; CN=api.twitter.com
*    start date: 2016-06-29 00:00:00 GMT
*    expire date: 2019-09-19 12:00:00 GMT
*    subjectAltName: api.twitter.com matched
*    issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
*    SSL certificate verify ok.
> GET /oauth2/token HTTP/1.1
> User-Agent: curl/7.38.0
> Host: api.twitter.com
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< allow: POST
< cache-control: no-cache
< content-length: 0
< content-security-policy: default-src 'none'; connect-src 'self'; font-src https://abs.twimg.com https://abs-0.twimg.com data:; frame-src 'self' twitter:; img-src https://abs.twimg.com https://*.twimg.com https://pbs.twimg.com data:; media-src 'none'; object-src 'none'; script-src https://abs.twimg.com https://abs-0.twimg.com https://twitter.com https://mobile.twitter.com; style-src https://abs.twimg.com https://abs-0.twimg.com; report-uri https://twitter.com/i/csp_report?a=NVQWGYLXFVWG6Z3JNY%3D%3D%3D%3D%3D%3D&ro=false;
< date: Thu, 21 Dec 2017 17:40:24 GMT
* Server tsa_b is not blacklisted
< server: tsa_b
< set-cookie: personalization_id="v1_Txp6AuuonT7REMqCB7vkzg=="; Expires=Sat, 21 Dec 2019 17:40:24 UTC; Path=/; Domain=.twitter.com
< set-cookie: guest_id=v1%3A151387802465523279; Expires=Sat, 21 Dec 2019 17:40:24 UTC; Path=/; Domain=.twitter.com
< status: 400 Bad Request
< strict-transport-security: max-age=631138519
< x-connection-hash: a5a497e59a35ec28ab7fae706c69598b
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-response-time: 5
< x-transaction: 006fdc83002993a0
< x-xss-protection: 1; mode=block
<
* Connection #0 to host api.twitter.com left intact
</code>```

The top level stack trace item from Laravel when this fails looks like:

```<code>TwitterOAuthException
Unknown SSL protocol error in connection to api.twitter.com:443

in TwitterOAuth.php (line 440)
at TwitterOAuth->request('https://api.twitter.com/oauth/access_token',
'POST', 'Authorization: OAuth oauth_version="1.0",
oauth_nonce="a93b697784a0b2d3ceaaf203d4d9aff8",
oauth_timestamp="1513875885",
oauth_consumer_key="T79KMPJi0Wx64fbmwoa606gut",
oauth_verifier="5ZKcm8A2VN6muXFwOBOdTaFRGyPnA9bi",
oauth_signature_method="HMAC-SHA1",
oauth_signature="Q4DkMhNz3eImT9T%2BbbDxgVZyRno%3D"', array())
in TwitterOAuth.php (line 357)
</code>```

In the stack trace you see:
    oauth_signature_method="HMAC-SHA1",

And in the CLI success output, you see

```<code>CN=DigiCert SHA2
</code>```

A clue?  Our Server Admin has an almost exact clone of our server and he doesn't have the issue, my local Ubuntu 17 system doesn't have the issue, and when I ssh into vagrant on my local system, running some scotch-box I don't have the issue.

I'm pretty sure I mentioned earlier in this post, BUT, there are exact issues on the twitter developer forum pertaining to curl 35 errors, each with no solution.  None of which should up when you are searching for this issue on google.

[Jan 26th 2018 Update]

Well, we finally have some concrete information.

We currently have 2 servers.  One in a cluster on the east coast, and one in another cluster on the west.  Our server admin had a clone of our server, on one of the same clusters we were on and claimed he could not reproduce it.  Well, he moved to what ended up being the problematic cluster and sure enough, the curl 35 issue started showing up.

We are currently opening up a dialog with our Host, and we are migrating our server to the cluster that is working.

At this point it seems pretty clear that the points the twitter API was bouncing us to occasionally included a point that didn't like where the call was coming from.  That there wasn't anything we could change in the code, or the server configuration that would fix this issue.

There are many similar posts in the twitter forums, and they all come to dead ends.  Trying to contact twitter leads you to talking to some bot in a chat.  So unfortunately I don't think twitter will make any moves towards fixing this if they have not already.

I will of course update this post if this ends up being the solution, and marking this post as solved.

答:
It's outdated, but it may be MTU size mismatch.

Try check MTU size in host machine and container. Or in host machine and router. As I understood packets during handshake marked as DoNotFragment, and if container used larger MTU size than host, sometimes bigger packest can't reach destination and dropped.

You can discover valid MTU using this command.

```<code>traceroute --mtu <target>
</code>```

[1] https://www.computerhope.com/unix/utracero.htm

[2] https://unix.stackexchange.com/questions/59854/discover-mtu-between-me-and-destination-ip

[3] https://blog.trukhin.com/решение-проблемы-curl-unknown-ssl-protocol-error-in-connection-to-google-com-443-20eea7700805

Body:
We are trying to link a user to their twitter account letting that user tweet from our site.  We get the "cURL error 35" error, but only sometimes.  The error directs us to a page that states we should see what is in the error buffer but because we are using socialite, I am unsure how to access that?

I have discovered various cURL options to enable more output, but can't for the life of me determine how to get socialite to use those?  It seems that a vendor package (socialite) is calling a vendor package (guzzle) that is calling curlFactory and I need to tell that last vendor package to output more verbose errors, to some log file somewhere?

Currently using: Laravel 5.4, laravel-socialite 3, socialiteproviders/twitter 3.

The full error:

cURL error 35: Unknown SSL protocol error in connection to api.twitter.com:443 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Any assistance would be greatly appreciated.

[EDIT]
We have narrowed this issue down to a server side configuration.  Running this command:

curl 'https://api.twitter.com/oauth2/token'

from the server eventually leads to the cURL 35 error.  But!  We run the same command from inside our vagrant machines and it works 100% of the time.

cURL version is 7.38 on the production server, but is 7.35 inside my vagrant machine.

[UPDATE]

Our Server admin has been dealing with this on and off for the past few days.  He reports that he still cannot get this to work.  He even downgraded to 7.35, which worked on our previous server to no avail.  It seems that the cURL packages in general are not playing nice with Debian 8 and php7.

Does anyone, in the whole wide world, and any ET's out there spying on us have any idea what is going on??  We are trying to work with Social Networks and it is a huge pain when EVERYONE says use cURL.

[UPDATE 2]

I have found similar posts on the twitter developer forums.  From a twitter staff member:

Twitter supports TLS 1.2 - SSLv3 was withdrawn some time ago3. I doubt
this is the specific reason for the error you are seeing - that's more
likely to be possibly related to routing between datacenters, I
imagine. Hard to say what the specific issue here is. 7 out of 10
failing calls does sound unusually high, but then the timeouts are a
bit surprising too.

Honestly would have been great if these forum posts showed in google when searching for this error.

While we wait for our server guy to look into TLS, we are making attempts to contact twitter.  Will update this post if anything comes of either of these routes.

[UPDATE 3]

This post is officially a month old and no luck!  Here are the latest steps our server admin has tried:

Updated all root certs in our server

Added twitter specific digi-cert (downloaded and added as files, made the SSL system look for it)

confirmed our cipher match twitters requested ciphers

Scanned our server with ssllabs.com (scans entire system and outputs details about cypers and ssl cert.) - We passed no issues found

CLI output says SHA2, the error in the Laravel stack trace says SHA1

DNS Caching issue, added DNS caching to server (there wasn't any before)

way to tell curl what cert to use, manually told it to use twitters cert, no clear problem reported, wasn't getting expected responses though.

insured certs are not expired.

3 common SSL issues with cURL:  destination does not like cypher, does not like protocol, private key has expired.

Sever admin went through all twitter dev info.  (https://developer.twitter.com/en/docs/basics/authentication/guides/tls)

We have ran cURL in the CLI with verbose mode on, when it PASSES the output looks like:

curl -v 'https://api.twitter.com/oauth2/token'

* Hostname was NOT found in DNS cache
*   Trying 104.244.42.130...
* Connected to api.twitter.com (104.244.42.130) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* Unknown SSL protocol error in connection to api.twitter.com:443
* Closing connection 0
curl: (35) Unknown SSL protocol error in connection to api.twitter.com:443

And when it passes, it looks like:

* Hostname was NOT found in DNS cache
*   Trying 104.244.42.2...
* Connected to api.twitter.com (104.244.42.2) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
*    subject: C=US; ST=California; L=San Francisco; O=Twitter, Inc.; OU=Twitter Security; CN=api.twitter.com
*    start date: 2016-06-29 00:00:00 GMT
*    expire date: 2019-09-19 12:00:00 GMT
*    subjectAltName: api.twitter.com matched
*    issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
*    SSL certificate verify ok.
> GET /oauth2/token HTTP/1.1
> User-Agent: curl/7.38.0
> Host: api.twitter.com
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< allow: POST
< cache-control: no-cache
< content-length: 0
< content-security-policy: default-src 'none'; connect-src 'self'; font-src https://abs.twimg.com https://abs-0.twimg.com data:; frame-src 'self' twitter:; img-src https://abs.twimg.com https://*.twimg.com https://pbs.twimg.com data:; media-src 'none'; object-src 'none'; script-src https://abs.twimg.com https://abs-0.twimg.com https://twitter.com https://mobile.twitter.com; style-src https://abs.twimg.com https://abs-0.twimg.com; report-uri https://twitter.com/i/csp_report?a=NVQWGYLXFVWG6Z3JNY%3D%3D%3D%3D%3D%3D&ro=false;
< date: Thu, 21 Dec 2017 17:40:24 GMT
* Server tsa_b is not blacklisted
< server: tsa_b
< set-cookie: personalization_id="v1_Txp6AuuonT7REMqCB7vkzg=="; Expires=Sat, 21 Dec 2019 17:40:24 UTC; Path=/; Domain=.twitter.com
< set-cookie: guest_id=v1%3A151387802465523279; Expires=Sat, 21 Dec 2019 17:40:24 UTC; Path=/; Domain=.twitter.com
< status: 400 Bad Request
< strict-transport-security: max-age=631138519
< x-connection-hash: a5a497e59a35ec28ab7fae706c69598b
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-response-time: 5
< x-transaction: 006fdc83002993a0
< x-xss-protection: 1; mode=block
<
* Connection #0 to host api.twitter.com left intact

The top level stack trace item from Laravel when this fails looks like:

TwitterOAuthException
Unknown SSL protocol error in connection to api.twitter.com:443

in TwitterOAuth.php (line 440)
at TwitterOAuth->request('https://api.twitter.com/oauth/access_token',
'POST', 'Authorization: OAuth oauth_version="1.0",
oauth_nonce="a93b697784a0b2d3ceaaf203d4d9aff8",
oauth_timestamp="1513875885",
oauth_consumer_key="T79KMPJi0Wx64fbmwoa606gut",
oauth_verifier="5ZKcm8A2VN6muXFwOBOdTaFRGyPnA9bi",
oauth_signature_method="HMAC-SHA1",
oauth_signature="Q4DkMhNz3eImT9T%2BbbDxgVZyRno%3D"', array())
in TwitterOAuth.php (line 357)

In the stack trace you see:
    oauth_signature_method="HMAC-SHA1",

And in the CLI success output, you see

CN=DigiCert SHA2

A clue?  Our Server Admin has an almost exact clone of our server and he doesn't have the issue, my local Ubuntu 17 system doesn't have the issue, and when I ssh into vagrant on my local system, running some scotch-box I don't have the issue.

I'm pretty sure I mentioned earlier in this post, BUT, there are exact issues on the twitter developer forum pertaining to curl 35 errors, each with no solution.  None of which should up when you are searching for this issue on google.

[Jan 26th 2018 Update]

Well, we finally have some concrete information.

We currently have 2 servers.  One in a cluster on the east coast, and one in another cluster on the west.  Our server admin had a clone of our server, on one of the same clusters we were on and claimed he could not reproduce it.  Well, he moved to what ended up being the problematic cluster and sure enough, the curl 35 issue started showing up.

We are currently opening up a dialog with our Host, and we are migrating our server to the cluster that is working.

At this point it seems pretty clear that the points the twitter API was bouncing us to occasionally included a point that didn't like where the call was coming from.  That there wasn't anything we could change in the code, or the server configuration that would fix this issue.

There are many similar posts in the twitter forums, and they all come to dead ends.  Trying to contact twitter leads you to talking to some bot in a chat.  So unfortunately I don't think twitter will make any moves towards fixing this if they have not already.

I will of course update this post if this ends up being the solution, and marking this post as solved.

Body:
It's outdated, but it may be MTU size mismatch.

Try check MTU size in host machine and container. Or in host machine and router. As I understood packets during handshake marked as DoNotFragment, and if container used larger MTU size than host, sometimes bigger packest can't reach destination and dropped.

You can discover valid MTU using this command.

traceroute --mtu <target>

[1] https://www.computerhope.com/unix/utracero.htm

[2] https://unix.stackexchange.com/questions/59854/discover-mtu-between-me-and-destination-ip

[3] https://blog.trukhin.com/решение-проблемы-curl-unknown-ssl-protocol-error-in-connection-to-google-com-443-20eea7700805


来源: stackexchange

问:
In GAE Java Standard environment how to scale based on memory consumption?
I developed an application, that makes some calculations, and those calculations consumes memory, the user need to use same machine recursivelly then after 15 minutes without use the memory is cleared, but if I got many users acessing the instance I got memory out problems, its normal, because the algorithm was created to consume memory, the point is I can tell the autoscaling to scale if processing goes above 80%, but I can't scale if memory goes above 80%, anyone know or have an idea about how to scale GAE Standard based on memory consumption?

TIA

答:
The only possible automatic scaling settings that can be configured for the App Engine standard environment are:

target_cpu_utilization

target_throughput_utilization

max_concurrent_requests

Find the documentation here and these are the corresponding parameters that you'll need to configure on your app.yaml file.

Notice that if you could somehow correlate the RAM used for your specific application with the concurrent requests, throughput utilization or the CPU utilization you could change the respective parameter(s) on your app.yaml file in order for your application to scale accordingly, but there is currently not a way to be able to enable automatic scaling on App Engine applications in the Standard environment based precisely on memory usage.

ContentLicense: CC BY-SA 4.0


问:
Prometheus client library for ASP.NET WebAPI
I've found a lot of NuGet packages for ASPNetCore-targeted Prometheus metrics exporters, but I can't find a single one for the "old good" ASP.NET WebAPI.

I need a client library somewhat similar to Prometheus.Client or prometheus-net that can register the end-point among other WebAPI controllers and expose the metrics gathered in different places in a standard Prometheus-compatible format.

DI, attributes and other Asp.Net goodies are welcome, but not must.

答:
Prometheus already has a .Net Framework package.

See https://github.com/prometheus-net/prometheus-net

Nuget package for ASP.NET Web API middleware on .NET Framework: prometheus-net.NetFramework.AspNet

Install-Package prometheus-net.NetFramework.AspNet


问:
How to cache Windows docker images on Linux?
What is the best way to cache Windows container images on a Linux system?
Setting up a registry mirror won't work because pulling a Windows image from Linux gets me a

no matching manifest for linux/amd64 in the manifest list entries

One option would be setting up the registry mirror in a Windows inside a Virtual Machine, but I hope there are better solutions.

答: The image architecture that Docker attempts to pull is determined by the client, not by the server. You can run your registry server under Linux and perform you docker push/pull from Windows.


问:
Athena: How to check number of duplicate elements in arrays of different rows
My table is on AWS Athena. I am not familiar with SQL or HIVE or Athena in general. I have the following table

```<code>col_id , col_list
ABC    , [abcde, 123gd, 12345, ...]
B3C    , [bbbbb, ergdg, 12345, ...]
YUT    , [uyteh, bbbbb, 12345, ...]

</code>```

col_id is unique and the elements in the array of one single row are also unique.

I need to run a query that count the total number of elements that repeat in different arrays in different rows. In the example above, the array element 12345 shows up in 1st, 2nd, and 3rd rows, and bbbbb shows up in 2nd and 3rd rows, so the number of repetitive elements is 2.

The number of rows is not big so I guess the performance is not a concern here.

Could anyone please let me know how to write this query in Athena?  Thank you!

答:
You can explode the array and aggregate:</p>

```<code>select col, count(*)
from t lateral view
     explode(t.col_list) col
group by col
order by count(*) desc;
</code>```

Body:
My table is on AWS Athena. I am not familiar with SQL or HIVE or Athena in general. I have the following table

col_id , col_list
ABC    , [abcde, 123gd, 12345, ...]
B3C    , [bbbbb, ergdg, 12345, ...]
YUT    , [uyteh, bbbbb, 12345, ...]

col_id is unique and the elements in the array of one single row are also unique.

I need to run a query that count the total number of elements that repeat in different arrays in different rows. In the example above, the array element 12345 shows up in 1st, 2nd, and 3rd rows, and bbbbb shows up in 2nd and 3rd rows, so the number of repetitive elements is 2.

The number of rows is not big so I guess the performance is not a concern here.

Could anyone please let me know how to write this query in Athena?  Thank you!

Body:
You can explode the array and aggregate:

select col, count(*)
from t lateral view
     explode(t.col_list) col
group by col
order by count(*) desc;


问:
adding encoding information to the result of FOR XML
I have a Script, which returns a XML using FOR XML in SQL 2008. Is there any way to add the version and encoding information in the beginning of the output. Eventually, i am planning to save the output in a file.

For example, right now my output looks like this

```<code><Agents>
  <Agent id="1">
    <Name>Mike</Name>
    <Location>Sanfrancisco</Location>
  </Agent>
  <Agent id="2">
    <Name>John</Name>
    <Location>NY</Location>
  </Agent>
</Agents>
</code>```

I would like to append the line <?xml version="1.0" encoding="UTF-8"?> in the beginning of the Xml output

So i want the output something like

```<code><?xml version="1.0" encoding="UTF-8"?>
<Agents>
 <Agent id="1">
   <Name>Mike</Name>
   <Location>Sanfrancisco</Location>
 </Agent>
<Agent id="2">
  <Name>John</Name>
  <Location>NY</Location>
</Agent>
</code>```

答:
SQL Server internally always uses utf-16 ucs-2 so you could just append it like we did. That is, SQL Server would never generate anything with "utf-8".

Edit: after some digging:

http://www.devnewsgroups.net/group/microsoft.public.sqlserver.xml/topic60022.aspx

http://forums.asp.net/t/1455808.aspx

ContentLicense: CC BY-SA 3.0

Body:
I have a Script, which returns a XML using FOR XML in SQL 2008. Is there any way to add the version and encoding information in the beginning of the output. Eventually, i am planning to save the output in a file.

For example, right now my output looks like this

<Agents>
  <Agent id="1">
    <Name>Mike</Name>
    <Location>Sanfrancisco</Location>
  </Agent>
  <Agent id="2">
    <Name>John</Name>
    <Location>NY</Location>
  </Agent>
</Agents>

I would like to append the line <?xml version="1.0" encoding="UTF-8"?> in the beginning of the Xml output

So i want the output something like

<?xml version="1.0" encoding="UTF-8"?>
<Agents>
 <Agent id="1">
   <Name>Mike</Name>
   <Location>Sanfrancisco</Location>
 </Agent>
<Agent id="2">
  <Name>John</Name>
  <Location>NY</Location>
</Agent>


问:
selenium isn't loading the page
```<code>from selenium import webdriver
driver= webdriver.Chrome()
driver.get('https://www.realestate.com.au/sold/') #opens normally but anything I search for doesn't load
driver.get('https://www.realestate.com.au/sold/in-alice+springs+-+greater+region%2c+nt%3b/list-1')
</code>```

The website opens and I don't get any captcha or block but the page doesn't load

答:
A bit of more information about your usecase would have helped us to debug the issue in a better way. However using Selenium I was able to access the website and retrieve the Page Source as follows:

Code Block:

```<code>from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.realestate.com.au/sold/")
print(driver.page_source)
</code>```

Console Output:

```<code><html class="js rui-burger rui-fancy-selects-on is-desktop app-loaded" lang="en"><head>
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=1140">
    <meta name="description" content="Discover how much the latest properties have been sold for. Browse sold real estate listings to find auction results and sold prices from all over Australia.">
    .
    .
    .
<script type="text/javascript" async="" charset="utf-8" id="utag_rea-group.sp-only_27" src="//tags.tiqcdn.com/utag/rea-group/sp-only/prod/utag.27.js?utv=ut4.44.201710110106"></script><script type="text/javascript" async="" charset="utf-8" id="utag_rea-group.sp-only_64" src="//tags.tiqcdn.com/utag/rea-group/sp-only/prod/utag.64.js?utv=ut4.44.202005070432"></script><script type="text/javascript" src="https://odb.outbrain.com/utils/get?url=http%3A%2F%2Fwww.realestate.com.au%2Fsold&settings=true&recs=true&widgetJSId=HPR&key=NANOWDGT01&idx=0&version=20009&apv=false&sig=kLvLc8wa&format=html&va=true&et=true&rand=98241&pdobuid=-1&osLang=en-US&winW=1366&winH=657&scrW=1366&scrH=768&adblck=false&secured=true&cmpStat=0&ccpaStat=0&ref=&px=119&py=1959&vpd=1302" charset="UTF-8" async=""></script><script src="https://safeinator.reamedia.com.au/2073b42b71554175cf729737a838c1f1c6d7f862/lib/base.min.js" async="" type="text/javascript"></script></head>
  <!--[if IE 8]>         <body class="sold rui-preload ie ie8 lt-ie9 lt-ie10" data-rui-select-auto-init="false"> <![endif]-->
  <!--[if IE 9]>         <body class="sold rui-preload ie ie9 lt-ie10" data-rui-select-auto-init="false"> <![endif]-->
  <!--[if gt IE 9]><!-->

  <body class="sold" data-rui-select-auto-init="false"><iframe src="https://secure-au.imrworldwide.com/storageframe.html" id="LOCSTORAGE" scrolling="no" name="empty" hidden="true" style="width: 1px; height: 1px; position: absolute; top: -7px; left: -7px; border: 0px;"></iframe>
    <!--<![endif]-->
    <div class="hero">
      <ul class="rui-visuallyhidden rui-accessibility">
    <li>
      <a href="#rui-main-nav" title="Go directly to the website navigation">skip to Main Navigation</a>
    </li>
    <li>
      <a href="#rui-main-content" title="Go directly to main content">skip to Content</a>
    </li>
      </ul>
      <header class="rui-header rui-header-inverse rui-header-not-fixed rui-clearfix" data-auto-init="false">
    <div class="rui-grid rui-header-container">
      <div class="rui-clearboth"></div>
      <button class="rui-burger-toggle rui-icon rui-icon-navdeck rui-button-no-style rui-desktop">
        <span class="rui-visuallyhidden">Menu</span>
        <span class="hit-box"></span>
      </button>
      <nav class="rui-myrea-nav">
        <div id="webCollectionsSlot"></div>
        <div id="webInboxSlot"></div>
        <div id="webInboxOverlay"></div>
        <ul class="rui-user-menu logged-out" style="">
          <li>
        <a href="/my-real-estate/login" title="Sign in">Sign in</a>
          </li>
          <li>
        <a href="/my-real-estate/register" class="rui-button-brand join" title="Create an account">Join</a>
          </li>
        </ul>
        <ul class="rui-user-menu logged-in rui-toggle-wrapper" style="display:none;">
          <li>
        <a href="#" class="rui-person-guy rui-toggle-link rui-icon rui-icon-user-off"></a>
        <div class="rui-account-menu-container">
          <ul class="rui-account-menu rui-toggle-container">
            <li class="first">
              <a href="/saved-properties" title="View saved properties">
            <span class="rui-icon rui-icon-save"></span><span>Saved properties</span>
              </a>
            </li>
            <li>
              <a href="/property/my-property" title="Track your property">
            <span class="rui-icon rui-icon-home"></span><span>Track your property</span>
              </a>
            </li>
            <li>
              <a href="https://homeloans.realestate.com.au/my-finances" title="My finances">
            <span class="rui-icon rui-icon-commission"></span><span>My finances</span>
              </a>
            </li>
            <li><a href="/my-real-estate/saved-searches-and-email-alerts" title="View property alerts">Saved searches & alerts</a></li>
            <li><a href="/my-real-estate/profile" title="View profile">My profile</a></li>
            <li><a href="/my-real-estate/account" title="Manage account settings">Account settings</a>
            </li>
            <li class="last"><a href="/logout.ds" title="Log out">Log out</a></li>
          </ul>
        </div>
          </li>
        </ul>
      </nav>
    </div>
    <div class="rui-grid rui-nav-container rui-burger-container">
      <a title="realestate.com.au homepage" href="/buy" class="logo">
        <img src="//s1.rui.au.reastatic.net/rui-static/img/rea-logo-thin-white-v3.png" alt="realestate.com.au Australia lives here">
      </a>
      <nav class="rui-main-nav">
        <ul>
          <li class="rui-nav-tab buy">
        <a href="/buy" title="Real estate and property for sale">
          <span>Buy</span>
        </a>
          </li>
          .
          .
          .
          <li class="rui-nav-tab commercial">
        <a href="http://www.realcommercial.com.au" target="_blank" title="Commercial real estate for sale and lease">
          <span>Commercial</span>
        </a>
          </li>
        </ul>
      </nav>
    </div>
      </header>

      <div class="hero-content">
    <div class="search-form-container">
      <form action="listsearchview.ds" class="search-form" name="search-form">
        <h1 id="search-form-title">Search sold properties</h1>
        <div class="search-container">
          <div class="search-inner-container" style="z-index: 1;">
        <nav class="search-channel-container">
          <a href="/buy" class="rui-search-tab">Buy</a>
          <a href="/rent/" class="rui-search-tab">Rent</a>
          <a href="/sold/" class="rui-search-tab rui-search-tab-selected">Sold</a>
          <a href="/property/" class="rui-search-tab property-value-tab">Property value</a>
          <a href="/find-agent" class="rui-search-tab find-agents-tab">Find agents</a>
        </nav>

        <div class="search-inner-container" style="z-index: 1;">

          <div class="rui-search-container search-input-container">
            <i class="rui-icon rui-icon-search search-icon"></i>

            <input name="where" id="where" tabindex="2" class="rui-input rui-location-box rui-auto-complete-input" data-auto-init="false" data-location-source="consumer-suggest" data-max-results="7" data-client-source="homepage" autocomplete="off" placeholder="Search by state, suburb or postcode" data-multi-select="true" data-suggest-types="suburb,precinct,region,state,postcode" data-auto-submit="false" autofocus=""><div class="clear-text-container"><a class="rui-icon rui-icon-cross" title="Clear text"> </a></div>
            <input name="theme" id="theme" type="hidden" value="rea.sold">
            <button class="rui-search-button" tabindex="10">
              <span class="rui-visually">Search</span>
            </button>
            <div class="focus-border" style="display: none;"></div>
          </div>
        </div>

          </div>
          <section class="search-refinements" id="search-refinements">

        <div class="condition property-select-holder">
          <div class="select-holder">
            <label>All property types</label>
            <select class="rui-input rui-select resize-select rui-select-rendered" id="rui-property-type-select-id" name="propertyType" multiple="multiple" style="display: none;">
              <option value="All" selected="selected">All property types</option>
              <option value="House">House</option>
              <option value="unit apartment">Apartment & Unit</option>
              <option value="Townhouse">Townhouse</option>
              <option value="Villa">Villa</option>
              <option value="Land">Land</option>
              <option value="Acreage">Acreage</option>
              <option value="Rural">Rural</option>
              <option value="unitblock">Block of Units</option>
              <option value="retire">Retirement Living</option>
            </select>
        </div>
        .
        .
        .
</body></html>
</code>```

Update

However, while attempting to invoke the url https://www.realestate.com.au/sold/in-alice+springs+-+greater+region%2c+nt%3b/list-1' it seems Selenium driven Browser Agent is getting detected through the fingerprints

Code Block:

```<code>driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.realestate.com.au/sold/in-alice+springs+-+greater+region%2c+nt%3b/list-1'")
</code>```

Console Output:

```<code><html lang="en"><head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="about:blank">
</head>
<body>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/j.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/f.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint/script/kpf.js?url=/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint&token=34091693-e55f-5166-d979-67e9426e1030"></script>

</body></html>
</code>```

You can find a relevant detailed discussions in Chrome browser initiated through ChromeDriver gets detected

Title: selenium isn't loading the page

Body:
from selenium import webdriver
driver= webdriver.Chrome()
driver.get('https://www.realestate.com.au/sold/') #opens normally but anything I search for doesn't load
driver.get('https://www.realestate.com.au/sold/in-alice+springs+-+greater+region%2c+nt%3b/list-1')

The website opens and I don't get any captcha or block but the page doesn't load

Body:
A bit of more information about your usecase would have helped us to debug the issue in a better way. However using Selenium I was able to access the website and retrieve the Page Source as follows:

Code Block:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.realestate.com.au/sold/")
print(driver.page_source)

Console Output:

<html class="js rui-burger rui-fancy-selects-on is-desktop app-loaded" lang="en"><head>
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=1140">
    <meta name="description" content="Discover how much the latest properties have been sold for. Browse sold real estate listings to find auction results and sold prices from all over Australia.">
    .
    .
    .
<script type="text/javascript" async="" charset="utf-8" id="utag_rea-group.sp-only_27" src="//tags.tiqcdn.com/utag/rea-group/sp-only/prod/utag.27.js?utv=ut4.44.201710110106"></script><script type="text/javascript" async="" charset="utf-8" id="utag_rea-group.sp-only_64" src="//tags.tiqcdn.com/utag/rea-group/sp-only/prod/utag.64.js?utv=ut4.44.202005070432"></script><script type="text/javascript" src="https://odb.outbrain.com/utils/get?url=http%3A%2F%2Fwww.realestate.com.au%2Fsold&amp;settings=true&amp;recs=true&amp;widgetJSId=HPR&amp;key=NANOWDGT01&amp;idx=0&amp;version=20009&amp;apv=false&amp;sig=kLvLc8wa&amp;format=html&amp;va=true&amp;et=true&amp;rand=98241&amp;pdobuid=-1&amp;osLang=en-US&amp;winW=1366&amp;winH=657&amp;scrW=1366&amp;scrH=768&amp;adblck=false&amp;secured=true&amp;cmpStat=0&amp;ccpaStat=0&amp;ref=&amp;px=119&amp;py=1959&amp;vpd=1302" charset="UTF-8" async=""></script><script src="https://safeinator.reamedia.com.au/2073b42b71554175cf729737a838c1f1c6d7f862/lib/base.min.js" async="" type="text/javascript"></script></head>
  <!--[if IE 8]>         <body class="sold rui-preload ie ie8 lt-ie9 lt-ie10" data-rui-select-auto-init="false"> <![endif]-->
  <!--[if IE 9]>         <body class="sold rui-preload ie ie9 lt-ie10" data-rui-select-auto-init="false"> <![endif]-->
  <!--[if gt IE 9]><!-->

  <body class="sold" data-rui-select-auto-init="false"><iframe src="https://secure-au.imrworldwide.com/storageframe.html" id="LOCSTORAGE" scrolling="no" name="empty" hidden="true" style="width: 1px; height: 1px; position: absolute; top: -7px; left: -7px; border: 0px;"></iframe>
    <!--<![endif]-->
    <div class="hero">
      <ul class="rui-visuallyhidden rui-accessibility">
    <li>
      <a href="#rui-main-nav" title="Go directly to the website navigation">skip to Main Navigation</a>
    </li>
    <li>
      <a href="#rui-main-content" title="Go directly to main content">skip to Content</a>
    </li>
      </ul>
      <header class="rui-header rui-header-inverse rui-header-not-fixed rui-clearfix" data-auto-init="false">
    <div class="rui-grid rui-header-container">
      <div class="rui-clearboth"></div>
      <button class="rui-burger-toggle rui-icon rui-icon-navdeck rui-button-no-style rui-desktop">
        <span class="rui-visuallyhidden">Menu</span>
        <span class="hit-box"></span>
      </button>
      <nav class="rui-myrea-nav">
        <div id="webCollectionsSlot"></div>
        <div id="webInboxSlot"></div>
        <div id="webInboxOverlay"></div>
        <ul class="rui-user-menu logged-out" style="">
          <li>
        <a href="/my-real-estate/login" title="Sign in">Sign in</a>
          </li>
          <li>
        <a href="/my-real-estate/register" class="rui-button-brand join" title="Create an account">Join</a>
          </li>
        </ul>
        <ul class="rui-user-menu logged-in rui-toggle-wrapper" style="display:none;">
          <li>
        <a href="#" class="rui-person-guy rui-toggle-link rui-icon rui-icon-user-off"></a>
        <div class="rui-account-menu-container">
          <ul class="rui-account-menu rui-toggle-container">
            <li class="first">
              <a href="/saved-properties" title="View saved properties">
            <span class="rui-icon rui-icon-save"></span><span>Saved properties</span>
              </a>
            </li>
            <li>
              <a href="/property/my-property" title="Track your property">
            <span class="rui-icon rui-icon-home"></span><span>Track your property</span>
              </a>
            </li>
            <li>
              <a href="https://homeloans.realestate.com.au/my-finances" title="My finances">
            <span class="rui-icon rui-icon-commission"></span><span>My finances</span>
              </a>
            </li>
            <li><a href="/my-real-estate/saved-searches-and-email-alerts" title="View property alerts">Saved searches &amp; alerts</a></li>
            <li><a href="/my-real-estate/profile" title="View profile">My profile</a></li>
            <li><a href="/my-real-estate/account" title="Manage account settings">Account settings</a>
            </li>
            <li class="last"><a href="/logout.ds" title="Log out">Log out</a></li>
          </ul>
        </div>
          </li>
        </ul>
      </nav>
    </div>
    <div class="rui-grid rui-nav-container rui-burger-container">
      <a title="realestate.com.au homepage" href="/buy" class="logo">
        <img src="//s1.rui.au.reastatic.net/rui-static/img/rea-logo-thin-white-v3.png" alt="realestate.com.au Australia lives here">
      </a>
      <nav class="rui-main-nav">
        <ul>
          <li class="rui-nav-tab buy">
        <a href="/buy" title="Real estate and property for sale">
          <span>Buy</span>
        </a>
          </li>
          .
          .
          .
          <li class="rui-nav-tab commercial">
        <a href="http://www.realcommercial.com.au" target="_blank" title="Commercial real estate for sale and lease">
          <span>Commercial</span>
        </a>
          </li>
        </ul>
      </nav>
    </div>
      </header>

      <div class="hero-content">
    <div class="search-form-container">
      <form action="listsearchview.ds" class="search-form" name="search-form">
        <h1 id="search-form-title">Search sold properties</h1>
        <div class="search-container">
          <div class="search-inner-container" style="z-index: 1;">
        <nav class="search-channel-container">
          <a href="/buy" class="rui-search-tab">Buy</a>
          <a href="/rent/" class="rui-search-tab">Rent</a>
          <a href="/sold/" class="rui-search-tab rui-search-tab-selected">Sold</a>
          <a href="/property/" class="rui-search-tab property-value-tab">Property value</a>
          <a href="/find-agent" class="rui-search-tab find-agents-tab">Find agents</a>
        </nav>

        <div class="search-inner-container" style="z-index: 1;">

          <div class="rui-search-container search-input-container">
            <i class="rui-icon rui-icon-search search-icon"></i>

            <input name="where" id="where" tabindex="2" class="rui-input rui-location-box rui-auto-complete-input" data-auto-init="false" data-location-source="consumer-suggest" data-max-results="7" data-client-source="homepage" autocomplete="off" placeholder="Search by state, suburb or postcode" data-multi-select="true" data-suggest-types="suburb,precinct,region,state,postcode" data-auto-submit="false" autofocus=""><div class="clear-text-container"><a class="rui-icon rui-icon-cross" title="Clear text"> </a></div>
            <input name="theme" id="theme" type="hidden" value="rea.sold">
            <button class="rui-search-button" tabindex="10">
              <span class="rui-visually">Search</span>
            </button>
            <div class="focus-border" style="display: none;"></div>
          </div>
        </div>

          </div>
          <section class="search-refinements" id="search-refinements">

        <div class="condition property-select-holder">
          <div class="select-holder">
            <label>All property types</label>
            <select class="rui-input rui-select resize-select rui-select-rendered" id="rui-property-type-select-id" name="propertyType" multiple="multiple" style="display: none;">
              <option value="All" selected="selected">All property types</option>
              <option value="House">House</option>
              <option value="unit apartment">Apartment &amp; Unit</option>
              <option value="Townhouse">Townhouse</option>
              <option value="Villa">Villa</option>
              <option value="Land">Land</option>
              <option value="Acreage">Acreage</option>
              <option value="Rural">Rural</option>
              <option value="unitblock">Block of Units</option>
              <option value="retire">Retirement Living</option>
            </select>
        </div>
        .
        .
        .
</body></html>

Update

However, while attempting to invoke the url https://www.realestate.com.au/sold/in-alice+springs+-+greater+region%2c+nt%3b/list-1' it seems Selenium driven Browser Agent is getting detected through the fingerprints

Code Block:

driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.realestate.com.au/sold/in-alice+springs+-+greater+region%2c+nt%3b/list-1'")

Console Output:

<html lang="en"><head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="about:blank">
</head>
<body>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/j.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/f.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint/script/kpf.js?url=/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint&amp;token=34091693-e55f-5166-d979-67e9426e1030"></script>

</body></html>

You can find a relevant detailed discussions in Chrome browser initiated through ChromeDriver gets detected


问:
An error is reported when the SysIntegrity API of HMS Core Safety Detect is integrated
The following error information is displayed when I integrate the SysIntegrity API of HMS Core Safety Detect:

```<code>Failed to read meta data for the AppID. D/SafetyDetectRepositoryImpl: unknown status code: 907135000
</code>```

My code is as follows:

```<code>SafetyDetect.getClient(getActivity())
            .sysIntegrity(nonce, APP_ID)
            .addOnSuccessListener(new OnSuccessListener<SysIntegrityResp>() {
          ...
})
.addOnFailureListener(new OnFailureListener() {
          ...
});
</code>```

答:
1.Error code 907135000:Verify that related input parameters are correctly set, for example, appid in the manifest file and whether to use the certificate signature.

2.Checking Steps：
a. check agc plugin cofig: Must be added in application module as below
   apply plugin: 'com.android.application'
   apply plugin: 'com.huawei.agconnect'
b. check json file dowloaded from agc and add in your proj as below
   json file

Body:
The following error information is displayed when I integrate the SysIntegrity API of HMS Core Safety Detect:

Failed to read meta data for the AppID. D/SafetyDetectRepositoryImpl: unknown status code: 907135000

My code is as follows:

SafetyDetect.getClient(getActivity())
            .sysIntegrity(nonce, APP_ID)
            .addOnSuccessListener(new OnSuccessListener<SysIntegrityResp>() {
          ...
})
.addOnFailureListener(new OnFailureListener() {
          ...
});


问:
How to make AuditorAware work with Spring Data Mongo Reactive
Spring Security 5 provides a ReactiveSecurityContextHolder to fetch  the SecurityContext from a Reactive context, but when I want to implement AuditorAware and get audition work automatically, but it does not work. Currently I can not find a Reactive variant for AuditorAware.

```<code>@Bean
public AuditorAware<Username> auditor() {
    return () -> ReactiveSecurityContextHolder.getContext()
        .map(SecurityContext::getAuthentication)
        .log()
        .filter(a -> a != null && a.isAuthenticated())
        .map(Authentication::getPrincipal)
        .cast(UserDetails.class)
        .map(auth -> new Username(auth.getName()))
        .switchIfEmpty(Mono.empty())
        .blockOptional();
}
</code>```

I have added @EnableMongoAuduting on my boot Application class.

On the Mongo document class. I added audition related annotations.

```<code>@CreatedDate
private LocalDateTime createdDate;

@CreatedBy
private Username author;
</code>```

When I added a post, the createdDate is filled, but author is null.

```<code>{"id":"5a49ccdb9222971f40a4ada1","title":"my first post","content":"content of my first post","createdDate":"2018-01-01T13:53:31.234","author":null}
</code>```

The complete codes is here, based on Spring Boot 2.0.0.M7.

Update: Spring Boot 2.4.0-M2/Spring Data Common 2.4.0-M2/Spring Data Mongo 3.1.0-M2 includes a ReactiveAuditorAware, Check this new sample, Note: use @EnableReactiveMongoAuditing to activiate it.

答:
Deprecated: see the update solution in the original post

Before the official reactive AuditAware is provided, there is an alternative to implement these via Spring Data Mongo specific ReactiveBeforeConvertCallback.

Do not use @EnableMongoAuditing

Implement your own  ReactiveBeforeConvertCallback, here I use a PersistentEntity interface for those entities that need to be audited.

public class PersistentEntityCallback implements ReactiveBeforeConvertCallback<PersistentEntity> {

    @Override
    public Publisher<PersistentEntity> onBeforeConvert(PersistentEntity entity, String collection) {
        var user = ReactiveSecurityContextHolder.getContext()
                .map(SecurityContext::getAuthentication)
                .filter(it -> it != null && it.isAuthenticated())
                .map(Authentication::getPrincipal)
                .cast(UserDetails.class)
                .map(userDetails -> new Username(userDetails.getUsername()))
                .switchIfEmpty(Mono.empty());

        var currentTime = LocalDateTime.now();

        if (entity.getId() == null) {
            entity.setCreatedDate(currentTime);
        }
        entity.setLastModifiedDate(currentTime);

        return user
                .map(u -> {
                            if (entity.getId() == null) {
                                entity.setCreatedBy(u);
                            }
                            entity.setLastModifiedBy(u);

                            return entity;
                        }
                )
                .defaultIfEmpty(entity);
    }
}
```

Check the complete codes here.

Body:
Spring Security 5 provides a ReactiveSecurityContextHolder to fetch  the SecurityContext from a Reactive context, but when I want to implement AuditorAware and get audition work automatically, but it does not work. Currently I can not find a Reactive variant for AuditorAware.

@Bean
public AuditorAware<Username> auditor() {
    return () -> ReactiveSecurityContextHolder.getContext()
        .map(SecurityContext::getAuthentication)
        .log()
        .filter(a -> a != null && a.isAuthenticated())
        .map(Authentication::getPrincipal)
        .cast(UserDetails.class)
        .map(auth -> new Username(auth.getName()))
        .switchIfEmpty(Mono.empty())
        .blockOptional();
}

I have added @EnableMongoAuduting on my boot Application class.

On the Mongo document class. I added audition related annotations.

@CreatedDate
private LocalDateTime createdDate;

@CreatedBy
private Username author;

When I added a post, the createdDate is filled, but author is null.

{"id":"5a49ccdb9222971f40a4ada1","title":"my first post","content":"content of my first post","createdDate":"2018-01-01T13:53:31.234","author":null}

The complete codes is here, based on Spring Boot 2.0.0.M7.

Update: Spring Boot 2.4.0-M2/Spring Data Common 2.4.0-M2/Spring Data Mongo 3.1.0-M2 includes a ReactiveAuditorAware, Check this new sample, Note: use @EnableReactiveMongoAuditing to activiate it.

Body:
Deprecated: see the update solution in the original post

Before the official reactive AuditAware is provided, there is an alternative to implement these via Spring Data Mongo specific ReactiveBeforeConvertCallback.

Do not use @EnableMongoAuditing

Implement your own  ReactiveBeforeConvertCallback, here I use a PersistentEntity interface for those entities that need to be audited.

public class PersistentEntityCallback implements ReactiveBeforeConvertCallback<PersistentEntity> {

    @Override
    public Publisher<PersistentEntity> onBeforeConvert(PersistentEntity entity, String collection) {
        var user = ReactiveSecurityContextHolder.getContext()
                .map(SecurityContext::getAuthentication)
                .filter(it -> it != null && it.isAuthenticated())
                .map(Authentication::getPrincipal)
                .cast(UserDetails.class)
                .map(userDetails -> new Username(userDetails.getUsername()))
                .switchIfEmpty(Mono.empty());

        var currentTime = LocalDateTime.now();

        if (entity.getId() == null) {
            entity.setCreatedDate(currentTime);
        }
        entity.setLastModifiedDate(currentTime);

        return user
                .map(u -> {
                            if (entity.getId() == null) {
                                entity.setCreatedBy(u);
                            }
                            entity.setLastModifiedBy(u);

                            return entity;
                        }
                )
                .defaultIfEmpty(entity);
    }
}

Check the complete codes here.


问:
How can I store a command in a variable in a shell script?
I would like to store a command to use at a later time in a variable (not the output of the command, but the command itself).

I have a simple script as follows:

```<code>command="ls";
echo "Command: $command"; #Output is: Command: ls

b=`$command`;
echo $b; #Output is: public_html REV test... (command worked successfully)
</code>```

However, when I try something a bit more complicated, it fails. For example, if I make

```<code>command="ls | grep -c '^'";
</code>```

The output is:

```<code>Command: ls | grep -c '^'
ls: cannot access |: No such file or directory
ls: cannot access grep: No such file or directory
ls: cannot access '^': No such file or directory
</code>```

How could I store such a command (with pipes/multiple commands) in a variable for later use?

答:
```<code>#!/bin/bash
#Note: this script works only when u use Bash. So, don't remove the first line.

TUNECOUNT=$(ifconfig |grep -c -o tune0) #Some command with "Grep".
echo $TUNECOUNT                         #This will return 0
                                    #if you don't have tune0 interface.
                                    #Or count of installed tune0 interfaces.
</code>```

Body:
I would like to store a command to use at a later time in a variable (not the output of the command, but the command itself).

I have a simple script as follows:

command="ls";
echo "Command: $command"; #Output is: Command: ls

b=`$command`;
echo $b; #Output is: public_html REV test... (command worked successfully)

However, when I try something a bit more complicated, it fails. For example, if I make

command="ls | grep -c '^'";

The output is:

Command: ls | grep -c '^'
ls: cannot access |: No such file or directory
ls: cannot access grep: No such file or directory
ls: cannot access '^': No such file or directory

How could I store such a command (with pipes/multiple commands) in a variable for later use?


问:
Play mp3 on iPad Safari
Is it possible to play embedded MP3 on iPad Safari (the way you do on normal desktop browsers) ?

If yes, do we need to code separately for iPad Safari ?

The reason I am asking is bcoz in my app, the desktop code for mp3 is not working on iPad..
The code for desktop is

```<code><EMBED src="'+audioUrl+'" autostart=true loop=false volume=100 hidden=true>
</code>```

答:
You can use the HTML 5 <audio> tag. Check out w3schools - HTML5 Audio.

There is also a table on there telling you what formats work with what browsers.

Title: Play mp3 on iPad Safari

Body:
Is it possible to play embedded MP3 on iPad Safari (the way you do on normal desktop browsers) ?

If yes, do we need to code separately for iPad Safari ?

The reason I am asking is bcoz in my app, the desktop code for mp3 is not working on iPad..
The code for desktop is

<EMBED src="'+audioUrl+'" autostart=true loop=false volume=100 hidden=true>


问:
append script to class / DIV
I am trying to append the following script in tampermonkey which should insert a script (adtag banner) into a div / class of a specific website but its not working.

```<code>// ==UserScript==
// @name         Insert TAG Into Class- zeit.com
// @require  https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @match       http*://www.website.xxx/*
// ==/UserScript==

(function () {
    var scriptElement = document.createElement( "script" );
    scriptElement.type = "text/javascript";
    scriptElement.src = "HTML SOURCE";
    $(".header").append(scriptElement);
})();
</code>```

Do you have any ideas?

答:
can you try this </p>

```<code>$(".header").append(`<script type="text/javascript" src="../path"></script>`)
</code>```

Title: append script to class / DIV

Body:
I am trying to append the following script in tampermonkey which should insert a script (adtag banner) into a div / class of a specific website but its not working.

// ==UserScript==
// @name         Insert TAG Into Class- zeit.com
// @require  https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @match       http*://www.website.xxx/*
// ==/UserScript==

(function () {
    var scriptElement = document.createElement( "script" );
    scriptElement.type = "text/javascript";
    scriptElement.src = "HTML SOURCE";
    $(".header").append(scriptElement);
})();

Do you have any ideas?

Body:
can you try this

$(".header").append(`<script type="text/javascript" src="../path"></script>`)


问:
How to create a plan in a function
I'd like to use a function to create a drake plan.  See MWE:

```<code>plan_func <- function(param) {
  drake::drake_plan(
    myparam = param
  )
}
</code>```

I would like

```<code>plan_func("a")
</code>```

to give

```<code># A tibble: 1 x 2
  target  command
  <chr>   <expr_lst>
1 myparam "a"
</code>```

but instead, it gives

```<code>> plan_func("a")
# A tibble: 1 x 2
  target  command
  <chr>   <expr_lst>
1 myparam param
</code>```

It feels like this is an NSE problem. Can someone give a friendly hint how to get this right?

My appreciation in advance!

答:
drake_plan() supports tidy evaluation, so you can write !!param in the plan.

library(drake)
plan_func <- function(param) {
  drake::drake_plan(
    myparam = !!param
  )
}
plan_func("a")
#> # A tibble: 1 x 2
#>   target  command
#>   <chr>   <expr_lst>
#> 1 myparam "a"
```

<p><sup>Created on 2020-06-02 by the reprex package (v0.3.0)</sup></p>

<p>Trickier situations like https://github.com/ropensci/drake/issues/1251 might require you to turn off the <code>tidy_eval</code> and <code>transform</code> arguments of <code>drake_plan()</code>.</p>

<h1>Edit</h1>

<p>To splice multiple arguments into a function, use triple-bang (!!!) instead of bang-bang (!!):</p>

<pre class="lang-r prettyprint-override"><code>library(drake)

plan_func <- function(param) {
  drake_plan(
    myparam = f(!!param)
  )
}

  plan_func(c("a", "b"))
#> # A tibble: 1 x 2
#>   target  command
#>   <chr>   <expr>
#> 1 myparam f(c("a", "b"))

plan_func <- function(param) {
  drake_plan(
    myparam = f(!!!param)
  )
}

plan_func(c("a", "b"))
#> # A tibble: 1 x 2
#>   target  command
#>   <chr>   <expr>
#> 1 myparam f("a", "b")
</code>```

Created on 2020-06-02 by the reprex package (v0.3.0)

Title: How to create a plan in a function

Body:
I'd like to use a function to create a drake plan.  See MWE:

plan_func <- function(param) {
  drake::drake_plan(
    myparam = param
  )
}

I would like

plan_func("a")

to give

# A tibble: 1 x 2
  target  command
  <chr>   <expr_lst>
1 myparam "a"

but instead, it gives

> plan_func("a")
# A tibble: 1 x 2
  target  command
  <chr>   <expr_lst>
1 myparam param

It feels like this is an NSE problem. Can someone give a friendly hint how to get this right?

My appreciation in advance!

Body:
drake_plan() supports tidy evaluation, so you can write !!param in the plan.

library(drake)
plan_func <- function(param) {
  drake::drake_plan(
    myparam = !!param
  )
}
plan_func("a")
#> # A tibble: 1 x 2
#>   target  command
#>   <chr>   <expr_lst>
#> 1 myparam "a"

Created on 2020-06-02 by the reprex package (v0.3.0)

Trickier situations like https://github.com/ropensci/drake/issues/1251 might require you to turn off the tidy_eval and transform arguments of drake_plan().

Edit

To splice multiple arguments into a function, use triple-bang (!!!) instead of bang-bang (!!):

library(drake)

plan_func <- function(param) {
  drake_plan(
    myparam = f(!!param)
  )
}

  plan_func(c("a", "b"))
#> # A tibble: 1 x 2
#>   target  command
#>   <chr>   <expr>
#> 1 myparam f(c("a", "b"))

plan_func <- function(param) {
  drake_plan(
    myparam = f(!!!param)
  )
}

plan_func(c("a", "b"))
#> # A tibble: 1 x 2
#>   target  command
#>   <chr>   <expr>
#> 1 myparam f("a", "b")

Created on 2020-06-02 by the reprex package (v0.3.0)


问:
How to get country specific result (only for UK) in HERE MAP iOS SDK?

HEREDeveloperSupport

Is there any method for AutoSuggestionRequest to get country specific result?

I am using the Native IOS SDK premium edition version 3.15,i need to show UK results only.

I am following the below code

```<code> let autoSuggestionRequest = NMAPlaces.sharedInstance()!.createAutoSuggestionRequest(location:geo,
            partialTerm:text, resultType:getResultType())

        autoSuggestionRequest?.languagePreference = languageLabel.text
</code>```

答:
I can't find this option in the 3.x Premium SDK (though I might also be missing it). As a workaround you can directly call the Autosuggest endpoint of the Search & Geocoding API. Using the "in" parameter and country code you can limit your results to a specific country.

Alternatively you can filter the results based on their country afterwards, though I understand that is less than convenient.

Body:
HEREDeveloperSupport

Is there any method for AutoSuggestionRequest to get country specific result?

I am using the Native IOS SDK premium edition version 3.15,i need to show UK results only.

I am following the below code

 let autoSuggestionRequest = NMAPlaces.sharedInstance()!.createAutoSuggestionRequest(location:geo,
            partialTerm:text, resultType:getResultType())

        autoSuggestionRequest?.languagePreference = languageLabel.text


问:
How to generate large word count file in Spark?
I want to generate 10 million lines’ wordcount file for performance test(each line has the same sentence). But I have no idea about how to code it.

You can give me an example code, and save file in HDFS directly.

答:
You could follow this approach.

Tail recursive to generate the objects list and Dataframes, and Union to generate the big Dataframe

```<code>  val spark = SparkSession
    .builder()
    .appName("TenMillionsRows")
    .master("local[*]")
    .config("spark.sql.shuffle.partitions","4") //Change to a more reasonable default number of partitions for our data
    .config("spark.app.id","TenMillionsRows") // To silence Metrics warning
    .getOrCreate()

  val sc = spark.sparkContext

    import spark.implicits._

    /**
      * Returns a List of nums sentences
      * @param sentence
      * @param num
      * @return
      */
    def getList(sentence: String, num: Int) : List[String] = {
      @tailrec
      def loop(st: String,n: Int, acc: List[String]): List[String] = {
        n match {
          case num if num == 0 => acc
          case _ => loop(st, n - 1, st :: acc)
        }
      }
      loop(sentence,num,List())
    }

    /**
      * Returns a Dataframe that is the union of nums dataframes
      * @param lst
      * @param num
      * @return
      */
    def getDataFrame(lst: List[String], num: Int): DataFrame = {
      @tailrec
      def loop (ls: List[String],n: Int, acc: DataFrame): DataFrame = {
        n match {
          case n if n == 0 => acc
          case _ => loop(lst,n - 1, acc.union(sc.parallelize(ls).toDF("sentence")))
        }
      }
      loop(lst, num, sc.parallelize(List(sentence)).toDF("sentence"))
    }

      val sentence = "hope for the best but prepare for the worst"
      val lSentence = getList(sentence, 100000)
      val dfs = getDataFrame(lSentence,100)

      println(dfs.count())
      // output: 10000001
      dfs.write.orc("path_to_hdfs") // write dataframe to a orc file
      // you can save the file as parquet, txt, json .......
      // with dataframe.write
</code>```

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

Hope this helps.

Body:
You could follow this approach.

Tail recursive to generate the objects list and Dataframes, and Union to generate the big Dataframe

  val spark = SparkSession
    .builder()
    .appName("TenMillionsRows")
    .master("local[*]")
    .config("spark.sql.shuffle.partitions","4") //Change to a more reasonable default number of partitions for our data
    .config("spark.app.id","TenMillionsRows") // To silence Metrics warning
    .getOrCreate()

  val sc = spark.sparkContext

    import spark.implicits._

    /**
      * Returns a List of nums sentences
      * @param sentence
      * @param num
      * @return
      */
    def getList(sentence: String, num: Int) : List[String] = {
      @tailrec
      def loop(st: String,n: Int, acc: List[String]): List[String] = {
        n match {
          case num if num == 0 => acc
          case _ => loop(st, n - 1, st :: acc)
        }
      }
      loop(sentence,num,List())
    }

    /**
      * Returns a Dataframe that is the union of nums dataframes
      * @param lst
      * @param num
      * @return
      */
    def getDataFrame(lst: List[String], num: Int): DataFrame = {
      @tailrec
      def loop (ls: List[String],n: Int, acc: DataFrame): DataFrame = {
        n match {
          case n if n == 0 => acc
          case _ => loop(lst,n - 1, acc.union(sc.parallelize(ls).toDF("sentence")))
        }
      }
      loop(lst, num, sc.parallelize(List(sentence)).toDF("sentence"))
    }

      val sentence = "hope for the best but prepare for the worst"
      val lSentence = getList(sentence, 100000)
      val dfs = getDataFrame(lSentence,100)

      println(dfs.count())
      // output: 10000001
      dfs.write.orc("path_to_hdfs") // write dataframe to a orc file
      // you can save the file as parquet, txt, json .......
      // with dataframe.write

Hope this helps.


问:
How do I calculate the coherence score of an sklearn LDA model?
Here, best_model_lda is an sklearn based LDA model and we are trying to find a coherence score for this model..

```<code>coherence_model_lda = CoherenceModel(model = best_lda_model,texts=data_vectorized, dictionary=dictionary,coherence='c_v')
coherence_lda = coherence_model_lda.get_coherence()
print('\n Coherence Score :',coherence_lda)
</code>```

Output : This error pops up because i'm trying to find the coherence score of an  sklearn LDA topic model, is there a way around it. Also , what metric is the sklearn LDA using to group these words together ?

```<code>---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in _get_topics_from_model(model, topn)
   490                 matutils.argsort(topic, topn=topn, reverse=True) for topic in
--> 491                 model.get_topics()
   492             ]

AttributeError: 'LatentDirichletAllocation' object has no attribute 'get_topics'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-106-ce8558d82330> in <module>
----> 1 coherence_model_lda = CoherenceModel(model = best_lda_model,texts=data_vectorized, dictionary=dictionary,coherence='c_v')
     2 coherence_lda = coherence_model_lda.get_coherence()
     3 print('\n Coherence Score :',coherence_lda)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in __init__(self, model, topics, texts, corpus, dictionary, window_size, keyed_vectors, coherence, topn, processes)
   210         self._accumulator = None
   211         self._topics = None
--> 212         self.topics = topics
   213
   214         self.processes = processes if processes >= 1 else max(1, mp.cpu_count() - 1)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in topics(self, topics)
   433                     self.model)
   434         elif self.model is not None:
--> 435             new_topics = self._get_topics()
   436             logger.debug("Setting topics to those of the model: %s", self.model)
   437         else:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in _get_topics(self)
   467     def _get_topics(self):
   468         """Internal helper function to return topics from a trained topic model."""
--> 469         return self._get_topics_from_model(self.model, self.topn)
   470
   471     @staticmethod

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in _get_topics_from_model(model, topn)
   493         except AttributeError:
   494             raise ValueError(
--> 495                 "This topic model is not currently supported. Supported topic models"
   496                 " should implement the `get_topics` method.")
   497

ValueError: This topic model is not currently supported. Supported topic models should implement the `get_topics` method.```
```

答:
You could use tmtoolkit to compute each of four coherence scores provided by gensim CoherenceModel.
The authors of the documentation claim that the method tmtoolkit.topicmod.evaluate.metric_coherence_gensim "also supports models from lda and sklearn (by passing topic_word_distrib, dtm and vocab)!".

So, to get for example 'c_v' coherence metric:

```<code># lda_model - LatentDirichletAllocation()
# vect - CountVectorizer()
# texts - the list of tokenized words
metric_coherence_gensim(measure='c_v',
                        top_n=25,
                        topic_word_distrib=lda_model.components_,
                        dtm=dtm_tf,
                        vocab=np.array([x for x in vect.vocabulary_.keys()]),
                        texts=train['cleaned_NOUN'].values)
</code>```

With regard to the second part of the question - as far as I know perplexity (often not aligned with human perception) is the native method for sklearn's LDA implementation evaluation.

Body:
Here, best_model_lda is an sklearn based LDA model and we are trying to find a coherence score for this model..

coherence_model_lda = CoherenceModel(model = best_lda_model,texts=data_vectorized, dictionary=dictionary,coherence='c_v')
coherence_lda = coherence_model_lda.get_coherence()
print('\n Coherence Score :',coherence_lda)

Output : This error pops up because i'm trying to find the coherence score of an  sklearn LDA topic model, is there a way around it. Also , what metric is the sklearn LDA using to group these words together ?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in _get_topics_from_model(model, topn)
   490                 matutils.argsort(topic, topn=topn, reverse=True) for topic in
--> 491                 model.get_topics()
   492             ]

AttributeError: 'LatentDirichletAllocation' object has no attribute 'get_topics'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-106-ce8558d82330> in <module>
----> 1 coherence_model_lda = CoherenceModel(model = best_lda_model,texts=data_vectorized, dictionary=dictionary,coherence='c_v')
     2 coherence_lda = coherence_model_lda.get_coherence()
     3 print('\n Coherence Score :',coherence_lda)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in __init__(self, model, topics, texts, corpus, dictionary, window_size, keyed_vectors, coherence, topn, processes)
   210         self._accumulator = None
   211         self._topics = None
--> 212         self.topics = topics
   213
   214         self.processes = processes if processes >= 1 else max(1, mp.cpu_count() - 1)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in topics(self, topics)
   433                     self.model)
   434         elif self.model is not None:
--> 435             new_topics = self._get_topics()
   436             logger.debug("Setting topics to those of the model: %s", self.model)
   437         else:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in _get_topics(self)
   467     def _get_topics(self):
   468         """Internal helper function to return topics from a trained topic model."""
--> 469         return self._get_topics_from_model(self.model, self.topn)
   470
   471     @staticmethod

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py in _get_topics_from_model(model, topn)
   493         except AttributeError:
   494             raise ValueError(
--> 495                 "This topic model is not currently supported. Supported topic models"
   496                 " should implement the `get_topics` method.")
   497

ValueError: This topic model is not currently supported. Supported topic models should implement the `get_topics` method.```

Body:
You could use tmtoolkit to compute each of four coherence scores provided by gensim CoherenceModel.
The authors of the documentation claim that the method tmtoolkit.topicmod.evaluate.metric_coherence_gensim "also supports models from lda and sklearn (by passing topic_word_distrib, dtm and vocab)!".

So, to get for example 'c_v' coherence metric:

# lda_model - LatentDirichletAllocation()
# vect - CountVectorizer()
# texts - the list of tokenized words
metric_coherence_gensim(measure='c_v',
                        top_n=25,
                        topic_word_distrib=lda_model.components_,
                        dtm=dtm_tf,
                        vocab=np.array([x for x in vect.vocabulary_.keys()]),
                        texts=train['cleaned_NOUN'].values)

With regard to the second part of the question - as far as I know perplexity (often not aligned with human perception) is the native method for sklearn's LDA implementation evaluation.


问:
Why doesn't the Route tab appear in Glimpse Web Debuggger?
I've just installed Glimpse Web Debugger for ASP.NET (Beta) - version 0.82. I installed it via the Package Manager console in Visual Studio 2010 and the installation was successful.  I'm trying to test it out using the ASP.NET Development server and the ASP.NET MVC 3 version of the MVCMusicStore demo site using the Razor view engine.

For some reason, however, the Routes tab does not appear when I turn Glimpse on and try to test the web app. The Glimpse settings in my web.config file (below) don't show any blacklisted plugins:

```<code>On = True
Allowed IP's =
    127.0.0.1
    ::1
Allowed ContentType's =
    text/html
Blacklisted Plugins =
</code>```

These are list of plugins that the Glimpse/Config page says are running:

```<code>Glimpse.Core.Plugin.Request
Glimpse.Core.Plugin.Environment
Glimpse.Core.Plugin.Trace
Glimpse.Core.Plugin.Config
Glimpse.Core.Plugin.Server
Glimpse.Core.Plugin.Session
</code>```

The only tabs that appear are: Ajax / Config / Environment / Remote / Request / Server. The Trace tab appears, but is greyed out.  Glimpse seems like a useful tool and I'd like to be able to test/debug routes with it but I can't figure out why it's not working correctly.  I'd greatly appreciate any help with this.

Thanks!

答:
It looks like you have only installed Glimpse, not Glimpse.MVC3 which adds in the MVC functionality.

Go ahead and Install-Package Glimpse.MVC3 in the powershell console, or just use the GUI to install Glimpse.MVC3.

In the future Glimpse may ship additional plugin packs similar to MVC3. Image we could have Glimpse.SharePoint or Glimpse.Orchard...

Body:
I've just installed Glimpse Web Debugger for ASP.NET (Beta) - version 0.82. I installed it via the Package Manager console in Visual Studio 2010 and the installation was successful.  I'm trying to test it out using the ASP.NET Development server and the ASP.NET MVC 3 version of the MVCMusicStore demo site using the Razor view engine.

For some reason, however, the Routes tab does not appear when I turn Glimpse on and try to test the web app. The Glimpse settings in my web.config file (below) don't show any blacklisted plugins:

On = True
Allowed IP's =
    127.0.0.1
    ::1
Allowed ContentType's =
    text/html
Blacklisted Plugins =

These are list of plugins that the Glimpse/Config page says are running:

Glimpse.Core.Plugin.Request
Glimpse.Core.Plugin.Environment
Glimpse.Core.Plugin.Trace
Glimpse.Core.Plugin.Config
Glimpse.Core.Plugin.Server
Glimpse.Core.Plugin.Session

The only tabs that appear are: Ajax / Config / Environment / Remote / Request / Server. The Trace tab appears, but is greyed out.  Glimpse seems like a useful tool and I'd like to be able to test/debug routes with it but I can't figure out why it's not working correctly.  I'd greatly appreciate any help with this.

Thanks!


问:
Lag Function for Dates
I want to lag on date to get a value from 7 days ago. However, there is not a value for everyday in the dataset, but I want the value from 7 days ago rather then the value 7 before the current.

What do I need to do to make this work?

Currently doing LAG(field, 7) OVER (partition by x,y,z ORDER By date asc)

答:
You need to use range within window function definition instead of rows(default).
To make it possible, you can convert the column to Unix seconds by applying UNIX_SECONDS(TIMESTAMP(date)) conversion.

In the following code 604800 is equal to 7 days in seconds. You can change that value to use another range.

```<code>FIRST_VALUE(field) OVER (partition by x,y,z ORDER By UNIX_SECONDS(TIMESTAMP(date)) asc RANGE BETWEEN 604800 PRECEDING AND 604800 PRECEDING)
</code>```

Example query:

```<code>WITH rawdata AS
 (
  SELECT 'cat1' as name, DATE '2019-01-01' as date, 1 as val UNION ALL
  SELECT 'cat1', DATE '2019-01-08', 3 UNION ALL
  SELECT 'cat1', DATE '2019-01-15', 7 UNION ALL
  SELECT 'cat2', DATE '2019-10-18', 10
)
SELECT
  name,
  date,
  val,
  FIRST_VALUE(val)
    OVER (PARTITION BY name ORDER BY UNIX_SECONDS(TIMESTAMP(date)) ASC
    RANGE BETWEEN 604800 PRECEDING AND 604800 PRECEDING) AS last_week_val
FROM rawdata
</code>```

Title: Lag Function for Dates

Body:
You need to use range within window function definition instead of rows(default).
To make it possible, you can convert the column to Unix seconds by applying UNIX_SECONDS(TIMESTAMP(date)) conversion.

In the following code 604800 is equal to 7 days in seconds. You can change that value to use another range.

FIRST_VALUE(field) OVER (partition by x,y,z ORDER By UNIX_SECONDS(TIMESTAMP(date)) asc RANGE BETWEEN 604800 PRECEDING AND 604800 PRECEDING)

Example query:

WITH rawdata AS
 (
  SELECT 'cat1' as name, DATE '2019-01-01' as date, 1 as val UNION ALL
  SELECT 'cat1', DATE '2019-01-08', 3 UNION ALL
  SELECT 'cat1', DATE '2019-01-15', 7 UNION ALL
  SELECT 'cat2', DATE '2019-10-18', 10
)
SELECT
  name,
  date,
  val,
  FIRST_VALUE(val)
    OVER (PARTITION BY name ORDER BY UNIX_SECONDS(TIMESTAMP(date)) ASC
    RANGE BETWEEN 604800 PRECEDING AND 604800 PRECEDING) AS last_week_val
FROM rawdata


问:
How to force  to be sticky in on side on the HTML page?
I'm trying to make  with google maps reference stick on the right side of my page I've tried this code still scrolls with the rest of the page

#map{
position: -webkit-sticky;
  position: sticky;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><iframe class="map" id="map" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d317715.71193692513!2d-0.38178583985785625!3d51.528735196048615!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47d8a00baf21de75%3A0x52963a5addd52a99!2sLondon%2C%20UK!5e0!3m2!1sen!2sae!4v1589590348452!5m2!1sen!2sae" width="600" height="700" frameborder="0" style="border:0; width: 100%;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe></code>```

答:
This should stick your map to the top (I've added a div to be able to scroll down):

#map {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
}

div {
  background-color: yellow;
  height: 2000px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><iframe class="map" id="map" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d317715.71193692513!2d-0.38178583985785625!3d51.528735196048615!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47d8a00baf21de75%3A0x52963a5addd52a99!2sLondon%2C%20UK!5e0!3m2!1sen!2sae!4v1589590348452!5m2!1sen!2sae" width="600" height="700" frameborder="0" style="border:0; width: 100%;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>

<div>Extra Space</div></code>```

If you want to the right, right: amount should do the trick. left for left and bottom for bottom.

@Edit - I've found that setting right does not seem to be working. I've searched around and seems like there are several rules when it comes for something to be sticky. I haven't used sticky yet so I don't know if I'm just missing something. I apologize as my comment is most likely useless in your case.

You might want to check Interneting Is Hard if you want to learn more about positioning, though it does not have sticky, it should have enough for your needs without the use of sticky.

Title: How to force < iframe> to be sticky in on side on the HTML page?

Body:
This should stick your map to the top (I've added a div to be able to scroll down):

#map {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
}

div {
  background-color: yellow;
  height: 2000px;
}

<iframe class="map" id="map" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d317715.71193692513!2d-0.38178583985785625!3d51.528735196048615!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47d8a00baf21de75%3A0x52963a5addd52a99!2sLondon%2C%20UK!5e0!3m2!1sen!2sae!4v1589590348452!5m2!1sen!2sae" width="600" height="700" frameborder="0" style="border:0; width: 100%;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>

<div>Extra Space</div>

If you want to the right, right: amount should do the trick. left for left and bottom for bottom.

@Edit - I've found that setting right does not seem to be working. I've searched around and seems like there are several rules when it comes for something to be sticky. I haven't used sticky yet so I don't know if I'm just missing something. I apologize as my comment is most likely useless in your case.

You might want to check Interneting Is Hard if you want to learn more about positioning, though it does not have sticky, it should have enough for your needs without the use of sticky.


问:
MONGODB_URI is undefined
Trying to make a Facebook chat bot following this guide: https://medium.com/@viviancpy/part-1-facebook-chatbot-with-heroku-webhook-b14090a136c7

I have no experience with node and JavaScript at all, mainly just Python. So I simply copy pasted the code from GitHub, but when I try to run it (as described in Step 4, with "yarn start") I get this error:

MongooseError: The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.

So I had a look at the code and found this:

```<code>const MONGODB_URI = process.env.MONGODB_URI;
var db = mongoose.connect(MONGODB_URI);
</code>```

So in Python at least this would mean that the MONGODB_URI constant is undefined, but I can't figure out why.
It might be I am missing a package (I believe it's called) or that it's a problem with me running this code on windows, or something entirely different. Have also tried to google, but either I don't understand the answer or I can't find an answer.

答:
The correct way to do this is to create a file called '.env' in the root directory of your project, from where you run 'heroku local'.

Using this file, heroku-cli will create an environment with the appropriate environment variables.

Step 1: Find out your actual MONGODB_URI.

Step 2: Create the .env file

Step 3: Write the line MONGODB_URI='your-actual-mongodb_uri' into the .env file

Step 4: Start your process with 'heroku local'

Your process can now access process.env.MONGODB_URI, just as if it was deployed on heroku directly.

Title: MONGODB_URI is undefined

Body:
Trying to make a Facebook chat bot following this guide: https://medium.com/@viviancpy/part-1-facebook-chatbot-with-heroku-webhook-b14090a136c7

I have no experience with node and JavaScript at all, mainly just Python. So I simply copy pasted the code from GitHub, but when I try to run it (as described in Step 4, with "yarn start") I get this error:

MongooseError: The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.

So I had a look at the code and found this:

const MONGODB_URI = process.env.MONGODB_URI;
var db = mongoose.connect(MONGODB_URI);

So in Python at least this would mean that the MONGODB_URI constant is undefined, but I can't figure out why.
It might be I am missing a package (I believe it's called) or that it's a problem with me running this code on windows, or something entirely different. Have also tried to google, but either I don't understand the answer or I can't find an answer.


问:
How to make disabled inputs editable after clicking edit button
How can I make these inputs editable after being clicked Edit button using vuejs?</p>

```<code>form
  .form-group
    label(for='exampleInputEmail1') Email address
    input.form-control(type='text', placeholder='jan.kowalski@poczta.pl', readonly='')
  .form-group
    label(for='exampleInputEmail1') Name
    input.form-control(type='text', placeholder='Jan', readonly='')
  .form-group
    label(for='exampleInputEmail1') Surname
    input.form-control(type='text', placeholder='Kowalski', readonly='')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', readonly='')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', readonly='')
  .form-group
    a.btn.btn-primary.btn-blood.btn-main
      | Edit
</code>```

答:
Rather than use the readonly attribute, use :disabled and set it's value to some variable. That variable will need to be true intially, but have the button press change it to false.

As an example, your pug would look like

```<code>form
  .form-group
    label(for='exampleInputEmail1') Email address
    input.form-control(type='text', placeholder='jan.kowalski@poczta.pl', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputEmail1') Name
    input.form-control(type='text', placeholder='Jan', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputEmail1') Surname
    input.form-control(type='text', placeholder='Kowalski', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', :disabled='notYetClicked')
  .form-group
    a.btn.btn-primary.btn-blood.btn-main(v-on:click='notYetClicked = false')
      | Edit
</code>```

and add the new variable to your JS

export default {
  name: 'item-list',

  data() {
    return {
      notYetClicked: true,
    }
  },
}
```

Body:
How can I make these inputs editable after being clicked Edit button using vuejs?

form
  .form-group
    label(for='exampleInputEmail1') Email address
    input.form-control(type='text', placeholder='jan.kowalski@poczta.pl', readonly='')
  .form-group
    label(for='exampleInputEmail1') Name
    input.form-control(type='text', placeholder='Jan', readonly='')
  .form-group
    label(for='exampleInputEmail1') Surname
    input.form-control(type='text', placeholder='Kowalski', readonly='')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', readonly='')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', readonly='')
  .form-group
    a.btn.btn-primary.btn-blood.btn-main
      | Edit

Body:
Rather than use the readonly attribute, use :disabled and set it's value to some variable. That variable will need to be true intially, but have the button press change it to false.

As an example, your pug would look like

form
  .form-group
    label(for='exampleInputEmail1') Email address
    input.form-control(type='text', placeholder='jan.kowalski@poczta.pl', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputEmail1') Name
    input.form-control(type='text', placeholder='Jan', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputEmail1') Surname
    input.form-control(type='text', placeholder='Kowalski', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', :disabled='notYetClicked')
  .form-group
    label(for='exampleInputPassword1') Password
    input.form-control(type='password', placeholder='*********', :disabled='notYetClicked')
  .form-group
    a.btn.btn-primary.btn-blood.btn-main(v-on:click='notYetClicked = false')
      | Edit

and add the new variable to your JS

export default {
  name: 'item-list',

  data() {
    return {
      notYetClicked: true,
    }
  },
}


问:
[disabled]="!isValid()" is not working in IE11 for Angular 8
disabled attribute with function is not working in IE11. It remains disable all the time. Please refer below code:

HTML:

```<code> <button type="submit" (click)="onSubmit()" [disabled]="!isValid()">SAVE</button>
</code>```

Component (.ts)

```<code>isValid(){
    return this.providedId != null;
}
</code>```

答:
Try working with a getter, so you won't need the parentheses inside the template:

```<code>get isValid(){
    return this.providedId != null;
    // Or any other complicated logic...
}
</code>```

And the template without the parentheses:

```<code><button [disabled]="!isValid">SAVE</button>
</code>```

Body:
disabled attribute with function is not working in IE11. It remains disable all the time. Please refer below code:

HTML:

 <button type="submit" (click)="onSubmit()" [disabled]="!isValid()">SAVE</button>

Component (.ts)

isValid(){
    return this.providedId != null;
}

Body:
Try working with a getter, so you won't need the parentheses inside the template:

get isValid(){
    return this.providedId != null;
    // Or any other complicated logic...
}

And the template without the parentheses:

<button [disabled]="!isValid">SAVE</button>


问:
Remove elements from 2d Numpy array based on a list
Thank you in advance for taking a look at my post.

I have a 2d np.array called actions with shape (2,x) which contains ints

I have another 1d np.array keys with elements of the same type to the first dimension of actions:  actions[0]. I want to remove from actions all array elements which are in keys. I tried diff = actions[:, not actions[0] == kids_keys]but it returns a 3d array of (1,2,x) shape.

How can I get a (2,x) diff array back ?

For example:

```<code>actions = [[121122, 211122, 221122, ... 455544, 545544][0, 0.35, 0.75, ... 1, -0.25]]
keys = [211122 221122]
# The operation I am looking for:
actions - keys = [[121122, ... 455544, 545544][0, ... 1, -0.25]]

</code>```

The error: The dimmentions of the diff array become (2,1,80) for some reason I dont know!

答:
Use np.isin:

mask = np.isin(actions[0], keys, invert=True)
result = actions[:, mask]
```

Body:
Thank you in advance for taking a look at my post.

I have a 2d np.array called actions with shape (2,x) which contains ints

I have another 1d np.array keys with elements of the same type to the first dimension of actions:  actions[0]. I want to remove from actions all array elements which are in keys. I tried diff = actions[:, not actions[0] == kids_keys]but it returns a 3d array of (1,2,x) shape.

How can I get a (2,x) diff array back ?

For example:

actions = [[121122, 211122, 221122, ... 455544, 545544][0, 0.35, 0.75, ... 1, -0.25]]
keys = [211122 221122]
# The operation I am looking for:
actions - keys = [[121122, ... 455544, 545544][0, ... 1, -0.25]]

The error: The dimmentions of the diff array become (2,1,80) for some reason I dont know!


问:
ERROR: Could not install packages due to an EnvironmentError: [Errno 28] No space left on device
I was trying to install turicreate using

pip install -U turicreate

But got the error

Could not install packages due to an EnvironmentError: [Errno 28] No
  space left on device.I followed all the steps on the installation
  instructions.

Does anyone know how I could solve this error?

答:
Solution 1:
Pip won't re-download the package in this solution but in other solution it does

Check the available disk space using df -h:

```<code>$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/linux--vg-root  100G   29G   71G  29% /
tmpfs                       2.0G   46M  1.9G   3% /tmp
tmpfs                       394M   12K  394M   1% /run/user/1000
</code>```

If you just need to change tmpfs size, you can remount it on-line with new size:

```<code>$ sudo mount -o remount,size=10G /run/user/1000 # User temp dir
$ sudo mount -o remount,size=10G /tmp # System-wide temp dir
</code>```

Solution 2:
You can set the environment variable 'TMPDIR' for pip

```<code>$ export TMPDIR=$HOME/new/tmp/dir
</code>```

Solution 3:
With custom cache/temp directory

```<code>$ pip install --cache-dir=$HOME/new/tmp/dir/ -U turicreate
</code>```

Solution 4:
With no cache directory

```<code>$ pip install --no-cache-dir -U turicreate
</code>```

Body:
Solution 1:
Pip won't re-download the package in this solution but in other solution it does

Check the available disk space using df -h:

$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/linux--vg-root  100G   29G   71G  29% /
tmpfs                       2.0G   46M  1.9G   3% /tmp
tmpfs                       394M   12K  394M   1% /run/user/1000

If you just need to change tmpfs size, you can remount it on-line with new size:

$ sudo mount -o remount,size=10G /run/user/1000 # User temp dir
$ sudo mount -o remount,size=10G /tmp # System-wide temp dir

Solution 2:
You can set the environment variable 'TMPDIR' for pip

$ export TMPDIR=$HOME/new/tmp/dir

Solution 3:
With custom cache/temp directory

$ pip install --cache-dir=$HOME/new/tmp/dir/ -U turicreate

Solution 4:
With no cache directory

$ pip install --no-cache-dir -U turicreate