text:
Q: How to Split a CSV file by line and then by semicolons Hi all I have a CSV file like this:
 ban;frst_name;last_nam;adrs_provnc;accnt_type_id....
 ban1;frst_name1;last_nam1;adrs_provnc1;accnt_type_id....
 ....

I want to put this file into a datatype in which I can access each line as well as each field of everyline. Example: if I want the second line of the file then I should have --
"ban1;frst_name1;last_nam1;adrs_provnc1;accnt_type_id...."

And if I want the second field of second line I should have:
"frst_name1"

Is there a way I can do this , by which I can get access to both lines and fields.
This is what i coded
 public class cvsreader {
List<List<String>> cust_data = new ArrayList<List<String>>(); // declared a list of list
public void run() throws IOException {

    String cust_line = "";

    String delimeter = ";";

    String cust_inputfile = "C:/input.csv"; // input file

    BufferedReader cust_br = new BufferedReader(new FileReader(cust_inputfile));

    while ((cust_line = cust_br.readLine()) != null){

        cust_data = Arrays.asList(Arrays.asList(cust_line.split(delimeter))); // stored data from cust_line(string) to cust_data (list of list, so did type casting from list to array)
        System.out.println(cust_data);

        }

    }
}

it gives me output like below
[[ban,frst_name,last_nam,adrs_provnc,accnt_type_id....]]
[[ban1,frst_name1,last_nam1,adrs_provnc1,accnt_type_id....]]
[[....                                                    ]]

now if i print
System.out.println(cust_data.get(0));

it gives output like this-
[ban,frst_name,last_nam,adrs_provnc,accnt_type_id....]
[ban1,frst_name1,last_nam1,adrs_provnc1,accnt_type_id....]
[....                                                    ]

the one sqaure braces has been reduced but instead it should have given only the frst line.
[ban,frst_name,last_nam,adrs_provnc,accnt_type_id....]

and now if i print
System.out.println(cust_data.get(0).get(0));

it prints the below
ban
ban1

without square braces but instead it should have printed only the first field of first line that is-
ban.
please if anyone can now understand what actually has to be done to get desired result please suggest.

A: This answer for reading line by line:
How to read a large text file line by line using Java?
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
    String line;
    while ((line = br.readLine()) != null) {
       // process the line.
    }
}

This answer for splitting a string: How to split a string in Java
String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556

This page for complete example of parsing CSV: http://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/
All code copy pasted from other SO threads.


text:
Q: Unable to ping from bridge interface(br0) to another subnet interface IP in Oracle Virtual Box VM I am newbie to networking and trying to ping from bridge interface to another interface configured with different subnet IP address.
I am trying these configuration in oracle virtual BOX VM running with Ubuntu 16.04.
I have three interfaces eth0, eth1, eth3. In which eth0, eth1 are part of bridge br0. The bridge br0 is configured with IP address as 10.1.1.10.
The  another interface eth3 is configured as 192.1.168.10.
When I am trying to add route it fails as Network unreachable. ip add default via 192.1.168.10 dev br0
I would need to : ping -I br0 192.1.168.10 ->>>> But fails.
In oracle virtual box VM, these interfaces are configured as internal network ports (inet).
brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.0800275f7d3e   no      eth0
                            eth1
ifconfig eth3
eth3      Link encap:Ethernet  HWaddr 08:00:27:f9:c1:a8
          inet addr:192.1.168.10  Bcast:192.1.168.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fef9:c1a8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 ifconfig br0
  br0       Link encap:Ethernet  HWaddr 08:00:27:5f:7d:3e
          inet addr:10.1.1.10  Bcast:10.255.255.255  Mask:255.0.0.0
          inet6 addr: fe80::a00:27ff:fe5f:7d3e/64 Scope:Link

virtualBox:~# ip route add default via 192.1.168.10 dev br0
**RTNETLINK answers: Network is unreachable****

VirtualBox:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 br0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth3
192.1.168.0     0.0.0.0         255.255.255.0   U     0      0        0 eth3
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth2

When I am trying to ping from bridge interface it is failed. Any ideas how to resolve this issue.
Network Diagram

redpajama_set_name: RedPajamaStackExchange


text:
Q: Recharts - limit the number of ticks on x-axis? I have a button to switch between charts, but sometimes the x-axis data contains 300 ticks, whereas sometimes it contains 90 ticks.
My x-axis looks like so:
<XAxis dataKey="time" interval={10}  />
This looks great for data with 90 ticks, however when it comes to 300 ticks all of the labels are mashed together because there are so many.
How can I normalize this so that there are always 11 evenly spread out labels on the x-axis no matter the number of data points?


text:
Q: iOS deployment target change from one version to the next I know you can change the deployment target when you build the app. Let's say I have version 1.0 of the app built with deployment target set to 6.0. If I now release version 1.1 and set deployment target to 7.0, the question is what happens to owners of iOS 6 devices running version 1.0 if they connect to itunes and sync? Will their 1.0 version be deleted or is it that they simply will not see version 1.1 available?

A: They will not be able to download and install version 1.1 unless they upgrade to iOS7. They will not lose version 1.0, that will remain on their device.
Users with older iOS version (in your case 6.0) will be able to continue downloading version 1.0 even after 1.1 has been released.
See the article below for more details:
App Resurection


text:
Q: How to get all contacts in Android and ignore email-only contacts Below is the code I am using to fetch contacts in Android.
String[] projectionFields = new String[]{
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME,
        };

CursorLoader cursorLoader = new CursorLoader(context,
                ContactsContract.Contacts.CONTENT_URI,
                projectionFields, // the columns to retrieve
                SELECTION, // the selection criteria (none)
                null, // the selection args (none)
                null // the sort order (default)
        );
Cursor cursor = cursorLoader.loadInBackground();

if (cursor.moveToFirst()) {
            int nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);

            do {
                String contactDisplayName = cursor.getString(nameIndex);
            } while (cursor.moveToNext());
        }

I am also getting a lot of email only contacts. I don't want to show email-only contacts. How can I go about this?

A: I understand from your question that you need to get the contacts that has phone numbers. If this is the case, you can check if the contact has phone number by
ContentResolver contentResolver = getContentResolver();
    ContentProviderClient mCProviderClient = contentResolver.acquireContentProviderClient(ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
    Cursor cursor = mCProviderClient.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null, "UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ") ASC");
    if (cursor.getCount() > 0) {
        while (cursor.moveToNext()) {
            String contactId =
                    cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
            String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));
            if (hasPhoneNumber > 0) {
                Cursor phones = mCProviderClient.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION_PHONE,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
                while (phones.moveToNext()) {
                    String number = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                }
                phones.close();
             }
        }
        mCProviderClient.close();
        cursor.close();
    }

The value of hasPhoneNumber will be > 0, if there is a phone number assigned to the contact.

A: Please refer to this answer, it will allow only numbers and will also remove duplication.
Hope you find it helpful and your problem gets resolved.
Thanks.


text:
Q: java.lang.IllegalStateException: Failed to load ApplicationContext ,springboot setting The following is the error message

java.lang.IllegalStateException: Failed to load ApplicationContext
at
  org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
  at
  org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
  at
  org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
  at
  org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
  at
  org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
  at
  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) at
  org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
  at
  org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at
  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
  at
  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
  at
  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at
  org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at
  org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at
  org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at
  org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at
  org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  at
  org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at
  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at
  com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
  at
  com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
  at
  com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
  at
  com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by:
  org.springframework.beans.factory.UnsatisfiedDependencyException:
  Error creating bean with name 'wokerLogController': Unsatisfied
  dependency expressed through field 'client'; nested exception is
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'client' defined in class path resource
  [com/aurora/backend/config/ESConfig.class]: Bean instantiation via
  factory method failed; nested exception is
  org.springframework.beans.BeanInstantiationException: Failed to
  instantiate [org.elasticsearch.client.Client]: Factory method 'client'
  threw exception; nested exception is java.lang.IllegalStateException:
  availableProcessors is already set to [4], rejecting [4] at
  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
  at
  org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
  at
  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
  at
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378)
  at
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
  at
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
  at
  org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
  at
  org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
  at
  org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
  at
  org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
  at
  org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
  at
  org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
  at
  org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
  at
  org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
  at
  org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
  at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
  at
  org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)
  at
  org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
  at
  org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
  ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'client' defined in class path resource
  [com/aurora/backend/config/ESConfig.class]: Bean instantiation via
  factory method failed; nested exception is
  org.springframework.beans.BeanInstantiationException: Failed to
  instantiate [org.elasticsearch.client.Client]: Factory method 'client'
  threw exception; nested exception is java.lang.IllegalStateException:
  availableProcessors is already set to [4], rejecting [4] at
  org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
  at
  org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)
  at
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288)
  at
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
  at
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
  at
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
  at
  org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
  at
  org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
  at
  org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
  at
  org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
  at
  org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
  at
  org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244)
  at
  org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)
  at
  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593)
  ... 42 more
Caused by: org.springframework.beans.BeanInstantiationException:
  Failed to instantiate [org.elasticsearch.client.Client]: Factory
  method 'client' threw exception; nested exception is
  java.lang.IllegalStateException: availableProcessors is already set to
  [4], rejecting [4] at
  org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
  at
  org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
  ... 55 more Caused by: java.lang.IllegalStateException:
  availableProcessors is already set to [4], rejecting [4] at
  io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:51)
  at
  io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87)
  at
  org.elasticsearch.transport.netty4.Netty4Utils.setAvailableProcessors(Netty4Utils.java:83)
  at
  org.elasticsearch.transport.netty4.Netty4Transport.(Netty4Transport.java:112)
  at
  org.elasticsearch.transport.Netty4Plugin.lambda$getTransports$0(Netty4Plugin.java:86)
  at
  org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:189)
  at
  org.elasticsearch.client.transport.TransportClient.(TransportClient.java:283)
  at
  org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:128)
  at
  org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:114)
  at
  org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:104)
  at com.aurora.backend.config.ESConfig.client(ESConfig.java:45) at
  com.aurora.backend.config.ESConfig$$EnhancerBySpringCGLIB$$d0b29c5a.CGLIB$client$0()
  at
  com.aurora.backend.config.ESConfig$$EnhancerBySpringCGLIB$$d0b29c5a$$FastClassBySpringCGLIB$$93c49e6a.invoke()
  at
  org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
  at
  org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
  at
  com.aurora.backend.config.ESConfig$$EnhancerBySpringCGLIB$$d0b29c5a.client()
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498) at
  org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
  ... 56 more

A springboot project that uses elasticSearch, mysql, redis, etc.
Google has a lot, but he is just a new spingboot. The online stuff doesn't work. I don't know how to change it.
application-local.yml

server:
  port: 8000
  servlet:
    context-path: /api/v3
  error:
    whitelabel:
      enabled: false

spring:
  http:
    multipart:

    encoding:
      charset: UTF-8
      force: true
      enabled: true

  datasource:
    url: jdbc:mysql://localhost:3306/aurora?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
    username: root
    password: 123456789
    driverClassName: com.mysql.jdbc.Driver
  jpa:
    database-platform: org.hibernate.dialect.MySQL57Dialect
    generate-ddl: true
    show-sql: true
  liquibase:
    change-log: classpath:db/db.master.xml
  data:
    elasticsearch:
      cluster-name: elasticsearch
      cluster-nodes: 127.0.0.1:9300
      repositories:
        enabled: true
  redis:
    host: 127.0.0.1
    port: 6379
    password:
    database: 0
    lettuce:
      pool:
        max-active: 8
        max-wait: -1
        max-idle: 8
        min-idle: 0
        timeout: 0
  servlet:
    multipart:
      max-file-size: 200MB # Max file size.
      max-request-size: 215MB # Max Request Size
      enabled: true

logging:
  pattern:
    file: "%d{yy-MM-dd HH:mm:ss.SSS} [%thread] %-5level : %X{user} %logger{36}.%M - %msg%n"
    console: "%d{yy-MM-dd HH:mm:ss.SSS} [%thread] %-5level : %X{user} %logger{36}.%M - %msg%n"
  level:
    org.springframework.web: DEBUG
    guru.springframework.controllers: DEBUG
    org.hibernate: DEBUG

app:
  wechat:
    notification: true
  design:
    root-path: /home/cloudeda/Aurora/UploadData
  jwt:
    base64-secret: NjkwNjU5ZTg0YmYxZmE0ZDJmYmFlNmMwMGNjMjJjZTc4MjFiZjkyNTk3N2IyN2M5OGQyNzg3ZTExN2M1MGYzMzNkNTg2MzMwODgzZTE3YzIwMDdhMTg1Y2M4ZWFmYmFjOGEyYWNiOTU3ZGYzNTY3NDdmMzg3ZWNjNjRmNjdjNzI=
    # Token is valid 24 hours
    token-validity-in-seconds: 86400
    token-validity-in-seconds-for-remember-me: 2592000
  id:
    data-center: 1
    machine: 1

  server:
    broker: tcp://localhost:5555
  flask:
    ibis-parser-url: http://localhost:5050/api/v3/server/parse-ibis-model
    generate-report-url: http://localhost:5050/api/v3/server/report

security:
  user:
    name: aurora
    password: aurora-monitor-password

elasticsearch:
  host: 127.0.0.1
  port: 9300
  cluster:
    name: elasticsearch

Should be related to the configuration of the ES
ESConfig.java
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
public class ESConfig {

    @Value("${elasticsearch.host:127.0.0.1}")
    private String host;

    @Value("${elasticsearch.port:9300}")
    private int port;

    @Value("${elasticsearch.cluster.name:elasticsearch}")
    private String clusterName;

    public String getHost() {
        return this.host;
    }

    public int getPort() {
        return this.port;
    }

    @Bean
    public Client client() {
        TransportClient client = null;

        Settings settings = Settings.builder()
            .put("cluster.name", clusterName)
            .put("client.transport.ignore_cluster_name", false)
            .build();

        try {
            client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        return client;
    }
}

Controller
import com.aurora.backend.beans.ResultBean;
import com.aurora.backend.beans.WorkerLogBean;
import com.aurora.backend.param.SearchSimulationLogParam;
import com.aurora.backend.security.CurrentUser;
import com.aurora.backend.security.UserPrincipal;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "/es")
@Slf4j
public class WokerLogController {

    @Autowired Client client;

    @PostMapping(value = "/simulation/log")
    public ResultBean getSimulationLog(
        @CurrentUser UserPrincipal user,
        @RequestBody SearchSimulationLogParam param
    ) {

        SearchResponse response = client.prepareSearch("logstash-worker")
            .setTypes("doc")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(QueryBuilders.matchQuery("logtype", 1))
            .setQuery(QueryBuilders.matchQuery("token", param.getToken()))
            .setPostFilter(
                QueryBuilders.rangeQuery("@timestamp")
                    .from(param.getStartTime()).to(param.getEndTime()))
            .get();

        SearchHit[] hits = response.getHits().getHits();
        List<WorkerLogBean> mapList = new ArrayList<>();
        for (int i = 0; i < hits.length; i++) {
            WorkerLogBean logBean = new WorkerLogBean();
            logBean.setId(hits[i].getId());
            logBean.setLog(hits[i].getSourceAsMap().get("log").toString());
            logBean.setMessage(hits[i].getSourceAsMap().get("message").toString());
            mapList.add(logBean);
        }
        return new ResultBean(mapList);
    }
}

A: This is where your exception is:

Caused by:
  org.springframework.beans.factory.UnsatisfiedDependencyException:
  Error creating bean with name 'wokerLogController': Unsatisfied
  dependency expressed through field 'client'; nested exception is
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'client' defined in class path resource

and

Caused by: org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'client' defined in class path resource
  [com/aurora/backend/config/ESConfig.class]: Bean instantiation via
  factory method failed; nested exception is
  org.springframework.beans.BeanInstantiationException: Failed to
  instantiate [org.elasticsearch.client.Client]: Factory method 'client'
  threw exception; nested exception is java.lang.IllegalStateException:
  availableProcessors is already set to [4], rejecting [4] at

and

Caused by: org.springframework.beans.BeanInstantiationException:
  Failed to instantiate [org.elasticsearch.client.Client]: Factory
  method 'client' threw exception; nested exception is
  java.lang.IllegalStateException: availableProcessors is already set to
  [4], rejecting [4] at

This problem has been reported in this link. Haven't faced this problem with elastic search. The following might solve your problem but this might be webserver dependent. Check this.
@Component
public class ElasticSearchConfiguration implements InitializingBean {
    static {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println(System.getProperty("es.set.netty.runtime.available.processors"));
    }
}

A: It could be a dependency issue. Anyway, if you are using spring boot 2.., go with rest client instead of transport client which is deprecated.
Use the following code:
build.gradle:
compile "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
    compile "com.fasterxml.jackson.core:jackson-annotations"
    compile "com.fasterxml.jackson.core:jackson-databind"
    compile "com.fasterxml.jackson.module:jackson-module-afterburner"
    runtime group: 'com.fasterxml.jackson.module', name: 'jackson-modules-java8', version: '2.9.8', ext: 'pom'
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-parameter-names
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: '2.9.8'

compile 'org.elasticsearch:elasticsearch'
    compile 'org.elasticsearch.client:transport'
    compile 'org.elasticsearch.client:elasticsearch-rest-client'
    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client'

    compile 'org.springframework.data:spring-data-elasticsearch'

Versions: Should be Compatible
org.elasticsearch.client:elasticsearch-rest-client -> 6.4.3 (*)
org.elasticsearch.client:elasticsearch-rest-high-level-client -> 6.4.3
org.elasticsearch:elasticsearch -> 6.4.3
org.springframework.data:spring-data-elasticsearch -> 3.1.4.RELEASE
com.fasterxml.jackson.datatype:jackson-datatype-hppc -> 2.9.8
com.fasterxml.jackson.core:jackson-core:2.9.8
com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
com.fasterxml.jackson.datatype:jackson-datatype-jsr310 -> 2.9.8 (*)
com.fasterxml.jackson.datatype:jackson-datatype-hibernate5 -> 2.9.8
com.fasterxml.jackson.core:jackson-annotations -> 2.9.0
com.fasterxml.jackson.module:jackson-module-afterburner -> 2.9.8
com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.8 (*)
com.fasterxml.jackson.module:jackson-modules-java8:2.9.8

ElasticSearchConfiguration:
RestHighLevelClient client = null;

@Bean
public RestHighLevelClient buildClient() {
    return new RestHighLevelClient(
            RestClient.builder(
                    new HttpHost("localhost", 9200, "http"),
                    new HttpHost("localhost", 9201, "http")));
}

@Bean
@Primary
public ElasticsearchOperations elasticsearchTemplate() {
    return new ElasticsearchTemplate((Client) buildClient(), new CustomEntityMapper(new ObjectMapper()));
}

public class CustomEntityMapper implements EntityMapper {

    private ObjectMapper objectMapper;

    public CustomEntityMapper(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        //objectMapper.registerModule(new JavaTimeModule());
        JavaTimeModule javaTimeModule=new JavaTimeModule();
        // Hack time module to allow 'Z' at the end of string (i.e. javascript json's)
        javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ISO_DATE_TIME));
        javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ISO_DATE));
        objectMapper.registerModule(javaTimeModule);

        objectMapper.findAndRegisterModules();
    }

    @Override
    public String mapToString(Object object) throws IOException {
        return objectMapper.writeValueAsString(object);
    }

    @Override
    public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
        return objectMapper.readValue(source, clazz);
    }
}


text:
Q: How to select and store ContentElement UID in Flux FlexForm Configuration? I'm currently building a TYPO3 PageTemplate with Flux and Fluidpages (both GitHub Master-Branch).
I'd like to have the possibility to select a number of ContentElements from the PageTree and store the UIDs in a variable for later rendering.
My first approach combining a Flux TreeField with a RelationField:
  <flux:form.sheet name="content" label="content settings">
    <flux:field.tree
      name="treetest"
      label="treetest"
      table="pages"
      parentField="pid"
      foreignLabel="title"
      multiple="true"
      minItems="0"
      maxItems="1000"
      size="8"
      expandAll="false"
    />
    <flux:field.relation
      name="relationtest"
      label="relationtest"
      table="tt_content"
      condition="AND tt_content.pid IN ({treetest})"
      multiple="true"
      size="8"
      minItems="0"
      maxItems="3"
    />
  </flux:form.sheet>

This sadly results in a SQL-Error because the last condition is inserted as:
  AND tt_content.pid IN (60|foo)

Where 'foo' is the title of a SysFolder with the UID 60.
Debug-Output in the frontend prints the field 'treetest' as:
  treetest => '60' (2 chars)

and the condition for the field 'relationtest' as:
  condition => 'AND tt_content.pid IN (60)' (26 chars)

Questions:

*

*As a matter of fact, I'm missing something here and I'd appreciate any hint, where the crux is here?

*Is there maybe a different solution to select a ContentElement from the PageTree?

A: 1) It is possible that you have either a default value, an inherited value or somehow disconnected XML which contains the other value. To be 100% sure none of these are your cause, try the same on a completely new page. The expected result of your code and selecting a page UID, is exactly the value 60 - nothing more, nothing less.
2) You may find it easier to use a ###STORAGE_PID### marker in your foreign_table_where and selecting the page(s) allowed for content selection, as values in the Behavior tab when editing your content element or page. This value has the added benefit of being possible to allow only for certain users or usergroups, or admins only.


text:
Q: How to add a value to an array list using Scanner class I want to ask how can I add a value to the arraylist using Scanner class without declaring any variable.
List<Integer> cl = new ArrayList<>();
List<String> al = new ArrayList<>();

System.out.println("Enter the name of the account user");
String name = si.next();
System.out.println("Enter the amount you want to deposit in your account");
int amount= si.nextInt();
cl.add(amount);
al.add(name);

Like in this code I want to add values to the array list without using the variables name and amount.

A: Scanner si = new Scanner(System.in);

List<Integer> cl = new ArrayList<>();
List<String> al = new ArrayList<>();

System.out.println("Enter the name of the account user");
al.add(si.nextLine());
System.out.println("Enter the amount you want to deposit in your account");
cl.add(si.nextInt());
si.nextLine();

The nextLines are for if you want to use the scanner after this code, now there won't still be new line characters in the scanner that could mess up your input.
I also swapped next() for nextLine() in case you'd want to enter a name that contains spaces. (nextLine() returns everything until there's a \n and it also drops the \n.)


text:
Q: IDempiere Service Integration I need to call Idempiere Business Modules (ex. Creating Purchase Order process) , not tables via a web services, Is there any way to do this without going through the source code of Idempiere, I don't want to use RESTful methods that will deal with tables directly

A: You are probably referring to improvements on iDempiere's Web Services where composite (master-detail) and CRUD actions are now possible. Complete description at the project wiki: http://wiki.idempiere.org/en/NF1.0_Web_Services_Improvements
Below I paste results of https://test.idempiere.org/ADInterface/services
Available SOAP services:
CompositeService
compositeOperation

Endpoint address: http://test.idempiere.org/ADInterface/services/compositeInterface

WSDL : {http://idempiere.org/ADInterface/1_0}compositeInterface
Target namespace: http://idempiere.org/ADInterface/1_0
ModelADService
setDocAction
createUpdateData
getList
readData
createData
runProcess
queryData
deleteData
updateData

Endpoint address: http://test.idempiere.org/ADInterface/services/ModelADService

WSDL : {http://idempiere.org/ADInterface/1_0}ModelADService
Target namespace: http://idempiere.org/ADInterface/1_0
Available RESTful services:
Endpoint address: http://test.idempiere.org/ADInterface/services/rest
WADL : http://test.idempiere.org/ADInterface/services/rest?_wadl

A: You can use create a provide service interface from org.adempiere.base plugin, invoke this service inside your code and invoke the constructor for class MOrder extends X_C_Order and for class MOrderLine extends X_C_OrderLine.
Here you have the example from IProcessFactory (you can create your factory like ICreateOrderFactory , or just IInsertFactory ( for a generic factory constructor you can set the table id  ) :
This is a interface declaration
public interface IProcessFactory {
    /**
     * Create new process instance
     * @param className
     * @return new process instance
     */

  public ProcessCall newProcessInstance(String className);

    }

This is a evocation method
    public class ProcessFactory implements IProcessFactory {
    @Override
    public ProcessCall newProcessInstance(String className) {
        if (className.equals("com.com.nexus.webservice.client.process.IntegratorWS"))
            return new IntegratorWS();
        else
            return null;
    }
}

Now you need to create .xml of this factory like that : (pay attention in provided interface)
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.nexus.integrator.ProcessFactory">
<implementation class="com.nexus.webservice.client.process.ProcessFactory"/>
<property name="service.ranking" type="Integer" value="5"/>
<service>
<provide interface="org.adempiere.base.IProcessFactory"/>
</service>
</scr:component>

To use this in OSGI architecture, you need to configure your MANIFEST file to import this
Service-Component: ( I always use osgi-inf directory for my factories xml)
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.nexus.webservice.client
Bundle-SymbolicName: com.nexus.webservice.client;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Macrosoftware
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.adempiere.base

Service-Component: OSGI-INF/ProcessFactory.xml

Import-Package: org.osgi.framework

You can do this , or you can use composite webservice .
I consider the second most safe and effective method


text:
Q: Why is this a* algorithm is slower than Djikstra's? I need to show how a* is quicker than Djikstra's using the graph below. I wrote the a* search function and then called it using a set of heuristics and then with all heuristics set to 0 (which is equivalent to Djikstra's). While the actual search with a* is more efficient, five steps to Djikstras seven, the recorded time it takes it to run is always higher, even averaged across numerous runs. The a* run with actual heuristic values is doing less so shouldnt it be faster? (Maybe my code is wonky?)
import heapq as heap

#Create graph

graph =    {
    'A': {'B':5},
    'B': {'C':8,'D':9,'E':3},
    'C': {'B':8,'G':2},
    'D': {'B':9,'F':2},
    'E': {'B':3,'I':4},
    'F': {'D':2,'I':3},
    'G': {'C':2,'H':3,'I':6},
    'H': {'G':3,'J':4},
    'I': {'E':4,'F':3,'G':6,'J':2},
    'J': {'H':4,'I':2},
    }

hcost =    {
    'A': 875.008571,
    'B': 717.54094,
    'C': 720.151373,
    'D': 685.286801,
    'E': 596.030201,
    'F': 434.165867,
    'G': 420.107129,
    'H': 190.779978,
    'I': 179.744263,
    'J': 0,
    }

hcost1 =    {
    'A': 0,
    'B': 0,
    'C': 0,
    'D': 0,
    'E': 0,
    'F': 0,
    'G': 0,
    'H': 0,
    'I': 0,
    'J': 0,
    }

def astar_algo(graph, start, target, hc):

    #We set the cost for all nodes from the source
    cost =  {vertex: float('infinity') for vertex in graph}
    #The distance from the source to itself is 0
    cost[start]=0

    #We create
    fcost={vertex: float('infinity') for vertex in graph}
    fcost[start]=hc[start]

    #We create a list of nodes to record the path i.e. the solution to the problem
    path=set()

    #We create a set to hold visited nodes
    visited=set()

    #We create a priority queue which contains distance to node,node,path and add our start node
    priorityq = [(fcost[start], start, [])]

    #While our priority queue isn't empty
    while priorityq:

        #pq0 =  [priorityq[idx][0] for idx in range(0, len(priorityq), 1)]
        #pq1 =  [priorityq[idx][1] for idx in range(0, len(priorityq), 1)]
        #print(f"Priority Queue: {list(zip(pq0,pq1))}\n")
        #We pop out the highest priority element of the queue i.e. the shortest distance entry
        (dist,current_node,path) = heap.heappop(priorityq)

        #print(f"dist {dist} current node {current_node} \tpath {path}\n")

        #Add it to the path list and record it as being visisted
        path = path+[current_node]
        visited.add(current_node)

        #We check if its our target, if it is we break the while loop with a return value
        if current_node==target:
            #We return a tuple with the target node and the cost to it as well as the path to it
            return (current_node,cost[current_node]), path

        #If it isnt our target node then we check all its adjacent nodes
        for adj_node, weight in graph[current_node].items():

            #If we've visited the node we move on to the nest
            if adj_node in visited:
                continue

            #If the node is new we calculate the cost to it by adding the weight to it to
            #the cost for the current node
            new_cost = cost[current_node]+weight

            #calculate fcost = graph cost + heuristic cost
            new_fcost = new_cost+hc[adj_node]

            #If the cost to the adjacent node is shorter than its recorded cost
            if cost[adj_node] > new_cost:
                #We update its recorded cost
                cost[adj_node]=new_cost

            #If the fcost to the adjacent node is shorter than its recorded fcost
            if fcost[adj_node] > new_fcost:
                #We update its recorded cost
                fcost[adj_node]=new_fcost
                #And it to the priority queue
                heap.heappush(priorityq, (new_fcost,adj_node,path))

    return (0,0),'none'

start='A'
target='J'

st =  perf_counter_ns()
cost,path = astar_algo(graph,start,target,hcost)
print('Time elapsed in nanoseconds {}\n'.format(perf_counter_ns() - st))

st =  perf_counter_ns()
cost,path = astar_algo(graph,start,target,hcost1)
print('Time elapsed in nanoseconds {}\n'.format(perf_counter_ns() - st))

if path=='none':
    print("There is no solution available.")
else:
    print(f"The distance to {cost[0]} is {cost[1]}.")
    print (f"The shortest path from {start} to {target} is",end=" ")
    print(*path, sep="->")

A: You can't just run a tiny code fragment once and take a nanosecond reading, even if your computer has an accurate nanosecond timer (which it probably doesn't). Memory caching and random chance of what else is happening in the computer are going to dominate the measurement (if it's accurate, which it's not).
Fortunately, python provides a timeit module which automates the process of running code over and over, and recording the time. I changed some variable names for clarity, but here is a snippit using timeit to get the times:
# I renamed some variables for clarity
from timeit import timeit

astar_time = timeit('cost, path = astar_algo(graph, start, target, hcost_astar)', globals=globals(), number=10000)
print ('astar time    {}'.format(astar_time))

djikstra_time = timeit('cost, path = astar_algo(graph, start, target, hcost_djikstra)', globals=globals(), number=10000)
print ('djikstra time {}'.format(djikstra_time))

astar time   0.4517704
djikstra time 0.5962602


text:
Q: Converting list requested from api to dataframe AttributeError: 'list' object has no attribute 'keys' trying to get intraday historical data for some years from eod api eod intraday api
from datetime import datetime
dates=[ '01-01-2021','01-04-2021','01-07-2021','01-10-2021',
        '01-01-2022','01-04-2022','01-07-2022']

# Convert your strings to datetime, using `datetime` library
dates = [datetime.strptime(date, "%d-%m-%Y") for date in dates]

def create_df(pair,dates):
    df = []
    for index, elem in enumerate(dates):
        if index== 0:
            curr_date = str(elem.timestamp())
            next_date = str(dates[index+1].timestamp())
            df = client.get_prices_intraday(pair, interval = '1m', from_ = curr_date, to = next_date)
        elif ((index>0) & (index+1 < len(dates))):
            curr_date = str(elem.timestamp())
            next_date = str(dates[index+1].timestamp())
            df2 = client.get_prices_intraday(pair, interval = '1m', from_ = curr_date, to = next_date)
            df.append(df2)
    return df

from eod import EodHistoricalData
# create the instance of the SDK
api_key = 'my_api_key'
client = EodHistoricalData(api_key)

GBPAUD = create_df('GBPAUD.FOREX',dates)

what gives me something like:
GBPAUD

[{'timestamp': 1609693200,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:00:00',
  'open': 1.77086,
  'high': 1.77086,
  'low': 1.77086,
  'close': 1.77086,
  'volume': 1},
 {'timestamp': 1609693260,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:01:00',
  'open': 1.77086,
  'high': 1.77086,
  'low': 1.77086,
  'close': 1.77086,
  'volume': 1},
 {'timestamp': 1609693320,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:02:00',
  'open': 1.77086,
  'high': 1.77086,
  'low': 1.77086,
  'close': 1.77086,
  'volume': 1},
 {'timestamp': 1609693380,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:03:00',
  'open': 1.77086,
  'high': 1.77222,
  'low': 1.77086,
  'close': 1.77199,
  'volume': 14},
 {'timestamp': 1609693440,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:04:00',
  'open': 1.77203,
  'high': 1.77348,
  'low': 1.77176,
  'close': 1.77199,
  'volume': 23},

that is stored as a list, but when I try to convert to pandas dataframe :
GBPAUD = pd.DataFrame(GBPAUD)

--------------------------------------------------------------------------- AttributeError                            Traceback (most recent call
last) Input In [39], in <cell line: 1>()
----> 1 GBPAUD = pd.DataFrame(GBPAUD)
File
~/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/pandas/core/frame.py:694,
in DataFrame.init(self, data, index, columns, dtype, copy)
689     if columns is not None:
690         # error: Argument 1 to "ensure_index" has incompatible type
691         # "Collection[Any]"; expected "Union[Union[Union[ExtensionArray,
692         # ndarray], Index, Series], Sequence[Any]]"
693         columns = ensure_index(columns)  # type: ignore[arg-type]
--> 694     arrays, columns, index = nested_data_to_arrays(
695         # error: Argument 3 to "nested_data_to_arrays" has incompatible
696         # type "Optional[Collection[Any]]"; expected "Optional[Index]"
697         data,
698         columns,
699         index,  # type: ignore[arg-type]
700         dtype,
701     )
702     mgr = arrays_to_mgr(
703         arrays,
704         columns,    (...)
708         typ=manager,
709     )
710 else:
File
~/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/pandas/core/internals/construction.py:483,
in nested_data_to_arrays(data, columns, index, dtype)
480 if is_named_tuple(data[0]) and columns is None:
481     columns = ensure_index(data[0]._fields)
--> 483 arrays, columns = to_arrays(data, columns, dtype=dtype)
484 columns = ensure_index(columns)
486 if index is None:
File
~/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/pandas/core/internals/construction.py:799,
in to_arrays(data, columns, dtype)
797     arr = _list_to_arrays(data)
798 elif isinstance(data[0], abc.Mapping):
--> 799     arr, columns = _list_of_dict_to_arrays(data, columns)
800 elif isinstance(data[0], ABCSeries):
801     arr, columns = _list_of_series_to_arrays(data, columns)
File
~/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/pandas/core/internals/construction.py:884,
in _list_of_dict_to_arrays(data, columns)
882     gen = (list(x.keys()) for x in data)
883     sort = not any(isinstance(d, dict) for d in data)
--> 884     pre_cols = lib.fast_unique_multiple_list_gen(gen, sort=sort)
885     columns = ensure_index(pre_cols)
887 # assure that they are of the base dict class and not of derived
888 # classes
File
~/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/pandas/_libs/lib.pyx:400,
in pandas._libs.lib.fast_unique_multiple_list_gen()
File
~/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/pandas/core/internals/construction.py:882,
in (.0)
862 """
863 Convert list of dicts to numpy arrays
864     (...)
879 columns : Index
880 """
881 if columns is None:
--> 882     gen = (list(x.keys()) for x in data)
883     sort = not any(isinstance(d, dict) for d in data)
884     pre_cols = lib.fast_unique_multiple_list_gen(gen, sort=sort)
AttributeError: 'list' object has no attribute 'keys'

anybody has a more elegant way to get a lot of data from that api, or a way to fix the error ?
Thanks

A: Your example data read into pandas correctly (after closing the list).  Without looking at your data (please share a snippet instead of a link to sign up for a service), in your for loop, you're adding your data in to the df variable in two different ways which creates a list of lists after a single list and no key.  That is what pandas is complaining about.  In the below example, which has a minimized version of your code, and uses your data as an input, observe the output after:
data = [{'timestamp': 1609693200,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:00:00',
  'open': 1.77086,
  'high': 1.77086,
  'low': 1.77086,
  'close': 1.77086,
  'volume': 1},
 {'timestamp': 1609693260,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:01:00',
  'open': 1.77086,
  'high': 1.77086,
  'low': 1.77086,
  'close': 1.77086,
  'volume': 1},
 {'timestamp': 1609693320,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:02:00',
  'open': 1.77086,
  'high': 1.77086,
  'low': 1.77086,
  'close': 1.77086,
  'volume': 1},
 {'timestamp': 1609693380,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:03:00',
  'open': 1.77086,
  'high': 1.77222,
  'low': 1.77086,
  'close': 1.77199,
  'volume': 14},
 {'timestamp': 1609693440,
  'gmtoffset': 0,
  'datetime': '2021-01-03 17:04:00',
  'open': 1.77203,
  'high': 1.77348,
  'low': 1.77176,
  'close': 1.77199,
  'volume': 23}]
df = []
dates = [1,2,3]
for index, elem in enumerate(dates):
    if index== 0:
        # df = client.get_prices_intraday(pair, interval = '1m', from_ = curr_date, to = next_date)
        df = data
    elif ((index>0) & (index+1 < len(dates))):
        # df2 = client.get_prices_intraday(pair, interval = '1m', from_ = curr_date, to = next_date)
        df2 = data
        df.append(df2)
print(df)

your output is:
[{'timestamp': 1609693200, 'gmtoffset': 0, 'datetime': '2021-01-03 17:00:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693260, 'gmtoffset': 0, 'datetime': '2021-01-03 17:01:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693320, 'gmtoffset': 0, 'datetime': '2021-01-03 17:02:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693380, 'gmtoffset': 0, 'datetime': '2021-01-03 17:03:00', 'open': 1.77086, 'high': 1.77222, 'low': 1.77086, 'close': 1.77199, 'volume': 14}, {'timestamp': 1609693440, 'gmtoffset': 0, 'datetime': '2021-01-03 17:04:00', 'open': 1.77203, 'high': 1.77348, 'low': 1.77176, 'close': 1.77199, 'volume': 23}, [...], [...]]

See the two lists it has at the end?  What I think you wanted, using the same list data, was this
df = []
dates = [1,2,3]
for date in dates:
        df += data
print(df)

which outputs this:
[{'timestamp': 1609693200, 'gmtoffset': 0, 'datetime': '2021-01-03 17:00:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693260, 'gmtoffset': 0, 'datetime': '2021-01-03 17:01:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693320, 'gmtoffset': 0, 'datetime': '2021-01-03 17:02:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693380, 'gmtoffset': 0, 'datetime': '2021-01-03 17:03:00', 'open': 1.77086, 'high': 1.77222, 'low': 1.77086, 'close': 1.77199, 'volume': 14}, {'timestamp': 1609693440, 'gmtoffset': 0, 'datetime': '2021-01-03 17:04:00', 'open': 1.77203, 'high': 1.77348, 'low': 1.77176, 'close': 1.77199, 'volume': 23}, {'timestamp': 1609693200, 'gmtoffset': 0, 'datetime': '2021-01-03 17:00:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693260, 'gmtoffset': 0, 'datetime': '2021-01-03 17:01:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693320, 'gmtoffset': 0, 'datetime': '2021-01-03 17:02:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693380, 'gmtoffset': 0, 'datetime': '2021-01-03 17:03:00', 'open': 1.77086, 'high': 1.77222, 'low': 1.77086, 'close': 1.77199, 'volume': 14}, {'timestamp': 1609693440, 'gmtoffset': 0, 'datetime': '2021-01-03 17:04:00', 'open': 1.77203, 'high': 1.77348, 'low': 1.77176, 'close': 1.77199, 'volume': 23}, {'timestamp': 1609693200, 'gmtoffset': 0, 'datetime': '2021-01-03 17:00:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693260, 'gmtoffset': 0, 'datetime': '2021-01-03 17:01:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693320, 'gmtoffset': 0, 'datetime': '2021-01-03 17:02:00', 'open': 1.77086, 'high': 1.77086, 'low': 1.77086, 'close': 1.77086, 'volume': 1}, {'timestamp': 1609693380, 'gmtoffset': 0, 'datetime': '2021-01-03 17:03:00', 'open': 1.77086, 'high': 1.77222, 'low': 1.77086, 'close': 1.77199, 'volume': 14}, {'timestamp': 1609693440, 'gmtoffset': 0, 'datetime': '2021-01-03 17:04:00', 'open': 1.77203, 'high': 1.77348, 'low': 1.77176, 'close': 1.77199, 'volume': 23}]

and reads into pandas or cudf just fine.


text:
Q: How to get rid of the Invalide CSRF token error I have a symfony form. Submitting it, I have an error message :
The CSRF token is invalid. Please try to resubmit the form.

I dont know why I have this. I bind request to form after checking the request method is post :
if ($request->getMethod() === 'POST') {
        $form->handleRequest($request);
}

Here is the type of the form.
class PasswordActionType extends AbstractType {
protected $forgotten_password;

public function __construct($forgotten_password) {
    $this->forgotten_password = $forgotten_password;
}

public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options) {
    $builder->add('identifiant', 'text', array('attr' => array('style' => 'width:250px')));

    if(!$this->forgotten_password) {
        $builder->add('ancienMDP', 'password', array(
            'label' => 'Ancien MDP',
            'attr' => array(
                'class' => 'ligne',
                'style' => 'width:252px'
        )));
        $builder->add('nouveauMDP', 'repeated', array(
            'type' => 'password',
            'invalid_message' => 'Confirmation différente du nouveau mot de passe',
            'first_options' => array('label' => 'Nouveau MDP'),
            'second_options' => array('label' => 'Confirmer'),
            'options' => array(
                'attr' => array(
                    'class' => 'ligne',
                    'style' => 'width:252px'
            ))
        ));
    } else {
        $builder->add('ancienMDP', 'hidden', array('error_bubbling' => false, 'data' => 'NULL'));
        $builder->add('nouveauMDP', 'hidden', array('error_bubbling' => false, 'data' => 'NULL'));
    }
}

public function configureOptions(\Symfony\Component\OptionsResolver\OptionsResolver $resolver) {
    $resolver->setDefaults(array(
       'data_class' => 'My\Bundle\Security\PasswordAction',
       'csrf_protection' => true,
       'csrf_field_name' => 'token'
    ));
}

public function getName() {
    return 'cramif_password_action';
}

}
So 2 forms use the same builder. The difference is the value of "forgotten_password".
form1 : forgotten_password = true
the 2 fields 'ancienMDP' and 'NouveauMDP' are hidden html fields
form2: forgotten_password = false
the 2 fields are what u can see.
There is not problem with form1, no CSRF error.
The problem occurs with form2.
Note : the 2 forms are displayed with Twig with the same commands.
Note2 : in the twig template I have a form_rest

A: Just to help people :
If u think u did it right :

*

*bind the request after checking that the form is posted

*used form_rest.
Check that you did not invalidate your session. Of course, for the CSRF to work, you need a valid session.


text:
Q: Show tooltip using JavaScript I am trying to show a tooltip by hovering the mouse on a circle inside a canvas. While the CSS is changing from hidden to visible by javaScript (saw that through chrome inspect), the tooltip is not showing up. Please help to sort this out. Thank you for your help.

const canvas = document.getElementById('flower');
const ctx = canvas.getContext('2d');

const circle2 = new Path2D();
                        circle2.arc(100, 100, 25, 0, 2 * Math.PI);
                        ctx.fillStyle = "red";
                        ctx.fill(circle2);

canvas.addEventListener("mousemove", function(event2) {
                            if (ctx.isPointInPath(circle2, event2.clientX, event2.clientY)) {
                                showtext();
                            }
                        });

function showtext(){
    document.getElementById("tooltiptext").style.visibility = 'visible';
}
html, body, div, canvas {
        width:  100%;
        height: 100%;
        margin: 0;
}
    .tooltip {
        position: relative;
        display: inline-block;
        border-bottom: 1px dotted black;
    }
    .tooltip .tooltiptextstyle {
        visibility: hidden;
        display: block;
        width: 120px;
        background-color: black;
        color: #fff;
        text-align: center;
        padding: 5px 0;
        border-radius: 6px;
        position: absolute;
        z-index: 1;
    }
<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link type="text/css" href="style.css"/>

        <canvas id="flower">

                blah

        </canvas>

A: you need to move the .tooltip element out of the canvas element, otherwise it won't display.

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

// Create circle
const circle = new Path2D();
circle.arc(150, 75, 50, 0, 2 * Math.PI);
ctx.fillStyle = 'red';
ctx.fill(circle);

// Listen for mouse moves
canvas.addEventListener('mousemove', function(event) {
  // Check whether point is inside circle
  if (ctx.isPointInPath(circle, event.clientX, event.clientY)) {
    showtext();
  } else {
    hidetext();
  }
});

function showtext() {
  document.getElementById("tooltiptext").style.visibility = 'visible';
}

function hidetext() {
  document.getElementById("tooltiptext").style.visibility = 'hidden';
}
.tooltip {
  visibility: hidden;
  position: absolute;
  top: 20px; left: 20px;
}

body {
  margin: 0;
}
<canvas id="canvas"></canvas>

  blah

A: There were two issues:

*

*The manner in which you were applying styles to your canvas were causing its display not to match its internal tracking of the position of the items it contained, so the if condition was not necessarily returning true when the cursor was over where the circle was appearing.

*A canvas cannot render and display contents.

As such, the below snippet shows a version of this that works.  You'll need to figure out how to position things correctly, but it solves the immediate issue.

const canvas = document.getElementById('flower');
const ctx = canvas.getContext('2d');

const circle2 = new Path2D();
circle2.arc(100, 100, 25, 0, 2 * Math.PI);
ctx.fillStyle = "red";
ctx.fill(circle2);

canvas.addEventListener("mousemove", function(event2) {
  if (ctx.isPointInPath(circle2, event2.clientX, event2.clientY)) {
    showtext();
  }
});

function showtext(){
    document.getElementById("tooltiptext").style.visibility = 'visible';
}
html, body, div {
  width:  100%;
  height: 100%;
  margin: 0;
}
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}
.tooltip .tooltiptextstyle {
    visibility: hidden;
    display: block;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;
    position: absolute;
    z-index: 1;
}
<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link type="text/css" href="style.css"/>

        <canvas id="flower">
        </canvas>

            blah

A: The problem was that you set the width and height of the canvas as the 100% of the parent in the css.
You need to set the canvas's width and height attribute instead.
html, body, div, canvas {
        width:  100%;
        height: 100%;
        margin: 0;
}

html, body, div {
        width:  100%;
        height: 100%;
        margin: 0;
}
<canvas id="canvas" width="200" height="200">


text:
Q: How can I manage child rows in DataTables using AJAX I am trying to bind a child table to a parent table with drill-down [build a DataTable where the main table data row can be expanded to show an embedded child row data]
I follow Ajax loaded row details blog this
I am not able to figure out how this can be managed when the data for the child table is coming through a separate AJAX call which then creates a dynamic table build a child DataTable where each row can be expanded to show an embedded parent DataTable
I had already managed it through an ajax call, and data coming from DB as except
every time I open drill down it adds new
 into the parent table for child row that's why the child table
  layout  tables Exceed their Size from a parent table
I  add an image table view for reference please review the table structure
Here the table structure after drill down open how it appends the
 inside the parent table according to it's raw table structure
below is the code
// Add event listener for opening and closing details
    $('#my-table tbody').off('click', 'td.details-control');
    $('#my-table tbody').on('click', 'td.details-control', function () {
        tr = $(this).closest('tr');
        console.log(tr);
        row = exporterListTable.row( tr );
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child(Details(row.data()) ).show();
            tr.addClass('shown');
        }
    } );

and then the format() will be
    function format ( rowData ) {
        div = $('
')
            .addClass( 'loading' )
            .addClass( 'table_child')
            .text( 'Loading...' );
        $.ajax( {
            url: 'get-table-items(details)',
            data: {
                yearMonth: rowData[1],
                productFilterName
            },
            dataType: 'json',
            success: function ( json ) {
                div.html(json)
                div.removeClass( 'loading' )
                if(json.length > 0){
                    div.append("
TABLE FIELD
")
                    var len = json.length;
                    for (var i = 0; i < len; i++) {
                        div.append("
"+JSON+"
");
                    }
                }
            }
        } );
            return div;
    }

and here is an ajax call
 function ExportersDetails ( rowData ) {
        div = $('
')
            .addClass( 'loading' )
            .addClass( 'table_child')
             .addClass('table-responsive')
            .text( 'Loading...' );
        $.ajax( {
            url: 'get-exporters-details',
            data: {
                exporter: rowData[1],
                overallFilter
            },
            dataType: 'json',
            success: function ( json ) {
                div.html(json)
                div.removeClass( 'loading' )
                if(json.length > 0){
                    div.append("
TABLE FIELD
")
                    var len = json.length;
                    for (var i = 0; i < len; i++) {
                        div.append("
"+JSON+"
");
                    }
                }
            }
        });
        return div;
    }

please help me to add the
 before the
 tag add, I already made many changes seems doesn't help!

A: var newHtml = "";
   newHtml += '
'+ addyourvariablecontent +'
';
   var newConHtml = '

' + newHtml  + '

';
   $("#yourID").html(newConHtml);
// this will help you to solve the problem, you can call your data in creating html+ variable then you can append the your data.

A: Finally after too many effort and exploring the web, successfully I found what I'm trying to achieve :)
here is the solution which I wrote if it helps others who may face the table structure related solution
In an ajax success call, I add class and whichever tag want to use
success: function ( json ) {
            div.html(json)
            div.removeClass( 'loading' )
            div.addClass('col-xl-12')
            if(json.length > 0){
                div.append("

TABLE FILEDS

")

                var tbody = $('#details')
                var len = json.length;
                for (var i = 0; i < len; i++) {
                    tbody.append("
"+[json]+"
");
                }
                tbody.append('

')
            }
        }

Thank you!


text:
Q: How to get properties of the object subjected to event using Fabric.js? Using Fabric.js 1.1.6, I have the following:
var rect = new fabric.Rect({});
rect.on('moving', function(obj) {
    // I want to retrieve and set properties from the
    // object rect from inside this event function
});

*

*Is it possible to retrieve and modify the rect properties from inside the function called by the event?

*If it is, how do I do that?

*If it is not, any suggestions on how could I modify rect properties from inside the event function?

Thank you in advance!
--
Update: The above question is correctly answered by @plalx, but I actually have this in a greater context:
function SomeClass()
{
    this.rect = new fabric.Rect({});
    this.rect.on('moving', function(obj) {
        // here, this.rect is undefined
    });
}

Well, in the latter context, I can't only use this.rect inside the function, because there this refers to the function, not to SomeClass.
How about now, what are the answers for the three questions above?

A:
"Is it possible to retrieve and modify the rect properties from inside
  the function called by the event?"

Not only it is possible but it is very simple ;) You should read about closures in JavaScript.
For question #1
var rect = new fabric.Rect({});
rect.on('moving', function(obj) {
    rect.someProperty = 'test';
});

For question #2
function SomeClass() {
    var rect = this.rect = new fabric.Rect({});

    this.rect.on('moving', function(obj) {
        // here, this.rect is undefined
        rect.someProperty;
    });
}


text:
Q: Clean Text Rendering I am using "open sans" font in my website. But it render unclear and dirty edges font. IMAGE BELOW

But i see on some another websites that they are using same open sans font but its very clean and retina ready Image below

Why my text edges are untidy and unclean?
ADDITIONAL: I tried disable the stylesheet codes and text rendering is clear and retina ready. But what i am missing?

A: I believe I know how to solve this...add this to your css:
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

I add that to ALL my web projects now. It makes the fonts looks much more crisp :)
Demo
Also, when using web fonts, it's a good idea to deliberately specify the font weight.
h1 {
    font-family: 'Open Sans';
    font-weight: 300; /* 300 is the "light" version of the font, 400 would be "normal" */
}


text:
Q: How to elaborate my program by using an account name appended with an integer to distinguish different account names? Here's my question, For the account name above, if an account name already exists, use an account name appended with an integer to distinguish different account names. For example, if there are three patients with the same account name "abranch", the second one should be named as "abranch1" and the third one should be named as "abranch2". How to elaborate my program by using an account name appended with an integer to distinguish different account names?
Here's is my code for generating the name list:
 with open('all_patients.txt', 'r') as fh:

    for line in fh:

        splited_list = line.split()
        surname = splited_list[1]
        given_name = splited_list[0][0]
        patient_name_u = given_name + surname
        patient_name.append(patient_name_u.lower())

fh.close()
print(patient_name)

A: If your file looks like this
abranch
abranch
abranch

Then you can use Counter
from collections import Counter
with open("file.txt") as f:
    d = [f"{names}_{time}" for names, times in Counter(f.read().splitlines()).items() for time in range(times) ]
print(d)
#['abranch_0', 'abranch_1', 'abranch_2']


text:
Q: Getting around Yahoo's 999 block? I'm using the jquery cross-domain-request JS script to run a list of names from a database through a criminal record search engine.  The JS script uses the "http://query.yahooapis.com/v1/public" vehicle to process the searches to get around the Same Origin Policy.  The problem is, my script runs about 200 names over a 2 minute period a few times a day, and this has resulted in my server's IP address being blocked for periods of time and given an 999 error for overloading the server.
Can anyone think of a way around this?  It isn't a huge amount of traffic.  Like I said, a couple hundred searches maybe 3 or 4 times a day.  I can't block my ip address because the script is being run on a webserver (not my personal pc).
I know this is a very random issue, but it is really causing me a lot of problems.

A: If you know which searches will be run ahead of time, you could schedule the searches to be doled out.
If the searches are live and dynamic you could perform them in smaller batches with a sleep between batches. Present the data returned by previous batches while you wait for the later batches to complete. See, for instance, the kayak.com interface for searching flights - early results populate while kayak searches for additional results. This approach would only really work well if small delyas were sufficient in overcoming yahoo's rate limiting.


text:
Q: recyclerView.scrollToPosition doesn't fully show the recyclerView last item I use  scrollToPosition(recycler.getAdapter().getItemCount() -1) in order to scroll my recyclerView to the last recyclerView item.
The problem is that all the recyclerView items are fully visible on screen except for the last item which is partially visible on the bottom of the screen. So, when I call scrollToPosition no scrolling occurs. How can I scroll the recyclerView to the last item so it will fully be display on the device screen?

A: Use linearLayoutManager.scrollToPositionWithOffset(count - 1, viewHeight)


text:
Q: Rachinsky quintets
This 1895 painting of Nikolai Bogdanov-Belsky shows mental calculations in the public school of Sergei Rachinsky. Boys in a Russian village school try to calculate $(10^2+11^2+12^2+13^2+14^2)/365$ in their heads. One of the methods of solution is based on the equality $10^2+11^2+12^2=13^2+14^2$. Now this Rachinsky equality can be considered as a generalization of the well-known Pythagorean triple (3,4,5), $3^2+4^2=5^2$, and in analogy with the Pythagorean triples one can define Rachinsky quintets as a set of five positive integers $(a,b,c,d,e)$ such that $a^2+b^2+c^2=d^2+e^2$. It is known that all primitive Pythagorean triples $(a,b,c)$ such that $a^2+b^2=c^2$ are generated by Euclid's formula $a=m^2-n^2$, $b=2mn$, $c=m^2+n^2$, where $m$ and $n$ are positive integers such that $m>n$, $m$ and $n$ are coprime, and $m \not\equiv n \bmod 2$. Can one establish an analogous result for Rachinsky quintets?

A: The equation $a^2+b^2+c^2=d^2+e^2$ defines a quadric  $Q\subset\mathbb{P}^4$, with a rational point $p=(1,0,0,0,1)$. Therefore it is rational : projecting from $p$, say on the hyperplane $e=0$, defines a birational map $Q --> \mathbb{P}^3$. The inverse of that map, namely
$$ (x,y,z,t)\mapsto (x-\lambda ,y,z,t,\lambda )\quad \mbox{with }\lambda :=(x^2+y^2+z^2-t^2)/2x$$
 gives a parametrization of all rational points  in $Q$ with $x\neq 0$; to get integral points just multiply all coordinates by $2x$.  To get the remaining points replace $p$ by $p'=(0,1,0,0,1)$, etc.

A:
The following recipe (algorithm) generates all solutions. It may be viewed as a parametrization in a general(ized) sense.

W.l.o.g. we may assume that $c$ is odd. Then
$$ \left(\frac{x-y}2\right)^2 + \left(\frac{u-v}2\right)^2 + c^2
        \ =\ \left(\frac{x+y}2\right)^2 + \left(\frac{u+v}2\right)^2 $$
where three conditions hold:

*

*$\ x\equiv y\equiv 1\ \mbox{mod}\ 2$

*$\ u\equiv v\equiv 0\ \mbox{mod}\ 2$

*$\ u\cdot v = c^2-x\cdot y$

i.e. we may take arbitrary $x$ and $y$ as in condition 1, and then one decomposes $c^2-x\cdot y$ (see condition 3), where $\ u\ v\ $ are as in condition 2; of course $\ 4\,|\,c^2-x\cdot y\ $ (and the expressions
under the squares are integers).


text:
Q: Why Servlet Filter can be Spring Bean? What i know about Filter and Interceptor is that Filters as J2EE Specifications are part of the webserver and not the Spring framework. So some older articles explain that it is impossible to register filters as Spring Bean while Interceptor is possible.
But the results I got when I tested today is that Filters can be Spring Bean and also inject Spring Bean on Filters are possible too like Interceptors.
(I tested on SpringBoot Framework)
@Component
public class CustomFilterTest implements Filter {

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

    @Override
    public void init(final FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }

}

@RestController
@RequiredArgsConstructor
public class ProductController {

    private final CustomFilterTest customFilterTest;

    @GetMapping("/test")
    public ResponseEntity<Void> temp() {
        System.out.println(customFilterTest);
        return ResponseEntity.noContent().build();
    }
}

Can anyone please explain to me?

A: We have to make a distinction between a regular Spring application and a Spring Boot application here. As with both, you can register a servlet filter as a bean, but the mechanism is a bit different.
Spring Framework
In plain Spring use the DelegatingFilterProxy to achieve this. The task of the DelegatingFilterProxy is to look for a bean with the same name as the filter in the root application context (the ApplicationContext registered through the ContextLoaderListener). This bean has to be your managed servlet filter.
@Configuration
@EnableWebMvc
public class WebConfiguration {

  @Bean
  public void YourFilter myFilter() { ... }
}

Then for the web application you would register a DelegatingFilterProxy with the name myFilter to make this work.
public class MyWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

public void onStartup(ServletContext servletContext)
               throws ServletException {
   super.onStartup(servletContext);
   servletContext.addFilter("myFilter", DelegatingFilterProxy.class);
}

Spring Boot
In Spring Boot it is a bit different as Spring Boot is also in control of your servlet container, like Tomcat. It basically means that Tomcat is also a managed bean in your ApplicationContext and Spring Boot can inject dependencies into it. So when Spring Boot detects a bean for the servlet filter it will automatically add it to the filter chain (without the need of a DelegatingFilterProxy).
Which means only an @Bean for your filter is needed.
@Configuration
public class WebConfiguration {

  @Bean
  public YourFilter myFilter() { ... }
}

Additionally you can configure things like URLs etc. by adding an additional FilterRegistrationBean for this filter.
Conclusion
For plain Spring the DelegatingFilterProxy has been around since Spring 1.2 which was released in 2005. This means if you are reading really, really, really old articles (before 2005) this was true, however with the addition of the DelegatingFilterProxy, this isn't anymore. With the release of Spring Boot, this became even a lesser issue, is it more or less is the only way to register a filter (as a managed bean).


text:
Q: WSAGetLastError() returns negative value after Sendto() fails UDP socket occasionally fails when trying to use Sendto(). I catch the error code with WSAGetLastError(), but the value it returns is negative. The list of WSAGetLastError errors do not list anything negative.
if (sendto(s, buf, sizeof(buf), 0, (struct sockaddr*) &si_sender, si_senderSize) == -1)
{
    int e = WSAGetLastError();
    fprintf(stderr, "Error %d\n", e);
}

I get error: -1073741251
So what is going on here?


text:
Q: CSS в верстке рассылок Кто верстает рассылки. Поделитесь. Во всех статьях призывают использовать таблицы чуть ли не для всего.
1. Можно ли задать основную внешнюю таблицу, а для внутреннего лэйаута использовать div-ы с width-ами, padding-ами и margin-ами? Или вообще обойтись без таблиц.
2. Как лучше верстать списки с нестандартными маркерами?
3. Какие программы/сервисы сейчас являются слабым звеном?
A: *

*Про это лучше забыть. Только таблицы, если не хотите, чтобы содержимое расползалось в различных почтовых клиентах.

*Маркер в виде картинки и - таблицы :)

*У всех почтовых клиентов свои ограничения, лучше тестировать - так же, как в случае с браузерами.


text:
Q: Translate a line from a whitepaper to English I'm attempting to implement an image processing algorithm from this white paper (p. 5), but I'm having difficulty with the math jargon, in particular this line:
If exist q that containing minimum (f(q) + h(p,q)) and (f(q) + h(p,q) < f(p)):

Can anyone translate this to English? This grammatical construction is new to me.

A: Sounds like a poor translation from another language... your best bet might be to just google raster scan...

A: I realize this post is nearly a year old, but since this page was the only result when I googled "If exist q that containing minimum," and since I was initially stumped, maybe some future reader will stumble across it.
The 2004 paper "Fast Euclidean distance transformation in two scans using a 3x3 neighborhood" by Shih and Wu presents a fast two-pass algorithm for calculating the Euclidean distance transform for every pixel in a foreground object. The distance transform is a standard technique in image processing.
http://en.wikipedia.org/wiki/Distance_transform
The algorithm determines the distance from a foreground pixel to the closest background pixel in a binarized image. The algorithm depends in part on comparisons of values for some pixel (x,y) to the values for the "8-neighbor" pixels surrounding the central pixel: (x-1,y), (x-1,y-1), (x,y-1), ..., (x-1, y+1). The authors label the central pixel p and its neighbors q(n) as follows:
q2   q3   q4
q1   p    q5
q8   q7   q6

The paper is generally readable, but as the original poster meeta pointed out, an apparently critical line in the description of the algorithm doesn't make sense. Here's the text, with [if] and [then] added for clarity:
for q = q1 to q4
   f(p) = min( f(p), f(q) + h(p,q) );
if exist q that containing minimum (f(q) + h(p,q)) and
   [if] (f(q) + h(p,q) < f(p)
   [then] R(p) = R(q) + G(p,q);

The phrase "if exist q" should be translated as something like "if q is a valid pixel" or "if q is a valid element in the 2D array." The technique requires a raster scan of an image from top to bottom, and from left to right in each row. (The second pass reverses the scan order: bottom to top, right to left.) Pixels in the topmost and bottommost rows and pixels in the leftmost and rightmost columns don't have eight valid neighbor pixels.
For example, consider the point (0,0). In traditional image processing, the +X-axis points from left to right, the +Y-axis points from top to bottom. The point (0,0) is located in the upper left corner of the image, and it does not have valid pixel neighbors either above (y < 0) or to the left (x < 0).
It helps to reinterpret the text by Shih and Wu as follows:
for q = q1 to q4
   f(p) = min( f(p), f(q) + h(p,q) );
if q is a valid pixel and if (f(q) + h(p,q)) is a minimum
   [then] R(p) = R(q) + G(p,q);

In pseudocode, this may be expressed as follows:
 for each q of (q1, q2, q3, q4)
    if q is a valid pixel
       x = f(q) + h(p,q)
       if (x < f(p))
          f(p) = x
          R(p) = R(q) + G(p,q)

Based on this interpretation, my implementation of the Chih and Wu algorithm yields the expected results for Distance Transform images.


text:
Q: is it safe to store the calculated RECT from a WM_NCCALCSIZE in a class member RECT variable and use it later in WM_NCPAINT? I need to know if it is safe to store some calculated non-client area RECT (not the window rect neither the client one, it is a based on some calculation) from the WM_NCCALCSIZE message and use it later in the WM_NCPAINT without the need to do the whole recalculation process again in WM_NCPAINT!?
i.e. is WM_NCPAINT always called immediately after WM_NCCALCSIZE?
I need to save the hassle of doing the recalculation process in WM_NCPAINT message, because DefWindowProc from WM_NCCALCSIZE already does all what I need to start my calculations based on what it does.
TIA.

A:
i.e. is WM_NCPAINT always called immediately after WM_NCCALCSIZE?

I test this sample which provided by krsi, we can find that WM_NCCALCSIZE is always called before WM_NCPAINT, but this does not mean that no other messages were called in the middle. For example, when testing, after receiving WM_NCCALCSIZE, WM_PAINT will be called first, and then WM_NCPAINT will be called.
You seem to be customizing the non-client area, I think you can first read Nonclient Area.

In general, processing these messages for standard windows is not
recommended, because the application must be able to draw all the
required parts of the nonclient area for the window. For this reason,
most applications pass these messages to DefWindowProc for default
processing.
An application that creates custom nonclient areas for its windows
must process these messages. When doing so, the application must use a
window device context to carry out drawing in the window. The window
device context enables the application to draw in all portions of the
window, including the nonclient area. An application retrieves a
window device context by using the GetWindowDC or GetDCEx function
and, when drawing is complete, must release the window device context
by using the ReleaseDC function.

If you just consider whether the size of the custom client area will change when WM_NCPAINT is called, I can't give a suitable answer because I haven't seen your code and I don't know what kind of project you need to complete.
I just tested the sample in another link, the non-client area will always maintain the border size of 4pixel, and the calculation is also performed in WM_NCCALCSIZE.


text:
Q: Cannot access to Windows after installing CentOS7 After installing dual boot Windows 10 and CentOS7. I cannot see the option for Windows booting.
I tried suggestion from this link THIS but I found something different.
In my case, I cannot find Windows on it
[xhdinh@localhost ~]$ sudo grub2-mkconfig > /dev/null
[sudo] password for xhdinh:
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-89b13d92e70f4ca09e4c4127a3ec37f5
Found initrd image: /boot/initramfs-0-rescue-89b13d92e70f4ca09e4c4127a3ec37f5.img
done

The lsblk -l
[xhdinh@localhost ~]$ lsblk -f
NAME    FSTYPE LABEL         UUID                                   MOUNTPOINT
sda
├─sda1  vfat   ESP           C0EE-5982
├─sda2
├─sda3  ntfs   OS            842245042244FD24
├─sda4  ntfs   Research      78700D2A700CF0A4
├─sda5  ntfs   Entertainment A48E8BD38E8B9C84
├─sda6  ntfs   WINRETOOLS    0ACC48ABCC48933D
├─sda7  ntfs   Image         6CF24A03F249D24E
├─sda8  ntfs   DELLSUPPORT   F8DACC77DACC3422
├─sda9
├─sda10 ext4                 d6e0e44c-ad34-464c-b4ca-333e3d393e54 /
├─sda11 ext4                 f612727f-5662-496f-82fb-5f8cb216ee1f /home
└─sda12 swap                 bbb04bda-9934-4b06-b72a-8b8832be58a0 [SWAP]
sdb
└─sdb1  ntfs                 36D44A09D449CC35                        /run/media/xhd

When I run [root@localhost ~]# cat /etc/default/grub
GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT="console"

GRUB_CMDLINE_LINUX="rhgb quiet"

GRUB_DISABLE_RECOVERY="true"

A: You need to install the os-prober package and then run grub2-mkconfig again.
This will detect all other bootable operating systems on the disk and create grub boot menu entries for them.


text:
Q: Why can't my MOSFETs fit in my breadboard? This is probably another question with obvious answers, but Googling didn't help.
I bought an N-channel power MOSFET from Adafruit recently. I also bought a breadboard, also from Adafruit. However, the MOSFET doesn't fit directly into the breadboard when it's oriented such that its long side runs parallel to the long side of the breadboard. It does fit when it's perpendicular, but that's not particularly useful to me as that would mean that all of the pins would be electrically connected. Pushing harder on the MOSFET just makes the pins on the MOSFET bend. My best guess is that this caused by the clips on the breadboard not being able to properly clasp at the rectangular pins on the MOSFET. I've been able to work around this by running three M–F jumpers from the breadboard to the MOSFET's pins, but that's admittedly not a pretty solution. Various tutorials all indicate to put MOSFETs directly into the breadboard, so I'm assuming that jumpers aren't intended. Any ideas on how I could fix this? I'd prefer not to break either the MOSFET or the breadboard.


text:
Q: Different latitude and longitude using google maps and ggmap geocode function I am trying to plot the nearest Walmart store in Canada to a certain post code using ggmap. The function used to get the location is:
goodPoint<-geocode("M1L2K1 walmart canada")

This returned the lat and lon:
> goodPoint
       lon      lat
1    -79.30113  43.72304

When I check Google map search using the same search term and get the latitude and longitude I get 43.728933,-79.29565.
The difference between the returned latitude and longitude is about 1.1 km, so quite significant.
Can anyone suggest why there is this difference when in the documentation it states that it uses Google Maps for the location? Any suggestions for ways around this?

A: Have you looked at the actual output from Google geocoder? The geocoder is not the same thing as the maps search. The geocoder resolves addresses, but it afaict does not perform searches such as "find a walmart near M1L2K1 canada".
https://maps.googleapis.com/maps/api/geocode/json?address=M1L2K1%20walmart%20canada&sensor=false
yields the following parsed address:

  "formatted_address" : "Scarborough, Ontario M1L 2K1, Kanada"
  ...
  "location_type" : "APPROXIMATE",
  ...
  "types" : [ "postal_code" ]

So in fact, Google even tells you that this is a "postal code resolution" geocoding.
Again, geocoding does not equal search. "Walmart" is not a postal address, but a reasonable search term.


text:
Q: Parser or postlex causing an error in Lark everyone. So, I'm parsing a shell output (mocked here) and I'm running into an error where I really don't expect. Minimum reproducible, working example is below:
from rich import print as rprint
import typing as tp

from lark import Lark, Transformer, Tree
from lark.indenter import Indenter

class TreeIndenter(Indenter):
    NL_type = '_NL'
    OPEN_PAREN_types: tp.List = []
    CLOSE_PAREN_types: tp.List = []
    INDENT_type = '_INDENT'
    DEDENT_type = '_DEDENT'
    tab_len = 8

    @property
    def always_accept(self):
        return (self.NL_type,)

kwargs = {
    "parser": "lalr",
    "postlex": TreeIndenter(),
    "maybe_placeholders": False,
}

text = """
=======================================================================
SKIT                       SEASON          EPISODE         CAST NUMBER
=======================================================================
skit_name=vikings          3               10              3
skit_name=parrot           2               5               2
skit_name=eel              1               7               2
"""

grammar = r"""
start: [_NL] header data
header: line_break column_names line_break
data: data_line+
data_line: me_info (STRING2 | STRING)* _NL
me_info: "skit_name="STRING

line_break: "="* _NL
column_names: (STRING | STRING2)* _NL

STRING2         : STRING " " STRING
STRING          : ESCAPED_STRING | VALUE
VALUE           : ("_" | LETTER | DIGIT | "-" | "[]" | "/" | "." | ":")+

%import common.ESCAPED_STRING
%import common.LETTER
%import common.DIGIT
%ignore / /

_NL: /(\r?\n[\t ]*)+/
"""

parser = Lark(grammar=grammar)
rprint(parser.parse(text))

This outputs the correct tree. Do note that kwargs isn't being used.
However, as I'd need to combine it with parser for output that is indented, I'd need to use an Indenter and the listed kwargs. When I include them, I get the following error (full trace omitted):
UnexpectedToken: Unexpected token Token('STRING', 'skit_name') at line 5, column 1.
Expected one of:
    * __ANON_0

Meaning that the first line that forms data causes the problem, but it's not obvious what is actually expected.
However, interesting thing, if the first line break is omitted (both from the text and grammar) it successfully parses.
Additionally, it seems that the error occurs when either parser or postlex are included, and it's the same error, no matter which of them is included in kwargs.
EDIT:
So I was hoping I can come up with a workaround for the indent and not use parser or postlex keywords, but it seems that specifying lalr parser is required to use the Transformer, so I will need to use that anyways so I can't just side-step the problem.

A: Providing a PostLexer changes the default parser/lexer combo from earley/dynamic to earley/basic, since the dynamic parser can't handle the postlexer. However, the basic lexer is far less powerful and can't handle this kind of ambiguity.It sees that at that point a STRING would fit and then just uses that.
There are a few possible solutions:

*

*Explicitly use the parser/lexer combo lalr/contextual. This might require changes in the grammar, since lalr can't handle ambiguity like early can.

*

*One thing that you can fix is to use "skit_name" "=". This will make the lexers correctly differentiate between "skit_name" and "NAME", as long as you have the contextual lexer. Yes, technically it means something else since you currently can't have whitespace there. If you really need that, you can use /\B=/ instead of /=/

*Somehow avoid the need for a postlexer and continue to use earley. (You can always just apply the Transformer after the fact instead of inline)


text:
Q: Is every suborder of $\mathbb{R}$ homeomorphic to some subspace of $\mathbb{R}$?
Let $X \subset \mathbb{R}$ and give $X$ its order topology. (When) is it true that $X$ is homeomorphic to some subspace of $Y \subset \mathbb{R}$?

Example: Let $X = [0,1) \cup \{2\} \cup (3,4]$, then $X$ is order isomorphic to $Y=[0,2]$ in a fairly obvious way, hence the order topologies on $X$ and $Y$ are homeomorphic. But, the order topology on $Y$ agrees with the subspace topology on $Y$, so this particular $X$ is indeed homeomorphic to a subspace of $\mathbb{R}$.
Example: Let $X$ equal the set of endpoints of the Cantor set. The order on $X$ is a bit strange (it's order isomorphic to $\mathbb{Q} \times \{0,1\}$ in the dictionary order with a largest and smallest element adjoined), so one might expect the order topology on $X$ to be strange, but... $X$ is clearly 2nd countable under the order topology (there are countably many points, hence countably many intervals) and any order topology is regular, so $X$ is metrizeable by Urysohn. It is also easy to see the order topology on $X$ has no isolated points so, by a theorem of Sierpinski (any countable metric space without isolated points is homeomorphic to $\mathbb{Q}$), the order topology on $X$ is homeomorphic to the subspace $Y = \mathbb{Q}$ of $\mathbb{R}$.
For any countable $X$, the argument above shows the order topology on $X$ is metrizeable. In fact, I think the order topology on any $X \subset \mathbb{R}$ is metrizeable by this theorem of Lusin (an order topology $X$ is metrizeable if and only if the diagonal in $X \times X$ is a $G_\delta$ set). But this doesn't preclude the possiblity of $X$ weird enough to not be homeomorphic to any subspace of $\mathbb{R}$. I'm not sure how one would arrange this though. If it can be arranged with $X$ countable there would need to be many isolated points to avoid Sierpinski's result for instance...
Advertisement: Brian's positive answer below actually proves something even better. Namely:
Theorem: Let $X \subset \mathbb{R}$. Then there is an order isomorphism (hence homeomorphism of order topologies) $\varphi$ from $X$ to a new set $Y \subset \mathbb{R}$ whose order topology and subspace topology coincide.
Roughly, approach is to take countable set $D \subset X$ such that each point in $X \setminus D$ is a 2-sided limit (topologically) of points in $D$. Using countability of $D$, one can find an order embedding $\varphi$ of $D$ into $\mathbb{Q}$ such that $\varphi(D)$ has no "topological gaps" that are not also "order gaps" (this is the property which makes the subspace and order topologies coincide). The final step is to extend $\varphi$ to the rest of $X$ and check nothing goes awry in doing so.

A: This is a completely different argument from the previous one (and with a little luck a correct one this time), but the conclusion is the same: the answer is yes, always.
Suppose that $X\subseteq\mathbb{R}$. Let $\tau_o$ and $\tau_s$ respectively be the order and subspace topologies on $X$; certainly $\tau_o\subseteq\tau_s$. In the sequel all intervals will be taken in $X$ unless subscripted with $\mathbb{R}$, so that for example $$[x,\to)=\{y\in X:x\le y\},$$ and $$[x,\to)_\mathbb{R}=\{y\in\mathbb{R}:x\le y\}\;.$$
Let $N$ be the set of points of $X$ that have either an immediate predecessor or an immediate successor in $X$; clearly $N$ is countable.
Let $L=\{x\in X:[x,\to)\in\tau_s\setminus\tau_o\}$ and $R=\{x\in X:(\leftarrow,x]\in\tau_s\setminus\tau_o\}$; I'll call points of $L$ left pseudogaps and points of $R$ right pseudogaps of $X$. It's not hard to see that for any $x\in X$:

*

*$x\in L$ iff there is $\epsilon>0$ such that $(x-\epsilon,x)_\mathbb{R}\cap X=\varnothing\ne(\leftarrow,x)$, and $x$ has no immediate predecessor in $X$; and

*$x\in R$ iff there is $\epsilon>0$ such that $(x,x+\epsilon)_\mathbb{R}\cap X=\varnothing\ne(x,\to)$, and $x$ has no immediate successor in $X$.

It follows immediately that $L\cup R$ is countable. Moreover, it's well-known that $\tau_s$ has a base of intervals, not necessarily open, in $X$, so $L\cup R$ is precisely the set of points at which $\tau_s$ and $\tau_o$ disagree.
Let $D_0$ be a countable $\tau_s$-dense subset of $X\setminus(L\cup R\cup N)$, and let $D=D_0\cup L\cup R\cup N$; we may assume that $D$ contains any endpoints of $X$. Enumerate $D=\{x_n:n\in\omega\}$ and $\mathbb{Q}=$  $\{q_n:n\in\omega\}$. Recursively define $\varphi:D\to\mathbb{Q}$ as follows: if $\varphi(x_k)$ has been defined for $k<n$, let $$m=\min\bigg\{i\in\omega:\forall k<n\big[q_i<\varphi(x_k)\leftrightarrow x_n<x_k\big]\bigg\}\;,\tag{1}$$ and set $\varphi(x_n)=q_m$. Clearly $\varphi$ is order-preserving.
Suppose that $x\in L$. Then $x=\sup_X(\leftarrow,x)\cap D$, and the construction guarantees that $\varphi(x)=$  $\sup_\mathbb{R}\varphi[(\leftarrow,x)\cap D]$. Similarly, $\varphi(x)=\inf_\mathbb{R}\varphi[(x,\to)]$ for each $x\in R$.
Now extend $\varphi$ to $X$ by setting $\varphi(x)=\sup_\mathbb{R}\{\varphi(y):y\in(\leftarrow,x)\cap D\}$ for $x\in X\setminus D\;$; clearly $\varphi$ is strictly order-preserving. Moreover, the construction ensures that if $x=\sup_X(\leftarrow,x)$, then $\varphi(x)=\sup_\mathbb{R}\varphi[(\leftarrow,x)]$, and if $x=\inf_X(x,\to)$, then $\varphi(x)=\inf_\mathbb{R}\varphi[(x,\to)]$. (This is a consequence of setting $\varphi(x_n)$ to $q_m$ with $m$ given by $(1)$.)
Let $Y=\varphi[X]$; clearly $Y$ with the order topology is homeomorphic to $\langle X,\tau_o\rangle$. Suppose that $y=\varphi(x)$ is a left pseudogap of $Y$. Then $\varphi(x)\ne\sup_\mathbb{R}\varphi[(\leftarrow,x)]$, so $x\ne\sup_X(\leftarrow,x)$. This is possible only if $x$ has an immediate predecessor $x^-$ in $X$, and in that case $(\varphi(x^-),y)=\varnothing$, and $y$ is not a left pseudogap of $Y$ after all. Similarly, $Y$ has no right pseudogaps, and therefore the subspace and order topologies on $Y$ coincide with each other, and $\langle X,\tau_o\rangle$ is homeomorphic to $Y$.

A: According to this paper, any second countable ordered space is (order) homeomorphic to a subspace of $\mathbb{R}$. Moreover, any separable one is homeomorphic to a subspace of the Sorgenfrey line. The proofs seem similar to Brian's.