问:
Java sort string both alphabetically and keep ASCII order
The list is: Arrays.asList("Za", "ab", "AB", "Sa", "1ab", "Ab", "!Ab");

If I use stream().sorted() then the order is: !Ab 1ab AB Ab Za ab --> Za should not be in front of ab.

If I use sorted(String.CASE_INSENSITIVE_ORDER) then the order is !Ab 1ab ab AB Ab Za --> This time, AB is behind ab.

Is there any way to combine the two rules so we have list sorted alphabetically and uppercase is greater than lower case?

Added Example: 1AB - A0B - AbD - aBD - abd1 - ZAB
Sorted alphabetically (Z is  never in front of a) and Number >  Uppercase > Lowercase (AbD > aBD)

答:
Write a comparator class like this:

```<code>import java.util.Comparator;

public class CustomComparator implements Comparator<String> {

    @Override
    public int compare(String o1, String o2) {
        int result = o1.compareToIgnoreCase(o2);
        if(result==0)
            result = o1.compareTo(o2);
        return result;
    }

}
</code>```

And then where you call the sort function, pass an object of the comparator:

```<code>stream().sorted(new CustomComparator());
</code>```

Body:
Write a comparator class like this:

import java.util.Comparator;

public class CustomComparator implements Comparator<String> {

    @Override
    public int compare(String o1, String o2) {
        int result = o1.compareToIgnoreCase(o2);
        if(result==0)
            result = o1.compareTo(o2);
        return result;
    }

}

And then where you call the sort function, pass an object of the comparator:

stream().sorted(new CustomComparator());


来源: stackexchange

问:
ionic 3 html5 p tag not expanding for size of text content css not working also
I am trying to make a html5 p tag display minimum 3 lines of a description inside an ionic 3 ion-item tag as shown below:

```<code>             <ion-item>
                <ion-avatar item-start>
                  <img src="{{company.logo_url}}" alt="company_logo" *ngIf="company.logo_url">
                </ion-avatar>
                <h2>{{ company.company_name }}</h2>
                <p class="desc-line">{{ company.description_short }}</p>
              </ion-item>

</code>```

The scss I tried to use was:

```<code>.desc-line {
    display:inline-block;
  }
</code>```

Which didn't work so I also tried:

```<code>.desc-line {
display: -webkit-box;
overflow : hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
</code>```

Now I have no idea of what to try next that will make sense and haven't found any other similar solutions.

答:
I have not tried this solution but I think it will work,

you can set minimum height, for example:

```<code>.desc-line {
  min-height: 30px !important;
}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I am trying to make a html5 p tag display minimum 3 lines of a description inside an ionic 3 ion-item tag as shown below:

             <ion-item>
                <ion-avatar item-start>

                </ion-avatar>

{{ company.company_name }}

{{ company.description_short }}

              </ion-item>

The scss I tried to use was:

.desc-line {
    display:inline-block;
  }

Which didn't work so I also tried:

.desc-line {
display: -webkit-box;
overflow : hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}

Now I have no idea of what to try next that will make sense and haven't found any other similar solutions.

Body:
I have not tried this solution but I think it will work,

you can set minimum height, for example:

.desc-line {
  min-height: 30px !important;
}


问:
How should i catch and handle 406 error in VUEJS
I have a route where i send to the api the day and h to verify in database if there is an opening in a schedule, if is not the api is sending 406. And i'm getting in console 406 error.
How should i handle that error to have a clean console? </p>

答:
If you are using Axios for API calls you can create a global interceptor and return a response based on your status code to your component.
This would go in your main.js.</p>

```<code>axios.interceptors.response.use(null, function(error) {
    console.log(error);
 if(err.response.status === 406){
       //your code here.
    }
    return Promise.reject(error);
});
</code>```

Body:
If you are using Axios for API calls you can create a global interceptor and return a response based on your status code to your component.
This would go in your main.js.

axios.interceptors.response.use(null, function(error) {
    console.log(error);
 if(err.response.status === 406){
       //your code here.
    }
    return Promise.reject(error);
});


问:
Can I set/use Nodejs environment in a browser?
Here is my specific problem: I want to use a custom http.agent for a websocket connection using engine.io-client. The problem is, I'm using electron, therefore I'm in a chromium environment, and I can't use a custom http.agent outside a nodejs environnement

agent (http.Agent): http.Agent to use, defaults to false (NodeJS only)

Any idea how to 'simulate' a nodejs environnement if I'm in a browser?

hope I'm clear enough

答: Electron is both a browser and a node.js environment, so yes you can use it.


问:
My For Loop is listing the break command as an output. How do I prevent this?
What happens is that when I hit the enter key to break the loop, it will count me breaking the loop as an output.
Example
1. Guest Name
2. Guest Name
3.                        < (Hit the enter key to activate break command)
This is my code.</p>

答:
Put if block just after input command in for loop.</p>

```<code>for iii in range(1, 1000):
    guests = input("....")
    if guests.lower() == "":
        break
    output = output + str(iii) + "." +guests
</code>```

Body:
Put if block just after input command in for loop.

for iii in range(1, 1000):
    guests = input("....")
    if guests.lower() == "":
        break
    output = output + str(iii) + "." +guests


问:
Glassfish admin console slow loading
Today I stopped/started my GlassfishV3 instance and now I cannot access the addmin console located at http://servername:4848/. The screen says:  "The admin console is loading..." This is going on forever now.

I have tried as follows:

I have tried adding the following entry to my domain.xml located at /glassfishv3/glassfish/domains/domain1/config as suggested in another Stack Overflow Q&A but after restarting the server still no luck.

<java-options>-Dcom.sun.enterprise.tools.admingui.NO_NETWORK=true</java-options>

I have also installed glassfishv3 on my local machine and cannot recreate the problem.I can go to http://localhost:4848 without any problem.

I have also looked at the server.log and jvm.log files located under the /glassfishv3/glassfish/domains/domain1/logs and nothing there that shed some light.

Any help would be very much appreciated

答:
I found a solution to my problem. Setting the java-option to NO_NETWORK to true did not work so I upgraded from 3.0.1 to 3.1 and it got fixed. Not immediately though, I had to stop/start the Glassfish server a couple of times before I got into the admin console without any really long delays.

Solution

The solution was to upgrade from the command line using the pkg utility.

You can find the steps in this link:
http://download.oracle.com/docs/cd/E18930_01/html/821-2437/gkthu.html#gktjf

Or do as follows:

Go to as-install-parent/bin

./pkg image-update

as-install-parent/glassfish/bin/asadmin start-domain --upgrade domain-name

as-install-parent/glassfish/bin/asadmin start-domain domain-name

UPDATE
I had peformance issues again and I found this other solution in Joshi's tech blog:
http://joshitech.blogspot.com/2009/09/glassfish-application-server.html

Basically add the following jvm options in the domain.xml. It should increase Glassfish boot up and deployment performance:

```<code><jvm-options>-server</jvm-options>
<jvm-options>-Xms3000m</jvm-options>
<jvm-options>-Xmx3000m</jvm-options>
<jvm-options>-XX:MaxPermSize=192m</jvm-options>
<jvm-options>-XX:NewRatio=2</jvm-options>
<jvm-options>-XX:+AggressiveHeap</jvm-options>
<jvm-options>-XX:+AggressiveOpts</jvm-options>
<jvm-options>-XX:+UseParallelGC</jvm-options>
<jvm-options>-XX:+UseParallelOldGC</jvm-options>
<jvm-options>-XX:ParallelGCThreads=5</jvm-options>
</code>```

ContentLicense: CC BY-SA 3.0

Title: Glassfish admin console slow loading

Body:
I found a solution to my problem. Setting the java-option to NO_NETWORK to true did not work so I upgraded from 3.0.1 to 3.1 and it got fixed. Not immediately though, I had to stop/start the Glassfish server a couple of times before I got into the admin console without any really long delays.

Solution

The solution was to upgrade from the command line using the pkg utility.

You can find the steps in this link:
http://download.oracle.com/docs/cd/E18930_01/html/821-2437/gkthu.html#gktjf

Or do as follows:

Go to as-install-parent/bin

./pkg image-update

as-install-parent/glassfish/bin/asadmin start-domain --upgrade domain-name

as-install-parent/glassfish/bin/asadmin start-domain domain-name

UPDATE
I had peformance issues again and I found this other solution in Joshi's tech blog:
http://joshitech.blogspot.com/2009/09/glassfish-application-server.html

Basically add the following jvm options in the domain.xml. It should increase Glassfish boot up and deployment performance:

<jvm-options>-server</jvm-options>
<jvm-options>-Xms3000m</jvm-options>
<jvm-options>-Xmx3000m</jvm-options>
<jvm-options>-XX:MaxPermSize=192m</jvm-options>
<jvm-options>-XX:NewRatio=2</jvm-options>
<jvm-options>-XX:+AggressiveHeap</jvm-options>
<jvm-options>-XX:+AggressiveOpts</jvm-options>
<jvm-options>-XX:+UseParallelGC</jvm-options>
<jvm-options>-XX:+UseParallelOldGC</jvm-options>
<jvm-options>-XX:ParallelGCThreads=5</jvm-options>


问:
How to get which route called a component
I am using react-route-dom, I want to implement this config:

```<code><Route exact path='/test/:id' component={MyComponent}/>
<Route exact path='/test2/:id' component={MyComponent}/>
</code>```

then in MyComponent, I want to make something different depending on which route is calling it.

```<code>const MyComponent = ({info: {param}, info2: {param1, param2}}) => {

  return (
    <div>

    </div>

  )
}

MyComponent.propTypes = {
  info: PropTypes.object.isRequired,
  info2: PropTypes.object.isRequired,
};

const mapStateToProps = (state) => ({
  info: state.info,
  info2: state.info2
});

export default connect(mapStateToProps, {})(MyComponent);
</code>```

How can I get the test or test2 params?

答:
You can send it via props:</p>

```<code><Route exact path='/test/:id'>
  <MyComponent route={'test'} />
</Route>
</code>```

Body:
I am using react-route-dom, I want to implement this config:

<Route exact path='/test/:id' component={MyComponent}/>
<Route exact path='/test2/:id' component={MyComponent}/>

then in MyComponent, I want to make something different depending on which route is calling it.

const MyComponent = ({info: {param}, info2: {param1, param2}}) => {

  return (

  )
}

MyComponent.propTypes = {
  info: PropTypes.object.isRequired,
  info2: PropTypes.object.isRequired,
};

const mapStateToProps = (state) => ({
  info: state.info,
  info2: state.info2
});

export default connect(mapStateToProps, {})(MyComponent);

How can I get the test or test2 params?

Body:
You can send it via props:

<Route exact path='/test/:id'>
  <MyComponent route={'test'} />
</Route>


问:
Stopped maven install
I am testing a spring boot project with it default pom.xml like that.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
</project>
```

<p>When I am trying to run the command <code>mvn clean install</code> the below two exceptions ProjectBuildingException and UnresolvableModelException appeared like below</p>

<pre class="lang-none prettyprint-override"><code>[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.4.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 5, column 10
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.example:demo:0.0.1-SNAPSHOT (C:\Users\User\Desktop\demo\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.4.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 5, column 10: Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.240.215] failed: Connection timed out: connect -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
</code>```

答:
This exactly same pom works fine for me without any change. must be some firewall blocking your connections to https://repo.maven.apache.org

check if you can open this from internet browser if yes, check network connections settings in your IDE and put proxy settings if required.

```<code>"C:\Program Files\Java\jdk1.8.0_152\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\Workspace\demo -Dmaven.home=D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven3 -Dclassworlds.conf=D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven3\bin\m2.conf -Dmaven.ext.class.path=D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven-event-listener.jar -javaagent:D:\Portables\IdeaIC-2019.2.3.win\lib\idea_rt.jar=1330:D:\Portables\IdeaIC-2019.2.3.win\bin -Dfile.encoding=UTF-8 -classpath D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version2019.2.3 clean compile
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom (8.1 kB at 4.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.2.4.RELEASE/spring-boot-dependencies-2.2.4.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.2.4.RELEASE/spring-boot-dependencies-2.2.4.RELEASE.pom (127 kB at 83 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-bom/2.10.2/jackson-bom-2.10.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-bom/2.10.2/jackson-bom-2.10.2.pom (13 kB at 20 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-parent/2.10/jackson-parent-2.10.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-parent/2.10/jackson-parent-2.10.pom (8.3 kB at 13 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/fasterxml/oss-parent/38/oss-parent-38.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/fasterxml/oss-parent/38/oss-parent-38.pom (23 kB at 36 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/micrometer/micrometer-bom/1.3.2/micrometer-bom-1.3.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/micrometer/micrometer-bom/1.3.2/micrometer-bom-1.3.2.pom (6.6 kB at 10 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/netty/netty-bom/4.1.45.Final/netty-bom-4.1.45.Final.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/netty/netty-bom/4.1.45.Final/netty-bom-4.1.45.Final.pom (7.9 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/projectreactor/reactor-bom/Dysprosium-SR4/reactor-bom-Dysprosium-SR4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/projectreactor/reactor-bom/Dysprosium-SR4/reactor-bom-Dysprosium-SR4.pom (4.1 kB at 6.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/rsocket/rsocket-bom/1.0.0-RC5/rsocket-bom-1.0.0-RC5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/rsocket/rsocket-bom/1.0.0-RC5/rsocket-bom-1.0.0-RC5.pom (3.0 kB at 4.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/logging/log4j/log4j-bom/2.12.1/log4j-bom-2.12.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/logging/log4j/log4j-bom/2.12.1/log4j-bom-2.12.1.pom (7.2 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-bom/9.4.25.v20191220/jetty-bom-9.4.25.v20191220.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-bom/9.4.25.v20191220/jetty-bom-9.4.25.v20191220.pom (17 kB at 27 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jersey/jersey-bom/2.29.1/jersey-bom-2.29.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/jersey/jersey-bom/2.29.1/jersey-bom-2.29.1.pom (19 kB at 28 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/ee4j/project/1.0.5/project-1.0.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/ee4j/project/1.0.5/project-1.0.5.pom (13 kB at 21 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-bom/1.3.61/kotlin-bom-1.3.61.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-bom/1.3.61/kotlin-bom-1.3.61.pom (8.8 kB at 14 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-bom/1.3.3/kotlinx-coroutines-bom-1.3.3.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-bom/1.3.3/kotlinx-coroutines-bom-1.3.3.pom (5.0 kB at 7.8 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.5.2/junit-bom-5.5.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.5.2/junit-bom-5.5.2.pom (4.4 kB at 7.0 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/5.2.3.RELEASE/spring-framework-bom-5.2.3.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/5.2.3.RELEASE/spring-framework-bom-5.2.3.RELEASE.pom (5.3 kB at 8.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/data/spring-data-releasetrain/Moore-SR4/spring-data-releasetrain-Moore-SR4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/data/spring-data-releasetrain/Moore-SR4/spring-data-releasetrain-Moore-SR4.pom (4.8 kB at 7.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/data/build/spring-data-build/2.2.4.RELEASE/spring-data-build-2.2.4.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/data/build/spring-data-build/2.2.4.RELEASE/spring-data-build-2.2.4.RELEASE.pom (7.1 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/integration/spring-integration-bom/5.2.3.RELEASE/spring-integration-bom-5.2.3.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/integration/spring-integration-bom/5.2.3.RELEASE/spring-integration-bom-5.2.3.RELEASE.pom (9.0 kB at 14 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/security/spring-security-bom/5.2.1.RELEASE/spring-security-bom-5.2.1.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/security/spring-security-bom/5.2.1.RELEASE/spring-security-bom-5.2.1.RELEASE.pom (5.4 kB at 8.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/session/spring-session-bom/Corn-RELEASE/spring-session-bom-Corn-RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/session/spring-session-bom/Corn-RELEASE/spring-session-bom-Corn-RELEASE.pom (2.8 kB at 4.4 kB/s)
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.pom (5.2 kB at 8.2 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/31/maven-plugins-31.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/31/maven-plugins-31.pom (10 kB at 16 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/31/maven-parent-31.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/31/maven-parent-31.pom (43 kB at 65 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.jar (30 kB at 35 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.pom (7.2 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.jar (32 kB at 38 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.pom (12 kB at 19 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.jar (62 kB at 88 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.pom (770 B at 1.2 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.7.1/plexus-containers-1.7.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.7.1/plexus-containers-1.7.1.pom (5.0 kB at 7.8 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.pom (5.6 kB at 8.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.jar (4.3 kB at 5.9 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.jar (167 kB at 71 kB/s)
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.pom (4.7 kB at 7.3 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.jar (262 kB at 175 kB/s)
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.pom (5.1 kB at 8.0 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-languages/0.9.10/plexus-languages-0.9.10.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-languages/0.9.10/plexus-languages-0.9.10.pom (4.1 kB at 6.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.pom (2.9 kB at 4.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/ow2/ow2/1.5/ow2-1.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/ow2/ow2/1.5/ow2-1.5.pom (11 kB at 18 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.pom (16 kB at 23 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.pom (867 B at 1.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler/2.8.4/plexus-compiler-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler/2.8.4/plexus-compiler-2.8.4.pom (6.0 kB at 9.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.pom (692 B at 1.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.pom (771 B at 1.2 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compilers/2.8.4/plexus-compilers-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compilers/2.8.4/plexus-compilers-2.8.4.pom (1.3 kB at 2.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.jar
Downloading from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.jar (39 kB at 42 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.jar (27 kB at 29 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar (21 kB at 13 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.jar (4.7 kB at 2.7 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.jar (111 kB at 42 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar (317 kB at 96 kB/s)
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  44.402 s
[INFO] Finished at: 2020-02-20T16:59:52+05:30
[INFO] ------------------------------------------------------------------------
</code>```

Title: Stopped maven install

Body:
I am testing a spring boot project with it default pom.xml like that.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
</project>

When I am trying to run the command mvn clean install the below two exceptions ProjectBuildingException and UnresolvableModelException appeared like below

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.4.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 5, column 10
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.example:demo:0.0.1-SNAPSHOT (C:\Users\User\Desktop\demo\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.4.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 5, column 10: Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.240.215] failed: Connection timed out: connect -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

Body:
This exactly same pom works fine for me without any change. must be some firewall blocking your connections to https://repo.maven.apache.org

check if you can open this from internet browser if yes, check network connections settings in your IDE and put proxy settings if required.

"C:\Program Files\Java\jdk1.8.0_152\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\Workspace\demo -Dmaven.home=D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven3 -Dclassworlds.conf=D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven3\bin\m2.conf -Dmaven.ext.class.path=D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven-event-listener.jar -javaagent:D:\Portables\IdeaIC-2019.2.3.win\lib\idea_rt.jar=1330:D:\Portables\IdeaIC-2019.2.3.win\bin -Dfile.encoding=UTF-8 -classpath D:\Portables\IdeaIC-2019.2.3.win\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version2019.2.3 clean compile
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom (8.1 kB at 4.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.2.4.RELEASE/spring-boot-dependencies-2.2.4.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.2.4.RELEASE/spring-boot-dependencies-2.2.4.RELEASE.pom (127 kB at 83 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-bom/2.10.2/jackson-bom-2.10.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-bom/2.10.2/jackson-bom-2.10.2.pom (13 kB at 20 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-parent/2.10/jackson-parent-2.10.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/jackson-parent/2.10/jackson-parent-2.10.pom (8.3 kB at 13 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/fasterxml/oss-parent/38/oss-parent-38.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/fasterxml/oss-parent/38/oss-parent-38.pom (23 kB at 36 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/micrometer/micrometer-bom/1.3.2/micrometer-bom-1.3.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/micrometer/micrometer-bom/1.3.2/micrometer-bom-1.3.2.pom (6.6 kB at 10 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/netty/netty-bom/4.1.45.Final/netty-bom-4.1.45.Final.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/netty/netty-bom/4.1.45.Final/netty-bom-4.1.45.Final.pom (7.9 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/projectreactor/reactor-bom/Dysprosium-SR4/reactor-bom-Dysprosium-SR4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/projectreactor/reactor-bom/Dysprosium-SR4/reactor-bom-Dysprosium-SR4.pom (4.1 kB at 6.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/rsocket/rsocket-bom/1.0.0-RC5/rsocket-bom-1.0.0-RC5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/io/rsocket/rsocket-bom/1.0.0-RC5/rsocket-bom-1.0.0-RC5.pom (3.0 kB at 4.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/logging/log4j/log4j-bom/2.12.1/log4j-bom-2.12.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/logging/log4j/log4j-bom/2.12.1/log4j-bom-2.12.1.pom (7.2 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-bom/9.4.25.v20191220/jetty-bom-9.4.25.v20191220.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-bom/9.4.25.v20191220/jetty-bom-9.4.25.v20191220.pom (17 kB at 27 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jersey/jersey-bom/2.29.1/jersey-bom-2.29.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/jersey/jersey-bom/2.29.1/jersey-bom-2.29.1.pom (19 kB at 28 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/ee4j/project/1.0.5/project-1.0.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/ee4j/project/1.0.5/project-1.0.5.pom (13 kB at 21 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-bom/1.3.61/kotlin-bom-1.3.61.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-bom/1.3.61/kotlin-bom-1.3.61.pom (8.8 kB at 14 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-bom/1.3.3/kotlinx-coroutines-bom-1.3.3.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-bom/1.3.3/kotlinx-coroutines-bom-1.3.3.pom (5.0 kB at 7.8 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.5.2/junit-bom-5.5.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.5.2/junit-bom-5.5.2.pom (4.4 kB at 7.0 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/5.2.3.RELEASE/spring-framework-bom-5.2.3.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/5.2.3.RELEASE/spring-framework-bom-5.2.3.RELEASE.pom (5.3 kB at 8.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/data/spring-data-releasetrain/Moore-SR4/spring-data-releasetrain-Moore-SR4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/data/spring-data-releasetrain/Moore-SR4/spring-data-releasetrain-Moore-SR4.pom (4.8 kB at 7.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/data/build/spring-data-build/2.2.4.RELEASE/spring-data-build-2.2.4.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/data/build/spring-data-build/2.2.4.RELEASE/spring-data-build-2.2.4.RELEASE.pom (7.1 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/integration/spring-integration-bom/5.2.3.RELEASE/spring-integration-bom-5.2.3.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/integration/spring-integration-bom/5.2.3.RELEASE/spring-integration-bom-5.2.3.RELEASE.pom (9.0 kB at 14 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/security/spring-security-bom/5.2.1.RELEASE/spring-security-bom-5.2.1.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/security/spring-security-bom/5.2.1.RELEASE/spring-security-bom-5.2.1.RELEASE.pom (5.4 kB at 8.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/session/spring-session-bom/Corn-RELEASE/spring-session-bom-Corn-RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/session/spring-session-bom/Corn-RELEASE/spring-session-bom-Corn-RELEASE.pom (2.8 kB at 4.4 kB/s)
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.pom (5.2 kB at 8.2 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/31/maven-plugins-31.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/31/maven-plugins-31.pom (10 kB at 16 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/31/maven-parent-31.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/31/maven-parent-31.pom (43 kB at 65 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.1.0/maven-clean-plugin-3.1.0.jar (30 kB at 35 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.pom (7.2 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.1.0/maven-resources-plugin-3.1.0.jar (32 kB at 38 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.pom (12 kB at 19 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.jar (62 kB at 88 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.pom (770 B at 1.2 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.7.1/plexus-containers-1.7.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.7.1/plexus-containers-1.7.1.pom (5.0 kB at 7.8 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.pom (5.6 kB at 8.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.jar (4.3 kB at 5.9 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.jar (167 kB at 71 kB/s)
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.pom (4.7 kB at 7.3 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.jar (262 kB at 175 kB/s)
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.pom (5.1 kB at 8.0 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-languages/0.9.10/plexus-languages-0.9.10.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-languages/0.9.10/plexus-languages-0.9.10.pom (4.1 kB at 6.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.pom (2.9 kB at 4.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/ow2/ow2/1.5/ow2-1.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/ow2/ow2/1.5/ow2-1.5.pom (11 kB at 18 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.pom (16 kB at 23 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.pom (867 B at 1.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler/2.8.4/plexus-compiler-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler/2.8.4/plexus-compiler-2.8.4.pom (6.0 kB at 9.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.pom (692 B at 1.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.pom (771 B at 1.2 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compilers/2.8.4/plexus-compilers-2.8.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compilers/2.8.4/plexus-compilers-2.8.4.pom (1.3 kB at 2.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.jar
Downloading from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.jar (39 kB at 42 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.jar (27 kB at 29 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar (21 kB at 13 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.jar (4.7 kB at 2.7 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.jar (111 kB at 42 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar (317 kB at 96 kB/s)
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  44.402 s
[INFO] Finished at: 2020-02-20T16:59:52+05:30
[INFO] ------------------------------------------------------------------------


问:
My search box doesn't recognize 0 like character PHP
I have search box and button to search inside MySQL table. And it works well. But when I inset 0 in my search box it gaves me error message (that I set it): Enter a word to search . This is my HTML for search box and button :

```<code><form method="post" class="form-inline my-2 my-lg-0 navbar navbar-expand-lg navbar-light bg-info">
            <input name="search" class="form-control mr-sm-2" placeholder="Search" aria-label="Search">
            <button name="submit-search" class="btn  my-2 my-sm-0 bg-white" type="submit">Search</button>
        </form>
</code>```

And my function search():

```<code>function search()
{
    if (empty($_POST['search'])) {
        $_SESSION['message'] = "Enter a word to search";
        $_SESSION['msg_type'] = "warning";
        return;
    }
    $keyword = '%' . $_POST['search'] . '%';
    $database = new Database;
    $db = $database->dbConnection();
    $stmt = $db->query("SELECT * FROM posts WHERE id LIKE '$keyword' OR userId LIKE '$keyword' OR title LIKE '$keyword'  OR completed LIKE  '$keyword'");

    $count = $stmt->rowCount(); //num di record trovati
    if ($count > 0) {
        $_SESSION['message'] = "Found items: " . $count;
        $_SESSION['msg_type'] = "success";
    } else {
        $_SESSION['message'] = "No article match with: " . $_POST['search'];//it results this message. I don't get it why don't recognize that character(0).
        $_SESSION['msg_type'] = "warning";
        //header("location: allart.php");
    } ?>

    <div class="container" style=" margin-top:5%;">
        <table class=" table table-hover" id="search-table" style="font-size: 18px;">
            <hr>
            <div style="text-align:center;"> <label style="text-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1), 10px 10px 10px rgba(0, 0, 0, 0.2); font-size:30px;border-radius: 45px; "> Results from search : </label></div> <br>
            <tr>
                <th>User ID:</th>
                <th> ID: </th>
                <th> Title: </th>
                <th> Compiled: </th>
            </tr>

            <?php while ($row = $stmt->fetch()) : ?>
                <tr>
                    <td> <?php echo $row['userId'] ?> </td>
                    <td> <?php echo $row['id'] ?> </td>
                    <td> <?php echo $row['title'] ?> </td>
                    <td> <?php echo $row['completed'] ? 'Compiled' : 'Not Compiled' ?> </td>
                </tr>
            <?php endwhile ?>
        </table>
    </div>
<?php }
</code>```

It works well. But when I insert 0 in my search box it seems like he does not recognize the character shows the error message that I set it .
I check my MySQL table and I found rows where id =10. So when I insert 0 in my search bar it should result that row with id = 10. I don't get it why it can't find any word that contains 0.

Any suggestion how to fix this?
Thanks!

答:
Your problem is that from PHP's standpoint, 0 is basically 'empty'. Instead of checking for this...

```<code>if (empty($_POST['search'])) {
</code>```

.. try checking for whether it's set or not:

```<code>if (!isset($_POST['search'])) {
</code>```

See a demo of this approach here:
https://3v4l.org/osfXH

Edit: I missed the exclamation mark, thanks! :)

Body:
I have search box and button to search inside MySQL table. And it works well. But when I inset 0 in my search box it gaves me error message (that I set it): Enter a word to search . This is my HTML for search box and button :

<form method="post" class="form-inline my-2 my-lg-0 navbar navbar-expand-lg navbar-light bg-info">
            <input name="search" class="form-control mr-sm-2" placeholder="Search" aria-label="Search">
            <button name="submit-search" class="btn  my-2 my-sm-0 bg-white" type="submit">Search</button>
        </form>

And my function search():

function search()
{
    if (empty($_POST['search'])) {
        $_SESSION['message'] = "Enter a word to search";
        $_SESSION['msg_type'] = "warning";
        return;
    }
    $keyword = '%' . $_POST['search'] . '%';
    $database = new Database;
    $db = $database->dbConnection();
    $stmt = $db->query("SELECT * FROM posts WHERE id LIKE '$keyword' OR userId LIKE '$keyword' OR title LIKE '$keyword'  OR completed LIKE  '$keyword'");

    $count = $stmt->rowCount(); //num di record trovati
    if ($count > 0) {
        $_SESSION['message'] = "Found items: " . $count;
        $_SESSION['msg_type'] = "success";
    } else {
        $_SESSION['message'] = "No article match with: " . $_POST['search'];//it results this message. I don't get it why don't recognize that character(0).
        $_SESSION['msg_type'] = "warning";
        //header("location: allart.php");
    } ?>

  Results from search :

                User ID:
                 ID:
                 Title:
                 Compiled:

            <?php while ($row = $stmt->fetch()) : ?>

                     <?php echo $row['userId'] ?>
                     <?php echo $row['id'] ?>
                     <?php echo $row['title'] ?>
                     <?php echo $row['completed'] ? 'Compiled' : 'Not Compiled' ?>

            <?php endwhile ?>

<?php }

It works well. But when I insert 0 in my search box it seems like he does not recognize the character shows the error message that I set it .
I check my MySQL table and I found rows where id =10. So when I insert 0 in my search bar it should result that row with id = 10. I don't get it why it can't find any word that contains 0.

Any suggestion how to fix this?
Thanks!

Body:
Your problem is that from PHP's standpoint, 0 is basically 'empty'. Instead of checking for this...

if (empty($_POST['search'])) {

.. try checking for whether it's set or not:

if (!isset($_POST['search'])) {

See a demo of this approach here:
https://3v4l.org/osfXH

Edit: I missed the exclamation mark, thanks! :)


问:
Expose service using nginx-ingress
All my pod work in the server.

```<code>NAMESPACE       NAME                                              READY   STATUS    RESTARTS   AGE
default         user-api-66fc4fc9d-igqnj                          3/3     Running   0          25s
ingress-nginx   nginx-ingress-controller-5556bd698f-qgw8r         1/1     Running   0          12h
kube-system     coredns-6955765f44-4xnhh                          1/1     Running   1          40h
kube-system     coredns-6955765f44-6tb8p                          1/1     Running   1          40h
kube-system     etcd-izbp1dyjigsfwmw0dtl85gz                      1/1     Running   1          40h
kube-system     kube-apiserver-izbp1dyjigsfwmw0dtl85gz            1/1     Running   1          40h
kube-system     kube-controller-manager-izbp1dyjigsfwmw0dtl85gz   1/1     Running   1          40h
kube-system     kube-flannel-ds-amd64-8b5pc                       1/1     Running   0          40h
kube-system     kube-flannel-ds-amd64-jq4kl                       1/1     Running   1          40h
kube-system     kube-proxy-9zx7c                                  1/1     Running   1          40h
kube-system     kube-proxy-lh55j                                  1/1     Running   0          40h
kube-system     kube-scheduler-izbp1dyjigsfwmw0dtl85gz            1/1     Running   1          40h
</code>```

The ingress I create.

```<code>NAME          HOSTS                ADDRESS   PORTS   AGE
app-ingress   example.com                    80      5h16m
</code>```

I create ClusterIP service for my single deployment, and using loadBalance ingress-nginx controller with resource file to expose internal service. The relative code show under below.

```<code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user-api
  strategy: {}
  template:
    metadata:
      labels:
        app: user-api
    spec:
      dnsPolicy: ClusterFirstWithHostNet
      hostNetwork: true
      containers:
      - name: user-api
        image: doumeyi/user-api-amd64:1.0
        ports:
        - name: user-api
          containerPort: 3000
        resources: {}
---
apiVersion: v1
kind: Service
metadata:
  name: user-api
spec:
  selector:
    app: user-api
  ports:
  - name: user-api
    port: 3000
    targetPort: 3000
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: example.com
      http:
        paths:
        - path: /user-api
          backend:
            serviceName: user-api
            servicePort: 3000
</code>```

It seems any problem with the ingress-nginx service, the external ip is always pending.

```<code>NAMESPACE       NAME            TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                        AGE
ingress-nginx   ingress-nginx   LoadBalancer   10.104.176.152   <pending>     80:31612/TCP,443:30097/TCP                     13h
</code>```

答:
Please change service definition and specify proper port :

```<code>apiVersion: v1
kind: Service
metadata:
  name: user-api
spec:
  selector:
    app: user-api
  ports:
    - name: user-api
    - port: 3000
      targetPort: 80
  type: LoadBalancer
</code>```

Traffic from the external load balancer is directed at the backend Pods. The cloud provider decides how it is load balanced.

For LoadBalancer type of Services, when there is more than one port defined, all ports must have the same protocol and the protocol must be one of TCP, UDP, and SCTP.

Some cloud providers allow you to specify the loadBalancerIP. In those cases, the load-balancer is created with the user-specified loadBalancerIP. If the loadBalancerIP field is not specified, the loadBalancer is set up with an ephemeral IP address. If you specify a loadBalancerIP but your cloud provider does not support the feature, the loadbalancerIP field that you set is ignored.

Also if you are using nginx ingress controller please remove dnspolicy and hostnetwork from Deployment configuration file and then apply changes ( $ kubectl apply -f your-deployment-conf-file.yaml).

More infromation you can find here: nginx-troubleshooting, nginx-ingress.

Title: Expose service using nginx-ingress

Body:
All my pod work in the server.

NAMESPACE       NAME                                              READY   STATUS    RESTARTS   AGE
default         user-api-66fc4fc9d-igqnj                          3/3     Running   0          25s
ingress-nginx   nginx-ingress-controller-5556bd698f-qgw8r         1/1     Running   0          12h
kube-system     coredns-6955765f44-4xnhh                          1/1     Running   1          40h
kube-system     coredns-6955765f44-6tb8p                          1/1     Running   1          40h
kube-system     etcd-izbp1dyjigsfwmw0dtl85gz                      1/1     Running   1          40h
kube-system     kube-apiserver-izbp1dyjigsfwmw0dtl85gz            1/1     Running   1          40h
kube-system     kube-controller-manager-izbp1dyjigsfwmw0dtl85gz   1/1     Running   1          40h
kube-system     kube-flannel-ds-amd64-8b5pc                       1/1     Running   0          40h
kube-system     kube-flannel-ds-amd64-jq4kl                       1/1     Running   1          40h
kube-system     kube-proxy-9zx7c                                  1/1     Running   1          40h
kube-system     kube-proxy-lh55j                                  1/1     Running   0          40h
kube-system     kube-scheduler-izbp1dyjigsfwmw0dtl85gz            1/1     Running   1          40h

The ingress I create.

NAME          HOSTS                ADDRESS   PORTS   AGE
app-ingress   example.com                    80      5h16m

I create ClusterIP service for my single deployment, and using loadBalance ingress-nginx controller with resource file to expose internal service. The relative code show under below.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user-api
  strategy: {}
  template:
    metadata:
      labels:
        app: user-api
    spec:
      dnsPolicy: ClusterFirstWithHostNet
      hostNetwork: true
      containers:
      - name: user-api
        image: doumeyi/user-api-amd64:1.0
        ports:
        - name: user-api
          containerPort: 3000
        resources: {}
---
apiVersion: v1
kind: Service
metadata:
  name: user-api
spec:
  selector:
    app: user-api
  ports:
  - name: user-api
    port: 3000
    targetPort: 3000
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: example.com
      http:
        paths:
        - path: /user-api
          backend:
            serviceName: user-api
            servicePort: 3000

It seems any problem with the ingress-nginx service, the external ip is always pending.

NAMESPACE       NAME            TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                        AGE
ingress-nginx   ingress-nginx   LoadBalancer   10.104.176.152   <pending>     80:31612/TCP,443:30097/TCP                     13h

Body:
Please change service definition and specify proper port :

apiVersion: v1
kind: Service
metadata:
  name: user-api
spec:
  selector:
    app: user-api
  ports:
    - name: user-api
    - port: 3000
      targetPort: 80
  type: LoadBalancer

Traffic from the external load balancer is directed at the backend Pods. The cloud provider decides how it is load balanced.

For LoadBalancer type of Services, when there is more than one port defined, all ports must have the same protocol and the protocol must be one of TCP, UDP, and SCTP.

Some cloud providers allow you to specify the loadBalancerIP. In those cases, the load-balancer is created with the user-specified loadBalancerIP. If the loadBalancerIP field is not specified, the loadBalancer is set up with an ephemeral IP address. If you specify a loadBalancerIP but your cloud provider does not support the feature, the loadbalancerIP field that you set is ignored.

Also if you are using nginx ingress controller please remove dnspolicy and hostnetwork from Deployment configuration file and then apply changes ( $ kubectl apply -f your-deployment-conf-file.yaml).

More infromation you can find here: nginx-troubleshooting, nginx-ingress.


问:
How to replace only part of a word from a string in Python
I have a list of street names

```<code>streetNames = ['WELSESTRAAT', 'HENDRIKLAAN', 'LOMMERWEG']
</code>```

And another list with street abbreviations

```<code>streetAbbr = [['WEG', 'WG'], ['STRAAT', 'STR'],['LAAN', 'LN']]
</code>```

I am trying to loop through street names and replace straat with str, weg with wg and so on
but I am stuck in the replace part as there is no such method for only part of a word.

```<code>for name in streetNames:
    for abbr in streetAbbr:
        if str(abbr[0]) in str(name):
            name.replace('straat', abbr[1]) #doesn't work
</code>```

答:
The issue here is that replace() function finds a blank space in order to replace strings. Since there is only a single word in your array, it's not working.

@Yatu's answer is correct but in case you don't want to update the data structures in your code, you can use this use-case specific solution.

```<code>for name in streetNames:
    for abbr in streetAbbr:
        if abbr[0] in name:
            new_str = name.split(abbr[0])
            name = f"{new_str[0]}{abbr[1]}"
            print(name)
</code>```

This solution may not work if there are multiple occurrences of the same substring in the names because of the usage of split. But since there are no such examples provided in the question it was assumed that this should work.

Body:
I have a list of street names

streetNames = ['WELSESTRAAT', 'HENDRIKLAAN', 'LOMMERWEG']

And another list with street abbreviations

streetAbbr = [['WEG', 'WG'], ['STRAAT', 'STR'],['LAAN', 'LN']]

I am trying to loop through street names and replace straat with str, weg with wg and so on
but I am stuck in the replace part as there is no such method for only part of a word.

for name in streetNames:
    for abbr in streetAbbr:
        if str(abbr[0]) in str(name):
            name.replace('straat', abbr[1]) #doesn't work

Body:
The issue here is that replace() function finds a blank space in order to replace strings. Since there is only a single word in your array, it's not working.

@Yatu's answer is correct but in case you don't want to update the data structures in your code, you can use this use-case specific solution.

for name in streetNames:
    for abbr in streetAbbr:
        if abbr[0] in name:
            new_str = name.split(abbr[0])
            name = f"{new_str[0]}{abbr[1]}"
            print(name)

This solution may not work if there are multiple occurrences of the same substring in the names because of the usage of split. But since there are no such examples provided in the question it was assumed that this should work.


问:
Sql query to get output on the basis of 3 columns in oracle SQL
I have a scenario where i have 3 coloumns i.e liqn_days , liq_months and liqn_years .
So if liqn_days have value and others are 0 then print Monthly .
or liq_months  is 3 others are 0 then get output as quartely.
or liq_months  is 6 and others coloumns are 0 then output will be half yearly
or liqn_years  is having value or others are 0 then output will be  yearly.

```<code>liqn_days  liq_months  liqn_years

0          0            1

12        0             0

0         3             0

ouput for 1st row - Yearly
ouput for 2st row  - Monthly
output for 3rd row - quarterly
</code>```

Please assist me in this .

答:
You can aswell user union all

```<code>WITH da(Other_columns,liqn_years, liq_months, liqn_days) AS (
SELECT 'Other_colums', 0,0,1 FROM dual
UNION ALL SELECT 'Other_colums',12,0,0 FROM dual
UNION ALL SELECT 'Other_colums',0,3,0 FROM dual
)
SELECT Other_columns, 'Yearly' AS output  FROM da WHERE liqn_years > 0
UNION ALL
SELECT Other_columns, 'Monthly' AS output  FROM da WHERE liqn_years > 0
UNION ALL
SELECT Other_columns, 'quaterly' AS output  FROM da WHERE liqn_years > 0
</code>```

Result

```<code>OTHER_COLUMNS|OUTPUT  |
-------------|--------|
Other_colums |Yearly  |
Other_colums |Monthly |
Other_colums |quaterly|
</code>```

Body:
I have a scenario where i have 3 coloumns i.e liqn_days , liq_months and liqn_years .
So if liqn_days have value and others are 0 then print Monthly .
or liq_months  is 3 others are 0 then get output as quartely.
or liq_months  is 6 and others coloumns are 0 then output will be half yearly
or liqn_years  is having value or others are 0 then output will be  yearly.

liqn_days  liq_months  liqn_years

0          0            1

12        0             0

0         3             0

ouput for 1st row - Yearly
ouput for 2st row  - Monthly
output for 3rd row - quarterly

Please assist me in this .

Body:
You can aswell user union all

WITH da(Other_columns,liqn_years, liq_months, liqn_days) AS (
SELECT 'Other_colums', 0,0,1 FROM dual
UNION ALL SELECT 'Other_colums',12,0,0 FROM dual
UNION ALL SELECT 'Other_colums',0,3,0 FROM dual
)
SELECT Other_columns, 'Yearly' AS output  FROM da WHERE liqn_years > 0
UNION ALL
SELECT Other_columns, 'Monthly' AS output  FROM da WHERE liqn_years > 0
UNION ALL
SELECT Other_columns, 'quaterly' AS output  FROM da WHERE liqn_years > 0

Result

OTHER_COLUMNS|OUTPUT  |
-------------|--------|
Other_colums |Yearly  |
Other_colums |Monthly |
Other_colums |quaterly|


问:
MySQL query runs very slow
I have a MySQL (v5.7.26) query that runs forever. Here is the query:

```<code>SELECT
    ur.user_id      AS user_id,
    sum(r.duration) AS total_time,
    count(user_id)  AS number_of_workouts
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE
    ur.status = 1
    AND NOT ur.action_date IS NULL
    AND ur.user_id IN (
        SELECT user_id
        FROM user_resource ur2
        WHERE ur2.action_date >= now() - INTERVAL 2 DAY
    )
    AND r.type = 'WORKOUT'
    GROUP BY ur.user_id;
</code>```

I have played a bit with it, by trying to understand where is the problem. For the testing purposes, I tried breaking in two. So:

```<code>SELECT user_id
FROM user_resource ur2
WHERE ur2.action_date >= now() - INTERVAL 2 DAY;
</code>```

That returns (very quickly) list of user user_id's.
When I plug the returned result in to the first part of the query, like this:

```<code>SELECT
    ur.user_id      AS user_id,
    sum(r.duration) AS total_time,
    count(user_id)  AS number_of_workouts
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE
    ur.status = 1
    AND NOT ur.action_date IS NULL
    AND ur.user_id IN (1,1,1,4,4,5,6,7,7,7);
      AND r.type = 'WORKOUT'
GROUP BY ur.user_id
</code>```

It runs very fast. My assumption is the IN (Subquery) is the bottleneck.

I was thinking to extract the subquery and get the user_ids, and then used it as a variable, but I am not sure is it the good approach, and additionally I am having issues with it. this is my attempt:

```<code>-- first statement
SET @v1 = (SELECT user_id
FROM user_resource ur2
WHERE ur2.action_date >= now() - INTERVAL 2 DAY)

-- second statement
SELECT
    ur.user_id      AS user_id,
    sum(r.duration) AS total_time,
    count(user_id)  AS prefixes
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE
    ur.status = 1
    AND NOT ur.action_date IS NULL
    AND ur.user_id IN (@v1);
    AND r.type = 'WORKOUT'
GROUP BY ur.user_id
</code>```

Problem here is that the first statement returns an error:

Subquery returns more than 1 row.

Expected result are user_id's, that can be duplicates. And I need those duplicated for the count.

How can I fix this?

答:
You could try:

-- first statement
SET @v1 = (SELECT GROUP_CONCAT(user_id)
FROM user_resource ur2
WHERE ur2.action_date >= now() - INTERVAL 2 DAY)
```

<pre class="lang-sql prettyprint-override"><code>-- second statement
SELECT
ur.user_id      AS user_id,
 sum(r.duration) AS total_time,
 count(user_id)  AS prefixes
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE ur.status = 1 AND NOT ur.action_date IS NULL AND FIND_IN_SET(ur.user_id,@v1)
AND r.type = 'WORKOUT'
GROUP BY ur.user_id
</code>```

Title: MySQL query runs very slow

Body:
I have a MySQL (v5.7.26) query that runs forever. Here is the query:

SELECT
    ur.user_id      AS user_id,
    sum(r.duration) AS total_time,
    count(user_id)  AS number_of_workouts
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE
    ur.status = 1
    AND NOT ur.action_date IS NULL
    AND ur.user_id IN (
        SELECT user_id
        FROM user_resource ur2
        WHERE ur2.action_date >= now() - INTERVAL 2 DAY
    )
    AND r.type = 'WORKOUT'
    GROUP BY ur.user_id;

I have played a bit with it, by trying to understand where is the problem. For the testing purposes, I tried breaking in two. So:

SELECT user_id
FROM user_resource ur2
WHERE ur2.action_date >= now() - INTERVAL 2 DAY;

That returns (very quickly) list of user user_id's.
When I plug the returned result in to the first part of the query, like this:

SELECT
    ur.user_id      AS user_id,
    sum(r.duration) AS total_time,
    count(user_id)  AS number_of_workouts
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE
    ur.status = 1
    AND NOT ur.action_date IS NULL
    AND ur.user_id IN (1,1,1,4,4,5,6,7,7,7);
      AND r.type = 'WORKOUT'
GROUP BY ur.user_id

It runs very fast. My assumption is the IN (Subquery) is the bottleneck.

I was thinking to extract the subquery and get the user_ids, and then used it as a variable, but I am not sure is it the good approach, and additionally I am having issues with it. this is my attempt:

-- first statement
SET @v1 = (SELECT user_id
FROM user_resource ur2
WHERE ur2.action_date >= now() - INTERVAL 2 DAY)

-- second statement
SELECT
    ur.user_id      AS user_id,
    sum(r.duration) AS total_time,
    count(user_id)  AS prefixes
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE
    ur.status = 1
    AND NOT ur.action_date IS NULL
    AND ur.user_id IN (@v1);
    AND r.type = 'WORKOUT'
GROUP BY ur.user_id

Problem here is that the first statement returns an error:

Subquery returns more than 1 row.

Expected result are user_id's, that can be duplicates. And I need those duplicated for the count.

How can I fix this?

Body:
You could try:

-- first statement
SET @v1 = (SELECT GROUP_CONCAT(user_id)
FROM user_resource ur2
WHERE ur2.action_date >= now() - INTERVAL 2 DAY)

-- second statement
SELECT
ur.user_id      AS user_id,
 sum(r.duration) AS total_time,
 count(user_id)  AS prefixes
FROM user_resource ur
INNER JOIN resource r ON r.id = ur.resource_id
WHERE ur.status = 1 AND NOT ur.action_date IS NULL AND FIND_IN_SET(ur.user_id,@v1)
AND r.type = 'WORKOUT'
GROUP BY ur.user_id


问:
Verhoeff Checksum function for PostgresSQL
I've found a Verhoeff Checksum function for PostgresSQL at: https://github.com/HIISORG/SNOMED-CT-PostgreSQL/blob/master/Verhoeff.sql

```<code>CREATE OR REPLACE FUNCTION verhoeff_generate (
  input numeric = NULL::numeric
)
RETURNS smallint AS $$
DECLARE
  _c SMALLINT := 0;
  _m SMALLINT;
  _i SMALLINT := 0;
  _n VARCHAR(255);
  -- Delcare array
  _d CHAR(100) := '0123456789123406789523401789563401289567401239567859876043216598710432765982104387659321049876543210';
  _p CHAR(80) := '01234567891576283094580379614289160435279453126870428657390127938064157046913258';
  _v CHAR(10) := '0432156789';
BEGIN
  _n := REVERSE(input::TEXT);
  WHILE _i<length(_n) LOOP
    _m := CAST(SUBSTRING(_p,(((_i + 1)%8)*10) + CAST(SUBSTRING(_n, _i+1, 1) AS SMALLINT) + 1, 1) AS SMALLINT);

    _c := CAST (substring(_d, (_c *10 + _m + 1), 1) AS SMALLINT);
    _i := _i + 1;
  END LOOP;

  RETURN CONCAT(input, CAST(substring(_v,_c+1,1) as SMALLINT));
END; $$
LANGUAGE 'plpgsql'
IMMUTABLE
RETURNS NULL ON NULL INPUT;
</code>```

I've modified the RETURN, so that it would concatenate the INPUT with the Checksum digit:

```<code>RETURN CONCAT(input, CAST(substring(_v,_c+1,1) as SMALLINT));
</code>```

And I get the error:

```<code>[2020-02-20 11:53:19] [22003] ERROR: value "331010000014" is out of range for type smallint
[2020-02-20 11:53:19] Where: PL/pgSQL function verhoeff_generate(numeric) while casting return value to function's return type
</code>```

I've tried:

```<code> RETURN CONCAT(input, CAST(substring(_v,_c+1,1) as BIGINT));
</code>```

Still getting the same error.

答:
You've modified the code that gives the return value, away from the original smallint it was returning, to now be a string. (CONCAT function outputs a string - you can cast numbers as many times as you like before you feed them into concat, but they will be converted into strings and then concatenated, and concat outputs a string, no matter what you feed into it).

CONCAT is now returning you a string containing too many digits (it is too numerically large) to fit into a smallint - a conversion that PG is attempting to carry out implicitly for you. This represents the core problem:

```<code>CREATE OR REPLACE FUNCTION return_big_number ()
RETURNS smallint AS $$
  RETURN '32769'; --string of a number that is too big for a smallint
END; $$
</code>```

'32769' is a string that cannot be converted to a smallint, because it's simply too numerically great - smallint caps out at 32767. Similarly by using concat, you're generating a string that contains digits representing a number too numerically large for a smallint

Either change the function declaration at the top so that it returns a suitable string:

```<code>RETURNS smallint AS $$
        ^^^^^^^^
       change this to perhaps "RETURNS text AS $$"
</code>```

Or if having the output as numeric would suit you better, change the function so it declares to return a numeric datatype that can represent more digits than a smallint, and change the return value calculation to keep it numeric (multiply the input by some power of 10, and add the checksum, rather than changing the input to string and concatenating the checksum)

Body:
I've found a Verhoeff Checksum function for PostgresSQL at: https://github.com/HIISORG/SNOMED-CT-PostgreSQL/blob/master/Verhoeff.sql

CREATE OR REPLACE FUNCTION verhoeff_generate (
  input numeric = NULL::numeric
)
RETURNS smallint AS $$
DECLARE
  _c SMALLINT := 0;
  _m SMALLINT;
  _i SMALLINT := 0;
  _n VARCHAR(255);
  -- Delcare array
  _d CHAR(100) := '0123456789123406789523401789563401289567401239567859876043216598710432765982104387659321049876543210';
  _p CHAR(80) := '01234567891576283094580379614289160435279453126870428657390127938064157046913258';
  _v CHAR(10) := '0432156789';
BEGIN
  _n := REVERSE(input::TEXT);
  WHILE _i<length(_n) LOOP
    _m := CAST(SUBSTRING(_p,(((_i + 1)%8)*10) + CAST(SUBSTRING(_n, _i+1, 1) AS SMALLINT) + 1, 1) AS SMALLINT);

    _c := CAST (substring(_d, (_c *10 + _m + 1), 1) AS SMALLINT);
    _i := _i + 1;
  END LOOP;

  RETURN CONCAT(input, CAST(substring(_v,_c+1,1) as SMALLINT));
END; $$
LANGUAGE 'plpgsql'
IMMUTABLE
RETURNS NULL ON NULL INPUT;

I've modified the RETURN, so that it would concatenate the INPUT with the Checksum digit:

RETURN CONCAT(input, CAST(substring(_v,_c+1,1) as SMALLINT));

And I get the error:

[2020-02-20 11:53:19] [22003] ERROR: value "331010000014" is out of range for type smallint
[2020-02-20 11:53:19] Where: PL/pgSQL function verhoeff_generate(numeric) while casting return value to function's return type

I've tried:

 RETURN CONCAT(input, CAST(substring(_v,_c+1,1) as BIGINT));

Still getting the same error.

Body:
You've modified the code that gives the return value, away from the original smallint it was returning, to now be a string. (CONCAT function outputs a string - you can cast numbers as many times as you like before you feed them into concat, but they will be converted into strings and then concatenated, and concat outputs a string, no matter what you feed into it).

CONCAT is now returning you a string containing too many digits (it is too numerically large) to fit into a smallint - a conversion that PG is attempting to carry out implicitly for you. This represents the core problem:

CREATE OR REPLACE FUNCTION return_big_number ()
RETURNS smallint AS $$
  RETURN '32769'; --string of a number that is too big for a smallint
END; $$

'32769' is a string that cannot be converted to a smallint, because it's simply too numerically great - smallint caps out at 32767. Similarly by using concat, you're generating a string that contains digits representing a number too numerically large for a smallint

Either change the function declaration at the top so that it returns a suitable string:

RETURNS smallint AS $$
        ^^^^^^^^
       change this to perhaps "RETURNS text AS $$"

Or if having the output as numeric would suit you better, change the function so it declares to return a numeric datatype that can represent more digits than a smallint, and change the return value calculation to keep it numeric (multiply the input by some power of 10, and add the checksum, rather than changing the input to string and concatenating the checksum)


问:
grass.script + scipy theilsen regression slope and intercept between values of two rasters
I need to compute TheilSen regression slope and intercept between values of two rasters in a GRASS GIS python script. The two rasters in this example (xtile and ytile) are both of the same dimensions 250x250 pixels and contain nodata (null) values.
I have so far used grass.script alone, so I am new to scipy. I tried to read some tutorials and based on that came up with following code I tried on command-line:

```<code>>>> from scipy import stats
>>> import grass.script as grass
>>> import grass.script.array as garray
>>> x = garray.array(mapname="xtile")
>>> y = garray.array(mapname="ytile")
>>> res_list = stats.theilslopes(y, x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/scipy/stats/_stats_mstats_common.py", line 214, in theilslopes
    deltax = x[:, np.newaxis] - x
MemoryError
</code>```

Evidently, it would not be so simple.
Edit: I removed my thoughts about the problem being dimensionality of the array, I was wrong. Now it seems the 250x250 array size is simply too much. Is it so? Any idea how to evade this?

Then there is another problem it seems. When I try to print the array x,

```<code>>>> print x
[[  0.   0.   0. ...   0.   0.   0.]
 [  0.   0.   0. ...   0.   0.   0.]
 [  0. 402.   0. ...   0.   0.   0.]
 ...
 [  0.   0.   0. ...   0.   0.   0.]
 [  0.   0.   0. ...   0.   0.   0.]
 [  0.   0.   0. ...   0.   0.   0.]]
</code>```

it appears all the nodata values from the raster got read as zeroes into the array. In the raster in question there is majority of nodata (or null as named in GRASS) pixels, which should be ignored in the regression, ie. if any value within the rasters x or y is nodata, corresponding pair of x,y data should not be used in the regression computation. Is it possible to define nodata values in the arrays so that these would be ignored directly in the manner described, or is it needded to first filter out the nodata pairs from the pair of arrays?

Thank you.

答:
I am not sure it is appropriate to answer my own question, but maybe it would be useful for others with similar problem.

I was able to finally make it work. The working (i.e. it computes something) modified example solves both problems mentioned in original question:

```<code>>>> from scipy import stats
>>> import grass.script as grass
>>> import grass.script.array as garray
>>> x = garray.array(mapname="xtile").reshape(-1)
>>> y = garray.array(mapname="ytile").reshape(-1)
>>> # Now the null raster values are changed to zeroes.
>>> # Let us filter them out by pairs of x, y values for any pair which contains a zero value.
>>> xfiltered = np.array([])
>>> yfiltered = np.array([])
>>> i = 0
>>> for xi in np.nditer(x):
...    if x[i] > 0:
...       if y[i] > 0:
...          xfiltered = np.append(xfiltered, [x[i]])
...          yfiltered = np.append(yfiltered, [y[i]])
...    i += 1
...
>>> # Compute the regression.
>>> res_list = stats.theilslopes(yfiltered, xfiltered)
>>> res_list
(0.8738738738738738, -26.207207207207148, 0.8327338129496403, 0.9155844155844156)
</code>```

Explanation: I filtered out all zero values which were nodata in the original rasters (and possibly negative values as well, there should not be any and if they were, it would mean defective data - physical meaning of the data is quantized reflectance) before regression computation. The use of reshape was not necessary for the stats.theilslopes, as I experimentally verified with a test data, but it makes the filtering of the two arrays much easier.

Now, I am still not sure why the filtering was needed for the stats.theilslopes to finish without errors (although with all the zeroes in the data the results would be wrong anyway). It could be, that filtering out the zeroes just made the the set small enough to fit in memory, but i do not believe so. I think that the majority zero values make it impossible to compute median slope of the pairs of x,y points, since in case majority of points have identical x,y values, then also majority of their pairs have undefined slope and median is about the majority. But it could be something entirely else.

Also, as I am not very skilled Python programmer, maybe the way I did this is not the most efficient one. That could be corrected by others.

Last remark, I probably have the x and y data reversed, if y are the dependent and x the independent variables. Intuitively I felt they should be in y,x order, but I see in all the tutorials and docs it is always x,y. I left it as it was in the original question, since you can search the inverse formula x=f(y) regression line in some cases and this is not part of the problem I was trying to solve.

Body:
I need to compute TheilSen regression slope and intercept between values of two rasters in a GRASS GIS python script. The two rasters in this example (xtile and ytile) are both of the same dimensions 250x250 pixels and contain nodata (null) values.
I have so far used grass.script alone, so I am new to scipy. I tried to read some tutorials and based on that came up with following code I tried on command-line:

>>> from scipy import stats
>>> import grass.script as grass
>>> import grass.script.array as garray
>>> x = garray.array(mapname="xtile")
>>> y = garray.array(mapname="ytile")
>>> res_list = stats.theilslopes(y, x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/scipy/stats/_stats_mstats_common.py", line 214, in theilslopes
    deltax = x[:, np.newaxis] - x
MemoryError

Evidently, it would not be so simple.
Edit: I removed my thoughts about the problem being dimensionality of the array, I was wrong. Now it seems the 250x250 array size is simply too much. Is it so? Any idea how to evade this?

Then there is another problem it seems. When I try to print the array x,

>>> print x
[[  0.   0.   0. ...   0.   0.   0.]
 [  0.   0.   0. ...   0.   0.   0.]
 [  0. 402.   0. ...   0.   0.   0.]
 ...
 [  0.   0.   0. ...   0.   0.   0.]
 [  0.   0.   0. ...   0.   0.   0.]
 [  0.   0.   0. ...   0.   0.   0.]]

it appears all the nodata values from the raster got read as zeroes into the array. In the raster in question there is majority of nodata (or null as named in GRASS) pixels, which should be ignored in the regression, ie. if any value within the rasters x or y is nodata, corresponding pair of x,y data should not be used in the regression computation. Is it possible to define nodata values in the arrays so that these would be ignored directly in the manner described, or is it needded to first filter out the nodata pairs from the pair of arrays?

Thank you.

Body:
I am not sure it is appropriate to answer my own question, but maybe it would be useful for others with similar problem.

I was able to finally make it work. The working (i.e. it computes something) modified example solves both problems mentioned in original question:

>>> from scipy import stats
>>> import grass.script as grass
>>> import grass.script.array as garray
>>> x = garray.array(mapname="xtile").reshape(-1)
>>> y = garray.array(mapname="ytile").reshape(-1)
>>> # Now the null raster values are changed to zeroes.
>>> # Let us filter them out by pairs of x, y values for any pair which contains a zero value.
>>> xfiltered = np.array([])
>>> yfiltered = np.array([])
>>> i = 0
>>> for xi in np.nditer(x):
...    if x[i] > 0:
...       if y[i] > 0:
...          xfiltered = np.append(xfiltered, [x[i]])
...          yfiltered = np.append(yfiltered, [y[i]])
...    i += 1
...
>>> # Compute the regression.
>>> res_list = stats.theilslopes(yfiltered, xfiltered)
>>> res_list
(0.8738738738738738, -26.207207207207148, 0.8327338129496403, 0.9155844155844156)

Explanation: I filtered out all zero values which were nodata in the original rasters (and possibly negative values as well, there should not be any and if they were, it would mean defective data - physical meaning of the data is quantized reflectance) before regression computation. The use of reshape was not necessary for the stats.theilslopes, as I experimentally verified with a test data, but it makes the filtering of the two arrays much easier.

Now, I am still not sure why the filtering was needed for the stats.theilslopes to finish without errors (although with all the zeroes in the data the results would be wrong anyway). It could be, that filtering out the zeroes just made the the set small enough to fit in memory, but i do not believe so. I think that the majority zero values make it impossible to compute median slope of the pairs of x,y points, since in case majority of points have identical x,y values, then also majority of their pairs have undefined slope and median is about the majority. But it could be something entirely else.

Also, as I am not very skilled Python programmer, maybe the way I did this is not the most efficient one. That could be corrected by others.

Last remark, I probably have the x and y data reversed, if y are the dependent and x the independent variables. Intuitively I felt they should be in y,x order, but I see in all the tutorials and docs it is always x,y. I left it as it was in the original question, since you can search the inverse formula x=f(y) regression line in some cases and this is not part of the problem I was trying to solve.


问:
Struggling to understand the result of the "Outer" applied on two arrays via the subtraction being used as the vectorized FUN
I'm trying to undrestand the outer in R. Here is my test case:

```<code>myarray <- array(data = c(0,5,7,3), dim = c(2,2))
myarray
outer_op <- outer(myarray, myarray, "-")
outer_op
</code>```

Based on what I've understood (or I'd rather say misunderstood) so far, each element in the array will be associated via FUN, a vectorized function, which in my test case is the subtraction operator, with all other elements in the array, therefore each time a pair of values. So the following is what I would excpect R to print if I had to do the outer operation by hand on a piece of paper:

```<code>, , 1, 1

     [,1] [,2]
[1,]    0   -7
[2,]   -5   -3

, , 2, 1

     [,1] [,2]
[1,]   -5    2
[2,]    0   -2

, , 1, 2

     [,1] [,2]
[1,]   -7    0
[2,]   -2   -4

, , 2, 2

     [,1] [,2]
[1,]   -3    4
[2,]    2    0
</code>```

What I've done, is that I took each element at the position
(i,j) = (row, column) and I've subtracted each time from one of other elements in the matrix.
So for example for the first matrix (, , 1, 1) here is what I've done:

```<code>0 - 0 = 0       = new element at the first row and first column after outer.
0 - 5 = -5      = new element at the second row and first column after outer.
0 - 7 = -7      = new element at the first row and second column after outer.
0 - 3 = -3      = new element at the second row and second column after outer.
</code>```

But it seems that I don't understand the concept as the result provided by
R is compltey different:

```<code>, , 1, 1

     [,1] [,2]
[1,]    0    7
[2,]    5    3

, , 2, 1

     [,1] [,2]
[1,]   -5    2
[2,]    0   -2

, , 1, 2

     [,1] [,2]
[1,]   -7    0
[2,]   -2   -4

, , 2, 2

     [,1] [,2]
[1,]   -3    4
[2,]    2    0
</code>```

So I don't really get how R has done the subtraction between elements to
provide theses matrixes. I'd appreciate if you could kindly make some
clarifications.

答:
If you start with myarray and subtract myarray[1,1] you get

```<code>myarray - myarray[1, 1]
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
</code>```

Then if you take myarray and subtract myarray[2, 1] you get

```<code>myarray - myarray[2, 1]
#>      [,1] [,2]
#> [1,]   -5    2
#> [2,]    0   -2
</code>```

And so on.

So basically the order of subtraction is just reversed from how you have done it by hand. It starts with myarray and subtracts a single number (taken from the second copy of myarray) from the whole of the first array to give each resultant slice.

You can see this more clearly if you use an array full of zeros and exchange the order:

zeroarray <- array(data = c(0, 0, 0, 0), dim = c(2, 2))
outer(myarray, zeroarray, "-")
#> , , 1, 1
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
#>
#> , , 2, 1
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
#>
#> , , 1, 2
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
#>
#> , , 2, 2
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
```

<p>Now reverse the order and each element of <code>myarray</code> is taken away from the zero array:</p>

```outer(zeroarray, myarray, "-")
#> , , 1, 1
#>
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0
#>
#> , , 2, 1
#>
#>      [,1] [,2]
#> [1,]   -5   -5
#> [2,]   -5   -5
#>
#> , , 1, 2
#>
#>      [,1] [,2]
#> [1,]   -7   -7
#> [2,]   -7   -7
#>
#> , , 2, 2
#>
#>      [,1] [,2]
#> [1,]   -3   -3
#> [2,]   -3   -3
```

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

Body:
I'm trying to undrestand the outer in R. Here is my test case:

myarray <- array(data = c(0,5,7,3), dim = c(2,2))
myarray
outer_op <- outer(myarray, myarray, "-")
outer_op

Based on what I've understood (or I'd rather say misunderstood) so far, each element in the array will be associated via FUN, a vectorized function, which in my test case is the subtraction operator, with all other elements in the array, therefore each time a pair of values. So the following is what I would excpect R to print if I had to do the outer operation by hand on a piece of paper:

, , 1, 1

     [,1] [,2]
[1,]    0   -7
[2,]   -5   -3

, , 2, 1

     [,1] [,2]
[1,]   -5    2
[2,]    0   -2

, , 1, 2

     [,1] [,2]
[1,]   -7    0
[2,]   -2   -4

, , 2, 2

     [,1] [,2]
[1,]   -3    4
[2,]    2    0

What I've done, is that I took each element at the position
(i,j) = (row, column) and I've subtracted each time from one of other elements in the matrix.
So for example for the first matrix (, , 1, 1) here is what I've done:

0 - 0 = 0       = new element at the first row and first column after outer.
0 - 5 = -5      = new element at the second row and first column after outer.
0 - 7 = -7      = new element at the first row and second column after outer.
0 - 3 = -3      = new element at the second row and second column after outer.

But it seems that I don't understand the concept as the result provided by
R is compltey different:

, , 1, 1

     [,1] [,2]
[1,]    0    7
[2,]    5    3

, , 2, 1

     [,1] [,2]
[1,]   -5    2
[2,]    0   -2

, , 1, 2

     [,1] [,2]
[1,]   -7    0
[2,]   -2   -4

, , 2, 2

     [,1] [,2]
[1,]   -3    4
[2,]    2    0

So I don't really get how R has done the subtraction between elements to
provide theses matrixes. I'd appreciate if you could kindly make some
clarifications.

Body:
If you start with myarray and subtract myarray[1,1] you get

myarray - myarray[1, 1]
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3

Then if you take myarray and subtract myarray[2, 1] you get

myarray - myarray[2, 1]
#>      [,1] [,2]
#> [1,]   -5    2
#> [2,]    0   -2

And so on.

So basically the order of subtraction is just reversed from how you have done it by hand. It starts with myarray and subtracts a single number (taken from the second copy of myarray) from the whole of the first array to give each resultant slice.

You can see this more clearly if you use an array full of zeros and exchange the order:

zeroarray <- array(data = c(0, 0, 0, 0), dim = c(2, 2))
outer(myarray, zeroarray, "-")
#> , , 1, 1
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
#>
#> , , 2, 1
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
#>
#> , , 1, 2
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3
#>
#> , , 2, 2
#>
#>      [,1] [,2]
#> [1,]    0    7
#> [2,]    5    3

Now reverse the order and each element of myarray is taken away from the zero array:

outer(zeroarray, myarray, "-")
#> , , 1, 1
#>
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0
#>
#> , , 2, 1
#>
#>      [,1] [,2]
#> [1,]   -5   -5
#> [2,]   -5   -5
#>
#> , , 1, 2
#>
#>      [,1] [,2]
#> [1,]   -7   -7
#> [2,]   -7   -7
#>
#> , , 2, 2
#>
#>      [,1] [,2]
#> [1,]   -3   -3
#> [2,]   -3   -3

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