问:
How to Find Recent or Today’s Modified Files in Linux
I have a requirement that will have to find out latest modified files list along with date and time.
mainly we have 2 files that boot.properties and ldap related files as part of beadmin password change activity.

```<code>find /target_directory -type f -name "*boot.properties" -exec ls -ltr {} \;
</code>```

is giving only boot.properties but I need to find other files which is in different location.

答:
try something like this if you have different location and file names.

```<code>find /root_directory \
\( \( \
 -path "/target_directory1/*" -type f  -name "*boot.properties" \) -o \( \
 -path "/target_directory2/*" -type f  -name "*boot2.properties" \
 \) \) -exec ls -ltr {} \;

</code>```

also, you have other options to find by modified date too.
check this article
https://www.cyberciti.biz/faq/linux-unix-osxfind-files-by-date/

Body:
I have a requirement that will have to find out latest modified files list along with date and time.
mainly we have 2 files that boot.properties and ldap related files as part of beadmin password change activity.

find /target_directory -type f -name "*boot.properties" -exec ls -ltr {} \;

is giving only boot.properties but I need to find other files which is in different location.

Body:
try something like this if you have different location and file names.

find /root_directory \
\( \( \
 -path "/target_directory1/*" -type f  -name "*boot.properties" \) -o \( \
 -path "/target_directory2/*" -type f  -name "*boot2.properties" \
 \) \) -exec ls -ltr {} \;

also, you have other options to find by modified date too.
check this article
https://www.cyberciti.biz/faq/linux-unix-osxfind-files-by-date/


来源: stackexchange

问:
No bean named 'loggingFilter' available error when deploying Spring Boot application in Tomcat
I have a Spring Boot application with Spring Security enabled. When I run it on IntelliJ it works fine and I am able to log in and use the application as expected. But when I try to deploy it on tomcat 8.5.x and 9.x I get the error No bean named 'loggingFilter' available error when deploying the application in Tomcat. Here is the complete log

```<code>08-Feb-2020 00:59:35.839 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log 3 Spring WebApplicationInitializers detected on classpath
08-Feb-2020 00:59:39.959 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
08-Feb-2020 00:59:57.047 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [delegatingFilterProxy]
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'loggingFilter' available
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:805)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1278)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1114)
        at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:338)
        at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:243)
        at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:239)
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:283)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:112)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4546)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5191)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
        at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
        at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
        at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:479)
        at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
        at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
        at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at java.management/com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1406)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
08-Feb-2020 00:59:57.052 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
</code>```

If it helps, I use logback.xml file to show INFO logs

```<code><configuration debug="true" scan="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

</code>```

pom.xml

```<code><properties>
    <java.version>11</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
    <javax.servlet-api.version>3.0.1</javax.servlet-api.version>
    <jsp-api.version>2.2</jsp-api.version>
    <tiles-jsp.version>3.0.8</tiles-jsp.version>
    <json-simple.version>1.1</json-simple.version>
    <commons-fileupload.version>1.3.1</commons-fileupload.version>
    <joda-time.version>2.10.4</joda-time.version>
    <modelmapper.version>2.3.0</modelmapper.version>
    <lombok.version>1.18.10</lombok.version>
    <jackson.version>2.9.3</jackson.version>
    <junit.version>4.12</junit.version>
    <spring-boot.version>2.2.2.RELEASE</spring-boot.version>
    <json.version>20190722</json.version>
    <validation-api.version>2.0.1.Final</validation-api.version>
    <hibernate.version>5.4.10.Final</hibernate.version>
    <mssql-jdbc.version>7.4.1.jre11</mssql-jdbc.version>
    <hazelcast.version>3.12.6</hazelcast.version>
    <jjwt.version>0.9.1</jjwt.version>
</properties>
<dependencies>
        <!-- Spring Core dependencies-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
        </dependency>
        <dependency>
            <groupId>com.unboundid</groupId>
            <artifactId>unboundid-ldapsdk</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <version>${spring-boot.version}</version>
            <optional>false</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <!-- Other Core dependencies-->

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>${mssql-jdbc.version}</version>
        </dependency>

        <!-- Utilities-->
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast</artifactId>
            <version>${hazelcast.version}</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-spring</artifactId>
            <version>${hazelcast.version}</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-hibernate53</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-client</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>${commons-fileupload.version}</version>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>${json.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>${modelmapper.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${validation-api.version}</version>
        </dependency>

        <!-- Test dependencies-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <version>${spring-boot.version}</version>
        </dependency>

    </dependencies>
</code>```

答:
The cause of this exception is straightforward – Spring Security looks for a bean named loggingFilter, and cannot find it. This bean is required by the main Spring Security Filter – the DelegatingFilterProxy – defined in the web.xml

DelegatingFilterProxy is a class in Spring's Web module. It provides features for making HTTP calls pass through filters before reaching the actual destination. With the help of DelegatingFilterProxy, a class implementing the javax.Servlet.Filter interface can be wired into the filter chain.

DelegatingFilterProxy also leverages invoking specific or multiple filters as per Request URI paths by providing the configuration in Spring's application context or in web.xml.

Therefore, you must have a custom filter class and a configuration associated with this class. Check it because there is something you didn't see.

```<code>@Component("loggingFilter")
public class CustomFilter implements Filter {

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void doFilter(
      ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) request;
        LOGGER.info("Request Info : " + req);
        chain.doFilter(request, response);
    }
    @Override
    public void destroy() {
    }
}
</code>```

To register a custom filter using Java settings:

```<code>public class ApplicationInitializer
  extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected javax.servlet.Filter[] getServletFilters() {
        DelegatingFilterProxy delegateFilterProxy = new DelegatingFilterProxy();
        delegateFilterProxy.setTargetBeanName("loggingFilter");
        return new Filter[]{delegateFilterProxy};
    }
}
</code>```

Custom filter using configuration in web.xml

```<code><filter>
    <filter-name>loggingFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>loggingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
</code>```

CustomFilter implements javax.Servlet.Filter. This class has a @Component annotation to register as Spring bean in the application context. This way, the DelegatingFilterProxy class can find our filter class while initializing the filter chain.

Note that the name of the Spring bean must be the same as the value in the filter-name provided during the registration of the custom filter in ApplicationInitializer class or in web.xml later because the DelegatingFilterProxy class will look for the filter bean with the exact same name in the application context.

If it can't find a bean with this name, it will raise an exception at application startup.

You can find more information here.

Something that you can also check is if it is an incompatibility problem between version of Spring and java that you use.

I hope it can help you and in the end find a solution.

ContentLicense: CC BY-SA 4.0

Body:
I have a Spring Boot application with Spring Security enabled. When I run it on IntelliJ it works fine and I am able to log in and use the application as expected. But when I try to deploy it on tomcat 8.5.x and 9.x I get the error No bean named 'loggingFilter' available error when deploying the application in Tomcat. Here is the complete log

08-Feb-2020 00:59:35.839 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log 3 Spring WebApplicationInitializers detected on classpath
08-Feb-2020 00:59:39.959 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
08-Feb-2020 00:59:57.047 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [delegatingFilterProxy]
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'loggingFilter' available
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:805)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1278)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1114)
        at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:338)
        at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:243)
        at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:239)
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:283)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:112)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4546)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5191)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
        at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
        at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
        at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:479)
        at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
        at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
        at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at java.management/com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1406)
        at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
08-Feb-2020 00:59:57.052 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext

If it helps, I use logback.xml file to show INFO logs

<configuration debug="true" scan="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

pom.xml

<properties>
    <java.version>11</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
    <javax.servlet-api.version>3.0.1</javax.servlet-api.version>
    <jsp-api.version>2.2</jsp-api.version>
    <tiles-jsp.version>3.0.8</tiles-jsp.version>
    <json-simple.version>1.1</json-simple.version>
    <commons-fileupload.version>1.3.1</commons-fileupload.version>
    <joda-time.version>2.10.4</joda-time.version>
    <modelmapper.version>2.3.0</modelmapper.version>
    <lombok.version>1.18.10</lombok.version>
    <jackson.version>2.9.3</jackson.version>
    <junit.version>4.12</junit.version>
    <spring-boot.version>2.2.2.RELEASE</spring-boot.version>
    <json.version>20190722</json.version>
    <validation-api.version>2.0.1.Final</validation-api.version>
    <hibernate.version>5.4.10.Final</hibernate.version>
    <mssql-jdbc.version>7.4.1.jre11</mssql-jdbc.version>
    <hazelcast.version>3.12.6</hazelcast.version>
    <jjwt.version>0.9.1</jjwt.version>
</properties>
<dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
        </dependency>
        <dependency>
            <groupId>com.unboundid</groupId>
            <artifactId>unboundid-ldapsdk</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <version>${spring-boot.version}</version>
            <optional>false</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>${mssql-jdbc.version}</version>
        </dependency>

        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast</artifactId>
            <version>${hazelcast.version}</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-spring</artifactId>
            <version>${hazelcast.version}</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-hibernate53</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-client</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>${commons-fileupload.version}</version>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>${json.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>${modelmapper.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${validation-api.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <version>${spring-boot.version}</version>
        </dependency>

    </dependencies>

Body:
The cause of this exception is straightforward – Spring Security looks for a bean named loggingFilter, and cannot find it. This bean is required by the main Spring Security Filter – the DelegatingFilterProxy – defined in the web.xml

DelegatingFilterProxy is a class in Spring's Web module. It provides features for making HTTP calls pass through filters before reaching the actual destination. With the help of DelegatingFilterProxy, a class implementing the javax.Servlet.Filter interface can be wired into the filter chain.

DelegatingFilterProxy also leverages invoking specific or multiple filters as per Request URI paths by providing the configuration in Spring's application context or in web.xml.

Therefore, you must have a custom filter class and a configuration associated with this class. Check it because there is something you didn't see.

@Component("loggingFilter")
public class CustomFilter implements Filter {

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void doFilter(
      ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) request;
        LOGGER.info("Request Info : " + req);
        chain.doFilter(request, response);
    }
    @Override
    public void destroy() {
    }
}

To register a custom filter using Java settings:

public class ApplicationInitializer
  extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected javax.servlet.Filter[] getServletFilters() {
        DelegatingFilterProxy delegateFilterProxy = new DelegatingFilterProxy();
        delegateFilterProxy.setTargetBeanName("loggingFilter");
        return new Filter[]{delegateFilterProxy};
    }
}

Custom filter using configuration in web.xml

<filter>
    <filter-name>loggingFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>loggingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

CustomFilter implements javax.Servlet.Filter. This class has a @Component annotation to register as Spring bean in the application context. This way, the DelegatingFilterProxy class can find our filter class while initializing the filter chain.

Note that the name of the Spring bean must be the same as the value in the filter-name provided during the registration of the custom filter in ApplicationInitializer class or in web.xml later because the DelegatingFilterProxy class will look for the filter bean with the exact same name in the application context.

If it can't find a bean with this name, it will raise an exception at application startup.

You can find more information here.

Something that you can also check is if it is an incompatibility problem between version of Spring and java that you use.

I hope it can help you and in the end find a solution.


问:
Print the result of a Python def
I want to read the date and time of a image by using Pillow.
And now I want to print the result of the def to be shure I got the Date and Time. But when I type print(defname) I just get some weird numbers as the output.

My code:

```<code>import os
import time
import shutil
import re
from PIL import Image, ExifTags
from PIL.ExifTags import TAGS

def get_date_taken(path):
    return Image.open(r"E:\insert_folder\DSC_3389.jpg")._getexif()[36867]

print(get_date_taken)
</code>```

One more thing... If you understand what I want to do and if you understand my code, could you pls check if there is any fault in my code?
Thanks to you guys! <3

答: Functions take magnificent things called parameters. You need to fill get_date_taken with a parameter such as get_date_taken("IMG_0001")

Title: Print the result of a Python def

Body:
I want to read the date and time of a image by using Pillow.
And now I want to print the result of the def to be shure I got the Date and Time. But when I type print(defname) I just get some weird numbers as the output.

My code:

import os
import time
import shutil
import re
from PIL import Image, ExifTags
from PIL.ExifTags import TAGS

def get_date_taken(path):
    return Image.open(r"E:\insert_folder\DSC_3389.jpg")._getexif()[36867]

print(get_date_taken)

One more thing... If you understand what I want to do and if you understand my code, could you pls check if there is any fault in my code?
Thanks to you guys! <3


问:
delete file other than particular extension file format
i have a lot of different type of files in one folder. i need to delete the files but except the pdf file.
I tried to display the pdf file only. but i need to delete the other than pdf files</p>

```<code>ls -1 | xargs file | grep 'PDF document,' | sed 's/:.*//'
</code>```

答:
Try inverting the grep match:</p>

```<code>ls -1 | xargs file | grep -v 'PDF document,' | sed 's/:.*//'
</code>```

ContentLicense: CC BY-SA 3.0

Body:
i have a lot of different type of files in one folder. i need to delete the files but except the pdf file.
I tried to display the pdf file only. but i need to delete the other than pdf files

ls -1 | xargs file | grep 'PDF document,' | sed 's/:.*//'

Body:
Try inverting the grep match:

ls -1 | xargs file | grep -v 'PDF document,' | sed 's/:.*//'


问:
How do you print out a string that has each element of an array four to a line
This is my code

```<code>public String toString() {
    String B = A[0] + " ";
    for (int w = 1; w < this.A.length; w-=-1) {
        B += A[w] + " ";
        if(w % 4 == 0)
            B += "\n";
    }
    return B;
}
</code>```

I am trying to make a string that has each element of my array in it and after every fourth element a new line is added. The output should be something like this:

```<code>AA BB CC DD
EE FF GG HH
II JJ KK LL
MM NN OO PP
</code>```

I am writing a toString method for a java class. The array has 52 elements
Instead I keep getting this as an output:

```<code>1S 4S 6S 2S 8S
8S 7S 3S 7S
6S 8S 5S 6S
3C 3C 1C 8C
8C 9C 4C
</code>```

答:
Using StringBuilder:</p>

```<code>private static void printArray(String[] array) {
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < array.length; i++) {
        if(i > 0 && i % 4 == 0) {
            sb.append("\n");
        }
        sb.append(array[i]);
        sb.append(" ");
    }
    System.out.println(sb);
}
</code>```

Body:
This is my code

public String toString() {
    String B = A[0] + " ";
    for (int w = 1; w < this.A.length; w-=-1) {
        B += A[w] + " ";
        if(w % 4 == 0)
            B += "\n";
    }
    return B;
}

I am trying to make a string that has each element of my array in it and after every fourth element a new line is added. The output should be something like this:

AA BB CC DD
EE FF GG HH
II JJ KK LL
MM NN OO PP

I am writing a toString method for a java class. The array has 52 elements
Instead I keep getting this as an output:

1S 4S 6S 2S 8S
8S 7S 3S 7S
6S 8S 5S 6S
3C 3C 1C 8C
8C 9C 4C

Body:
Using StringBuilder:

private static void printArray(String[] array) {
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < array.length; i++) {
        if(i > 0 && i % 4 == 0) {
            sb.append("\n");
        }
        sb.append(array[i]);
        sb.append(" ");
    }
    System.out.println(sb);
}


问:
Docker-compose failing to start after macOS 10.15.2 Beta (19C39d) Catalina update
Trying to run my docker-compose after upgrading my macOS to latest beta version of Catalina 10.15.2 Beta (19C39d), but I was not able to to do so.

If anyone have a smilier experience please share your fix, since I pretty sure my docker-compose was working before the update.

System Info

Running docker system info

```<code>Client:
 Debug Mode: false

Server:
 Containers: 3
  Running: 0
  Paused: 0
  Stopped: 3
 Images: 37
 Server Version: 19.03.4
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.9.184-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 6
 Total Memory: 1.952GiB
 Name: docker-desktop
 ID: GY6V:NEYP:UYIY:SYOL:ZFWA:CNCY:NVMK:PWYA:MQPQ:AJTS:IDLM:3FWE
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 35
  Goroutines: 50
  System Time: 2019-11-15T22:25:09.226536684Z
  EventsListeners: 2
 HTTP Proxy: gateway.docker.internal:3128
 HTTPS Proxy: gateway.docker.internal:3129
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine
</code>```

Error logs coming from my console:

I was able to find some errors using console on my machine looking like this
com.apple.AppKit

```<code>Unable to simultaneously satisfy constraints:
(
    "<NSLayoutConstraint:0x6000000211d0 V:|-(20)-[NSScrollView:0x7f865980fc00]   (active, names: '|':NSView:0x7f8657520090 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d2c0 h=-&- v=-&- NSClipView:0x7f8657520710.minY == 1   (active, names: '|':NSScrollView:0x7f865980fc00 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d310 h=-&- v=-&- V:[NSClipView:0x7f8657520710]-(1)-|   (active, names: '|':NSScrollView:0x7f865980fc00 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d1d0 h=-&- v=-&- V:[Docker.TextView:0x7f8657520a20]-(321)-|   (active, names: '|':NSClipView:0x7f8657520710 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d180 h=-&- v=-&- Docker.TextView:0x7f8657520a20.minY == 0   (active, names: '|':NSClipView:0x7f8657520710 )>",
    "<NSLayoutConstraint:0x600000021360 V:|-(20)-[Docker.TextViewInView:0x7f86577c81b0]   (active, names: '|':NSView:0x7f8657520090 )>",
    "<NSLayoutConstraint:0x600000021b30 NSView:0x7f86575202f0.bottom == NSScrollView:0x7f865980fc00.bottom + 7   (active)>",
    "<NSLayoutConstraint:0x600000020f50 NSTextField:0x7f86577cb4a0.height == 21   (active)>",
    "<NSLayoutConstraint:0x6000000215e0 V:[Docker.TextViewInView:0x7f86577c8450]-(14)-[NSTextField:0x7f86577cb4a0]   (active)>",
    "<NSLayoutConstraint:0x600000021860 V:[NSTextField:0x7f86577cb4a0]-(20)-[NSButton:0x7f86577cbd40'Report an issue']   (active)>",
    "<NSLayoutConstraint:0x600000020aa0 Docker.TextViewInView:0x7f86577c8450.height == 85   (active)>",
    "<NSLayoutConstraint:0x600000020ff0 NSButton:0x7f86577cbd40'Report an issue'.height == 21   (active)>",
    "<NSLayoutConstraint:0x600000021400 V:[Docker.TextViewInView:0x7f86577c81b0]-(20)-[Docker.TextViewInView:0x7f86577c8450]   (active)>",
    "<NSLayoutConstraint:0x6000000677a0 Docker.TextViewInView:0x7f86577c81b0.height == 34   (active)>",
    "<NSLayoutConstraint:0x6000000219f0 V:[NSButton:0x7f86577cbd40'Report an issue']-(20)-[NSView:0x7f86575202f0]   (active)>",
    "<NSLayoutConstraint:0x600000051a40 NSView:0x7f86575202f0.height == 32   (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000020aa0 Docker.TextViewInView:0x7f86577c8450.height == 85   (active)>

Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens.  And/or, set a symbolic breakpoint on LAYOUT_CONSTRAINTS_NOT_SATISFIABLE to catch this in the debugger.
</code>```

Also getting errors like:

```<code>default 16:45:28.317339-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.317361-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.383430-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.383903-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_CERTIFICATE_VERIFY [16]
default 16:45:28.456181-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.456197-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:51.405194-0600    com.docker.hyperkit [    2.316084] i8042: probe of i8042 failed with error -5
default 16:45:51.408830-0600    com.docker.hyperkit [    2.319402] ACPI Error: Could not enable RealTimeClock event (20160831/evxfevnt-218)
default 16:46:07.163398-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.283329064Z] failed to load plugin io.containerd.snapshotter.v1.btrfs  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter"
default 16:46:07.165905-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.285229275Z] failed to load plugin io.containerd.snapshotter.v1.aufs  \^[[33merror\^[[0m="modprobe aufs failed: "modprobe: module aufs not found in modules.dep\n": exit status 1"
default 16:46:07.171205-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291218565Z] failed to load plugin io.containerd.snapshotter.v1.zfs  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter"
default 16:46:07.173894-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291372447Z] could not use snapshotter btrfs in metadata plugin  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter"
default 16:46:07.175331-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291471719Z] could not use snapshotter aufs in metadata plugin  \^[[33merror\^[[0m="modprobe aufs failed: "modprobe: module aufs not found in modules.dep\n": exit status 1"
default 16:46:07.176960-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291582578Z] could not use snapshotter zfs in metadata plugin  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter"
default 16:46:07.203958-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.324548880Z] failed to load plugin io.containerd.internal.v1.opt  \^[[33merror\^[[0m="mkdir /opt/containerd: read-only file system"
error   16:46:11.450428-0600    Docker  Cmd: unknown flag: --format
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "/Users/awadowda/.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "/Users/awadowda/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default
                         <…>
error   16:46:11.531395-0600    Docker  Cmd: unknown flag: --format
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "/Users/awadowda/.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "/Users/awadowda/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default
                         <…>
</code>```

I also opened an issue for docker on Github, but I was hoping to see if anyone had this experience since docker-compose is critical to my project.

Uninstalling docker-compose and installing it again did not fix this issue, following this article.

答: In case anyone finds this, my issue was related to some docker variables in my bash_profile. For whatever reason, it didn't manifest itself until I updated to Catalina. Once I commented them out, it immediately started working.</p>

Body:
Trying to run my docker-compose after upgrading my macOS to latest beta version of Catalina 10.15.2 Beta (19C39d), but I was not able to to do so.

If anyone have a smilier experience please share your fix, since I pretty sure my docker-compose was working before the update.

System Info

Running docker system info

Client:
 Debug Mode: false

Server:
 Containers: 3
  Running: 0
  Paused: 0
  Stopped: 3
 Images: 37
 Server Version: 19.03.4
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.9.184-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 6
 Total Memory: 1.952GiB
 Name: docker-desktop
 ID: GY6V:NEYP:UYIY:SYOL:ZFWA:CNCY:NVMK:PWYA:MQPQ:AJTS:IDLM:3FWE
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 35
  Goroutines: 50
  System Time: 2019-11-15T22:25:09.226536684Z
  EventsListeners: 2
 HTTP Proxy: gateway.docker.internal:3128
 HTTPS Proxy: gateway.docker.internal:3129
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

Error logs coming from my console:

I was able to find some errors using console on my machine looking like this
com.apple.AppKit

Unable to simultaneously satisfy constraints:
(
    "<NSLayoutConstraint:0x6000000211d0 V:|-(20)-[NSScrollView:0x7f865980fc00]   (active, names: '|':NSView:0x7f8657520090 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d2c0 h=-&- v=-&- NSClipView:0x7f8657520710.minY == 1   (active, names: '|':NSScrollView:0x7f865980fc00 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d310 h=-&- v=-&- V:[NSClipView:0x7f8657520710]-(1)-|   (active, names: '|':NSScrollView:0x7f865980fc00 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d1d0 h=-&- v=-&- V:[Docker.TextView:0x7f8657520a20]-(321)-|   (active, names: '|':NSClipView:0x7f8657520710 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x60000002d180 h=-&- v=-&- Docker.TextView:0x7f8657520a20.minY == 0   (active, names: '|':NSClipView:0x7f8657520710 )>",
    "<NSLayoutConstraint:0x600000021360 V:|-(20)-[Docker.TextViewInView:0x7f86577c81b0]   (active, names: '|':NSView:0x7f8657520090 )>",
    "<NSLayoutConstraint:0x600000021b30 NSView:0x7f86575202f0.bottom == NSScrollView:0x7f865980fc00.bottom + 7   (active)>",
    "<NSLayoutConstraint:0x600000020f50 NSTextField:0x7f86577cb4a0.height == 21   (active)>",
    "<NSLayoutConstraint:0x6000000215e0 V:[Docker.TextViewInView:0x7f86577c8450]-(14)-[NSTextField:0x7f86577cb4a0]   (active)>",
    "<NSLayoutConstraint:0x600000021860 V:[NSTextField:0x7f86577cb4a0]-(20)-[NSButton:0x7f86577cbd40'Report an issue']   (active)>",
    "<NSLayoutConstraint:0x600000020aa0 Docker.TextViewInView:0x7f86577c8450.height == 85   (active)>",
    "<NSLayoutConstraint:0x600000020ff0 NSButton:0x7f86577cbd40'Report an issue'.height == 21   (active)>",
    "<NSLayoutConstraint:0x600000021400 V:[Docker.TextViewInView:0x7f86577c81b0]-(20)-[Docker.TextViewInView:0x7f86577c8450]   (active)>",
    "<NSLayoutConstraint:0x6000000677a0 Docker.TextViewInView:0x7f86577c81b0.height == 34   (active)>",
    "<NSLayoutConstraint:0x6000000219f0 V:[NSButton:0x7f86577cbd40'Report an issue']-(20)-[NSView:0x7f86575202f0]   (active)>",
    "<NSLayoutConstraint:0x600000051a40 NSView:0x7f86575202f0.height == 32   (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000020aa0 Docker.TextViewInView:0x7f86577c8450.height == 85   (active)>

Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens.  And/or, set a symbolic breakpoint on LAYOUT_CONSTRAINTS_NOT_SATISFIABLE to catch this in the debugger.

Also getting errors like:

default 16:45:28.317339-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.317361-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.383430-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.383903-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_CERTIFICATE_VERIFY [16]
default 16:45:28.456181-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:28.456197-0600    Docker  boringssl_session_handshake_incomplete(191) [C7.1:2][0x7f865be00ce0] Early handshake return caused by SSL_ERROR_WANT_READ [2]
default 16:45:51.405194-0600    com.docker.hyperkit [    2.316084] i8042: probe of i8042 failed with error -5
default 16:45:51.408830-0600    com.docker.hyperkit [    2.319402] ACPI Error: Could not enable RealTimeClock event (20160831/evxfevnt-218)
default 16:46:07.163398-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.283329064Z] failed to load plugin io.containerd.snapshotter.v1.btrfs  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter"
default 16:46:07.165905-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.285229275Z] failed to load plugin io.containerd.snapshotter.v1.aufs  \^[[33merror\^[[0m="modprobe aufs failed: "modprobe: module aufs not found in modules.dep\n": exit status 1"
default 16:46:07.171205-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291218565Z] failed to load plugin io.containerd.snapshotter.v1.zfs  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter"
default 16:46:07.173894-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291372447Z] could not use snapshotter btrfs in metadata plugin  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter"
default 16:46:07.175331-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291471719Z] could not use snapshotter aufs in metadata plugin  \^[[33merror\^[[0m="modprobe aufs failed: "modprobe: module aufs not found in modules.dep\n": exit status 1"
default 16:46:07.176960-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.291582578Z] could not use snapshotter zfs in metadata plugin  \^[[33merror\^[[0m="path /var/lib/containerd/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter"
default 16:46:07.203958-0600    com.docker.hyperkit \^[[33mWARN\^[[0m[2019-11-15T22:46:06.324548880Z] failed to load plugin io.containerd.internal.v1.opt  \^[[33merror\^[[0m="mkdir /opt/containerd: read-only file system"
error   16:46:11.450428-0600    Docker  Cmd: unknown flag: --format
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "/Users/awadowda/.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "/Users/awadowda/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default
                         <…>
error   16:46:11.531395-0600    Docker  Cmd: unknown flag: --format
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "/Users/awadowda/.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "/Users/awadowda/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default
                         <…>

I also opened an issue for docker on Github, but I was hoping to see if anyone had this experience since docker-compose is critical to my project.

Uninstalling docker-compose and installing it again did not fix this issue, following this article.


问:
How to calculate average asymptotic running time in Big-O notation?
Trying to understand Asymptotic notations which I understand is used to describe performance of an algorithm. Am I correct in saying that there is worst, best and average case scenarios? So for example, for the following piece of code, what is the average asymptotic running time in Big-O notation?

```<code>for (int i = 0; i < size; i++)
{
    printf("%d\n", i);
}
for (int i = 0; i < size; i++)
{
    for (int j = 0; j < size; j++)
    {
        printf("%d\n", i + j);
    }
}
</code>```

Would it be O(n^2)?

答:
Am I correct in saying that there is worst, best and average case scenarios?

Generally only worst case and average case are of interest, but you can consider the best case as well if you prefer.

Would it be O(n^2)?

What you have there is a typical O(n^2) complexity, yes. Best, average and worst, they're all the same for your particular case. They're only not the same if you can break out of loops early, or conditionally skip entire loops.

Edit: Example of when the average and best case complexity are different:

```<code>for(var i = 0; i < len; ++i)
  if(arr[i] == needle)
    return needle;
</code>```

This is at best a constant operation, ie O(1), if the element is found right away, and at worst an O(n) linear operation -- a linear search specifically.

Body:
Trying to understand Asymptotic notations which I understand is used to describe performance of an algorithm. Am I correct in saying that there is worst, best and average case scenarios? So for example, for the following piece of code, what is the average asymptotic running time in Big-O notation?

for (int i = 0; i < size; i++)
{
    printf("%d\n", i);
}
for (int i = 0; i < size; i++)
{
    for (int j = 0; j < size; j++)
    {
        printf("%d\n", i + j);
    }
}

Would it be O(n^2)?

Body:
Am I correct in saying that there is worst, best and average case scenarios?

Generally only worst case and average case are of interest, but you can consider the best case as well if you prefer.

Would it be O(n^2)?

What you have there is a typical O(n^2) complexity, yes. Best, average and worst, they're all the same for your particular case. They're only not the same if you can break out of loops early, or conditionally skip entire loops.

Edit: Example of when the average and best case complexity are different:

for(var i = 0; i < len; ++i)
  if(arr[i] == needle)
    return needle;

This is at best a constant operation, ie O(1), if the element is found right away, and at worst an O(n) linear operation -- a linear search specifically.


问:
Template or abstract base class?
If I want to make a class adaptable, and make it possible to select different algorithms from the outside -- what is the best implementation in C++?

I see mainly two possibilities:

Use an abstract base class and pass concrete object in

Use a template

Here is a little example, implemented in the various versions:

Version 1: Abstract base class

```<code>class Brake {
public: virtual void stopCar() = 0;
};

class BrakeWithABS : public Brake {
public: void stopCar() { ... }
};

class Car {
  Brake* _brake;
public:
  Car(Brake* brake) : _brake(brake) { brake->stopCar(); }
};
</code>```

Version 2a: Template

```<code>template<class Brake>
class Car {
  Brake brake;
public:
  Car(){ brake.stopCar(); }
};
</code>```

Version 2b: Template and private inheritance

```<code>template<class Brake>
class Car : private Brake {
  using Brake::stopCar;
public:
  Car(){ stopCar(); }
};
</code>```

Coming from Java, I am naturally inclined to always use version 1, but the templates versions seem to be preferred often, e.g. in STL code? If that's true, is it just because of memory efficiency etc (no inheritance, no virtual function calls)?

I realize there is not a big difference between version 2a and 2b, see C++ FAQ.

Can you comment on these possibilities?

答:
The rule of thumb is:

1) If the choice of the concrete type is made at compile time, prefer a template. It will be safer (compile time errors vs run time errors) and probably better optimized.
2) If the choice is made at run-time (i.e. as a result of a user's action) there is really no choice - use inheritance and virtual functions.

ContentLicense: CC BY-SA 2.5

Title: Template or abstract base class?

Body:
If I want to make a class adaptable, and make it possible to select different algorithms from the outside -- what is the best implementation in C++?

I see mainly two possibilities:

Use an abstract base class and pass concrete object in

Use a template

Here is a little example, implemented in the various versions:

Version 1: Abstract base class

class Brake {
public: virtual void stopCar() = 0;
};

class BrakeWithABS : public Brake {
public: void stopCar() { ... }
};

class Car {
  Brake* _brake;
public:
  Car(Brake* brake) : _brake(brake) { brake->stopCar(); }
};

Version 2a: Template

template<class Brake>
class Car {
  Brake brake;
public:
  Car(){ brake.stopCar(); }
};

Version 2b: Template and private inheritance

template<class Brake>
class Car : private Brake {
  using Brake::stopCar;
public:
  Car(){ stopCar(); }
};

Coming from Java, I am naturally inclined to always use version 1, but the templates versions seem to be preferred often, e.g. in STL code? If that's true, is it just because of memory efficiency etc (no inheritance, no virtual function calls)?

I realize there is not a big difference between version 2a and 2b, see C++ FAQ.

Can you comment on these possibilities?

OwnerDisplayName: Nemanja Trifunovic

LastEditorDisplayName: Nemanja Trifunovic


问:
How can I use different arrays for different sections in a table view?
I am trying to create a table view that uses different arrays for data for each section. But, I am not sure how to access the section number to create conditionals to set the data for each section. Please let me know if my explanation if confusing and I would really appreciate it if anyone could help me. The code is below.</p>

```<code>import UIKit
import Firebase
import FirebaseFirestore

struct PlasticCellData {
    let image: UIImage?
    let message: String?
}
struct PlasticAlphaHeader {
    let label: String?
}

class PlasticMaterial: UITableViewController {

    var rowHeight: CGFloat = 50
    var headerheight: CGFloat = 100
    var ref: DatabaseReference?
    var databaseHandle: DatabaseHandle?

    var alphaHeaderArray = [PlasticAlphaHeader]()
    var aData = [PlasticCellData]()
    var bData = [PlasticCellData]()
    var cData = [PlasticCellData]()
    var dData = [PlasticCellData]()
    var eData = [PlasticCellData]()
    var fData = [PlasticCellData]()
    var gData = [PlasticCellData]()
    var hData = [PlasticCellData]()
    var iData = [PlasticCellData]()
    var jData = [PlasticCellData]()
    var kData = [PlasticCellData]()
    var lData = [PlasticCellData]()
    var mData = [PlasticCellData]()
    var nData = [PlasticCellData]()
    var oData = [PlasticCellData]()
    var pData = [PlasticCellData]()
    var qData = [PlasticCellData]()
    var rData = [PlasticCellData]()
    var sData = [PlasticCellData]()
    var tData = [PlasticCellData]()
    var uData = [PlasticCellData]()
    var vData = [PlasticCellData]()
    var wData = [PlasticCellData]()
    var xData = [PlasticCellData]()
    var yData = [PlasticCellData]()
    var zData = [PlasticCellData]()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        setupNavBar()
        let db = Firestore.firestore()

        alphaHeaderArray =
            [PlasticAlphaHeader.init(label: "A"), PlasticAlphaHeader.init(label: "B"),
            PlasticAlphaHeader.init(label: "C"), PlasticAlphaHeader.init(label: "D"),
            PlasticAlphaHeader.init(label: "E"), PlasticAlphaHeader.init(label: "F"),
            PlasticAlphaHeader.init(label: "G"), PlasticAlphaHeader.init(label: "H"),
            PlasticAlphaHeader.init(label: "I"), PlasticAlphaHeader.init(label: "J"),
            PlasticAlphaHeader.init(label: "K"), PlasticAlphaHeader.init(label: "L"),
            PlasticAlphaHeader.init(label: "M"), PlasticAlphaHeader.init(label: "N"),
            PlasticAlphaHeader.init(label: "O"), PlasticAlphaHeader.init(label: "P"),
            PlasticAlphaHeader.init(label: "Q"), PlasticAlphaHeader.init(label: "R"),
            PlasticAlphaHeader.init(label: "S"), PlasticAlphaHeader.init(label: "T"),
            PlasticAlphaHeader.init(label: "U"), PlasticAlphaHeader.init(label: "V"),
            PlasticAlphaHeader.init(label: "W"), PlasticAlphaHeader.init(label: "X"),
            PlasticAlphaHeader.init(label: "Y"), PlasticAlphaHeader.init(label: "Z")]

        db.collection("plastic").getDocuments { (snapshot, error) in
            if let error = error {

            }
            else {
                for document in snapshot!.documents {
                    let data = document.data()
                    let name = data["name"] as? String ?? ""
                    let firstLetter = name.prefix(1)
                    if firstLetter == "A" {
                        self.aData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "B" {
                        self.bData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "C" {
                        self.cData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "D" {
                        self.dData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "E" {
                        self.eData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "F" {
                        self.fData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "G" {
                        self.gData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "H" {
                        self.hData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "I" {
                        self.iData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "J" {
                        self.jData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "K" {
                        self.kData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "L" {
                        self.lData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "M" {
                        self.mData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "N" {
                        self.nData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "O" {
                        self.oData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "P" {
                        self.pData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "Q" {
                        self.qData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "R" {
                        self.rData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "S" {
                        self.sData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "T" {
                        self.tData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "U" {
                        self.uData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "V" {
                        self.vData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "W" {
                        self.wData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "X" {
                        self.xData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "Y" {
                        self.yData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else {
                        self.zData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    self.tableView.reloadData()
                }
            }
        }

        self.tableView.register(ItemCustomCell.self, forCellReuseIdentifier: "custom")
    }

    func setupNavBar() {
        navigationItem.title = "Select Item"
        navigationController?.navigationBar.prefersLargeTitles = true
    }

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let alphaHeader = Bundle.main.loadNibNamed("AlphaHeaderView", owner: self, options: nil)?.first as! AlphaHeaderView

        alphaHeader.headerLabel.text = alphaHeaderArray[section].label
        return alphaHeader
    }
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return headerheight
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCell(withIdentifier: "custom") as! ItemCustomCell
        cell.itemImage = aData[indexPath.row].image
        cell.message = aData[indexPath.row].message
        cell.itemImage = bData[indexPath.row].image
        cell.message = bData[indexPath.row].message
        cell.itemImage = cData[indexPath.row].image
        cell.message = cData[indexPath.row].message
        cell.itemImage = dData[indexPath.row].image
        cell.message = dData[indexPath.row].message
        cell.itemImage = eData[indexPath.row].image
        cell.message = eData[indexPath.row].message
        cell.itemImage = fData[indexPath.row].image
        cell.message = fData[indexPath.row].message
        cell.itemImage = gData[indexPath.row].image
        cell.message = gData[indexPath.row].message
        cell.itemImage = hData[indexPath.row].image
        cell.message = hData[indexPath.row].message
        cell.itemImage = iData[indexPath.row].image
        cell.message = iData[indexPath.row].message
        cell.itemImage = jData[indexPath.row].image
        cell.message = jData[indexPath.row].message
        cell.itemImage = kData[indexPath.row].image
        cell.message = kData[indexPath.row].message
        cell.itemImage = lData[indexPath.row].image
        cell.message = lData[indexPath.row].message
        cell.itemImage = mData[indexPath.row].image
        cell.message = mData[indexPath.row].message
        cell.itemImage = nData[indexPath.row].image
        cell.message = nData[indexPath.row].message
        cell.itemImage = oData[indexPath.row].image
        cell.message = oData[indexPath.row].message
        cell.itemImage = pData[indexPath.row].image
        cell.message = pData[indexPath.row].message
        cell.itemImage = qData[indexPath.row].image
        cell.message = qData[indexPath.row].message
        cell.itemImage = rData[indexPath.row].image
        cell.message = rData[indexPath.row].message
        cell.itemImage = sData[indexPath.row].image
        cell.message = sData[indexPath.row].message
        cell.itemImage = tData[indexPath.row].image
        cell.message = tData[indexPath.row].message
        cell.itemImage = uData[indexPath.row].image
        cell.message = uData[indexPath.row].message
        cell.itemImage = vData[indexPath.row].image
        cell.message = vData[indexPath.row].message
        cell.itemImage = wData[indexPath.row].image
        cell.message = wData[indexPath.row].message
        cell.itemImage = xData[indexPath.row].image
        cell.message = xData[indexPath.row].message
        cell.itemImage = yData[indexPath.row].image
        cell.message = yData[indexPath.row].message
        cell.itemImage = zData[indexPath.row].image
        cell.message = zData[indexPath.row].message

        return cell
    }
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return rowHeight
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 26
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return aData.count
        }
        if section == 1 {
            return bData.count
        }
        if section == 2 {
            return cData.count
        }
        if section == 3 {
            return dData.count
        }
        if section == 4 {
            return eData.count
        }
        if section == 5 {
            return fData.count
        }
        if section == 6 {
            return gData.count
        }
        if section == 7 {
            return hData.count
        }
        if section == 8 {
            return iData.count
        }
        if section == 9 {
            return jData.count
        }
        if section == 10 {
            return kData.count
        }
        if section == 11 {
            return lData.count
        }
        if section == 12 {
            return mData.count
        }
        if section == 13 {
            return nData.count
        }
        if section == 14 {
            return oData.count
        }
        if section == 15 {
            return pData.count
        }
        if section == 16 {
            return qData.count
        }
        if section == 17 {
            return rData.count
        }
        if section == 18{
            return sData.count
        }
        if section == 19 {
            return tData.count
        }
        if section == 20 {
            return uData.count
        }
        if section == 21 {
            return vData.count
        }
        if section == 22 {
            return wData.count
        }
        if section == 23 {
            return xData.count
        }
        if section == 24 {
            return yData.count
        }
        return zData.count
    }
}
</code>```

答:
At the cellForRowAt function try to choose the array based on the section, like so:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCell(withIdentifier: "custom") as! ItemCustomCell
        switch indexPath.section {
             case 0:
                  cell.itemImage = aData[indexPath.row].image
                  cell.message = aData[indexPath.row].message
             case 1:
                  cell.itemImage = bData[indexPath.row].image
                  cell.message = bData[indexPath.row].message
             //(...make one for each letter case until Z...)
             default:
                  cell.itemImage = zData[indexPath.row].image
                  cell.message = zData[indexPath.row].message
        }
        return cell
}
```

That works for your data structure, ideally though you should use a two-dimensional array, with the first dimension representing the letters and the second dimension representing the data of each letter.

Body:
I am trying to create a table view that uses different arrays for data for each section. But, I am not sure how to access the section number to create conditionals to set the data for each section. Please let me know if my explanation if confusing and I would really appreciate it if anyone could help me. The code is below.

import UIKit
import Firebase
import FirebaseFirestore

struct PlasticCellData {
    let image: UIImage?
    let message: String?
}
struct PlasticAlphaHeader {
    let label: String?
}

class PlasticMaterial: UITableViewController {

    var rowHeight: CGFloat = 50
    var headerheight: CGFloat = 100
    var ref: DatabaseReference?
    var databaseHandle: DatabaseHandle?

    var alphaHeaderArray = [PlasticAlphaHeader]()
    var aData = [PlasticCellData]()
    var bData = [PlasticCellData]()
    var cData = [PlasticCellData]()
    var dData = [PlasticCellData]()
    var eData = [PlasticCellData]()
    var fData = [PlasticCellData]()
    var gData = [PlasticCellData]()
    var hData = [PlasticCellData]()
    var iData = [PlasticCellData]()
    var jData = [PlasticCellData]()
    var kData = [PlasticCellData]()
    var lData = [PlasticCellData]()
    var mData = [PlasticCellData]()
    var nData = [PlasticCellData]()
    var oData = [PlasticCellData]()
    var pData = [PlasticCellData]()
    var qData = [PlasticCellData]()
    var rData = [PlasticCellData]()
    var sData = [PlasticCellData]()
    var tData = [PlasticCellData]()
    var uData = [PlasticCellData]()
    var vData = [PlasticCellData]()
    var wData = [PlasticCellData]()
    var xData = [PlasticCellData]()
    var yData = [PlasticCellData]()
    var zData = [PlasticCellData]()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        setupNavBar()
        let db = Firestore.firestore()

        alphaHeaderArray =
            [PlasticAlphaHeader.init(label: "A"), PlasticAlphaHeader.init(label: "B"),
            PlasticAlphaHeader.init(label: "C"), PlasticAlphaHeader.init(label: "D"),
            PlasticAlphaHeader.init(label: "E"), PlasticAlphaHeader.init(label: "F"),
            PlasticAlphaHeader.init(label: "G"), PlasticAlphaHeader.init(label: "H"),
            PlasticAlphaHeader.init(label: "I"), PlasticAlphaHeader.init(label: "J"),
            PlasticAlphaHeader.init(label: "K"), PlasticAlphaHeader.init(label: "L"),
            PlasticAlphaHeader.init(label: "M"), PlasticAlphaHeader.init(label: "N"),
            PlasticAlphaHeader.init(label: "O"), PlasticAlphaHeader.init(label: "P"),
            PlasticAlphaHeader.init(label: "Q"), PlasticAlphaHeader.init(label: "R"),
            PlasticAlphaHeader.init(label: "S"), PlasticAlphaHeader.init(label: "T"),
            PlasticAlphaHeader.init(label: "U"), PlasticAlphaHeader.init(label: "V"),
            PlasticAlphaHeader.init(label: "W"), PlasticAlphaHeader.init(label: "X"),
            PlasticAlphaHeader.init(label: "Y"), PlasticAlphaHeader.init(label: "Z")]

        db.collection("plastic").getDocuments { (snapshot, error) in
            if let error = error {

            }
            else {
                for document in snapshot!.documents {
                    let data = document.data()
                    let name = data["name"] as? String ?? ""
                    let firstLetter = name.prefix(1)
                    if firstLetter == "A" {
                        self.aData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "B" {
                        self.bData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "C" {
                        self.cData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "D" {
                        self.dData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "E" {
                        self.eData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "F" {
                        self.fData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "G" {
                        self.gData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "H" {
                        self.hData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "I" {
                        self.iData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "J" {
                        self.jData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "K" {
                        self.kData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "L" {
                        self.lData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "M" {
                        self.mData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "N" {
                        self.nData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "O" {
                        self.oData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "P" {
                        self.pData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "Q" {
                        self.qData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "R" {
                        self.rData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "S" {
                        self.sData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "T" {
                        self.tData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "U" {
                        self.uData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "V" {
                        self.vData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "W" {
                        self.wData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "X" {
                        self.xData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else if firstLetter == "Y" {
                        self.yData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    else {
                        self.zData = [PlasticCellData.init(image: #imageLiteral(resourceName: "PlasticSilverware"), message: name)]
                    }
                    self.tableView.reloadData()
                }
            }
        }

        self.tableView.register(ItemCustomCell.self, forCellReuseIdentifier: "custom")
    }

    func setupNavBar() {
        navigationItem.title = "Select Item"
        navigationController?.navigationBar.prefersLargeTitles = true
    }

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let alphaHeader = Bundle.main.loadNibNamed("AlphaHeaderView", owner: self, options: nil)?.first as! AlphaHeaderView

        alphaHeader.headerLabel.text = alphaHeaderArray[section].label
        return alphaHeader
    }
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return headerheight
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCell(withIdentifier: "custom") as! ItemCustomCell
        cell.itemImage = aData[indexPath.row].image
        cell.message = aData[indexPath.row].message
        cell.itemImage = bData[indexPath.row].image
        cell.message = bData[indexPath.row].message
        cell.itemImage = cData[indexPath.row].image
        cell.message = cData[indexPath.row].message
        cell.itemImage = dData[indexPath.row].image
        cell.message = dData[indexPath.row].message
        cell.itemImage = eData[indexPath.row].image
        cell.message = eData[indexPath.row].message
        cell.itemImage = fData[indexPath.row].image
        cell.message = fData[indexPath.row].message
        cell.itemImage = gData[indexPath.row].image
        cell.message = gData[indexPath.row].message
        cell.itemImage = hData[indexPath.row].image
        cell.message = hData[indexPath.row].message
        cell.itemImage = iData[indexPath.row].image
        cell.message = iData[indexPath.row].message
        cell.itemImage = jData[indexPath.row].image
        cell.message = jData[indexPath.row].message
        cell.itemImage = kData[indexPath.row].image
        cell.message = kData[indexPath.row].message
        cell.itemImage = lData[indexPath.row].image
        cell.message = lData[indexPath.row].message
        cell.itemImage = mData[indexPath.row].image
        cell.message = mData[indexPath.row].message
        cell.itemImage = nData[indexPath.row].image
        cell.message = nData[indexPath.row].message
        cell.itemImage = oData[indexPath.row].image
        cell.message = oData[indexPath.row].message
        cell.itemImage = pData[indexPath.row].image
        cell.message = pData[indexPath.row].message
        cell.itemImage = qData[indexPath.row].image
        cell.message = qData[indexPath.row].message
        cell.itemImage = rData[indexPath.row].image
        cell.message = rData[indexPath.row].message
        cell.itemImage = sData[indexPath.row].image
        cell.message = sData[indexPath.row].message
        cell.itemImage = tData[indexPath.row].image
        cell.message = tData[indexPath.row].message
        cell.itemImage = uData[indexPath.row].image
        cell.message = uData[indexPath.row].message
        cell.itemImage = vData[indexPath.row].image
        cell.message = vData[indexPath.row].message
        cell.itemImage = wData[indexPath.row].image
        cell.message = wData[indexPath.row].message
        cell.itemImage = xData[indexPath.row].image
        cell.message = xData[indexPath.row].message
        cell.itemImage = yData[indexPath.row].image
        cell.message = yData[indexPath.row].message
        cell.itemImage = zData[indexPath.row].image
        cell.message = zData[indexPath.row].message

        return cell
    }
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return rowHeight
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 26
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return aData.count
        }
        if section == 1 {
            return bData.count
        }
        if section == 2 {
            return cData.count
        }
        if section == 3 {
            return dData.count
        }
        if section == 4 {
            return eData.count
        }
        if section == 5 {
            return fData.count
        }
        if section == 6 {
            return gData.count
        }
        if section == 7 {
            return hData.count
        }
        if section == 8 {
            return iData.count
        }
        if section == 9 {
            return jData.count
        }
        if section == 10 {
            return kData.count
        }
        if section == 11 {
            return lData.count
        }
        if section == 12 {
            return mData.count
        }
        if section == 13 {
            return nData.count
        }
        if section == 14 {
            return oData.count
        }
        if section == 15 {
            return pData.count
        }
        if section == 16 {
            return qData.count
        }
        if section == 17 {
            return rData.count
        }
        if section == 18{
            return sData.count
        }
        if section == 19 {
            return tData.count
        }
        if section == 20 {
            return uData.count
        }
        if section == 21 {
            return vData.count
        }
        if section == 22 {
            return wData.count
        }
        if section == 23 {
            return xData.count
        }
        if section == 24 {
            return yData.count
        }
        return zData.count
    }
}

Body:
At the cellForRowAt function try to choose the array based on the section, like so:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCell(withIdentifier: "custom") as! ItemCustomCell
        switch indexPath.section {
             case 0:
                  cell.itemImage = aData[indexPath.row].image
                  cell.message = aData[indexPath.row].message
             case 1:
                  cell.itemImage = bData[indexPath.row].image
                  cell.message = bData[indexPath.row].message
             //(...make one for each letter case until Z...)
             default:
                  cell.itemImage = zData[indexPath.row].image
                  cell.message = zData[indexPath.row].message
        }
        return cell
}

That works for your data structure, ideally though you should use a two-dimensional array, with the first dimension representing the letters and the second dimension representing the data of each letter.


问:
Git stash and unstash deleted my stash without adding it to the version
What part of this work flow was wrong:
I tried to push, was told I couldn't because of changes not pulled.
I tried to pull, was told I couldn't because of conflicts.
I stashed all my changes and reset to the repo with git reset --hard.
I unstashed my changes with git stash pop

The result is that my stash has been deleted but didn't get unstashed.

答:
You most likely did the commands out of order.

You intended to do:

```<code>git stash && git pull && git stash pop && git add {your-files} && git commit -m "your message" && git push
</code>```

yet you most likely ended up doing:

```<code># git stash && git pop && git reset --hard
</code>```

Since git pop is basically a shortcut for git apply stash@{0} && git drop stash@{0} you applied your changes, and then deleted the applied stash. By resetting the repo via # git reset --hard you deleted your work.

I recommend using git stash apply over drop. You can have basically unlimmited amount of stash and browse them repeatedly, apply them, and delete them whenever you like.

You may be able to recover your dropped git stash or restor

Body:
You most likely did the commands out of order.

You intended to do:

git stash && git pull && git stash pop && git add {your-files} && git commit -m "your message" && git push

yet you most likely ended up doing:

# git stash && git pop && git reset --hard

Since git pop is basically a shortcut for git apply stash@{0} && git drop stash@{0} you applied your changes, and then deleted the applied stash. By resetting the repo via # git reset --hard you deleted your work.

I recommend using git stash apply over drop. You can have basically unlimmited amount of stash and browse them repeatedly, apply them, and delete them whenever you like.

You may be able to recover your dropped git stash or restor