问:
Elasticsearch process memory locking failed
I have set boostrap.memory_lock=true
Updated /etc/security/limits.conf added memlock unlimited for elastic search user

My elastic search was running fine for many months. Suddenly it failed 1 day back. In logs I can see below error and process never starts

ERROR: bootstrap checks failed
memory locking requested for elasticsearch process but memory is not locked

I hit ulimit -as and I can see max locked memory set to unlimited. What is going wrong here? I have been trying for hours but all in vain. Please help.

OS is RHEL 7.2
Elasticsearch 5.1.2

ulimit -as output

```<code>core file size        (blocks -c) 0
data seg size         (kbytes -d) unlimited
scheduling policy            (-e) 0
file size            (blocks, -f) unlimited
pending signals              (-i) 83552
max locked memory    (kbytes, -l) unlimited
max memory size      (kbytes, -m) unlimited
open files                   (-n) 65536
pipe size         (512 bytes, -q) 8
POSIX message queues   (bytes,-q) 819200
real-time priority           (-r) 0
stack size            kbytes, -s) 8192
cpu time             seconds, -t) unlimited
max user processes           (-u) 4096
virtual memory       (kbytes, -v) unlimited
file locks                   (-x) unlimited
</code>```

答:
check for the actual limit when the process is running (albeit short) with:

```<code>cat /proc/<pid>/limits
</code>```

You will find lines similar to this:

```<code>Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
<truncated>
</code>```

Then depend on the runner or container (in my case it was supervisord's minfds value), you can lift the actual limitation configuration.

I hope it gives a little hint for more general cases.

Body:
I have set boostrap.memory_lock=true
Updated /etc/security/limits.conf added memlock unlimited for elastic search user

My elastic search was running fine for many months. Suddenly it failed 1 day back. In logs I can see below error and process never starts

ERROR: bootstrap checks failed
memory locking requested for elasticsearch process but memory is not locked

I hit ulimit -as and I can see max locked memory set to unlimited. What is going wrong here? I have been trying for hours but all in vain. Please help.

OS is RHEL 7.2
Elasticsearch 5.1.2

ulimit -as output

core file size        (blocks -c) 0
data seg size         (kbytes -d) unlimited
scheduling policy            (-e) 0
file size            (blocks, -f) unlimited
pending signals              (-i) 83552
max locked memory    (kbytes, -l) unlimited
max memory size      (kbytes, -m) unlimited
open files                   (-n) 65536
pipe size         (512 bytes, -q) 8
POSIX message queues   (bytes,-q) 819200
real-time priority           (-r) 0
stack size            kbytes, -s) 8192
cpu time             seconds, -t) unlimited
max user processes           (-u) 4096
virtual memory       (kbytes, -v) unlimited
file locks                   (-x) unlimited

Body:
check for the actual limit when the process is running (albeit short) with:

cat /proc/<pid>/limits

You will find lines similar to this:

Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
<truncated>

Then depend on the runner or container (in my case it was supervisord's minfds value), you can lift the actual limitation configuration.

I hope it gives a little hint for more general cases.


来源: stackexchange

问:
Not able to understand what this C function does
I have seen this piece of code several times but am unable to understand what it does

```<code>inline char nc()
{
    static char buf[100000], *L = buf, *R = buf;
    return L == R && (R = (L = buf) + fread(buf, 1, 100000, stdin), L == R) ? EOF : *L++;
}
</code>```

The condition L==R should always be true , right? since both the pointers point to the same variable. I cant understand what the second part of the condition checks. Could someone please help me out?

答:
This function is essentially a fancy getchar() that buffers the input. The static declaration part is really run once.
Let's break it down. buf is the buffer. L and R probably stand for left and right. So they point to the beginning and ending of the buffer. If L == R is false, we still have something in the buffer, so the second condition is not evaluated, and we get a character from the buffer, and increase the left pointer. If L == R is true, the second part is evaluated which tries to fill the buffer with L pointing to the very beginning and R pointing to L plus the number of characters read from stdin. The comma operator means the first part is ignored and we evaluate L == R again, which is false if we read some characters, so we return the first one, but is true if we didn't read anything, so we return EOF which is really not guaranteed to be representable with a char. The return type should probably be an int.

Here is a more readable version (untested):

```<code>inline int nc() // notice the return type
{
    static char buf[100000];      // run only once
    static char *beg = buf; // L  // run only once
    static char *end = buf; // R  // run only once

    if (beg != end)  // If buffer is not empty
    {
      return *beg++; // return a character
    }
    beg = buf;
    // if the buffer is empty, try to read into it
    end = buf + fread(buf, 1, 100000, stdin);
    if (beg != end)
    {
      return *beg++;
    }
    // If reading failed, return EOF
    return EOF;
}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have seen this piece of code several times but am unable to understand what it does

inline char nc()
{
    static char buf[100000], *L = buf, *R = buf;
    return L == R && (R = (L = buf) + fread(buf, 1, 100000, stdin), L == R) ? EOF : *L++;
}

The condition L==R should always be true , right? since both the pointers point to the same variable. I cant understand what the second part of the condition checks. Could someone please help me out?

Body:
This function is essentially a fancy getchar() that buffers the input. The static declaration part is really run once.
Let's break it down. buf is the buffer. L and R probably stand for left and right. So they point to the beginning and ending of the buffer. If L == R is false, we still have something in the buffer, so the second condition is not evaluated, and we get a character from the buffer, and increase the left pointer. If L == R is true, the second part is evaluated which tries to fill the buffer with L pointing to the very beginning and R pointing to L plus the number of characters read from stdin. The comma operator means the first part is ignored and we evaluate L == R again, which is false if we read some characters, so we return the first one, but is true if we didn't read anything, so we return EOF which is really not guaranteed to be representable with a char. The return type should probably be an int.

Here is a more readable version (untested):

inline int nc() // notice the return type
{
    static char buf[100000];      // run only once
    static char *beg = buf; // L  // run only once
    static char *end = buf; // R  // run only once

    if (beg != end)  // If buffer is not empty
    {
      return *beg++; // return a character
    }
    beg = buf;
    // if the buffer is empty, try to read into it
    end = buf + fread(buf, 1, 100000, stdin);
    if (beg != end)
    {
      return *beg++;
    }
    // If reading failed, return EOF
    return EOF;
}


问:
Disable default sign in prompt while using ntlm passthrough technique in express-ntlm
I am using following code in express-ntlm to get workstation details in my node.js app:

```<code>var express = require('express'),
ntlm = require('express-ntlm');

var app = express();
app.use(ntlm());

app.all('*', function(request, response) {
console.log(request.ntlm.Workstation);
});

app.listen(3000);
</code>```

When I hit localhost:3000 it pops up sign in prompt asking username and password. This is due to http setheader('WWW-Authenticate','NTLM') in the express-ntlm package code.
How do I disable this sign in prompt and still be able to get workstation details?

P.S : (I tried disabling it through express-ntlm code, though it doesn't do it. There is some callback that I am missing, to reproduce exact events, which are triggered when you click sign in button on the prompt.
Also I am not trying to put any custom sign in page.)

答:
This is not possible. The WWW-Authenticate header tells the browser to use NTLM for authentication. If the browser supports NTLM natively, you won't notice this process, but if not, there will be a prompt to enter credentials. If you remove the header, the authentication won't happen and therefore you will not receive the required information.

Also, using ntlm() without a domain controller is not clever, as it disables authentication checks and therefore any user can provide any details they want, without any verification.

Body:
I am using following code in express-ntlm to get workstation details in my node.js app:

var express = require('express'),
ntlm = require('express-ntlm');

var app = express();
app.use(ntlm());

app.all('*', function(request, response) {
console.log(request.ntlm.Workstation);
});

app.listen(3000);

When I hit localhost:3000 it pops up sign in prompt asking username and password. This is due to http setheader('WWW-Authenticate','NTLM') in the express-ntlm package code.
How do I disable this sign in prompt and still be able to get workstation details?

P.S : (I tried disabling it through express-ntlm code, though it doesn't do it. There is some callback that I am missing, to reproduce exact events, which are triggered when you click sign in button on the prompt.
Also I am not trying to put any custom sign in page.)


Title: How to get ALL combinations of array elements in Ruby?

Body:
If I have an array:

%w(a b c d e)
=> ["a","b","c","d","e"]

I can get some combinations with

irb(main):071:0> %w(a b c d e).combination(3).to_a
=> [["a", "b", "c"], ["a", "b", "d"], ["a", "b", "e"], ["a", "c", "d"], ["a", "c", "e"], ["a", "d", "e"], ["b", "c", "d"], ["b", "c", "e"], ["b", "d", "e"], ["c", "d", "e"]]

However that is not ALL the combinations, just the unique ones, e.g. ["e", "a", "b"] is missing

When I similarly try with s smaller array I only get one result:

irb(main):059:0> %w(a b c).combination(3).to_a
=> [["a", "b", "c"]]

How can I get all 6 combinations, i.e. for ['a', 'b', 'c'] I want to get

[['a','b','c'], ['a','c','b'], ['b', 'a', 'c'], ['b', 'c', 'a'], ['c', 'a', 'b'], ['c', 'b', 'a']

Similarly for [1,2,3,4] if I want all the 3 digit combo I should get

irb(main):074:0> [[1,2,3],[1,2,4],[1,3,2],[1,3,4],[1,4,2],[1,4,3],  [2,1,3],[2,1,4],[2,3,4],[2,3,1],[2,4,1],[2,4,2],  [3,1,2],[3,1,4],[3,2,3],[3,2,4],[3,4,2],[3,4,1]]

?

Body:
You are looking for permutation instead of combination.

In combinations, we do not care about the order of the elements, and only care about the presence of all the elements in the set.

[1,2,3,4].permutation(3).to_a
#=> [[1, 2, 3], [1, 2, 4], [1, 3, 2], [1, 3, 4], [1, 4, 2], [1, 4, 3], [2, 1, 3], [2, 1, 4], [2, 3, 1], [2, 3, 4], [2, 4, 1], [2, 4, 3], [3, 1, 2], [3, 1, 4], [3, 2, 1], [3, 2, 4], [3, 4, 1], [3, 4, 2], [4, 1, 2], [4, 1, 3], [4, 2, 1], [4, 2, 3], [4, 3, 1], [4, 3, 2]]


问:
Java thread doubt
Consider this program:

```<code>public class test {
    public static void main(String [] args){
        Runnable r = new Runnable() {
            public void run() {
                System.out.print("foo");
            }
        };
        Thread t = new Thread(r) {
            public void run() {
                System.out.print("bar");
            }
        };
        t.start();
    }
}
</code>```

On running the output is

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

I would like to know why is that so.

My understanding:

We instantiate an anonymous inner class that implements Runnable by overriding run method. And assign it to r.

Next we pass this runnable to the Thread class constructor. But we also create a new anonymous inner class that extends Thread by overriding run.

So we have two run methods now and the 2nd will take preference over the 1st.

I'm very confused please correct me if I'm wrong.

Also are such crazy things used in real world Java programming? (My Prof says yes and thats what keeps us going :D).

答:
You are overriding the default behaviour for a thread when you override its run() method.  In this way you control the order and whether r is run at all.

```<code>public void run() { // ignores "r"
    System.out.print("bar");
}
</code>```

or

```<code>public void run() {
    super.run(); // runs "r" first.
    System.out.print("bar");
}
</code>```

or

```<code>public void run() {
    System.out.print("bar");
    super.run(); // runs "r" second.
}
</code>```

or

```<code>public void run() {
    super.run(); // runs "r" first.
    System.out.print("bar");
    super.run(); // and runs "r" second.
}
</code>```

or

```<code>public void run() {
    r.run(); // runs "r" first.
    System.out.print("bar");
    r.run(); // and runs "r" second.
}
</code>```

ContentLicense: CC BY-SA 3.0

Title: Java thread doubt

Body:
Consider this program:

public class test {
    public static void main(String [] args){
        Runnable r = new Runnable() {
            public void run() {
                System.out.print("foo");
            }
        };
        Thread t = new Thread(r) {
            public void run() {
                System.out.print("bar");
            }
        };
        t.start();
    }
}

On running the output is

bar

I would like to know why is that so.

My understanding:

We instantiate an anonymous inner class that implements Runnable by overriding run method. And assign it to r.

Next we pass this runnable to the Thread class constructor. But we also create a new anonymous inner class that extends Thread by overriding run.

So we have two run methods now and the 2nd will take preference over the 1st.

I'm very confused please correct me if I'm wrong.

Also are such crazy things used in real world Java programming? (My Prof says yes and thats what keeps us going :D).

Body:
You are overriding the default behaviour for a thread when you override its run() method.  In this way you control the order and whether r is run at all.

public void run() { // ignores "r"
    System.out.print("bar");
}

or

public void run() {
    super.run(); // runs "r" first.
    System.out.print("bar");
}

or

public void run() {
    System.out.print("bar");
    super.run(); // runs "r" second.
}

or

public void run() {
    super.run(); // runs "r" first.
    System.out.print("bar");
    super.run(); // and runs "r" second.
}

or

public void run() {
    r.run(); // runs "r" first.
    System.out.print("bar");
    r.run(); // and runs "r" second.
}


问:
How to let spark cluster fetch package jars from local path rather than from master?
I found that every time I launch an application in my spark standalone cluster with external packages, say pyspark --master=spark://master:7077 --packages Azure:mmlspark:0.17, executors are always trying to fetch package jars from the driver. Here is the log:

```<code>2019-05-23 21:14:56 INFO  Executor:54 - Fetching spark://Master:2653/files/com.microsoft.cntk_cntk-2.4.jar with timestamp 1558616430055
2019-05-23 21:14:56 INFO  TransportClientFactory:267 - Successfully created connection to Master/192.168.100.2:2653 after 23 ms (0 ms spent in bootstraps)
2019-05-23 21:14:56 INFO  Utils:54 - Fetching spark://Master:2653/files/com.microsoft.cntk_cntk-2.4.jar to /tmp/spark-0a60d982-0082-4d37-aea1-e1c0b21ee2be/executor-c9632fd2-29fc-429c-bdfb-31d870ed19e8/spark-15805ad8-ab00-41b3-b466-b0e8e95a3f56/fetchFileTemp5196357990337888981.tmp
</code>```

Something like this repeats in the logs of the executors. The size of the package is quite big, so the process takes a lot of time.

I have tried using --jars argument of pyspark to upload required jars to each executor. Executors did fetch them from the local path, but I couldn't import the package in the shell.

So how to solve the problem? What should I do to let the executors fetch the package from the local path? Or maybe from HDFS?

答: We can copy the jar to all nodes and add the path to the jar in spark.executor.extraClassPath config param, so that the jars are available in executor's classpath.

Body:
I found that every time I launch an application in my spark standalone cluster with external packages, say pyspark --master=spark://master:7077 --packages Azure:mmlspark:0.17, executors are always trying to fetch package jars from the driver. Here is the log:

2019-05-23 21:14:56 INFO  Executor:54 - Fetching spark://Master:2653/files/com.microsoft.cntk_cntk-2.4.jar with timestamp 1558616430055
2019-05-23 21:14:56 INFO  TransportClientFactory:267 - Successfully created connection to Master/192.168.100.2:2653 after 23 ms (0 ms spent in bootstraps)
2019-05-23 21:14:56 INFO  Utils:54 - Fetching spark://Master:2653/files/com.microsoft.cntk_cntk-2.4.jar to /tmp/spark-0a60d982-0082-4d37-aea1-e1c0b21ee2be/executor-c9632fd2-29fc-429c-bdfb-31d870ed19e8/spark-15805ad8-ab00-41b3-b466-b0e8e95a3f56/fetchFileTemp5196357990337888981.tmp

Something like this repeats in the logs of the executors. The size of the package is quite big, so the process takes a lot of time.

I have tried using --jars argument of pyspark to upload required jars to each executor. Executors did fetch them from the local path, but I couldn't import the package in the shell.

So how to solve the problem? What should I do to let the executors fetch the package from the local path? Or maybe from HDFS?


问:
How to center two markers with react native map view
I got two markers at two different coordinates.

How do people normally center two markers so that you can see two marker at the same time on map, regardless how far away they are.

```<code><MapView
ref={ (map)=> this.map = map}
initialRegion={this.state.init}
style={css.map}>
    { this.state.marker1 !==0 && <MapView.Marker
        coordinate={{
            'latitude':this.state.marker1.lat,
            'longitude':this.state.marker1.lng}}
        />}
    { this.state.marker2 !==0 && <MapView.Marker
        coordinate={{
            'latitude':this.state.marker2.lat,
            'longitude':this.state.marker2.lng}}
        />}
</MapView>
</code>```

答:
You can use the fitToSuppliedMarkers or fitToCoordinates method of the MapView.
https://github.com/react-native-community/react-native-maps/blob/master/docs/mapview.md

Body:
I got two markers at two different coordinates.

How do people normally center two markers so that you can see two marker at the same time on map, regardless how far away they are.

<MapView
ref={ (map)=> this.map = map}
initialRegion={this.state.init}
style={css.map}>
    { this.state.marker1 !==0 && <MapView.Marker
        coordinate={{
            'latitude':this.state.marker1.lat,
            'longitude':this.state.marker1.lng}}
        />}
    { this.state.marker2 !==0 && <MapView.Marker
        coordinate={{
            'latitude':this.state.marker2.lat,
            'longitude':this.state.marker2.lng}}
        />}
</MapView>


答:
This is basically equivalent of:</p>

```<code>char buf[100000];
char* L = buf;
char* R = buf;

char non_fancy_getchar()
{
    if (L == R) {
        /* reset pointers and try to read stdin again */
        L = buf;
        R = L + fread(buf, 1, sizeof(buf), stdin);
    }

    /* return next char or EOF */
    return (L == R) ? EOF : *L++;
}
</code>```

Title: Not able to understand what this C function does

Body:
This is basically equivalent of:

char buf[100000];
char* L = buf;
char* R = buf;

char non_fancy_getchar()
{
    if (L == R) {
        /* reset pointers and try to read stdin again */
        L = buf;
        R = L + fread(buf, 1, sizeof(buf), stdin);
    }

    /* return next char or EOF */
    return (L == R) ? EOF : *L++;
}


问:
How to normalize a relative path using pathlib
I'm trying to use relative paths in Python, and I want to put my csv files in a separate folder from my python code.

My python program is in the following folder:

```<code>G:\projects\code
</code>```

I want to read this file which is one level up:

```<code>G:\projects\data\sales.csv
</code>```

How do I specify a path using pathlib that is one level up from my current working folder? I don't want to change the current working folder.

I tried this:

```<code>from pathlib import Path
file = Path.cwd() /'..'/'data'/'sales.csv'
</code>```

But now the 'file' variable equals this:

```<code>'G:/projects/code/../data/sales.csv'
</code>```

I read through the docs and either it isn't explained there or I'm just missing it.

答:
```<code>print(
    Path(__file__).parent,  # the folder
    Path(__file__).parent.parent,  # the folder's parent
    sep='\n'
)

print(
    Path(
        Path(__file__).parent.parent, 'hello.py'
    )
)
</code>```

results in

```<code>C:\Users\isik\Desktop\Python\MessAround\project\module
C:\Users\isik\Desktop\Python\MessAround\project
C:\Users\isik\Desktop\Python\MessAround\project\hello.py
</code>```

with this file structure

```<code>-project
    -module
        -__init__.py
    -hello.py
    -__init__.py
</code>```

while the code is located inside project.module.__init__.py

Body:
I'm trying to use relative paths in Python, and I want to put my csv files in a separate folder from my python code.

My python program is in the following folder:

G:\projects\code

I want to read this file which is one level up:

G:\projects\data\sales.csv

How do I specify a path using pathlib that is one level up from my current working folder? I don't want to change the current working folder.

I tried this:

from pathlib import Path
file = Path.cwd() /'..'/'data'/'sales.csv'

But now the 'file' variable equals this:

'G:/projects/code/../data/sales.csv'

I read through the docs and either it isn't explained there or I'm just missing it.

Body:
print(
    Path(__file__).parent,  # the folder
    Path(__file__).parent.parent,  # the folder's parent
    sep='\n'
)

print(
    Path(
        Path(__file__).parent.parent, 'hello.py'
    )
)

results in

C:\Users\isik\Desktop\Python\MessAround\project\module
C:\Users\isik\Desktop\Python\MessAround\project
C:\Users\isik\Desktop\Python\MessAround\project\hello.py

with this file structure

-project
    -module
        -__init__.py
    -hello.py
    -__init__.py

while the code is located inside project.module.__init__.py


问:
is there any convenient way to get a index of sub section in a page?
it is convenient to use "index-x" to quick locate a sub section in a page.

for instance

```<code>https://docs.python.org/3/library/re.html#index-2
</code>```

gives 3rd sub-section in this page.

when i want to share the location of a sub-section to others, how to get the index in a convenient way?

for instance, how to get the index of {m,n} sub-section without counting from index-0?

答:
You're looking for index-7.

You can download the HTML of the page and get all the possible values of index-something with the following code:

```<code>import re
import requests
from bs4 import BeautifulSoup

r = requests.get('https://docs.python.org/3/library/re.html')
soup = BeautifulSoup(r.content.decode())

result = [t['id'] for t in soup.find_all(id=re.compile('index-\d+'))]

print(result)
</code>```

Output:

```<code>['index-0', 'index-1', 'index-2', 'index-3', 'index-4', 'index-5', 'index-6', 'index-7', 'index-8', 'index-9', 'index-10', 'index-11', 'index-12', 'index-13', 'index-14', 'index-15', 'index-16', 'index-17', 'index-18', 'index-19', 'index-20', 'index-21', 'index-22', 'index-23', 'index-24', 'index-25', 'index-26', 'index-27', 'index-28', 'index-29', 'index-30', 'index-31', 'index-32', 'index-33', 'index-34', 'index-35', 'index-36', 'index-37', 'index-38']
</code>```

The t objects in the list comprehension contain the HTML of the tags whose id matches the regex.

Body:
it is convenient to use "index-x" to quick locate a sub section in a page.

for instance

https://docs.python.org/3/library/re.html#index-2

gives 3rd sub-section in this page.

when i want to share the location of a sub-section to others, how to get the index in a convenient way?

for instance, how to get the index of {m,n} sub-section without counting from index-0?

Body:
You're looking for index-7.

You can download the HTML of the page and get all the possible values of index-something with the following code:

import re
import requests
from bs4 import BeautifulSoup

r = requests.get('https://docs.python.org/3/library/re.html')
soup = BeautifulSoup(r.content.decode())

result = [t['id'] for t in soup.find_all(id=re.compile('index-\d+'))]

print(result)

Output:

['index-0', 'index-1', 'index-2', 'index-3', 'index-4', 'index-5', 'index-6', 'index-7', 'index-8', 'index-9', 'index-10', 'index-11', 'index-12', 'index-13', 'index-14', 'index-15', 'index-16', 'index-17', 'index-18', 'index-19', 'index-20', 'index-21', 'index-22', 'index-23', 'index-24', 'index-25', 'index-26', 'index-27', 'index-28', 'index-29', 'index-30', 'index-31', 'index-32', 'index-33', 'index-34', 'index-35', 'index-36', 'index-37', 'index-38']

The t objects in the list comprehension contain the HTML of the tags whose id matches the regex.


问:
how to get doxygen to see documentation of preprocessor macro in .F90 file?
I am working with the ParallelIO library, a free software library for high performance computing (HPC) I/O with a netCDF-like API.

In some fortran code I have a file called piolib_mod.F90 that starts:

```<code>!>
!! @file
!! @brief Initialization Routines for PIO
#define __PIO_FILE__ "piolib_mod.F90"
</code>```

This produces a doxygen warning:

```<code>/home/ed/tmp/ParallelIO/src/flib/piolib_mod.F90:4: warning: Member __PIO_FILE__ (macro definition) of file piolib_mod.F90 is not documented.
</code>```

But no matter what I do, I can't doxygen to accept my definition of the documentation for this macro. I have tried:

```<code>!> for debugging
#define __PIO_FILE__ "piolib_mod.f90"
</code>```

also:

```<code>!> @def __PIO_FILE__ for debugging
#define __PIO_FILE__ "piolib_mod.f90"
</code>```

I have tried to exclude this line from doxygen processing:

```<code>!> @cond exclude
#define __PIO_FILE__ 'piodarray'
!> @endcond
</code>```

But that does not work either.

Doxygen may be confused by the concept of a pre-processor macro in a Fortran file, but that's just the 21st Century for you, expensive supercomputers and programming languages from the 1960s.

How do I document this pre-processor define with doxygen?

答:
The way I accomplished this was to pre-process the *.F90 files into *.f90 files, and then use the *.f90 files for Doxygen.

Here's what did the trick in Makefile.am:

```<code># Doxygen does not cope well with pre-processor use in Fortran. So
# create .f90 files from .F90 files by running the C
# pre-processor. These will only be used by doxygen when --enable-docs
# is used at configure.
if BUILD_DOCS
BUILT_SOURCES += piodarray.f90 piolib_mod.f90 pionfatt_mod.f90 pionfget_mod.f90 pionfput_mod.f90 pionfatt_mod_2.f90 pionfget_mod_2.f90
piodarray.f90: piodarray.F90
    $(CC) -E $< > $@
piolib_mod.f90: piolib_mod.F90
    $(CC) -E $< > $@
pionfatt_mod.f90: pionfatt_mod.F90
    $(CC) -E $< > $@
pionfget_mod.f90: pionfget_mod.F90
    $(CC) -E $< > $@
pionfput_mod.f90: pionfput_mod.F90
    $(CC) -E $< > $@
</code>```

In my configure.ac I set up Doxygen to read the Fortran files I need:

```<code># If building docs, process Doxyfile.in into Doxyfile.
if test "x$enable_docs" = xyes; then
   AC_SUBST([CMAKE_CURRENT_SOURCE_DIR], ["."])
   AC_SUBST([CMAKE_BINARY_DIR], [".."])
   if test "x$enable_fortran" = xno; then
      AC_MSG_ERROR([--enable-fortran is required for documentation builds.])
   fi
   AC_SUBST([FORTRAN_SRC_FILES], ["../src/flib/piodarray.f90  ../src/flib/pio.F90  ../src/flib/pio_kinds.F90  ../src/flib/piolib_mod.f90  ../src/flib/pionfatt_mod_2.f90  ../src/flib/pio_nf.F90  ../src/flib/pionfget_mod_2.f90  ../src/flib/pionfput_mod.f90  ../src/flib/pio_support.F90  ../src/flib/pio_types.F90"])
   if test "x$enable_developer_docs" = xyes; then
      AC_SUBST([C_SRC_FILES], ["../src/clib"])
   else
      AC_SUBST([C_SRC_FILES], ["../src/clib/pio_nc.c ../src/clib/pio_nc4.c ../src/clib/pio_darray.c ../src/clib/pio_get_nc.c ../src/clib/pio_put_nc.c ../src/clib/pioc_support.c ../src/clib/pioc.c ../src/clib/pio_file.c ../src/clib/pio.h"])
   fi
   AC_CONFIG_FILES([doc/Doxyfile])
fi
</code>```

This all works and now I have a clean doxygen build with no warnings. ;-)

Body:
I am working with the ParallelIO library, a free software library for high performance computing (HPC) I/O with a netCDF-like API.

In some fortran code I have a file called piolib_mod.F90 that starts:

!>
!! @file
!! @brief Initialization Routines for PIO
#define __PIO_FILE__ "piolib_mod.F90"

This produces a doxygen warning:

/home/ed/tmp/ParallelIO/src/flib/piolib_mod.F90:4: warning: Member __PIO_FILE__ (macro definition) of file piolib_mod.F90 is not documented.

But no matter what I do, I can't doxygen to accept my definition of the documentation for this macro. I have tried:

!> for debugging
#define __PIO_FILE__ "piolib_mod.f90"

also:

!> @def __PIO_FILE__ for debugging
#define __PIO_FILE__ "piolib_mod.f90"

I have tried to exclude this line from doxygen processing:

!> @cond exclude
#define __PIO_FILE__ 'piodarray'
!> @endcond

But that does not work either.

Doxygen may be confused by the concept of a pre-processor macro in a Fortran file, but that's just the 21st Century for you, expensive supercomputers and programming languages from the 1960s.

How do I document this pre-processor define with doxygen?

Body:
The way I accomplished this was to pre-process the *.F90 files into *.f90 files, and then use the *.f90 files for Doxygen.

Here's what did the trick in Makefile.am:

# Doxygen does not cope well with pre-processor use in Fortran. So
# create .f90 files from .F90 files by running the C
# pre-processor. These will only be used by doxygen when --enable-docs
# is used at configure.
if BUILD_DOCS
BUILT_SOURCES += piodarray.f90 piolib_mod.f90 pionfatt_mod.f90 pionfget_mod.f90 pionfput_mod.f90 pionfatt_mod_2.f90 pionfget_mod_2.f90
piodarray.f90: piodarray.F90
    $(CC) -E $< > $@
piolib_mod.f90: piolib_mod.F90
    $(CC) -E $< > $@
pionfatt_mod.f90: pionfatt_mod.F90
    $(CC) -E $< > $@
pionfget_mod.f90: pionfget_mod.F90
    $(CC) -E $< > $@
pionfput_mod.f90: pionfput_mod.F90
    $(CC) -E $< > $@

In my configure.ac I set up Doxygen to read the Fortran files I need:

# If building docs, process Doxyfile.in into Doxyfile.
if test "x$enable_docs" = xyes; then
   AC_SUBST([CMAKE_CURRENT_SOURCE_DIR], ["."])
   AC_SUBST([CMAKE_BINARY_DIR], [".."])
   if test "x$enable_fortran" = xno; then
      AC_MSG_ERROR([--enable-fortran is required for documentation builds.])
   fi
   AC_SUBST([FORTRAN_SRC_FILES], ["../src/flib/piodarray.f90  ../src/flib/pio.F90  ../src/flib/pio_kinds.F90  ../src/flib/piolib_mod.f90  ../src/flib/pionfatt_mod_2.f90  ../src/flib/pio_nf.F90  ../src/flib/pionfget_mod_2.f90  ../src/flib/pionfput_mod.f90  ../src/flib/pio_support.F90  ../src/flib/pio_types.F90"])
   if test "x$enable_developer_docs" = xyes; then
      AC_SUBST([C_SRC_FILES], ["../src/clib"])
   else
      AC_SUBST([C_SRC_FILES], ["../src/clib/pio_nc.c ../src/clib/pio_nc4.c ../src/clib/pio_darray.c ../src/clib/pio_get_nc.c ../src/clib/pio_put_nc.c ../src/clib/pioc_support.c ../src/clib/pioc.c ../src/clib/pio_file.c ../src/clib/pio.h"])
   fi
   AC_CONFIG_FILES([doc/Doxyfile])
fi

This all works and now I have a clean doxygen build with no warnings. ;-)


问:
View not found Invariant Violation
I'm using react-navigation to navigate between login and register page.And i am having problem in View of Login page.

I have seen this 'React Native Invariant Violation: View config'  but I didn't got my answer.

In App.js --

```<code>import Register from './src/pages/Register';

const MainNavigator = createStackNavigator({
  LoginPage : { screen : 'Login'},
  SignUp : {screen : 'Register'}
  }
);

const App = createAppContainer(MainNavigator);

export default App;
</code>```

In Login.js --

```<code>import LoginForm from '../components/LoginForm';

export default class Login extends Component{
    render(){
        const {navigate} = this.props.navigation;
        return(

                <View style = {styles.container}>
                <Logo />
                <LoginForm type="Log In"/>
                <View style = {styles.signupcont}>
                <Text>Not a User</Text>
                <TouchableOpacity>
                <Text style = {styles.signuptxt}
                      onPress = {() => navigate('SignUp')}>Sign Up</Text>
                </TouchableOpacity>
                </View>
                </View>
        )
    }
}
</code>```

I expected when clicking on the text it will navigate to Register page but it shows 'Invariant Violation: View config not found for name Login.'

答:
Screen is not an string, it is the page class. </p>

```<code>import Register from './src/pages/Register';
import Login from >>insert login page path here<<;

const MainNavigator = createStackNavigator({
  LoginPage : { screen : Login},
  SignUp : {screen : Register}
  }
);
</code>```

Title: View not found Invariant Violation

Body:
I'm using react-navigation to navigate between login and register page.And i am having problem in View of Login page.

I have seen this 'React Native Invariant Violation: View config'  but I didn't got my answer.

In App.js --

import Register from './src/pages/Register';

const MainNavigator = createStackNavigator({
  LoginPage : { screen : 'Login'},
  SignUp : {screen : 'Register'}
  }
);

const App = createAppContainer(MainNavigator);

export default App;

In Login.js --

import LoginForm from '../components/LoginForm';

export default class Login extends Component{
    render(){
        const {navigate} = this.props.navigation;
        return(

                <View style = {styles.container}>
                <Logo />
                <LoginForm type="Log In"/>
                <View style = {styles.signupcont}>
                <Text>Not a User</Text>
                <TouchableOpacity>
                <Text style = {styles.signuptxt}
                      onPress = {() => navigate('SignUp')}>Sign Up</Text>
                </TouchableOpacity>
                </View>
                </View>
        )
    }
}

I expected when clicking on the text it will navigate to Register page but it shows 'Invariant Violation: View config not found for name Login.'

Body:
Screen is not an string, it is the page class.

import Register from './src/pages/Register';
import Login from >>insert login page path here<<;

const MainNavigator = createStackNavigator({
  LoginPage : { screen : Login},
  SignUp : {screen : Register}
  }
);


问:
How to convert class attributs of types numpy.double, numpy.single and struct.Struct to the respective numba types?
How to convert class attributs of types numpy.double, numpy.single and struct.Struct to the respective numba types, in order to be able to use such attributes with jitclass?

1) For example one of the class attributes has the following form:

```<code>self.type = numpy.double
</code>```

In order to compile a python class with such attribute I would have to map it to a numba type. I tried numba.typeof(numpy.double) but it yields the following error

```<code>In [1]: a=numpy.double
In [2]: numba.typeof(a)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-244-7ab9d6ba8d0a> in <module>
----> 1 numba.typeof(a)

C:\ProgramData\Anaconda3\lib\site-packages\numba\typing\typeof.py in typeof(val
 purpose)
     32         msg = _termcolor.errmsg(
     33             "cannot determine Numba type of %r") % (type(val),)
---> 34         raise ValueError(msg)
     35     return ty
     36

ValueError: cannot determine Numba type of <class 'type'>
</code>```

2) in the case of using struct.Struct I get a similar error

```<code>In [1]: from struct import Struct
In [2]: a = Struct(">dd")
In [3]: numba.typeof(a)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-76-7ab9d6ba8d0a> in <module>
----> 1 numba.typeof(a)

C:\ProgramData\Anaconda3\lib\site-packages\numba\typing\typeof.py in typeof(val,
 purpose)
     32         msg = _termcolor.errmsg(
     33             "cannot determine Numba type of %r") % (type(val),)
---> 34         raise ValueError(msg)
     35     return ty
     36

ValueError: cannot determine Numba type of <class 'Struct'>
</code>```

MINIMAL (WORKING) EXAMPLE:

```<code>import numpy as np
import numba as nb
from struct import Struct

spec = [('type', nb.typeof(np.double)), ('h', nb.typeof(Struct(">f8")))]

@nb.jitclass(spec)
class TestClass:

    def __init__(self):
        self.type = np.double
        self.h = Struct(">f8")
</code>```

When I try to compile the above class I get the following error:

```<code>C:>python classtest.py
Traceback (most recent call last):
  File "classtest.py", line 5, in <module>
    spec = [('type', nb.typeof(np.double)), ('h', nb.typeof(Struct(">f8")))]
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\typing\typeof.py", line
 34, in typeof
    raise ValueError(msg)
ValueError: ←[1mcannot determine Numba type of <class 'type'>←[0m
</code>```

答:
How to convert class attributs of types numpy.double, numpy.single and struct.Struct to the respective numba types, in order to be able to use such attributes with jitclass?

For numpy.double and numpy.single it's easy, numba.float64 and numba.float32 are the corresponding numba types.

In Version 0.43.1 the numba.typeof also works on the NumPy types, however the function is expecting an instance not the class itself:

```<code>>>> import numpy as np
>>> import numba as nb
>>> nb.__version__
'0.43.1'
>>> nb.typeof(np.double(10))
float64
</code>```

However there's currently (as of version 0.43.1 of numba) no support for struct in numba (see "2.6. Supported Python features" of the numba documentation), so you cannot use struct with nopython mode in numba (that includes jitclass).

Of course you can unpack your struct into the individual components and if numba supports them use them instead. For example instead of 'dd' you could add two numba.float64 fields on the jitclass. Since you've been using different structs and not every Python type is supported in numba you may need to experiment with that.

Body:
How to convert class attributs of types numpy.double, numpy.single and struct.Struct to the respective numba types, in order to be able to use such attributes with jitclass?

1) For example one of the class attributes has the following form:

self.type = numpy.double

In order to compile a python class with such attribute I would have to map it to a numba type. I tried numba.typeof(numpy.double) but it yields the following error

In [1]: a=numpy.double
In [2]: numba.typeof(a)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-244-7ab9d6ba8d0a> in <module>
----> 1 numba.typeof(a)

C:\ProgramData\Anaconda3\lib\site-packages\numba\typing\typeof.py in typeof(val
 purpose)
     32         msg = _termcolor.errmsg(
     33             "cannot determine Numba type of %r") % (type(val),)
---> 34         raise ValueError(msg)
     35     return ty
     36

ValueError: cannot determine Numba type of <class 'type'>

2) in the case of using struct.Struct I get a similar error

In [1]: from struct import Struct
In [2]: a = Struct(">dd")
In [3]: numba.typeof(a)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-76-7ab9d6ba8d0a> in <module>
----> 1 numba.typeof(a)

C:\ProgramData\Anaconda3\lib\site-packages\numba\typing\typeof.py in typeof(val,
 purpose)
     32         msg = _termcolor.errmsg(
     33             "cannot determine Numba type of %r") % (type(val),)
---> 34         raise ValueError(msg)
     35     return ty
     36

ValueError: cannot determine Numba type of <class 'Struct'>

MINIMAL (WORKING) EXAMPLE:

import numpy as np
import numba as nb
from struct import Struct

spec = [('type', nb.typeof(np.double)), ('h', nb.typeof(Struct(">f8")))]

@nb.jitclass(spec)
class TestClass:

    def __init__(self):
        self.type = np.double
        self.h = Struct(">f8")

When I try to compile the above class I get the following error:

C:>python classtest.py
Traceback (most recent call last):
  File "classtest.py", line 5, in <module>
    spec = [('type', nb.typeof(np.double)), ('h', nb.typeof(Struct(">f8")))]
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\typing\typeof.py", line
 34, in typeof
    raise ValueError(msg)
ValueError: ←[1mcannot determine Numba type of <class 'type'>←[0m

Body:
How to convert class attributs of types numpy.double, numpy.single and struct.Struct to the respective numba types, in order to be able to use such attributes with jitclass?

For numpy.double and numpy.single it's easy, numba.float64 and numba.float32 are the corresponding numba types.

In Version 0.43.1 the numba.typeof also works on the NumPy types, however the function is expecting an instance not the class itself:

>>> import numpy as np
>>> import numba as nb
>>> nb.__version__
'0.43.1'
>>> nb.typeof(np.double(10))
float64

However there's currently (as of version 0.43.1 of numba) no support for struct in numba (see "2.6. Supported Python features" of the numba documentation), so you cannot use struct with nopython mode in numba (that includes jitclass).

Of course you can unpack your struct into the individual components and if numba supports them use them instead. For example instead of 'dd' you could add two numba.float64 fields on the jitclass. Since you've been using different structs and not every Python type is supported in numba you may need to experiment with that.


答:
It is a broken function written by somebody who thought they were clever.

The objects buf, L, and R are defined with static, they they exist for the duration of program execution and are initialized when execution begins. They keep their values between calls to the function.

Nominally, the function returns either a character (*L++) or EOF. But the return type is char, which should not be used by routines returning EOF. EOF is specified to be an int value and either is not char value, overlaps a char value (which is not desired because then they cannot be distinguished—the routine ought to be using unsigned char for buf), or raises other issues when converted to a char value (the conversion will signal or will overlap with a char value).

The intent appears to be that L (for “Left”) points to the left side of characters that have been read into the buffer and not yet consumed, and R points to the right side (end) of characters that have been read into the buffer. When L equals R, the buffer is empty, and more characters should be read into it.

When L (for “Left”) and R (for “Right”) are equal, the right operand of the && is evaluated. We can rewrite it:

```<code>(R = (L=buf) + fread(buf,1,100000,stdin), L==R)
    ? EOF
    : *L++;
</code>```

This resets L to the start of the buffer and then attempts to read 10000 characters. The number of characters actually read is added to L and then assigned to R. So L points to the start of the newly read characters (at the beginning of buf), and R points to the end (one past the last character read).

After this, the comma operator effectively causes L==R to be used as the controlling value for ? :. If no characters were read, L equals R, and the routine attempts to return EOF (but may fail as explained above). If characters were read, *L++ returns the first character and increments L to point to the next character.

On subsequent calls when there are characters in the buffer, the left operand of the &&, L==R, is false, so right operand is not evaluated. The expression then looks like false && (DoesNotMatter) ? EOF : *L++. Since the result of the && is false, *L++ returns the next character in the buffer and advances L. As calls continue, eventually L will equal R, and the buffer will be empty, causing new data to be read.

Body:
I have seen this piece of code several times but am unable to understand what it does

inline char nc()
{
    static char buf[100000], *L = buf, *R = buf;
    return L == R && (R = (L = buf) + fread(buf, 1, 100000, stdin), L == R) ? EOF : *L++;
}

The condition L==R should always be true , right? since both the pointers point to the same variable. I cant understand what the second part of the condition checks. Could someone please help me out?

Body:
It is a broken function written by somebody who thought they were clever.

The objects buf, L, and R are defined with static, they they exist for the duration of program execution and are initialized when execution begins. They keep their values between calls to the function.

Nominally, the function returns either a character (*L++) or EOF. But the return type is char, which should not be used by routines returning EOF. EOF is specified to be an int value and either is not char value, overlaps a char value (which is not desired because then they cannot be distinguished—the routine ought to be using unsigned char for buf), or raises other issues when converted to a char value (the conversion will signal or will overlap with a char value).

The intent appears to be that L (for “Left”) points to the left side of characters that have been read into the buffer and not yet consumed, and R points to the right side (end) of characters that have been read into the buffer. When L equals R, the buffer is empty, and more characters should be read into it.

When L (for “Left”) and R (for “Right”) are equal, the right operand of the && is evaluated. We can rewrite it:

(R = (L=buf) + fread(buf,1,100000,stdin), L==R)
    ? EOF
    : *L++;

This resets L to the start of the buffer and then attempts to read 10000 characters. The number of characters actually read is added to L and then assigned to R. So L points to the start of the newly read characters (at the beginning of buf), and R points to the end (one past the last character read).

After this, the comma operator effectively causes L==R to be used as the controlling value for ? :. If no characters were read, L equals R, and the routine attempts to return EOF (but may fail as explained above). If characters were read, *L++ returns the first character and increments L to point to the next character.

On subsequent calls when there are characters in the buffer, the left operand of the &&, L==R, is false, so right operand is not evaluated. The expression then looks like false && (DoesNotMatter) ? EOF : *L++. Since the result of the && is false, *L++ returns the next character in the buffer and advances L. As calls continue, eventually L will equal R, and the buffer will be empty, causing new data to be read.


问:
Is the baseurl support NFS shared repository for yum update
I wanted to share a repository over NFS or CISF shared location. Is the baseurl support NFS repsoitiry. I tried something like below sample code.

```<code>name=XXXX
baseurl=//100.96.37.56/ShareFolder/1035
enabled=1
gpgcheck=1
timeout=600
</code>```

I tried to do yum clean, it shows error like:
Error parsing config: Error parsing "baseurl = '//100.96.37.56/ShareFolder/1035'": URL must be http, ftp, file or https not ""

答:
I think you should be specifying the location in the following format;
file:///path/to/local/repo

Which would make your config file read as;

```<code>name=XXXX
baseurl=file:///100.96.37.56/ShareFolder/1035
enabled=1
gpgcheck=1
timeout=600
</code>```

More info can be found here on the RedHat site, or here on the CentOS wiki.

Body:
I wanted to share a repository over NFS or CISF shared location. Is the baseurl support NFS repsoitiry. I tried something like below sample code.

name=XXXX
baseurl=//100.96.37.56/ShareFolder/1035
enabled=1
gpgcheck=1
timeout=600

I tried to do yum clean, it shows error like:
Error parsing config: Error parsing "baseurl = '//100.96.37.56/ShareFolder/1035'": URL must be http, ftp, file or https not ""

Body:
I think you should be specifying the location in the following format;
file:///path/to/local/repo

Which would make your config file read as;

name=XXXX
baseurl=file:///100.96.37.56/ShareFolder/1035
enabled=1
gpgcheck=1
timeout=600

More info can be found here on the RedHat site, or here on the CentOS wiki.


问:
Elasticsearch - Bootstrap checks failing
I'm trying to use the Flink 5.x Elasticsearch sink connector to insert data to ES 5.2.1 instance hosted on a tiny VM.

As this is a tiny VM in development mode, I cant get it to start up to accept TransportClient remote client connections on 9300 without failing the bootstrap checks.

```<code>[2017-02-17T09:02:48,581][INFO ][o.e.n.Node               ] [Z_fiBnl] starting ...
[2017-02-17T09:02:48,866][INFO ][o.e.t.TransportService   ] [Z_fiBnl] publish_address {xxxxxx:9300}, bound_addresses {127.0.0.1:9300}
[2017-02-17T09:02:48,878][INFO ][o.e.b.BootstrapChecks    ] [Z_fiBnl] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
max number of threads [1024] for user [xxx] is too low, increase to at least [2048]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
</code>```

I've played around with the below settings but just cant get it to startup(http clients on 9200 work fine)

```<code>transport.publish_host: 0.0.0.0
transport.bind_host: 0.0.0.0
http.host: "xxx"
http.host: 169.117.72.167
network.host: 0.0.0.0
network.publish_host: 0.0.0.0
</code>```

Note that ES is running on a tiny VM just for dev purposes and I don't have access to change for ex. the file descriptor limits on this box.

答:
Been scouring google for this and apply different suggestion, but I think this is the general solution:

check for the actual limit when the process is running (albeit short) with:

```<code>cat /proc/<pid>/limits
</code>```

You will find lines similar to this:

```<code>Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
<truncated>
</code>```

Then depend on the runner or container (in my case it was supervisord's minfds value), you can lift the actual limitation configuration.

Body:
I'm trying to use the Flink 5.x Elasticsearch sink connector to insert data to ES 5.2.1 instance hosted on a tiny VM.

As this is a tiny VM in development mode, I cant get it to start up to accept TransportClient remote client connections on 9300 without failing the bootstrap checks.

[2017-02-17T09:02:48,581][INFO ][o.e.n.Node               ] [Z_fiBnl] starting ...
[2017-02-17T09:02:48,866][INFO ][o.e.t.TransportService   ] [Z_fiBnl] publish_address {xxxxxx:9300}, bound_addresses {127.0.0.1:9300}
[2017-02-17T09:02:48,878][INFO ][o.e.b.BootstrapChecks    ] [Z_fiBnl] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
max number of threads [1024] for user [xxx] is too low, increase to at least [2048]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

I've played around with the below settings but just cant get it to startup(http clients on 9200 work fine)

transport.publish_host: 0.0.0.0
transport.bind_host: 0.0.0.0
http.host: "xxx"
http.host: 169.117.72.167
network.host: 0.0.0.0
network.publish_host: 0.0.0.0

Note that ES is running on a tiny VM just for dev purposes and I don't have access to change for ex. the file descriptor limits on this box.

Body:
Been scouring google for this and apply different suggestion, but I think this is the general solution:

check for the actual limit when the process is running (albeit short) with:

cat /proc/<pid>/limits

You will find lines similar to this:

Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
<truncated>

Then depend on the runner or container (in my case it was supervisord's minfds value), you can lift the actual limitation configuration.


问:
Angular 7 parameter route is overriding non parameter route
I am using modular structure for my project.

Parent route is

```<code> { path: 'questions', loadChildren: '../questions/questions.module#QuestionsModule'}
</code>```

and in child I have :

```<code>const routes: Routes = [
{
path: '',
component: QuestionComponent,
children: [
  {
     path: ':id',
     component: ViewComponent,
  },

  {
    path: 'ask',
    component: AskComponent,
    pathMatch: 'full'
  },
  {
    path: '',
    redirectTo:'/:id',
    pathMatch:'full'
 },
]}];
</code>```

for both http://localhost:4200/questions/123 and http://localhost:4200/questions/ask routes ,
ViewComponent is loading.

Here is my folder structure with routing: https://stackblitz.com/edit/angular-sjd9u9

答:
The problem is Routing, add static link before parameter will solves your issue

https://stackblitz.com/edit/angular-gkpabq?file=src/app/pages/index/index.component.html

```<code>  {
        path: '',
        component: QuestionComponent,
        children: [
          {
             path: 'test/:id',
             component: ViewComponent
          },

   {
        path: 'ask',
        component: AskComponent,
        pathMatch:'full'
      },
      {
        path: '',
        redirectTo:'/:id',
        pathMatch:'full'
     }

    <div>
    <div>
        <a [routerLink]="['/questions/test',123]">View Questiion </a>
    </div>
    <div>
        <a [routerLink]="['/questions/ask']">Ask Questiion</a>
    <span style="color:red">It is redirecting to View Question Page : Issue</span>
    </div>
</div>
</code>```

Body:
I am using modular structure for my project.

Parent route is

 { path: 'questions', loadChildren: '../questions/questions.module#QuestionsModule'}

and in child I have :

const routes: Routes = [
{
path: '',
component: QuestionComponent,
children: [
  {
     path: ':id',
     component: ViewComponent,
  },

  {
    path: 'ask',
    component: AskComponent,
    pathMatch: 'full'
  },
  {
    path: '',
    redirectTo:'/:id',
    pathMatch:'full'
 },
]}];

for both http://localhost:4200/questions/123 and http://localhost:4200/questions/ask routes ,
ViewComponent is loading.

Here is my folder structure with routing: https://stackblitz.com/edit/angular-sjd9u9

Body:
The problem is Routing, add static link before parameter will solves your issue

https://stackblitz.com/edit/angular-gkpabq?file=src/app/pages/index/index.component.html

  {
        path: '',
        component: QuestionComponent,
        children: [
          {
             path: 'test/:id',
             component: ViewComponent
          },

   {
        path: 'ask',
        component: AskComponent,
        pathMatch:'full'
      },
      {
        path: '',
        redirectTo:'/:id',
        pathMatch:'full'
     }

    <div>
    <div>
        <a [routerLink]="['/questions/test',123]">View Questiion </a>
    </div>
    <div>
        <a [routerLink]="['/questions/ask']">Ask Questiion</a>
    <span style="color:red">It is redirecting to View Question Page : Issue</span>
    </div>
</div>


问:
Postman post request works ok but exported Ruby Don
Post request work in Postman but the same code exported in Ruby doesn't work. It is a request

```<code>Content-Type= application/x-www-form-urlencoded with body
content-type = 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
</code>```

I need to send a confirmation to payU for IDN. The request works ok if it is send from Postman but not working ok when I ran the same code from ruby. (their server's answer is "Invalid account code" which is equivalent with no parameters received by payU.)

Request makes a post requests to

```<code>https://sandbox.payu.ro/order/idn.php
</code>```

with header:

```<code>Content-Type:application/x-www-form-urlencoded
with
    body: multipart/form-date and the parameters:
    MERCHANT=GOISTEST
    ORDER_REF=304911
    ORDER_AMOUNT=35.70
    ORDER_CURRENCY=RON
    IDN_DATE=2019-05-26 07:50:39
    ORDER_HASH=b27e42645e9c52b81fab955eb7309f70
</code>```

```<code>The Postman request result is
<EPAYMENT>304911|7|Order already confirmed|2019-05-26 08:57:52|5c25acc698cb607a2af3676fdbaabf7b</EPAYMENT>
</code>```

If you export in Ruby and run it you get an error for Error EOF
but if you add:

```<code>http.use_ssl = true
</code>```

then the request is done and response is:

"Invalid account code"

I would need the request to work in ruby!

This is the code exported by postman to Ruby:

```<code>The Postman request result is
<EPAYMENT>304911|7|Order already confirmed|2019-05-26 08:57:52|5c25acc698cb607a2af3676fdbaabf7b</EPAYMENT>
</code>```

If you export in Ruby and run it you get an error for Error EOF
but if you add:

```<code>http.use_ssl = true
</code>```

then the request is done and response is:

"Invalid account code"

This is the server's answer when you do not send the parameters at all!
"What more can I do? "

答:
In the end I found out from that
http://ruby-doc.org/stdlib-2.0.0/libdoc/net/http/rdoc/Net/HTTP.html#label-Setting+Headers
that
request["content-type"] = 'multipart/form-data; boundary=----NEW_BOUNDARY'
is not working but
    request.content_type = 'multipart/form-data; boundary=----NEW_BOUNDARY'
works.
I could make finnaly the post after many hours of debugging.

Body:
Post request work in Postman but the same code exported in Ruby doesn't work. It is a request

Content-Type= application/x-www-form-urlencoded with body
content-type = 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'

I need to send a confirmation to payU for IDN. The request works ok if it is send from Postman but not working ok when I ran the same code from ruby. (their server's answer is "Invalid account code" which is equivalent with no parameters received by payU.)

Request makes a post requests to

https://sandbox.payu.ro/order/idn.php

with header:

Content-Type:application/x-www-form-urlencoded
with
    body: multipart/form-date and the parameters:
    MERCHANT=GOISTEST
    ORDER_REF=304911
    ORDER_AMOUNT=35.70
    ORDER_CURRENCY=RON
    IDN_DATE=2019-05-26 07:50:39
    ORDER_HASH=b27e42645e9c52b81fab955eb7309f70

The Postman request result is
<EPAYMENT>304911|7|Order already confirmed|2019-05-26 08:57:52|5c25acc698cb607a2af3676fdbaabf7b</EPAYMENT>

If you export in Ruby and run it you get an error for Error EOF
but if you add:

http.use_ssl = true

then the request is done and response is:

"Invalid account code"

I would need the request to work in ruby!

This is the code exported by postman to Ruby:

The Postman request result is
<EPAYMENT>304911|7|Order already confirmed|2019-05-26 08:57:52|5c25acc698cb607a2af3676fdbaabf7b</EPAYMENT>

If you export in Ruby and run it you get an error for Error EOF
but if you add:

http.use_ssl = true

then the request is done and response is:

"Invalid account code"

This is the server's answer when you do not send the parameters at all!
"What more can I do? "


问:
Copy a folder in go
Is there an easy way to copy a directory in go?
I have the following function:

```<code>err = CopyDir("sourceFolder","destinationFolder")
</code>```

Nothing so far has worked, including libraries such as github.com/cf-guardian/guardian/kernel/fileutils

One important thing to note is that I need to preserve directory structure, including the sourceFolder itself, not simply copy all contents of the folder.

答:
I believe that docker implementation can be considered as complete solution for handling edge cases:
https://github.com/moby/moby/blob/master/daemon/graphdriver/copy/copy.go

There are following good things:

unsupported file type rise error

preserving permissions and ownership

preserving extended attributes

preserving timestamp

but because of a lot of imports your tiny application becomes huge.

I've tried to combine several solutions but use stdlib and for Linux only:

```<code>func CopyDirectory(scrDir, dest string) error {
    entries, err := os.ReadDir(scrDir)
    if err != nil {
        return err
    }
    for _, entry := range entries {
        sourcePath := filepath.Join(scrDir, entry.Name())
        destPath := filepath.Join(dest, entry.Name())

        fileInfo, err := os.Stat(sourcePath)
        if err != nil {
            return err
        }

        stat, ok := fileInfo.Sys().(*syscall.Stat_t)
        if !ok {
            return fmt.Errorf("failed to get raw syscall.Stat_t data for '%s'", sourcePath)
        }

        switch fileInfo.Mode() & os.ModeType{
        case os.ModeDir:
            if err := CreateIfNotExists(destPath, 0755); err != nil {
                return err
            }
            if err := CopyDirectory(sourcePath, destPath); err != nil {
                return err
            }
        case os.ModeSymlink:
            if err := CopySymLink(sourcePath, destPath); err != nil {
                return err
            }
        default:
            if err := Copy(sourcePath, destPath); err != nil {
                return err
            }
        }

        if err := os.Lchown(destPath, int(stat.Uid), int(stat.Gid)); err != nil {
            return err
        }

        fInfo, err := entry.Info()
        if err != nil {
            return err
        }

        isSymlink := fInfo.Mode()&os.ModeSymlink != 0
        if !isSymlink {
            if err := os.Chmod(destPath, fInfo.Mode()); err != nil {
                return err
            }
        }
    }
    return nil
}

func Copy(srcFile, dstFile string) error {
    out, err := os.Create(dstFile)
    if err != nil {
        return err
    }

    defer out.Close()

    in, err := os.Open(srcFile)
    defer in.Close()
    if err != nil {
        return err
    }

    _, err = io.Copy(out, in)
    if err != nil {
        return err
    }

    return nil
}

func Exists(filePath string) bool {
    if _, err := os.Stat(filePath); os.IsNotExist(err) {
        return false
    }

    return true
}

func CreateIfNotExists(dir string, perm os.FileMode) error {
    if Exists(dir) {
        return nil
    }

    if err := os.MkdirAll(dir, perm); err != nil {
        return fmt.Errorf("failed to create directory: '%s', error: '%s'", dir, err.Error())
    }

    return nil
}

func CopySymLink(source, dest string) error {
    link, err := os.Readlink(source)
    if err != nil {
        return err
    }
    return os.Symlink(link, dest)
}

</code>```

Title: Copy a folder in go

Body:
Is there an easy way to copy a directory in go?
I have the following function:

err = CopyDir("sourceFolder","destinationFolder")

Nothing so far has worked, including libraries such as github.com/cf-guardian/guardian/kernel/fileutils

One important thing to note is that I need to preserve directory structure, including the sourceFolder itself, not simply copy all contents of the folder.

Body:
I believe that docker implementation can be considered as complete solution for handling edge cases:
https://github.com/moby/moby/blob/master/daemon/graphdriver/copy/copy.go

There are following good things:

unsupported file type rise error

preserving permissions and ownership

preserving extended attributes

preserving timestamp

but because of a lot of imports your tiny application becomes huge.

I've tried to combine several solutions but use stdlib and for Linux only:

func CopyDirectory(scrDir, dest string) error {
    entries, err := os.ReadDir(scrDir)
    if err != nil {
        return err
    }
    for _, entry := range entries {
        sourcePath := filepath.Join(scrDir, entry.Name())
        destPath := filepath.Join(dest, entry.Name())

        fileInfo, err := os.Stat(sourcePath)
        if err != nil {
            return err
        }

        stat, ok := fileInfo.Sys().(*syscall.Stat_t)
        if !ok {
            return fmt.Errorf("failed to get raw syscall.Stat_t data for '%s'", sourcePath)
        }

        switch fileInfo.Mode() & os.ModeType{
        case os.ModeDir:
            if err := CreateIfNotExists(destPath, 0755); err != nil {
                return err
            }
            if err := CopyDirectory(sourcePath, destPath); err != nil {
                return err
            }
        case os.ModeSymlink:
            if err := CopySymLink(sourcePath, destPath); err != nil {
                return err
            }
        default:
            if err := Copy(sourcePath, destPath); err != nil {
                return err
            }
        }

        if err := os.Lchown(destPath, int(stat.Uid), int(stat.Gid)); err != nil {
            return err
        }

        fInfo, err := entry.Info()
        if err != nil {
            return err
        }

        isSymlink := fInfo.Mode()&os.ModeSymlink != 0
        if !isSymlink {
            if err := os.Chmod(destPath, fInfo.Mode()); err != nil {
                return err
            }
        }
    }
    return nil
}

func Copy(srcFile, dstFile string) error {
    out, err := os.Create(dstFile)
    if err != nil {
        return err
    }

    defer out.Close()

    in, err := os.Open(srcFile)
    defer in.Close()
    if err != nil {
        return err
    }

    _, err = io.Copy(out, in)
    if err != nil {
        return err
    }

    return nil
}

func Exists(filePath string) bool {
    if _, err := os.Stat(filePath); os.IsNotExist(err) {
        return false
    }

    return true
}

func CreateIfNotExists(dir string, perm os.FileMode) error {
    if Exists(dir) {
        return nil
    }

    if err := os.MkdirAll(dir, perm); err != nil {
        return fmt.Errorf("failed to create directory: '%s', error: '%s'", dir, err.Error())
    }

    return nil
}

func CopySymLink(source, dest string) error {
    link, err := os.Readlink(source)
    if err != nil {
        return err
    }
    return os.Symlink(link, dest)
}


问:
@Singleton vs @ApplicationScope
For a project I need to have a unique ID generator. So I thought about a Singleton with synchronized methods.

Since a Singleton following the traditional Singleton pattern (private static instance) is shared accross Sessions, I'm wondering if the @Singleton Annotation is working the same way?

The documentation says: Identifies a type that the injector only instantiates once.

Does it mean, that a @Singleton will be independent per User Session (which is bad for an id-generator)? Should I prefer an old school Singleton with Class.getInstance() over an Injection of an @Singleton-Bean?

Or should I use neither nor and provide the Service within an @ApplicationScoped bean?

it musst be guaranteed that only ONE thread, independent of the user session can access the method to generate the next id. (It's not solvable with auto-increment database ids)

Edit: JSF 2.2, CDI and javax.inject.* i'm talking about :)

答:
javax.inject.Singleton - When used on your bean, you have to implement writeResolve() and readReplace to avoid any serialization issues. Use it judiciously based on what your bean actually has in it.

javax.enterprise.context.ApplicationScoped - Allows the container to proxy the bean and take care of serialization process automatically. This is recommended to avoid unprecedented issues.

For More information refer this page number 45.

Title: @Singleton vs @ApplicationScope


问:
express-ntlm returning the wrong user
I'm using express-ntlm to get the current user's windows ID in an intranet setting. It works fine most of the time, but occasionally it will return the ID of a completely different person. I'm guessing this is something to do with sessions maybe? </p>

```<code>const ntlm = require('express-ntlm');

module.exports = app => {

  app.use(
    ntlm({
      debug: function() {
        var args = Array.prototype.slice.apply(arguments);
        console.log.apply(null, args);
      },
      domain: 'MS',
      domaincontroller: 'ldap://something.com'
    })
  );
app.post('/get-user-details/', (req, res) => {
console.log(req.ntlm.UserName); //Returns correct user most of the time, but sometimes it returns different person who open site at the same time
});
</code>```

答:
Unfortunately NTLM authenticates connections, not sessions. Which was fine in the past, but doesn't make sense anymore, since browser tend to open multiple connections at once to speed up page loading and reverse proxies are sharing connections to the backend. That's where the problem is: Your reverse proxy will reuse already authenticated connections to the backend, and therefore mix up users. To mitigate this issue, you have to make sure your reverse proxy has NTLM support enabled.

There is still an open pull request for express-ntlm that adds a Keep-Alive property which might solve this issue, unfortunately it's widely untested and first needs to be verified.

Title: express-ntlm returning the wrong user

Body:
I'm using express-ntlm to get the current user's windows ID in an intranet setting. It works fine most of the time, but occasionally it will return the ID of a completely different person. I'm guessing this is something to do with sessions maybe?

const ntlm = require('express-ntlm');

module.exports = app => {

  app.use(
    ntlm({
      debug: function() {
        var args = Array.prototype.slice.apply(arguments);
        console.log.apply(null, args);
      },
      domain: 'MS',
      domaincontroller: 'ldap://something.com'
    })
  );
app.post('/get-user-details/', (req, res) => {
console.log(req.ntlm.UserName); //Returns correct user most of the time, but sometimes it returns different person who open site at the same time
});


问:
list literal and list comprehension behaving differently
I'm having a very strange issue with Python 3.7. Specifically, I have a function that takes a list of document IDs, and returns the wikipedia documents they correspond to. What's strange is that, if I pass in a list comprehension as I want to do, it returns nothing, but if I pass in a list literal with the exact same values, it somehow works. Note that this is using pdb, in the interactive prompt it opens when you type interact:

If I run the list comprehension, I get this list:

```<code>>>> [x[0] for x in truncated]
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]
</code>```

If I run the query with this list literal, it works (data truncated for brevity):

```<code>>>> self._db.query_ids([3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007])
[(1955046, 'Hairy_nightshade', 'Hairy nightshade is a common name for...')]
</code>```

But if I combine the two expressions, it returns nothing:

```<code>>>> self._db.query_ids([x[0] for x in truncated])
[]
</code>```

The actual function that's being called has no side effects, it just queries a database, so it doesn't change between calls in any way:

```<code>def query_ids(self, ids):
    """
    Returns the tokens for each document with the given ID
    """
    result = self.conn.execute(
        'SELECT doc_id, document, group_concat(tokens, " ") FROM doc WHERE doc_id in ({}) GROUP BY doc_id'.format(
            ', '.join(['?'] * len(ids))), ids)
    data = result.fetchall()
    return data
</code>```

How is this possible?

If I add a print(ids) to the first line of my query_ids function, the list of IDs is printed identically both times, but it still doesn't work with the list comprehension:

```<code>(Pdb) self._db.query_ids([x[0] for x in truncated])
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]
[]
(Pdb) self._db.query_ids([3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007])
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]
[(1955046, 'Hairy_nightshade', 'Hairy nightshade is a common name for several plants and may refer to...')]
</code>```

答:
This was a strange bug, but I believe I've worked it out.

The issue wasn't the type of truncated, which was a list, but rather the contents of that list were numpy int64 types, not python integers:

```<code>(Pdb) !a = [x[0] for x in truncated]
(Pdb) type(a)
<class 'list'>
(Pdb) type(a[0])
<class 'numpy.int64'>
</code>```

When this list of numpy.int64s were passed into the database query, they were ignored, because the Python sqlite3 API doesn't know how to deal with non-native Python types: https://docs.python.org/3/library/sqlite3.html#using-adapters-to-store-additional-python-types-in-sqlite-databases

The following Python types can thus be sent to SQLite without any problem: None, int, float, str, bytes

Thus, when I converted the data into native Python integers, it worked:

```<code>(Pdb) self._db.query_ids([int(x[0]) for x in truncated])
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]
[(1955046, 'Hairy_nightshade', 'Hairy nightshade is a common name for several plants and may refer to ')]
</code>```

Body:
I'm having a very strange issue with Python 3.7. Specifically, I have a function that takes a list of document IDs, and returns the wikipedia documents they correspond to. What's strange is that, if I pass in a list comprehension as I want to do, it returns nothing, but if I pass in a list literal with the exact same values, it somehow works. Note that this is using pdb, in the interactive prompt it opens when you type interact:

If I run the list comprehension, I get this list:

>>> [x[0] for x in truncated]
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]

If I run the query with this list literal, it works (data truncated for brevity):

>>> self._db.query_ids([3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007])
[(1955046, 'Hairy_nightshade', 'Hairy nightshade is a common name for...')]

But if I combine the two expressions, it returns nothing:

>>> self._db.query_ids([x[0] for x in truncated])
[]

The actual function that's being called has no side effects, it just queries a database, so it doesn't change between calls in any way:

def query_ids(self, ids):
    """
    Returns the tokens for each document with the given ID
    """
    result = self.conn.execute(
        'SELECT doc_id, document, group_concat(tokens, " ") FROM doc WHERE doc_id in ({}) GROUP BY doc_id'.format(
            ', '.join(['?'] * len(ids))), ids)
    data = result.fetchall()
    return data

How is this possible?

If I add a print(ids) to the first line of my query_ids function, the list of IDs is printed identically both times, but it still doesn't work with the list comprehension:

(Pdb) self._db.query_ids([x[0] for x in truncated])
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]
[]
(Pdb) self._db.query_ids([3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007])
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]
[(1955046, 'Hairy_nightshade', 'Hairy nightshade is a common name for several plants and may refer to...')]

Body:
This was a strange bug, but I believe I've worked it out.

The issue wasn't the type of truncated, which was a list, but rather the contents of that list were numpy int64 types, not python integers:

(Pdb) !a = [x[0] for x in truncated]
(Pdb) type(a)
<class 'list'>
(Pdb) type(a[0])
<class 'numpy.int64'>

When this list of numpy.int64s were passed into the database query, they were ignored, because the Python sqlite3 API doesn't know how to deal with non-native Python types: https://docs.python.org/3/library/sqlite3.html#using-adapters-to-store-additional-python-types-in-sqlite-databases

The following Python types can thus be sent to SQLite without any problem: None, int, float, str, bytes

Thus, when I converted the data into native Python integers, it worked:

(Pdb) self._db.query_ids([int(x[0]) for x in truncated])
[3553957, 4480571, 4686346, 1955046, 4476254, 4510002, 3941950, 2991560, 5314256, 3949007]
[(1955046, 'Hairy_nightshade', 'Hairy nightshade is a common name for several plants and may refer to ')]


问:
how to align asynchronous reports for a related asset?
The example I will give is a train. A train has multiple train-cars and in my system each train car will send me a packet of info on a determined interval. For example, I can guarantee I will have at least 1 packet from each train-car every 10 minutes.

What I want to do is show an animation of the train cars proceeding along the map.

The problem I have is how to align all the data to make a train - visualization with each car in it's relative position to each other - when the data is recorded at different times and without any order relevant to the order of the train cars?

What ends up happening is sometimes car2 will look like it's in front of car1! In the example below, if I showed the data reported for this period, car2 looks like it's on top of car1!

For example

```<code>CAR | TIME | LOCATION | LOCATION of 1 (guessed, not reported)
1   | 05   |  10,10   | 10,10
2   | 06   |  10,10   | 10,11
3   | 04   |  10,07   | 10,09
</code>```

You may suggest that I look at my own example and visualize the guessed location of the other cars at a specific point. For a train where the route is known this is a good solution (and a likely candidate I'll be implementing). But if you change the scope of the problem from trains on tracks to semi-convoys on roads the guessing solution breaks down. There's no way to know if the first car in the convoy took a turn...

This returns the question to trying to find a reasonable analytical/computational solution to synchronizing the recorded metrics.

Is there a known strategy for dealing with this type of problem? Where do I start my research? Any prefab solutions?

The only solution I can think of that's analytical will be to find the smallest window of available data from the data points to create the smallest possible frame of data, select the mean time for the frame and then approximate the location for the other points based on the point closest to the mean.

This is very close to the strategy I disregarded earlier where I use the know distance between the cars to guess where carA is based on carC. Because it's a train I can assume that the speed is the same for all cars at any time. In a semi convoy this isn't true, semiACar1 could be slightly slower or faster than semiBcar1.

So by now I think you understand the problem and where I am .

Thanks for your ideas and interest.

答:
If you don't have reported data, interpolate /extrapolate the positions. If your temporal resolution is high enough this should work just fine.

If your temporal resolution isn't good enough, first model the likely track, then interpolate along the track.

Body:
The example I will give is a train. A train has multiple train-cars and in my system each train car will send me a packet of info on a determined interval. For example, I can guarantee I will have at least 1 packet from each train-car every 10 minutes.

What I want to do is show an animation of the train cars proceeding along the map.

The problem I have is how to align all the data to make a train - visualization with each car in it's relative position to each other - when the data is recorded at different times and without any order relevant to the order of the train cars?

What ends up happening is sometimes car2 will look like it's in front of car1! In the example below, if I showed the data reported for this period, car2 looks like it's on top of car1!

For example

CAR | TIME | LOCATION | LOCATION of 1 (guessed, not reported)
1   | 05   |  10,10   | 10,10
2   | 06   |  10,10   | 10,11
3   | 04   |  10,07   | 10,09

You may suggest that I look at my own example and visualize the guessed location of the other cars at a specific point. For a train where the route is known this is a good solution (and a likely candidate I'll be implementing). But if you change the scope of the problem from trains on tracks to semi-convoys on roads the guessing solution breaks down. There's no way to know if the first car in the convoy took a turn...

This returns the question to trying to find a reasonable analytical/computational solution to synchronizing the recorded metrics.

Is there a known strategy for dealing with this type of problem? Where do I start my research? Any prefab solutions?

The only solution I can think of that's analytical will be to find the smallest window of available data from the data points to create the smallest possible frame of data, select the mean time for the frame and then approximate the location for the other points based on the point closest to the mean.

This is very close to the strategy I disregarded earlier where I use the know distance between the cars to guess where carA is based on carC. Because it's a train I can assume that the speed is the same for all cars at any time. In a semi convoy this isn't true, semiACar1 could be slightly slower or faster than semiBcar1.

So by now I think you understand the problem and where I am .

Thanks for your ideas and interest.


问:
How to get all posts in a limited date range in Instagram Graph API?
I need to retrieve all posts from the instagram page associated to my business account.

The Instagram API documentation does not mention any way to get media only between a certain period.

I´ve tried a analog request with the one I use in Facebook API

```<code>/{my_business_account_id}/media/?limit=100&period=day&access_token={my_user_access_token}&since=2019-02-23&until=2019-02-24&fields=id,caption,like_count,media_type,media_url,timestamp,permalink,username
</code>```

That request works but ignores the since / until parameters and retrieve literally all my posts.

How do I limit the date range of the retrieved posts?

答:
Answer is here: https://stackoverflow.com/a/50946962/5696380:

Unfortunately the since and until parameters are not supported on
  this endpoint and this endpoint has only support cursor based
  pagination.

Body:
I need to retrieve all posts from the instagram page associated to my business account.

The Instagram API documentation does not mention any way to get media only between a certain period.

I´ve tried a analog request with the one I use in Facebook API

/{my_business_account_id}/media/?limit=100&period=day&access_token={my_user_access_token}&since=2019-02-23&until=2019-02-24&fields=id,caption,like_count,media_type,media_url,timestamp,permalink,username

That request works but ignores the since / until parameters and retrieve literally all my posts.

How do I limit the date range of the retrieved posts?


问:
How to make entire screen inactive (darken) under a popup widget in flutter (similar to showDialog)?
I have an "add" floating action button in Scaffold. When clicking the "add" floating action button, it will create two more floating action buttons above the original floating action button so that the user can choose which floating action button to click.

When the two more floating action buttons are active/popup, I want the entire screen to go blur/dark and inactive, similar to the effect to call showDialog(). So that only the three floating action buttons are active and all other screen parts are inactive and dark/blur.

And finally by clicking the inactive area, the two floating action buttons will be dismissed.

Thank you very much for your help.

答:
I found two ways to achieve this.

With PopupRoute

I read flutter framework code and found out showDialog is actually using PopupRoute. Basically, this will create a new route and make the previous routepage inactive.

The simplest code is as follows:

class MyPopupRoute extends PopupRoute<void> {
  @override
  Color get barrierColor => Colors.black54;

  @override
  bool get barrierDismissible => true;
  @override
  String get barrierLabel => "Close";

  @override
  Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) => MyPopupPage();

  @override
  Duration get transitionDuration => const Duration(milliseconds: 300);
}
```

where MyPopupPage is the new popup widget.

If you want animations, you can override the method buildTransitions method. Simply check the API doc for more detail.

With Overlay

Thank @01leo very much for providing this way. The Flutter Challenge: Feature Discovery video has detail explanation on how to use it. Basically, just use Overlay.of(context).insert(overlayEntry); and the overlay is like a hidden stack on the top of the current page built-in.

At the time I am writing this answer, the code provided by the video author is not working in the latest fluter (dart 2). You have to wrap the overlay insert in a Timer such as Timer.run(() { Overlay.of(context).insert(calendarOverlay);}); to workaround the problem and make the code run.

By my findings, the reason why the author needs an async function call for overlay insert is because it couples the creation of overlay and the normal widget in a stateful widget. And when the state changes, the overlay insert will be called before building the child's widget and overlay needs to know the child's position but the child's widget is not created yet. If you don't want to async call overlay insert, you can simply decouple the creation of overlay and the corresponding normal widget. In such a way, you can simply call overlay insert normally. But with this sync way, you may not be able to find the normal widget position easily though.
(Btw, I use the word "normal widget" here, but it's not very correct. I haven't found a proper English word for it.)

Body:
I found two ways to achieve this.

With PopupRoute

I read flutter framework code and found out showDialog is actually using PopupRoute. Basically, this will create a new route and make the previous routepage inactive.

The simplest code is as follows:

class MyPopupRoute extends PopupRoute<void> {
  @override
  Color get barrierColor => Colors.black54;

  @override
  bool get barrierDismissible => true;
  @override
  String get barrierLabel => "Close";

  @override
  Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) => MyPopupPage();

  @override
  Duration get transitionDuration => const Duration(milliseconds: 300);
}

where MyPopupPage is the new popup widget.

If you want animations, you can override the method buildTransitions method. Simply check the API doc for more detail.

With Overlay

Thank @01leo very much for providing this way. The Flutter Challenge: Feature Discovery video has detail explanation on how to use it. Basically, just use Overlay.of(context).insert(overlayEntry); and the overlay is like a hidden stack on the top of the current page built-in.

At the time I am writing this answer, the code provided by the video author is not working in the latest fluter (dart 2). You have to wrap the overlay insert in a Timer such as Timer.run(() { Overlay.of(context).insert(calendarOverlay);}); to workaround the problem and make the code run.

By my findings, the reason why the author needs an async function call for overlay insert is because it couples the creation of overlay and the normal widget in a stateful widget. And when the state changes, the overlay insert will be called before building the child's widget and overlay needs to know the child's position but the child's widget is not created yet. If you don't want to async call overlay insert, you can simply decouple the creation of overlay and the corresponding normal widget. In such a way, you can simply call overlay insert normally. But with this sync way, you may not be able to find the normal widget position easily though.
(Btw, I use the word "normal widget" here, but it's not very correct. I haven't found a proper English word for it.)


问:
My insertion python sort is always placing the second number at the beginning
my code is working mostly fine except for a small bug where it is placing the second element at the beginning no matter the value e.g. 1,6,2,9,3,8,4,7,5,0 would become 6,0,1,2,3,4,5,7,8,9

I've tried altering the numbers in the FOR loop a bit but other than that genuinely cannot see what's wrong

```<code>def InsertionSort(array):
    for i in range(len(array)):
        for j in range(len(array)):
            if array[i] <= array[j+1]:
                new = array.pop(i)
                array.insert(j+1,new)
                break
            elif array[i] > array[j+1]:
                continue
        print (array)
</code>```

答:
Any time you modify the collection you are looping over, you can get different behavior than what you expect. This is especially true when you are removing items from the collection since it messes with the current index.

Here is an example that simply swaps the orders of elements (and also prints debug information along the way so you can see exactly what is happening):

```<code>def insertionSort(my_list):
    # for every element in our array
    for index in range(1, len(my_list)):
        current = my_list[index]
        position = index

        while position > 0 and my_list[position-1] > current:
            print("Swapped {} for {}".format(my_list[position], my_list[position-1]))
            my_list[position] = my_list[position-1]
            print(my_list)
            position -= 1

        my_list[position] = current

    return my_list

my_list = [8,2,1,3,5,4]

print(insertionSort(my_list))
</code>```

Body:
my code is working mostly fine except for a small bug where it is placing the second element at the beginning no matter the value e.g. 1,6,2,9,3,8,4,7,5,0 would become 6,0,1,2,3,4,5,7,8,9

I've tried altering the numbers in the FOR loop a bit but other than that genuinely cannot see what's wrong

def InsertionSort(array):
    for i in range(len(array)):
        for j in range(len(array)):
            if array[i] <= array[j+1]:
                new = array.pop(i)
                array.insert(j+1,new)
                break
            elif array[i] > array[j+1]:
                continue
        print (array)

Body:
Any time you modify the collection you are looping over, you can get different behavior than what you expect. This is especially true when you are removing items from the collection since it messes with the current index.

Here is an example that simply swaps the orders of elements (and also prints debug information along the way so you can see exactly what is happening):

def insertionSort(my_list):
    # for every element in our array
    for index in range(1, len(my_list)):
        current = my_list[index]
        position = index

        while position > 0 and my_list[position-1] > current:
            print("Swapped {} for {}".format(my_list[position], my_list[position-1]))
            my_list[position] = my_list[position-1]
            print(my_list)
            position -= 1

        my_list[position] = current

    return my_list

my_list = [8,2,1,3,5,4]

print(insertionSort(my_list))