问:
Trying to animate the a div as the user clicks on it.
I am a beginner programmer trying to create my first project that combines html, css and javascript. I have researched the topic for hours now and I would like to find an effective solution and explanation. I have an html and a corresponding java and css file. I am trying to create a memory game. I am trying to flip the cards when the user clicks it. I have read various solutions but none that I could apply straight. I am looking for a pure javascript/css solution. Thanks in advance.

```<code><!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="style.css"> <!--making a link to the css stylesheet-->
    <script src="scripts.js" type="text/javascript"></script>
    <meta charset="UTF-8">
    <title>Matching Game</title>
</head>
<body>
    <div class = "title"><h1>Matching Game</h1></div>
    <div class = "infobar">
        <span>
            __stars__
        </span>
        <span>
            __move__
        </span>
        <span>
            __timer__
        </span>
        <span>
            __restart__
        </span>
    </div>
    <div class = "gameboard">
        <div class = "cardrows">
            <div class = "flip1">
                <div id = "card1" class = "card, off" onclick="flip(this.id)">
                    <div class = "cardback">
                        2
                    </div>
                    <div class = "cardfront ">
                        1
                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
        <div class = "cardrows">
            <div class = "flip1">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
        <div class = "cardrows">
            <div class = "flip1">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
        <div class = "cardrows">
            <div class = "flip1">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
</code>```

CSS

```<code>* {
    -webkit-box-sizing: border-box; /*few lines of code for compatibility and for correct box resizing*/
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
    background-color: rgb(228, 227, 225);
}

.title {
    text-align: center;
    color: black;
}

.gameboard {
    width: 530px;
    height: 530px;
    background-color: #92bbce;
    box-shadow: 0 0 11px 5px #00BCD4;
    position: fixed;
    right: 0;
    left: 0;
    margin-right: auto;
    margin-left: auto;
    margin-top: 20px;
    margin-bottom: 20px;
}

.cardrows {
    width: 524px;
    height: 125px;
    margin-left: 3px;
    margin-right: 3px;
    margin-top: 6px;
    margin-bottom: 6px;
    background-color: transparent;
    position: relative;
}

.infobar {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}

.cardback, .cardfront, .flip1, .flip2, .flip3, .flip4 {
    width: 125px;
    height: 125px;
}

.cardback, .cardfront {
/* hide back during swap */
    backface-visibility: hidden;

    position: absolute;
    top: 0;
    left: 0;

    transition: transform 1s;
    transform-style: preserve-3d;
}

.cardfront {
/* front placed above back element */
    z-index: 2;
    transform: rotateY(0deg);

    background-color: #108DC0;
}

.cardback {
/* back hidden at start */
    transform: rotateY(180deg);
}

.card {
    position: relative;
}

.flip1, .flip2, .flip3, .flip4 {
/*container keeps perspective */
    perspective: 1000px;
    position: absolute;
}

.flip1 {
    left: 3px;
}

.flip2 {
    left: 134px;
}

.flip3 {
    left: 265px;
}

.flip4 {
    left: 396px;
}

.on {
    -webkit-transform: rotateY( 180deg );
    -moz-transform: rotateY( 180deg );
    -o-transform: rotateY( 180deg );

    transform: rotateY( 180deg );
}

.off {
    -webkit-transform: rotateY( 0deg );
    -moz-transform: rotateY( 0deg );
    -o-transform: rotateY( 0deg );

    transform: rotateY( 0deg );

}
</code>```

java:

```<code>function flip(el) {
    console.log("flip called");
    var elem = document.getElementById(el);
    console.log(elem);
    elem.className = "on";
    console.log(elem);
}
</code>```

答:
If you're just trying to get the card to flip, you were pretty close!

I've just added these two css styles

```<code>transition: 1.0s;
transform-style: preserve-3d;
</code>```

to the .on and .off classes (they need to know how long the animation runs!)

function flip(el) {
  console.log("flip called");
  var elem = document.getElementById(el);
  console.log(elem);
  elem.className = "on";
  console.log(elem);
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>* {
  -webkit-box-sizing: border-box;
  /*few lines of code for compatibility and for correct box resizing*/
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
  background-color: rgb(228, 227, 225);
}

.title {
  text-align: center;
  color: black;
}

.gameboard {
  width: 530px;
  height: 530px;
  background-color: #92bbce;
  box-shadow: 0 0 11px 5px #00BCD4;
  position: fixed;
  right: 0;
  left: 0;
  margin-right: auto;
  margin-left: auto;
  margin-top: 20px;
  margin-bottom: 20px;
}

.cardrows {
  width: 524px;
  height: 125px;
  margin-left: 3px;
  margin-right: 3px;
  margin-top: 6px;
  margin-bottom: 6px;
  background-color: transparent;
  position: relative;
}

.infobar {
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.cardback,
.cardfront,
.flip1,
.flip2,
.flip3,
.flip4 {
  width: 125px;
  height: 125px;
}

.cardback,
.cardfront {
  /* hide back during swap */
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  transition: transform 1s;
  transform-style: preserve-3d;
}

.cardfront {
  /* front placed above back element */
  z-index: 2;
  transform: rotateY(0deg);
  background-color: #108DC0;
}

.cardback {
  /* back hidden at start */
  transform: rotateY(180deg);
}

.card {
  position: relative;
}

.flip1,
.flip2,
.flip3,
.flip4 {
  /*container keeps perspective */
  perspective: 1000px;
  position: absolute;
}

.flip1 {
  left: 3px;
}

.flip2 {
  left: 134px;
}

.flip3 {
  left: 265px;
}

.flip4 {
  left: 396px;
}

.on {
  transition: 1.0s;
  transform-style: preserve-3d;
  -webkit-transform: rotateY( 180deg);
  -moz-transform: rotateY( 180deg);
  -o-transform: rotateY( 180deg);
  transform: rotateY( 180deg);
}

.off {
  transition: 1.0s;
  transform-style: preserve-3d;
  -webkit-transform: rotateY( 0deg);
  -moz-transform: rotateY( 0deg);
  -o-transform: rotateY( 0deg);
  transform: rotateY( 0deg);
}</code>```

Matching Game

            __stars__

            __move__

            __timer__

            __restart__

          2

          1

```

Body:
I am a beginner programmer trying to create my first project that combines html, css and javascript. I have researched the topic for hours now and I would like to find an effective solution and explanation. I have an html and a corresponding java and css file. I am trying to create a memory game. I am trying to flip the cards when the user clicks it. I have read various solutions but none that I could apply straight. I am looking for a pure javascript/css solution. Thanks in advance.

<!DOCTYPE html>

    <link rel="stylesheet" href="style.css">

    <meta charset="UTF-8">
    <title>Matching Game</title>

Matching Game

            __stars__

            __move__

            __timer__

            __restart__

                        2

                        1

CSS

* {
    -webkit-box-sizing: border-box; /*few lines of code for compatibility and for correct box resizing*/
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
    background-color: rgb(228, 227, 225);
}

.title {
    text-align: center;
    color: black;
}

.gameboard {
    width: 530px;
    height: 530px;
    background-color: #92bbce;
    box-shadow: 0 0 11px 5px #00BCD4;
    position: fixed;
    right: 0;
    left: 0;
    margin-right: auto;
    margin-left: auto;
    margin-top: 20px;
    margin-bottom: 20px;
}

.cardrows {
    width: 524px;
    height: 125px;
    margin-left: 3px;
    margin-right: 3px;
    margin-top: 6px;
    margin-bottom: 6px;
    background-color: transparent;
    position: relative;
}

.infobar {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}

.cardback, .cardfront, .flip1, .flip2, .flip3, .flip4 {
    width: 125px;
    height: 125px;
}

.cardback, .cardfront {
/* hide back during swap */
    backface-visibility: hidden;

    position: absolute;
    top: 0;
    left: 0;

    transition: transform 1s;
    transform-style: preserve-3d;
}

.cardfront {
/* front placed above back element */
    z-index: 2;
    transform: rotateY(0deg);

    background-color: #108DC0;
}

.cardback {
/* back hidden at start */
    transform: rotateY(180deg);
}

.card {
    position: relative;
}

.flip1, .flip2, .flip3, .flip4 {
/*container keeps perspective */
    perspective: 1000px;
    position: absolute;
}

.flip1 {
    left: 3px;
}

.flip2 {
    left: 134px;
}

.flip3 {
    left: 265px;
}

.flip4 {
    left: 396px;
}

.on {
    -webkit-transform: rotateY( 180deg );
    -moz-transform: rotateY( 180deg );
    -o-transform: rotateY( 180deg );

    transform: rotateY( 180deg );
}

.off {
    -webkit-transform: rotateY( 0deg );
    -moz-transform: rotateY( 0deg );
    -o-transform: rotateY( 0deg );

    transform: rotateY( 0deg );

}

java:

function flip(el) {
    console.log("flip called");
    var elem = document.getElementById(el);
    console.log(elem);
    elem.className = "on";
    console.log(elem);
}

Body:
If you're just trying to get the card to flip, you were pretty close!

I've just added these two css styles

transition: 1.0s;
transform-style: preserve-3d;

to the .on and .off classes (they need to know how long the animation runs!)

function flip(el) {
  console.log("flip called");
  var elem = document.getElementById(el);
  console.log(elem);
  elem.className = "on";
  console.log(elem);
}

* {
  -webkit-box-sizing: border-box;
  /*few lines of code for compatibility and for correct box resizing*/
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
  background-color: rgb(228, 227, 225);
}

.title {
  text-align: center;
  color: black;
}

.gameboard {
  width: 530px;
  height: 530px;
  background-color: #92bbce;
  box-shadow: 0 0 11px 5px #00BCD4;
  position: fixed;
  right: 0;
  left: 0;
  margin-right: auto;
  margin-left: auto;
  margin-top: 20px;
  margin-bottom: 20px;
}

.cardrows {
  width: 524px;
  height: 125px;
  margin-left: 3px;
  margin-right: 3px;
  margin-top: 6px;
  margin-bottom: 6px;
  background-color: transparent;
  position: relative;
}

.infobar {
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.cardback,
.cardfront,
.flip1,
.flip2,
.flip3,
.flip4 {
  width: 125px;
  height: 125px;
}

.cardback,
.cardfront {
  /* hide back during swap */
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  transition: transform 1s;
  transform-style: preserve-3d;
}

.cardfront {
  /* front placed above back element */
  z-index: 2;
  transform: rotateY(0deg);
  background-color: #108DC0;
}

.cardback {
  /* back hidden at start */
  transform: rotateY(180deg);
}

.card {
  position: relative;
}

.flip1,
.flip2,
.flip3,
.flip4 {
  /*container keeps perspective */
  perspective: 1000px;
  position: absolute;
}

.flip1 {
  left: 3px;
}

.flip2 {
  left: 134px;
}

.flip3 {
  left: 265px;
}

.flip4 {
  left: 396px;
}

.on {
  transition: 1.0s;
  transform-style: preserve-3d;
  -webkit-transform: rotateY( 180deg);
  -moz-transform: rotateY( 180deg);
  -o-transform: rotateY( 180deg);
  transform: rotateY( 180deg);
}

.off {
  transition: 1.0s;
  transform-style: preserve-3d;
  -webkit-transform: rotateY( 0deg);
  -moz-transform: rotateY( 0deg);
  -o-transform: rotateY( 0deg);
  transform: rotateY( 0deg);
}

<div class="title">
  <h1>Matching Game</h1>
</div>
<div class="infobar">
  <span>
            __stars__
        </span>
  <span>
            __move__
        </span>
  <span>
            __timer__
        </span>
  <span>
            __restart__
        </span>
</div>
<div class="gameboard">
  <div class="cardrows">
    <div class="flip1">
      <div id="card1" class="card, off" onclick="flip(this.id)">
        <div class="cardback">
          2
        </div>
        <div class="cardfront ">
          1
        </div>
      </div>
    </div>
    <div class="flip2">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip3">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip4">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
  </div>
  <div class="cardrows">
    <div class="flip1">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip2">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip3">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip4">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
  </div>
  <div class="cardrows">
    <div class="flip1">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip2">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip3">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip4">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
  </div>
  <div class="cardrows">
    <div class="flip1">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip2">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip3">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
    <div class="flip4">
      <div class="card">
        <div class="cardback">

        </div>
        <div class="cardfront">

        </div>
      </div>
    </div>
  </div>
</div>


来源: stackexchange

问:
Laravel get url for file in public folder from full path
In Laravel I save an uploaded folder in a directory in my public folder. I want to find a way to get the public url of this file from the file object itself.

E.g. $file is an instance of Symfony\Component\HttpFoundation\File\File. So can do $file->getRealPath() which returns something like C:\xampp\htdocs\myapp\public\uploads\2015\2\test.pdf.

How can I generate the public url for this? I tried using asset($file->getRealPath()); but this gives something like http://localhost/myapp/C:\xampp\htdocs\myapp\public\uploads\2015\2\06-12-2014-2.pdf. I.e. I need to remove the part of the path before the public folder before feeding it to asset().

I thought of doing something like

```<code>asset(str_replace(public_path(), '' , $file->getRealPath()));
</code>```

(which works, and should continue to work between environments) but I was hoping for something more elegant.

答:
Laravel provides helper functions to generate urls. For instance, if $file holds the path of your file then you can simply use the url() function to generate the public url of this file.

```<code>url($file)
</code>```

More information: https://laravel.com/docs/5.4/helpers#method-url

ContentLicense: CC BY-SA 3.0

Body:
In Laravel I save an uploaded folder in a directory in my public folder. I want to find a way to get the public url of this file from the file object itself.

E.g. $file is an instance of Symfony\Component\HttpFoundation\File\File. So can do $file->getRealPath() which returns something like C:\xampp\htdocs\myapp\public\uploads\2015\2\test.pdf.

How can I generate the public url for this? I tried using asset($file->getRealPath()); but this gives something like http://localhost/myapp/C:\xampp\htdocs\myapp\public\uploads\2015\2\06-12-2014-2.pdf. I.e. I need to remove the part of the path before the public folder before feeding it to asset().

I thought of doing something like

asset(str_replace(public_path(), '' , $file->getRealPath()));

(which works, and should continue to work between environments) but I was hoping for something more elegant.

Body:
Laravel provides helper functions to generate urls. For instance, if $file holds the path of your file then you can simply use the url() function to generate the public url of this file.

url($file)

More information: https://laravel.com/docs/5.4/helpers#method-url


问:
Only allow EC2 instance to access static website on S3
I have a static website hosted on S3, I have set all files to be public.
Also, I have an EC2 instance with nginx that acts as a reverse proxy and can access the static website, so S3 plays the role of the origin.

What I would like to do now is set all files on S3 to be private, so that the website can only be accessed by traffic coming from the nginx (EC2).

So far I have tried the following. I have created and attached a new policy role to the EC2 instance with

Policies Granting Permission: AmazonS3ReadOnlyAccess

And have rebooted the EC2 instance.

I then created a policy in my S3 bucket console > Permissions > Bucket Policy

```<code>{
    "Version": "xxxxx",
    "Id": "xxxxxxx",
    "Statement": [
        {
            "Sid": "xxxxxxx",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::XXXXXXXXXX:role/MyROLE"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::XXX-bucket/*"
        }
    ]
}
</code>```

As principal I have set the ARN I got when I created the role for the EC2 instance.

```<code>"Principal": {
                "AWS": "arn:aws:iam::XXXXXXXXXX:role/MyROLE"
            },
</code>```

However, this does not work, any help is appreciated.

答:
If the Amazon EC2 instance with nginx is merely making generic web requests to Amazon S3, then the question becomes how to identify requests coming from nginx as 'permitted', while rejecting all other requests.

One method is to use a VPC Endpoint for S3, which allows direct communication from a VPC to Amazon S3 (rather than going out an Internet Gateway).

A bucket policy can then restrict access to the bucket such that it can only be accessed via that endpoint.

Here is a bucket policy from Example Bucket Policies for VPC Endpoints for Amazon S3:

The following is an example of an S3 bucket policy that allows access to a specific bucket, examplebucket, only from the VPC endpoint with the ID vpce-1a2b3c4d. The policy uses the aws:sourceVpce condition key to restrict access to the specified VPC endpoint.

```<code>{
   "Version": "2012-10-17",
   "Id": "Policy",
   "Statement": [
     {
       "Sid": "Access-to-specific-VPCE-only",
       "Action": "s3:*",
       "Effect": "Allow",
       "Resource": ["arn:aws:s3:::examplebucket",
                    "arn:aws:s3:::examplebucket/*"],
       "Condition": {
         "StringEquals": {
           "aws:sourceVpce": "vpce-1a2b3c4d"
         }
       },
       "Principal": "*"
     }
   ]
}
</code>```

So, the complete design would be:

Object ACL: Private only (remove any current public permissions)

Bucket Policy: As above

IAM Role: Not needed

Route Table configured for VPC Endpoint

Body:
I have a static website hosted on S3, I have set all files to be public.
Also, I have an EC2 instance with nginx that acts as a reverse proxy and can access the static website, so S3 plays the role of the origin.

What I would like to do now is set all files on S3 to be private, so that the website can only be accessed by traffic coming from the nginx (EC2).

So far I have tried the following. I have created and attached a new policy role to the EC2 instance with

Policies Granting Permission: AmazonS3ReadOnlyAccess

And have rebooted the EC2 instance.

I then created a policy in my S3 bucket console > Permissions > Bucket Policy

{
    "Version": "xxxxx",
    "Id": "xxxxxxx",
    "Statement": [
        {
            "Sid": "xxxxxxx",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::XXXXXXXXXX:role/MyROLE"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::XXX-bucket/*"
        }
    ]
}

As principal I have set the ARN I got when I created the role for the EC2 instance.

"Principal": {
                "AWS": "arn:aws:iam::XXXXXXXXXX:role/MyROLE"
            },

However, this does not work, any help is appreciated.

Body:
If the Amazon EC2 instance with nginx is merely making generic web requests to Amazon S3, then the question becomes how to identify requests coming from nginx as 'permitted', while rejecting all other requests.

One method is to use a VPC Endpoint for S3, which allows direct communication from a VPC to Amazon S3 (rather than going out an Internet Gateway).

A bucket policy can then restrict access to the bucket such that it can only be accessed via that endpoint.

Here is a bucket policy from Example Bucket Policies for VPC Endpoints for Amazon S3:

The following is an example of an S3 bucket policy that allows access to a specific bucket, examplebucket, only from the VPC endpoint with the ID vpce-1a2b3c4d. The policy uses the aws:sourceVpce condition key to restrict access to the specified VPC endpoint.

{
   "Version": "2012-10-17",
   "Id": "Policy",
   "Statement": [
     {
       "Sid": "Access-to-specific-VPCE-only",
       "Action": "s3:*",
       "Effect": "Allow",
       "Resource": ["arn:aws:s3:::examplebucket",
                    "arn:aws:s3:::examplebucket/*"],
       "Condition": {
         "StringEquals": {
           "aws:sourceVpce": "vpce-1a2b3c4d"
         }
       },
       "Principal": "*"
     }
   ]
}

So, the complete design would be:

Object ACL: Private only (remove any current public permissions)

Bucket Policy: As above

IAM Role: Not needed

Route Table configured for VPC Endpoint


问:
Q: Get Item's Title Python eBay SDK
I am trying to get item's title with "GetSingleItem" method by providing the ItemID, but it does not work.

Here is the code:

```<code>from ebaysdk.shopping import Connection as Shopping

api = Shopping(appid='&',certid='&',devid='&',token='&')
ItemID=&
a = print (api.execute('GetSingleItem',{'ItemID':ItemID,'IncludeSelector':['Title']}))
print(a)
</code>```

The response:

```<code><ebaysdk.response.Response object at 0x003A3B10>
None
</code>```

答:
I think you need to put the itemID like this

{
    "ItemID": "000000000000"
}

Title: Q: Get Item's Title Python eBay SDK

Body:
I am trying to get item's title with "GetSingleItem" method by providing the ItemID, but it does not work.

Here is the code:

from ebaysdk.shopping import Connection as Shopping

api = Shopping(appid='&',certid='&',devid='&',token='&')
ItemID=&
a = print (api.execute('GetSingleItem',{'ItemID':ItemID,'IncludeSelector':['Title']}))
print(a)

The response:

<ebaysdk.response.Response object at 0x003A3B10>
None


答:
I hope this helps:

https://codepen.io/anon/pen/KqwGPq

function flip(el) {
  console.log("flip called");
  var elem = document.getElementById(el);
  console.log(elem);
  elem.className = "on";
  console.log(elem);
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>* {
  -webkit-box-sizing: border-box;
  /*few lines of code for compatibility and for correct box resizing*/
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
  background-color: rgb(228, 227, 225);
}

.title {
  text-align: center;
  color: black;
}

.gameboard {
  width: 530px;
  height: 530px;
  background-color: #92bbce;
  box-shadow: 0 0 11px 5px #00BCD4;
  position: fixed;
  right: 0;
  left: 0;
  margin-right: auto;
  margin-left: auto;
  margin-top: 20px;
  margin-bottom: 20px;
}

.cardrows {
  width: 524px;
  height: 125px;
  margin-left: 3px;
  margin-right: 3px;
  margin-top: 6px;
  margin-bottom: 6px;
  background-color: transparent;
  position: relative;
}

.infobar {
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.cardback,
.cardfront,
.flip1,
.flip2,
.flip3,
.flip4 {
  width: 125px;
  height: 125px;
}

.cardback,
.cardfront {
  /* hide back during swap */
  backface-visibility: hidden;

  position: absolute;
  top: 0;
  left: 0;

  transition: transform 1s;
  transform-style: preserve-3d;
}

.cardfront {
  /* front placed above back element */
  z-index: 2;
  transform: rotateY(0deg);

  background-color: #108DC0;
}

.cardback {
  /* back hidden at start */
  transform: rotateY(180deg);
}

.card {
  position: relative;

}

.flip1,
.flip2,
.flip3,
.flip4 {
  /*container keeps perspective */
  perspective: 1000px;
  position: absolute;
}

.flip1 {
  left: 3px;
}

.flip2 {
  left: 134px;
}

.flip3 {
  left: 265px;
}

.flip4 {
  left: 396px;
}

.on {
  -webkit-transform: rotateY( 180deg);
  -moz-transform: rotateY( 180deg);
  -o-transform: rotateY( 180deg);
  transition: 0.25s ease;
  transform: rotateY( 180deg);
}

.off {
  -webkit-transform: rotateY( 0deg);
  -moz-transform: rotateY( 0deg);
  -o-transform: rotateY( 0deg);
   transition: 0.25s ease;
  transform: rotateY( 0deg);
}</code>```

<!DOCTYPE html>

    <link rel="stylesheet" href="style.css">

    <meta charset="UTF-8">
    <title>Matching Game</title>

Matching Game

            __stars__

            __move__

            __timer__

            __restart__

                        2

                        1

```

The only thing I changed was adding two lines of CSS to the .on and .off classes:

transition: 0.25s ease;

(You can learn more about using transitions  here: https://www.w3schools.com/css/css3_transitions.asp and here: https://developer.mozilla.org/en-US/docs/Web/CSS/transition?v=example )

You can change 0.25 to something else, like 1, or 0.5 ect.

Have fun!

-Sean

Title: Trying to animate the a div as the user clicks on it.

Body:
I hope this helps:

https://codepen.io/anon/pen/KqwGPq

function flip(el) {
  console.log("flip called");
  var elem = document.getElementById(el);
  console.log(elem);
  elem.className = "on";
  console.log(elem);
}

* {
  -webkit-box-sizing: border-box;
  /*few lines of code for compatibility and for correct box resizing*/
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
  background-color: rgb(228, 227, 225);
}

.title {
  text-align: center;
  color: black;
}

.gameboard {
  width: 530px;
  height: 530px;
  background-color: #92bbce;
  box-shadow: 0 0 11px 5px #00BCD4;
  position: fixed;
  right: 0;
  left: 0;
  margin-right: auto;
  margin-left: auto;
  margin-top: 20px;
  margin-bottom: 20px;
}

.cardrows {
  width: 524px;
  height: 125px;
  margin-left: 3px;
  margin-right: 3px;
  margin-top: 6px;
  margin-bottom: 6px;
  background-color: transparent;
  position: relative;
}

.infobar {
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.cardback,
.cardfront,
.flip1,
.flip2,
.flip3,
.flip4 {
  width: 125px;
  height: 125px;
}

.cardback,
.cardfront {
  /* hide back during swap */
  backface-visibility: hidden;

  position: absolute;
  top: 0;
  left: 0;

  transition: transform 1s;
  transform-style: preserve-3d;
}

.cardfront {
  /* front placed above back element */
  z-index: 2;
  transform: rotateY(0deg);

  background-color: #108DC0;
}

.cardback {
  /* back hidden at start */
  transform: rotateY(180deg);
}

.card {
  position: relative;

}

.flip1,
.flip2,
.flip3,
.flip4 {
  /*container keeps perspective */
  perspective: 1000px;
  position: absolute;
}

.flip1 {
  left: 3px;
}

.flip2 {
  left: 134px;
}

.flip3 {
  left: 265px;
}

.flip4 {
  left: 396px;
}

.on {
  -webkit-transform: rotateY( 180deg);
  -moz-transform: rotateY( 180deg);
  -o-transform: rotateY( 180deg);
  transition: 0.25s ease;
  transform: rotateY( 180deg);
}

.off {
  -webkit-transform: rotateY( 0deg);
  -moz-transform: rotateY( 0deg);
  -o-transform: rotateY( 0deg);
   transition: 0.25s ease;
  transform: rotateY( 0deg);
}

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="style.css"> <!--making a link to the css stylesheet-->
    <script src="scripts.js" type="text/javascript"></script>
    <meta charset="UTF-8">
    <title>Matching Game</title>
</head>
<body>
    <div class = "title"><h1>Matching Game</h1></div>
    <div class = "infobar">
        <span>
            __stars__
        </span>
        <span>
            __move__
        </span>
        <span>
            __timer__
        </span>
        <span>
            __restart__
        </span>
    </div>
    <div class = "gameboard">
        <div class = "cardrows">
            <div class = "flip1">
                <div id = "card1" class = "card, off" onclick="flip(this.id)">
                    <div class = "cardback">
                        2
                    </div>
                    <div class = "cardfront ">
                        1
                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
        <div class = "cardrows">
            <div class = "flip1">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
        <div class = "cardrows">
            <div class = "flip1">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
        <div class = "cardrows">
            <div class = "flip1">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip2">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip3">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
            <div class = "flip4">
                <div class = "card">
                    <div class = "cardback">

                    </div>
                    <div class = "cardfront">

                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

The only thing I changed was adding two lines of CSS to the .on and .off classes:

transition: 0.25s ease;

(You can learn more about using transitions  here: https://www.w3schools.com/css/css3_transitions.asp and here: https://developer.mozilla.org/en-US/docs/Web/CSS/transition?v=example )

You can change 0.25 to something else, like 1, or 0.5 ect.

Have fun!

-Sean


问:
Something like a for loop does not use pl / sql triangle printing, Is there a method that can use in the select clause?
I would like to print something like this

```<code>    ***
    **
    *
</code>```

I have some code in MySQL
SELECT REPEAT('* ', @NUMBER := @NUMBER - 1);

答:
I find solution:</p>

```<code>   select rpad('*', (3 - level + 1) * 2, ' *') from dual
   connect by level <= 3;
</code>```

Body:
I would like to print something like this

    ***
    **
    *

I have some code in MySQL
SELECT REPEAT('* ', @NUMBER := @NUMBER - 1);

Body:
I find solution:

   select rpad('*', (3 - level + 1) * 2, ' *') from dual
   connect by level <= 3;


问:
can I combine multiple string matching cases in scala?
Can I combine the following two cases into one case clause since they both do the same thing?

```<code>e match {
  case "hello" => e + "world"
  case "hi" => e + "world
}
</code>```

Also, what about if I want to match using startsWith e.g.,

```<code>e match { case e.startsWith("he") | e.startsWith("hi") => ... }
</code>```

答:
Yes you can simply use or (|) to match one of the pattern,

```<code>scala> "hi" match { case "hello" | "hi" => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "hello" match { case "hello" | "hi" => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "something else" match { case "hello" | "hi" => println("fantastic")  case _ => println("very very bad")}
very very bad
</code>```

You can also use regex to pattern match, especially useful when there are many criterias to match,

```<code>scala> val startsWithHiOrHello = """hello.*|hi.*""".r
startsWithHiOrHello: scala.util.matching.Regex = hello.*|hi.*

scala> "hi there" match { case startsWithHiOrHello() => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "hello there" match { case startsWithHiOrHello() => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "non of hi or hello there" match { case startsWithHiOrHello() => println("fantastic")  case _ => println("very very bad")}
very very bad
</code>```

Refer to Scala multiple type pattern matching and Scala match case on regex directly

Body:
Can I combine the following two cases into one case clause since they both do the same thing?

e match {
  case "hello" => e + "world"
  case "hi" => e + "world
}

Also, what about if I want to match using startsWith e.g.,

e match { case e.startsWith("he") | e.startsWith("hi") => ... }

Body:
Yes you can simply use or (|) to match one of the pattern,

scala> "hi" match { case "hello" | "hi" => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "hello" match { case "hello" | "hi" => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "something else" match { case "hello" | "hi" => println("fantastic")  case _ => println("very very bad")}
very very bad

You can also use regex to pattern match, especially useful when there are many criterias to match,

scala> val startsWithHiOrHello = """hello.*|hi.*""".r
startsWithHiOrHello: scala.util.matching.Regex = hello.*|hi.*

scala> "hi there" match { case startsWithHiOrHello() => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "hello there" match { case startsWithHiOrHello() => println("fantastic")  case _ => println("very very bad")}
fantastic

scala> "non of hi or hello there" match { case startsWithHiOrHello() => println("fantastic")  case _ => println("very very bad")}
very very bad

Refer to Scala multiple type pattern matching and Scala match case on regex directly


问:
Passing function pointers & int references to another function
Just started working on a c project.  Need help with passing function pointers/macro functions/etc.  I'm a php & python OO guy, but new to c.  I tried to generalize the example for this post. I have a main.c with a lib for the Axon microcontroller I'm working with.  Works like a charm with everything in main.c.  I need to move some of the functionality out of main to more organized lib files as my code grows.  The base microcontroller lib creates a macro function that allows me to send data to the microcontroller to make a servo move left or right.  I now need to create a servo specific file (HS-422.c) that will will allow me to pass references/pointers(?) to a generic function that will execute for each servo to ease on code duplication.

Keep in mind I'm only focused on passing macros/functions/variable references to other functions and have them called / set.  The other basics of c I understand. I must have tried a 100 different ways to make this work today with no luck. So just wrote a simplified version hoping you might get an idea of what I'm attempting.

Thank you for your help!

```<code>/*
 * main.h
 * I'm trying to make a pointer or reference to the macro.
 * The original file had:
 * #define servo1(position) servo(PORTE,2,position);
 */

 // servo is a macro defined in another microcontroller file
 #define (void)(*servo1)(position) servo(PORTE,2,position);
 #define (void)(*servo2)(position) servo(PORTE,3,position);

/* main.c */

// init main functions
void servo_scan(void);

// init vars
int servo1_location = 0;
int servo2_location = 0;

int main(void)
{
  for(;;)
  {
     servo_turn();
  }
}

// get the servos to turn
void servo_turn(void)
{
  turn_servo( *servo1, &servo1_location, 200);
  turn_servo( *servo2, &servo2_location, 950);
}

/* HS-422.c */
void turn_servo(void (*servo)(int position), int &currentLocation, int newLocation)
{
  // turning
  for(uint16_t  i=&currentLocation; i<newLocation; i=i+10)
  {
    // turn servo
    // hoping the specifc passed servo# pointer gets called
    *servo(i);

    // set value by reference to origional servo#_location var. making sure.
    &currentLocation = i;

    // pause
    delay_ms(20);
  }
}
</code>```

答:
I have picked the main point of your code and have this code below.

You may want to modify your #define in your original code.

Please see the code below: (you can also run this)

```<code>void myFunc(int pos);
void myFunc2(int pos);

int main (int argc, const char * argv[]) {

    typedef void (*pFunc)(int);
    pFunc pfArr[2];
    pfArr[0] = &myFunc;
    pfArr[1] = &myFunc2;

    int x = 3;
    int newLoc = 4;
    turn_servo(pfArr[1], x, newLoc);
    turn_servo(pfArr[0], x, newLoc);

    return 0;
}

void turn_servo(void (*servo)(int position), int currentLocation, int newLocation)
{
    printf("\nturn_servo starts");
    printf("\nturn_servo currentLocation: %d", currentLocation);
    printf("\nturn_servo newLocation: %d", newLocation);
    servo(1);

}

void myFunc(int pos)
{
    printf("\nmyFunc starts");
    printf("\nmyFunc pos: %d", pos);
}

void myFunc2(int pos)
{
    printf("\nmyFunc2 starts");
    printf("\nmyFunc2 pos: %d", pos);
}
</code>```

Your turn_servo() function will now accept two functions as parameter (either myFunc() or myFunc2()).

Just get the main point of this code and apply it. Hope this will help.

ContentLicense: CC BY-SA 2.5

Body:
Just started working on a c project.  Need help with passing function pointers/macro functions/etc.  I'm a php & python OO guy, but new to c.  I tried to generalize the example for this post. I have a main.c with a lib for the Axon microcontroller I'm working with.  Works like a charm with everything in main.c.  I need to move some of the functionality out of main to more organized lib files as my code grows.  The base microcontroller lib creates a macro function that allows me to send data to the microcontroller to make a servo move left or right.  I now need to create a servo specific file (HS-422.c) that will will allow me to pass references/pointers(?) to a generic function that will execute for each servo to ease on code duplication.

Keep in mind I'm only focused on passing macros/functions/variable references to other functions and have them called / set.  The other basics of c I understand. I must have tried a 100 different ways to make this work today with no luck. So just wrote a simplified version hoping you might get an idea of what I'm attempting.

Thank you for your help!

/*
 * main.h
 * I'm trying to make a pointer or reference to the macro.
 * The original file had:
 * #define servo1(position) servo(PORTE,2,position);
 */

 // servo is a macro defined in another microcontroller file
 #define (void)(*servo1)(position) servo(PORTE,2,position);
 #define (void)(*servo2)(position) servo(PORTE,3,position);

/* main.c */

// init main functions
void servo_scan(void);

// init vars
int servo1_location = 0;
int servo2_location = 0;

int main(void)
{
  for(;;)
  {
     servo_turn();
  }
}

// get the servos to turn
void servo_turn(void)
{
  turn_servo( *servo1, &servo1_location, 200);
  turn_servo( *servo2, &servo2_location, 950);
}

/* HS-422.c */
void turn_servo(void (*servo)(int position), int &currentLocation, int newLocation)
{
  // turning
  for(uint16_t  i=&currentLocation; i<newLocation; i=i+10)
  {
    // turn servo
    // hoping the specifc passed servo# pointer gets called
    *servo(i);

    // set value by reference to origional servo#_location var. making sure.
    &currentLocation = i;

    // pause
    delay_ms(20);
  }
}

Body:
I have picked the main point of your code and have this code below.

You may want to modify your #define in your original code.

Please see the code below: (you can also run this)

void myFunc(int pos);
void myFunc2(int pos);

int main (int argc, const char * argv[]) {

    typedef void (*pFunc)(int);
    pFunc pfArr[2];
    pfArr[0] = &myFunc;
    pfArr[1] = &myFunc2;

    int x = 3;
    int newLoc = 4;
    turn_servo(pfArr[1], x, newLoc);
    turn_servo(pfArr[0], x, newLoc);

    return 0;
}

void turn_servo(void (*servo)(int position), int currentLocation, int newLocation)
{
    printf("\nturn_servo starts");
    printf("\nturn_servo currentLocation: %d", currentLocation);
    printf("\nturn_servo newLocation: %d", newLocation);
    servo(1);

}

void myFunc(int pos)
{
    printf("\nmyFunc starts");
    printf("\nmyFunc pos: %d", pos);
}

void myFunc2(int pos)
{
    printf("\nmyFunc2 starts");
    printf("\nmyFunc2 pos: %d", pos);
}

Your turn_servo() function will now accept two functions as parameter (either myFunc() or myFunc2()).

Just get the main point of this code and apply it. Hope this will help.


问:
Filter a dom object of input tags
I am building an object from a form that is currently rendered server side. I collect all the check boxes displayed in the image below and I am trying to sort them in a way that all the check boxes under each step (1, 2, 3 etc) is a single object based on the property parentNode.

Currently the document.querySelectorAll('.checkboxes')  fetches all the checkboxes in following format.

```<code>var newObj = [
    {
      name: 'one',
      parentNode: {
        id: 'stepOne'
      }
    },
    {
      name: 'two',
      parentNode: {
        id: 'stepTwo'
      }
    },
    {
      name: 'three',
      parentNode: {
        id: 'stepOne'
      }
    },
]
</code>```

The new object should be:

```<code>var newObj = {
    stepOne: [
      {
        name: 'one',
        parentNode: {
          id: 'stepOne'
        }
      },
      {
        name: 'three',
        parentNode: {
          id: 'stepOne'
        }
      },
    ],
    stepTwo: [
      {
        name: 'two',
        parentNode: {
          id: 'stepTwo'
        }
      },
    ]
}
</code>```

Usually I do something like this:

```<code>let stepOne = function(step) {
  return step.parentNode.getAttribute('id') === 'stepOne';
}

let stepTwo = function(step) {
  return step.parentNode.getAttribute('id') === 'stepTwo';
}

let allTheStepOnes = fetchCheckBoxes.filter(stepOne);
</code>```

But filter doesn't work on dom object and this seems inefficient as well.

答:
This function should do the trick</p>

```<code>function mapObj(obj) {
    var result = {};
    for(var i = 0; i < obj.length; i++) {
        var e = obj[i];
        result[e.parentNode.id] = result[e.parentNode.id] || [];
        result[e.parentNode.id].push(e);
    }
    return result;
}
</code>```

Title: Filter a dom object of input tags

Body:
I am building an object from a form that is currently rendered server side. I collect all the check boxes displayed in the image below and I am trying to sort them in a way that all the check boxes under each step (1, 2, 3 etc) is a single object based on the property parentNode.

Currently the document.querySelectorAll('.checkboxes')  fetches all the checkboxes in following format.

var newObj = [
    {
      name: 'one',
      parentNode: {
        id: 'stepOne'
      }
    },
    {
      name: 'two',
      parentNode: {
        id: 'stepTwo'
      }
    },
    {
      name: 'three',
      parentNode: {
        id: 'stepOne'
      }
    },
]

The new object should be:

var newObj = {
    stepOne: [
      {
        name: 'one',
        parentNode: {
          id: 'stepOne'
        }
      },
      {
        name: 'three',
        parentNode: {
          id: 'stepOne'
        }
      },
    ],
    stepTwo: [
      {
        name: 'two',
        parentNode: {
          id: 'stepTwo'
        }
      },
    ]
}

Usually I do something like this:

let stepOne = function(step) {
  return step.parentNode.getAttribute('id') === 'stepOne';
}

let stepTwo = function(step) {
  return step.parentNode.getAttribute('id') === 'stepTwo';
}

let allTheStepOnes = fetchCheckBoxes.filter(stepOne);

But filter doesn't work on dom object and this seems inefficient as well.

Body:
This function should do the trick

function mapObj(obj) {
    var result = {};
    for(var i = 0; i < obj.length; i++) {
        var e = obj[i];
        result[e.parentNode.id] = result[e.parentNode.id] || [];
        result[e.parentNode.id].push(e);
    }
    return result;
}


问:
Mysql query LIKE search and using strings with symbols
My problem is having symbols used in the search query. I want users to be able to use symbols without being a problem, but the LIKE function in mysql seems to not be the solution so I need some help.

EXAMPLE: If someone searches for "Blue's car" and "Blues car" is in the database, this query will return with 0 results. OR viseversa, if someone searches for "Blues car" and "Blue's car" is in the database, this query will return with 0 results as well.

This is an example of what I'm currently using:

```<code>("SELECT Title FROM MyData WHERE Title LIKE '%".$search."%'")
</code>```

Is there another way on providing better search results?

Thanks.

答:
You can you this search term. This is very useful for multi column search from MySQL

```<code>$q = htmlspecialchars($_GET["q"], ENT_QUOTES, "ISO-8859-1");
$q = stripslashes($q);
$search_exploded = explode (" ", $q);
$construct = "";

  $construct .=" CONCAT(title,' ',category,' ',subCategory,' ',description,' ',contact,' ',email,' ',website,' ',address) LIKE '%$q%' ";

foreach($search_exploded as $search_each)
{

$construct .=" OR CONCAT(title,' ',category,' ',subCategory,' ',description,' ',contact,' ',email,' ',website,' ',address) LIKE '%$search_each%' ";

}
$constructs ="SELECT * FROM content WHERE   active='1' AND ($construct) ";
$run = mysql_query($constructs);
$foundnum = mysql_num_rows($run);
</code>```

If you want i will provide more information

Body:
My problem is having symbols used in the search query. I want users to be able to use symbols without being a problem, but the LIKE function in mysql seems to not be the solution so I need some help.

EXAMPLE: If someone searches for "Blue's car" and "Blues car" is in the database, this query will return with 0 results. OR viseversa, if someone searches for "Blues car" and "Blue's car" is in the database, this query will return with 0 results as well.

This is an example of what I'm currently using:

("SELECT Title FROM MyData WHERE Title LIKE '%".$search."%'")

Is there another way on providing better search results?

Thanks.

Body:
You can you this search term. This is very useful for multi column search from MySQL

$q = htmlspecialchars($_GET["q"], ENT_QUOTES, "ISO-8859-1");
$q = stripslashes($q);
$search_exploded = explode (" ", $q);
$construct = "";

  $construct .=" CONCAT(title,' ',category,' ',subCategory,' ',description,' ',contact,' ',email,' ',website,' ',address) LIKE '%$q%' ";

foreach($search_exploded as $search_each)
{

$construct .=" OR CONCAT(title,' ',category,' ',subCategory,' ',description,' ',contact,' ',email,' ',website,' ',address) LIKE '%$search_each%' ";

}
$constructs ="SELECT * FROM content WHERE   active='1' AND ($construct) ";
$run = mysql_query($constructs);
$foundnum = mysql_num_rows($run);

If you want i will provide more information


问:
Checking if string exists in array - what is the mistake here?
I am trying remove duplicates from an array and build a reduced array. I receive an object required error. Here is what I am doing -

```<code>Dim LUT as object, baseArray() as string, sval as variant
'Dim sval as string ... ignore this
For I = 1 to n
    Set LUT = CreateObject("Scripting.Dictionary")
    ... other stuff
    u = 1
    for each sval in baseArray
        if not LUT.exists(sval) then
            do something...
            LUT.Add u, sval
        end if
    u = u + 1
    next sval
    Set LUT = nothing
Next I
</code>```

Please forgive if the code is unrefined. I need it to work more than being the most memory efficient, although unnecessary clutter is always to be avoided. Thanks for your help.

答:
If you want to do this without the scripting dictionary, you can do it with string comparisons:</p>

```<code>Sub DeDupeArray()
Dim MyArr As Variant, NewArr() As String, X As Long
MyArr = Array("Hello", "World", "This", "World", "Is Some", "World", "Data")
ReDim Preserve NewArr(0)
For X = LBound(MyArr) To UBound(MyArr)
    If InStr(1, "|" & Join(NewArr, "|") & "|", "|" & MyArr(X) & "|") = 0 Then 'Test if the element in MyArr exists in NewArr
        If NewArr(0) <> "" Then ReDim Preserve NewArr(UBound(NewArr) + 1) 'Add another element to the array only if it's not the first element to be entered (otherwise will be blank in address 0)
        NewArr(UBound(NewArr)) = MyArr(X) 'Add Element X from MyArr into the last address of NewArr
    End If
Next
MsgBox "Old Array: " & Join(MyArr, "|") & vbLf & vbLf & "New Array: " & Join(NewArr, "|")
End Sub
</code>```

Body:
I am trying remove duplicates from an array and build a reduced array. I receive an object required error. Here is what I am doing -

Dim LUT as object, baseArray() as string, sval as variant
'Dim sval as string ... ignore this
For I = 1 to n
    Set LUT = CreateObject("Scripting.Dictionary")
    ... other stuff
    u = 1
    for each sval in baseArray
        if not LUT.exists(sval) then
            do something...
            LUT.Add u, sval
        end if
    u = u + 1
    next sval
    Set LUT = nothing
Next I

Please forgive if the code is unrefined. I need it to work more than being the most memory efficient, although unnecessary clutter is always to be avoided. Thanks for your help.

Body:
If you want to do this without the scripting dictionary, you can do it with string comparisons:

Sub DeDupeArray()
Dim MyArr As Variant, NewArr() As String, X As Long
MyArr = Array("Hello", "World", "This", "World", "Is Some", "World", "Data")
ReDim Preserve NewArr(0)
For X = LBound(MyArr) To UBound(MyArr)
    If InStr(1, "|" & Join(NewArr, "|") & "|", "|" & MyArr(X) & "|") = 0 Then 'Test if the element in MyArr exists in NewArr
        If NewArr(0) <> "" Then ReDim Preserve NewArr(UBound(NewArr) + 1) 'Add another element to the array only if it's not the first element to be entered (otherwise will be blank in address 0)
        NewArr(UBound(NewArr)) = MyArr(X) 'Add Element X from MyArr into the last address of NewArr
    End If
Next
MsgBox "Old Array: " & Join(MyArr, "|") & vbLf & vbLf & "New Array: " & Join(NewArr, "|")
End Sub


问:
Combine two vectors into single list
I have a list of variables with two sets of identifying numbers. I just used paste to get the vectors, so I have :

```<code>in <- "abc001":"abc050"
</code>```

and

```<code>out <- "001xyz":"200xyz"
</code>```

I want to combine them so that every value is accounted for. I tried paste(in, "-", out, separate="") which gives:

"abc001-001xyz"

But only until I hit 200xyz. How can I get a list of every possible combination of those values?

答:
Use expand.grid:

```<code>df <- expand.grid(in, out)
paste(df$in,df$out, separate = "-")
</code>```

Title: Combine two vectors into single list

Body:
I have a list of variables with two sets of identifying numbers. I just used paste to get the vectors, so I have :

in <- "abc001":"abc050"

and

out <- "001xyz":"200xyz"

I want to combine them so that every value is accounted for. I tried paste(in, "-", out, separate="") which gives:

"abc001-001xyz"

But only until I hit 200xyz. How can I get a list of every possible combination of those values?

Body:
Use expand.grid:

df <- expand.grid(in, out)
paste(df$in,df$out, separate = "-")


问:
web.config error
Hello everyone can someone help me with my web.config file? I am having error. I just want you guys to look at it and if there are errors someone that needs correction. Thank you all:

This is the error message:

Warning    1   The 'targetFramework' attribute is not declared.    G:\display images in gridview\Web.config    17  62  Miscellaneous Files

Message    2   Could not find schema information for the element 'modules'.    G:\display images in gridview\Web.config    51  7   Miscellaneous Files

Message    3   Could not find schema information for the attribute 'runAllManagedModulesForAllRequests'.   G:\display images in gridview\Web.config    51  15  Miscellaneous Files

Error  4   The 'configuration' start tag on line 10 does not match the end tag of 'system.web'. Line 101, position 4. (C:\Users\Collins\Documents\Visual Studio 2005\WebSites\living to please god world\web.config line 101)

Here is the Web.config file:

```<code><?xml version="1.0"?>
<configuration>
<connectionStrings>
    <add name="ConnectionString"
             connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
             providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
    <customErrors mode="Off"/>
    <compilation debug="true"/>
</system.web>
<pages>
    <namespaces>
        <clear/>
        <add namespace="System"/>
        <add namespace="System.Collections"/>
        <add namespace="System.Collections.Specialized"/>
        <add namespace="System.Configuration"/>
        <add namespace="System.Text"/>
        <add namespace="System.Text.RegularExpressions"/>
        <add namespace="System.Web"/>
        <add namespace="System.Web.Caching"/>
        <add namespace="System.Web.SessionState"/>
        <add namespace="System.Web.Security"/>
        <add namespace="System.Web.Profile"/>
        <add namespace="System.Web.UI"/>
        <add namespace="System.Web.UI.WebControls"/>
        <add namespace="System.Web.UI.WebControls.WebParts"/>
        <add namespace="System.Web.UI.HtmlControls"/>
    </namespaces>
</pages>
<membership>
    <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    </providers>
</membership>
<profile>
    <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/"/>
    </providers>
</profile>
<authentication mode="Forms">
    <forms loginUrl="login.aspx" defaultUrl="Default.aspx"/>
</authentication>
<authorization>
    <allow users="*"/>
</authorization>
<location path="PhotoAdmin">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>
<system.net>
    <mailSettings>
      <smtp from="some@example.com">
        <network host="relay-hosting.example.net" password="" userName=""/>
      </smtp>
    </mailSettings>
</system.net>
</configuration>
</code>```

答:
Well there are several things that are messed up.

The targetFramework attribute must be specified if the application pool that you are using is set up to use .Net Framework 4. If this is the case then you should have the following section under system.web:

```<code><compilation debug="true" targetFramework="4.0" />
</code>```

The system.web section is closed too earlier. The sections 'pages', 'membership', 'profile', 'authentication' and 'authorization' must be subsections of system.web.

Title: web.config error

Body:
Hello everyone can someone help me with my web.config file? I am having error. I just want you guys to look at it and if there are errors someone that needs correction. Thank you all:

This is the error message:

Warning    1   The 'targetFramework' attribute is not declared.    G:\display images in gridview\Web.config    17  62  Miscellaneous Files

Message    2   Could not find schema information for the element 'modules'.    G:\display images in gridview\Web.config    51  7   Miscellaneous Files

Message    3   Could not find schema information for the attribute 'runAllManagedModulesForAllRequests'.   G:\display images in gridview\Web.config    51  15  Miscellaneous Files

Error  4   The 'configuration' start tag on line 10 does not match the end tag of 'system.web'. Line 101, position 4. (C:\Users\Collins\Documents\Visual Studio 2005\WebSites\living to please god world\web.config line 101)

Here is the Web.config file:

<?xml version="1.0"?>
<configuration>
<connectionStrings>
    <add name="ConnectionString"
             connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
             providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
    <customErrors mode="Off"/>
    <compilation debug="true"/>
</system.web>
<pages>
    <namespaces>
        <clear/>
        <add namespace="System"/>
        <add namespace="System.Collections"/>
        <add namespace="System.Collections.Specialized"/>
        <add namespace="System.Configuration"/>
        <add namespace="System.Text"/>
        <add namespace="System.Text.RegularExpressions"/>
        <add namespace="System.Web"/>
        <add namespace="System.Web.Caching"/>
        <add namespace="System.Web.SessionState"/>
        <add namespace="System.Web.Security"/>
        <add namespace="System.Web.Profile"/>
        <add namespace="System.Web.UI"/>
        <add namespace="System.Web.UI.WebControls"/>
        <add namespace="System.Web.UI.WebControls.WebParts"/>
        <add namespace="System.Web.UI.HtmlControls"/>
    </namespaces>
</pages>
<membership>
    <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    </providers>
</membership>
<profile>
    <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/"/>
    </providers>
</profile>
<authentication mode="Forms">
    <forms loginUrl="login.aspx" defaultUrl="Default.aspx"/>
</authentication>
<authorization>
    <allow users="*"/>
</authorization>
<location path="PhotoAdmin">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>
<system.net>
    <mailSettings>
      <smtp from="some@example.com">
        <network host="relay-hosting.example.net" password="" userName=""/>
      </smtp>
    </mailSettings>
</system.net>
</configuration>

Body:
Well there are several things that are messed up.

The targetFramework attribute must be specified if the application pool that you are using is set up to use .Net Framework 4. If this is the case then you should have the following section under system.web:

<compilation debug="true" targetFramework="4.0" />

The system.web section is closed too earlier. The sections 'pages', 'membership', 'profile', 'authentication' and 'authorization' must be subsections of system.web.


问:
A good pattern for complex search criteria?
I am currently working on a user search function.
The search criteria are quite complex, for example:

```<code>Footage >= 50 AND (SizeCode == SizeType.Large OR MobileEnd == "ABC")
</code>```

I think that the Criteria/Filter Pattern could be suitable for this function.
http://en.wikipedia.org/wiki/Criteria_Pattern

My questions are:
How can I add parameters into the MeetCriteria()?
I need some functions like:

```<code>public List<Store> MeetCriteria(List<Store> entities, int footage)

public List<Store> MeetCriteria(List<Store> entities, string mobileEnd)
</code>```

The parenthesis is a trouble to parse. Is it a good idea to design interface as "standard form" (using OR only in the top level), so that the above search criteria can be accepted as:

```<code>(Footage >= 50 AND SizeCode == SizeType.Large) OR
(Footage >= 50 AND MobileEnd == "ABC")
</code>```

Thanks.

答:
Specification pattern is another candidate:  https://en.wikipedia.org/wiki/Specification_pattern . It let you build more criteria on top of existing criteria.

Here is how you would use it:

```<code>var OverDue = new OverDueSpecification();
var NoticeSent = new NoticeSentSpecification();
var InCollection = new InCollectionSpecification();

// example of specification pattern logic chaining
var SendToCollection = OverDue.And(NoticeSent).And(InCollection.Not());

var InvoiceCollection = Service.GetInvoices();

foreach (var currentInvoice in InvoiceCollection) {
    if (SendToCollection.IsSatisfiedBy(currentInvoice))  {
        currentInvoice.SendToCollection();
    }
}
</code>```

and the generic code in C# 6.0:

```<code>  public interface ISpecification<T>
    {
        bool IsSatisfiedBy(T candidate);
        ISpecification<T> And(ISpecification<T> other);
        ISpecification<T> AndNot(ISpecification<T> other);
        ISpecification<T> Or(ISpecification<T> other);
        ISpecification<T> OrNot(ISpecification<T> other);
        ISpecification<T> Not();
    }

    public abstract class LinqSpecification<T> : CompositeSpecification<T>
    {
        public abstract Expression<Func<T, bool>> AsExpression();
        public override bool IsSatisfiedBy(T candidate) => AsExpression().Compile()(candidate);
    }

    public abstract class CompositeSpecification<T> : ISpecification<T>
    {
        public abstract bool IsSatisfiedBy(T candidate);
        public ISpecification<T> And(ISpecification<T> other) => new AndSpecification<T>(this, other);
        public ISpecification<T> AndNot(ISpecification<T> other) => new AndNotSpecification<T>(this, other);
        public ISpecification<T> Or(ISpecification<T> other) => new OrSpecification<T>(this, other);
        public ISpecification<T> OrNot(ISpecification<T> other) => new OrNotSpecification<T>(this, other);
        public ISpecification<T> Not() => new NotSpecification<T>(this);
    }

    public class AndSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public AndSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) && right.IsSatisfiedBy(candidate);
    }

    public class AndNotSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public AndNotSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) && right.IsSatisfiedBy(candidate) != true;
    }

    public class OrSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public OrSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) || right.IsSatisfiedBy(candidate);
    }
    public class OrNotSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public OrNotSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) || right.IsSatisfiedBy(candidate) != true;
    }

    public class NotSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> other;
        public NotSpecification(ISpecification<T> other) => this.other = other;
        public override bool IsSatisfiedBy(T candidate) => !other.IsSatisfiedBy(candidate);
    }
</code>```

References:

Specifications design pattern: http://www.martinfowler.com/apsupp/spec.pdf

Body:
I am currently working on a user search function.
The search criteria are quite complex, for example:

Footage >= 50 AND (SizeCode == SizeType.Large OR MobileEnd == "ABC")

I think that the Criteria/Filter Pattern could be suitable for this function.
http://en.wikipedia.org/wiki/Criteria_Pattern

My questions are:
How can I add parameters into the MeetCriteria()?
I need some functions like:

public List<Store> MeetCriteria(List<Store> entities, int footage)

public List<Store> MeetCriteria(List<Store> entities, string mobileEnd)

The parenthesis is a trouble to parse. Is it a good idea to design interface as "standard form" (using OR only in the top level), so that the above search criteria can be accepted as:

(Footage >= 50 AND SizeCode == SizeType.Large) OR
(Footage >= 50 AND MobileEnd == "ABC")

Thanks.

Body:
Specification pattern is another candidate:  https://en.wikipedia.org/wiki/Specification_pattern . It let you build more criteria on top of existing criteria.

Here is how you would use it:

var OverDue = new OverDueSpecification();
var NoticeSent = new NoticeSentSpecification();
var InCollection = new InCollectionSpecification();

// example of specification pattern logic chaining
var SendToCollection = OverDue.And(NoticeSent).And(InCollection.Not());

var InvoiceCollection = Service.GetInvoices();

foreach (var currentInvoice in InvoiceCollection) {
    if (SendToCollection.IsSatisfiedBy(currentInvoice))  {
        currentInvoice.SendToCollection();
    }
}

and the generic code in C# 6.0:

  public interface ISpecification<T>
    {
        bool IsSatisfiedBy(T candidate);
        ISpecification<T> And(ISpecification<T> other);
        ISpecification<T> AndNot(ISpecification<T> other);
        ISpecification<T> Or(ISpecification<T> other);
        ISpecification<T> OrNot(ISpecification<T> other);
        ISpecification<T> Not();
    }

    public abstract class LinqSpecification<T> : CompositeSpecification<T>
    {
        public abstract Expression<Func<T, bool>> AsExpression();
        public override bool IsSatisfiedBy(T candidate) => AsExpression().Compile()(candidate);
    }

    public abstract class CompositeSpecification<T> : ISpecification<T>
    {
        public abstract bool IsSatisfiedBy(T candidate);
        public ISpecification<T> And(ISpecification<T> other) => new AndSpecification<T>(this, other);
        public ISpecification<T> AndNot(ISpecification<T> other) => new AndNotSpecification<T>(this, other);
        public ISpecification<T> Or(ISpecification<T> other) => new OrSpecification<T>(this, other);
        public ISpecification<T> OrNot(ISpecification<T> other) => new OrNotSpecification<T>(this, other);
        public ISpecification<T> Not() => new NotSpecification<T>(this);
    }

    public class AndSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public AndSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) && right.IsSatisfiedBy(candidate);
    }

    public class AndNotSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public AndNotSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) && right.IsSatisfiedBy(candidate) != true;
    }

    public class OrSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public OrSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) || right.IsSatisfiedBy(candidate);
    }
    public class OrNotSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> left;
        ISpecification<T> right;

        public OrNotSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.left = left;
            this.right = right;
        }

        public override bool IsSatisfiedBy(T candidate) => left.IsSatisfiedBy(candidate) || right.IsSatisfiedBy(candidate) != true;
    }

    public class NotSpecification<T> : CompositeSpecification<T>
    {
        ISpecification<T> other;
        public NotSpecification(ISpecification<T> other) => this.other = other;
        public override bool IsSatisfiedBy(T candidate) => !other.IsSatisfiedBy(candidate);
    }

References:

Specifications design pattern: http://www.martinfowler.com/apsupp/spec.pdf


问:
Is it possible in Quickbooks Desktop to do an IIF transaction import which keys off of a customer id rather than the 'NAME' field?
First of all, yes, I know that IIF (Intuit Interchange Format) files are a deprecated way of transferring data into Quickbooks Desktop.

However, I have been tasked with writing a PHP script that will create an IIF file that a customer could use to import an invoice that is created by my web application. If it were my choice, I wouldn't attempt to use IIF.

The Question:
Using an IIF import, is it possible to have Quickbooks use either its internal ids, an account number (which ends up in the NOTE field), or a custom field to link the customer to the invoice rather than using the NAME field?

答:
It appears the answer is no.

The closest thing I could find to an answer was from here:
https://community.intuit.com/questions/1575622-how-do-you-import-iif-file-using-a-custom-field-as-identifier

The answer from that link:

"Custom Fields are not a Key Field; Vendor Name is the Key Field. You
  cannot import Bills except by reference to the Relational key field of
  Vendor Name. This is a relational database, so the things that matter
  are the Key Fields. AP and Vendor Name, at a minimum, define Bills."

My question was about transactions rather than Bills, but I imagine that the same answer that applies to Bills applies to Invoices and the customer Name.


答:
Proper way of doing this is a forEach loop and using associative arrays like this:

```<code>let newObject = {};

originalObject.forEach((item)=>{
    let step = item.parentNode.id
    if (newObj[step] === undefined) {
        newObj[step] = []
    }
    newObj[step].push(item)
})
</code>```

Title: Filter a dom object of input tags

Body:
Proper way of doing this is a forEach loop and using associative arrays like this:

let newObject = {};

originalObject.forEach((item)=>{
    let step = item.parentNode.id
    if (newObj[step] === undefined) {
        newObj[step] = []
    }
    newObj[step].push(item)
})


问:
How to access secondary travis logs
I know the primary travis build logs are available on the web and with the logs command in the travis command line client, but I was wondering if there is a way to access other files generated as part of the build process, such as the file /home/travis/.rvm/log/1391454748_rbx-2.2.4/rubygems.install.log referenced in https://travis-ci.org/rspec/rspec-its/jobs/18148204

答:
banzaiman's answer is good (it helped me!).  But if you use:

```<code>install: gem install XXX || cat /home/travis/.rvm/log/*_rbx-2.2.4/rubygems.install.log
</code>```

then the cat command will likely succeed, and so the line above will count as as success, and the build will continue.  If you want the build to fail when the install fails, then you need to make sure the line has a non-zero exit status.  So do something like this:

```<code>install: gem install XXX || { cat /home/travis/.rvm/log/*_rbx-2.2.4/rubygems.install.log && 1; }
</code>```

The expression in curly braces will be run only if the gem install XXX fails (i.e., has a non-zero exit status).  cat will presumably succeed, so the command after the && will be run.  That 1 ensures a non-zero exit status for the whole line, causing the build to stop at that point.

Note the necessary whitespace around the curly braces.

Title: How to access secondary travis logs

Body:
banzaiman's answer is good (it helped me!).  But if you use:

install: gem install XXX || cat /home/travis/.rvm/log/*_rbx-2.2.4/rubygems.install.log

then the cat command will likely succeed, and so the line above will count as as success, and the build will continue.  If you want the build to fail when the install fails, then you need to make sure the line has a non-zero exit status.  So do something like this:

install: gem install XXX || { cat /home/travis/.rvm/log/*_rbx-2.2.4/rubygems.install.log && 1; }

The expression in curly braces will be run only if the gem install XXX fails (i.e., has a non-zero exit status).  cat will presumably succeed, so the command after the && will be run.  That 1 ensures a non-zero exit status for the whole line, causing the build to stop at that point.

Note the necessary whitespace around the curly braces.


问:
Too few arguments to function in WooCommerce Email Hook
I'm creating a function in PHP and I want to pass three arguments into it below:

```<code>function lnz_wc_emails_memberreceipients($headers, $object, $order) {

$company = $order->billing_company;

$emailreturn = array (
    'Robin' => "weiltest@weiltest.com",
    'Other' => "beistest@beistest.com, beistest2@beistest.com"
);

$headers = array();
$headers[] = 'Bcc: your name '.$emailreturn[$company];
$headers[] = 'Content-Type: text/html';
return $headers;

}
add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 2);
</code>```

However, when I try and do this I get an error which suggests that my function is asking for 3 arguments but is only being passed two.

```<code>Fatal error: Uncaught ArgumentCountError: Too few arguments to function lnz_wc_emails_memberreceipients(), 2 passed in /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php on line 300 and exactly 3 expected in /home/benefacto/public_html/dev3/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php:17 Stack trace: #0 /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php(300): lnz_wc_emails_memberreceipients('Content-Type: t...', 'customer_comple...') #1 /home/benefacto/public_html/dev3/wp-includes/plugin.php(203): WP_Hook->apply_filters('Content-Type: t...', Array) #2 /home/benefacto/public_html/dev3/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php(287): apply_filters('woocommerce_ema...', 'Content-Type: t...', 'customer_comple...', Object(WC_Order)) #3 /home/benefacto/public_html/dev3/wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-completed-order.php(75): WC_Email->get_headers() #4 /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php(298): WC_Email in /home/benefacto/public_html/dev3/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php on line 17
</code>```

If I remove either $object OR $order it works just fine! But if I try and include both it throws the wobbly.

Is there anything I can do to pass it all three? Any thoughts much appreciated.

答:
Replace

```<code>add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 2);
</code>```

With

```<code>add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 3);
</code>```

which accepts 3 arguments for the filter woocommerce_email_headers

Body:
I'm creating a function in PHP and I want to pass three arguments into it below:

function lnz_wc_emails_memberreceipients($headers, $object, $order) {

$company = $order->billing_company;

$emailreturn = array (
    'Robin' => "weiltest@weiltest.com",
    'Other' => "beistest@beistest.com, beistest2@beistest.com"
);

$headers = array();
$headers[] = 'Bcc: your name '.$emailreturn[$company];
$headers[] = 'Content-Type: text/html';
return $headers;

}
add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 2);

However, when I try and do this I get an error which suggests that my function is asking for 3 arguments but is only being passed two.

Fatal error: Uncaught ArgumentCountError: Too few arguments to function lnz_wc_emails_memberreceipients(), 2 passed in /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php on line 300 and exactly 3 expected in /home/benefacto/public_html/dev3/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php:17 Stack trace: #0 /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php(300): lnz_wc_emails_memberreceipients('Content-Type: t...', 'customer_comple...') #1 /home/benefacto/public_html/dev3/wp-includes/plugin.php(203): WP_Hook->apply_filters('Content-Type: t...', Array) #2 /home/benefacto/public_html/dev3/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php(287): apply_filters('woocommerce_ema...', 'Content-Type: t...', 'customer_comple...', Object(WC_Order)) #3 /home/benefacto/public_html/dev3/wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-completed-order.php(75): WC_Email->get_headers() #4 /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php(298): WC_Email in /home/benefacto/public_html/dev3/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php on line 17

If I remove either $object OR $order it works just fine! But if I try and include both it throws the wobbly.

Is there anything I can do to pass it all three? Any thoughts much appreciated.

Body:
Replace

add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 2);

With

add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 3);

which accepts 3 arguments for the filter woocommerce_email_headers


问:
Getting "ReferenceError" error while performing multiple chaining of promise in nodejs application for neo4j import using cypher query
I am writing nodejs application using neo4j js driver (and async utility module) to use a project's source js files' data to be imported in neo4j database.

There are 2 folders namely "State"and "City" and a single "country.js" file in my test project folder "testapp".
The "country.js" file contains the name and id of the countries and the countryid is used as a parameter in the js files present in the folders "State"and "City".

-- snippet from country.js file

```<code>const countries= [
{ id: "1", label: "USA" },
{ id: "2", label: "Scotland" }
];
module.exports = countries;
</code>```

The "State" folder has js files which has naming convention like this: (Country-1-statelist.js, Country-2-statelist.js and so on).

--Sample from js file present in "State" folder.

```<code>    const data = {"params":{"country_id":"1"},"items":
    [{"id":"1","label":"Alaska"},{"id":"2","label":"Alabama"}]
      module.exports = data;
</code>```

Similarly, "City" folder has js files which has naming convention like this: (Country-1-state-1-list.js, Country-1-state-2-list.js and so on).

-- sample from a particular js file present in "City" folder

```<code>const data =
  {"params":
   {"country_id":"1","state_id":"1"},

   "items":[
       {"id":"1","label":"New York"},
       {"id":"2","label":"Chicago"}
   ]
        }
 module.exports = data;
</code>```

So,I am trying to add nodes with label Countries, States and Cities such that they would be imported without their relationship being unaltered. But I am getting error in nodejs while trying to use multiple chain promise to import it into my test db.

so, far I was able to import the data present in country.js and other js files from "State" folder. But while trying to do the same from js files of "City" folder, I am getting "ReferenceError: item is not defined" error.

I have created index.js file in nodejs to do so, which has the following code:

const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "testapp"));
const session = driver.session();
const async = require('async');
const appPathway = '/Users/reactor/Documents/testapp';
const country = require(appPathway+'/country');

async.eachSeries(country, (item, callback) => {

  const resPromise = session.run(
    `CREATE (c:country {label: "${item.label}", id: "${item.id}"}) RETURN c.id`
  );
  resPromise
  .then((data) => {
    return insertState(item.id);
              }
  )
  .then
   (
    (done) => {
    callback(null);
              }
    )
  .catch
  (
    (err) => {
    callback(err);
             }
  );
},

 (err) => {
  console.log(err);
  session.close();
  driver.close();
          }
  );

function insertState(countryID) {

  let state = require(appPathway+'/State/Country-'+countryID+'-statelist.js');

  return new Promise((resolve, reject) =>{
    async.eachSeries(state.items, (item1,item2, callback) => {

      const resPromise = session.run(
        `
        CREATE (s:state {label: "${item.label}", id: "${item.id}"})
        WITH s
        MATCH (c:Country)
        WHERE c.id = '${countryID}'
        CREATE (s)-[r:LOCATED_IN]->(c)
        RETURN c,s
        `
      );
      resPromise
      .then((state) => {
        console.log(state);
        callback(null);
      })
      resPromise
      .then((data) => {
        return insertCity(item1.id,item2.id);
      })
      .then((done) => {
        callback(null);
                  }
        )

      .catch((err) => {
        callback(err);
      });
    }, (err) => {
      if(err) {
        reject(err);
      }
      resolve(true);
    });
 }
);
}

// Problem rose when i inserted the following block of  code !!

function insertCity(countryID,stateID)  {
  let city = require(appPathway+'/city/Country-'+countryID+'-state-'+stateID+'-list.js');

  return new Promise((resolve, reject) =>
                  {
    async.eachSeries(city.items, () => {

      const resPromise = session.run(
        `
        CREATE (w:city {label: "${item.label}", id: "${item.id}"})
        WITH w
        MATCH (s:state)
        WHERE s.id = '${stateID}'

        /* How am I suppose to use the countryid parameter here in this cypher query ? As it doesn't have direct relation with label "country" in this query */

        CREATE (w)-[r:PRESENT_IN]->(s)
        RETURN w
        `
      );
      resPromise
      .then((city) => {
        console.log(city);
        callback(null);
      })
      .then((done) => {
        callback(null);
      })
      .catch((err) => {
        callback(err);
      });
      }, (err) => {
      if(err) {
        reject(err);
      }
      resolve(true);
      });
               }
      );
}```

I am new to ES6,cypher and promise function which may have caused this problem. Although,
I have looked into most of the posts, blogs and videos related to multiple promise chaining, but still I am unable to figure out how to do it when multiple parameters are present in a single js file and how to use these parameters to pull the data using cypher query.

Any help or suggestion would be really helpful for me now ! Thanks in Advance

答: In insertState() and insertCity(), you are trying to dereference item.label and item.id, but there is no item in scope.

Body:
I am writing nodejs application using neo4j js driver (and async utility module) to use a project's source js files' data to be imported in neo4j database.

There are 2 folders namely "State"and "City" and a single "country.js" file in my test project folder "testapp".
The "country.js" file contains the name and id of the countries and the countryid is used as a parameter in the js files present in the folders "State"and "City".

-- snippet from country.js file

const countries= [
{ id: "1", label: "USA" },
{ id: "2", label: "Scotland" }
];
module.exports = countries;

The "State" folder has js files which has naming convention like this: (Country-1-statelist.js, Country-2-statelist.js and so on).

--Sample from js file present in "State" folder.

    const data = {"params":{"country_id":"1"},"items":
    [{"id":"1","label":"Alaska"},{"id":"2","label":"Alabama"}]
      module.exports = data;

Similarly, "City" folder has js files which has naming convention like this: (Country-1-state-1-list.js, Country-1-state-2-list.js and so on).

-- sample from a particular js file present in "City" folder

const data =
  {"params":
   {"country_id":"1","state_id":"1"},

   "items":[
       {"id":"1","label":"New York"},
       {"id":"2","label":"Chicago"}
   ]
        }
 module.exports = data;

So,I am trying to add nodes with label Countries, States and Cities such that they would be imported without their relationship being unaltered. But I am getting error in nodejs while trying to use multiple chain promise to import it into my test db.

so, far I was able to import the data present in country.js and other js files from "State" folder. But while trying to do the same from js files of "City" folder, I am getting "ReferenceError: item is not defined" error.

I have created index.js file in nodejs to do so, which has the following code:

const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "testapp"));
const session = driver.session();
const async = require('async');
const appPathway = '/Users/reactor/Documents/testapp';
const country = require(appPathway+'/country');

async.eachSeries(country, (item, callback) => {

  const resPromise = session.run(
    `CREATE (c:country {label: "${item.label}", id: "${item.id}"}) RETURN c.id`
  );
  resPromise
  .then((data) => {
    return insertState(item.id);
              }
  )
  .then
   (
    (done) => {
    callback(null);
              }
    )
  .catch
  (
    (err) => {
    callback(err);
             }
  );
},

 (err) => {
  console.log(err);
  session.close();
  driver.close();
          }
  );

function insertState(countryID) {

  let state = require(appPathway+'/State/Country-'+countryID+'-statelist.js');

  return new Promise((resolve, reject) =>{
    async.eachSeries(state.items, (item1,item2, callback) => {

      const resPromise = session.run(
        `
        CREATE (s:state {label: "${item.label}", id: "${item.id}"})
        WITH s
        MATCH (c:Country)
        WHERE c.id = '${countryID}'
        CREATE (s)-[r:LOCATED_IN]->(c)
        RETURN c,s
        `
      );
      resPromise
      .then((state) => {
        console.log(state);
        callback(null);
      })
      resPromise
      .then((data) => {
        return insertCity(item1.id,item2.id);
      })
      .then((done) => {
        callback(null);
                  }
        )

      .catch((err) => {
        callback(err);
      });
    }, (err) => {
      if(err) {
        reject(err);
      }
      resolve(true);
    });
 }
);
}

// Problem rose when i inserted the following block of  code !!

function insertCity(countryID,stateID)  {
  let city = require(appPathway+'/city/Country-'+countryID+'-state-'+stateID+'-list.js');

  return new Promise((resolve, reject) =>
                  {
    async.eachSeries(city.items, () => {

      const resPromise = session.run(
        `
        CREATE (w:city {label: "${item.label}", id: "${item.id}"})
        WITH w
        MATCH (s:state)
        WHERE s.id = '${stateID}'

        /* How am I suppose to use the countryid parameter here in this cypher query ? As it doesn't have direct relation with label "country" in this query */

        CREATE (w)-[r:PRESENT_IN]->(s)
        RETURN w
        `
      );
      resPromise
      .then((city) => {
        console.log(city);
        callback(null);
      })
      .then((done) => {
        callback(null);
      })
      .catch((err) => {
        callback(err);
      });
      }, (err) => {
      if(err) {
        reject(err);
      }
      resolve(true);
      });
               }
      );
}

I am new to ES6,cypher and promise function which may have caused this problem. Although,
I have looked into most of the posts, blogs and videos related to multiple promise chaining, but still I am unable to figure out how to do it when multiple parameters are present in a single js file and how to use these parameters to pull the data using cypher query.

Any help or suggestion would be really helpful for me now ! Thanks in Advance


问:
jquery form submission button not working on mobile / touchscreens
Form submit button not working on mobile / touchscreen devices, it works on laptops but on mobile devices nothing happens, code below:</p>

```<code>  $('[data-behavior="publish-button"]').on('click', function() {
    $('.editor-form').submit();
  });

  $('.publish-dropdown').on('click', function(e) {
  e.stopPropagation();
  });
},
</code>```

答:
If the element you are trying to touch does not have a pointer as the cursor (which is what I assume), it will not be touchable on iOS Safari.

Set cursor: pointer; and it will work as expected.

Body:
Form submit button not working on mobile / touchscreen devices, it works on laptops but on mobile devices nothing happens, code below:

  $('[data-behavior="publish-button"]').on('click', function() {
    $('.editor-form').submit();
  });

  $('.publish-dropdown').on('click', function(e) {
  e.stopPropagation();
  });
},


问:
LINQ in asp.net
What is the difference between IEnumerable and IQuearable in LINQ ? I read the more article on this but i doesn't understand the practicle diffrence.</p>

答:
IEnumerable and IQueryable are the two most used terms of any LINQ discussion. What I am trying to here is that I am trying to simplify the two interfaces depending on their behavior. In LINQ world we generally have few providers available within .NET Framework, like LINQ to Object, LINQ to SQL, LINQ to XML.

It is a statement that every LINQ statement returns IEnumerable. IEnumerable works in steps. Meaning, when you write,

```<code>var q = from a in b

           where a > 5

           select a;
</code>```

It creates a list out “b” depending on “where” then it creates another list for “select”. This is the behavior of LINQ to Object and LINQ to XML.

When you use LINQ to SQL it uses IQueryable. This interface inherits from IEnumerable but typically any LINQ to SQL generates T-SQL at the backend to be able to get the data for us. This evaluate and generates the query at one shot and gives us the whole data.

What is the difference between IQueryable<T> and IEnumerable<T>?

Title: LINQ in asp.net

Body:
IEnumerable and IQueryable are the two most used terms of any LINQ discussion. What I am trying to here is that I am trying to simplify the two interfaces depending on their behavior. In LINQ world we generally have few providers available within .NET Framework, like LINQ to Object, LINQ to SQL, LINQ to XML.

It is a statement that every LINQ statement returns IEnumerable. IEnumerable works in steps. Meaning, when you write,

var q = from a in b

           where a > 5

           select a;

It creates a list out “b” depending on “where” then it creates another list for “select”. This is the behavior of LINQ to Object and LINQ to XML.

When you use LINQ to SQL it uses IQueryable. This interface inherits from IEnumerable but typically any LINQ to SQL generates T-SQL at the backend to be able to get the data for us. This evaluate and generates the query at one shot and gives us the whole data.

What is the difference between IQueryable<T> and IEnumerable<T>?