问:
Facing issue with kura and block reactive
I am implementing simple block reactive, and want deploy a package in kura.

However, every time I am upload the .dp file, kura stops working, or the file is not installed. I followed all the steps to configure eclipse and kura, including importing the zip for block reactive, and installing mtoolkit.

I did all necessary network setup in kura, too.

This is the output from /var/log/kura-console.log:

```<code>!MESSAGE Bundle 'com.bitreactive.blocks.osgi.runtime/2.6.1 already present in other deployment packages!

!ENTRY 1 0 2017-11-16 03:43:10.582 !MESSAGE [IAgent][DeploymentEventListener@49dc62] [handleComplete] Deployment package event is not successful

!ENTRY org.apache.felix.deploymentadmin 4 0 2017-11-16 03:48:25.393 !MESSAGE Bundle 'com.bitreactive.blocks.osgi.runtime/2.6.1 already present in other deployment packages!

!ENTRY 1 0 2017-11-16 03:48:25.402 !MESSAGE [IAgent][DeploymentEventListener@49dc62] [handleComplete] Deployment package event is not successful

THIS IS THE OUTPUT OF 'ss' command
    id  State       Bundle
    0   ACTIVE      org.eclipse.osgi_3.8.1.v20120830-144521 Fragments=74
    1   ACTIVE      com.bitreactive.library.coap_1.5.0
    2   INSTALLED   jdk.dio_1.0.5
    3   ACTIVE      org.eclipse.kura.emulator.clock_1.0.1
    4   ACTIVE      com.bitreactive.library.buffering_3.11.2
    5   ACTIVE      org.eclipse.kura.camel.xml_1.0.0
    6   ACTIVE      com.google.protobuf_2.6.0
    7   ACTIVE      org.eclipse.kura.core.net_1.0.10
    8   ACTIVE      org.eclipse.kura.example.camel.publisher_1.0.0
    9   ACTIVE      com.bitreactive.library.polling_1.1.2
    10  ACTIVE      org.eclipse.kura.example.camel.quickstart_1.1.0
    11  ACTIVE      org.eclipse.equinox.util_1.0.400.v20120522-2049
    12  ACTIVE      org.eclipse.osgi.util_3.2.300.v20120522-1822
    13  ACTIVE      com.bitreactive.library.geofence_1.5.0
    14  ACTIVE      org.apache.felix.dependencymanager_3.0.0
    15  ACTIVE      org.eclipse.soda.dk.comm_1.2.3
    16  ACTIVE      com.bitreactive.library.rpi.peripherals_1.15.0
    17  ACTIVE      org.eclipse.jetty.http_8.1.3.v20120522
    18  ACTIVE      org.apache.felix.gogo.command_0.8.0.v201108120515
    19  ACTIVE      californium-osgi_1.0.0.SNAPSHOT
    20  ACTIVE      com.bitreactive.library.osgi.service_1.0.0
    21  ACTIVE      org.eclipse.kura.emulator_1.0.8
    22  ACTIVE      com.google.gson_2.2.4
    23  ACTIVE      org.apache.camel.camel-kura_2.17.2
    24  ACTIVE      org.hsqldb.hsqldb_2.3.0
    25  ACTIVE      com.bitreactive.library.keyteq.sms_1.1.0
    26  ACTIVE      com.bitreactive.library.chirp_2.0.0
    27  ACTIVE      org.eclipse.kura.deployment.agent_1.0.7
    28  ACTIVE      org.eclipse.equinox.common_3.6.100.v20120522-1841
    29  ACTIVE      org.eclipse.jetty.continuation_8.1.3.v20120522
    30  ACTIVE      org.eclipse.jetty.server_8.1.3.v20120522
    31  ACTIVE      org.eclipse.jetty.util_8.1.3.v20120522
    32  ACTIVE      org.eclipse.kura.core.configuration_1.0.9
    33  ACTIVE      com.bitreactive.library.properties_1.2.0
    34  ACTIVE      org.apache.camel.camel-core_2.17.2
                    Fragments=54
    35  ACTIVE      org.eclipse.equinox.event_1.2.200.v20120522-2049
    36  ACTIVE      br.lib.camera_1.18.0
    37  ACTIVE      org.eclipse.kura.web_2.0.3
    38  ACTIVE      org.apache.commons.io_2.4.0
    39  ACTIVE      org.apache.felix.gogo.shell_0.8.0.v201110170705
    40  ACTIVE      org.eclipse.equinox.io_1.0.400.v20120522-2049
    41  ACTIVE      org.eclipse.kura.core.status_1.0.2
    42  ACTIVE      com.bitreactive.library.email_1.9.0
    43  ACTIVE      demo2_1.0.0
    44  ACTIVE      org.junit_4.10.0.v4_10_0_v20120426-0900
    45  ACTIVE      agrinode_1.0.0
    46  ACTIVE      com.bitreactive.library.twilio.sms_1.5.0
    47  ACTIVE      org.eclipse.kura.core.comm_1.0.3
    48  ACTIVE      com.bitreactive.library.simplehttp_1.17.0
    49  ACTIVE      com.bitreactive.blocks.osgi.runtime_2.6.1
    50  ACTIVE      org.eclipse.equinox.app_1.3.100.v20120522-1841
    51  ACTIVE      org.eclipse.jetty.io_8.1.3.v20120522
    52  ACTIVE      javax.servlet_3.0.0.v201112011016
    53  ACTIVE      com.gwt.user_1.0.0
    54  RESOLVED    org.eclipse.kura.camel.sun.misc_1.0.0
                    Master=34
    55  ACTIVE      no.ntnu.item.arctis.library.sessions_1.8.1
    56  ACTIVE      br.lib.intel.edison.peripheral_1.0.2
    57  ACTIVE      joda-time_2.0.0
    58  ACTIVE      org.eclipse.equinox.http.servlet_1.1.300.v20120522-1841
    59  ACTIVE      com.bitreactive.library.osgi_1.7.0
    60  ACTIVE      org.apache.camel.camel-core-osgi_2.17.2
    61  ACTIVE      slf4j.api_1.7.21
                    Fragments=104, 117
    62  ACTIVE      com.bitreactive.libraries.types.coap_1.6.0
    63  ACTIVE      org.eclipse.kura.api_1.1.0
    64  ACTIVE      org.eclipse.equinox.cm_1.0.400.v20120522-1841
    65  ACTIVE      org.apache.felix.gogo.runtime_0.8.0.v201108120515
    66  ACTIVE      org.eclipse.jetty.security_8.1.3.v20120522
    67  ACTIVE      org.eclipse.equinox.console_1.0.0.v20120522-1841
    68  ACTIVE      bcprov_1.53.0
    69  ACTIVE      com.bitreactive.library.rpi.gpio_1.10.0
    70  ACTIVE      br.lib.intel.edison_1.0.1
    71  ACTIVE      br.lib.rpi_1.9.0
    72  ACTIVE      com.bitreactive.library.kml_1.2.0
    73  ACTIVE      org.eclipse.kura.example.ble.tisensortag_1.0.3
    74  RESOLVED    org.eclipse.kura.sun.misc_1.0.0
                    Master=0
    75  ACTIVE      org.eclipse.kura.example.publisher_1.0.2
    76  ACTIVE      com.codeminders.hidapi_1.1.2
    77  ACTIVE      org.eclipse.kura.core.certificates_1.0.3
    78  ACTIVE      org.eclipse.kura.emulator.position_1.0.2
    79  ACTIVE      org.apache.commons.exec_1.3.0
    80  ACTIVE      org.eclipse.equinox.registry_3.5.200.v20120522-1841
    81  ACTIVE      com.bitreactive.library.timers_1.6.1
    82  ACTIVE      org.apache.camel.camel-stream_2.17.2
    83  ACTIVE      com.bitreactive.library.sms.clickatell_1.7.0
    84  ACTIVE      org.eclipse.kura.example.camel.aggregation_1.1.0
    85  ACTIVE      org.eclipse.equinox.http.registry_1.1.200.v20120522-2049
    86  ACTIVE      org.eclipse.kura.camel_1.1.0
    87  ACTIVE      org.eclipse.kura.emulator.watchdog_1.0.1
    88  ACTIVE      no.ntnu.item.arctis.library.speech_2.8.0
    89  ACTIVE      org.tigris.mtoolkit.iagent.rpc_3.0.0.20110411-0918
    90  ACTIVE      org.hamcrest.core_1.1.0.v20090501071000
    91  ACTIVE      org.eclipse.jetty.servlet_8.1.3.v20120522
    92  ACTIVE      com.bitreactive.features.mqtt_1.2.0
    93  RESOLVED    log4j.apache-log4j-extras_1.1.0
                    Master=126
    94  ACTIVE      org.blocksreactive.kura.demo_1.0.0
    95  ACTIVE      org.knowhowlab.osgi.monitoradmin_1.0.2
    96  ACTIVE      com.bitreactive.library.gson_1.6.0
    97  ACTIVE      org.eclipse.kura.demo.heater_1.0.2
    98  ACTIVE      org.eclipse.kura.core_1.0.10
    99  ACTIVE      com.bitreactive.library.iterator_1.5.0
    100 ACTIVE      com.bitreactive.subsystem.mqtt_1.2.0
    101 ACTIVE      jcl.over.slf4j_1.7.21
    102 ACTIVE      org.eclipse.kura.core.crypto_1.0.5
    103 ACTIVE      org.usb4java_1.0.0
    104 RESOLVED    slf4j.log4j12_1.7.21
                    Master=61
    105 ACTIVE      org.apache.felix.deploymentadmin_0.9.5
    106 ACTIVE      org.eclipse.paho.client.mqttv3_1.0.1
    107 ACTIVE      osgi.cmpn_4.3.0.201111022214
    108 ACTIVE      org.apache.commons.fileupload_1.2.2.v20111214-1400
    109 ACTIVE      com.bitreactive.library.counter_1.9.0
    110 ACTIVE      demo1_1.0.0
    111 ACTIVE      org.eclipse.kura.core.cloud_1.0.9
    112 ACTIVE      com.bitreactive.library.flowlogic_1.13.0
    113 ACTIVE      bcpkix_1.53.0
    114 ACTIVE      com.bitreactive.library.kura_1.1.0
    115 ACTIVE      org.eclipse.core.runtime_3.8.0.v20120521-2346
    116 ACTIVE      org.eclipse.kura.camel.cloud.factory_1.0.0
    117 RESOLVED    slf4j.jdk14_1.7.21
                    Master=61
    118 ACTIVE      org.apache.commons.net_3.1.0.v201205071737
    119 ACTIVE      org.eclipse.equinox.launcher_1.3.0.v20120522-1813
    120 ACTIVE      org.eclipse.kura.emulator.net_1.0.2
    121 ACTIVE      pi4j-core_1.0.0
    122 ACTIVE      rb.kura.demo_2.2.2_2.1.1
    123 ACTIVE      org.eclipse.equinox.http.jetty_3.0.0.v20120522-1841
    124 ACTIVE      org.eclipse.paho.client.mqttv3_1.0.2
    125 ACTIVE      org.eclipse.kura.emulator.gpio_1.0.2
    126 ACTIVE      log4j_1.2.17 Fragments=93
    127 ACTIVE      org.eclipse.equinox.ds_1.4.0.v20120522-1841
    128 ACTIVE      org.eclipse.kura.example.beacon_1.0.2
    129 ACTIVE      org.eclipse.core.jobs_3.5.300.v20120622-204750
    130 ACTIVE      org.eclipse.osgi.services_3.3.100.v20120522-1822
    131 ACTIVE      org.eclipse.kura.emulator.usb_1.0.2
    132 ACTIVE      br.lib.rpi.berryclip_1.9.0
    133 ACTIVE      com.bitreactive.library.periodictimers_1.5.0
    134 ACTIVE      org.eclipse.equinox.metatype_1.2.0.v20120522-1841
    135 ACTIVE      org.eclipse.equinox.preferences_3.5.0.v20120522-1841
    136 ACTIVE      com.bitreactive.library.mqtt_2.12.8
    137 ACTIVE      org.eclipse.kura.linux.bluetooth_1.0.7
    138 ACTIVE      usb4java-javax_1.0.0
    139 ACTIVE      org.apache.commons.lang3_3.4.0
    140 ACTIVE      org.eclipse.core.contenttype_3.4.200.v20120523-2004
</code>```

This is the output of the ls command:

```<code>    ID  State           Component Name          Located in bundle
        1   Active      org.eclipse.kura.clock.ClockService         org.eclipse.kura.emulator.clock(bid=3)
        2   Active      org.eclipse.kura.camel.xml.XmlRouterComponent           org.eclipse.kura.camel.xml(bid=5)
        3   Active      org.eclipse.kura.example.camel.publisher.ExamplePublisher           org.eclipse.kura.example.camel.publisher(bid=8)
        4   Active      org.eclipse.kura.example.camel.quickstart.GatewayRouterJava         org.eclipse.kura.example.camel.quickstart(bid=10)
        5   Unsatisfied     org.eclipse.kura.example.camel.quickstart.GatewayRouterXml          org.eclipse.kura.example.camel.quickstart(bid=10)
        6   Active      org.eclipse.kura.emulator.Emulator          org.eclipse.kura.emulator(bid=21)
        7   Active      org.eclipse.kura.deployment.agent           org.eclipse.kura.deployment.agent(bid=27)
        8   Active      org.eclipse.kura.core.configuration.CloudConfigurationHandler           org.eclipse.kura.core.configuration(bid=32)
        9   Active      org.eclipse.kura.configuration.ConfigurationService         org.eclipse.kura.core.configuration(bid=32)
        10  Active      org.eclipse.equinox.event           org.eclipse.equinox.event(bid=35)
        11  Active      org.eclipse.kura.web.Console            org.eclipse.kura.web(bid=37)
        12  Active      org.eclipse.kura.status.CloudConnectionStatusService            org.eclipse.kura.core.status(bid=41)
        13  Active      org.eclipse.kura.core.comm.CommConnectionFactory            org.eclipse.kura.core.comm(bid=47)
        14  Unsatisfied     org.eclipse.kura.example.ble.tisensortag.BluetoothLe            org.eclipse.kura.example.ble.tisensortag(bid=73)
        15  Unsatisfied     org.eclipse.kura.example.publisher.ExamplePublisher         org.eclipse.kura.example.publisher(bid=75)
        16  Active      org.eclipse.kura.certificate.CertificatesService            org.eclipse.kura.core.certificates(bid=77)
        17  Active      org.eclipse.kura.position.PositionService           org.eclipse.kura.emulator.position(bid=78)
        18  Active      org.eclipse.kura.example.camel.aggregation.GatewayRouter            org.eclipse.kura.example.camel.aggregation(bid=84)
        19  Unsatisfied     org.eclipse.kura.camel.KuraCloudComponentResolver           org.eclipse.kura.camel(bid=86)
        20  Active      org.eclipse.kura.watchdog.WatchdogService           org.eclipse.kura.emulator.watchdog(bid=87)
        21  Unsatisfied     org.eclipse.kura.demo.heater.Heater         org.eclipse.kura.demo.heater(bid=97)
        22  Unsatisfied     org.eclipse.kura.data.DataService           org.eclipse.kura.core(bid=98)
        23  Active      org.eclipse.kura.db.DbService           org.eclipse.kura.core(bid=98)
        24  Unsatisfied     org.eclipse.kura.core.data.transport.mqtt.MqttDataTransport         org.eclipse.kura.core(bid=98)
        25  Active      org.eclipse.kura.ssl.SslManagerService          org.eclipse.kura.core(bid=98)
        26  Active      org.eclipse.kura.system.SystemService           org.eclipse.kura.core(bid=98)
        27  Active      org.eclipse.kura.system.SystemAdminService          org.eclipse.kura.core(bid=98)
        28  Active      org.eclipse.kura.crypto.CryptoService           org.eclipse.kura.core.crypto(bid=102)
        29  Unsatisfied     demo1.demo1.Component           demo1(bid=110)
        30  Unsatisfied     org.eclipse.kura.cloud.CloudService         org.eclipse.kura.core.cloud(bid=111)
        31  Unsatisfied     org.eclipse.kura.cloud.CloudCallService         org.eclipse.kura.core.cloud(bid=111)
        32  Active      org.eclipse.kura.core.cloud.factory.DefaultCloudServiceFactory          org.eclipse.kura.core.cloud(bid=111)
        33  Unsatisfied     org.eclipse.kura.cloud.app.command.CommandCloudApp          org.eclipse.kura.core.cloud(bid=111)
        34  Unsatisfied     org.eclipse.kura.camel.cloud.factory.CamelFactory           org.eclipse.kura.camel.cloud.factory(bid=116)
        35  Active      org.eclipse.kura.camel.cloud.factory.CamelCloudServiceFactory           org.eclipse.kura.camel.cloud.factory(bid=116)
        36  Active      org.eclipse.kura.net.NetworkService         org.eclipse.kura.emulator.net(bid=120)
        37  Active      org.eclipse.kura.gpio.GPIOService           org.eclipse.kura.emulator.gpio(bid=125)
        38  Active      org.eclipse.kura.example.beacon.BeaconExample           org.eclipse.kura.example.beacon(bid=128)
        39  Active      org.eclipse.kura.usb.UsbService         org.eclipse.kura.emulator.usb(bid=131)
        40  Active      org.eclipse.kura.bluetooth.BluetoothService         org.eclipse.kura.l
</code>```

Output of /var/log/kura.log: https://i.stack.imgur.com/F042L.jpg

答: Sorry for the delayed response, I just noticed this post. Have you resolved  your issue? I see a couple of things wrong. The first, your demo component is not active (it is Unsatisfied). Can you issue the OSGi command comp 29 to see what is wrong with the component? The second, it looks like mToolkit is trying to install a second copy of the deployment package. You may have to uninstall your DP first, then re-install. It may be easier to use the Kura web UI for managing the DP instead of mToolkit.</p>

Body:
I am implementing simple block reactive, and want deploy a package in kura.

However, every time I am upload the .dp file, kura stops working, or the file is not installed. I followed all the steps to configure eclipse and kura, including importing the zip for block reactive, and installing mtoolkit.

I did all necessary network setup in kura, too.

This is the output from /var/log/kura-console.log:

!MESSAGE Bundle 'com.bitreactive.blocks.osgi.runtime/2.6.1 already present in other deployment packages!

!ENTRY 1 0 2017-11-16 03:43:10.582 !MESSAGE [IAgent][DeploymentEventListener@49dc62] [handleComplete] Deployment package event is not successful

!ENTRY org.apache.felix.deploymentadmin 4 0 2017-11-16 03:48:25.393 !MESSAGE Bundle 'com.bitreactive.blocks.osgi.runtime/2.6.1 already present in other deployment packages!

!ENTRY 1 0 2017-11-16 03:48:25.402 !MESSAGE [IAgent][DeploymentEventListener@49dc62] [handleComplete] Deployment package event is not successful

THIS IS THE OUTPUT OF 'ss' command
    id  State       Bundle
    0   ACTIVE      org.eclipse.osgi_3.8.1.v20120830-144521 Fragments=74
    1   ACTIVE      com.bitreactive.library.coap_1.5.0
    2   INSTALLED   jdk.dio_1.0.5
    3   ACTIVE      org.eclipse.kura.emulator.clock_1.0.1
    4   ACTIVE      com.bitreactive.library.buffering_3.11.2
    5   ACTIVE      org.eclipse.kura.camel.xml_1.0.0
    6   ACTIVE      com.google.protobuf_2.6.0
    7   ACTIVE      org.eclipse.kura.core.net_1.0.10
    8   ACTIVE      org.eclipse.kura.example.camel.publisher_1.0.0
    9   ACTIVE      com.bitreactive.library.polling_1.1.2
    10  ACTIVE      org.eclipse.kura.example.camel.quickstart_1.1.0
    11  ACTIVE      org.eclipse.equinox.util_1.0.400.v20120522-2049
    12  ACTIVE      org.eclipse.osgi.util_3.2.300.v20120522-1822
    13  ACTIVE      com.bitreactive.library.geofence_1.5.0
    14  ACTIVE      org.apache.felix.dependencymanager_3.0.0
    15  ACTIVE      org.eclipse.soda.dk.comm_1.2.3
    16  ACTIVE      com.bitreactive.library.rpi.peripherals_1.15.0
    17  ACTIVE      org.eclipse.jetty.http_8.1.3.v20120522
    18  ACTIVE      org.apache.felix.gogo.command_0.8.0.v201108120515
    19  ACTIVE      californium-osgi_1.0.0.SNAPSHOT
    20  ACTIVE      com.bitreactive.library.osgi.service_1.0.0
    21  ACTIVE      org.eclipse.kura.emulator_1.0.8
    22  ACTIVE      com.google.gson_2.2.4
    23  ACTIVE      org.apache.camel.camel-kura_2.17.2
    24  ACTIVE      org.hsqldb.hsqldb_2.3.0
    25  ACTIVE      com.bitreactive.library.keyteq.sms_1.1.0
    26  ACTIVE      com.bitreactive.library.chirp_2.0.0
    27  ACTIVE      org.eclipse.kura.deployment.agent_1.0.7
    28  ACTIVE      org.eclipse.equinox.common_3.6.100.v20120522-1841
    29  ACTIVE      org.eclipse.jetty.continuation_8.1.3.v20120522
    30  ACTIVE      org.eclipse.jetty.server_8.1.3.v20120522
    31  ACTIVE      org.eclipse.jetty.util_8.1.3.v20120522
    32  ACTIVE      org.eclipse.kura.core.configuration_1.0.9
    33  ACTIVE      com.bitreactive.library.properties_1.2.0
    34  ACTIVE      org.apache.camel.camel-core_2.17.2
                    Fragments=54
    35  ACTIVE      org.eclipse.equinox.event_1.2.200.v20120522-2049
    36  ACTIVE      br.lib.camera_1.18.0
    37  ACTIVE      org.eclipse.kura.web_2.0.3
    38  ACTIVE      org.apache.commons.io_2.4.0
    39  ACTIVE      org.apache.felix.gogo.shell_0.8.0.v201110170705
    40  ACTIVE      org.eclipse.equinox.io_1.0.400.v20120522-2049
    41  ACTIVE      org.eclipse.kura.core.status_1.0.2
    42  ACTIVE      com.bitreactive.library.email_1.9.0
    43  ACTIVE      demo2_1.0.0
    44  ACTIVE      org.junit_4.10.0.v4_10_0_v20120426-0900
    45  ACTIVE      agrinode_1.0.0
    46  ACTIVE      com.bitreactive.library.twilio.sms_1.5.0
    47  ACTIVE      org.eclipse.kura.core.comm_1.0.3
    48  ACTIVE      com.bitreactive.library.simplehttp_1.17.0
    49  ACTIVE      com.bitreactive.blocks.osgi.runtime_2.6.1
    50  ACTIVE      org.eclipse.equinox.app_1.3.100.v20120522-1841
    51  ACTIVE      org.eclipse.jetty.io_8.1.3.v20120522
    52  ACTIVE      javax.servlet_3.0.0.v201112011016
    53  ACTIVE      com.gwt.user_1.0.0
    54  RESOLVED    org.eclipse.kura.camel.sun.misc_1.0.0
                    Master=34
    55  ACTIVE      no.ntnu.item.arctis.library.sessions_1.8.1
    56  ACTIVE      br.lib.intel.edison.peripheral_1.0.2
    57  ACTIVE      joda-time_2.0.0
    58  ACTIVE      org.eclipse.equinox.http.servlet_1.1.300.v20120522-1841
    59  ACTIVE      com.bitreactive.library.osgi_1.7.0
    60  ACTIVE      org.apache.camel.camel-core-osgi_2.17.2
    61  ACTIVE      slf4j.api_1.7.21
                    Fragments=104, 117
    62  ACTIVE      com.bitreactive.libraries.types.coap_1.6.0
    63  ACTIVE      org.eclipse.kura.api_1.1.0
    64  ACTIVE      org.eclipse.equinox.cm_1.0.400.v20120522-1841
    65  ACTIVE      org.apache.felix.gogo.runtime_0.8.0.v201108120515
    66  ACTIVE      org.eclipse.jetty.security_8.1.3.v20120522
    67  ACTIVE      org.eclipse.equinox.console_1.0.0.v20120522-1841
    68  ACTIVE      bcprov_1.53.0
    69  ACTIVE      com.bitreactive.library.rpi.gpio_1.10.0
    70  ACTIVE      br.lib.intel.edison_1.0.1
    71  ACTIVE      br.lib.rpi_1.9.0
    72  ACTIVE      com.bitreactive.library.kml_1.2.0
    73  ACTIVE      org.eclipse.kura.example.ble.tisensortag_1.0.3
    74  RESOLVED    org.eclipse.kura.sun.misc_1.0.0
                    Master=0
    75  ACTIVE      org.eclipse.kura.example.publisher_1.0.2
    76  ACTIVE      com.codeminders.hidapi_1.1.2
    77  ACTIVE      org.eclipse.kura.core.certificates_1.0.3
    78  ACTIVE      org.eclipse.kura.emulator.position_1.0.2
    79  ACTIVE      org.apache.commons.exec_1.3.0
    80  ACTIVE      org.eclipse.equinox.registry_3.5.200.v20120522-1841
    81  ACTIVE      com.bitreactive.library.timers_1.6.1
    82  ACTIVE      org.apache.camel.camel-stream_2.17.2
    83  ACTIVE      com.bitreactive.library.sms.clickatell_1.7.0
    84  ACTIVE      org.eclipse.kura.example.camel.aggregation_1.1.0
    85  ACTIVE      org.eclipse.equinox.http.registry_1.1.200.v20120522-2049
    86  ACTIVE      org.eclipse.kura.camel_1.1.0
    87  ACTIVE      org.eclipse.kura.emulator.watchdog_1.0.1
    88  ACTIVE      no.ntnu.item.arctis.library.speech_2.8.0
    89  ACTIVE      org.tigris.mtoolkit.iagent.rpc_3.0.0.20110411-0918
    90  ACTIVE      org.hamcrest.core_1.1.0.v20090501071000
    91  ACTIVE      org.eclipse.jetty.servlet_8.1.3.v20120522
    92  ACTIVE      com.bitreactive.features.mqtt_1.2.0
    93  RESOLVED    log4j.apache-log4j-extras_1.1.0
                    Master=126
    94  ACTIVE      org.blocksreactive.kura.demo_1.0.0
    95  ACTIVE      org.knowhowlab.osgi.monitoradmin_1.0.2
    96  ACTIVE      com.bitreactive.library.gson_1.6.0
    97  ACTIVE      org.eclipse.kura.demo.heater_1.0.2
    98  ACTIVE      org.eclipse.kura.core_1.0.10
    99  ACTIVE      com.bitreactive.library.iterator_1.5.0
    100 ACTIVE      com.bitreactive.subsystem.mqtt_1.2.0
    101 ACTIVE      jcl.over.slf4j_1.7.21
    102 ACTIVE      org.eclipse.kura.core.crypto_1.0.5
    103 ACTIVE      org.usb4java_1.0.0
    104 RESOLVED    slf4j.log4j12_1.7.21
                    Master=61
    105 ACTIVE      org.apache.felix.deploymentadmin_0.9.5
    106 ACTIVE      org.eclipse.paho.client.mqttv3_1.0.1
    107 ACTIVE      osgi.cmpn_4.3.0.201111022214
    108 ACTIVE      org.apache.commons.fileupload_1.2.2.v20111214-1400
    109 ACTIVE      com.bitreactive.library.counter_1.9.0
    110 ACTIVE      demo1_1.0.0
    111 ACTIVE      org.eclipse.kura.core.cloud_1.0.9
    112 ACTIVE      com.bitreactive.library.flowlogic_1.13.0
    113 ACTIVE      bcpkix_1.53.0
    114 ACTIVE      com.bitreactive.library.kura_1.1.0
    115 ACTIVE      org.eclipse.core.runtime_3.8.0.v20120521-2346
    116 ACTIVE      org.eclipse.kura.camel.cloud.factory_1.0.0
    117 RESOLVED    slf4j.jdk14_1.7.21
                    Master=61
    118 ACTIVE      org.apache.commons.net_3.1.0.v201205071737
    119 ACTIVE      org.eclipse.equinox.launcher_1.3.0.v20120522-1813
    120 ACTIVE      org.eclipse.kura.emulator.net_1.0.2
    121 ACTIVE      pi4j-core_1.0.0
    122 ACTIVE      rb.kura.demo_2.2.2_2.1.1
    123 ACTIVE      org.eclipse.equinox.http.jetty_3.0.0.v20120522-1841
    124 ACTIVE      org.eclipse.paho.client.mqttv3_1.0.2
    125 ACTIVE      org.eclipse.kura.emulator.gpio_1.0.2
    126 ACTIVE      log4j_1.2.17 Fragments=93
    127 ACTIVE      org.eclipse.equinox.ds_1.4.0.v20120522-1841
    128 ACTIVE      org.eclipse.kura.example.beacon_1.0.2
    129 ACTIVE      org.eclipse.core.jobs_3.5.300.v20120622-204750
    130 ACTIVE      org.eclipse.osgi.services_3.3.100.v20120522-1822
    131 ACTIVE      org.eclipse.kura.emulator.usb_1.0.2
    132 ACTIVE      br.lib.rpi.berryclip_1.9.0
    133 ACTIVE      com.bitreactive.library.periodictimers_1.5.0
    134 ACTIVE      org.eclipse.equinox.metatype_1.2.0.v20120522-1841
    135 ACTIVE      org.eclipse.equinox.preferences_3.5.0.v20120522-1841
    136 ACTIVE      com.bitreactive.library.mqtt_2.12.8
    137 ACTIVE      org.eclipse.kura.linux.bluetooth_1.0.7
    138 ACTIVE      usb4java-javax_1.0.0
    139 ACTIVE      org.apache.commons.lang3_3.4.0
    140 ACTIVE      org.eclipse.core.contenttype_3.4.200.v20120523-2004

This is the output of the ls command:

    ID  State           Component Name          Located in bundle
        1   Active      org.eclipse.kura.clock.ClockService         org.eclipse.kura.emulator.clock(bid=3)
        2   Active      org.eclipse.kura.camel.xml.XmlRouterComponent           org.eclipse.kura.camel.xml(bid=5)
        3   Active      org.eclipse.kura.example.camel.publisher.ExamplePublisher           org.eclipse.kura.example.camel.publisher(bid=8)
        4   Active      org.eclipse.kura.example.camel.quickstart.GatewayRouterJava         org.eclipse.kura.example.camel.quickstart(bid=10)
        5   Unsatisfied     org.eclipse.kura.example.camel.quickstart.GatewayRouterXml          org.eclipse.kura.example.camel.quickstart(bid=10)
        6   Active      org.eclipse.kura.emulator.Emulator          org.eclipse.kura.emulator(bid=21)
        7   Active      org.eclipse.kura.deployment.agent           org.eclipse.kura.deployment.agent(bid=27)
        8   Active      org.eclipse.kura.core.configuration.CloudConfigurationHandler           org.eclipse.kura.core.configuration(bid=32)
        9   Active      org.eclipse.kura.configuration.ConfigurationService         org.eclipse.kura.core.configuration(bid=32)
        10  Active      org.eclipse.equinox.event           org.eclipse.equinox.event(bid=35)
        11  Active      org.eclipse.kura.web.Console            org.eclipse.kura.web(bid=37)
        12  Active      org.eclipse.kura.status.CloudConnectionStatusService            org.eclipse.kura.core.status(bid=41)
        13  Active      org.eclipse.kura.core.comm.CommConnectionFactory            org.eclipse.kura.core.comm(bid=47)
        14  Unsatisfied     org.eclipse.kura.example.ble.tisensortag.BluetoothLe            org.eclipse.kura.example.ble.tisensortag(bid=73)
        15  Unsatisfied     org.eclipse.kura.example.publisher.ExamplePublisher         org.eclipse.kura.example.publisher(bid=75)
        16  Active      org.eclipse.kura.certificate.CertificatesService            org.eclipse.kura.core.certificates(bid=77)
        17  Active      org.eclipse.kura.position.PositionService           org.eclipse.kura.emulator.position(bid=78)
        18  Active      org.eclipse.kura.example.camel.aggregation.GatewayRouter            org.eclipse.kura.example.camel.aggregation(bid=84)
        19  Unsatisfied     org.eclipse.kura.camel.KuraCloudComponentResolver           org.eclipse.kura.camel(bid=86)
        20  Active      org.eclipse.kura.watchdog.WatchdogService           org.eclipse.kura.emulator.watchdog(bid=87)
        21  Unsatisfied     org.eclipse.kura.demo.heater.Heater         org.eclipse.kura.demo.heater(bid=97)
        22  Unsatisfied     org.eclipse.kura.data.DataService           org.eclipse.kura.core(bid=98)
        23  Active      org.eclipse.kura.db.DbService           org.eclipse.kura.core(bid=98)
        24  Unsatisfied     org.eclipse.kura.core.data.transport.mqtt.MqttDataTransport         org.eclipse.kura.core(bid=98)
        25  Active      org.eclipse.kura.ssl.SslManagerService          org.eclipse.kura.core(bid=98)
        26  Active      org.eclipse.kura.system.SystemService           org.eclipse.kura.core(bid=98)
        27  Active      org.eclipse.kura.system.SystemAdminService          org.eclipse.kura.core(bid=98)
        28  Active      org.eclipse.kura.crypto.CryptoService           org.eclipse.kura.core.crypto(bid=102)
        29  Unsatisfied     demo1.demo1.Component           demo1(bid=110)
        30  Unsatisfied     org.eclipse.kura.cloud.CloudService         org.eclipse.kura.core.cloud(bid=111)
        31  Unsatisfied     org.eclipse.kura.cloud.CloudCallService         org.eclipse.kura.core.cloud(bid=111)
        32  Active      org.eclipse.kura.core.cloud.factory.DefaultCloudServiceFactory          org.eclipse.kura.core.cloud(bid=111)
        33  Unsatisfied     org.eclipse.kura.cloud.app.command.CommandCloudApp          org.eclipse.kura.core.cloud(bid=111)
        34  Unsatisfied     org.eclipse.kura.camel.cloud.factory.CamelFactory           org.eclipse.kura.camel.cloud.factory(bid=116)
        35  Active      org.eclipse.kura.camel.cloud.factory.CamelCloudServiceFactory           org.eclipse.kura.camel.cloud.factory(bid=116)
        36  Active      org.eclipse.kura.net.NetworkService         org.eclipse.kura.emulator.net(bid=120)
        37  Active      org.eclipse.kura.gpio.GPIOService           org.eclipse.kura.emulator.gpio(bid=125)
        38  Active      org.eclipse.kura.example.beacon.BeaconExample           org.eclipse.kura.example.beacon(bid=128)
        39  Active      org.eclipse.kura.usb.UsbService         org.eclipse.kura.emulator.usb(bid=131)
        40  Active      org.eclipse.kura.bluetooth.BluetoothService         org.eclipse.kura.l

Output of /var/log/kura.log: https://i.stack.imgur.com/F042L.jpg


来源: stackexchange

问:
I need help writing a complex SELECT statement
i am trying to write an sql statement that will select items from one table and order it by the result of the other table..

the 2 tables are:

events:
id, name

attendance:
user, event

ive got this statement:

```<code>SELECT *
FROM `attendance`
WHERE event='1'
  AND user IN (1,2,3,4,5,6,7,8,9,10,11,12,13,444,153)
</code>```

I am using this to get the number of friends that coming to event number 1.

now I want to combine that statement with another one to create a statement that select all the events, and order it by the number of friends that going...
how can i write that statement?

Thank you very much, Amir.

答:
Assuming that the list of numbers is the set of friends you're interested in (it would be better to store them in a table - that's how you record information in a database), then:

```<code>SELECT e.id, e.name, COUNT(*) AS friends
  FROM attendance AS a
  JOIN event      AS e ON a.event = e.id
 WHERE a.user IN (1,2,3,4,5,6,7,8,9,10,11,12,13,444,153)
 GROUP BY e.id, e.name;
</code>```

Complexity, of course, is in the eye of the beholder - this is not actually complex.  Note that as written, it does not list events to which none of the friends go.  If you want that, you need a LEFT OUTER JOIN and you need the 'friend filter' earlier than the main WHERE clause:

```<code>SELECT e.id, e.name, COUNT(user) AS friends
  FROM event AS e
  LEFT OUTER JOIN
       (SELECT user, event
          FROM attendance
         WHERE user IN (1,2,3,4,5,6,7,8,9,10,11,12,13,444,153)
       ) AS a
    ON a.event = e.id
 GROUP BY e.id, e.name;
</code>```

The COUNT(user) aggregate returns zero if all the rows in a group contain NULL in the user column.

Untested SQL.

ContentLicense: CC BY-SA 2.5

Body:
i am trying to write an sql statement that will select items from one table and order it by the result of the other table..

the 2 tables are:

events:
id, name

attendance:
user, event

ive got this statement:

SELECT *
FROM `attendance`
WHERE event='1'
  AND user IN (1,2,3,4,5,6,7,8,9,10,11,12,13,444,153)

I am using this to get the number of friends that coming to event number 1.

now I want to combine that statement with another one to create a statement that select all the events, and order it by the number of friends that going...
how can i write that statement?

Thank you very much, Amir.

Body:
Assuming that the list of numbers is the set of friends you're interested in (it would be better to store them in a table - that's how you record information in a database), then:

SELECT e.id, e.name, COUNT(*) AS friends
  FROM attendance AS a
  JOIN event      AS e ON a.event = e.id
 WHERE a.user IN (1,2,3,4,5,6,7,8,9,10,11,12,13,444,153)
 GROUP BY e.id, e.name;

Complexity, of course, is in the eye of the beholder - this is not actually complex.  Note that as written, it does not list events to which none of the friends go.  If you want that, you need a LEFT OUTER JOIN and you need the 'friend filter' earlier than the main WHERE clause:

SELECT e.id, e.name, COUNT(user) AS friends
  FROM event AS e
  LEFT OUTER JOIN
       (SELECT user, event
          FROM attendance
         WHERE user IN (1,2,3,4,5,6,7,8,9,10,11,12,13,444,153)
       ) AS a
    ON a.event = e.id
 GROUP BY e.id, e.name;

The COUNT(user) aggregate returns zero if all the rows in a group contain NULL in the user column.

Untested SQL.


问:
AngularJS ng-repeat grouped 2 dimensional
what I'm trying to do is using the ng-repeat directive to iterate some kind of 2 dimensional in angularjs

I have a long list, that I want to display in an html table with lets say 4 per row.

I'm currently using a somekind workaround to do this by doing so:

```<code><table>
    <tr>
        <td data-ng-repeat="x in my.list.slice(0, 4)">
           {{x}}
        </td>
    </tr>
    <tr>
        <td data-ng-repeat="x in my.list.slice(4, 8)">
           {{x}}
        </td>
    </tr>
    <tr>
        <td data-ng-repeat="x in my.list.slice(8, 12)">
           {{x}}
        </td>
    </tr>
    <tr>
        <!-- -->
    </tr>
</table>
</code>```

I'm wondering if there is somekind of itterating on
 but having everytime 4 *  ?

答:
I have one solution for you, might be better ones there but this will work fine.

First you make two dimensional array from your array (i.e. using reduce) and then just display it with ng-repeat on tr and td:

JS - I used simple 1,2,3,4,5,6,...etc. array:

```<code>let mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
$scope.mylist = mylist.reduce((prevVal, currVal, index) => {
    if (!prevVal[Math.floor(index / 4)]) {
      prevVal[Math.floor(index / 4)] = [];
    }
    prevVal[Math.floor(index / 4)].push(currVal);
    return prevVal;
  }, []);
</code>```

it might not look so nice but it does job very good and will create array of first four elements like [[1,2,3,4], [5,6,7,8]] basically grouping elements.

After that you just need to loop through entire list like here:

```<code><table>
      <tr ng-repeat="x in mylist">
        <td ng-repeat="num in x">
          {{num}}
        </td>
      </tr>
    </table>
</code>```

And you will get table of every fourth element in one table row.

Oh, forgot my fiddle: https://jsfiddle.net/pegla/b0pckLgh/

I hope this is helpful, Cheers.

ContentLicense: CC BY-SA 3.0

Body:
what I'm trying to do is using the ng-repeat directive to iterate some kind of 2 dimensional in angularjs

I have a long list, that I want to display in an html table with lets say 4 per row.

I'm currently using a somekind workaround to do this by doing so:

           {{x}}

           {{x}}

           {{x}}

I'm wondering if there is somekind of itterating on
 but having everytime 4 *  ?

Body:
I have one solution for you, might be better ones there but this will work fine.

First you make two dimensional array from your array (i.e. using reduce) and then just display it with ng-repeat on tr and td:

JS - I used simple 1,2,3,4,5,6,...etc. array:

let mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
$scope.mylist = mylist.reduce((prevVal, currVal, index) => {
    if (!prevVal[Math.floor(index / 4)]) {
      prevVal[Math.floor(index / 4)] = [];
    }
    prevVal[Math.floor(index / 4)].push(currVal);
    return prevVal;
  }, []);

it might not look so nice but it does job very good and will create array of first four elements like [[1,2,3,4], [5,6,7,8]] basically grouping elements.

After that you just need to loop through entire list like here:

<table>
      <tr ng-repeat="x in mylist">
        <td ng-repeat="num in x">
          {{num}}
        </td>
      </tr>
    </table>

And you will get table of every fourth element in one table row.

Oh, forgot my fiddle: https://jsfiddle.net/pegla/b0pckLgh/

I hope this is helpful, Cheers.


问:
MYSQL query that can group by the highest datetime from two rows that might have the same value but flip flopped
I have a MYSQL 5.x database that I can't change the schema, read only access:

```<code>SELECT * FROM table;

--------------------+------------+------------+---------
stamp               | src        | dst        | data
--------------------+------------+------------+---------
2017-12-06 11:08:39 | 2055551234 | 2059999999 | somedata
2017-12-04 16:04:14 | 2059999999 | 2055551234 | somedata
2017-12-04 14:28:21 | 2055551234 | 2059999999 | somedata
2017-12-04 14:26:24 | 8004441111 | 2562428766 | somedata
2017-12-04 14:06:22 | 2562428766 | 8004441111 | somedata
2017-12-04 13:15:52 | 8004441111 | 2562428766 | somedata
+---------------------+------------+------------+-------
</code>```

I need all rows that service sets of two numbers, for example 2055551234 and 2055551234, each can be SRC or DST.  I need the most recent row.

I need rows that contain both 2055551234 and 2055551234 but in either SRC or DST columns.  The values can be in either column and thus my problem.

Each of the matching SRC,DST sets has multiple rows, I need the row with the most recent datetime from each set.

I thought I had it outsmarted when I decided to try to create a hash with MD5(SRC+DST) which would also equal MD5(DST+SRC) but I got unreliable results.

There can be anywhere from 1 to thousands of groups of rows that have matching sets.

I need to be able to LIMIT the results so just iterating client side isn't going to work because of the unknown rows in each group.

I can't store any procedures, any iterating work will have to be done client side.

From the above data I would like:

```<code>--------------------+------------+------------+---------
stamp               | src        | dst        | data
--------------------+------------+------------+---------
2017-12-06 11:08:39 | 2055551234 | 2059999999 | somedata
2017-12-04 14:26:24 | 8004441111 | 2562428766 | somedata
+---------------------+------------+------------+-------
</code>```

Thoughts?

答:
Ah, now I think I got it. You are not looking for two particular numbers; you are looking for groups of rows that have the same number pair, no matter in what order. So get the lesser and the greater value and group.

```<code>select *
from mytable
where (least(src, dst), greatest(src, dst), stamp) in
(
  select least(src, dst), greatest(src, dst), max(stamp)
  from mytable
  group by least(src, dst), greatest(src, dst)
);
</code>```

SQL fiddle: http://sqlfiddle.com/#!9/5bed58/1

Body:
I have a MYSQL 5.x database that I can't change the schema, read only access:

SELECT * FROM table;

--------------------+------------+------------+---------
stamp               | src        | dst        | data
--------------------+------------+------------+---------
2017-12-06 11:08:39 | 2055551234 | 2059999999 | somedata
2017-12-04 16:04:14 | 2059999999 | 2055551234 | somedata
2017-12-04 14:28:21 | 2055551234 | 2059999999 | somedata
2017-12-04 14:26:24 | 8004441111 | 2562428766 | somedata
2017-12-04 14:06:22 | 2562428766 | 8004441111 | somedata
2017-12-04 13:15:52 | 8004441111 | 2562428766 | somedata
+---------------------+------------+------------+-------

I need all rows that service sets of two numbers, for example 2055551234 and 2055551234, each can be SRC or DST.  I need the most recent row.

I need rows that contain both 2055551234 and 2055551234 but in either SRC or DST columns.  The values can be in either column and thus my problem.

Each of the matching SRC,DST sets has multiple rows, I need the row with the most recent datetime from each set.

I thought I had it outsmarted when I decided to try to create a hash with MD5(SRC+DST) which would also equal MD5(DST+SRC) but I got unreliable results.

There can be anywhere from 1 to thousands of groups of rows that have matching sets.

I need to be able to LIMIT the results so just iterating client side isn't going to work because of the unknown rows in each group.

I can't store any procedures, any iterating work will have to be done client side.

From the above data I would like:

--------------------+------------+------------+---------
stamp               | src        | dst        | data
--------------------+------------+------------+---------
2017-12-06 11:08:39 | 2055551234 | 2059999999 | somedata
2017-12-04 14:26:24 | 8004441111 | 2562428766 | somedata
+---------------------+------------+------------+-------

Thoughts?

Body:
Ah, now I think I got it. You are not looking for two particular numbers; you are looking for groups of rows that have the same number pair, no matter in what order. So get the lesser and the greater value and group.

select *
from mytable
where (least(src, dst), greatest(src, dst), stamp) in
(
  select least(src, dst), greatest(src, dst), max(stamp)
  from mytable
  group by least(src, dst), greatest(src, dst)
);

SQL fiddle: http://sqlfiddle.com/#!9/5bed58/1


问:
Select elements of html table and change contents using jquery

Hello Professionals

I have a table in my asp.net page

Search Results : 25

          No.
          Album Name
          Year
          Artist

          1

             Al Muallim

          2003
          Sami Yusuf

          2

             Barakah

          2017
          Sami Yusuf

```
</div>
</div>
</p>

<p><br />
the table you see is an html template, it has 25 rows as you see in the <code><span></code> in the <code><h4></code> . <br /><br />
I get data of Albums by ajax and I want by jQuery to assign the values in there palces in the table. <br />
I am using a loop on the 25 rows, and for every row I must reach the <code><img></code> in the second <code><td></code> to change its <code>src</code> , same for the <code><spane></code> beside it to change the text inside it which is the album name.<br />
In the third <code><td></code> also to change the year in it .<br />
In the forth <code><td></code> I need to change the <code>href</code> of <code><a></code> and the text of <code><a></code> which is the name of the artist. <br />
Do you see that <code>id="a"</code> in the first <code><div></code>, this is because I have like this table for every letter in the alphabet, where the letter is the <code>id</code> for that table, <br /> and there is an A-ZList of the letters where a click on a letter wil make request to bring the albums with names start with the clicked letter, and assing them from the <code>XmlHttpRequest.responseText</code> to the table. <br />
Thats why I use <code>letter</code> variable in this jQuery code to pass the <code>id</code> of the first <code><div></code> to assign the values into the table , because there is another <code><div id="b"></code> and so on <br /></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>function AssignAlbumIntoDOM(albumName, albumYear, albumPhotoPath, artistName, albumsCount, i, letter) {
  if (i < 25 && i >= 0) { // keep calling until i is 25
    jQuery("#" + letter + " h4 span").text(albumsCount);
    jQuery("#" + letter + " table tbody").children().eq(i).children().eq(1).children().eq(0).children().eq(0).attr("src", albumPhotoPath);
    jQuery("#" + letter + " table tbody").children().eq(i).children().eq(2).text(albumYear);
    jQuery("#" + letter + " table tbody").children().eq(i).children().eq(3).children().eq(0).text(artistName);
  }
}</code>```

by the this code I can assing the albumYear in the third  and artistName in thr fourth ,
 but could not change in the second  the albumPhotoPath in  src and the albumName in the

Can I extend the question

This page as you see from the explanation, is a search page

And I have all the information of the album except the songs of the album, so how can I pass these information to a page called Single.aspx dedcated to show an album information and its songs after clicking the  in the second , and in the Single.aspx I only need by ajax to request the songs of the album not all the information again.

I think the passing will be as a QueryString in the href of  in the second , is there another way?

I thank you so much so much

答:
I noticed by the developer tools in Firefox that the javascript libraries in the html template are wrapping the the content of the second  in the table in a  that is why my first jQuery code did not work but after I modyfied it, it worked like this

if (i < 25 && i >= 0) { // keep calling until i is 25 means i:[0-24]
  jQuery("#" + letter + " h4 span").text(albumsCount);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(1).children().eq(0).children().eq(0).children().eq(0).attr("src", albumPhotoPath);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(1).children().eq(0).children().eq(0).children().eq(1).text(albumName);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(2).text(albumYear);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(3).children().eq(0).text(artistName);
  //jQuery("#" + letter + " h4 span").text(albumsCount);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(1) img").attr('src', albumPhotoPath);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(1) a span").text(albumName);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(2)").text(albumYear);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(3) a").text(artistName);
}```

here in the comments I tried Matt Spinks's answer with modification but I replaced :nth-child(1-based index) with :eq(0-based index)

Body:
Hello Professionals

I have a table in my asp.net page

Search Results : 25

          No.
          Album Name
          Year
          Artist

          1

             Al Muallim

          2003
          Sami Yusuf

          2

             Barakah

          2017
          Sami Yusuf

the table you see is an html template, it has 25 rows as you see in the  in the
 .

I get data of Albums by ajax and I want by jQuery to assign the values in there palces in the table.

I am using a loop on the 25 rows, and for every row I must reach the  in the second  to change its src , same for the <spane> beside it to change the text inside it which is the album name.

In the third  also to change the year in it .

In the forth  I need to change the href of  and the text of  which is the name of the artist.

Do you see that id="a" in the first
, this is because I have like this table for every letter in the alphabet, where the letter is the id for that table,
 and there is an A-ZList of the letters where a click on a letter wil make request to bring the albums with names start with the clicked letter, and assing them from the XmlHttpRequest.responseText to the table.

Thats why I use letter variable in this jQuery code to pass the id of the first
 to assign the values into the table , because there is another
 and so on

function AssignAlbumIntoDOM(albumName, albumYear, albumPhotoPath, artistName, albumsCount, i, letter) {
  if (i < 25 && i >= 0) { // keep calling until i is 25
    jQuery("#" + letter + " h4 span").text(albumsCount);
    jQuery("#" + letter + " table tbody").children().eq(i).children().eq(1).children().eq(0).children().eq(0).attr("src", albumPhotoPath);
    jQuery("#" + letter + " table tbody").children().eq(i).children().eq(2).text(albumYear);
    jQuery("#" + letter + " table tbody").children().eq(i).children().eq(3).children().eq(0).text(artistName);
  }
}

by the this code I can assing the albumYear in the third  and artistName in thr fourth ,
 but could not change in the second  the albumPhotoPath in  src and the albumName in the

Can I extend the question

This page as you see from the explanation, is a search page

And I have all the information of the album except the songs of the album, so how can I pass these information to a page called Single.aspx dedcated to show an album information and its songs after clicking the  in the second , and in the Single.aspx I only need by ajax to request the songs of the album not all the information again.

I think the passing will be as a QueryString in the href of  in the second , is there another way?

I thank you so much so much

Body:
I noticed by the developer tools in Firefox that the javascript libraries in the html template are wrapping the the content of the second <td> in the table in a <span> that is why my first jQuery code did not work but after I modyfied it, it worked like this

if (i < 25 && i >= 0) { // keep calling until i is 25 means i:[0-24]
  jQuery("#" + letter + " h4 span").text(albumsCount);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(1).children().eq(0).children().eq(0).children().eq(0).attr("src", albumPhotoPath);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(1).children().eq(0).children().eq(0).children().eq(1).text(albumName);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(2).text(albumYear);
  jQuery("#" + letter + " table tbody").children().eq(i).children().eq(3).children().eq(0).text(artistName);
  //jQuery("#" + letter + " h4 span").text(albumsCount);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(1) img").attr('src', albumPhotoPath);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(1) a span").text(albumName);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(2)").text(albumYear);
  //jQuery("#" + letter + "r" + (i + 1) + " td:eq(3) a").text(artistName);
}

here in the comments I tried Matt Spinks's answer with modification but I replaced :nth-child(1-based index) with :eq(0-based index)


问:
Laravel 5.5 form confirmed by password
Im making form via LaravelCollective forms in my app.
I have email changing form with fields:
New e-mail
Confirm Email
Password

I need to validate user password on this form with user password in database. Can i do it via Validate?

My form:

```<code>{{ Form::model($user, ['route' => ['profile.email.update']]) }}
<div class="form-group row">
    <div class="col-md-12">
        <h2>Edytuj email</h2>
        <div class="form-group">
            <label for="edit-page-email">Nowy adres email</label>

            {{Form::text('email',null,['class' => 'form-control', 'id'=>'edit-page-email'])}}
        </div>
        <div class="form-group">
            <label for="edit-page-repemail">Nowy adres email (powtórz)</label>
            {{Form::text('email_confirmation',null,['class' => 'form-control', 'id'=>'edit-page-email'])}}
        </div>
        <div class="form-group">
            <label for="edit-page-pass">Twoje hasło</label>
                {{Form::password('password',['class' => 'form-control', 'id'=>'edit-page-npass'])}}
        </div>
        <div class="col-md-12 text-center">
                {{Form::submit('Zapisz zmiany',['class' => 'btn btn-primary btm-sm']) }}
            <a href="#" class="btn btn-link btn-sm font-red" title="Anuluj">Anuluj</a>
        </div>
    </div>
</div>
{{Form::close()}}
</code>```

And validation is:

```<code> $request->validate([
            'email' => 'required|confirmed',
            'email_confirmation' => 'required',
            'password' => 'required|confirmed',
        ]);
</code>```

Any ideas how can i do this?

答:
No you cannot do this with built in validation rules of Laravel. Beside, you might already know that Laravel store password using bycrypt method. This is not just a plain string comparison operation too.

So, you need to write your own custom validation to check password, or you can just check password and return error if not matched instead of validation.

Note: The confirmed validation rule is to check one password is matched with another password filed or not. This is basically used to match two password form in single form. Not to check associated hashed password with the email in db.

Title: Laravel 5.5 form confirmed by password

Body:
Im making form via LaravelCollective forms in my app.
I have email changing form with fields:
New e-mail
Confirm Email
Password

I need to validate user password on this form with user password in database. Can i do it via Validate?

My form:

{{ Form::model($user, ['route' => ['profile.email.update']]) }}

Edytuj email

            Nowy adres email

            {{Form::text('email',null,['class' => 'form-control', 'id'=>'edit-page-email'])}}

            Nowy adres email (powtórz)
            {{Form::text('email_confirmation',null,['class' => 'form-control', 'id'=>'edit-page-email'])}}

            Twoje hasło
                {{Form::password('password',['class' => 'form-control', 'id'=>'edit-page-npass'])}}

                {{Form::submit('Zapisz zmiany',['class' => 'btn btn-primary btm-sm']) }}
            Anuluj

{{Form::close()}}

And validation is:

 $request->validate([
            'email' => 'required|confirmed',
            'email_confirmation' => 'required',
            'password' => 'required|confirmed',
        ]);

Any ideas how can i do this?


问:
How to use  & href tag in React-Router
I need to use an  in React Router in order to use Passport.js in my application for OAuthentication. Whenever I create an anchor tag and click it in React it just goes to a blank page in React Router and I don't even get the callback from my Node server on the backend with all the verification from Google/Facebook/Linkedin

What is a useful way to have an href tag in React-Router so that my backend can register it, go through its api flow with the callbacks, and then send it to the right place in React-Router?

The problem is this

The Problem of using axios.get() for OAuthentication with Passport.js

EDIT

In this post they have the same problem that I do and the solution was just a simple href tag, however I have react-router on my application and its possible they did not, also they have no example

Previous post about Authentication with Passport.js with React front

EDIT

I am moving this project from jQuery focused to React, React-Router and Redux so a majority of my server-side Node code didn't need updating but here is ther part of my routes that handles the OAuth with Passport. I just need my front to reach this, let it do its thing and then send back to me

```<code>router.get('/linkedin', passport.authenticate('linkedin'),
    function(req, res){
      console.log('nexted')
    }
  );

  router.get('/linkedin/callback',
      passport.authenticate('linkedin', { failureRedirect: '/index' }),
    function(req, res) {
      console.log('here')
      res.redirect('/professionals');
  });
</code>```

答:
I noticed in the comments that you mention having CORS problems, if I'm right I believe you are using the authorization code grant OAuth flow, I had the same issue with GitHub when I had my SPA and my backend in different servers. If this is the case serve the static files of the SPA through the backend server. If you do this you should put the code below as your last route in order for React Router to work. You can find a repo where I did the same here

```<code>app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname + '/client/index.html'));
});
</code>```

Note: If you don't want to do this you can use the implicit grant OAuth flow, and make the authentication in the SPA.

Title: How to use <a> & href tag in React-Router

Body:
I need to use an  in React Router in order to use Passport.js in my application for OAuthentication. Whenever I create an anchor tag and click it in React it just goes to a blank page in React Router and I don't even get the callback from my Node server on the backend with all the verification from Google/Facebook/Linkedin

What is a useful way to have an href tag in React-Router so that my backend can register it, go through its api flow with the callbacks, and then send it to the right place in React-Router?

The problem is this

The Problem of using axios.get() for OAuthentication with Passport.js

EDIT

In this post they have the same problem that I do and the solution was just a simple href tag, however I have react-router on my application and its possible they did not, also they have no example

Previous post about Authentication with Passport.js with React front

EDIT

I am moving this project from jQuery focused to React, React-Router and Redux so a majority of my server-side Node code didn't need updating but here is ther part of my routes that handles the OAuth with Passport. I just need my front to reach this, let it do its thing and then send back to me

router.get('/linkedin', passport.authenticate('linkedin'),
    function(req, res){
      console.log('nexted')
    }
  );

  router.get('/linkedin/callback',
      passport.authenticate('linkedin', { failureRedirect: '/index' }),
    function(req, res) {
      console.log('here')
      res.redirect('/professionals');
  });

Body:
I noticed in the comments that you mention having CORS problems, if I'm right I believe you are using the authorization code grant OAuth flow, I had the same issue with GitHub when I had my SPA and my backend in different servers. If this is the case serve the static files of the SPA through the backend server. If you do this you should put the code below as your last route in order for React Router to work. You can find a repo where I did the same here

app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname + '/client/index.html'));
});

Note: If you don't want to do this you can use the implicit grant OAuth flow, and make the authentication in the SPA.


问:
GORM prevent creation of a foreign key constraint for a Domain
I am developing a web based application in Grails. I have come across a situation where I would like to try and suppress GORM from creating a foreign key constraint on a field in a table.

I have a domain class which is part of a class hierarchy. The domain class essentially acts as a link to a target domain. The target domain can be of different types and each of the subclasses of this link domain is designed to provide the link for each specific type of linked item. These linked items have certain behaviour in common i.e. implement the same interface but otherwise are different to the point that they are stored in different tables.

Within this link domain table there is one column which represents the id of the item being linked to. All the linked items have the same integer based id. The problem is that GORM tries to create multiple foreign key constraints of this same table column, one for each of the link domain subclasses which represents a different type of linked item. I know I could have separate columns for the id of each time where the other id columns would be null but this seems kind of messy. If there were a way to just tell GORM I don't want it to create a foreign key constraint on that column (because different foreign keys use the same column) that would solve the problem.

I know that the question comes up of referential integrity and whether a link key value  could be put in the column which does not exist in the foreign table but the application should prevent this situation from occurring.

failing this then I would have to deal with loading the linked item manually and not rely on GORM to do it automatically.

答:
have you looked at this section of the documentation

http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20(GORM).html#5.5.2 Custom ORM Mapping

you can override grails's default persistence semantics by using the custom mapping DSL.


问:
What is the best way pull updated changes into the Docker containers that already deployed?
I had to perform these steps to deploy my Nodejs/Angular site to AWS via DockerCloud

Write Dockerfile

Build Docker Images base on my Dockerfiles

Push those images to Docker Hub

Create Node Cluster on DockerCloud Account

Write Docker stack file on DockerCloud

Run the stack on DockerCloud

See the instance running in AWS, and can see my site

If we require a small thing changes that require a pull from my project repo.
BUT we already deployed our dockers as you may know.

What is the best way pull those changes into the Docker containers that already deployed ?

I hope we don’t have to :

Rebuild our Docker Images

Re-push those images to Docker Hub

Re-create our Node Cluster on DockerCloud

Re-write our docker stack file on DockerCloud

Re-run the stack on DockerCloud

I was thinking

SSH into a VM that has the Docker running

```<code>git pull
npm start
</code>```

Am I on the right track?

答:
If you want to treat a Docker container as a VM, you totally can, however, I would strongly caution against this. Anything in a container is ephemeral...if you make changes to files in it and the container goes down, it will not come back up with the changes.

That said, if you have access to the server you can exec into the container and execute whatever commands you want. Usually helpful for dev, but applicable to any container.

This command will start an interactive bash session inside your desired container. See the docs for more info.

docker exec -it <container_name> bash

Best practice would probably be to update the docker image and redeploy it.

Body:
I had to perform these steps to deploy my Nodejs/Angular site to AWS via DockerCloud

Write Dockerfile

Build Docker Images base on my Dockerfiles

Push those images to Docker Hub

Create Node Cluster on DockerCloud Account

Write Docker stack file on DockerCloud

Run the stack on DockerCloud

See the instance running in AWS, and can see my site

If we require a small thing changes that require a pull from my project repo.
BUT we already deployed our dockers as you may know.

What is the best way pull those changes into the Docker containers that already deployed ?

I hope we don’t have to :

Rebuild our Docker Images

Re-push those images to Docker Hub

Re-create our Node Cluster on DockerCloud

Re-write our docker stack file on DockerCloud

Re-run the stack on DockerCloud

I was thinking

SSH into a VM that has the Docker running

git pull
npm start

Am I on the right track?


问:
Randomly remove image from game space without using class in JavaScript/jQuery

I am trying to have the Moles (little cubes in https://jsfiddle.net/JennyF/s4rteuks/13/) randomly disappear form the #gamespace if they are not clicked on. They randomly appear between 0 - 2 seconds. The game is working on Firefox without this question addressed while including my attempt, but it is not working in JSFiddle.

```<code>      function addMole(){
        xPos=randPosX();
        yPos=randPosY();
        $("#gamespace").append('<img src="img/mole.png" style="top:'+xPos+'px; left:'+yPos+'px;" />');
        var r=Math.floor(Math.random()*(2000));
        t=setTimeout("addMole();", r);
        var count=0;
        setTimeout("remove()", 1000);
        function remove(){
            $("#gamespace").append("<img id='img"+count+"'></img>");
            count++;
            setTimeout("remove()", 1000);
        };
    };//end mole
</code>```

My instructor told us not to use a class and gave us this example. Obviously, I want to fadeOut instead of add anything. And I don't have any
 tags. I just don't know what to put in their place. Or if I totally messed it up.

```<code>var count=0;
setTimeout("add()", 1000);
function add(){
$("div#div1").append("<p id='p"+count+"'></p>");
count++;
  setTimeout("add()", 1000);}
</code>```

答:
Well, here is the corrected code and my jsfiddle https://jsfiddle.net/JennyF/s4rteuks/14/, which doesn't work, it works in my program, though. I don't know what I'm doing wrong in jsfiddle. I copied everything exactly and attached the right jQuery library. </p>

```<code>    function addMole(){
        if (time_left >0){
            xPos=randPosX();
            yPos=randPosY();
            $("#gamespace").append('<img id='+count+' src="img/mole.png" style="top:'+xPos+'px; left:'+yPos+'px;" />');
            var f='#'+count;
            count++;
            $("#gamespace").find(f).delay(1500).fadeOut();
            var r=Math.floor(Math.random()*(2000));
            t=setTimeout("addMole();", r);
            }else{
                clearTimeout(t);
                $("#gamespace").off("click", "img");
            };//end if
    };//end mole
</code>```

Body:
I am trying to have the Moles (little cubes in https://jsfiddle.net/JennyF/s4rteuks/13/) randomly disappear form the #gamespace if they are not clicked on. They randomly appear between 0 - 2 seconds. The game is working on Firefox without this question addressed while including my attempt, but it is not working in JSFiddle.

      function addMole(){
        xPos=randPosX();
        yPos=randPosY();
        $("#gamespace").append('');
        var r=Math.floor(Math.random()*(2000));
        t=setTimeout("addMole();", r);
        var count=0;
        setTimeout("remove()", 1000);
        function remove(){
            $("#gamespace").append("");
            count++;
            setTimeout("remove()", 1000);
        };
    };//end mole

My instructor told us not to use a class and gave us this example. Obviously, I want to fadeOut instead of add anything. And I don't have any
 tags. I just don't know what to put in their place. Or if I totally messed it up.

var count=0;
setTimeout("add()", 1000);
function add(){
$("div#div1").append("

");
count++;
  setTimeout("add()", 1000);}

Body:
Well, here is the corrected code and my jsfiddle https://jsfiddle.net/JennyF/s4rteuks/14/, which doesn't work, it works in my program, though. I don't know what I'm doing wrong in jsfiddle. I copied everything exactly and attached the right jQuery library.

    function addMole(){
        if (time_left >0){
            xPos=randPosX();
            yPos=randPosY();
            $("#gamespace").append('<img id='+count+' src="img/mole.png" style="top:'+xPos+'px; left:'+yPos+'px;" />');
            var f='#'+count;
            count++;
            $("#gamespace").find(f).delay(1500).fadeOut();
            var r=Math.floor(Math.random()*(2000));
            t=setTimeout("addMole();", r);
            }else{
                clearTimeout(t);
                $("#gamespace").off("click", "img");
            };//end if
    };//end mole


问:
Using Switch-blocks to Parse input for a Text Adventure?
Okay, I have a goal right now to make a basic text adventure. To do this, however, I would need/want to have a switch statement that can do the following:

Check to see if a string has a word SOMEWHERE inside.

Check to see if a string has two words in any combination somewhere inside.

How would I accomplish this? Could you show me coding for this specific example:

A user is prompted for data. A switch statement checks for "look box" as one case, and "sleep" as another. The program doesn't care what order any words are in, but does care about the order of the letters.

Please explain everything in detail. I just started coding.

EDIT: Thank you for all the answers. I understand there are better, more complicated, and more useful ways of handling this, but it just isn't at my level yet.

答:
You can’t use switch for this directly, but then again, I think you shouldn’t. You should probably have the logic that finds the words in a different place than the logic that contains the switch.

Consider using an enum to contain all the possible actions:

```<code>public enum AdventureAction
{
    LookBox,
    Sleep
}
</code>```

Consider writing a method that does the “parsing”:

```<code>public static AdventureAction Parse(string text)
{
    if (text.Contains("look") && text.Contains("box"))
        return AdventureAction.LookBox;

    if (text.Contains("sleep"))
        return AdventureAction.Sleep;
}
</code>```

And then you can use a simple switch statement to perform the action:

```<code>var action = Parse(input);
switch (action)
{
    case AdventureAction.LookBox:
        // do something interesting with the box
        break;

    case AdventureAction.Sleep:
        // go to sleep
        break;
}
</code>```

Body:
You can’t use switch for this directly, but then again, I think you shouldn’t. You should probably have the logic that finds the words in a different place than the logic that contains the switch.

Consider using an enum to contain all the possible actions:

public enum AdventureAction
{
    LookBox,
    Sleep
}

Consider writing a method that does the “parsing”:

public static AdventureAction Parse(string text)
{
    if (text.Contains("look") && text.Contains("box"))
        return AdventureAction.LookBox;

    if (text.Contains("sleep"))
        return AdventureAction.Sleep;
}

And then you can use a simple switch statement to perform the action:

var action = Parse(input);
switch (action)
{
    case AdventureAction.LookBox:
        // do something interesting with the box
        break;

    case AdventureAction.Sleep:
        // go to sleep
        break;
}


问:
Can the time stamp of a Retweet be accessed?
I'm trying to use the Twitter API: GET statuses/retweets/:id
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweets-id

It doesn't seem like the API returns the time a Tweet was retweeted. It only shows when it was created. Is this true? And if so, is there any other way of being able to retrieve the retweet timestamp?

答:
From Introduction to Tweet JSON:

If you are working with a Retweet object, then that object will contain two Tweet objects, complete with two User objects.  The Tweet that was Retweeted is referred to as the 'original' Tweet and is displayed under the 'retweeted_status' key. If a Retweet gets Retweeted, the 'retweet_status' will still point to the original Tweet, meaning the intermediate Retweet is not included.

The top-level created_at attribute should be the time of the retweet that you're looking for. The original tweet is embedded inside the retweet object as the retweeted_status and it has its own (earlier) timestamp.


问:
VB6 Converting a fraction to a decimal and a decimal to fraction
There's a few posts on this, but none seem to provide a whole code solution, so I'm posting this up, which is culled (and credited where appropriate) from various bits and pieces of ideas on the Internet. VB6 doesn't have any function to convert from a fraction to a decimal number, which I needed for a project that I was working on which was concerned with meal recipes. I considered writing a DLL in .NET and plugging it into my application, but decided on this approach in the end. I hope this is useful for others. The solution below will do the following:

You supply a decimal number and you will be returned the fraction as a string.

You supply a fraction as a string and you will be returned with the decimal number.

In both cases, whole numbers are accounted for eg. "2 3/4" (two and three quarters) or "2.75".

I'm sure the code is not efficient, so any improvements are welcome.

答:
Copy/Paste this as a new Class module:

```<code>Option Explicit

Private ErrorNote As String

'Properties
Public Property Get GetAsFraction(numToConvert As Double) As String

        On Error GoTo GetAsFraction_Error

        GetAsFraction = FncGetAsFraction(numToConvert)

        On Error GoTo 0

        Exit Property

GetAsFraction_Error:

        ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'GetAsFraction' in 'ClsFractionDecimal'"
        MsgBox (ErrorNote)

End Property

Public Property Get GetAsDecimal(fractionString As String) As Double

        On Error GoTo GetAsDecimal_Error

        GetAsDecimal = FncGetAsDecimal(fractionString)

        On Error GoTo 0

        Exit Property

GetAsDecimal_Error:

        ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'GetAsDecimal' in 'ClsFractionDecimal'"
        MsgBox (ErrorNote)

End Property

'Functions - private
Private Function FncGetAsDecimal(fractionToConvert As String) As Double

        Dim result As Double
        Dim wholeNumber As Integer
        Dim splitStr As Variant
        Dim numerator As Integer
        Dim denominator As Integer
        Dim fractionString As String
        Dim dividedByPos As Integer

        On Error GoTo FncGetAsDecimal_Error

        splitStr = Split(fractionToConvert, " ")

        If UBound(splitStr) = 1 Then

            wholeNumber = splitStr(0)
            fractionString = splitStr(1)

        Else

            fractionString = splitStr(0)

        End If

        dividedByPos = InStr(1, fractionString, "/")

        numerator = Left(fractionString, dividedByPos - 1)
        denominator = Mid(fractionString, dividedByPos + 1)

        result = Val(numerator) / Val(denominator) + wholeNumber

       FncGetAsDecimal = result

       On Error GoTo 0

       Exit Function

FncGetAsDecimal_Error:

       ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncGetAsDecimal' in 'ClsFractionDecimal'"
       MsgBox (ErrorNote)

End Function

Private Function FncGetAsFraction(numToConvert As Double) As String

        Dim result As String
        Dim numeratorCount As Integer
        Dim denominator As Single
        Dim multiplierStr As String
        Dim i As Integer
        Dim fractionNum As Single
        Dim lowestCommonDenominator As Long
        Dim wholeNumber As Integer
        Dim decimalPos As Integer

        On Error GoTo FncGetAsFraction_Error

        If numToConvert > 0 Then

            decimalPos = InStr(1, CStr(numToConvert), ".")

            If decimalPos > 1 Then

                wholeNumber = CStr(Mid(numToConvert, 1, decimalPos - 1))
                numToConvert = CStr(Mid(numToConvert, decimalPos))

            End If

            numeratorCount = FncCountDecimalPlaces(numToConvert)
            multiplierStr = "1"

           For i = 1 To numeratorCount

               multiplierStr = multiplierStr & "0"

           Next i

           fractionNum = numToConvert * Val(multiplierStr)
           denominator = 1 * Val(multiplierStr)

               result = FncCrunchFraction(fractionNum, denominator)
               If result = "" Then result = fractionNum & "/" & denominator
               If wholeNumber <> 0 Then result = wholeNumber & " " & result

       Else

           result = "ERROR"

       End If

       FncGetAsFraction = result

       On Error GoTo 0

       Exit Function

FncGetAsFraction_Error:

       ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncGetAsFraction' in 'ClsFractionDecimal'"
       MsgBox (ErrorNote)

End Function

Private Function FncCountDecimalPlaces(num As Double) As Integer

        Dim result As Integer
        Dim numberStr As String
        Dim i As Integer
        Dim decimalPointPos As Integer

        On Error GoTo FncCountDecimalPlaces_Error

        numberStr = CStr(num)

        If Len(numberStr) > 0 Then

            i = 1

            Do While i <= Len(numberStr) And decimalPointPos = 0

                If Mid(numberStr, i, 1) = "." Then decimalPointPos = i
                i = i + 1

            Loop

        End If

        If i > 1 Then

           result = (Len(numberStr) - i + 1)

       End If

       FncCountDecimalPlaces = result

       On Error GoTo 0

       Exit Function

FncCountDecimalPlaces_Error:

       ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncCountDecimalPlaces' in 'ClsFractionDecimal'"
       MsgBox (ErrorNote)

End Function

'Credit to:
'http://www.tek-tips.com/viewthread.cfm?qid=206890
'dsi (Programmer) - 7 Feb 02 10:38
Private Function FncCrunchFraction(num1 As Single, num2 As Single) As String

        Dim num As Single
        Dim dem As Single
        Dim cnt1 As Integer
        Dim cnt2 As Integer
        Dim numFactors() As Single
        Dim demFactors() As Single
        Dim common As Single
        Dim i As Integer
        Dim j As Integer

        On Error GoTo FncCrunchFraction_Error

        num = num1
        dem = num2

        For i = 2 To Int(num / 2) Step 1

            If (num Mod i = 0) Then

                cnt1 = cnt1 + 1
                ReDim Preserve numFactors(1 To cnt1)
                numFactors(cnt1) = i

            End If

        Next i

        cnt1 = cnt1 + 1

        ReDim Preserve numFactors(1 To cnt1)
       numFactors(cnt1) = num

       For i = 2 To Int(dem / 2) Step 1

           If (dem Mod i = 0) Then

                cnt2 = cnt2 + 1
                ReDim Preserve demFactors(1 To cnt2)
                demFactors(cnt2) = i

            End If

        Next i

        cnt2 = cnt2 + 1
        ReDim Preserve demFactors(1 To cnt2)
        demFactors(cnt2) = dem

        For i = cnt1 To 1 Step -1

            For j = cnt2 To 1 Step -1

                If (numFactors(i) = demFactors(j)) Then

                    common = numFactors(i)
                    FncCrunchFraction = num / common & "/" & dem / common
                    Exit Function

                End If

            Next j

        Next i

        FncCrunchFraction = ""

        On Error GoTo 0

        Exit Function

FncCrunchFraction_Error:

        ErrorNote = "Line:" & Erl & " Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncCrunchFraction' in 'ClsFractionDecimal'"
        MsgBox (ErrorNote)

End Function
</code>```

Then call it with these code examples:

```<code>    Public Function DecimalToFraction(number As Double) As String

    Dim myFractionDecimal As New ClsFractionDecimal

    DecimalToFraction = myFractionDecimal.GetAsFraction(number)

    Set myFractionDecimal = Nothing

End Function

Public Function FractionToDecimal(fractionString As String) As Double

    Dim myFractionDecimal As New ClsFractionDecimal

    FractionToDecimal = myFractionDecimal.GetAsDecimal(fractionString)

    Set myFractionDecimal = Nothing

End Function
</code>```

Body:
Copy/Paste this as a new Class module:

Option Explicit

Private ErrorNote As String

'Properties
Public Property Get GetAsFraction(numToConvert As Double) As String

        On Error GoTo GetAsFraction_Error

        GetAsFraction = FncGetAsFraction(numToConvert)

        On Error GoTo 0

        Exit Property

GetAsFraction_Error:

        ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'GetAsFraction' in 'ClsFractionDecimal'"
        MsgBox (ErrorNote)

End Property

Public Property Get GetAsDecimal(fractionString As String) As Double

        On Error GoTo GetAsDecimal_Error

        GetAsDecimal = FncGetAsDecimal(fractionString)

        On Error GoTo 0

        Exit Property

GetAsDecimal_Error:

        ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'GetAsDecimal' in 'ClsFractionDecimal'"
        MsgBox (ErrorNote)

End Property

'Functions - private
Private Function FncGetAsDecimal(fractionToConvert As String) As Double

        Dim result As Double
        Dim wholeNumber As Integer
        Dim splitStr As Variant
        Dim numerator As Integer
        Dim denominator As Integer
        Dim fractionString As String
        Dim dividedByPos As Integer

        On Error GoTo FncGetAsDecimal_Error

        splitStr = Split(fractionToConvert, " ")

        If UBound(splitStr) = 1 Then

            wholeNumber = splitStr(0)
            fractionString = splitStr(1)

        Else

            fractionString = splitStr(0)

        End If

        dividedByPos = InStr(1, fractionString, "/")

        numerator = Left(fractionString, dividedByPos - 1)
        denominator = Mid(fractionString, dividedByPos + 1)

        result = Val(numerator) / Val(denominator) + wholeNumber

       FncGetAsDecimal = result

       On Error GoTo 0

       Exit Function

FncGetAsDecimal_Error:

       ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncGetAsDecimal' in 'ClsFractionDecimal'"
       MsgBox (ErrorNote)

End Function

Private Function FncGetAsFraction(numToConvert As Double) As String

        Dim result As String
        Dim numeratorCount As Integer
        Dim denominator As Single
        Dim multiplierStr As String
        Dim i As Integer
        Dim fractionNum As Single
        Dim lowestCommonDenominator As Long
        Dim wholeNumber As Integer
        Dim decimalPos As Integer

        On Error GoTo FncGetAsFraction_Error

        If numToConvert > 0 Then

            decimalPos = InStr(1, CStr(numToConvert), ".")

            If decimalPos > 1 Then

                wholeNumber = CStr(Mid(numToConvert, 1, decimalPos - 1))
                numToConvert = CStr(Mid(numToConvert, decimalPos))

            End If

            numeratorCount = FncCountDecimalPlaces(numToConvert)
            multiplierStr = "1"

           For i = 1 To numeratorCount

               multiplierStr = multiplierStr & "0"

           Next i

           fractionNum = numToConvert * Val(multiplierStr)
           denominator = 1 * Val(multiplierStr)

               result = FncCrunchFraction(fractionNum, denominator)
               If result = "" Then result = fractionNum & "/" & denominator
               If wholeNumber <> 0 Then result = wholeNumber & " " & result

       Else

           result = "ERROR"

       End If

       FncGetAsFraction = result

       On Error GoTo 0

       Exit Function

FncGetAsFraction_Error:

       ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncGetAsFraction' in 'ClsFractionDecimal'"
       MsgBox (ErrorNote)

End Function

Private Function FncCountDecimalPlaces(num As Double) As Integer

        Dim result As Integer
        Dim numberStr As String
        Dim i As Integer
        Dim decimalPointPos As Integer

        On Error GoTo FncCountDecimalPlaces_Error

        numberStr = CStr(num)

        If Len(numberStr) > 0 Then

            i = 1

            Do While i <= Len(numberStr) And decimalPointPos = 0

                If Mid(numberStr, i, 1) = "." Then decimalPointPos = i
                i = i + 1

            Loop

        End If

        If i > 1 Then

           result = (Len(numberStr) - i + 1)

       End If

       FncCountDecimalPlaces = result

       On Error GoTo 0

       Exit Function

FncCountDecimalPlaces_Error:

       ErrorNote = "Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncCountDecimalPlaces' in 'ClsFractionDecimal'"
       MsgBox (ErrorNote)

End Function

'Credit to:
'http://www.tek-tips.com/viewthread.cfm?qid=206890
'dsi (Programmer) - 7 Feb 02 10:38
Private Function FncCrunchFraction(num1 As Single, num2 As Single) As String

        Dim num As Single
        Dim dem As Single
        Dim cnt1 As Integer
        Dim cnt2 As Integer
        Dim numFactors() As Single
        Dim demFactors() As Single
        Dim common As Single
        Dim i As Integer
        Dim j As Integer

        On Error GoTo FncCrunchFraction_Error

        num = num1
        dem = num2

        For i = 2 To Int(num / 2) Step 1

            If (num Mod i = 0) Then

                cnt1 = cnt1 + 1
                ReDim Preserve numFactors(1 To cnt1)
                numFactors(cnt1) = i

            End If

        Next i

        cnt1 = cnt1 + 1

        ReDim Preserve numFactors(1 To cnt1)
       numFactors(cnt1) = num

       For i = 2 To Int(dem / 2) Step 1

           If (dem Mod i = 0) Then

                cnt2 = cnt2 + 1
                ReDim Preserve demFactors(1 To cnt2)
                demFactors(cnt2) = i

            End If

        Next i

        cnt2 = cnt2 + 1
        ReDim Preserve demFactors(1 To cnt2)
        demFactors(cnt2) = dem

        For i = cnt1 To 1 Step -1

            For j = cnt2 To 1 Step -1

                If (numFactors(i) = demFactors(j)) Then

                    common = numFactors(i)
                    FncCrunchFraction = num / common & "/" & dem / common
                    Exit Function

                End If

            Next j

        Next i

        FncCrunchFraction = ""

        On Error GoTo 0

        Exit Function

FncCrunchFraction_Error:

        ErrorNote = "Line:" & Erl & " Number:" & Err.number & " (" & Err.Description & ") in procedure 'FncCrunchFraction' in 'ClsFractionDecimal'"
        MsgBox (ErrorNote)

End Function

Then call it with these code examples:

    Public Function DecimalToFraction(number As Double) As String

    Dim myFractionDecimal As New ClsFractionDecimal

    DecimalToFraction = myFractionDecimal.GetAsFraction(number)

    Set myFractionDecimal = Nothing

End Function

Public Function FractionToDecimal(fractionString As String) As Double

    Dim myFractionDecimal As New ClsFractionDecimal

    FractionToDecimal = myFractionDecimal.GetAsDecimal(fractionString)

    Set myFractionDecimal = Nothing

End Function


问:
Python requests send text with binary data
I'm trying to send both binary data and a text string (or any other normal variable) between servers using python's requests library.

I have two servers talking to each other.  Server A sends a GET request via python's requests library.  It looks something like this:

```<code>color, file_data = requests.get('https://www.serverb.com/testing', params = {...})
</code>```

Server B then does something like:

```<code>var1 = request.args.get('var1')
var2 = request.args.get('var2')

# This function creates a binary file, saves it to disk, and returns the file name.
res = some_function(var1, var2)

file_data = codecs.open(res, 'rb').read()

return 'Success!', file_data
</code>```

However, when I attempt this, Server B throws a 500 error.

Is what I'm attempting to do impossible?  If I can only send back the binary data, but with custom headers, that would work as well, and help on how to set those up would be appreciated.

Thanks in advance.

答:
An HTTP response looks like this:

```<code>HTTP/1.1 200 OK
<headers>
<blank line>
<response body>
</code>```

The <blank line> generally contains these characters - \r\n, also known as CRLF.

So, when a server sends a response, the client (or browser) can differentiate from the headers and the response body by looking at the <blank line>. So, anything after <blank line> is treated as the response body.

What that means is, there can be at most 1 response body only. So, even if you think you're sending color and file_data separately like you're doing, they're still going in one response and the client will treat them as a single body.

What you can do to get around this?

You'll need a way to know which part of the response body is the color and which is file_data. You can do that by sending a custom header along with the response.

Let's say, your response looks like this:

```<code>HTTP/1.1 200 OK
<headers>
<blank line>
<color><file_data>
</code>```

Now, you can set a custom header on your response which will tell you how many bytes are there of the color variable.

For example, if the value of color is yellow and it's 6 characters, that means it has 6 bytes. So, you can set a custom header that would tell you the total length of color:

```<code>HTTP/1.1 200 OK
<headers>
X-Color-Length: 6
<blank line>
<color><file_data>
</code>```

Then, in your client side, you can get the total bytes from the X-Color-Length header and read that number of bytes from the body to get the value of the color. Example:

```<code>response = requests.get(...)

color_len = response.headers['X-Color-Length']

color = response.content[:color_len]
file_data = response.content[color_len:]
</code>```

UPDATE: Now that I think about it, I've made this a little more complex than it should be. You can just send the color's value directly in a header like X-Color: <color>, instead of the number of bytes it has.

Body:
I'm trying to send both binary data and a text string (or any other normal variable) between servers using python's requests library.

I have two servers talking to each other.  Server A sends a GET request via python's requests library.  It looks something like this:

color, file_data = requests.get('https://www.serverb.com/testing', params = {...})

Server B then does something like:

var1 = request.args.get('var1')
var2 = request.args.get('var2')

# This function creates a binary file, saves it to disk, and returns the file name.
res = some_function(var1, var2)

file_data = codecs.open(res, 'rb').read()

return 'Success!', file_data

However, when I attempt this, Server B throws a 500 error.

Is what I'm attempting to do impossible?  If I can only send back the binary data, but with custom headers, that would work as well, and help on how to set those up would be appreciated.

Thanks in advance.

Body:
An HTTP response looks like this:

HTTP/1.1 200 OK
<headers>
<blank line>
<response body>

The <blank line> generally contains these characters - \r\n, also known as CRLF.

So, when a server sends a response, the client (or browser) can differentiate from the headers and the response body by looking at the <blank line>. So, anything after <blank line> is treated as the response body.

What that means is, there can be at most 1 response body only. So, even if you think you're sending color and file_data separately like you're doing, they're still going in one response and the client will treat them as a single body.

What you can do to get around this?

You'll need a way to know which part of the response body is the color and which is file_data. You can do that by sending a custom header along with the response.

Let's say, your response looks like this:

HTTP/1.1 200 OK
<headers>
<blank line>
<color><file_data>

Now, you can set a custom header on your response which will tell you how many bytes are there of the color variable.

For example, if the value of color is yellow and it's 6 characters, that means it has 6 bytes. So, you can set a custom header that would tell you the total length of color:

HTTP/1.1 200 OK
<headers>
X-Color-Length: 6
<blank line>
<color><file_data>

Then, in your client side, you can get the total bytes from the X-Color-Length header and read that number of bytes from the body to get the value of the color. Example:

response = requests.get(...)

color_len = response.headers['X-Color-Length']

color = response.content[:color_len]
file_data = response.content[color_len:]

UPDATE: Now that I think about it, I've made this a little more complex than it should be. You can just send the color's value directly in a header like X-Color: <color>, instead of the number of bytes it has.

ContentLicense: CC BY-SA 4.0


问:
Base operand of '->' has non-pointer type vector<object*>
```<code>std::vector<Piece*> player1, player2;

/* Filling player 1 and 2 vith piece
   player1.push_back(new Piece()) */

std::vector<Piece*> *currentPlayer, *opponent;

currentPlayer = &player1;
opponent      = &player2

for(int i = 0; i < currentPlayer.size(); ++i)
{
    // This is where i get the error
    // error: base operand of '->' has non-pointer type 'std::vector<Piece*>'
    currentPlayer[i]->memberFunctionOfPiece()
}
</code>```

As you can see I am trying to use a pointer pointing to a vector of pointers. but getting non-pointer type when trying to access the vector
Why can't i access the member function?

答:
You could also use ranged for loop on STL containers</p>

```<code>for(auto&& player : *currentPlayer)
{
    player->memberFunctionOfPiece();
}
</code>```

Body:
std::vector<Piece*> player1, player2;

/* Filling player 1 and 2 vith piece
   player1.push_back(new Piece()) */

std::vector<Piece*> *currentPlayer, *opponent;

currentPlayer = &player1;
opponent      = &player2

for(int i = 0; i < currentPlayer.size(); ++i)
{
    // This is where i get the error
    // error: base operand of '->' has non-pointer type 'std::vector<Piece*>'
    currentPlayer[i]->memberFunctionOfPiece()
}

As you can see I am trying to use a pointer pointing to a vector of pointers. but getting non-pointer type when trying to access the vector
Why can't i access the member function?

Body:
You could also use ranged for loop on STL containers

for(auto&& player : *currentPlayer)
{
    player->memberFunctionOfPiece();
}


问:
Unable to get numbers from window.location.search
I am using the following code in my JS file:

```<code>var match = window.location.search.match(/(\d*)/);
this.room = (match) ? decodeURIComponent(match) : 0;
</code>```

And I am trying to just get the numbers from my URL. For example, in www.myurl.com/streams228, I just want to get the 228.

The issue I am getting is it is just returning %2, nothing else, or 0.

答:
Try to match the pathname. The search refers to the query string.

```<code>window.location.pathname.match(/(\d*)/)
</code>```

Body:
I am using the following code in my JS file:

var match = window.location.search.match(/(\d*)/);
this.room = (match) ? decodeURIComponent(match) : 0;

And I am trying to just get the numbers from my URL. For example, in www.myurl.com/streams228, I just want to get the 228.

The issue I am getting is it is just returning %2, nothing else, or 0.

Body:
Try to match the pathname. The search refers to the query string.

window.location.pathname.match(/(\d*)/)


问:
C++ subclassing access modifier?
I'm C++ newbie, and I have many years of experience about OO languages such as C/C#/Objective-C. Now, I'm learning C++.

I saw this C++ code:

```<code>    class World : public State
    {
    };
</code>```

It seems class World inherits the class State publicly.
Public subclassing? It's hard to understand.

What's the concept of this feature?
And when is this useful or required?

答:
The need for the public keyword there is just that for classes defined with the keyword class, the default access modifier (for everything - data members, member functions, and base classes) is private. So

```<code>class World : State {};
</code>```

is the same as:

```<code>class World : private State {};
</code>```

and that's probably not what you want - it means that the base class is only accessible within the class World. Outsiders "don't know" that the inheritance is there at all.

For classes defined with the keyword struct, the default access modifier is public, so you could write:

```<code>struct World : State {};
</code>```

and get something that both looks and behaves a bit like every other language with inheritance. But the struct keyword, and the fact that it defines a class, is really only there for compatibility with C. You won't find many C++ style guides that recommend using it just in order to get the default public accessibility - generally it's used only for classes which are POD, or perhaps only for classes with no member functions at all.

As for why C++ has private inheritance in the first place: for most purposes, private inheritance is a form of composition. Normal composition:

```<code>class World {
    State state;
  public:
    void foo() {
        state.bar();
        state.baz();
        and so on
    }
};
</code>```

That is, the class World knows that it's implemented using a State, and the outside world doesn't know how World is implemented.

vs.

```<code>class World : private State {
  public:
    void foo() {
        bar();
        baz();
        and so on
    }
};
</code>```

That is, the class World knows that it's implemented by being a State, and the outside world doesn't know how it's implemented. But you can selectively expose parts of the interface of State by for example putting using State::bar; in the public part of World's definition. The effect is as if you'd laboriously written a function (or several overloads) in World, each of which delegates to the same function on State.

Other than avoiding typing, though, one common use of private inheritance is when the class State is empty, i.e. has no data members. Then if it's a member of World it must occupy some space (admittedly, depending on the object layout this might be space that otherwise would just be padding, so it doesn't necessarily increase the size of World), but if it's a base class then a thing called the "empty base class optimization" kicks in, and it can be zero-size. If you're creating a lot of objects, this might matter. Private inheritance enables the optimization, but the outside world won't infer an "is-a" relationship, because it doesn't see the inheritance.

It's a pretty fine difference - if in doubt just use explicit composition. Introducing inheritance to save typing is all very well until it has some unexpected consequence.

Title: C++ subclassing access modifier?

Body:
I'm C++ newbie, and I have many years of experience about OO languages such as C/C#/Objective-C. Now, I'm learning C++.

I saw this C++ code:

    class World : public State
    {
    };

It seems class World inherits the class State publicly.
Public subclassing? It's hard to understand.

What's the concept of this feature?
And when is this useful or required?

Body:
The need for the public keyword there is just that for classes defined with the keyword class, the default access modifier (for everything - data members, member functions, and base classes) is private. So

class World : State {};

is the same as:

class World : private State {};

and that's probably not what you want - it means that the base class is only accessible within the class World. Outsiders "don't know" that the inheritance is there at all.

For classes defined with the keyword struct, the default access modifier is public, so you could write:

struct World : State {};

and get something that both looks and behaves a bit like every other language with inheritance. But the struct keyword, and the fact that it defines a class, is really only there for compatibility with C. You won't find many C++ style guides that recommend using it just in order to get the default public accessibility - generally it's used only for classes which are POD, or perhaps only for classes with no member functions at all.

As for why C++ has private inheritance in the first place: for most purposes, private inheritance is a form of composition. Normal composition:

class World {
    State state;
  public:
    void foo() {
        state.bar();
        state.baz();
        and so on
    }
};

That is, the class World knows that it's implemented using a State, and the outside world doesn't know how World is implemented.

vs.

class World : private State {
  public:
    void foo() {
        bar();
        baz();
        and so on
    }
};

That is, the class World knows that it's implemented by being a State, and the outside world doesn't know how it's implemented. But you can selectively expose parts of the interface of State by for example putting using State::bar; in the public part of World's definition. The effect is as if you'd laboriously written a function (or several overloads) in World, each of which delegates to the same function on State.

Other than avoiding typing, though, one common use of private inheritance is when the class State is empty, i.e. has no data members. Then if it's a member of World it must occupy some space (admittedly, depending on the object layout this might be space that otherwise would just be padding, so it doesn't necessarily increase the size of World), but if it's a base class then a thing called the "empty base class optimization" kicks in, and it can be zero-size. If you're creating a lot of objects, this might matter. Private inheritance enables the optimization, but the outside world won't infer an "is-a" relationship, because it doesn't see the inheritance.

It's a pretty fine difference - if in doubt just use explicit composition. Introducing inheritance to save typing is all very well until it has some unexpected consequence.