问:
Android Dynamic Array
I am parsing an XML file through Android Pull Parser technique. First, have a look at the below XML file:

```<code><childs>
    <students>
        <name> hello </name>
        <address> xyz </address>
    </stdents>

    <students>
        <name> abc </name>
        <address> def </address>
    </stdents>

</childs>
</code>```

Consider that I'm parsing the above file. Now, my problem is that I want to create a separate array for name and address. So while parsing, I want to store 1st student's data in name[0] and address[0] and the next student's data in name[1] and address[1]. In short, array size is extending as more data is parsed.

Is there any way to do so? I mean to create a dynamic extendable array? Or if there is another way to do so then please help me to fight with this problem.

答:
The most simple method to create an unlimited size array is using String Builder.
This allow you to add many elements in runtime.
It has 3 major components.

Decleration and Initialization.

Value addition/ Append

Print out/ Usage

Use the bellow code anywhere in Android Studio.

//Basic Decleration
        StringBuilder myString = new StringBuilder();

//Adding data
       myString.append("Hello text
");
        myString.append("some more data
");
        myString.append("more data to store
");

//Displaying in already created text view
        deviceDetails.setText(Html.fromHtml(callLogs+""));
       ```

Note: I'm treating this as HTML string and "
" tags will create the next line in text view. So, all added data will be displayed in a new line.

Title: Android Dynamic Array

Body:
I am parsing an XML file through Android Pull Parser technique. First, have a look at the below XML file:

<childs>
    <students>
        <name> hello </name>
        <address> xyz </address>
    </stdents>

    <students>
        <name> abc </name>
        <address> def </address>
    </stdents>

</childs>

Consider that I'm parsing the above file. Now, my problem is that I want to create a separate array for name and address. So while parsing, I want to store 1st student's data in name[0] and address[0] and the next student's data in name[1] and address[1]. In short, array size is extending as more data is parsed.

Is there any way to do so? I mean to create a dynamic extendable array? Or if there is another way to do so then please help me to fight with this problem.

Body:
The most simple method to create an unlimited size array is using String Builder.
This allow you to add many elements in runtime.
It has 3 major components.

Decleration and Initialization.

Value addition/ Append

Print out/ Usage

Use the bellow code anywhere in Android Studio.

//Basic Decleration
        StringBuilder myString = new StringBuilder();

//Adding data
       myString.append("Hello text <br>");
        myString.append("some more data <br>");
        myString.append("more data to store <br>");

//Displaying in already created text view
        deviceDetails.setText(Html.fromHtml(callLogs+""));

Note: I'm treating this as HTML string and "
" tags will create the next line in text view. So, all added data will be displayed in a new line.


来源: stackexchange

问:
D language: Are function signatures with constraints considered equal if they refer to the type directly or the parameter names?
Given the below function signatures (and their constraints), would they be considered the same? Both pass my unittests, so I am led to believe they may be, but I'd like to know if they are truly identical or if they are different (but behave the same):

Here, the signature constraint refers the parameter names (I realize the runtime information is not available, my assumption is that the compiler uses these to refer to the types of haystack and needle):

```<code>T[] find(T, E)(T[] haystack, E needle)
  if(is(typeof(haystack[0] != needle) == bool))
{
  // ...
}
</code>```

Now, if I update to refer to the types T and E, it still works. I like this form better because it's explicit that my signature constraint is looking the types (and not runtime information)... and well it's more concise:

```<code>T[] find(T, E)(T[] haystack, E needle)
  if(is(typeof(T != E) == bool))
{
  // ...
}
</code>```

Are my assumptions correct or am I missing something?

答:
personally I'd use if(is(typeof(T.init != E.init) == bool)) to ensure it's about the vars of the type

(and then when you want T to be a range (and losing the array notation it'd be if(isInputRange(T) && is(typeof(T.init.front != E.init) == bool)))

edit: best way to test things like this is by expanding the test case:

if we take a different function:

```<code>int binarySearch(T,E)(T[] haystack, E needle)
    if(is(typeof(haystack[0] < needle) == bool)) {
//...
   return -1;
}
</code>```

this compiles and works as you'd expect (barring implementation details...)

but

```<code>int binarySearch(T,E)(T[] haystack, E needle)
    if(is(typeof(T < E) == bool)) {
//...
   return -1;
}
</code>```

doesn't (calling binarySearch([1,2,3],0); on it doesn't compile)

however like my original answer:

```<code>int binarySearch(T,E)(T[] haystack, E needle)
   if(is(typeof(T.init > E.init) == bool)) {
    //...
    return -1;
}
</code>```

this does work like expected

ContentLicense: CC BY-SA 3.0

Body:
Given the below function signatures (and their constraints), would they be considered the same? Both pass my unittests, so I am led to believe they may be, but I'd like to know if they are truly identical or if they are different (but behave the same):

Here, the signature constraint refers the parameter names (I realize the runtime information is not available, my assumption is that the compiler uses these to refer to the types of haystack and needle):

T[] find(T, E)(T[] haystack, E needle)
  if(is(typeof(haystack[0] != needle) == bool))
{
  // ...
}

Now, if I update to refer to the types T and E, it still works. I like this form better because it's explicit that my signature constraint is looking the types (and not runtime information)... and well it's more concise:

T[] find(T, E)(T[] haystack, E needle)
  if(is(typeof(T != E) == bool))
{
  // ...
}

Are my assumptions correct or am I missing something?

Body:
personally I'd use if(is(typeof(T.init != E.init) == bool)) to ensure it's about the vars of the type

(and then when you want T to be a range (and losing the array notation it'd be if(isInputRange(T) && is(typeof(T.init.front != E.init) == bool)))

edit: best way to test things like this is by expanding the test case:

if we take a different function:

int binarySearch(T,E)(T[] haystack, E needle)
    if(is(typeof(haystack[0] < needle) == bool)) {
//...
   return -1;
}

this compiles and works as you'd expect (barring implementation details...)

but

int binarySearch(T,E)(T[] haystack, E needle)
    if(is(typeof(T < E) == bool)) {
//...
   return -1;
}

doesn't (calling binarySearch([1,2,3],0); on it doesn't compile)

however like my original answer:

int binarySearch(T,E)(T[] haystack, E needle)
   if(is(typeof(T.init > E.init) == bool)) {
    //...
    return -1;
}

this does work like expected


问:
What is the condition that an equality operator (==) cause a compile error in Kotlin?
What is the condition that an equality operator (==) cause a compile error in Kotlin?

Comparing same types is ok, of course.

```<code>fun compare1(x: Int) = x == 1
</code>```

Comparing different types cause an error:

```<code>fun compare2(x: String) = x == 1
</code>```

Operator '==' cannot be applied to 'String' and 'Int'

But comparing to generic type is ok though T may be String:

```<code>fun <T> compare3(x: T) = x == 1
</code>```

答:
== can't be applied to incompatible types, i.e. such that one object can't have both types simultaneously. Note that this applies even in cases where it would actually return true:

```<code>class X(val n: Int) {
    override fun equals(other: Any?) = x is Int
}

public fun main(){
    println(X(0) == 0) // Operator '==' cannot be applied to 'X' and 'Int'
}
</code>```

on assumption that equals "shouldn't" return true for incompatible types.

So in compare3 what matters is not that T may be String, but that it may be Int, so the comparison sometimes makes sense.

ContentLicense: CC BY-SA 4.0

Body:
What is the condition that an equality operator (==) cause a compile error in Kotlin?

Comparing same types is ok, of course.

fun compare1(x: Int) = x == 1

Comparing different types cause an error:

fun compare2(x: String) = x == 1

Operator '==' cannot be applied to 'String' and 'Int'

But comparing to generic type is ok though T may be String:

fun <T> compare3(x: T) = x == 1

Body:
== can't be applied to incompatible types, i.e. such that one object can't have both types simultaneously. Note that this applies even in cases where it would actually return true:

class X(val n: Int) {
    override fun equals(other: Any?) = x is Int
}

public fun main(){
    println(X(0) == 0) // Operator '==' cannot be applied to 'X' and 'Int'
}

on assumption that equals "shouldn't" return true for incompatible types.

So in compare3 what matters is not that T may be String, but that it may be Int, so the comparison sometimes makes sense.


问:
how to format the hint displayed inside a html form field?
There was a question previously on how to show hints in a text field (html form field), which clears automatically when the user clicks on the field under consideration. As in, when the field gets focus, the hint displayed inside the form gets cleared without the user having to manually delete the characters.

The solution given (and it works perfectly) -

```<code><input onfocus="if (this.value=='search') this.value = ''" type="text" value="search">
</code>```

Now my question is, how do you format the text that is displayed as the hint (in this case "search"). By formatting, i would want it to be in a certain color and font type.

I can do this to the other fields, which do not have this preloaded hint in it, by using css-
color:#123123; font-family:calibri;

Thanks!

答:
You're asking about styling the content (value) of an input element.

You can use regular CSS for this:

```<code>input {
  color:#123123;
  font-family:Calibri;
}
</code>```

Working example: http://jsfiddle.net/fxxp4/

Body:
There was a question previously on how to show hints in a text field (html form field), which clears automatically when the user clicks on the field under consideration. As in, when the field gets focus, the hint displayed inside the form gets cleared without the user having to manually delete the characters.

The solution given (and it works perfectly) -

<input onfocus="if (this.value=='search') this.value = ''" type="text" value="search">

Now my question is, how do you format the text that is displayed as the hint (in this case "search"). By formatting, i would want it to be in a certain color and font type.

I can do this to the other fields, which do not have this preloaded hint in it, by using css-
color:#123123; font-family:calibri;

Thanks!

Body:
You're asking about styling the content (value) of an input element.

You can use regular CSS for this:

input {
  color:#123123;
  font-family:Calibri;
}

Working example: http://jsfiddle.net/fxxp4/


问:
Combine two datasets, based on POSIXct values
I am struggling with combining two datasets with each other.

Dataset1 is containing a "before time" and a "after time", and a "channel".

Dataset2 is containing just one "time" and a "channel" column as well.

I want to add an binary column (Yes/No) to Dataset1, with this logic:
If there is a row in Dataset2, where the channel == channel, and Time is within the "before" and "after" time, I want to have "YES". Else "NO".

Data1

```<code>ID   Channel   before_time   after_time
1       A1  2019-09-02 20:13:00 2019-09-02 20:33:00
2       B1  2019-09-02 20:03:00 2019-09-02 20:23:00
3       C1  2019-09-02 20:23:00 2019-09-02 20:43:00
4       D1  2019-09-02 20:23:00 2019-09-02 20:43:00
</code>```

Data2

```<code>ID_B     Channel_B    Time_B
Hallo       A1        2019-09-02 20:23:00
Hi          B2        2019-09-02 20:05:00
Hoi         C1        2019-09-02 22:23:00
</code>```

Desired Output

```<code>ID   Channel   before_time   after_time                     Available
1       A1  2019-09-02 20:13:00 2019-09-02 20:33:00         Yes  # Channel == Channel, Time between before & after
2       B1  2019-09-02 20:03:00 2019-09-02 20:23:00          No  # Channel != Channel
3       C1  2019-09-02 20:23:00 2019-09-02 20:43:00          No  # Time is not between before & after
4       D1  2019-09-02 20:23:00 2019-09-02 20:43:00          No  # There is no matching data where channel is D1
</code>```

Desired Output 2 (comments Solutions)

Adding extra columns from the second data set (Data2).

```<code>ID   Channel   before_time   after_time                     Available   ID_B
1       A1  2019-09-02 20:13:00 2019-09-02 20:33:00          Yes        Hallo
2       B1  2019-09-02 20:03:00 2019-09-02 20:23:00          No         x
3       C1  2019-09-02 20:23:00 2019-09-02 20:43:00          No         x
4       D1  2019-09-02 20:23:00 2019-09-02 20:43:00          No         x
</code>```

Reproducible example (the data):

```<code>ID <- c("1", "2", "3", "4")
channel <- c("A1", "B1", "C1", "D1)
#startdate <- as.POSIXct(c("2019-09-02 20:23:00", "2019-09-02 20:13:00", "2019-09-02 20:33:00", "2019-09-02 20:33:00"))
before_time <- as.POSIXct(c("2019-09-02 20:13:00", "2019-09-02 20:03:00", "2019-09-02 20:23:00", "2019-09-02 20:23:00"))
after_time  <- as.POSIXct(c("2019-09-02 20:33:00", "2019-09-02 20:23:00", "2019-09-02 20:43:00","2019-09-02 20:43:00"))
data1 <- data.frame(ID, channel,   before_time, after_time)
View(data1)

ID_B <- c("Hallo", "Hi", "Hoi")
channel_B <- c("A1", "B2", "C1")
Time_B <- as.POSIXct(c("2019-09-02 20:23:00", "2019-09-02 20:05:00", "2019-09-02 22:23:00"))
data2 <- data.frame(ID_B, channel_B, Time_B)
View(data2)
</code>```

Body:
I am struggling with combining two datasets with each other.

Dataset1 is containing a "before time" and a "after time", and a "channel".

Dataset2 is containing just one "time" and a "channel" column as well.

I want to add an binary column (Yes/No) to Dataset1, with this logic:
If there is a row in Dataset2, where the channel == channel, and Time is within the "before" and "after" time, I want to have "YES". Else "NO".

Data1

ID   Channel   before_time   after_time
1       A1  2019-09-02 20:13:00 2019-09-02 20:33:00
2       B1  2019-09-02 20:03:00 2019-09-02 20:23:00
3       C1  2019-09-02 20:23:00 2019-09-02 20:43:00
4       D1  2019-09-02 20:23:00 2019-09-02 20:43:00

Data2

ID_B     Channel_B    Time_B
Hallo       A1        2019-09-02 20:23:00
Hi          B2        2019-09-02 20:05:00
Hoi         C1        2019-09-02 22:23:00

Desired Output

ID   Channel   before_time   after_time                     Available
1       A1  2019-09-02 20:13:00 2019-09-02 20:33:00         Yes  # Channel == Channel, Time between before & after
2       B1  2019-09-02 20:03:00 2019-09-02 20:23:00          No  # Channel != Channel
3       C1  2019-09-02 20:23:00 2019-09-02 20:43:00          No  # Time is not between before & after
4       D1  2019-09-02 20:23:00 2019-09-02 20:43:00          No  # There is no matching data where channel is D1

Desired Output 2 (comments Solutions)

Adding extra columns from the second data set (Data2).

ID   Channel   before_time   after_time                     Available   ID_B
1       A1  2019-09-02 20:13:00 2019-09-02 20:33:00          Yes        Hallo
2       B1  2019-09-02 20:03:00 2019-09-02 20:23:00          No         x
3       C1  2019-09-02 20:23:00 2019-09-02 20:43:00          No         x
4       D1  2019-09-02 20:23:00 2019-09-02 20:43:00          No         x

Reproducible example (the data):

ID <- c("1", "2", "3", "4")
channel <- c("A1", "B1", "C1", "D1)
#startdate <- as.POSIXct(c("2019-09-02 20:23:00", "2019-09-02 20:13:00", "2019-09-02 20:33:00", "2019-09-02 20:33:00"))
before_time <- as.POSIXct(c("2019-09-02 20:13:00", "2019-09-02 20:03:00", "2019-09-02 20:23:00", "2019-09-02 20:23:00"))
after_time  <- as.POSIXct(c("2019-09-02 20:33:00", "2019-09-02 20:23:00", "2019-09-02 20:43:00","2019-09-02 20:43:00"))
data1 <- data.frame(ID, channel,   before_time, after_time)
View(data1)

ID_B <- c("Hallo", "Hi", "Hoi")
channel_B <- c("A1", "B2", "C1")
Time_B <- as.POSIXct(c("2019-09-02 20:23:00", "2019-09-02 20:05:00", "2019-09-02 22:23:00"))
data2 <- data.frame(ID_B, channel_B, Time_B)
View(data2)

Body:
As mentioned by arg0naut91, here is non-equi join in data.table:

library(data.table)
setDT(data1)
setDT(data2)
data1[, c("Available", "ID_B") :=
        data2[.SD, on=.(channel_B=channel, Time_B>=before_time, Time_B<=after_time),
            by=.EACHI, .(.N > 0, ID_B)][, (1L:3L) := NULL]
    ]

output:

   ID channel         before_time          after_time Available  ID_B
1:  1      A1 2019-09-02 20:13:00 2019-09-02 20:33:00      TRUE Hallo
2:  2      B1 2019-09-02 20:03:00 2019-09-02 20:23:00     FALSE  <NA>
3:  3      C1 2019-09-02 20:23:00 2019-09-02 20:43:00     FALSE  <NA>
4:  4      D1 2019-09-02 20:23:00 2019-09-02 20:43:00     FALSE  <NA>


问:
Google Calendar API: holiday event with day off property
In my app, I am getting the events from the holiday calendar of a particular country. I wonder if it's possible to distinguish between holiday in which you work and the holiday when you have day off. Eg.: Valintine day in my country is not a day off but Christmas day is.

Thanks for any advice!

答:
This depends on the calendar

The default Google holiday calendars do not specify in the description which holidays are bank holidays (the ones where you don't work) and which are not, so there is no way to know distinguish between them.

What you can do instead is create or find a private calendar that you can import.

I don't know your region, but for example for Barcelona, the council of Barcelona offers a public holiday calendar that you can download as a ICS file and import into your calendar. I am sure that for your region you can find something similar.


问:
Invalid Syntax on tkinter's geometry widget
I am trying to design a GUI for a bit of fun.
the purpose of the  code is to take what you entered into a "entry widget" and print it out in the terminal using the print() command when you press the submit button.

Two questions.

One: i keep getting an "Invalid syntax" error in the code both the root.geometry() and root.mainloop()

```<code>root.geometry("300x300")

root.mainloop()
</code>```

two: is there a more effective way of getting the text from a tkinter entry widget and storing it in a variable. i would like to be able to store data from multiple entry widgets to multiple variables, and how can i do that.

Here is my full code.

```<code>from tkinter import *

root = Tk()

def get_input():
    val = e1.get("1.0", "end-1-c")
    print(val)

lbl1 = Label(root, text = "Enter your name:").grid(row= "0", column= "0")
e1 = Entry(root, borderwidth = 5, width = 20).grid(row = "0", column = "1")
sbut = Button(root, text = "submit", command = get_input.grid(row= "1", column = "0")

root.geometry("300x300")

root.mainloop()
</code>```

i used https://www.youtube.com/watch?v=FueIPFqRyyY&t=85s for the code to save entry widget data to a varible

Thanks for any help

答:
You should not define a widget and .grid() it in the same line. You also had an Invalid syntax because you forgot a ) at the line sbut = Button(....grid(row= "1", column = "0"))

You can try this :

```<code>from tkinter import *

root = Tk()

def get_input():
    val = e1.get()
    e1.delete("0", "end")
    print(val)

lbl1 = Label(root, text = "Enter your name:")
lbl1.grid(row= "0", column= "0")
e1 = Entry(root, borderwidth = 5, width = 20)
e1.grid(row = "0", column = "1")
sbut = Button(root, text = "submit", command = get_input)
sbut.grid(row= "1", column = "0")

root.geometry("300x300")

root.mainloop()
</code>```

Body:
I am trying to design a GUI for a bit of fun.
the purpose of the  code is to take what you entered into a "entry widget" and print it out in the terminal using the print() command when you press the submit button.

Two questions.

One: i keep getting an "Invalid syntax" error in the code both the root.geometry() and root.mainloop()

root.geometry("300x300")

root.mainloop()

two: is there a more effective way of getting the text from a tkinter entry widget and storing it in a variable. i would like to be able to store data from multiple entry widgets to multiple variables, and how can i do that.

Here is my full code.

from tkinter import *

root = Tk()

def get_input():
    val = e1.get("1.0", "end-1-c")
    print(val)

lbl1 = Label(root, text = "Enter your name:").grid(row= "0", column= "0")
e1 = Entry(root, borderwidth = 5, width = 20).grid(row = "0", column = "1")
sbut = Button(root, text = "submit", command = get_input.grid(row= "1", column = "0")

root.geometry("300x300")

root.mainloop()

i used https://www.youtube.com/watch?v=FueIPFqRyyY&t=85s for the code to save entry widget data to a varible

Thanks for any help

Body:
You should not define a widget and .grid() it in the same line. You also had an Invalid syntax because you forgot a ) at the line sbut = Button(....grid(row= "1", column = "0"))

You can try this :

from tkinter import *

root = Tk()

def get_input():
    val = e1.get()
    e1.delete("0", "end")
    print(val)

lbl1 = Label(root, text = "Enter your name:")
lbl1.grid(row= "0", column= "0")
e1 = Entry(root, borderwidth = 5, width = 20)
e1.grid(row = "0", column = "1")
sbut = Button(root, text = "submit", command = get_input)
sbut.grid(row= "1", column = "0")

root.geometry("300x300")

root.mainloop()


问:
How to display filenames of word documents in a folder using python?
I want to display the filenames of word document present in a specified path using python.</p>

答:
this could work for you:</p>

```<code>for file in os.listdir(PATH):
    if file.endswith(".doc") or file.endswith(".docx"):
        print(file)
</code>```

Body:
this could work for you:

for file in os.listdir(PATH):
    if file.endswith(".doc") or file.endswith(".docx"):
        print(file)


问:
Link is not clickable using GeckoDriver and Firefox through Selenium and Java
I get an error when trying to open a link via Selenium in:

FireFox V. 73. 0 (64-bit)

Geckodriver driver version-v0.26. 0

Help me solve the problem

```<code>public By searchResultLinktLocator(int searchResult) {
    By searchResultLinktLocator = By.xpath("//li[@data-result-number='" + searchResult + "']" + "//a");
    return searchResultLinktLocator;
}

public BBCSearchPage openSearchResultLink(int searchResult) {
    actions.click(driver.findElement(searchResultLinktLocator(searchResult))).perform();
    return this;
}
</code>```

The link for this function does not open:

```<code>searchPage.openSearchResultLink(1);
</code>```

A page that does not open a link: https://www.bbc.co.uk/search?q=Andersen

```<code>1581606071797   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\anduser\\AppData\\Local\\Temp\\rust_mozprofileZpIGZz"
1581606072297   addons.webextension.doh-rollout@mozilla.org WARN    Loading extension 'doh-rollout@mozilla.org': Reading manifest: Invalid extension permission: networkStatus
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1581606075330   Marionette  INFO    Listening on port 53959
1581606075570   Marionette  WARN    TLS certificate errors will be ignored for this session
фев 13, 2020 6:01:15 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript error: https://nav.files.bbci.co.uk/orbit/1b2e292884201dd13064a9204e177864/js/require.min.js, line 1: TypeError: e.slice is not a function
1581606081548   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
action.dispatch@chrome://marionette/content/action.js:1034:5
performActions@chrome://marionette/content/listener.js:850:16
dispatch/</req<@chrome://marionette/content/listener.js:527:14
dispatch/<@chrome://marionette/content/listener.js:520:15
1581606081697   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081712   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081730   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081732   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081734   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081747   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081752   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081753   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081755   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081755   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081863   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081874   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081882   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081886   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081888   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081899   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081931   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081945   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
JavaScript error: , line 0: uncaught exception: undefined
</code>```

答:
I took your code and simplified the structure and ran the test with minimal lines of code as follows:

Code Block:

```<code>public class A_Firefox_Test
{
    public static void main(String[] args)
    {
        System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.bbc.co.uk/search?q=Andersen");
        int searchResult = 1;
        new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@data-result-number='" + searchResult + "']"))).click();
    }
}
</code>```

Similar to your observation I have hit the same roadblock, that the desired link wasn't clickable and additionally an WARNING as:

```<code>[Parent 7472, Gecko_IOThread] WARNING: file z:/task_1579290903/build/src/ipc/chromium/src/base/process_util_win.cc, line 160
</code>```

which implies the service was interupted within process_util_win.cc i.e. process module.

Deep dive

I went ahead and while inspecting the DOM Tree of the webpage it was observed that some of the

Body:
I get an error when trying to open a link via Selenium in:

FireFox V. 73. 0 (64-bit)

Geckodriver driver version-v0.26. 0

Help me solve the problem

public By searchResultLinktLocator(int searchResult) {
    By searchResultLinktLocator = By.xpath("//li[@data-result-number='" + searchResult + "']" + "//a");
    return searchResultLinktLocator;
}

public BBCSearchPage openSearchResultLink(int searchResult) {
    actions.click(driver.findElement(searchResultLinktLocator(searchResult))).perform();
    return this;
}

The link for this function does not open:

searchPage.openSearchResultLink(1);

A page that does not open a link: https://www.bbc.co.uk/search?q=Andersen

1581606071797   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\anduser\\AppData\\Local\\Temp\\rust_mozprofileZpIGZz"
1581606072297   addons.webextension.doh-rollout@mozilla.org WARN    Loading extension 'doh-rollout@mozilla.org': Reading manifest: Invalid extension permission: networkStatus
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1581606072791   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1581606075330   Marionette  INFO    Listening on port 53959
1581606075570   Marionette  WARN    TLS certificate errors will be ignored for this session
фев 13, 2020 6:01:15 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript error: https://nav.files.bbci.co.uk/orbit/1b2e292884201dd13064a9204e177864/js/require.min.js, line 1: TypeError: e.slice is not a function
1581606081548   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
action.dispatch@chrome://marionette/content/action.js:1034:5
performActions@chrome://marionette/content/listener.js:850:16
dispatch/</req<@chrome://marionette/content/listener.js:527:14
dispatch/<@chrome://marionette/content/listener.js:520:15
1581606081697   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081712   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081730   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081732   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081734   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081747   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081752   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081753   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081755   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081755   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081863   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081874   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081882   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081886   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081888   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081899   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081931   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
1581606081945   Marionette  WARN    TimedPromise timed out after 0 ms: stacktrace:
TimedPromise/<@chrome://marionette/content/sync.js:244:13
TimedPromise@chrome://marionette/content/sync.js:229:10
Sleep@chrome://marionette/content/sync.js:282:10
dispatchPause@chrome://marionette/content/action.js:1482:10
toEvents/<@chrome://marionette/content/action.js:1156:16
action.dispatchTickActions@chrome://marionette/content/action.js:1060:35
action.dispatch/chainEvents<@chrome://marionette/content/action.js:1028:20
JavaScript error: , line 0: uncaught exception: undefined

Body:
I took your code and simplified the structure and ran the test with minimal lines of code as follows:

Code Block:

public class A_Firefox_Test
{
    public static void main(String[] args)
    {
        System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.bbc.co.uk/search?q=Andersen");
        int searchResult = 1;
        new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@data-result-number='" + searchResult + "']"))).click();
    }
}

Similar to your observation I have hit the same roadblock, that the desired link wasn't clickable and additionally an WARNING as:

[Parent 7472, Gecko_IOThread] WARNING: file z:/task_1579290903/build/src/ipc/chromium/src/base/process_util_win.cc, line 160

which implies the service was interupted within process_util_win.cc i.e. process module.

Deep dive

I went ahead and while inspecting the DOM Tree of the webpage it was observed that some of the <script> tag refers to JavaScripts having keyword dist. As an example:

map['idcta-v2/idcta-1'] = 'https://static.files.bbci.co.uk/account/id-cta/1.36.1/modules/idcta-v2/dist/idcta-1.min';

document.write('<script type="text/javascript" src="https://static.bbc.co.uk/bbcdotcom/3.6.969/script/dist/bbcdotcom.dev.js">\x3C/script>');

document.write('<script type="text/javascript" src="https://static.bbc.co.uk/bbcdotcom/3.6.969/script/dist/bbcdotcom.js">\x3C/script>');

Which is a clear indication that the website is protected by Bot Management service provider Distil Networks and the navigation by ChromeDriver gets detected and subsequently blocked.

Distil

As per the article There Really Is Something About Distil.it...:

Distil protects sites against automatic content scraping bots by observing site behavior and identifying patterns peculiar to scrapers. When Distil identifies a malicious bot on one site, it creates a blacklisted behavioral profile that is deployed to all its customers. Something like a bot firewall, Distil detects patterns and reacts.

Further,

"One pattern with Selenium was automating the theft of Web content", Distil CEO Rami Essaid said in an interview last week. "Even though they can create new bots, we figured out a way to identify Selenium the a tool they're using, so we're blocking Selenium no matter how many times they iterate on that bot. We're doing that now with Python and a lot of different technologies. Once we see a pattern emerge from one type of bot, then we work to reverse engineer the technology they use and identify it as malicious".

Reference

You can find a couple of relevant detailed discussions in:

Chrome browser initiated through ChromeDriver gets detected

Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection

Akamai Bot Manager detects WebDriver driven Chrome Browsing Context

Is there a version of selenium webdriver that is not detectable?


问:
Issue with the direction: rtl CSS property
I have an HTML element and I need to display a folder / file path within it that can sometimes be very long.

I also want to keep it on a single line (within a width constrained container) so I obviously need to add some ellipsis to it.

Another requirement is that I should always see the deepest folder nodes in that path (this is helpful when the path is long, because the latest nodes is what you're actually interested in).

The problem is, this is quite hard to achieve if I'm to use the direction: rtl; CSS property, because it will move other characters around, such as / or even paranthesis.

Take a look at this example: https://jsfiddle.net/r897duu9/1/ (as you can see, I didn't use the text-overflow: ellipsis property as this will, for some reason, override the direction: rtl property).

What I've tried so far and it works on modern browsers is adding the unicode-bidi: plaintext; CSS property, but according to the Mozilla Developer Network this is experimental and not well supported across not-so-modern cough IE browsers. The fiddle for this is here: https://jsfiddle.net/n05b3jgt/1/ .

Does anyone know a better way to achieve this, that would be well supported across a wide range of browsers?

答:
I looked at the other solutions but I think this is simpler and more effective.

.title-wrapper {
  max-width: 200px;

  text-align: left;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  direction: rtl;
}

.title {
  unicode-bidi: plaintext;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code>  <div class="title-wrapper">
    <span class="title">asdasd/qweqwe/xcvxcv/rtyrty/dfgdfgdfgdfgdfgd</span>
  </div></code>```

Body:
I looked at the other solutions but I think this is simpler and more effective.

.title-wrapper {
  max-width: 200px;

  text-align: left;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  direction: rtl;
}

.title {
  unicode-bidi: plaintext;
}

  <div class="title-wrapper">
    <span class="title">asdasd/qweqwe/xcvxcv/rtyrty/dfgdfgdfgdfgdfgd</span>
  </div>


问:
How can i achieve multiple page scraping with axios and cheerio
Hello i am using axios with cheerio to scrape some data.I want to scrape multiple pages,
the url structure is like example.com/?page=1.How i can scrape every single page with a counter ? </p>

```<code>axios({
    method: "get",
    url:
      "https://example.com/?page=",
    headers: {
      "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
    }
  }).then(res => {
</code>```

答:
I believe there are multiple ways to achieve that solution but basically you need to execute all the axios and parse all of them with Cheerio programatically.

If you know how many pages that you want to scrape

You can create a simple for loop and push all the axios functions into an array one by one with the generated urls. Then you can call these with Promise.all

```<code>const promises = [];

for(let page = 0; page <= 5; page ++){
     promises.push(
          axios({method: "get",url:`https://example.com?page=${page}`})
          .then(res => {
              // Parse your result with Cheerio or whatever you like
          })
     );
}

// You can pass the responses on this resolve if you want.
Promise.all(promises).then(...)
</code>```

If you are scraping a list page and total page number is unknown

Then you can create a async/recursive function for dispatching the request with axios and conditionally iterate. With that way you can also reduce maximum usage of memory when you compare with the solution below. And it will be slower because the requests will not be in parallel.

```<code>// The function below is kind-of pseudo code so don't try to copy/paste it :)
const dispatchRequest = (page) => {
     const response = axios({url: `https://example.com?page=${page}`});
     // Ex: You can parse the response here with Cheerio and check if pagination is not disable
     if(something){
          return dispatchRequest(page+1);
     }
     else{
         return response;
     }

}
</code>```

The solutions above has down-sides of course. If you get blocked by target website or somehow your request fails, you have no chance to retry the same request or rotate your proxies to bypass the target websites security.

I'd suggest you to implement a queue and put all of the request dispatch functions there. With that way you can detect fails/problems and enqueue the failed requests again. You can also implement both of the solutions above with a queue support. You can run it in parallel and manage your memory/CPU consuming way much better.

Also you can use SDKs too. I saw there are couple of scraping SDKs with provides you this whole toolset so you won't re-invent the wheel.

Body:
Hello i am using axios with cheerio to scrape some data.I want to scrape multiple pages,
the url structure is like example.com/?page=1.How i can scrape every single page with a counter ?

axios({
    method: "get",
    url:
      "https://example.com/?page=",
    headers: {
      "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
    }
  }).then(res => {

Body:
I believe there are multiple ways to achieve that solution but basically you need to execute all the axios and parse all of them with Cheerio programatically.

If you know how many pages that you want to scrape

You can create a simple for loop and push all the axios functions into an array one by one with the generated urls. Then you can call these with Promise.all

const promises = [];

for(let page = 0; page <= 5; page ++){
     promises.push(
          axios({method: "get",url:`https://example.com?page=${page}`})
          .then(res => {
              // Parse your result with Cheerio or whatever you like
          })
     );
}

// You can pass the responses on this resolve if you want.
Promise.all(promises).then(...)

If you are scraping a list page and total page number is unknown

Then you can create a async/recursive function for dispatching the request with axios and conditionally iterate. With that way you can also reduce maximum usage of memory when you compare with the solution below. And it will be slower because the requests will not be in parallel.

// The function below is kind-of pseudo code so don't try to copy/paste it :)
const dispatchRequest = (page) => {
     const response = axios({url: `https://example.com?page=${page}`});
     // Ex: You can parse the response here with Cheerio and check if pagination is not disable
     if(something){
          return dispatchRequest(page+1);
     }
     else{
         return response;
     }

}

The solutions above has down-sides of course. If you get blocked by target website or somehow your request fails, you have no chance to retry the same request or rotate your proxies to bypass the target websites security.

I'd suggest you to implement a queue and put all of the request dispatch functions there. With that way you can detect fails/problems and enqueue the failed requests again. You can also implement both of the solutions above with a queue support. You can run it in parallel and manage your memory/CPU consuming way much better.

Also you can use SDKs too. I saw there are couple of scraping SDKs with provides you this whole toolset so you won't re-invent the wheel.


问:
Graphviz for documenting EVMS chart
I am evaluating ways to generate charts similar to the following. Would graphviz with subplots be an appropriate approach, or is there a better way? Not even sure what to look for in a web search right now.

Would like to show a WBS in tree form across the top, an Organizational Structure in tree form on the left side and then, where appropriate, control account designations in the cells that correspond to intersecting leaf nodes.

答:
I don't think the automatic layouts in the GraphViz package can help you here, alone. While at the top and at the right side the graph does look like a regular tree structure which should be easily doable with the "dot" hierarchical style, the difficult part would be to get the matrix style in the center of the graph or more specifically merging the two tree layouts in the matrix.

Even with a more sophisticated diagramming and layout library, this kind of layout would require some manual configuration and extra coding (which nodes belong to the top and right hand side, which ones belong to the "matrix" part, etc.).

If you try yFiles, you would need to combine two instances of the TreeLayout, one GenericPartitionGridStage combined with a LayoutMultiplexer, one TabularLayout and a StraightLineRouter or use a custom "LayoutStage" for the simple "matrix part". Doable and feasible, but certainly not a simple task.

Full disclosure: I work for the company that creates the above mentioned graph layout library. I do not represent my employer here on SO, though. Thoughts and comments are my own.

Title: Graphviz for documenting EVMS chart


问:
Type annotation for overloads that exclude types (something vs everything else)
I'm trying to use @overload to communicate the different ways of calling a function, but what is easily communicated in the code with a simple else statement is not possible in the type annotations.  Without the "else" MyPy (correctly) complains that the overload versions mismatch (see the snippet below for example).

error: Overloaded function signatures 1 and 2 overlap with incompatible return types

Did I understand correctly that there is no good solution for this problem?

eg. here is a simple example:

ListOrTuple = TypeVar("ListOrTuple", List, Tuple)
# unfortunately, typing doesn't support "anything else" at the moment
# https://github.com/python/typing/issues/599#issuecomment-586007066
AnythingElse = TypeVar("AnythingElse")
# what I would like to have is something like AnythingElse= TypeVar("AnythingElse", Not[List,Tuple])

@overload
def as_list(val: ListOrTuple) -> ListOrTuple:
    ...

@overload
def as_list(val: AnythingElse) -> List[AnythingElse]:
    ...

def as_list(val):
    """Return list/tuple as is, otherwise wrap in a list

    >>> as_list("test")
    ['test']
    """
    return val if isinstance(val, (list, tuple)) else [val]
```

答:
This is the work-around that I have. It works well enough for me but I don't like it at all.</p>

```<code># attempt to list all the "other" possible types
AnythingElse = TypeVar("AnythingElse", Set, Mapping, type, int, str, None, Callable, Set, Deque, ByteString)
ListOrTuple = TypeVar("ListOrTuple", List, Tuple, Sequence)

@overload
def as_list(val: ListOrTuple) -> ListOrTuple:
    ...

@overload
def as_list(val: AnythingElse) -> List[AnythingElse]:
    ...

def as_list(val):
    """Return list/tuple as is, otherwise wrap in a list

    >>> as_list("test")
    ['test']
    """
    return val if isinstance(val, (list, tuple)) else [val]
</code>```

Body:
This is the work-around that I have. It works well enough for me but I don't like it at all.

# attempt to list all the "other" possible types
AnythingElse = TypeVar("AnythingElse", Set, Mapping, type, int, str, None, Callable, Set, Deque, ByteString)
ListOrTuple = TypeVar("ListOrTuple", List, Tuple, Sequence)

@overload
def as_list(val: ListOrTuple) -> ListOrTuple:
    ...

@overload
def as_list(val: AnythingElse) -> List[AnythingElse]:
    ...

def as_list(val):
    """Return list/tuple as is, otherwise wrap in a list

    >>> as_list("test")
    ['test']
    """
    return val if isinstance(val, (list, tuple)) else [val]


问:
Operand type clash: int is incompatible with DaysAndHours
Exception: Operand type clash: int is incompatible with DaysAndHours    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action

The above exception is getting when I add int type value to SQL parameters.How to pass the int value to sql parameters.

C# code:

```<code> public bool VendorDaysAndHoursInfoByMemberID(UpdateVendaorDaysAndHoursDM updateVendaorDaysAndHoursDM)
        {
            _logger.LogInformation("VendorRepository.vendorDaysAndHoursInfoByMemberID method called!!!");
            var memberId = updateVendaorDaysAndHoursDM.MemberID;

            var vendorDaysAndHoursDMsList = updateVendaorDaysAndHoursDM.DaysAndHours.Select(c => c).Select(c => c).ToList();
            DataTable dtVendorDaysAndHoursDMsList = DataReaderToList.ToDataTable<DaysAndHoursDM>(vendorDaysAndHoursDMsList);

            using (SqlConnection conn = new SqlConnection(GetComapnyConnection.ConnectionString))
            {
                conn.Open();
                using (var transaction = conn.BeginTransaction())
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("exec VendorDaysAndHoursInfoByMemberID @MemberID, @DaysAndHours", conn, transaction);

                        cmd.CommandTimeout = 0;
                        cmd.Transaction = transaction;

                       cmd.Parameters.AddWithValue("@MemberID", SqlDbType.Int).Value = memberId;

                        //cmd.Parameters.Add(new SqlParameter()
                        //{
                        //    ParameterName = "@MemberID",
                        //    SqlDbType = SqlDbType.Structured,
                        //    Value = memberId,
                        //    TypeName = "MemberID"
                        //});

                        var pDaysAndHoursDMsList = new SqlParameter("@DaysAndHours", SqlDbType.Structured);
                        pDaysAndHoursDMsList.TypeName = "DaysAndHours";
                        if (dtVendorDaysAndHoursDMsList.Rows.Count == 0)
                            pDaysAndHoursDMsList.Value = null;
                        else
                            pDaysAndHoursDMsList.Value = dtVendorDaysAndHoursDMsList;
                        cmd.Parameters.Add(pDaysAndHoursDMsList);
                        var dataReader = cmd.ExecuteReader();
                        var isResult = DataReaderToList.DataReaderMapToList<bool>(dataReader);

                        dataReader.Dispose();

                        transaction.Commit();

                        conn.Close();

                        return true;
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        conn.Close();
                        _logger.LogError(e.Message);
                        return false;
                    }
                }
            }

        }
</code>```

I need to post data in the below format.

```<code>{
"MemberID":"a7f1819db38ccb5e03ad52396eafa5ac"                    ,
"DaysAndHours":[
                    {"DayName":"Sunday","StartTime":"08:00:00","EndTime":"17:00:00","Available":false},
                    {"DayName":"Monday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Tuesday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Wednesday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Thursday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Friday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Saturday","StartTime":"08:00:00","EndTime":"19:00:00","Available":true}
                   ]
    }
</code>```

How to pass the int value to SQL parameters in above format.

Stored Procedure:

```<code>Create proc [dbo].[VendorDaysAndHoursInfoByMemberID]
(
@DaysAndHours as [dbo].DaysAndHours readonly,
@MemberID int,
@IsSuccess bit= 'false' output
)
as begin
SET NOCOUNT ON;

    update DaysAndHours  set
    DaysAndHours.DayName=DaysAndHoursData.DayName,
    DaysAndHours.StartTime=DaysAndHoursData.StartTime,
    DaysAndHours.EndTime=DaysAndHoursData.EndTime,
    DaysAndHours.Available=DaysAndHoursData.Available

    from  @DaysAndHours DaysAndHoursData
 where MemberID = @MemberID;

 set @IsSuccess = 'true'

End
return @IsSuccess
</code>```

Code is not displaying errors.But isResult is getting count zero which is below of DataReader.

答:
Sql Command is not properly configured. Try this

```<code>
SqlCommand cmd = new SqlCommand("VendorDaysAndHoursInfoByMemberID", conn, transaction);
</code>```

Stored Procedure code

```<code>Create proc [dbo].[VendorDaysAndHoursInfoByMemberID]
(
@DaysAndHours as [dbo].DaysAndHours readonly,
@MemberID int,
@IsSuccess bit= 0 output
)
as begin
SET NOCOUNT ON;

    update DaysAndHours  set
        DayName=@DaysAndHours.DayName,
        StartTime=@DaysAndHours.StartTime,
        EndTime=@DaysAndHours.EndTime,
        Available=@DaysAndHours.Available
from DaysAndHours join @DaysAndHours
ON DaysAndHours.MemberID =@DaysAndHours.MemberID
 where MemberID = @MemberID;

 set @IsSuccess = 1

End
return @IsSuccess
</code>```

Body:
Exception: Operand type clash: int is incompatible with DaysAndHours    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action

The above exception is getting when I add int type value to SQL parameters.How to pass the int value to sql parameters.

C# code:

 public bool VendorDaysAndHoursInfoByMemberID(UpdateVendaorDaysAndHoursDM updateVendaorDaysAndHoursDM)
        {
            _logger.LogInformation("VendorRepository.vendorDaysAndHoursInfoByMemberID method called!!!");
            var memberId = updateVendaorDaysAndHoursDM.MemberID;

            var vendorDaysAndHoursDMsList = updateVendaorDaysAndHoursDM.DaysAndHours.Select(c => c).Select(c => c).ToList();
            DataTable dtVendorDaysAndHoursDMsList = DataReaderToList.ToDataTable<DaysAndHoursDM>(vendorDaysAndHoursDMsList);

            using (SqlConnection conn = new SqlConnection(GetComapnyConnection.ConnectionString))
            {
                conn.Open();
                using (var transaction = conn.BeginTransaction())
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("exec VendorDaysAndHoursInfoByMemberID @MemberID, @DaysAndHours", conn, transaction);

                        cmd.CommandTimeout = 0;
                        cmd.Transaction = transaction;

                       cmd.Parameters.AddWithValue("@MemberID", SqlDbType.Int).Value = memberId;

                        //cmd.Parameters.Add(new SqlParameter()
                        //{
                        //    ParameterName = "@MemberID",
                        //    SqlDbType = SqlDbType.Structured,
                        //    Value = memberId,
                        //    TypeName = "MemberID"
                        //});

                        var pDaysAndHoursDMsList = new SqlParameter("@DaysAndHours", SqlDbType.Structured);
                        pDaysAndHoursDMsList.TypeName = "DaysAndHours";
                        if (dtVendorDaysAndHoursDMsList.Rows.Count == 0)
                            pDaysAndHoursDMsList.Value = null;
                        else
                            pDaysAndHoursDMsList.Value = dtVendorDaysAndHoursDMsList;
                        cmd.Parameters.Add(pDaysAndHoursDMsList);
                        var dataReader = cmd.ExecuteReader();
                        var isResult = DataReaderToList.DataReaderMapToList<bool>(dataReader);

                        dataReader.Dispose();

                        transaction.Commit();

                        conn.Close();

                        return true;
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        conn.Close();
                        _logger.LogError(e.Message);
                        return false;
                    }
                }
            }

        }

I need to post data in the below format.

{
"MemberID":"a7f1819db38ccb5e03ad52396eafa5ac"                    ,
"DaysAndHours":[
                    {"DayName":"Sunday","StartTime":"08:00:00","EndTime":"17:00:00","Available":false},
                    {"DayName":"Monday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Tuesday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Wednesday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Thursday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Friday","StartTime":"08:00:00","EndTime":"17:00:00","Available":true},
                    {"DayName":"Saturday","StartTime":"08:00:00","EndTime":"19:00:00","Available":true}
                   ]
    }

How to pass the int value to SQL parameters in above format.

Stored Procedure:

Create proc [dbo].[VendorDaysAndHoursInfoByMemberID]
(
@DaysAndHours as [dbo].DaysAndHours readonly,
@MemberID int,
@IsSuccess bit= 'false' output
)
as begin
SET NOCOUNT ON;

    update DaysAndHours  set
    DaysAndHours.DayName=DaysAndHoursData.DayName,
    DaysAndHours.StartTime=DaysAndHoursData.StartTime,
    DaysAndHours.EndTime=DaysAndHoursData.EndTime,
    DaysAndHours.Available=DaysAndHoursData.Available

    from  @DaysAndHours DaysAndHoursData
 where MemberID = @MemberID;

 set @IsSuccess = 'true'

End
return @IsSuccess

Code is not displaying errors.But isResult is getting count zero which is below of DataReader.

Body:
Sql Command is not properly configured. Try this

SqlCommand cmd = new SqlCommand("VendorDaysAndHoursInfoByMemberID", conn, transaction);

Stored Procedure code

Create proc [dbo].[VendorDaysAndHoursInfoByMemberID]
(
@DaysAndHours as [dbo].DaysAndHours readonly,
@MemberID int,
@IsSuccess bit= 0 output
)
as begin
SET NOCOUNT ON;

    update DaysAndHours  set
        DayName=@DaysAndHours.DayName,
        StartTime=@DaysAndHours.StartTime,
        EndTime=@DaysAndHours.EndTime,
        Available=@DaysAndHours.Available
from DaysAndHours join @DaysAndHours
ON DaysAndHours.MemberID =@DaysAndHours.MemberID
 where MemberID = @MemberID;

 set @IsSuccess = 1

End
return @IsSuccess


问:
How to compare all the values of two keys with in same PCollection in python?
I am new to Apache Beam/dataflow. I am reading a BigQuery table in Apache Beam and I want to do group by two different columns and compare all the values for two different keys. I have created a tuple of two different columns (ID, Date) that acts as Key. Below is the sample data in a table

```<code>  ID         Date        P_id    position
  "abc"    2019-08-01   "rt56"      5
  "abc"    2019-08-01   "rt57"      6
  "abc"    2019-08-01   "rt58"      7
  "abc"    2019-08-02   "rt56"      2
  "abc"    2019-08-02   "rt57"      4
  "abc"    2019-08-02   "rt58"      7
</code>```

Now I want to compare the position of the P_ids for pair ("abc", 2019-08-01) and ("abc", 2019-08-02) and see if any of the P_id position is changed then add another column in the table "status" with True. So my new table should be like below

I am trying it with below code

```<code>  ID         Date        P_id    position  Status
  "abc"    2019-08-01   "rt56"      5       False (as this is first date)
  "abc"    2019-08-01   "rt57"      6
  "abc"    2019-08-01   "rt58"      7
  "abc"    2019-08-02   "rt56"      2       True
  "abc"    2019-08-02   "rt57"      4
  "abc"    2019-08-02   "rt58"      7
</code>```

```<code>(
p
| "get_key_tuple" >> beam.ParDo(lambda element: tuple(element["Id"], element["Date]))
| "group_by" >> beam.GroupByKey()
| "compare_and_add_status" >> beam.ParDo(compare_pos)
)
</code>```

But I don't know how should I proceed for the function compare_pos()

It would be very helpful to get some ideas on how can I efficiently compare the position and create a new column to know the status considering I have a very large table and lots of ID's.

答:
I might be interpreting OP wrong, but if the suggestion by @robertwb doesn't work, try perhaps grouping by the following instead:

```<code>| "Create k, v tuple" >> beam.Map(
                    lambda elem: ((elem["P_id"], elem["ID"]), [elem["Date"], elem["position"]]))
| "Group by key" >> beam.GroupByKey()
</code>```

Which will output the following structure:

```<code>(('rt56', 'abc'), [['2019-08-01', 5], ['2019-08-02', 2]])
(('rt57', 'abc'), [['2019-08-01', 6], ['2019-08-02', 4]])
(('rt58', 'abc'), [['2019-08-01', 7], ['2019-08-02', 7]])
</code>```

Which should allow you to compare each element in the resulting PCollection individually, instead of cross-comparing across elements in the PCollection. This should probably fit the execution model of Beam better if I'm correct.

This is based on my assumption that you want to check if the position for a given P_id has changed between two dates.

Body:
I am new to Apache Beam/dataflow. I am reading a BigQuery table in Apache Beam and I want to do group by two different columns and compare all the values for two different keys. I have created a tuple of two different columns (ID, Date) that acts as Key. Below is the sample data in a table

  ID         Date        P_id    position
  "abc"    2019-08-01   "rt56"      5
  "abc"    2019-08-01   "rt57"      6
  "abc"    2019-08-01   "rt58"      7
  "abc"    2019-08-02   "rt56"      2
  "abc"    2019-08-02   "rt57"      4
  "abc"    2019-08-02   "rt58"      7

Now I want to compare the position of the P_ids for pair ("abc", 2019-08-01) and ("abc", 2019-08-02) and see if any of the P_id position is changed then add another column in the table "status" with True. So my new table should be like below

I am trying it with below code

  ID         Date        P_id    position  Status
  "abc"    2019-08-01   "rt56"      5       False (as this is first date)
  "abc"    2019-08-01   "rt57"      6
  "abc"    2019-08-01   "rt58"      7
  "abc"    2019-08-02   "rt56"      2       True
  "abc"    2019-08-02   "rt57"      4
  "abc"    2019-08-02   "rt58"      7

(
p
| "get_key_tuple" >> beam.ParDo(lambda element: tuple(element["Id"], element["Date]))
| "group_by" >> beam.GroupByKey()
| "compare_and_add_status" >> beam.ParDo(compare_pos)
)

But I don't know how should I proceed for the function compare_pos()

It would be very helpful to get some ideas on how can I efficiently compare the position and create a new column to know the status considering I have a very large table and lots of ID's.

Body:
I might be interpreting OP wrong, but if the suggestion by @robertwb doesn't work, try perhaps grouping by the following instead:

| "Create k, v tuple" >> beam.Map(
                    lambda elem: ((elem["P_id"], elem["ID"]), [elem["Date"], elem["position"]]))
| "Group by key" >> beam.GroupByKey()

Which will output the following structure:

(('rt56', 'abc'), [['2019-08-01', 5], ['2019-08-02', 2]])
(('rt57', 'abc'), [['2019-08-01', 6], ['2019-08-02', 4]])
(('rt58', 'abc'), [['2019-08-01', 7], ['2019-08-02', 7]])

Which should allow you to compare each element in the resulting PCollection individually, instead of cross-comparing across elements in the PCollection. This should probably fit the execution model of Beam better if I'm correct.

This is based on my assumption that you want to check if the position for a given P_id has changed between two dates.


问:
warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
I'm trying to compile the below code using GCC compiler

```<code>class Class
{
public:

uInt16    temp;
const uInt32 function() const;

}

inline const uInt32 class::function() const
{
   return temp;
}
</code>```

And I'm getting the following compiler warning

warning: type qualifiers ignored on function return type [-Wignored-qualifiers]

Any ideas how I can fix this warning?

答:
The const type qualifier on the return type has no effect. Indeed, your function returns a copy of temp. It's the caller who will decide whether this value has to be const or not:

```<code>const auto val = Class{}.function(); // here, val is const
auto val = Class{}.function(); // here val is not const
</code>```

The const type qualifier makes sense if, for example, you want to return a reference to a class member. Compare:

```<code>int f() { /* ... */ } // return int
const int& f() { /* ... */ } // return const reference to an int
</code>```

Body:
I'm trying to compile the below code using GCC compiler

class Class
{
public:

uInt16    temp;
const uInt32 function() const;

}

inline const uInt32 class::function() const
{
   return temp;
}

And I'm getting the following compiler warning

warning: type qualifiers ignored on function return type [-Wignored-qualifiers]

Any ideas how I can fix this warning?

Body:
The const type qualifier on the return type has no effect. Indeed, your function returns a copy of temp. It's the caller who will decide whether this value has to be const or not:

const auto val = Class{}.function(); // here, val is const
auto val = Class{}.function(); // here val is not const

The const type qualifier makes sense if, for example, you want to return a reference to a class member. Compare:

int f() { /* ... */ } // return int
const int& f() { /* ... */ } // return const reference to an int


问:
I'm confused about space complexity
I'm a little confused about the space complexity.

```<code>int fn_sum(int a[], int n){
    int result =0;
    for(int i=0; i<n ; i++){
        result += a[i];
    }

    return result;
}
</code>```

In this case, is the space complexity  O(n) or O(1)?
I think it uses only result,i variables so it is O(1). What's the answer?

答:
Another way to calculate space complexity is to analyze whether the memory required by your code scales/increases according to the input given.

Your input is int a[] with size being n. The only variable you have declared is result.

No matter what the size of n is, result is declared only once. It does not depend on the size of your input n.

Hence you can conclude your space complexity to be O(1).

Title: I'm confused about space complexity

Body:
I'm a little confused about the space complexity.

int fn_sum(int a[], int n){
    int result =0;
    for(int i=0; i<n ; i++){
        result += a[i];
    }

    return result;
}

In this case, is the space complexity  O(n) or O(1)?
I think it uses only result,i variables so it is O(1). What's the answer?


问:
R: Changing an S4 object from within an S4 method
I have an S4 object that represents a recursive tree structure containing some data and other objects of the same class. I also have a recursive function to modify two slots in each node in the tree.  The function (call it "propagate()") does its thing properly when I do this:

```<code>> obj <- treeObj(4, 5)
> slotNames(obj)
[1] "x" "y" "listOfOtherTreeObjs"
> obj <- propagate(obj, 1, 4)
</code>```

I can write a function like this that takes an argument and populates the tree with that data, no problem.

What I want, though, is to be able to call propagate() from within a method of the root object:

```<code>setMethod("transform", signature="treeObj",
    definition=function(object, i, j) {
         object@x <- i;  object@y <- j;
         object <- propagate(object, i, j);
         ... (do some other stuff in the tree)
    })
</code>```

In this method, propagate() seems to function as it should, but its result does not seem to be assigned to the parent object in a way that is detectable within the transform() method definition. My questions:

I imagine this is to do with the call-by-value nature of R and that I cannot affect the value of the object that was used to invoke the transform function. Is that correct or am I just being stupid and this should work?

Is there any kind of R magic to get around this?  Some way to invoke the 'assign()' function to force the new definition of object to replace the current one?  Or something?

Is there a more R-ish way to build my recursive object to support this kind of thing?

Thanks in advance.

答:
There are two things you need to do to make this work:

1) presumably, the recursion doesn't go on for ever i.e. at some point an object won't contain a link to another object because it is at the bottom of the tree. So you need the possibility that the list of other tree objs is NULL. You do this with a class union:

```<code>setClassUnion("listOfOtherTreeObjsOrNULL",c("listOfOtherTreeObjs","NULL"))
</code>```

and then the correct class to use in the third slot of your object is this new class union.

2) when you are defining the method for transform it needs to look something like this:

```<code>function(object,i,j){
  ## do whatever you want with i and j
  if(is.null(object@listOfOtherTreeObjs)) return(object)
  else{
    object@listOfOTherTreeObjs <- lapply(object@listOfOtherTreeObjs,propagate)
    return(object)
  }
}
</code>```

The reason your changes didn't appear to take any effect is that you were not returning anything from your function, so you were only modifying copies of your objects which weren't being saved anywhere.

Body:
I have an S4 object that represents a recursive tree structure containing some data and other objects of the same class. I also have a recursive function to modify two slots in each node in the tree.  The function (call it "propagate()") does its thing properly when I do this:

> obj <- treeObj(4, 5)
> slotNames(obj)
[1] "x" "y" "listOfOtherTreeObjs"
> obj <- propagate(obj, 1, 4)

I can write a function like this that takes an argument and populates the tree with that data, no problem.

What I want, though, is to be able to call propagate() from within a method of the root object:

setMethod("transform", signature="treeObj",
    definition=function(object, i, j) {
         object@x <- i;  object@y <- j;
         object <- propagate(object, i, j);
         ... (do some other stuff in the tree)
    })

In this method, propagate() seems to function as it should, but its result does not seem to be assigned to the parent object in a way that is detectable within the transform() method definition. My questions:

I imagine this is to do with the call-by-value nature of R and that I cannot affect the value of the object that was used to invoke the transform function. Is that correct or am I just being stupid and this should work?

Is there any kind of R magic to get around this?  Some way to invoke the 'assign()' function to force the new definition of object to replace the current one?  Or something?

Is there a more R-ish way to build my recursive object to support this kind of thing?

Thanks in advance.

Body:
There are two things you need to do to make this work:

1) presumably, the recursion doesn't go on for ever i.e. at some point an object won't contain a link to another object because it is at the bottom of the tree. So you need the possibility that the list of other tree objs is NULL. You do this with a class union:

setClassUnion("listOfOtherTreeObjsOrNULL",c("listOfOtherTreeObjs","NULL"))

and then the correct class to use in the third slot of your object is this new class union.

2) when you are defining the method for transform it needs to look something like this:

function(object,i,j){
  ## do whatever you want with i and j
  if(is.null(object@listOfOtherTreeObjs)) return(object)
  else{
    object@listOfOTherTreeObjs <- lapply(object@listOfOtherTreeObjs,propagate)
    return(object)
  }
}

The reason your changes didn't appear to take any effect is that you were not returning anything from your function, so you were only modifying copies of your objects which weren't being saved anywhere.


问:
Saving Matplotlib Output to Blob Storage on Databricks
I'm trying to write matplotlib figures to the Azure blob storage using the method provided here:
Saving Matplotlib Output to DBFS on Databricks.

However, when I replace the path in the code with

```<code>path = 'wasbs://test@someblob.blob.core.windows.net/'
</code>```

I get this error

[Errno 2] No such file or directory: 'wasbs://test@someblob.blob.core.windows.net/'

I don't understand the problem...

答:
This is what I also came up with so far. In order to reload the image from blob and display it as png in a databricks notebook again I use the following code:</p>

```<code>blob_path = ...
dbfs_path = ...
dbutils.fs.cp( blob_path, dbfs_path )

with open( dbfs_path, "rb" ) as f:
  im = BytesIO( f.read() )

img = mpimg.imread( im )
imgplot = plt.imshow( img )
display( imgplot.figure )
</code>```

Body:
I'm trying to write matplotlib figures to the Azure blob storage using the method provided here:
Saving Matplotlib Output to DBFS on Databricks.

However, when I replace the path in the code with

path = 'wasbs://test@someblob.blob.core.windows.net/'

I get this error

[Errno 2] No such file or directory: 'wasbs://test@someblob.blob.core.windows.net/'

I don't understand the problem...

Body:
This is what I also came up with so far. In order to reload the image from blob and display it as png in a databricks notebook again I use the following code:

blob_path = ...
dbfs_path = ...
dbutils.fs.cp( blob_path, dbfs_path )

with open( dbfs_path, "rb" ) as f:
  im = BytesIO( f.read() )

img = mpimg.imread( im )
imgplot = plt.imshow( img )
display( imgplot.figure )


问:
How to assert equal 2 lists which contain dicts?
How to assert equal 2 lists which contain dicts?

```<code>List1 = [{'key1':'value1'}, {'key2':'value2'}, {'key3':'value3'}]
List2 = [{'key1':'value1'}, {'key2':'value2'}, {'key3':'value4'}]
</code>```

I read that assertEqual / assertListEqual need that the list items be in the same order. Where as assertCountEqual does not consider order. This is fine if the items of the list are simple string/init value.

However, there is no clarity on whether order is important for list items also? For example - if list contains a dict or tuple item, dict is unordered so does assertEqual not check order of dict inside list? What about tuple inside list? Where can I find how this works?

答:
assertEquals simply delegates to ==, which can be overridden by each type.

However, there is no clarity on whether order is important for list items also?

That's because it's delegated to the list items themselves. list.__eq__ simply checks if both lists have the same length, and if they have the same items at the same place using ==. How == behaves for each item is the item's decision.

dict is unordered so does assertEqual not check order of dict inside list?

Correct. dict equality simply checks that dicts have the same (key, value) pairs, it doesn't care about order. Same for set equality.

What about tuple inside list?

tuple equality is the same as list equality, it does care about order.

Where can I find how this works?

The documentation of each individual type I'd guess.

Body:
How to assert equal 2 lists which contain dicts?

List1 = [{'key1':'value1'}, {'key2':'value2'}, {'key3':'value3'}]
List2 = [{'key1':'value1'}, {'key2':'value2'}, {'key3':'value4'}]

I read that assertEqual / assertListEqual need that the list items be in the same order. Where as assertCountEqual does not consider order. This is fine if the items of the list are simple string/init value.

However, there is no clarity on whether order is important for list items also? For example - if list contains a dict or tuple item, dict is unordered so does assertEqual not check order of dict inside list? What about tuple inside list? Where can I find how this works?


问:
Displaying DateTime in Xamarin.Forms with SQLite
I am creating a Xamarin.Forms application for a school project. This project displays a list of school terms (6-month blocks of time) with the start and end dates. The list of the terms displays without issues, but the dates do not appear as expected: all dates are 01/01/0001. The terms table is:

```<code>    Id          TermName    StartDate   EndDate
----------  ----------  ----------  ----------
1           Term 1      2020-01-01  2020-06-30
2           Term 2      2020-07-01  2020-12-31
3           Term 3      2021-01-01  2021-06-30
4           Term 4      2021-07-01  2021-12-31
5           Term 5      2022-01-01  2022-06-30
6           Term 6      2022-07-01  2022-12-31
</code>```

Since SQLite doesn't have a specific DATETIME data type, I'm storing the StartDate and EndDate as a TEXT data type, but the terms.cs model file uses the DateTime datatype. Placing a breakpoint at the loading of the list of terms shows:
Breakpoint data.

Terms.cs file:

```<code>[Table("Terms")]
    public class Terms
    {
        public int Term { get; set; }
        public string TermName { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }
</code>```

MainPage.xaml.cs file:

```<code>protected override void OnAppearing()
        {
            base.OnAppearing();
            using (SQLiteConnection conn = new SQLiteConnection(App.DBLocation))
            {
                conn.CreateTable<Terms>();
                var terms = conn.Table<Terms>().ToList();
                TermsListView.ItemsSource = terms;
                TermsListView.SelectedItem = null;
            }
        }
</code>```

How do I get the StartDate and EndDate from my table to show up in my ListView correctly?

答:
Try this code in ListView  </p>

```<code>     <Label
                                        FontSize="18"
                                        HorizontalOptions="Center"
                                        HorizontalTextAlignment="Center"
                                        Text="{Binding StartDate, StringFormat='{0:dd/MM/yyyy}'}" />
<Label
                                        FontSize="18"
                                        HorizontalOptions="Center"
                                        HorizontalTextAlignment="Center"
                                        Text="{Binding EndDate, StringFormat='{0:dd/MM/yyyy}'}" />
</code>```

Body:
I am creating a Xamarin.Forms application for a school project. This project displays a list of school terms (6-month blocks of time) with the start and end dates. The list of the terms displays without issues, but the dates do not appear as expected: all dates are 01/01/0001. The terms table is:

    Id          TermName    StartDate   EndDate
----------  ----------  ----------  ----------
1           Term 1      2020-01-01  2020-06-30
2           Term 2      2020-07-01  2020-12-31
3           Term 3      2021-01-01  2021-06-30
4           Term 4      2021-07-01  2021-12-31
5           Term 5      2022-01-01  2022-06-30
6           Term 6      2022-07-01  2022-12-31

Since SQLite doesn't have a specific DATETIME data type, I'm storing the StartDate and EndDate as a TEXT data type, but the terms.cs model file uses the DateTime datatype. Placing a breakpoint at the loading of the list of terms shows:
Breakpoint data.

Terms.cs file:

[Table("Terms")]
    public class Terms
    {
        public int Term { get; set; }
        public string TermName { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }

MainPage.xaml.cs file:

protected override void OnAppearing()
        {
            base.OnAppearing();
            using (SQLiteConnection conn = new SQLiteConnection(App.DBLocation))
            {
                conn.CreateTable<Terms>();
                var terms = conn.Table<Terms>().ToList();
                TermsListView.ItemsSource = terms;
                TermsListView.SelectedItem = null;
            }
        }

How do I get the StartDate and EndDate from my table to show up in my ListView correctly?

Body:
Try this code in ListView

     <Label
                                        FontSize="18"
                                        HorizontalOptions="Center"
                                        HorizontalTextAlignment="Center"
                                        Text="{Binding StartDate, StringFormat='{0:dd/MM/yyyy}'}" />
<Label
                                        FontSize="18"
                                        HorizontalOptions="Center"
                                        HorizontalTextAlignment="Center"
                                        Text="{Binding EndDate, StringFormat='{0:dd/MM/yyyy}'}" />


问:
Can't use LOOP PostgreSQL
I'm facing an issue from yesterday and I can't understand why my SQL is not working..
This may be a simple error since i'm a beginner in SQL but I can't find where it is.

Here is what I try to do:

```<code>CREATE FUNCTION test() RETURN integer AS $$
BEGIN
    FOR i IN 1..5 LOOP
    SELECT * from result WHERE id=i;
end loop;
    RETURN 1;
END;
$$ LANGUAGE plpgsql;
</code>```

This is just a simple loop as I can find in the documentation but I have this error:

```<code>Error report -
ERROR: syntax error at or near "RETURN" (this is the first RETURN statement in the function)
</code>```

The database is in PostgreSQL and the version is 9.4.5

Why it's not working ?

答:
There are several problems, apart from the fact that the function isn't doing anything useful:

It must be RETURNS integer, not RETURN integer.

That't what causes the error.

The SELECT has no destination. Either add an INTO clause or discard the result with

```<code>PERFORM * from result WHERE id=i;
</code>```

You should indent the code correctly, so that you can read and understand it.

Title: Can't use LOOP PostgreSQL

Body:
I'm facing an issue from yesterday and I can't understand why my SQL is not working..
This may be a simple error since i'm a beginner in SQL but I can't find where it is.

Here is what I try to do:

CREATE FUNCTION test() RETURN integer AS $$
BEGIN
    FOR i IN 1..5 LOOP
    SELECT * from result WHERE id=i;
end loop;
    RETURN 1;
END;
$$ LANGUAGE plpgsql;

This is just a simple loop as I can find in the documentation but I have this error:

Error report -
ERROR: syntax error at or near "RETURN" (this is the first RETURN statement in the function)

The database is in PostgreSQL and the version is 9.4.5

Why it's not working ?

Body:
There are several problems, apart from the fact that the function isn't doing anything useful:

It must be RETURNS integer, not RETURN integer.

That't what causes the error.

The SELECT has no destination. Either add an INTO clause or discard the result with

PERFORM * from result WHERE id=i;

You should indent the code correctly, so that you can read and understand it.