问:
Docker swarm mode running Hazelcast cluster
I'm running Hazelcast cluster using docker swarm. Even though nodes establish connection

```<code>Members [1] {
        Member [10.0.0.3]:5701 - b5fae3e3-0727-4bfd-8eb1-82706256ba2d this
}

May 27, 2017 2:38:12 PM com.hazelcast.internal.management.ManagementCenterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Hazelcast will connect to Hazelcast Management Center on address:
http://10.0.0.3:8080/mancenter
May 27, 2017 2:38:12 PM com.hazelcast.internal.management.ManagementCenterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Failed to pull tasks from management center
May 27, 2017 2:38:12 PM com.hazelcast.internal.management.ManagementCenterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Failed to connect to:http://10.0.0.3:8080/mancenter/collector.do
May 27, 2017 2:38:12 PM com.hazelcast.core.LifecycleService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] [10.0.0.3]:5701 is STARTED
May 27, 2017 2:38:12 PM com.hazelcast.internal.partition.impl.PartitionStateManager
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Initializing cluster partition table arrangement...
May 27, 2017 2:38:19 PM com.hazelcast.internal.cluster.ClusterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8]

Members [2] {
        Member [10.0.0.3]:5701 - b5fae3e3-0727-4bfd-8eb1-82706256ba2d this
        Member [10.0.0.4]:5701 - b3bd51d4-9366-45f0-bb66-78e67b13268c
}

May 27, 2017 2:38:19 PM com.hazelcast.internal.partition.impl.MigrationManager
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Re-partitioning cluster data... Migration queue size: 271
May 27, 2017 2:38:21 PM com.hazelcast.internal.partition.InternalPartitionService
</code>```

after while I keep getting errors:

```<code>WARNING: [10.0.0.3]:5701 [kpts-cluster] [3.8] Wrong bind request from [10.0.0.3]:5701! This node is not requested endpoint: [10.0.0.2]:5701
May 27, 2017 2:45:06 PM com.hazelcast.nio.tcp.TcpIpConnection
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Connection[id=18, /10.0.0.3:5701->/10.0.0.3:49575, endpoint=null, alive=false, type=MEMBER] closed. Reason: Wrong bind request from [10.0.0.3]:5701! This node is not requested endpoint: [10.0.0.2]:5701
May 27, 2017 2:45:06 PM com.hazelcast.nio.tcp.TcpIpConnection
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Connection[id=17, /10.0.0.2:49575->/10.0.0.2:5701, endpoint=[10.0.0.2]:5701, alive=false, type=MEMBER] closed. Reason: Connection closed by the other side
</code>```

I suppose this has to do something with the interface eth0 on every node. There are 2 addresses assigned - one "real" and one "fake" of the cluster manager... for some reason it is advertised as an endpoint...

```<code>1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
82: eth0@if83: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default
    link/ether 02:42:0a:00:00:03 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.3/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.0.2/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:aff:fe00:3/64 scope link
       valid_lft forever preferred_lft forever
84: eth1@if85: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:12:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.3/16 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe12:3/64 scope link
       valid_lft forever preferred_lft forever
86: eth2@if87: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default
    link/ether 02:42:0a:ff:00:07 brd ff:ff:ff:ff:ff:ff
    inet 10.255.0.7/16 scope global eth2
       valid_lft forever preferred_lft forever
    inet 10.255.0.6/32 scope global eth2
       valid_lft forever preferred_lft forever
    inet6 fe80::42:aff:feff:7/64 scope link
       valid_lft forever preferred_lft forever
</code>```

Here is the network config read from one of the nodes:

```<code>[
    {
        "Name": "hazelcast-net",
        "Id": "ly1p50ykwjhf68k88220gxih6",
        "Created": "2017-05-27T16:38:04.638580169+02:00",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Containers": {
            "0fa2bd8f8e8e931e1140e2d4bee1b43ff1f7bd5e3049d95e9176c63fa9f47e4f": {
                "Name": "kpts.1zhprrumdjvenkl4cvsc7bt40.2ugiv46ubar8utnxc5hko1hdf",
                "EndpointID": "0c5681aebbacd27672c300742077a460c07a081d113c2238f4c707def735ebec",
                "MacAddress": "02:42:0a:00:00:03",
                "IPv4Address": "10.0.0.3/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "c4-6f6cd87e898f",
                "IP": "10.6.225.34"
            },
            {
                "Name": "c5-77d9f542efe8",
                "IP": "10.6.225.35"
            }
        ]
    }
]
</code>```

答:
You may find this previous issue useful:

Docker networking - "This node is not requested endpoint" error #4537

Now more to the point. You have a sound connection working which is why the nodes are able to join; however, you are most likely (guestimate since I don't have your hazelcast.xml) binding to all the interfaces and thus you want to change your network binding to only bind to the address desired. We bind to * by default since we don't know which network you want to use.

Hope this helps,

Body:
I'm running Hazelcast cluster using docker swarm. Even though nodes establish connection

Members [1] {
        Member [10.0.0.3]:5701 - b5fae3e3-0727-4bfd-8eb1-82706256ba2d this
}

May 27, 2017 2:38:12 PM com.hazelcast.internal.management.ManagementCenterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Hazelcast will connect to Hazelcast Management Center on address:
http://10.0.0.3:8080/mancenter
May 27, 2017 2:38:12 PM com.hazelcast.internal.management.ManagementCenterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Failed to pull tasks from management center
May 27, 2017 2:38:12 PM com.hazelcast.internal.management.ManagementCenterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Failed to connect to:http://10.0.0.3:8080/mancenter/collector.do
May 27, 2017 2:38:12 PM com.hazelcast.core.LifecycleService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] [10.0.0.3]:5701 is STARTED
May 27, 2017 2:38:12 PM com.hazelcast.internal.partition.impl.PartitionStateManager
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Initializing cluster partition table arrangement...
May 27, 2017 2:38:19 PM com.hazelcast.internal.cluster.ClusterService
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8]

Members [2] {
        Member [10.0.0.3]:5701 - b5fae3e3-0727-4bfd-8eb1-82706256ba2d this
        Member [10.0.0.4]:5701 - b3bd51d4-9366-45f0-bb66-78e67b13268c
}

May 27, 2017 2:38:19 PM com.hazelcast.internal.partition.impl.MigrationManager
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Re-partitioning cluster data... Migration queue size: 271
May 27, 2017 2:38:21 PM com.hazelcast.internal.partition.InternalPartitionService

after while I keep getting errors:

WARNING: [10.0.0.3]:5701 [kpts-cluster] [3.8] Wrong bind request from [10.0.0.3]:5701! This node is not requested endpoint: [10.0.0.2]:5701
May 27, 2017 2:45:06 PM com.hazelcast.nio.tcp.TcpIpConnection
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Connection[id=18, /10.0.0.3:5701->/10.0.0.3:49575, endpoint=null, alive=false, type=MEMBER] closed. Reason: Wrong bind request from [10.0.0.3]:5701! This node is not requested endpoint: [10.0.0.2]:5701
May 27, 2017 2:45:06 PM com.hazelcast.nio.tcp.TcpIpConnection
INFO: [10.0.0.3]:5701 [kpts-cluster] [3.8] Connection[id=17, /10.0.0.2:49575->/10.0.0.2:5701, endpoint=[10.0.0.2]:5701, alive=false, type=MEMBER] closed. Reason: Connection closed by the other side

I suppose this has to do something with the interface eth0 on every node. There are 2 addresses assigned - one "real" and one "fake" of the cluster manager... for some reason it is advertised as an endpoint...

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
82: eth0@if83: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default
    link/ether 02:42:0a:00:00:03 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.3/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.0.2/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:aff:fe00:3/64 scope link
       valid_lft forever preferred_lft forever
84: eth1@if85: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:12:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.3/16 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe12:3/64 scope link
       valid_lft forever preferred_lft forever
86: eth2@if87: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default
    link/ether 02:42:0a:ff:00:07 brd ff:ff:ff:ff:ff:ff
    inet 10.255.0.7/16 scope global eth2
       valid_lft forever preferred_lft forever
    inet 10.255.0.6/32 scope global eth2
       valid_lft forever preferred_lft forever
    inet6 fe80::42:aff:feff:7/64 scope link
       valid_lft forever preferred_lft forever

Here is the network config read from one of the nodes:

[
    {
        "Name": "hazelcast-net",
        "Id": "ly1p50ykwjhf68k88220gxih6",
        "Created": "2017-05-27T16:38:04.638580169+02:00",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Containers": {
            "0fa2bd8f8e8e931e1140e2d4bee1b43ff1f7bd5e3049d95e9176c63fa9f47e4f": {
                "Name": "kpts.1zhprrumdjvenkl4cvsc7bt40.2ugiv46ubar8utnxc5hko1hdf",
                "EndpointID": "0c5681aebbacd27672c300742077a460c07a081d113c2238f4c707def735ebec",
                "MacAddress": "02:42:0a:00:00:03",
                "IPv4Address": "10.0.0.3/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "c4-6f6cd87e898f",
                "IP": "10.6.225.34"
            },
            {
                "Name": "c5-77d9f542efe8",
                "IP": "10.6.225.35"
            }
        ]
    }
]


来源: stackexchange

问:
What dependency/repository for maven-jaxb-plugin?
in my pom.xml I've configured maven-jaxb-plugin but I'm getting a "A required plugin was not found: Plugin could not be found - check that the goal name is correct: Unable to download the artifact from any repository" because of it. My config is like this:

```<code><plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <generate-package>tld.mycompany.myproject.data.ws-schema</generate-package>
        <schemaDirectory>src/main/resources/ws/xsd</schemaDirectory>
    </configuration>
</plugin>
</code>```

In dependencies, I have added the following.

```<code><dependency>
    <groupId>maven-plugins</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.7.5</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-xjc</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2</version>
</dependency>
</code>```

What am I missing? Why can't it find the correct artifacts?

Cheers

Nik

答:
I suggest you use, when facing such a problem, one of the available maven search engines :

mvnbrowser

jarvana

mvnrepository

the two first having my preference. Here is what they say about your artifacts :

maven-jaxb-plugin is available at Apache

maven-jaxb2-plugin 0.7.5 is not known. The most up-to-date version, is 0.7.3 on mvnbrowser and 0.7.4 on jarvana. which may be the reason why your maven build is broken

jaxb-api 2.2 is available at both JavaNet and JBoss repositories

Well, wion't do all the job for you, as I guess you get the picture now.

ContentLicense: CC BY-SA 2.5

Body:
in my pom.xml I've configured maven-jaxb-plugin but I'm getting a "A required plugin was not found: Plugin could not be found - check that the goal name is correct: Unable to download the artifact from any repository" because of it. My config is like this:

<plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <generate-package>tld.mycompany.myproject.data.ws-schema</generate-package>
        <schemaDirectory>src/main/resources/ws/xsd</schemaDirectory>
    </configuration>
</plugin>

In dependencies, I have added the following.

<dependency>
    <groupId>maven-plugins</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.7.5</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-xjc</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2</version>
</dependency>

What am I missing? Why can't it find the correct artifacts?

Cheers

Nik


问:
How to remove duplicate values from dict?
I'm trying to remove duplicate values in my dict but its not working:

```<code>samples_antibiotics_with_duplicates = {'S00541-09': ['Streptomycin', 'Sulfamethoxazole', 'Trimethoprim', 'Spectinomycin', 'Streptomycin', 'Streptomycin', 'Trimethoprim']}
samples_antibiotics = {}
    for key,value in samples_antibiotics_with_duplicates.iteritems():
      if value not in samples_antibiotics.values():
        samples_antibiotics[key] = value
print samples_antibiotics
</code>```

This prints:

```<code>{'S00541-09': ['Streptomycin', 'Sulfamethoxazole', 'Trimethoprim', 'Spectinomycin', 'Streptomycin', 'Streptomycin', 'Trimethoprim']}
</code>```

答:
If you don't care about retaining original order then set(my_list) will remove all duplicates.

If you want to retain original order then list(OrderedDict.fromkeys(my_list))

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to remove duplicate values in my dict but its not working:

samples_antibiotics_with_duplicates = {'S00541-09': ['Streptomycin', 'Sulfamethoxazole', 'Trimethoprim', 'Spectinomycin', 'Streptomycin', 'Streptomycin', 'Trimethoprim']}
samples_antibiotics = {}
    for key,value in samples_antibiotics_with_duplicates.iteritems():
      if value not in samples_antibiotics.values():
        samples_antibiotics[key] = value
print samples_antibiotics

This prints:

{'S00541-09': ['Streptomycin', 'Sulfamethoxazole', 'Trimethoprim', 'Spectinomycin', 'Streptomycin', 'Streptomycin', 'Trimethoprim']}

ContentLicense: CC BY-SA 3.0


问:
Cannot see trace details in zipkin
we are using elasticsearch as the storage of zipkin, the dependency are as follows:

```<code><dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
    </dependency>

    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-ui</artifactId>
        <version>1.26.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-server</artifactId>
        <version>1.26.0</version>
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-autoconfigure-storage-elasticsearch</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-autoconfigure-ui</artifactId>
        <version>1.26.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-jmx</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
    </dependency>
</dependencies>
</code>```

now, trace log was storaged in elasticsearch, and we can see trance spans in the zipkin ui,but cannot to see span details or find trace via traceid,with the exception of :

```<code>java.lang.AbstractMethodError: zipkin.storage.guava.InternalGuavaToAsyncSpanStoreAdapter.getTrace(JJLzipkin/storage/Callback;)V
    at zipkin.storage.InternalAsyncToBlockingSpanStoreAdapter.getTrace(InternalAsyncToBlockingSpanStoreAdapter.java:41) ~[zipkin-1.19.2.jar:na]
    at zipkin.server.ZipkinQueryApiV1.getTrace(ZipkinQueryApiV1.java:118) ~[zipkin-server-1.26.0.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:108) ~[spring-boot-actuator-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.cloud.sleuth.instrument.web.TraceFilter.doFilter(TraceFilter.java:145) ~[spring-cloud-sleuth-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106) ~[spring-boot-actuator-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
</code>```

答: You are blending Zipkin autoconfigure version 1.2 with Zipkin 1.26. This results in a version missmatch.</p>

Title: Cannot see trace details in zipkin

Body:
we are using elasticsearch as the storage of zipkin, the dependency are as follows:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
    </dependency>

    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-ui</artifactId>
        <version>1.26.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-server</artifactId>
        <version>1.26.0</version>
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-autoconfigure-storage-elasticsearch</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-autoconfigure-ui</artifactId>
        <version>1.26.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-jmx</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
    </dependency>
</dependencies>

now, trace log was storaged in elasticsearch, and we can see trance spans in the zipkin ui,but cannot to see span details or find trace via traceid,with the exception of :

java.lang.AbstractMethodError: zipkin.storage.guava.InternalGuavaToAsyncSpanStoreAdapter.getTrace(JJLzipkin/storage/Callback;)V
    at zipkin.storage.InternalAsyncToBlockingSpanStoreAdapter.getTrace(InternalAsyncToBlockingSpanStoreAdapter.java:41) ~[zipkin-1.19.2.jar:na]
    at zipkin.server.ZipkinQueryApiV1.getTrace(ZipkinQueryApiV1.java:118) ~[zipkin-server-1.26.0.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:108) ~[spring-boot-actuator-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.cloud.sleuth.instrument.web.TraceFilter.doFilter(TraceFilter.java:145) ~[spring-cloud-sleuth-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106) ~[spring-boot-actuator-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]


问:
How to use : colon char in Bottle route
I have simple Bottle route, and URL should contain : (colon) sign. URL should be like /REST/item:128 or /REST/item:89753

My route is

```<code>@route('/REST/item:<id:int>')
def icc(id):
    return { 'id': id }
</code>```

Route is not working properly. id contain only last char from url id, not full id.

How to use : (colon) in route?

答:
Wow, this was confusing.

I haven't had time to fully understand what's happening, but I suspect that one of Bottle's route regexes is eating too many characters when there's a colon in the route.

In any case, escaping the colon with a backslash appears to solve the problem:

```<code>@route(r'/REST/item\:<id_:int>')  # note the "r" prefix there
def icc(id_):
    return {'id': id_}
</code>```

Here's a test request and its response:

```<code>=> curl -v 'http://127.0.0.1:8080/REST/item:123'
{"id": 123}
</code>```

EDIT: Mystery solved.

Bottle currently supports two syntaxes for url wildcards: The
  one (since 0.10) and the :old syntax. Both are described here:
  http://bottlepy.org/docs/dev/routing.html

In your example, the : triggered the old syntax. The solution is to
  escape the colon with a backslash (as described in the SO answer).
  Escaping is fully implemented and works as intended, but is
  undocumented. This is why I leave this issue open. Pull requests for
  better documentation would be welcomed.

Title: How to use : colon char in Bottle route

Body:
I have simple Bottle route, and URL should contain : (colon) sign. URL should be like /REST/item:128 or /REST/item:89753

My route is

@route('/REST/item:<id:int>')
def icc(id):
    return { 'id': id }

Route is not working properly. id contain only last char from url id, not full id.

How to use : (colon) in route?

Body:
Wow, this was confusing.

I haven't had time to fully understand what's happening, but I suspect that one of Bottle's route regexes is eating too many characters when there's a colon in the route.

In any case, escaping the colon with a backslash appears to solve the problem:

@route(r'/REST/item\:<id_:int>')  # note the "r" prefix there
def icc(id_):
    return {'id': id_}

Here's a test request and its response:

=> curl -v 'http://127.0.0.1:8080/REST/item:123'
{"id": 123}

EDIT: Mystery solved.

Bottle currently supports two syntaxes for url wildcards: The
  one (since 0.10) and the :old syntax. Both are described here:
  http://bottlepy.org/docs/dev/routing.html

In your example, the : triggered the old syntax. The solution is to
  escape the colon with a backslash (as described in the SO answer).
  Escaping is fully implemented and works as intended, but is
  undocumented. This is why I leave this issue open. Pull requests for
  better documentation would be welcomed.


问:
Sending GIF image in asset folder to another application using Intent
How do we send GIF image which is present in asset folder to another application using Intent?

I have tried this:

```<code>private File getEmojiFile(int position) {
    AssetManager assetManager = getApplicationContext().getAssets();
    File file = new File(getCacheDir(), mEmojiFileNames[position]);
    try {
        if (!file.createNewFile()) {
            //Emoji File already exists.
            return file;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    FileChannel in_chan = null, out_chan = null;
    try {
        AssetFileDescriptor in_afd = assetManager.openFd(mEmojiFileNames[position]);
        FileInputStream in_stream = in_afd.createInputStream();
        in_chan = in_stream.getChannel();

        FileOutputStream out_stream = new FileOutputStream(file);
        out_chan = out_stream.getChannel();
        in_chan.transferTo(in_afd.getStartOffset(), in_afd.getLength(), out_chan);
    } catch (IOException ioe) {
        Log.w("copyFileFromAssets", "Failed to copy file '" + mEmojiFileNames[position] + "' to external storage:" + ioe.toString());
    } finally {
        try {
            if (in_chan != null) {
                in_chan.close();
            }
            if (out_chan != null) {
                out_chan.close();
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
    return file;
}
</code>```

and then sending it to another app using Intent:

```<code>            final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            EMOJI_IMAGE_TYPE emojiImageType = getImageType(position);
            intent.setType("image/gif"));
            intent.setPackage(getCurrentAppPackage(SoftKeyboard.this, getCurrentInputEditorInfo()));

            PackageManager packageManager = getPackageManager();
            if (intent.resolveActivity(packageManager) != null) {

                //Save emoji file because current input field supports GIF/PNG.
                File emojiFile = getEmojiFile(position);
                Uri photoURI = FileProvider.getUriForFile(SoftKeyboard.this, SoftKeyboard.this.getApplicationContext().getPackageName() + ".provider", emojiFile);
                intent.putExtra(Intent.EXTRA_STREAM, photoURI);

                dialog.dismiss();
                hideWindow();
                try {
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(SoftKeyboard.this,"This text field does not support "+
                       "GIF"+" insertion from the keyboard.",Toast.LENGTH_LONG).show();
            }
</code>```

However, after this blank image is coming. Here is tried to send the image to messenger application. It accepted intent but showed blank transparent image:

答:
Scenario: You have a gif file in  the Drawable Folder.
Then the code will be:`</p>

```<code>private void shareDrawable(Context context,int resourceId,String fileName) {
    try {
        //create an temp file in app cache folder
        File outputFile = new File(context.getCacheDir(), fileName + ".gif");
        FileOutputStream outPutStream = new FileOutputStream(outputFile);

        //Saving the resource GIF into the outputFile:
        InputStream is = getResources().openRawResource(resourceId);
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int current = 0;
        while ((current = bis.read()) != -1) {
            baos.write(current);
        }
        FileOutputStream fos = new FileOutputStream(outputFile);
        fos.write(baos.toByteArray());

        //
        outPutStream.flush();
        outPutStream.close();
        outputFile.setReadable(true, false);

        //share file
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile));
        shareIntent.setType("image/gif");
        context.startActivity(shareIntent);
    }
    catch (Exception e) { Toast.makeText(context, "error", Toast.LENGTH_LONG);}
}
</code>```

Body:
How do we send GIF image which is present in asset folder to another application using Intent?

I have tried this:

private File getEmojiFile(int position) {
    AssetManager assetManager = getApplicationContext().getAssets();
    File file = new File(getCacheDir(), mEmojiFileNames[position]);
    try {
        if (!file.createNewFile()) {
            //Emoji File already exists.
            return file;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    FileChannel in_chan = null, out_chan = null;
    try {
        AssetFileDescriptor in_afd = assetManager.openFd(mEmojiFileNames[position]);
        FileInputStream in_stream = in_afd.createInputStream();
        in_chan = in_stream.getChannel();

        FileOutputStream out_stream = new FileOutputStream(file);
        out_chan = out_stream.getChannel();
        in_chan.transferTo(in_afd.getStartOffset(), in_afd.getLength(), out_chan);
    } catch (IOException ioe) {
        Log.w("copyFileFromAssets", "Failed to copy file '" + mEmojiFileNames[position] + "' to external storage:" + ioe.toString());
    } finally {
        try {
            if (in_chan != null) {
                in_chan.close();
            }
            if (out_chan != null) {
                out_chan.close();
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
    return file;
}

and then sending it to another app using Intent:

            final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            EMOJI_IMAGE_TYPE emojiImageType = getImageType(position);
            intent.setType("image/gif"));
            intent.setPackage(getCurrentAppPackage(SoftKeyboard.this, getCurrentInputEditorInfo()));

            PackageManager packageManager = getPackageManager();
            if (intent.resolveActivity(packageManager) != null) {

                //Save emoji file because current input field supports GIF/PNG.
                File emojiFile = getEmojiFile(position);
                Uri photoURI = FileProvider.getUriForFile(SoftKeyboard.this, SoftKeyboard.this.getApplicationContext().getPackageName() + ".provider", emojiFile);
                intent.putExtra(Intent.EXTRA_STREAM, photoURI);

                dialog.dismiss();
                hideWindow();
                try {
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(SoftKeyboard.this,"This text field does not support "+
                       "GIF"+" insertion from the keyboard.",Toast.LENGTH_LONG).show();
            }

However, after this blank image is coming. Here is tried to send the image to messenger application. It accepted intent but showed blank transparent image:

Body:
Scenario: You have a gif file in  the Drawable Folder.
Then the code will be:`

private void shareDrawable(Context context,int resourceId,String fileName) {
    try {
        //create an temp file in app cache folder
        File outputFile = new File(context.getCacheDir(), fileName + ".gif");
        FileOutputStream outPutStream = new FileOutputStream(outputFile);

        //Saving the resource GIF into the outputFile:
        InputStream is = getResources().openRawResource(resourceId);
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int current = 0;
        while ((current = bis.read()) != -1) {
            baos.write(current);
        }
        FileOutputStream fos = new FileOutputStream(outputFile);
        fos.write(baos.toByteArray());

        //
        outPutStream.flush();
        outPutStream.close();
        outputFile.setReadable(true, false);

        //share file
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile));
        shareIntent.setType("image/gif");
        context.startActivity(shareIntent);
    }
    catch (Exception e) { Toast.makeText(context, "error", Toast.LENGTH_LONG);}
}


问:
How do I execute a Java/Python program multiple times?
I am currently working on an assignment, where the task is to measure the execution time for a number of programs in both Python and Java, for the purpose of measuring and comparing performance for the two computer languages. I have 10 tests in total, in sets of 2; for every set, one test is written in Java and the corresponding one is written in Python, and so forth. I want to run every test multiple times, e.g. 100 times, and measure the time for every run. Then I'd like to compute the sum of the obtained execution time(s). How would I do this in Python/Java? I have tried writing a double for-loop like this:

```<code>for i in range(1, 100):
for j in range(1, 10000000):
# do integer division
</code>```

...but it doesn't seem to work. Also I'd like to do the same thing in Java. How would I do this?

答:
The first item you may want to add is the time command, which returns the current time in seconds.  Thus, you can measure a time span like this:

```<code>import time

for i in range(1, 100):
    start = time.time()
    for j in range(1, 10000000):
        # do integer division
    finish = time.time()
    span = finish - start
    # span is the time in seconds.
</code>```

Body:
I am currently working on an assignment, where the task is to measure the execution time for a number of programs in both Python and Java, for the purpose of measuring and comparing performance for the two computer languages. I have 10 tests in total, in sets of 2; for every set, one test is written in Java and the corresponding one is written in Python, and so forth. I want to run every test multiple times, e.g. 100 times, and measure the time for every run. Then I'd like to compute the sum of the obtained execution time(s). How would I do this in Python/Java? I have tried writing a double for-loop like this:

for i in range(1, 100):
for j in range(1, 10000000):
# do integer division

...but it doesn't seem to work. Also I'd like to do the same thing in Java. How would I do this?

Body:
The first item you may want to add is the time command, which returns the current time in seconds.  Thus, you can measure a time span like this:

import time

for i in range(1, 100):
    start = time.time()
    for j in range(1, 10000000):
        # do integer division
    finish = time.time()
    span = finish - start
    # span is the time in seconds.


问:
How can I collect the user's correct choice in my Trivia game?
I have tried multiple things to collect the right answer when the radio button is pressed, but after the game is done I still get a 0 out of 5.
I'm not sure what else to do and have been stuck on this for a while.  Any help will be greatly appreciated!

$(document).ready(function() {

  $("#clickStart").click(function() {
    $('#questions').show(600);
    $('#clock').show(700);
    $('#hide').hide(500);

  });

  (function() {
    var questions = [{
        question: "The great Victoria Desert is located in?",
        choices: ['Canada', 'West Africa', 'Australia', 'North America'],
        correctAnswer: 'Australia'
      },
      {
        question: "The intersecting lines drawn on maps and globes are?",
        choices: ['lattitudes', 'longitudes', 'geographic grids', 'none of the above'],
        correctAnswer: 'geographic gird'
      },
      {
        question: "The landmass of which of the following continents is the least?",
        choices: ['Africa', 'Asia', 'Australia', 'Europe'],
        correctAnswer: 'Australia'
      },
      {
        question: "Without ____ the equator would be much hotter than it is while the poles would be much cooler",
        choices: ['Lattitude of redistribution of heat', 'Cycle of air circulation', 'Global wind pattern', 'All are similiar'],
        correctAnswer: 'All are simliar'
      },
      {
        question: "The habitats valuable for commercially harvested species are called?",
        choices: ['Coral reefs', 'Sea grass bed', 'hot spots', 'None of the above'],
        correctAnswer: 'Sea grass bed'
      }
    ];

    var questionCounter = 0; //Tracks question number
    var selections = []; //Array containing user choices
    var quiz = $("#quiz"); //Quiz div object

    // Display initial question
    displayNext();

    //  'next' button
    $("#next").on("click", function(e) {
      e.preventDefault();

      // Suspend click listener during fade animation
      if (quiz.is(":animated")) {
        return false;
      }
      choose();

      // If no user selection, progress is stopped
      if (isNaN(selections[questionCounter])) {
        alert("Please make a selection!");
      } else {
        questionCounter++;
        displayNext();
      }
    });

    // 'prev' button
    $("#prev").on("click", function(e) {
      e.preventDefault();

      if (quiz.is(":animated")) {
        return false;
      }
      choose();
      questionCounter--;
      displayNext();
    });

    // 'Start Over' button
    $("#start").on("click", function(e) {
      e.preventDefault();

      if (quiz.is(":animated")) {
        return false;
      }
      questionCounter = 0;
      selections = [];
      displayNext();
      $("#start").hide();
    });

    // Animates buttons on hover
    $(".button").on("mouseenter", function() {
      $(this).addClass("active");
    });
    $(".button").on("mouseleave", function() {
      $(this).removeClass("active");
    });

    // Creates and returns the div that contains the questions and
    // the answer selections
    function createQuestionElement(index) {
      var qElement = $("
", {
        id: "question"
      });

      var header = $("
Question " + (index + 1) + ":
");
      qElement.append(header);

      var question = $("
").append(questions[index].question);
      qElement.append(question);

      var radioButtons = createRadios(index);
      qElement.append(radioButtons);

      return qElement;
    }

    // Creates a list of the answer choices as radio inputs
    function createRadios(index) {
      var radioList = $("
");
      var item;
      var input = "";
      for (var i = 0; i < questions[index].choices.length; i++) {
        item = $("
");
        input = '<input type="radio" name="answer" value=' + i + " />";
        input += questions[index].choices[i];
        item.append(input);
        radioList.append(item);
      }
      return radioList;
    }

    // Reads the user selection and pushes the value to an array
    function choose() {
      selections[questionCounter] = +$('input[name="answer"]:checked').val();
    }

    // Displays next requested element
    function displayNext() {
      quiz.fadeOut(function() {
        $("#question").remove();

        if (questionCounter < questions.length) {
          var nextQuestion = createQuestionElement(questionCounter);
          quiz.append(nextQuestion).fadeIn();
          if (!isNaN(selections[questionCounter])) {
            $("input[value=" + selections[questionCounter] + "]").prop(
              "checked",
              true
            );
          }

          // Controls display of 'prev' button
          if (questionCounter === 1) {
            $("#prev").show();
          } else if (questionCounter === 0) {
            $("#prev").hide();
            $("#next").show();
          }
        } else {
          var scoreElem = displayScore();
          quiz.append(scoreElem).fadeIn();
          $("#next").hide();
          $("#prev").hide();
          $("#start").show();
        }
      });
    }

    // Computes score and returns a paragraph element to be displayed
    function displayScore() {
      var score = $("
", {
        id: "question"
      });

      var numCorrect = 0;
      for (var i = 0; i < selections.length; i++) {
        if (selections[i] === questions[i].correctAnswer) {
          numCorrect++;
        }
      }

      score.append(
        "You got " +
        numCorrect +
        " questions out of " +
        questions.length +
        " right!!!"
      );
      return score;
    }
  })();
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  padding: 0;
  margin: 0;
  width: 100%;
  background: url(../images/background.png);
  height: 1vh;
  background-repeat: no-repeat;
}

h1 {
  font-family: sans-serif;
  font-size: 3em;
  font-weight: 700;
  color: #fff;
  text-align: center;
}

#title {
  text-decoration: underline;
}

#header {
  text-align: center;
  font-size: 30px;
  font-weight: 700px;
  color: #fff;
  width: 100%;
  height: 200px;
  padding: 7%;
}

.start-button {
  background-color: rgba(0, 0, 0, .7);
  margin-top: 5%;
  width: 300px;
  height: 100px;
}

.start-button:hover {
  background-color: #0246e2;
  color: #f5684f;
  font-size: 50px;
}

button {
  text-align: center;
}

#clock {
  display: none;
  color: #fff;
  font-size: 100px;
  z-index: 1000;
}

#quiz {
  text-indent: 10px;
}

.button {
  border: 4px solid;
  border-radius: 5px;
  width: 40px;
  padding-left: 5px;
  padding-right: 5px;
  position: relative;
  float: right;
  background-color: #DCDCDC;
  color: black;
  margin: 0 2px 0 2px;
}

.button.active {
  background-color: #F8F8FF;
  color: #525252;
}

#questions {
  display: none;
  padding-top: 10%;
  width: 100%;
  height: auto;
}

.button a {
  text-decoration: none;
  color: black;
}

#content {
  width: 100%;
  margin: auto;
  padding: 0 25px 40px 10px;
  background-color: rgba(0, 0, 0, .7);
  border: 4px solid #B0E0E6;
  border-radius: 5px;
  color: #FFFFFF;
  font-weight: bold;
  box-shadow: 5px 5px 5px #888;
  height: 500px;
}

ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

#prev {
  display: none;
}

#start {
  display: none;
  width: 90px;
}</code>```

<!DOCTYPE html>

  <title>Trivia Game</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="./assets/css/style.css">

How Well Do You Know Your Geography?

You have 2 min to guess all the questions...Good Luck!

          <button id="clickStart" class="start-button">Start!</button>

00:00

Next

Prev

 Start Over

```

答:
```<code>selections[questionCounter] = +$('input[name="answer"]:checked').val();
</code>```

Do you mean +=, not = + ?

Body:
I have tried multiple things to collect the right answer when the radio button is pressed, but after the game is done I still get a 0 out of 5.
I'm not sure what else to do and have been stuck on this for a while.  Any help will be greatly appreciated!

$(document).ready(function() {

  $("#clickStart").click(function() {
    $('#questions').show(600);
    $('#clock').show(700);
    $('#hide').hide(500);

  });

  (function() {
    var questions = [{
        question: "The great Victoria Desert is located in?",
        choices: ['Canada', 'West Africa', 'Australia', 'North America'],
        correctAnswer: 'Australia'
      },
      {
        question: "The intersecting lines drawn on maps and globes are?",
        choices: ['lattitudes', 'longitudes', 'geographic grids', 'none of the above'],
        correctAnswer: 'geographic gird'
      },
      {
        question: "The landmass of which of the following continents is the least?",
        choices: ['Africa', 'Asia', 'Australia', 'Europe'],
        correctAnswer: 'Australia'
      },
      {
        question: "Without ____ the equator would be much hotter than it is while the poles would be much cooler",
        choices: ['Lattitude of redistribution of heat', 'Cycle of air circulation', 'Global wind pattern', 'All are similiar'],
        correctAnswer: 'All are simliar'
      },
      {
        question: "The habitats valuable for commercially harvested species are called?",
        choices: ['Coral reefs', 'Sea grass bed', 'hot spots', 'None of the above'],
        correctAnswer: 'Sea grass bed'
      }
    ];

    var questionCounter = 0; //Tracks question number
    var selections = []; //Array containing user choices
    var quiz = $("#quiz"); //Quiz div object

    // Display initial question
    displayNext();

    //  'next' button
    $("#next").on("click", function(e) {
      e.preventDefault();

      // Suspend click listener during fade animation
      if (quiz.is(":animated")) {
        return false;
      }
      choose();

      // If no user selection, progress is stopped
      if (isNaN(selections[questionCounter])) {
        alert("Please make a selection!");
      } else {
        questionCounter++;
        displayNext();
      }
    });

    // 'prev' button
    $("#prev").on("click", function(e) {
      e.preventDefault();

      if (quiz.is(":animated")) {
        return false;
      }
      choose();
      questionCounter--;
      displayNext();
    });

    // 'Start Over' button
    $("#start").on("click", function(e) {
      e.preventDefault();

      if (quiz.is(":animated")) {
        return false;
      }
      questionCounter = 0;
      selections = [];
      displayNext();
      $("#start").hide();
    });

    // Animates buttons on hover
    $(".button").on("mouseenter", function() {
      $(this).addClass("active");
    });
    $(".button").on("mouseleave", function() {
      $(this).removeClass("active");
    });

    // Creates and returns the div that contains the questions and
    // the answer selections
    function createQuestionElement(index) {
      var qElement = $("
", {
        id: "question"
      });

      var header = $("
Question " + (index + 1) + ":
");
      qElement.append(header);

      var question = $("
").append(questions[index].question);
      qElement.append(question);

      var radioButtons = createRadios(index);
      qElement.append(radioButtons);

      return qElement;
    }

    // Creates a list of the answer choices as radio inputs
    function createRadios(index) {
      var radioList = $("
");
      var item;
      var input = "";
      for (var i = 0; i < questions[index].choices.length; i++) {
        item = $("
");
        input = '<input type="radio" name="answer" value=' + i + " />";
        input += questions[index].choices[i];
        item.append(input);
        radioList.append(item);
      }
      return radioList;
    }

    // Reads the user selection and pushes the value to an array
    function choose() {
      selections[questionCounter] = +$('input[name="answer"]:checked').val();
    }

    // Displays next requested element
    function displayNext() {
      quiz.fadeOut(function() {
        $("#question").remove();

        if (questionCounter < questions.length) {
          var nextQuestion = createQuestionElement(questionCounter);
          quiz.append(nextQuestion).fadeIn();
          if (!isNaN(selections[questionCounter])) {
            $("input[value=" + selections[questionCounter] + "]").prop(
              "checked",
              true
            );
          }

          // Controls display of 'prev' button
          if (questionCounter === 1) {
            $("#prev").show();
          } else if (questionCounter === 0) {
            $("#prev").hide();
            $("#next").show();
          }
        } else {
          var scoreElem = displayScore();
          quiz.append(scoreElem).fadeIn();
          $("#next").hide();
          $("#prev").hide();
          $("#start").show();
        }
      });
    }

    // Computes score and returns a paragraph element to be displayed
    function displayScore() {
      var score = $("
", {
        id: "question"
      });

      var numCorrect = 0;
      for (var i = 0; i < selections.length; i++) {
        if (selections[i] === questions[i].correctAnswer) {
          numCorrect++;
        }
      }

      score.append(
        "You got " +
        numCorrect +
        " questions out of " +
        questions.length +
        " right!!!"
      );
      return score;
    }
  })();
});

body {
  padding: 0;
  margin: 0;
  width: 100%;
  background: url(../images/background.png);
  height: 1vh;
  background-repeat: no-repeat;
}

h1 {
  font-family: sans-serif;
  font-size: 3em;
  font-weight: 700;
  color: #fff;
  text-align: center;
}

#title {
  text-decoration: underline;
}

#header {
  text-align: center;
  font-size: 30px;
  font-weight: 700px;
  color: #fff;
  width: 100%;
  height: 200px;
  padding: 7%;
}

.start-button {
  background-color: rgba(0, 0, 0, .7);
  margin-top: 5%;
  width: 300px;
  height: 100px;
}

.start-button:hover {
  background-color: #0246e2;
  color: #f5684f;
  font-size: 50px;
}

button {
  text-align: center;
}

#clock {
  display: none;
  color: #fff;
  font-size: 100px;
  z-index: 1000;
}

#quiz {
  text-indent: 10px;
}

.button {
  border: 4px solid;
  border-radius: 5px;
  width: 40px;
  padding-left: 5px;
  padding-right: 5px;
  position: relative;
  float: right;
  background-color: #DCDCDC;
  color: black;
  margin: 0 2px 0 2px;
}

.button.active {
  background-color: #F8F8FF;
  color: #525252;
}

#questions {
  display: none;
  padding-top: 10%;
  width: 100%;
  height: auto;
}

.button a {
  text-decoration: none;
  color: black;
}

#content {
  width: 100%;
  margin: auto;
  padding: 0 25px 40px 10px;
  background-color: rgba(0, 0, 0, .7);
  border: 4px solid #B0E0E6;
  border-radius: 5px;
  color: #FFFFFF;
  font-weight: bold;
  box-shadow: 5px 5px 5px #888;
  height: 500px;
}

ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

#prev {
  display: none;
}

#start {
  display: none;
  width: 90px;
}

<!DOCTYPE html>

  <title>Trivia Game</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="./assets/css/style.css">

How Well Do You Know Your Geography?

You have 2 min to guess all the questions...Good Luck!

          <button id="clickStart" class="start-button">Start!</button>

00:00

Next

Prev

 Start Over

Body:
selections[questionCounter] = +$('input[name="answer"]:checked').val();

Do you mean +=, not = + ?


问:
Why is the Chars property of the StringBuilder class missing in Visual C# 2008 Express?
That's pretty much the whole question. I've installed Visual C# 2008 Express on a clean Windows XP Pro SP3 machine, started a new Windows Forms project, double-clicked the form to create a Form1_Load method, then typed:

```<code>StringBuilder SB;
SB = new StringBuilder("test");
SB.Chars
</code>```

but Chars doesn't appear on the autocomplete menu. Why not?

答:
It's the indexer, which you reference with foo[bar] syntax instead of foo.Chars(bar):

```<code>StringBuilder sb = new StringBuilder("Hello");
char c = sb[1]; // c='e'
</code>```

C# doesn't use the names of indexers, nor can it use multiple indexers with the same parameters which are named differently (created in a different language).

Most of the time this is okay, but just occasionally I wish it supported named indexers fully...

OwnerDisplayName: matthewk

Body:
That's pretty much the whole question. I've installed Visual C# 2008 Express on a clean Windows XP Pro SP3 machine, started a new Windows Forms project, double-clicked the form to create a Form1_Load method, then typed:

StringBuilder SB;
SB = new StringBuilder("test");
SB.Chars

but Chars doesn't appear on the autocomplete menu. Why not?

Body:
It's the indexer, which you reference with foo[bar] syntax instead of foo.Chars(bar):

StringBuilder sb = new StringBuilder("Hello");
char c = sb[1]; // c='e'

C# doesn't use the names of indexers, nor can it use multiple indexers with the same parameters which are named differently (created in a different language).

Most of the time this is okay, but just occasionally I wish it supported named indexers fully...

OwnerDisplayName: Jon Skeet


问:
HttpPostedFileBase to Image throws exceptions
I am uploading a big image ~10Mb and I have the following code:

```<code>public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
    foreach (var file in files)
    {
        var image = Image.FromStream(file.InputStream, true, true);
        ...
    }
}
</code>```

Sometime it throws Out of Memory, sometimes GDI+ generic errors. I cannot reproduce this in a console app with the following code:

```<code>using (FileStream stream = File.Open(@"d:\test.jpg", FileMode.Open))
{
    var image = Image.FromStream(stream);
}
</code>```

What can be the cause for those exceptions? One note: for small images everything works great.

答:
Refer- out of memory Image.FromFile

I think the reason you are not able to reproduce this in console app is because you are using disposable code block (using block).

Try changing you code to something like this-

```<code>public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
    foreach (var file in files)
    {
        fs = new FileStream(image_url, FileMode.Open, FileAccess.Read);
        img = Image.FromStream(fs);
        var image = Image.FromStream(fs);
        ...

        //after you are done call below line
        fs.Close();
    }
}
</code>```

Or you can use using block within your for-loop-

```<code>public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
    foreach (var file in files)
    {
        using (FileStream stream = File.Open(<give_file_URL_here>, FileMode.Open))
        {
            var image = Image.FromStream(stream);
            //...
        }
    }
}
</code>```

Body:
I am uploading a big image ~10Mb and I have the following code:

public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
    foreach (var file in files)
    {
        var image = Image.FromStream(file.InputStream, true, true);
        ...
    }
}

Sometime it throws Out of Memory, sometimes GDI+ generic errors. I cannot reproduce this in a console app with the following code:

using (FileStream stream = File.Open(@"d:\test.jpg", FileMode.Open))
{
    var image = Image.FromStream(stream);
}

What can be the cause for those exceptions? One note: for small images everything works great.

Body:
Refer- out of memory Image.FromFile

I think the reason you are not able to reproduce this in console app is because you are using disposable code block (using block).

Try changing you code to something like this-

public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
    foreach (var file in files)
    {
        fs = new FileStream(image_url, FileMode.Open, FileAccess.Read);
        img = Image.FromStream(fs);
        var image = Image.FromStream(fs);
        ...

        //after you are done call below line
        fs.Close();
    }
}

Or you can use using block within your for-loop-

public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
    foreach (var file in files)
    {
        using (FileStream stream = File.Open(<give_file_URL_here>, FileMode.Open))
        {
            var image = Image.FromStream(stream);
            //...
        }
    }
}


问:
ACH eCheck payment via Forte payment processing, one time tocken and restAPI
I am integrating ACH eCheck payment via Forte.js.

The documentation said the first step is getting a one-time security token, which I did, using forte.js.

Then I should use this token for the REST API to make the transaction.

Does anyone know what is the next step after getting the token (it is alerted)?

It's not clear from the documentation how to make a transaction.

Thank you!

答:
You should be able to call the REST API with this JSON data</p>

```<code>{
   "action":"sale",
   "authorization_amount":1.00,
   "billing_address":{
      "first_name":"Emmett",
      "last_name":"Brown"
   },
   "echeck":{
      "one_time_token":"ott_tq0hemmmtf-zsxgp689rew"
   }
}
</code>```

Body:
You should be able to call the REST API with this JSON data

{
   "action":"sale",
   "authorization_amount":1.00,
   "billing_address":{
      "first_name":"Emmett",
      "last_name":"Brown"
   },
   "echeck":{
      "one_time_token":"ott_tq0hemmmtf-zsxgp689rew"
   }
}


问:
paypal rest api update payment's item
i use paypal rest api payments resource to update a payment's amount and item info; i just want change the item's price and tax; and shipping amount; but return MALFORMED_REQUEST; make me drunken...

the request_data is :

 {
    "op": "replace",
    "path": "/transactions/0/item_list/items/0",
    "value": {
      "name": "hello",
      "quantity": "2",
      "price": "100",
      "currency": "USD",
      "tax": "12"
    }
  },
  {
    "op": "replace",
    "path": "/transactions/0/amount",
    "value": {
      "currency": "USD",
      "total": "224",
      "details": {
        "shipping": "12",
        "subtotal": "200",
        "tax": "12"
      }
    }
  }```

and return :
    {"name":"MALFORMED_REQUEST","message":"MALFORMED_REQUEST","information_link":"https://developer.paypal.com/docs/api/#MALFORMED_REQUEST","debug_id":"78c05f9b4f21"}

i want make sure that:

1、can update payment's item info with paypal

2、is the path "/transactions/0/item_list/items/0" right

thank you very much!

答:
I'm using PayPal Java SDK and I used the code below to update the cart items and total value.</p>

```<code>APIContext context = new APIContext(clientId,clientSecret,environment);

List<Patch> patches = new ArrayList<Patch>();

Amount amount = new Amount();
amount.setCurrency("BRL");
amount.setTotal("100.00");

Patch patch1 = new Patch();
patch1.setOp("replace").setPath("/transactions/0/amount").setValue(amount);

patches.add(patch1);

ItemList items = getItens(order);

Patch patch2 = new Patch();
        patch2.setOp("replace").setPath("/transactions/0/item_list").setValue(items);

patches.add(patch2);

try {

    Payment payment = Payment.get(context, id);

    payment.update(context, patches);

    ...
} ....
</code>```

Title: paypal rest api update payment's item

Body:
i use paypal rest api payments resource to update a payment's amount and item info; i just want change the item's price and tax; and shipping amount; but return MALFORMED_REQUEST; make me drunken...

the request_data is :

 {
    "op": "replace",
    "path": "/transactions/0/item_list/items/0",
    "value": {
      "name": "hello",
      "quantity": "2",
      "price": "100",
      "currency": "USD",
      "tax": "12"
    }
  },
  {
    "op": "replace",
    "path": "/transactions/0/amount",
    "value": {
      "currency": "USD",
      "total": "224",
      "details": {
        "shipping": "12",
        "subtotal": "200",
        "tax": "12"
      }
    }
  }

and return :
    {"name":"MALFORMED_REQUEST","message":"MALFORMED_REQUEST","information_link":"https://developer.paypal.com/docs/api/#MALFORMED_REQUEST","debug_id":"78c05f9b4f21"}

i want make sure that:

1、can update payment's item info with paypal

2、is the path "/transactions/0/item_list/items/0" right

thank you very much!

Body:
I'm using PayPal Java SDK and I used the code below to update the cart items and total value.

APIContext context = new APIContext(clientId,clientSecret,environment);

List<Patch> patches = new ArrayList<Patch>();

Amount amount = new Amount();
amount.setCurrency("BRL");
amount.setTotal("100.00");

Patch patch1 = new Patch();
patch1.setOp("replace").setPath("/transactions/0/amount").setValue(amount);

patches.add(patch1);

ItemList items = getItens(order);

Patch patch2 = new Patch();
        patch2.setOp("replace").setPath("/transactions/0/item_list").setValue(items);

patches.add(patch2);

try {

    Payment payment = Payment.get(context, id);

    payment.update(context, patches);

    ...
} ....


问:
Sort dates in descending order
I want to sort my object that has dates in descending order. Here is the code I use in my fragment -

```<code>int pos = adapter.contains(status.id);
if (pos == -1) {
    myobj = new MyAdapter.Mymyobj();
    myobj.status = status;
    adapter.addItem(myobj);
} else {
    myobj = adapter.getItem(pos);
    myobj.status = status;
}
convertStringToDate(myobj.status.getTimeInString());
sortDates.add(convertedDate);
Comparator<Date> cmp = Collections.reverseOrder(null);
Collections.sort(sortDates, cmp);

adapter.notifyDataSetChanged();

private Date convertStringToDate(final String dateString) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM. HH:mm");
    try {
        convertedDate = dateFormat.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return convertedDate;
}
</code>```

The above code is not working..Nothing is happening actually. I want the list to be in descending order.
Should I do something in adapter as well?

答:
Take a look at this tutorial. It shows you how to use the Collections.reverseOrder() comparator. Basically, you're calling it wrong. You should use:

Collections.sort(sortDates, Collections.reverseOrder());

Note that I'm not passing null as parameter here.

Title: Sort dates in descending order

Body:
I want to sort my object that has dates in descending order. Here is the code I use in my fragment -

int pos = adapter.contains(status.id);
if (pos == -1) {
    myobj = new MyAdapter.Mymyobj();
    myobj.status = status;
    adapter.addItem(myobj);
} else {
    myobj = adapter.getItem(pos);
    myobj.status = status;
}
convertStringToDate(myobj.status.getTimeInString());
sortDates.add(convertedDate);
Comparator<Date> cmp = Collections.reverseOrder(null);
Collections.sort(sortDates, cmp);

adapter.notifyDataSetChanged();

private Date convertStringToDate(final String dateString) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM. HH:mm");
    try {
        convertedDate = dateFormat.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return convertedDate;
}

The above code is not working..Nothing is happening actually. I want the list to be in descending order.
Should I do something in adapter as well?


问:
Convert Spritekit Game to Android?
Are there any new options for converting a spritekit game to android? It seems the only options are to recode everything in Java or to use Cocos2D, LibGDX, etc.</p>

答: There are no easy options for supporting Android with a SpriteKit game, but with a little bit of work and not too much difficulty you can recode your game to use Cocos2d-x.  I just completed such a project for my game.  It took me about four months working half time.  I've posted some tips here: http://doffen.org/porting-spritekit-to-cocos2d-x. </p>

Title: Convert Spritekit Game to Android?


问:
How to get intersection of the arrays in a nested array
I have an array like the following which is computed from another function I don't want to modify.

```<code>var d = [[1, 2, 3], [2, 3], [1, 3]];
</code>```

I want to use _.intersection with all the arrays within the above array like this:

```<code>var c = _.intersection(d);
// should return [3]
</code>```

but _.intersection takes multiple array parameters as input, not an array of arrays.

I have tried to flatten an array using something similar to Merge/flatten an array of arrays in JavaScript? but it convert the whole array into a single array.

```<code>var merged = [].concat.apply([], d);
[1, 2, 3, 2, 3, 1, 3]; // I don't want this
</code>```

Let me explain this in detail. I have a nested array d (which contains arrays and length is dynamic). Now I want to find the intersection of all arrays that are within array d.

How can I call _.intersection([1, 2, 3], [2, 3], [1, 3], ...) but dynamically with d?

答:
Your desired result is not a data structure js would support. However, you can destructure the arrays into variables:

let [a,b,c] = [[1, 2, 3], [2, 3], [1, 3]];
console.log(a,b,c);```
</div>
</div>
</p>

<p>The only valid representation of what you want to get is a string. You can get the exact result you've asked for like that :-) :</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let d = [
  [1, 2, 3],
  [2, 3],
  [1, 3]
];

function createString(arr) {
  let s = arr.map(el => `[${el}]`).join(", ");
  return `result ${s};`;
}

console.log(createString(d));</code>```

Body:
I have an array like the following which is computed from another function I don't want to modify.

var d = [[1, 2, 3], [2, 3], [1, 3]];

I want to use _.intersection with all the arrays within the above array like this:

var c = _.intersection(d);
// should return [3]

but _.intersection takes multiple array parameters as input, not an array of arrays.

I have tried to flatten an array using something similar to Merge/flatten an array of arrays in JavaScript? but it convert the whole array into a single array.

var merged = [].concat.apply([], d);
[1, 2, 3, 2, 3, 1, 3]; // I don't want this

Let me explain this in detail. I have a nested array d (which contains arrays and length is dynamic). Now I want to find the intersection of all arrays that are within array d.

How can I call _.intersection([1, 2, 3], [2, 3], [1, 3], ...) but dynamically with d?

Body:
Your desired result is not a data structure js would support. However, you can destructure the arrays into variables:

let [a,b,c] = [[1, 2, 3], [2, 3], [1, 3]];
console.log(a,b,c);

The only valid representation of what you want to get is a string. You can get the exact result you've asked for like that :-) :

let d = [
  [1, 2, 3],
  [2, 3],
  [1, 3]
];

function createString(arr) {
  let s = arr.map(el => `[${el}]`).join(", ");
  return `result ${s};`;
}

console.log(createString(d));


问:
Creating an Array to store Table Cell Button Values at Cell Index
I am currently working on a program where I have a TableView with a Segmented Control in each row. I have attached a tag to each segmented control that corresponds to the row the segmented control is in (i.e. segmented control 1 corresponds to row 1, etc). Additionally, the segmented control has its own index (option 0 corresponds to an index of 0 and option 1 corresponds to an index of 1)

I would like to have an array that stores the value of the segmented control index in a location that corresponds to segmented control's tag. i.e. if the first row's segmented control index is 1, the second row's segmented control index is 0, and the third row's segmented control index is 1, the array should output:
[1,0,1]

The best idea I have is to create an array, specify the array's index as the segmented control's tag, and then specify the value at that index to be the value of the segmented control's index (sorry I know its confusing).

I'm sure this is a programming problem someone has had before, however I can't find any information on it. I am programming in swift, but since this is more of a logical problem than a programming one I am willing to accept a solution in any other language.

Thanks,
Nick

P.S.
Here is a picture of the app so far and the code I am using for your reference.

https://i.stack.imgur.com/ezMUJ.png

import UIKit

class MyTableViewController: UITableViewController {

```<code>override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 150
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return 10
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)

    let nameLabel: UILabel = {
        let label = UILabel()
        label.text = "Sample Item"
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()

    let actionButton = YSSegmentedControl(
        frame: CGRect.zero,
        titles: [
            "Yes",
            "No"
        ])

actionButton.delegate = self
cell.addSubview(nameLabel)
cell.addSubview(actionButton)
actionButton.translatesAutoresizingMaskIntoConstraints = false

cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]-160-[v1]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel, "v1": actionButton]));
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-60-[v0]-60-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": actionButton]))

actionButton.tag = indexPath.row

    cell.backgroundColor = .green
    return cell

}

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellId")

    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

extension MyTableViewController: YSSegmentedControlDelegate {
func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt    index: Int) {
    print("\(segmentedControl.tag)" + "\(index)")

}

func segmentedControl(_ segmentedControl: YSSegmentedControl, didPressItemAt index: Int) {

}
</code>```

}

答:
Using an array like will work as long as the number of items in the array matches the number of cells. So in you table view controller you have an array which is populated with the initial values.  Something like this:

```<code>var dataArray: [Int] = [1,0,1,1,1,1,0]
</code>```

You can then use the array to determine the number of rows you require so that they always match like this:

```<code>override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return dataArray.count
}
</code>```

The basic idea is to separate out the data representation from the UI.

On a related note and to help you out you have a problem when creating the cell.  You use dequeueReusableCell to get a cell from the table and then add your label and segmented control to it.  When the table scrolls the cells will begin to be reused and you will get one you have already added the label and segmented control to and you will add another label and segmented control to it.  This will continue on and on until you have loads of labels and segment controls on each cell.  You need to avoid doing this otherwise eventually your app may crash.

Body:
I am currently working on a program where I have a TableView with a Segmented Control in each row. I have attached a tag to each segmented control that corresponds to the row the segmented control is in (i.e. segmented control 1 corresponds to row 1, etc). Additionally, the segmented control has its own index (option 0 corresponds to an index of 0 and option 1 corresponds to an index of 1)

I would like to have an array that stores the value of the segmented control index in a location that corresponds to segmented control's tag. i.e. if the first row's segmented control index is 1, the second row's segmented control index is 0, and the third row's segmented control index is 1, the array should output:
[1,0,1]

The best idea I have is to create an array, specify the array's index as the segmented control's tag, and then specify the value at that index to be the value of the segmented control's index (sorry I know its confusing).

I'm sure this is a programming problem someone has had before, however I can't find any information on it. I am programming in swift, but since this is more of a logical problem than a programming one I am willing to accept a solution in any other language.

Thanks,
Nick

P.S.
Here is a picture of the app so far and the code I am using for your reference.

https://i.stack.imgur.com/ezMUJ.png

import UIKit

class MyTableViewController: UITableViewController {

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

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return 10
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)

    let nameLabel: UILabel = {
        let label = UILabel()
        label.text = "Sample Item"
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()

    let actionButton = YSSegmentedControl(
        frame: CGRect.zero,
        titles: [
            "Yes",
            "No"
        ])

actionButton.delegate = self
cell.addSubview(nameLabel)
cell.addSubview(actionButton)
actionButton.translatesAutoresizingMaskIntoConstraints = false

cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]-160-[v1]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel, "v1": actionButton]));
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-60-[v0]-60-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": actionButton]))

actionButton.tag = indexPath.row

    cell.backgroundColor = .green
    return cell

}

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellId")

    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

extension MyTableViewController: YSSegmentedControlDelegate {
func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt    index: Int) {
    print("\(segmentedControl.tag)" + "\(index)")

}

func segmentedControl(_ segmentedControl: YSSegmentedControl, didPressItemAt index: Int) {

}

}

Body:
Using an array like will work as long as the number of items in the array matches the number of cells. So in you table view controller you have an array which is populated with the initial values.  Something like this:

var dataArray: [Int] = [1,0,1,1,1,1,0]

You can then use the array to determine the number of rows you require so that they always match like this:

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return dataArray.count
}

The basic idea is to separate out the data representation from the UI.

On a related note and to help you out you have a problem when creating the cell.  You use dequeueReusableCell to get a cell from the table and then add your label and segmented control to it.  When the table scrolls the cells will begin to be reused and you will get one you have already added the label and segmented control to and you will add another label and segmented control to it.  This will continue on and on until you have loads of labels and segment controls on each cell.  You need to avoid doing this otherwise eventually your app may crash.


问:
Why does my code thinks that 60 is bigger than 135?

i want to get the bigger number and subtract by the smaller number (input's value) even tho they are in the wrong order when you put them into the input like -1 = inputX / 1 = inputY then 1 = greater and -1 smaller, it works with other numbers, but these kinda break it idk why tho what did I do wrong?
  why does it think 60 is bigger than 135? look at the img...

```<code><script type="text/javascript">
var x;
var y;
var big;
var small;
var result;
function calcT() {
    x = document.getElementById("inputX").value;
    y = document.getElementById("inputY").value;
    //result = x - y;
    if(x > y) {
      big = x;
      small = y;
       } else if(x < y) {
      big = y;
      small = x;
       }
    result = parseInt(big) - parseInt(small);
    document.getElementById("resultHere").innerHTML = result;

}
</code>```

答:
Wouldn't it be easier to do this:

```<code>var result = Math.abs(x-y);
</code>```

This will save you the trouble of using the if-else ladder and basically give you the same thing in 1 line.

And the issue is with you comparing strings instead of numbers as pointed out by others. You could do something like:

```<code>var x = parseInt(document.getElementById("inputX").value);
var y = parseInt(document.getElementById("inputY").value);
var result = (x<y) ? y-x : x-y;
</code>```

Body:
Wouldn't it be easier to do this:

var result = Math.abs(x-y);

This will save you the trouble of using the if-else ladder and basically give you the same thing in 1 line.

And the issue is with you comparing strings instead of numbers as pointed out by others. You could do something like:

var x = parseInt(document.getElementById("inputX").value);
var y = parseInt(document.getElementById("inputY").value);
var result = (x<y) ? y-x : x-y;