Syntax Error: TypeError: this.getOptions is not a function

less is a great css preprocessor which can be converted to css stylesheet. But using latest version of less with Vue 2.x version has some problems.

ERROR Failed to compile with 1 error 上午11:51:16

error in ./src/components/ChooseDistributors.vue?vue&type=style&index=0&id=0bd67dd3&lang=less&scoped=true&

Syntax Error: TypeError: this.getOptions is not a function

@ ./node_modules/vue-style-loader??ref--10-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--10-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--10-oneOf-1-2!./node_modules/less-loader/dist/cjs.js??ref--10-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/ChooseDistributors.vue?vue&type=style&index=0&id=0bd67dd3&lang=less&scoped=true& 4:14-476 15:3-20:5 16:22-484
@ ./src/components/ChooseDistributors.vue?vue&type=style&index=0&id=0bd67dd3&lang=less&scoped=true&
@ ./src/components/ChooseDistributors.vue
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://192.168.0.15:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

Above error is shown when building when running npm run build.

Current vue version is 2.6.11, less version is 4.1.1 and less-loader is 8.1.0.

Solution

Changing less-loader version to 7.3.0 fixed this issue.

Automatically generate requirements.txt for pip

pip is popular package manager for Python.

There is often a requirements.txt file in lots of Python projects specifying several dependencies need to install.
We can install several packages using pip at once using following command

pip -r requirements.txt

to generate requirements for pip, certainly we can type the required package names line by line,
but there is a tool called pipreqs can help us.

pipreqs

pipreqs can analyze your python project for dependencies and generate requirements.txt
used by pip automatically.

Installation

pip install pipreqs

Generate requirements.txt

pipreqs .

This command will generate requirements.txt using current directory as source root directory.
Then you can run pip -r requirements.txt to install dependencies.

java.lang.ClassNotFoundException: redis.clients.jedis.util.Pool

When trying to setup spring-session-data-redis, following error is appeared

09-May-2020 14:27:53.522 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class core.web.SystemInitListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration#0' defined in file [F:\df_web\target\classes\applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory#0': Failed to introspect bean class [org.springframework.data.redis.connection.jedis.JedisConnectionFactory] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: redis/clients/jedis/util/Pool
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:480)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:41010)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1696)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45009)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45012)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:484)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:433)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45009)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45012)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at java.security.AccessController.doPrivileged(Native Method)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45009)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45012)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory#0': Failed to introspect bean class [org.springframework.data.redis.connection.jedis.JedisConnectionFactory] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: redis/clients/jedis/util/Pool
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1091)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getObject(DefaultListableBeanFactory.java:1630)
at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration.setRedisConnectionFactory(RedisHttpSessionConfiguration.java:209)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45009)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45012)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:701)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
… 65 more
Caused by: java.lang.NoClassDefFoundError: redis/clients/jedis/util/Pool
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
… 88 more
Caused by: java.lang.ClassNotFoundException: redis.clients.jedis.util.Pool
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
… 95 more

pom.xml

Checking source code of jedis on Github, I found version 2.9.0 exactly doesn't define such class. But in version 3.3 it exists.

So change jedis version to 3.3.0 fixed this issue

Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

I try to add an Export button in ExtJS, it should do URL encoding for the search parameters and pass the generated query string to the export URL.

When testing above code in Chrome, following error happened:

Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode


The reason is let keyword is not allowed in non-strict mode for this version of Chrome.

One solution is to change let to var. (But it isn't good)
The better solution is to add "use strict" statement.

So the final code should be

keras-vggface deploy model file locally

keras-vggface is a face detection library based on keras.

Running above code will load vgg16 model. if models is not downloaded before, it will try to fetch the model file from web.

What if you want to deploy the model locally, pack it with your application distribution, so the user don't need to download model file when using your application first time?

Solution

The answer is to put the model file under ~/.keras/models/vggface

The ~ is your home path. If you're using Linux, just copy the path as it is, supported on Linux by default.
But if you are using Windows, the ~ should be replaced with C:/Users/Administrator
(assume system path is C: and current logged in username is Administrator)

Note that the model file name cannot be changed, e.g. for vgg16 model the filename should be rcmalli_vggface_tf_vgg16.h5

SFTP ls command returns no files

I created a new user called phone for the client, and created a new directory /home/phone as his home directory. Next create some files for testing purpose.

Then modify /etc/ssh/sshd_config to set chroot configuration

But logging in with this new user and run ls command, no files are listed, it returns nothing.. But if I run ls in ssh, the files are shown.

After trying lots of time, the reason is found: It's because there is no "x" permission for /home/phone directory..

What is "x" permission?

The "x" permission for directory is used to traverse directory. And the "x" permission for file is for file execution.

Then run following command to add "x" permission for /home/phone

And try running ls command in sftp again, the issue is fixed now, we can see files are listed now.

mvn add jar file to local repository

Did you ever want to put a local jar library file into your deployment jar file, but the library file is not available on public repository (or you don't want to put it on public repository?)

One possible method is to add maven dependency with scope and systemPath property

<dependency>
<groupId>aeszip</groupId>
<artifactId>aeszip</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/WebContent/WEB-INF/lib/aeszip.jar</systemPath>
</dependency>

But using scope and systemPath has a problem, that is when I run mvn package to build a package, the dependency will not be included, so running the application on another machine will always complain NoClassDefFoundError or ClassNotFoundException

So a better method is to use mvn install:install-file plugin

This will add AesZip.jar to your local maven repository. When running mvn package to create package, the dependent libraries will be included into the generated package

Python No module named feedparser

I want to use following tool to download paper from arxiv

https://github.com/pvskand/arXiv_download

I installed it by pip

When trying to run python arXiv, following error happened.

Install feedparser using pip

Run python arXiv again, the issue is fixed

OpenCV findContours with RETR_EXTERNAL not working

Following code is trying to extracting bounding rectangles from contours and merge rectangles which is contained in other rectangles

 

In above found contours, one inner contour is contained within an outer contour, but is not merged with outer contour. the inner one's border is 2 pixel away from outer one's border.

I checked the code multiple times, and not found something wrong.

 

Then I tried changed the drawing rectangle border thickness to 2, and it works..

 

 

Checking it in PyCharm SciView Data View I found their border is connected. So I'm not sure why it's working is caused by increased border width or connected shapes. (But in the past cv2.findContours with RETR_EXTERNAL will work for inner contours, so it's likely caused by thin border)