问:
Loop json variable in javascript
I have a variable in which I get json value. The value comes from 4 tables. I want to loop each table while assigning values. Below is my code

```<code>var dataResponse = JSON.parse(response);
</code>```

I get values from table as

dataResponse.Table[0] , dataResponse.Table[1] ....

how to loop it in javascript. Please help

My json value

```<code>{
  "Table": [{
    "JOB_PROGRESS_ID": 4.0,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU",
    "LINK_ID": "12345678",
    "SPAN_TYPE": "INTERCITY",
    "NE_SPAN_LENGTH": 200.0,
    "HOTO_OFFERED_LENGTH": 26.0,
    "LIT_OFFERED_LENGTH": 30.0,
    "HOTO_ACTUAL_LENGTH": 20.0,
    "LIT_ACTUAL_LENGTH": 15.0,
    "HOTO_OFFERED_DATE": null,
    "HOTO_ACCEPTENCE_DATE": null,
    "LIT_ACCEPTENCE_DATE": null,
    "APPROV_REJECT_REMARK": null,
    "ISABDMISSING": 1.0,
    "JOB_ID": 1.0,
    "MAINTENANCEZONECODE": "INMUKLYN01"
  }],
  "Table1": [{
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.09,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": null,
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 12.41,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.01,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.46,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.02,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 6,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "CLAMP",
    "ASBUILT_LENGTH": 0.48,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 5,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.14,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 5.45,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": null,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.23,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }],
  "Table2": [],
  "Table3": [{
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }]
}
</code>```

UPDATE

```<code>var dataResponse = JSON.parse(response);

for (var i = 0; i < dataResponse.Table.length; i++) {
  if (dataResponse.Table[i] != "" || dataResponse.Table[i] != null) {
    $("#spnLinkId").text(dataResponse.Table[i].LINK_ID);
    $("#spnSpanLength").text(dataResponse.Table[i].NE_SPAN_LENGTH);
    $("#txtFiberActlength").val(dataResponse.Table[i].HOTO_ACTUAL_LENGTH);
    $("#txtLITActlength").val(dataResponse.Table[i].LIT_ACTUAL_LENGTH);
  }
  if (dataResponse.Table[i].ISABDMISSING != "" || dataResponse.Table[i].ISABDMISSING != null) {

    if (dataResponse.Table[i].ISABDMISSING == 1) {
      $("#FEmissingAsBuiltYes").prop("checked", true);
    } else {
      $("#FEmissingAsBuiltNo").prop("checked", true);
    }
  }
}
</code>```

答:
Oh my... Your dataResponse.Table is not an Array. It is an Object.

For Array of array-like object, you use for loop.

However, to loop an Object, you use for...in loop.

In your case, it can be done so like:

```<code>for (var key in dataResponse){
    /* Your logic here */
    /* key => Table, Table1, Table2... */
    /* dataResponse[key] => [{...}], [{...}]... */
}
</code>```

I will not answer your question directly. Because clearly you have not make any notable effort in researching looping in javascript.

Title: Loop json variable in javascript

Body:
I have a variable in which I get json value. The value comes from 4 tables. I want to loop each table while assigning values. Below is my code

var dataResponse = JSON.parse(response);

I get values from table as

dataResponse.Table[0] , dataResponse.Table[1] ....

how to loop it in javascript. Please help

My json value

{
  "Table": [{
    "JOB_PROGRESS_ID": 4.0,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU",
    "LINK_ID": "12345678",
    "SPAN_TYPE": "INTERCITY",
    "NE_SPAN_LENGTH": 200.0,
    "HOTO_OFFERED_LENGTH": 26.0,
    "LIT_OFFERED_LENGTH": 30.0,
    "HOTO_ACTUAL_LENGTH": 20.0,
    "LIT_ACTUAL_LENGTH": 15.0,
    "HOTO_OFFERED_DATE": null,
    "HOTO_ACCEPTENCE_DATE": null,
    "LIT_ACCEPTENCE_DATE": null,
    "APPROV_REJECT_REMARK": null,
    "ISABDMISSING": 1.0,
    "JOB_ID": 1.0,
    "MAINTENANCEZONECODE": "INMUKLYN01"
  }],
  "Table1": [{
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.09,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": null,
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 12.41,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.01,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.46,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.02,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 6,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "CLAMP",
    "ASBUILT_LENGTH": 0.48,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 5,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.14,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 5.45,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": null,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.23,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }],
  "Table2": [],
  "Table3": [{
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }]
}

UPDATE

var dataResponse = JSON.parse(response);

for (var i = 0; i < dataResponse.Table.length; i++) {
  if (dataResponse.Table[i] != "" || dataResponse.Table[i] != null) {
    $("#spnLinkId").text(dataResponse.Table[i].LINK_ID);
    $("#spnSpanLength").text(dataResponse.Table[i].NE_SPAN_LENGTH);
    $("#txtFiberActlength").val(dataResponse.Table[i].HOTO_ACTUAL_LENGTH);
    $("#txtLITActlength").val(dataResponse.Table[i].LIT_ACTUAL_LENGTH);
  }
  if (dataResponse.Table[i].ISABDMISSING != "" || dataResponse.Table[i].ISABDMISSING != null) {

    if (dataResponse.Table[i].ISABDMISSING == 1) {
      $("#FEmissingAsBuiltYes").prop("checked", true);
    } else {
      $("#FEmissingAsBuiltNo").prop("checked", true);
    }
  }
}

Body:
Oh my... Your dataResponse.Table is not an Array. It is an Object.

For Array of array-like object, you use for loop.

However, to loop an Object, you use for...in loop.

In your case, it can be done so like:

for (var key in dataResponse){
    /* Your logic here */
    /* key => Table, Table1, Table2... */
    /* dataResponse[key] => [{...}], [{...}]... */
}

I will not answer your question directly. Because clearly you have not make any notable effort in researching looping in javascript.


来源: stackexchange

问:
Position fixed div with relative to the parent container
I want to add a div in right sidebar which is fixed and relative to the parent container just like this in this website see the right sidebar this is exactly what I want for my website

I tried many things but not got any result here is my code

```<code><div id="parent_div">
 <div id="fixed_div">
  Some Content here.....
 </div>
</div>

parent_div
{
 float:right;
 width:300px;
 margin-top:50px;
 margin-right:5px;
 position:relative;
 border:1px solid red;
}

fixed_div
{
 position:fixed;
 width:300px;
 background-color:#084B8A;
 padding:10px;
 box-sizing:border-box;
}
</code>```

How can I do this in css which is cross browser and if it is not possible in css how can I do this in jquery or javascript

答:
You can use position:sticky;

or else use function

```<code>$(window).on("scroll", function() {
    if($(window).scrollTop() > 50) {
        $(".sidebar").addClass("active");
    } else {
        //remove the background property so it comes transparent again (defined in your css)
       $(".sidebar").removeClass("active");
    }
});
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I want to add a div in right sidebar which is fixed and relative to the parent container just like this in this website see the right sidebar this is exactly what I want for my website

I tried many things but not got any result here is my code

  Some Content here.....

parent_div
{
 float:right;
 width:300px;
 margin-top:50px;
 margin-right:5px;
 position:relative;
 border:1px solid red;
}

fixed_div
{
 position:fixed;
 width:300px;
 background-color:#084B8A;
 padding:10px;
 box-sizing:border-box;
}

How can I do this in css which is cross browser and if it is not possible in css how can I do this in jquery or javascript

Body:
You can use position:sticky;

or else use function

$(window).on("scroll", function() {
    if($(window).scrollTop() > 50) {
        $(".sidebar").addClass("active");
    } else {
        //remove the background property so it comes transparent again (defined in your css)
       $(".sidebar").removeClass("active");
    }
});

ContentLicense: CC BY-SA 3.0


问:
How many bits of precision does a normalized double precision IEEE Floating Point number have?
How many bits of precision does a normalized double precision IEEE Floating Point number have? Is there sort of formula

what I found was this but I feel like it is wrong:

•   +2-1022 to (2-2-52) * 21023

答:
Please read https://en.wikipedia.org/wiki/IEEE_754-1985

In particular, it reads

Precision is defined as the minimum difference between two successive mantissa representations; thus it is a function only in the mantissa;

A double-precision IEEE 754 value uses 52 bits for the mantissa. A normalized value has an implicit '1' bit:

The leading 1 bit is omitted since all numbers except zero start with a leading 1; the leading 1 is implicit and doesn't actually need to be stored which gives an extra bit of precision for "free."

Thus, there are 53 bits of precision in an IEEE 754 double-precision floating-point value.


问:
Using Skimage adaptive thresholding on an image and getting the output
I am trying to use scikit-image's adaptive threshold on my image. I tested out their sample code from HERE

```<code>import matplotlib.pyplot as plt

from skimage import data
from skimage.filters import threshold_otsu, threshold_adaptive

image = data.page()

global_thresh = threshold_otsu(image)
binary_global = image > global_thresh

block_size = 35
binary_adaptive = threshold_adaptive(image, block_size, offset=10)

fig, axes = plt.subplots(nrows=3, figsize=(7, 8))
ax0, ax1, ax2 = axes
plt.gray()

ax0.imshow(image)
ax0.set_title('Image')

ax1.imshow(binary_global)
ax1.set_title('Global thresholding')

ax2.imshow(binary_adaptive)
ax2.set_title('Adaptive thresholding')

for ax in axes:
    ax.axis('off')

plt.show()
</code>```

The code takes in a sample image, thresholds it and shows it using plt. However, I am trying to retrieve the numpy array of the thresholded image. When I tried using cv2.imwrite on the variable binary_global, it does not work. When printing out binary_global--it is actually an array consisting of False and True values rather than numbers. I am not sure how plt can use that and produce an image. Regardless, how can I threshold the image and retrieve the new thresholded image's array with the RGB values?

答:
You first need convert the scikit image to opencv to be able to use cv2.imwrite().

Add the following changes-

```<code>from skimage import img_as_ubyte
import matplotlib.pyplot as plt
from skimage import data
from skimage.filters import threshold_otsu, threshold_adaptive
import cv2

image = data.page()

global_thresh = threshold_otsu(image)
binary_global = image > global_thresh

block_size = 35
binary_adaptive = threshold_adaptive(image, block_size, offset=10)

fig, axes = plt.subplots(nrows=3, figsize=(7, 8))
ax0, ax1, ax2 = axes
plt.gray()

ax0.imshow(image)
ax0.set_title('Image')

ax1.imshow(binary_global)
ax1.set_title('Global thresholding')

ax2.imshow(binary_adaptive)
ax2.set_title('Adaptive thresholding')

for ax in axes:
    ax.axis('off')

plt.show()
img = img_as_ubyte(binary_global)
cv2.imshow("image", img)
cv2.waitKey(0)
</code>```

You can then use the img for writing etc.

Body:
I am trying to use scikit-image's adaptive threshold on my image. I tested out their sample code from HERE

import matplotlib.pyplot as plt

from skimage import data
from skimage.filters import threshold_otsu, threshold_adaptive

image = data.page()

global_thresh = threshold_otsu(image)
binary_global = image > global_thresh

block_size = 35
binary_adaptive = threshold_adaptive(image, block_size, offset=10)

fig, axes = plt.subplots(nrows=3, figsize=(7, 8))
ax0, ax1, ax2 = axes
plt.gray()

ax0.imshow(image)
ax0.set_title('Image')

ax1.imshow(binary_global)
ax1.set_title('Global thresholding')

ax2.imshow(binary_adaptive)
ax2.set_title('Adaptive thresholding')

for ax in axes:
    ax.axis('off')

plt.show()

The code takes in a sample image, thresholds it and shows it using plt. However, I am trying to retrieve the numpy array of the thresholded image. When I tried using cv2.imwrite on the variable binary_global, it does not work. When printing out binary_global--it is actually an array consisting of False and True values rather than numbers. I am not sure how plt can use that and produce an image. Regardless, how can I threshold the image and retrieve the new thresholded image's array with the RGB values?

Body:
You first need convert the scikit image to opencv to be able to use cv2.imwrite().

Add the following changes-

from skimage import img_as_ubyte
import matplotlib.pyplot as plt
from skimage import data
from skimage.filters import threshold_otsu, threshold_adaptive
import cv2

image = data.page()

global_thresh = threshold_otsu(image)
binary_global = image > global_thresh

block_size = 35
binary_adaptive = threshold_adaptive(image, block_size, offset=10)

fig, axes = plt.subplots(nrows=3, figsize=(7, 8))
ax0, ax1, ax2 = axes
plt.gray()

ax0.imshow(image)
ax0.set_title('Image')

ax1.imshow(binary_global)
ax1.set_title('Global thresholding')

ax2.imshow(binary_adaptive)
ax2.set_title('Adaptive thresholding')

for ax in axes:
    ax.axis('off')

plt.show()
img = img_as_ubyte(binary_global)
cv2.imshow("image", img)
cv2.waitKey(0)

You can then use the img for writing etc.


问:
Is there a way we can get docker service logs in older docker version 1.12.2
We have to use the older version of docker  1.12.2 due to some compliance issues.
But docker service logs is not introduced till docker 1.29.
The service I am starting is failing with "task: non-zero exit (1)"
and that's the extent of failure data I am able to retrieve using docker service ps

Basically, I need the docker service logs on older docker version is there any way for achieving it.

I am new to docker.
Thanks in advance, any help will be appreciated.

答:
As explained here, you would need to use a sidecar approach (here explained with Kubernetes, but applicable for Docker alone) in order for each of your container to send logs to the same place.

Or you can write a program that collect logs from the containers you are listing in your service.


问:
Stream and Filter operations on a Map
I have an EdmPortfolio type that has id (int), name (String) and tags which is a  map as its members.

EdmPortfolio say has an id 1, and name as Portfolio1 and Map could have the following values,
analyst, John
region, US

I have a List,  At the end i want to have a Map which has all the map values combined from all portfolios. Another EdmPortfolio  might have the id as 2, name as Portfolio2 and Map with values analyst, Smith
region , UK

I want to have a combined Map with Values
region 'US','UK'
analyst 'John','Smith'

analyst and region are the keys to the map.
It has both the maps combined. I have the following code but i am a little lost

```<code>List<Map<Tag,String>> portfolioTagsList = new ArrayList<>();
            for (EdmPortfolio edmPortfolio : edmPortfolioList) {
              Map<Tag,String> portfolioTags =  edmPortfolio.getPortfolioTags().entrySet()
                        .stream()

                        .filter(e -> (e.getValue() != ""|| e.getValue() !=null))
                        .collect(Collectors.toMap(
                                Map.Entry::getKey,
                                Map.Entry::getValue
                        ));

                portfolioTagsList.add(portfolioTags);
            }
            Map<Tag,String> finalTags = portfolioTagsList.stream()
                    .flatMap(m -> m.entrySet().stream())
                    .collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.joining(",",Map.Entry::getValue)));
</code>```

I am getting nonstatic method cannot be referenced from static context. How do i achieve this?

Thanks for your time

答:
I'd do something like:

```<code>Map<Tag,String> finalTags = edmPortfolioList.stream()
.flatMap(edmPortfolio -> edmPortfolio.getPortfolioTags().entrySet().stream())
.filter(e -> (e.getValue() != "" || e.getValue() !=null)) // this seems weird, but just keeping
.collect(Collectors.groupingBy(e -> e.getKey(),
    Collectors.mapping(ev -> ev.getValue(),
        Collectors.joining(",")));
</code>```

BTW: Any reason to break that in two streams?

Title: Stream and Filter operations on a Map

Body:
I have an EdmPortfolio type that has id (int), name (String) and tags which is a  map as its members.

EdmPortfolio say has an id 1, and name as Portfolio1 and Map could have the following values,
analyst, John
region, US

I have a List,  At the end i want to have a Map which has all the map values combined from all portfolios. Another EdmPortfolio  might have the id as 2, name as Portfolio2 and Map with values analyst, Smith
region , UK

I want to have a combined Map with Values
region 'US','UK'
analyst 'John','Smith'

analyst and region are the keys to the map.
It has both the maps combined. I have the following code but i am a little lost

List<Map<Tag,String>> portfolioTagsList = new ArrayList<>();
            for (EdmPortfolio edmPortfolio : edmPortfolioList) {
              Map<Tag,String> portfolioTags =  edmPortfolio.getPortfolioTags().entrySet()
                        .stream()

                        .filter(e -> (e.getValue() != ""|| e.getValue() !=null))
                        .collect(Collectors.toMap(
                                Map.Entry::getKey,
                                Map.Entry::getValue
                        ));

                portfolioTagsList.add(portfolioTags);
            }
            Map<Tag,String> finalTags = portfolioTagsList.stream()
                    .flatMap(m -> m.entrySet().stream())
                    .collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.joining(",",Map.Entry::getValue)));

I am getting nonstatic method cannot be referenced from static context. How do i achieve this?

Thanks for your time

Body:
I'd do something like:

Map<Tag,String> finalTags = edmPortfolioList.stream()
.flatMap(edmPortfolio -> edmPortfolio.getPortfolioTags().entrySet().stream())
.filter(e -> (e.getValue() != "" || e.getValue() !=null)) // this seems weird, but just keeping
.collect(Collectors.groupingBy(e -> e.getKey(),
    Collectors.mapping(ev -> ev.getValue(),
        Collectors.joining(",")));

BTW: Any reason to break that in two streams?


问:
Access Denied Connecting to MySQL with PHP
I know there are a lot of threads asking this question already, but I have been at this for hours and am at wits end.  I am attempting to connect to a MySQL database that I am running of my MacBook with the following PHP:

```<code><?php
DEFINE('DB_USER', 'webuser');
DEFINE('DB_PASSWORD', 'thispassword');
DEFINE('DB_HOST', '127.0.0.1:3306');
DEFINE('DB_NAME', 'learning_accounts');

$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Error connecting: ' .
mysqli_connect_error()
);

?>
</code>```

That returns the following error:

```<code>Error connecting: Access denied for user 'webuser'@'localhost' (using password: YES)
</code>```

I can connect fine through the terminal, even trying to connect with PHP and root does not work.  I am new to both PHP and MySQL so any guidance and insight would be appreciated!

I have tried tons of solutions such as granting privileges, flushing privileges, creating new users, using PDO, nothing has been working - please help!

Thanks so much, I hate learning new languages because then I'm a lost fish when it comes to debugging at first!

Update

I have a password set for my root account, but changing the DB_PASSWORD variable to '' changes the error to: Error connecting: Unknown database 'learning_accounts'

Update 2
I have fixed the issue, check my answer to see how, if you are having this problem then I hope you found this thread quickly!

Zach L

答:
If you are working on the local server then no need to require the password just make it `blank'.

```<code>    define('DB_HOST', 'localhost');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_NAME', 'learning_accounts');

$conn = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
if (!$link) {
    die("Database connection failed: " . mysqli_error());
}
</code>```

If you are working on the server the just change the DB_USER, DB_PASSWORD and DB_NAME.
    If still not able to connect then check the database name is correct or not.

If everything is perfect you have to check the below link

How to install MySQLi

Body:
I know there are a lot of threads asking this question already, but I have been at this for hours and am at wits end.  I am attempting to connect to a MySQL database that I am running of my MacBook with the following PHP:

<?php
DEFINE('DB_USER', 'webuser');
DEFINE('DB_PASSWORD', 'thispassword');
DEFINE('DB_HOST', '127.0.0.1:3306');
DEFINE('DB_NAME', 'learning_accounts');

$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Error connecting: ' .
mysqli_connect_error()
);

?>

That returns the following error:

Error connecting: Access denied for user 'webuser'@'localhost' (using password: YES)

I can connect fine through the terminal, even trying to connect with PHP and root does not work.  I am new to both PHP and MySQL so any guidance and insight would be appreciated!

I have tried tons of solutions such as granting privileges, flushing privileges, creating new users, using PDO, nothing has been working - please help!

Thanks so much, I hate learning new languages because then I'm a lost fish when it comes to debugging at first!

Update

I have a password set for my root account, but changing the DB_PASSWORD variable to '' changes the error to: Error connecting: Unknown database 'learning_accounts'

Update 2
I have fixed the issue, check my answer to see how, if you are having this problem then I hope you found this thread quickly!

Zach L

Body:
If you are working on the local server then no need to require the password just make it `blank'.

    define('DB_HOST', 'localhost');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_NAME', 'learning_accounts');

$conn = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
if (!$link) {
    die("Database connection failed: " . mysqli_error());
}

If you are working on the server the just change the DB_USER, DB_PASSWORD and DB_NAME.
    If still not able to connect then check the database name is correct or not.

If everything is perfect you have to check the below link

How to install MySQLi


问:
Angular 4 RXJS Observable .interval() Doesn't Work In Background
I have a simple timer observable which is subscribed to when a timer starts in my app. It works well, but if another browser tab is selected then the timer stops until the app's tab is selected again.

```<code>public timer = Observable
  .interval(100)
</code>```

Is there a way I can keep the observable running while the tab is in the background?

Update

I looked briefly into running this as a Web Worker, but soon started reading about difficulties of integrating Web Workers into Angular projects.

So for the time being I'm using the simple solution of getting the start time of my timer and subtracting that from the current time to get the timer run duration. This way the timer will correct itself when when the tab becomes active again.

I did want the page title to display the timer count so that it can be seen just by looking at the tab, so I'd still like to find a better solution to this problem.

答:
It doesnt seems like that , this is working

```<code>let j=0;
Rx.Observable.interval(1000).subscribe((v)=>{
  console.info('j: '+j++);})
</code>```

Check here working demo : http://jsbin.com/zufebipawe/edit?html,js,console,output

also check here : https://github.com/ReactiveX/rxjs/issues/3042

Body:
I have a simple timer observable which is subscribed to when a timer starts in my app. It works well, but if another browser tab is selected then the timer stops until the app's tab is selected again.

public timer = Observable
  .interval(100)

Is there a way I can keep the observable running while the tab is in the background?

Update

I looked briefly into running this as a Web Worker, but soon started reading about difficulties of integrating Web Workers into Angular projects.

So for the time being I'm using the simple solution of getting the start time of my timer and subtracting that from the current time to get the timer run duration. This way the timer will correct itself when when the tab becomes active again.

I did want the page title to display the timer count so that it can be seen just by looking at the tab, so I'd still like to find a better solution to this problem.

Body:
It doesnt seems like that , this is working

let j=0;
Rx.Observable.interval(1000).subscribe((v)=>{
  console.info('j: '+j++);})

Check here working demo : http://jsbin.com/zufebipawe/edit?html,js,console,output

also check here : https://github.com/ReactiveX/rxjs/issues/3042


问:
Please explain Get and Post in ASP.net
I am new to ASP.net . Can any one please explain what is the difference between Get and Post method in asp.Net.

Thanks
Pradeep.A

答: "xelco52" very well explained. In addition "Get" and "Post" method is not .Net/ASP.Net specific. Other languages does the same also such as PHP.</p>

ContentLicense: CC BY-SA 2.5

Title: Please explain Get and Post in ASP.net


问:
After update android studio could not create parent directory for lock file
Updated android studio and plugins when sync, fails with could not create parent directory for lock file

wrapper properties:

```<code>#Sun Mar 05 16:51:59 PKT 2017 distributionBase=
GRADLE_USER_HOME  distributionPath=wrapper/
dists  zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/
dists  distributionUrl=https\://services.gradle.org/distributions/
gradle- 3.3-all.zip
</code>```

build.gradle app module:

```<code>apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.sarahn.toyapplication"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-   rules.pro'
}
}
productFlavors {
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:
2.2.2',   {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}
</code>```

build.gradle(project)

```<code>`// Top-level build file where you can add configuration options
common to  all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
</code>```

tried downloading NDK, deleting .gradle folder from project and from installs but not going forward

Environment:
Windows 10

答:
This worked for me Android Studio v3.0

delete in the root folder .gradlew gradle.bat(on windows) , gradle/ .idea/
reopen the project.

Body:
Updated android studio and plugins when sync, fails with could not create parent directory for lock file

wrapper properties:

#Sun Mar 05 16:51:59 PKT 2017 distributionBase=
GRADLE_USER_HOME  distributionPath=wrapper/
dists  zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/
dists  distributionUrl=https\://services.gradle.org/distributions/
gradle- 3.3-all.zip

build.gradle app module:

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.sarahn.toyapplication"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-   rules.pro'
}
}
productFlavors {
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:
2.2.2',   {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}

build.gradle(project)

`// Top-level build file where you can add configuration options
common to  all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

tried downloading NDK, deleting .gradle folder from project and from installs but not going forward

Environment:
Windows 10


问:
WordPress: Site is HTTPS; redirect only one site page over HTTP
I'm trying to get a website I'm administrating to redirect only one page over HTTP, while the rest of the site will be sent over HTTPS.

The server is an Ubuntu Server 16.04.3 setup, with WordPress 4.9 installed. The certificate is from Let's Encrypt.

According to another post I was reading, one of the solutions given was to add something similar to the following code in the site's .htaccess file:

```<code># redirects non-www page requests to www version
RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [NC]
RewriteRule (.*) http://www.mywebsite.com/$1 [R=301,L,NE]

# adds a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

# 3 pages to be on https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(order-form|employment-
application|about/contact-us)/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301,NE]

# All other pages have to be on http
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(order-form|employment-
application|about/contact-us)/ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301,NE]
</code>```

However, after applying this solution and restarting the apache server, the entire site went into a state of constant redirects and timeouts. As mentioned, I just need one page and one page only to be on HTTP, and the rest of the site can safely be on HTTPS. Any solutions would be greatly appreciated.

答: Personally, I would try to come up with an alternative way to pull in that resource from wherever it lives on HTTP. Is it a script? An image? There has to be a better way to pull it.</p>

Body:
I'm trying to get a website I'm administrating to redirect only one page over HTTP, while the rest of the site will be sent over HTTPS.

The server is an Ubuntu Server 16.04.3 setup, with WordPress 4.9 installed. The certificate is from Let's Encrypt.

According to another post I was reading, one of the solutions given was to add something similar to the following code in the site's .htaccess file:

# redirects non-www page requests to www version
RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [NC]
RewriteRule (.*) http://www.mywebsite.com/$1 [R=301,L,NE]

# adds a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

# 3 pages to be on https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(order-form|employment-
application|about/contact-us)/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301,NE]

# All other pages have to be on http
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(order-form|employment-
application|about/contact-us)/ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301,NE]

However, after applying this solution and restarting the apache server, the entire site went into a state of constant redirects and timeouts. As mentioned, I just need one page and one page only to be on HTTP, and the rest of the site can safely be on HTTPS. Any solutions would be greatly appreciated.


问:
Visual Studio Advanced Query Builder MySql adding "def." before table names
From within the .xsd designer I drag a table from a MySql connection on the list and begin  configure it.  When I open the Advanced Query builder, The sql is changed from what was in the initial box

```<code>select * from x;
</code>```

to

```<code>select * from def.schema.x
</code>```

where schema is the actual schema and the problem is that I don't see where the def prefix is coming.  MySql version 5.5.8, MySqlConnector 6.3.4, Visual Studio 2008, Windows 7 64.  This same process was working fine on XP.

Any ideas?

答:
Hey ,I had this damn problem before but i solved it
All what you need to is :
install .net FrameWork 4.0 before installing the .net connector 6.3.6.

In Case it did not work install visual studio 2010 and it will work 100%.

Body:
From within the .xsd designer I drag a table from a MySql connection on the list and begin  configure it.  When I open the Advanced Query builder, The sql is changed from what was in the initial box

select * from x;

to

select * from def.schema.x

where schema is the actual schema and the problem is that I don't see where the def prefix is coming.  MySql version 5.5.8, MySqlConnector 6.3.4, Visual Studio 2008, Windows 7 64.  This same process was working fine on XP.

Any ideas?


问:
How to Iterate through all property of object and delete specific property AngularJS
I have a JavaScript object like the following:

```<code>{
    "widget": {
        "debug": "on",
        "test": {},
        "window": [{
            "title": "Sample Konfabulator Widget",
            "name": "main_window",
            "width": 500,
            "height": 500,
            "test": {}
        }]
        "image": {
            "src": "Images/Sun.png",
            "name": "sun1",
            "test": {},
            "vOffset": 250
        },
        "text": {
            "data": "Click Here",
            "test": {},
            "alignment": "center",
            "image": {
                "src": "Images/test.png",
                "name": "sun2",
                "test": {}
            }
        }
    }
}
</code>```

Now I want to Iterate through the object and delete all "test" property. How can I do that?

答:
var data = {
  "widget": {
    "debug": "on",
    "test": {},
    "window": [{
      "title": "Sample Konfabulator Widget",
      "name": "main_window",
      "width": 500,
      "height": 500,
      "test": {}
    }],
    "image": {
      "src": "Images/Sun.png",
      "name": "sun1",
      "test": {},
      "vOffset": 250
    },
    "text": {
      "data": "Click Here",
      "test": {},
      "alignment": "center",
      "image": {
        "src": "Images/test.png",
        "name": "sun2",
        "test": {}
      }
    }
  }
};

function DeleteProperty(input, name) {
  if (input instanceof Object) {
    for (var prop in input) {
      if (prop == name)
        delete input[prop]
      else
        DeleteProperty(input[prop], name)
    }
  }
}

DeleteProperty(data, 'test');
console.log(data);```

Body:
I have a JavaScript object like the following:

{
    "widget": {
        "debug": "on",
        "test": {},
        "window": [{
            "title": "Sample Konfabulator Widget",
            "name": "main_window",
            "width": 500,
            "height": 500,
            "test": {}
        }]
        "image": {
            "src": "Images/Sun.png",
            "name": "sun1",
            "test": {},
            "vOffset": 250
        },
        "text": {
            "data": "Click Here",
            "test": {},
            "alignment": "center",
            "image": {
                "src": "Images/test.png",
                "name": "sun2",
                "test": {}
            }
        }
    }
}

Now I want to Iterate through the object and delete all "test" property. How can I do that?


问:
Konvajs layer positions not being set as expected
I have an app where I am panning and zooming multiple layers.

However, when I set the position of the layers they are being updated to the wrong values.

For instance, after calling:

```<code>layer.position({
    x: 12,
    y: 233,
});
</code>```

I would expect

```<code>layer.getClientRect();
</code>```

to return

```<code>{
  x: 12,
  y: 233,
}
</code>```

Instead it returns

```<code>{
  x: -22,
  y: 220,
}
</code>```

Is there any known reason this is happening?

答: I realised I wasn't taking into account all the offsets. The x position of a circle is set from the centre while getClientRect() returns the width and height including negatives. So getClientRect() on a circle with a radius of 50 and x of 0 will actually return {x: -25, y: -25, width: 50, height: 50}.

Body:
I have an app where I am panning and zooming multiple layers.

However, when I set the position of the layers they are being updated to the wrong values.

For instance, after calling:

layer.position({
    x: 12,
    y: 233,
});

I would expect

layer.getClientRect();

to return

{
  x: 12,
  y: 233,
}

Instead it returns

{
  x: -22,
  y: 220,
}

Is there any known reason this is happening?


问:
Need some formatting help in the logging function in Python 2.7
I am developing my skills in Python and now try to add some logging to my files. I run into formatting issue and cannot find any information or I ask the wrong question.
So to it:
Some snippets of my code.

```<code> import logging
logging.basicConfig(filename='/var/log/larmlog/getandsendlogger.log',level=logging.DEBUG,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',datefmt='%Y-%m-%d %H:%M:%S ')
</code>```

I am fetching two variables from MySQL

```<code>cursor.execute("""SELECT omr,county FROM rico where pocnr = '%s'""" %  (pocin))
        records = cursor.fetchall()
        nystad = [record[0] for record in records]
        county = [record[1] for record in records]
logging.debug("chkomr returns nystad {} and county {}.".format(nystad,county))
</code>```

and when I use the variables in the log it looks like this

2017-12-05 02:46:02  - root - DEBUG - chkomr returns nystad [None] and county [u'J\xf6nk\xf6pings l\xe4n'].

Why and how can I correct it? Should be strings with Swedish. The log should say Jönköpings län. My code should be set to utf-8.

I have not asked so many questions here and probably messed up the question with codeblocks and so. Just ask if you need more code or explanation.

答:
This solved my problem but i am not sure why i have to extract the data twice. Just happy my loggs start to look good. :D</p>

```<code>logging.debug('chkomr returns nystad %s and county %s.' % (nystad[0],county[0]))
</code>```

Body:
I am developing my skills in Python and now try to add some logging to my files. I run into formatting issue and cannot find any information or I ask the wrong question.
So to it:
Some snippets of my code.

 import logging
logging.basicConfig(filename='/var/log/larmlog/getandsendlogger.log',level=logging.DEBUG,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',datefmt='%Y-%m-%d %H:%M:%S ')

I am fetching two variables from MySQL

cursor.execute("""SELECT omr,county FROM rico where pocnr = '%s'""" %  (pocin))
        records = cursor.fetchall()
        nystad = [record[0] for record in records]
        county = [record[1] for record in records]
logging.debug("chkomr returns nystad {} and county {}.".format(nystad,county))

and when I use the variables in the log it looks like this

2017-12-05 02:46:02  - root - DEBUG - chkomr returns nystad [None] and county [u'J\xf6nk\xf6pings l\xe4n'].

Why and how can I correct it? Should be strings with Swedish. The log should say Jönköpings län. My code should be set to utf-8.

I have not asked so many questions here and probably messed up the question with codeblocks and so. Just ask if you need more code or explanation.

Body:
This solved my problem but i am not sure why i have to extract the data twice. Just happy my loggs start to look good. :D

logging.debug('chkomr returns nystad %s and county %s.' % (nystad[0],county[0]))


问:
Get latest data for all people in a table and then filter based on some criteria
I am attempting to return the row of the highest value for timestamp (an integer) for each person (that has multiple entries) in a table. Additionally, I am only interested in rows with the field containing ABCD, but this should be done after filtering to return the latest (max timestamp) entry for each person.

```<code>SELECT table."person", max(table."timestamp")
FROM table
WHERE table."type" = 1
HAVING table."field" LIKE '%ABCD%'
GROUP BY table."person"
</code>```

For some reason, I am not receiving the data I expect. The returned table is nearly twice the size of expectation. Is there some step here that I am not getting correct?

答:
You can 1st return a table having max(timestamp) and then use it in sub query of another select statement, following is query</p>

```<code>  SELECT table."person", timestamp FROM
 (SELECT table."person",max(table."timestamp") as timestamp, type, field FROM table GROUP BY table."person")
    where type = 1 and field LIKE '%ABCD%'
</code>```

Body:
I am attempting to return the row of the highest value for timestamp (an integer) for each person (that has multiple entries) in a table. Additionally, I am only interested in rows with the field containing ABCD, but this should be done after filtering to return the latest (max timestamp) entry for each person.

SELECT table."person", max(table."timestamp")
FROM table
WHERE table."type" = 1
HAVING table."field" LIKE '%ABCD%'
GROUP BY table."person"

For some reason, I am not receiving the data I expect. The returned table is nearly twice the size of expectation. Is there some step here that I am not getting correct?

Body:
You can 1st return a table having max(timestamp) and then use it in sub query of another select statement, following is query

  SELECT table."person", timestamp FROM
 (SELECT table."person",max(table."timestamp") as timestamp, type, field FROM table GROUP BY table."person")
    where type = 1 and field LIKE '%ABCD%'


问:
Comparing parallel arrays read from a text file
I have a question about using two parallel arrays.

For example, I read in 20 characters from a text file into a character array. Then I read in 20 different characters from another text file with a different character array.

How can I compare the two and see if they match?

This is a separate function from the main, so this function will be passed on the arrays from main.

答:
It was actually extremely easy (in case anyone else was wondering)

All i did was create a for loop, and inside the loop created an if statement where i called in the corresponding cells of each. If they were not equal i made a counter of how many were wrong, and displayed it at the end.

And if the questions were right do nothing.

I don't know if i explained it super well. I'm still super new to programming and i gotta say the feeling of figuring something out on your own after a lot of work feels really good :).

Thanks for the replys.


问:
How do we access/manipulate variable names which conflicts with byebug reserved keywords?
How do we access those variable names which conflict with byebug reserved name?

```<code>(byebug) var local
h = {"hierarchyId"=>"59f0b029e4b037ef11a055f7", "level"=>2, ...
self =                   <div class="index_as_table"></div>

(byebug)
</code>```

I want to access variable "h"

but typing h would show up the "help dialog box for byebug"

```<code>(byebug) h

  break      -- Sets breakpoints in the source code
  catch      -- Handles exception catchpoints
  condition  -- Sets conditions on breakpoints
  continue   -- Runs until program ends, hits a breakpoint or reaches a line
  debug      -- Spawns a subdebugger
  delete     -- Deletes breakpoints
  disable    -- Disables breakpoints or displays
  display    -- Evaluates expressions every time the debugger stops
  down       -- Moves to a lower frame in the stack trace
  edit       -- Edits source files
  enable     -- Enables breakpoints or displays
  finish     -- Runs the program until frame returns
  frame      -- Moves to a frame in the call stack
  help       -- Helps you using byebug
  history    -- Shows byebug's history of commands
  info       -- Shows several informations about the program being debugged
  interrupt  -- Interrupts the program
  irb        -- Starts an IRB session
  kill       -- Sends a signal to the current process
  list       -- Lists lines of source code
  method     -- Shows methods of an object, class or module
  next       -- Runs one or more lines of code
  pry        -- Starts a Pry session
  quit       -- Exits byebug
  restart    -- Restarts the debugged program
  save       -- Saves current byebug session to a file
  set        -- Modifies byebug settings
  show       -- Shows byebug settings
  source     -- Restores a previously saved byebug session
  step       -- Steps into blocks or methods one or more times
  thread     -- Commands to manipulate threads
  tracevar   -- Enables tracing of a global variable
  undisplay  -- Stops displaying all or some expressions when program stops
  untracevar -- Stops tracing a global variable
  up         -- Moves to a higher frame in the stack trace
  var        -- Shows variables and its values
  where      -- Displays the backtrace

(byebug)
</code>```

Is there any way to access variables who conflicts with these reserved keyword names. like exclamation prefix in python's pdb? (!h didn't work for byebug)

答:
You can use:

```<code>eval h
</code>```

Byebug Guide: https://github.com/deivid-rodriguez/byebug/blob/master/GUIDE.md

Body:
How do we access those variable names which conflict with byebug reserved name?

(byebug) var local
h = {"hierarchyId"=>"59f0b029e4b037ef11a055f7", "level"=>2, ...
self =

(byebug)

I want to access variable "h"

but typing h would show up the "help dialog box for byebug"

(byebug) h

  break      -- Sets breakpoints in the source code
  catch      -- Handles exception catchpoints
  condition  -- Sets conditions on breakpoints
  continue   -- Runs until program ends, hits a breakpoint or reaches a line
  debug      -- Spawns a subdebugger
  delete     -- Deletes breakpoints
  disable    -- Disables breakpoints or displays
  display    -- Evaluates expressions every time the debugger stops
  down       -- Moves to a lower frame in the stack trace
  edit       -- Edits source files
  enable     -- Enables breakpoints or displays
  finish     -- Runs the program until frame returns
  frame      -- Moves to a frame in the call stack
  help       -- Helps you using byebug
  history    -- Shows byebug's history of commands
  info       -- Shows several informations about the program being debugged
  interrupt  -- Interrupts the program
  irb        -- Starts an IRB session
  kill       -- Sends a signal to the current process
  list       -- Lists lines of source code
  method     -- Shows methods of an object, class or module
  next       -- Runs one or more lines of code
  pry        -- Starts a Pry session
  quit       -- Exits byebug
  restart    -- Restarts the debugged program
  save       -- Saves current byebug session to a file
  set        -- Modifies byebug settings
  show       -- Shows byebug settings
  source     -- Restores a previously saved byebug session
  step       -- Steps into blocks or methods one or more times
  thread     -- Commands to manipulate threads
  tracevar   -- Enables tracing of a global variable
  undisplay  -- Stops displaying all or some expressions when program stops
  untracevar -- Stops tracing a global variable
  up         -- Moves to a higher frame in the stack trace
  var        -- Shows variables and its values
  where      -- Displays the backtrace

(byebug)

Is there any way to access variables who conflicts with these reserved keyword names. like exclamation prefix in python's pdb? (!h didn't work for byebug)

Body:
You can use:

eval h

Byebug Guide: https://github.com/deivid-rodriguez/byebug/blob/master/GUIDE.md


问:
MySQL date format convert "Fri, 06 Nov 2015 04:06:05 -0500"
I have "Fri, 06 Nov 2015 04:06:05 -0500" date format in MySQL.

I want to convert it to Y-m-d H:i:s format within MySQL query. Can anyone please help?

I tried this DATE_FORMAT("Fri, 06 Nov 2015 04:06:05 -0500", '%Y-%m-%d H:i:s') but didn't work.

答:
DATE_FORMAT doesn't recognize the string you passed as a date, you have to use STR_TO_DATE() and match the string as follows:

```<code>STR_TO_DATE("Fri, 06 Nov 2015 04:06:05 -0500",'%a, %d %b %Y %H:%i:%s');
</code>```

This already outputs in Y-m-d H:i:s format.

Body:
DATE_FORMAT doesn't recognize the string you passed as a date, you have to use STR_TO_DATE() and match the string as follows:

STR_TO_DATE("Fri, 06 Nov 2015 04:06:05 -0500",'%a, %d %b %Y %H:%i:%s');

This already outputs in Y-m-d H:i:s format.


问:
java.lang.NoClassDefFoundError when using large icon in notification
When using a large icon in a notification this error appears and the app crashes:

```<code>  06-06 19:53:34.688 25207-25207/com.example.hadi.music E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.hadi.music, PID: 25207
    java.lang.NoClassDefFoundError: Failed resolution of: Landroid/graphics/drawable/Icon;
        at com.example.hadi.music.service.MediaPlayerService.buildNotification(MediaPlayerService.java:90)
        at com.example.hadi.music.service.MediaPlayerService.access$100(MediaPlayerService.java:25)
        at com.example.hadi.music.service.MediaPlayerService$1.onPlay(MediaPlayerService.java:126)
        at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1150)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.Icon" on path: DexPathList[[zip file "/data/app/com.example.hadi.music-2/base.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at com.example.hadi.music.service.MediaPlayerService.buildNotification(MediaPlayerService.java:90)
        at com.example.hadi.music.service.MediaPlayerService.access$100(MediaPlayerService.java:25)
        at com.example.hadi.music.service.MediaPlayerService$1.onPlay(MediaPlayerService.java:126)
        at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1150)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
        Suppressed: java.lang.ClassNotFoundException: android.graphics.drawable.Icon
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                ... 12 more

    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
</code>```

I'm using this method to load the bitmap from url :

```<code>.setLargeIcon(Icon.createWithBitmap(utilities.getBitmapFromURL(MusicPlayActivity.base)))

public Bitmap getBitmapFromURL(String strURL) {
        try {
            URL url = new URL(strURL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
</code>```

How can fix this problem?

答: This issue is also reported in google issue tracker here. And according to this answer here, this issue can be solved by updating your libraries to API 27 and using support library v27 or above. Do reply about whether it was solved using this or not.</p>

Body:
When using a large icon in a notification this error appears and the app crashes:

  06-06 19:53:34.688 25207-25207/com.example.hadi.music E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.hadi.music, PID: 25207
    java.lang.NoClassDefFoundError: Failed resolution of: Landroid/graphics/drawable/Icon;
        at com.example.hadi.music.service.MediaPlayerService.buildNotification(MediaPlayerService.java:90)
        at com.example.hadi.music.service.MediaPlayerService.access$100(MediaPlayerService.java:25)
        at com.example.hadi.music.service.MediaPlayerService$1.onPlay(MediaPlayerService.java:126)
        at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1150)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.Icon" on path: DexPathList[[zip file "/data/app/com.example.hadi.music-2/base.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at com.example.hadi.music.service.MediaPlayerService.buildNotification(MediaPlayerService.java:90)
        at com.example.hadi.music.service.MediaPlayerService.access$100(MediaPlayerService.java:25)
        at com.example.hadi.music.service.MediaPlayerService$1.onPlay(MediaPlayerService.java:126)
        at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1150)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
        Suppressed: java.lang.ClassNotFoundException: android.graphics.drawable.Icon
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                ... 12 more

    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

I'm using this method to load the bitmap from url :

.setLargeIcon(Icon.createWithBitmap(utilities.getBitmapFromURL(MusicPlayActivity.base)))

public Bitmap getBitmapFromURL(String strURL) {
        try {
            URL url = new URL(strURL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

How can fix this problem?


问:
how can search people by email address in google plus by google api?
I want to use google api to find people username in google plus by their email address , i have ?

 I used follow this to check people search in google api, but when enter email address , return nothing.

how can solve this my problem ?

答: Email addresses are not searchable on Google+.</p>


问:
Run curl inside php
I want to execute Curl code inside PHP.

```<code>curl -X POST 'https://api.sightengine.com/1.0/check.json' \
     -F 'api_user=1********5' \
     -F 'api_secret=q**************Q' \
     -F 'media=@/full/path/to/image.jpg' \
     -F 'models=nudity'
</code>```

Above code has four parameters to pass to the api. Below PHP code I tried to execute:

```<code>function image()
{
    $body_data = http_build_query(array('api_user' => 1********5,
                       'api_secret' => 'q**************Q',
                       'media' => $_FILES['image']['name'],
                       'models' => 'nudity'));

    // Configure cURL
    $image_curl = curl_init();
    curl_setopt($image_curl, CURLOPT_URL, "https://api.sightengine.com/1.0/check.json");
    curl_setopt($image_curl, CURLOPT_POST, true); // Use POST
    curl_setopt($image_curl, CURLOPT_POSTFIELDS, $body_data); // Setup post body
    curl_setopt($image_curl, CURLOPT_RETURNTRANSFER, true); // Receive server response

    // Execute request and read responce
    $session_response = curl_exec($image_curl);
    $response = json_decode($session_response);

    print_r($response);
}
</code>```

Response:

stdClass Object ( [status] => failure [request] => stdClass Object ( [id] => req_2365jHPuLcC6Bydh7WNd7 [timestamp] => 1512542730.57 [operations] => 0 ) [error] => stdClass Object ( [type] => argument_error [code] => 4 [message] => No media specified ) )

Now the problem is fro the media and models parameters.

I'm not sure the file path to media parameter has some problem. And do I want to and an additional @ in-front of the path.

I'm I defined all parameters in $body_data array and passing them to the CURLOPT_URL properly.

Please help me to solve this issue. When I try this in POSTMAN it works fine. Thanks in advance.

答:
You don't need to use http_build_query.

PHP 5.5, 5.6 etc supported to pass @ sign, but deprecated in PHP 7. Now we can use https://secure.php.net/manual/en/class.curlfile.php .

```<code>$body_data = array(
    'api_user' => '3454',
    'api_secret' => 'q**************Q',
    'models' => 'nudity'
);

$body_data['media'] = new CurlFile(realpath('file.jpg'));

// Configure cURL
$image_curl = curl_init();
curl_setopt($image_curl, CURLOPT_URL, "https://api.sightengine.com/1.0/check.json");
curl_setopt($image_curl, CURLOPT_POST, true); // Use POST
curl_setopt($image_curl, CURLOPT_POSTFIELDS, $body_data); // Setup post body
curl_setopt($image_curl, CURLOPT_RETURNTRANSFER, true); // Receive server response

// Execute request and read responce
$session_response = curl_exec($image_curl);
$response = json_decode($session_response);
</code>```

Title: Run curl inside php

Body:
I want to execute Curl code inside PHP.

curl -X POST 'https://api.sightengine.com/1.0/check.json' \
     -F 'api_user=1********5' \
     -F 'api_secret=q**************Q' \
     -F 'media=@/full/path/to/image.jpg' \
     -F 'models=nudity'

Above code has four parameters to pass to the api. Below PHP code I tried to execute:

function image()
{
    $body_data = http_build_query(array('api_user' => 1********5,
                       'api_secret' => 'q**************Q',
                       'media' => $_FILES['image']['name'],
                       'models' => 'nudity'));

    // Configure cURL
    $image_curl = curl_init();
    curl_setopt($image_curl, CURLOPT_URL, "https://api.sightengine.com/1.0/check.json");
    curl_setopt($image_curl, CURLOPT_POST, true); // Use POST
    curl_setopt($image_curl, CURLOPT_POSTFIELDS, $body_data); // Setup post body
    curl_setopt($image_curl, CURLOPT_RETURNTRANSFER, true); // Receive server response

    // Execute request and read responce
    $session_response = curl_exec($image_curl);
    $response = json_decode($session_response);

    print_r($response);
}

Response:

stdClass Object ( [status] => failure [request] => stdClass Object ( [id] => req_2365jHPuLcC6Bydh7WNd7 [timestamp] => 1512542730.57 [operations] => 0 ) [error] => stdClass Object ( [type] => argument_error [code] => 4 [message] => No media specified ) )

Now the problem is fro the media and models parameters.

I'm not sure the file path to media parameter has some problem. And do I want to and an additional @ in-front of the path.

I'm I defined all parameters in $body_data array and passing them to the CURLOPT_URL properly.

Please help me to solve this issue. When I try this in POSTMAN it works fine. Thanks in advance.

Body:
You don't need to use http_build_query.

PHP 5.5, 5.6 etc supported to pass @ sign, but deprecated in PHP 7. Now we can use https://secure.php.net/manual/en/class.curlfile.php .

$body_data = array(
    'api_user' => '3454',
    'api_secret' => 'q**************Q',
    'models' => 'nudity'
);

$body_data['media'] = new CurlFile(realpath('file.jpg'));

// Configure cURL
$image_curl = curl_init();
curl_setopt($image_curl, CURLOPT_URL, "https://api.sightengine.com/1.0/check.json");
curl_setopt($image_curl, CURLOPT_POST, true); // Use POST
curl_setopt($image_curl, CURLOPT_POSTFIELDS, $body_data); // Setup post body
curl_setopt($image_curl, CURLOPT_RETURNTRANSFER, true); // Receive server response

// Execute request and read responce
$session_response = curl_exec($image_curl);
$response = json_decode($session_response);


问:
UWP: how to prevent page-level scroll bounce effect when scrolling inside a list?
I've got the following simple XAML page setup:

```<code><Page ...>
    <ScrollViewer>
        <StackPanel>
            <Border Height="100">
                <TextBlock Text="Block 1" />
            </Border>
            <ListView Height="200">
                <ListViewItem Content="Lorem" />
                <ListViewItem Content="Ipsum" />
                <ListViewItem Content="Lorem" />
                <ListViewItem Content="Ipsum" />
                <ListViewItem Content="Lorem" />
                <ListViewItem Content="Ipsum" />
            </ListView>
            <Border Height="800">
                <TextBlock Text="Block 2" />
            </Border>
        </StackPanel>
    </ScrollViewer>
</Page>
</code>```

Typically I'm happy with the scroll "bounce" effect that the top-level ScrollViewer provides when the user scrolls to the top/bottom of the page. However, when scrolling inside the ListView, I get a double-bounce; i.e., both the ListView and the ScrollViewer give that elastic stretch. I feel that it's an odd user experience for this to happen.

Is there any way to keep the ListView's bounce while preventing it from passing on to the parent scroll container?

答:
This is happen only on touch input not on mouse input , there may be many ways but it is fastest and easy way.

This will work

XAML

```<code><ScrollViewer Name="sv"> <!-- Name added -->
    <StackPanel>
        <Border Height="100">
            <TextBlock Text="Block 1" />
        </Border>
        <ListView Name="lv" Height="200"> <!-- Name added -->
            <ListViewItem Content="Lorem" />
            <ListViewItem Content="Ipsum" />
            <ListViewItem Content="Lorem" />
            <ListViewItem Content="Ipsum" />
            <ListViewItem Content="Lorem" />
            <ListViewItem Content="Ipsum" />
        </ListView>
        <Border Height="800">
            <TextBlock Text="Block 2" />
        </Border>
    </StackPanel>
</ScrollViewer>
</code>```

C#

```<code>public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        //Add this two event handlers and you can add this event handler from xaml also.
        lv.AddHandler(UIElement.PointerEnteredEvent, new PointerEventHandler(OnPointerEntered), true);
        lv.AddHandler(UIElement.PointerExitedEvent, new PointerEventHandler(OnPointerExited), true);
    }

    private void OnPointerEntered(object sender, PointerRoutedEventArgs e)
    {
        sv.VerticalScrollMode = ScrollMode.Disabled;
    }

    private void OnPointerExited(object sender, PointerRoutedEventArgs e)
    {
        sv.VerticalScrollMode = ScrollMode.Enabled;
    }
}
</code>```

Body:
I've got the following simple XAML page setup:

<Page ...>
    <ScrollViewer>
        <StackPanel>
            <Border Height="100">
                <TextBlock Text="Block 1" />
            </Border>
            <ListView Height="200">
                <ListViewItem Content="Lorem" />
                <ListViewItem Content="Ipsum" />
                <ListViewItem Content="Lorem" />
                <ListViewItem Content="Ipsum" />
                <ListViewItem Content="Lorem" />
                <ListViewItem Content="Ipsum" />
            </ListView>
            <Border Height="800">
                <TextBlock Text="Block 2" />
            </Border>
        </StackPanel>
    </ScrollViewer>
</Page>

Typically I'm happy with the scroll "bounce" effect that the top-level ScrollViewer provides when the user scrolls to the top/bottom of the page. However, when scrolling inside the ListView, I get a double-bounce; i.e., both the ListView and the ScrollViewer give that elastic stretch. I feel that it's an odd user experience for this to happen.

Is there any way to keep the ListView's bounce while preventing it from passing on to the parent scroll container?

Body:
This is happen only on touch input not on mouse input , there may be many ways but it is fastest and easy way.

This will work

XAML

<ScrollViewer Name="sv"> <!-- Name added -->
    <StackPanel>
        <Border Height="100">
            <TextBlock Text="Block 1" />
        </Border>
        <ListView Name="lv" Height="200"> <!-- Name added -->
            <ListViewItem Content="Lorem" />
            <ListViewItem Content="Ipsum" />
            <ListViewItem Content="Lorem" />
            <ListViewItem Content="Ipsum" />
            <ListViewItem Content="Lorem" />
            <ListViewItem Content="Ipsum" />
        </ListView>
        <Border Height="800">
            <TextBlock Text="Block 2" />
        </Border>
    </StackPanel>
</ScrollViewer>

C#

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        //Add this two event handlers and you can add this event handler from xaml also.
        lv.AddHandler(UIElement.PointerEnteredEvent, new PointerEventHandler(OnPointerEntered), true);
        lv.AddHandler(UIElement.PointerExitedEvent, new PointerEventHandler(OnPointerExited), true);
    }

    private void OnPointerEntered(object sender, PointerRoutedEventArgs e)
    {
        sv.VerticalScrollMode = ScrollMode.Disabled;
    }

    private void OnPointerExited(object sender, PointerRoutedEventArgs e)
    {
        sv.VerticalScrollMode = ScrollMode.Enabled;
    }
}


问:
Loop json variable in javascript
I have a variable in which I get json value. The value comes from 4 tables. I want to loop each table while assigning values. Below is my code

```<code>var dataResponse = JSON.parse(response);
</code>```

I get values from table as

dataResponse.Table[0] , dataResponse.Table[1] ....

how to loop it in javascript. Please help

My json value

```<code>{
  "Table": [{
    "JOB_PROGRESS_ID": 4.0,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU",
    "LINK_ID": "12345678",
    "SPAN_TYPE": "INTERCITY",
    "NE_SPAN_LENGTH": 200.0,
    "HOTO_OFFERED_LENGTH": 26.0,
    "LIT_OFFERED_LENGTH": 30.0,
    "HOTO_ACTUAL_LENGTH": 20.0,
    "LIT_ACTUAL_LENGTH": 15.0,
    "HOTO_OFFERED_DATE": null,
    "HOTO_ACCEPTENCE_DATE": null,
    "LIT_ACCEPTENCE_DATE": null,
    "APPROV_REJECT_REMARK": null,
    "ISABDMISSING": 1.0,
    "JOB_ID": 1.0,
    "MAINTENANCEZONECODE": "INMUKLYN01"
  }],
  "Table1": [{
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.09,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": null,
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 12.41,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.01,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.46,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.02,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 6,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "CLAMP",
    "ASBUILT_LENGTH": 0.48,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 5,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.14,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 5.45,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": null,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.23,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }],
  "Table2": [],
  "Table3": [{
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }]
}
</code>```

UPDATE

```<code>var dataResponse = JSON.parse(response);

for (var i = 0; i < dataResponse.Table.length; i++) {
  if (dataResponse.Table[i] != "" || dataResponse.Table[i] != null) {
    $("#spnLinkId").text(dataResponse.Table[i].LINK_ID);
    $("#spnSpanLength").text(dataResponse.Table[i].NE_SPAN_LENGTH);
    $("#txtFiberActlength").val(dataResponse.Table[i].HOTO_ACTUAL_LENGTH);
    $("#txtLITActlength").val(dataResponse.Table[i].LIT_ACTUAL_LENGTH);
  }
  if (dataResponse.Table[i].ISABDMISSING != "" || dataResponse.Table[i].ISABDMISSING != null) {

    if (dataResponse.Table[i].ISABDMISSING == 1) {
      $("#FEmissingAsBuiltYes").prop("checked", true);
    } else {
      $("#FEmissingAsBuiltNo").prop("checked", true);
    }
  }
}
</code>```

答:
var dataResponse = {
  "Table": [{
    "JOB_PROGRESS_ID": 4.0,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU",
    "LINK_ID": "12345678",
    "SPAN_TYPE": "INTERCITY",
    "NE_SPAN_LENGTH": 200.0,
    "HOTO_OFFERED_LENGTH": 26.0,
    "LIT_OFFERED_LENGTH": 30.0,
    "HOTO_ACTUAL_LENGTH": 20.0,
    "LIT_ACTUAL_LENGTH": 15.0,
    "HOTO_OFFERED_DATE": null,
    "HOTO_ACCEPTENCE_DATE": null,
    "LIT_ACCEPTENCE_DATE": null,
    "APPROV_REJECT_REMARK": null,
    "ISABDMISSING": 1.0,
    "JOB_ID": 1.0,
    "MAINTENANCEZONECODE": "INMUKLYN01"
  }],
  "Table1": [{
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.09,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": null,
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 12.41,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.01,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.46,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.02,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 6,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "CLAMP",
    "ASBUILT_LENGTH": 0.48,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 5,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.14,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 5.45,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": null,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.23,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }],
  "Table2": [],
  "Table3": [{
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }]
}
for(count in dataResponse){
 console.log(`[[[[[[[[[[[[[${count}]]]]]]]]]]]]]]`);
 for(item of dataResponse[count]){
    console.log(item);
  }
}

  ```

You can get easily the value of dataResponse with for-of and for-in.

First, you have to get the object name using for-in.

Second, you can control the name of tables. (Table, Table1 ...)

for(item of dataResponse[table]) will return the value of each table.

Title: Loop json variable in javascript

Body:
I have a variable in which I get json value. The value comes from 4 tables. I want to loop each table while assigning values. Below is my code

var dataResponse = JSON.parse(response);

I get values from table as

dataResponse.Table[0] , dataResponse.Table[1] ....

how to loop it in javascript. Please help

My json value

{
  "Table": [{
    "JOB_PROGRESS_ID": 4.0,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU",
    "LINK_ID": "12345678",
    "SPAN_TYPE": "INTERCITY",
    "NE_SPAN_LENGTH": 200.0,
    "HOTO_OFFERED_LENGTH": 26.0,
    "LIT_OFFERED_LENGTH": 30.0,
    "HOTO_ACTUAL_LENGTH": 20.0,
    "LIT_ACTUAL_LENGTH": 15.0,
    "HOTO_OFFERED_DATE": null,
    "HOTO_ACCEPTENCE_DATE": null,
    "LIT_ACCEPTENCE_DATE": null,
    "APPROV_REJECT_REMARK": null,
    "ISABDMISSING": 1.0,
    "JOB_ID": 1.0,
    "MAINTENANCEZONECODE": "INMUKLYN01"
  }],
  "Table1": [{
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.09,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": null,
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 12.41,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.01,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.46,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.02,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 6,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "CLAMP",
    "ASBUILT_LENGTH": 0.48,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 5,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.14,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 5.45,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": null,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.23,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }],
  "Table2": [],
  "Table3": [{
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }]
}

UPDATE

var dataResponse = JSON.parse(response);

for (var i = 0; i < dataResponse.Table.length; i++) {
  if (dataResponse.Table[i] != "" || dataResponse.Table[i] != null) {
    $("#spnLinkId").text(dataResponse.Table[i].LINK_ID);
    $("#spnSpanLength").text(dataResponse.Table[i].NE_SPAN_LENGTH);
    $("#txtFiberActlength").val(dataResponse.Table[i].HOTO_ACTUAL_LENGTH);
    $("#txtLITActlength").val(dataResponse.Table[i].LIT_ACTUAL_LENGTH);
  }
  if (dataResponse.Table[i].ISABDMISSING != "" || dataResponse.Table[i].ISABDMISSING != null) {

    if (dataResponse.Table[i].ISABDMISSING == 1) {
      $("#FEmissingAsBuiltYes").prop("checked", true);
    } else {
      $("#FEmissingAsBuiltNo").prop("checked", true);
    }
  }
}

Body:
var dataResponse = {
  "Table": [{
    "JOB_PROGRESS_ID": 4.0,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU",
    "LINK_ID": "12345678",
    "SPAN_TYPE": "INTERCITY",
    "NE_SPAN_LENGTH": 200.0,
    "HOTO_OFFERED_LENGTH": 26.0,
    "LIT_OFFERED_LENGTH": 30.0,
    "HOTO_ACTUAL_LENGTH": 20.0,
    "LIT_ACTUAL_LENGTH": 15.0,
    "HOTO_OFFERED_DATE": null,
    "HOTO_ACCEPTENCE_DATE": null,
    "LIT_ACCEPTENCE_DATE": null,
    "APPROV_REJECT_REMARK": null,
    "ISABDMISSING": 1.0,
    "JOB_ID": 1.0,
    "MAINTENANCEZONECODE": "INMUKLYN01"
  }],
  "Table1": [{
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.09,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": null,
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 12.41,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 3,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.01,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.46,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "HDD",
    "ASBUILT_LENGTH": 0.02,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 6,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.33,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 7,
    "ROUTETYPE": "CLAMP",
    "ASBUILT_LENGTH": 0.48,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 5,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.14,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": 8,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 5.45,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }, {
    "NUMBEROFDUCTS": null,
    "ROUTETYPE": "OT",
    "ASBUILT_LENGTH": 0.23,
    "SPAN_ID": "MUMUMBMUKLYNSPN001_BU"
  }],
  "Table2": [],
  "Table3": [{
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }, {
    "UMS_GROUP_ASS_BY_NAME": "Construction_Eng",
    "MODIFIED_BY": "HARDIK1.SHAH",
    "MODIFIED_DATE": "2017-11-27T12:07:39",
    "APPROVED_DATE": null,
    "REJECTED_DATE": null
  }]
}
for(count in dataResponse){
 console.log(`[[[[[[[[[[[[[${count}]]]]]]]]]]]]]]`);
 for(item of dataResponse[count]){
    console.log(item);
  }
}

You can get easily the value of dataResponse with for-of and for-in.

First, you have to get the object name using for-in.

Second, you can control the name of tables. (Table, Table1 ...)

for(item of dataResponse[table]) will return the value of each table.


问:
Is there a way to check for shift held down THEN control held down for each input?
I'm trying to use _getch to get keyboard strokes for incrementing money in a game. If I want the money to be incremented faster, in 10's while shift is held down and 100's control is held down what would be the best way to do that? If I just check for shifts it's easy enough, but if I want to check for a shift then a control afterwards it won't work.

For instance checking to increment by 1 or 10 I'd do something like this

```<code>key = _getch();
if (key == 224)
{
    key = _getch();
    if (key == 75) // left arrow
    {
        if (GetAsyncKeyState(VK_SHIFT)
            for (int i = 0; i < 10; i++) // go left 10 times
                    left();
        else
            left();
    }
}
</code>```

If I add an else if for control for 100's it will NOT work. Most likely because running the GetAsyncKeyState fucntion again makes it not read the key state properly.

```<code>else if (GetAsyncKeyState(VK_CONTROL)
    for (int i = 0; i < 100; i++) // go left 100 times
        left();
</code>```

Any possible workaround? Thanks!

答: How about "if(GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_CONTROL))"? You can not use one GAKS call to check multiple keys.</p>

Body:
I'm trying to use _getch to get keyboard strokes for incrementing money in a game. If I want the money to be incremented faster, in 10's while shift is held down and 100's control is held down what would be the best way to do that? If I just check for shifts it's easy enough, but if I want to check for a shift then a control afterwards it won't work.

For instance checking to increment by 1 or 10 I'd do something like this

key = _getch();
if (key == 224)
{
    key = _getch();
    if (key == 75) // left arrow
    {
        if (GetAsyncKeyState(VK_SHIFT)
            for (int i = 0; i < 10; i++) // go left 10 times
                    left();
        else
            left();
    }
}

If I add an else if for control for 100's it will NOT work. Most likely because running the GetAsyncKeyState fucntion again makes it not read the key state properly.

else if (GetAsyncKeyState(VK_CONTROL)
    for (int i = 0; i < 100; i++) // go left 100 times
        left();

Any possible workaround? Thanks!


问:
How can I compare all the values of an enum with a given array in java?
I have an enum class with values:

```<code>  enum carBrand{BMW,HONDA,MERC,AUDI};
</code>```

And there's an array called Sales with Array values:

```<code> sales[] = {CHEVVY, BMW , MERC, AUDI};
</code>```

So how could I check that the sales[] has all the values of enum carBrand?

I'm trying to put it in a for loop as:

```<code> for(int i = 0; i<sales.length;i++){
     if(carBrand.sales == sales[i]){
        return true;
     }
 return false;
 }
</code>```

答:
Add carBrand values to list

loop sales, remove the carBrand from the list

check if list is empty, if so they have all the values

Note: Class names should be names in PascalCase (CarBrand, Sales)

Body:
I have an enum class with values:

  enum carBrand{BMW,HONDA,MERC,AUDI};

And there's an array called Sales with Array values:

 sales[] = {CHEVVY, BMW , MERC, AUDI};

So how could I check that the sales[] has all the values of enum carBrand?

I'm trying to put it in a for loop as:

 for(int i = 0; i<sales.length;i++){
     if(carBrand.sales == sales[i]){
        return true;
     }
 return false;
 }


问:
How can i convert an xml file into JSON using python?
I have an XML file which I want to convert into JSON file using python, but its nt working out for me.

```<code><?xml version="1.0"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>
</code>```

The above XML file I am parsing using ElementTree and giving it to Simplejson to serialize like this:

```<code>from xml.etree import ElementTree as ET
import simplejson

tree = ET.parse(Xml_file_path)
simplejson.dumps(tree)
</code>```

It gives me an error: TypeError: xml.etree.ElementTree.ElementTree object at 0x00C49DD0 is not JSON serializable.

答:
You can try to use xmljson. The code for the same is </p>

```<code>from xmljson import badgerfish as bf
from xml.etree.ElementTree import fromstring
s = '''<?xml version="1.0"?>
<note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
</note>'''
json.dumps(bf.data(fromstring(s)))
</code>```

Body:
I have an XML file which I want to convert into JSON file using python, but its nt working out for me.

<?xml version="1.0"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    Don't forget me this weekend!
</note>

The above XML file I am parsing using ElementTree and giving it to Simplejson to serialize like this:

from xml.etree import ElementTree as ET
import simplejson

tree = ET.parse(Xml_file_path)
simplejson.dumps(tree)

It gives me an error: TypeError: xml.etree.ElementTree.ElementTree object at 0x00C49DD0 is not JSON serializable.

Body:
You can try to use xmljson. The code for the same is

from xmljson import badgerfish as bf
from xml.etree.ElementTree import fromstring
s = '''<?xml version="1.0"?>
<note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
</note>'''
json.dumps(bf.data(fromstring(s)))


问:
Magento Product rating calculation performance
If my web pages show many products (include title and rating), then web page needs to calculate rating percentage by every products with following code.
I am sure this kinds of calculation will slow down my web page.
Is this the only choice that i can choose, or is there any better performance code that i can use?</p>

```<code>            if (count($reviews) > 0)
            {
                foreach ($reviews->getItems() as $review)
                {
                    foreach( $review->getRatingVotes() as $vote )
                    {
                        $ratings[] = $vote->getPercent();
                    }
                }
                $avg = array_sum($ratings)/count($ratings);
            }
</code>```

答:
You can use review model of Magento's core</p>

```<code><?php
$store_id = Mage::app()->getStore()->getId(); //get store id

//in your product loop

$review_summary = Mage::getModel('review/review_summary')->setStoreId($store_id)->load($_product->getId()); //pass product's id to review model
echo $review_summary['rating_summary']; //get rating summary

?>
</code>```

Body:
If my web pages show many products (include title and rating), then web page needs to calculate rating percentage by every products with following code.
I am sure this kinds of calculation will slow down my web page.
Is this the only choice that i can choose, or is there any better performance code that i can use?

            if (count($reviews) > 0)
            {
                foreach ($reviews->getItems() as $review)
                {
                    foreach( $review->getRatingVotes() as $vote )
                    {
                        $ratings[] = $vote->getPercent();
                    }
                }
                $avg = array_sum($ratings)/count($ratings);
            }

Body:
You can use review model of Magento's core

<?php
$store_id = Mage::app()->getStore()->getId(); //get store id

//in your product loop

$review_summary = Mage::getModel('review/review_summary')->setStoreId($store_id)->load($_product->getId()); //pass product's id to review model
echo $review_summary['rating_summary']; //get rating summary

?>