问:
JAVA - SCANNER to get user input
I have the following block code:

```<code>    boolean run = true;
    while (run) {
        Scanner scanner = new Scanner(System.in);
        // do something

        System.out.println("Another action? [Y/N]");
        while (!scanner.hasNext("[YyNn]")) {
            System.out.println("Incorrect input");
            scanner.next();
        }
        String choice = scanner.next();
        if (choice.toLowerCase().equals("f"))
            run = false;

        scanner.close();
    }
</code>```

I want to perform something until the user types 'N'.
Currently, I'm able to run the while loop only one time.
The second time I'm not able to type my choice and I have the following error:

```<code>Another action? [Y/N]     <--- here no chance to type choice
Incorrect input
java.util.NoSuchElementException
    at java.util.Scanner.throwFor
    at java.util.Scanner.next
</code>```

What is wrong?
Thanks

EDIT: I think my problem is in "do something". It is in turn a sequence of user input where i close the scanner.

答:
As many of the answers suggests, the problem is with the statement Scanner scanner = new Scanner(System.in);. Following is the corrected version using try-with-resources, a cleaner way to handle resources in Java:

```<code> boolean run = true;
 try(Scanner scanner = new Scanner(System.in))
    {
        while (run)
        {
            System.out.println("Another action? [Y/N]");
            while (!scanner.hasNext("[YyNnFf]")) {
                System.out.println("Incorrect input");
                        scanner.next();
            }
            String choice = scanner.next();
            if (choice.toLowerCase().equalsIgnoreCase("f"))
                        run = false;
        }
    }
</code>```

You can see it working here.

NOTE: I have changed the pattern matching statement from [YyNn] to [YyNnFf] and choice.toLowerCase().equals("f") to choice.toLowerCase().equalsIgnoreCase("f"), because It seems a logical error. See if it is as per your need.

Title: JAVA - SCANNER to get user input

Body:
I have the following block code:

    boolean run = true;
    while (run) {
        Scanner scanner = new Scanner(System.in);
        // do something

        System.out.println("Another action? [Y/N]");
        while (!scanner.hasNext("[YyNn]")) {
            System.out.println("Incorrect input");
            scanner.next();
        }
        String choice = scanner.next();
        if (choice.toLowerCase().equals("f"))
            run = false;

        scanner.close();
    }

I want to perform something until the user types 'N'.
Currently, I'm able to run the while loop only one time.
The second time I'm not able to type my choice and I have the following error:

Another action? [Y/N]     <--- here no chance to type choice
Incorrect input
java.util.NoSuchElementException
    at java.util.Scanner.throwFor
    at java.util.Scanner.next

What is wrong?
Thanks

EDIT: I think my problem is in "do something". It is in turn a sequence of user input where i close the scanner.

Body:
As many of the answers suggests, the problem is with the statement Scanner scanner = new Scanner(System.in);. Following is the corrected version using try-with-resources, a cleaner way to handle resources in Java:

 boolean run = true;
 try(Scanner scanner = new Scanner(System.in))
    {
        while (run)
        {
            System.out.println("Another action? [Y/N]");
            while (!scanner.hasNext("[YyNnFf]")) {
                System.out.println("Incorrect input");
                        scanner.next();
            }
            String choice = scanner.next();
            if (choice.toLowerCase().equalsIgnoreCase("f"))
                        run = false;
        }
    }

You can see it working here.

NOTE: I have changed the pattern matching statement from [YyNn] to [YyNnFf] and choice.toLowerCase().equals("f") to choice.toLowerCase().equalsIgnoreCase("f"), because It seems a logical error. See if it is as per your need.


来源: stackexchange

问:
How call jQuery function in AngularJS controller?
I have the following html:

```<code><iframe name='iframe1' id="iframe1" src='http://micro.shoretel.com" frameborder='0' width='660' height='450'></iframe>
</code>```

And the jQuery:

```<code>$("iframe").contents().find("element-selector").css("border-color", "blue");
</code>```

I want to do:

```<code>app.controller("myCntrl", function ($scope, angularService, $modal) {

        $scope.deletePrepared = function (itm) {
            var getData = angularService.DeletePrepared(itm.ProductId);
            getData.then(function (msg) {
                GetAllPrepared();
            }, function () {
$("iframe").contents().find("element-selector").css("border-color", "blue");});}});
</code>```

What is the mistake can be?

答:
var app = angular.module("Profile",[])
app.controller("ProfileCtrl", function($scope){
  window.call_from_scope = function(){
        alert('CALLED FROM SCOPE')
      }
  $scope.get_name = function(){
        window.call_from_scope()
  }
})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="Profile" ng-controller="ProfileCtrl">
    <button ng-click="get_name()">Click Here</button>
</body></code>```

ContentLicense: CC BY-SA 3.0

Body:
I have the following html:

And the jQuery:

$("iframe").contents().find("element-selector").css("border-color", "blue");

I want to do:

app.controller("myCntrl", function ($scope, angularService, $modal) {

        $scope.deletePrepared = function (itm) {
            var getData = angularService.DeletePrepared(itm.ProductId);
            getData.then(function (msg) {
                GetAllPrepared();
            }, function () {
$("iframe").contents().find("element-selector").css("border-color", "blue");});}});

What is the mistake can be?

Body:
var app = angular.module("Profile",[])
app.controller("ProfileCtrl", function($scope){
  window.call_from_scope = function(){
        alert('CALLED FROM SCOPE')
      }
  $scope.get_name = function(){
        window.call_from_scope()
  }
})

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="Profile" ng-controller="ProfileCtrl">
    <button ng-click="get_name()">Click Here</button>
</body>


问:
What's the best way to save a complete webpage on a linux server?
I need to archive complete pages including any linked images etc. on my linux server. Looking for the best solution. Is there a way to save all assets and then relink them all to work in the same directory?

I've thought about using curl, but I'm unsure of how to do all of this. Also, will I maybe need PHP-DOM?

Is there a way to use firefox on the server and copy the temp files after the address has been loaded or similar?

Any and all input welcome.

Edit:

It seems as though wget is 'not' going to work as the files need to be rendered. I have firefox installed on the server, is there a way to load the url in firefox and then grab the temp files and clear the temp files after?

答:
wget can do that, for example:

```<code>wget -r http://example.com/
</code>```

This will mirror the whole example.com site.

Some interesting options are:

-Dexample.com: do not follow links of other domains

--html-extension: renames pages with text/html content-type to .html

Manual: http://www.gnu.org/software/wget/manual/

ContentLicense: CC BY-SA 2.5

Body:
wget can do that, for example:

wget -r http://example.com/

This will mirror the whole example.com site.

Some interesting options are:

-Dexample.com: do not follow links of other domains

--html-extension: renames pages with text/html content-type to .html

Manual: http://www.gnu.org/software/wget/manual/


问:
angular-virtual-keyboard not opening on focus

var myApp = angular.module('myApp',['angular-virtual-keyboard']);
myApp.controller('MyCtrl',MyCtrl);

function MyCtrl($scope) {
    document.getElementsByTagName('input')[0].focus();
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://rawgit.com/the-darc/angular-virtual-keyboard/master/release/angular-virtual-keyboard.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"></script>
<script src="https://rawgit.com/the-darc/angular-virtual-keyboard/master/release/angular-virtual-keyboard.js"></script>

<body ng-app='myApp'>
  <div ng-controller="MyCtrl">
    <input type='text' ng-model="textValue" ng-virtual-keyboard/>
  </div>
</body></code>```

If I click on input then virtual keyboard is opening. But how can I open the keyboard without click. I tried using input.focus() that didn't work.

答:
You are doing change outside angularJS framework, so you need to apply it by $scope.$apply();</p>

```<code>var myApp = angular.module('myApp',['angular-virtual-keyboard']);
myApp.controller('MyCtrl',MyCtrl);

function MyCtrl($scope) {
    document.getElementsByTagName('input')[0].focus();
    $scope.$apply();
}
</code>```

Body:
var myApp = angular.module('myApp',['angular-virtual-keyboard']);
myApp.controller('MyCtrl',MyCtrl);

function MyCtrl($scope) {
    document.getElementsByTagName('input')[0].focus();
}

<link href="https://rawgit.com/the-darc/angular-virtual-keyboard/master/release/angular-virtual-keyboard.css" rel="stylesheet"/>

    <input type='text' ng-model="textValue" ng-virtual-keyboard/>

If I click on input then virtual keyboard is opening. But how can I open the keyboard without click. I tried using input.focus() that didn't work.

Body:
You are doing change outside angularJS framework, so you need to apply it by $scope.$apply();

var myApp = angular.module('myApp',['angular-virtual-keyboard']);
myApp.controller('MyCtrl',MyCtrl);

function MyCtrl($scope) {
    document.getElementsByTagName('input')[0].focus();
    $scope.$apply();
}


问:
I can't seem to define a variable to the value of a form
Hello fellow programmers, i'm trying to make a website that makes a route description, but I can't assign a variable to the input form.
I am trying to assign the variable "Bval" (B value) To the green select form, and "Aval" (A value) To the blue select form. Could anyone point out the issue in this code?

$(document).ready(function() {

  $('#selectroomA').change(function() {
   Aval = $('#selectroomA').value;
  });

 $('#selectroomB').change(function() {
  Bval = $('#selectroomB').value;
 });

 $('#submit').click(function() {
      console.log('clicked');
  if (Aval === "a001") {
            console.log('Aval = a001');
   if (Bval === "a001") {
              console.log('Bval = a001');
     alert('Je bent al in de A001');
   }
  } else {
          console.log('error with if statements');
        }
 });
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  margin: 0px;
  padding: 0px;
  font-family: Roboto;
}

.map-box {
  width: 600px;
  height: 300px;
  background: lightgrey;
  overflow: scroll;
}
.svg-container {
  width: 80%;
  margin-left: 10%;
  margin-right: 10%;
  overflow: scroll;
  background: lightgrey;
}
.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 1px;  /* Preferred icon size */
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;
  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;
  /* Support for IE. */
  font-feature-settings: 'liga';
}

/* Buildings */
#building {
  transition: 0.4s fill ease-in-out;
}
.building-a {
  height: 180px;
  width: 120px;
  fill: #455a64;
}
.building-a1 {
  height: 180px;
  width: 120px;
  fill: #1976D2;
}
.building-a2 {
  height: 180px;
  width: 120px;
  fill: #388E3C;
}
#a0 {
  opacity: 1;
}
#a1 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}
#a2 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}

/* Rooms */
#room {
  fill: #607d8b;
  transition: 0.4s fill ease-in-out;
}

/* Paths */
#generalpath {
  fill: white;
}
.path {
  transition: 0.3s opacity ease-in-out;
}
#a0path1, #a0path2, #a0path3, #a001pathty, #a002path, #a003path, #a004path, #a0stairpath {
  fill: #F44336;
  opacity: 0;
}

/* Form */
fieldset {
  border: none;
}
select {
  font-family: Roboto;
  background: white;
  color: black;
  padding: 5px;
  margin: 5px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
}
button {
  margin-top: 12px;
}
#selectroomA {
  background: #40C4FF;
}
#selectroomB {
  background: #00E676;
}

/* Buttons */
.buttons {
  display: block;
}
.upButton, .downButton {
  font-family: Roboto;
  background: #EEE;
  color: black;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: pointer;
  float: right;
}
.upButton, .downButton:hover {
  box-shadow: 2px 2px 6px #37474F;
  background-color: white;
}
#button i {
  margin-top: 4px;
  font-size: 22px;
}
.disabled {
  font-family: Roboto;
  background: #CCC;
  color: grey;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: default;
  float: right;
}
/* Toolbar */
#toolbartop {
  width: 77%;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #607D8B;
  color: white;
}
.selection {
  display: block;
  padding-right: 10px;
  white-space: nowrap;
}
.selection select {
  vertical-align: middle;
  margin-left: 10px;
}
#A {
  float: left;
}
#B {
  float: left;
}
#submit {
  width: 77%;
  height: 30px;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #455A64;
  color: white;
  text-align: center;
  cursor: pointer;
  transition: 0.4s background-color ease-in-out;
}
#submit:hover {
  background-color: #546E7A;
}</code>```

    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

      <form method="post">

          <fieldset class="ui-field-contain">

              <select name="selectroomA" id="selectroomA">
                <option value="null">Selecteer startpunt</option>
                <optgroup label="A-gebouw">
                  <option value="a001">A001</option>
                  <option value="a002">A002</option>
                  <option value="a003">A003</option>
                  <option value="a004">A004</option>
                  <option value="a005">A005</option>
                </optgroup>
              </select>

            <select name="selectroomB" id="selectroomB">
              <option value="null">Selecteer bestemming</option>
              <optgroup label="A-gebouw">
                <option value="a001">A001</option>
                <option value="a002">A002</option>
                <option value="a003">A003</option>
                <option value="a004">A004</option>
                <option value="a005">A005</option>
              </optgroup>
            </select>

          </fieldset>

      </form>

arrow_upward

arrow_downward

Maak route

    <svg class="map-box" xmlns="http://www.w3.org/2000/svg">
      <g id="a0">

        <g class="staircase">
          <rect x='160px' y='16px' height='35px' width='26px' id="building" fill="#455a64" />
          <rect x='175px' y='40px' height='10px' width='11px' fill="#2196f3"/>

          <rect x='175px' y='39px' height='4px' width='11px' fill="#2196f3"/>
          <rect x='175px' y='33px' height='4px' width='11px' fill="#2994E7"/>
          <rect x='175px' y='27px' height='4px' width='11px' fill="#368DCF"/>
          <rect x='160px' y='16px' height='9px' width='26px' fill="#3E8AC2"/>
          <rect x='160px' y='27px' height='4px' width='11px' fill="#4B85AE"/>
          <rect x='160px' y='33px' height='4px' width='11px' fill="#5A7F95"/>
          <rect x='160px' y='39px' height='4px' width='11px' fill="#607D8B"/>
        </g>

        <rect x='130px' y='50px' class="building-a" id="building"/>
        <rect x='330px' y='50px' class="building-a" id="building"/>

        <rect x='213px' y='200px' width="35px" height="30px" id="room" class="a001"/>

        <rect x='130px' y='110px' width="30px" height="57px" id="room" class="a002"/>

        <rect x='130px' y='50px' width="30px" height="57px" id="room" class="a003"/>

        <rect x='130px' y='170px' width="30px" height="50px" id="room" class="a004"/>
        <rect x='130px' y='200px' width="80px" height="30px" id="room" class="a004"/>

        <rect x='185px' y='50px' width="25px" height="40px" id="room" class="a007"/>

        <rect x='164px' y='179px' width="85px" height="17px" id="generalpath"/>
        <rect x='164px' y='50px' width="17px" height="137px" id="generalpath"/>

        <rect x='169px' y='185px' width="65px" height="7px" id="a0path1" class="path"/>
        <rect x='169px' y='135px' width="7px" height="50px" id="a0path2" class="path"/>
        <rect x='169px' y='75px' width="7px" height="60px" id="a0path3" class="path"/>

        <rect x='228px' y='185px' width="7px" height="15px" id="a001path" class="path"/>
        <rect x='160px' y='135px' width="15px" height="7px" id="a002path" class="path"/>
        <rect x='160px' y='75px' width="15px" height="7px" id="a003path" class="path"/>
        <rect x='160px' y='185px' width="15px" height="7px" id="a004path" class="path"/>

        <rect x='169px' y='50px' width="7px" height="60px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="16" height="5px" id="a0stairpath" class="path"/>
        <rect x='178px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
      </g>

      <g id="a1">

        <rect x='160px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='160px' y='16px' height='10px' width='26px' id="building" fill="#1976D2"/>
        <rect x='175px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='175px' y='40px' height='10px' width='11px' fill="#4CAF50"/>

        <rect x='175px' y='39px' height='4px' width='11px' fill="#4CAF50"/>
        <rect x='175px' y='33px' height='4px' width='11px' fill="#41A977"/>
        <rect x='175px' y='27px' height='4px' width='11px' fill="#3DA788"/>
        <rect x='160px' y='16px' height='9px' width='26px' fill="#36A2A5"/>
        <rect x='160px' y='27px' height='4px' width='11px' fill="#2E9EBE"/>
        <rect x='160px' y='33px' height='4px' width='11px' fill="#279AD9"/>
        <rect x='160px' y='39px' height='4px' width='11px' fill="#2196F3"/>

        <rect x='130px' y='50px' class="building-a1" id="building"/>

      </g>

      <g id="a2">
        <rect x='130px' y='50px' class="building-a2" id="building"/>
      </g>
    </svg>

```

Does anyone know what i did wrong? If so thanks in advance.

答:
change .value to .val() as you are using jquery

$(document).ready(function() {
  $('#selectroomA').change(function() {
   Aval = $('#selectroomA').val();
  });

 $('#selectroomB').change(function() {
  Bval = $('#selectroomB').val();
 });

 $('#submit').click(function() {
    console.log('clicked',Aval);
  if (Aval === "a001" && Bval === "a001"){
      console.log('Je bent al in de A001');
  }else{
      console.log('error with if statements');
    }
 });
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  margin: 0px;
  padding: 0px;
  font-family: Roboto;
}

.map-box {
  width: 600px;
  height: 300px;
  background: lightgrey;
  overflow: scroll;
}
.svg-container {
  width: 80%;
  margin-left: 10%;
  margin-right: 10%;
  overflow: scroll;
  background: lightgrey;
}
.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 1px;  /* Preferred icon size */
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;
  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;
  /* Support for IE. */
  font-feature-settings: 'liga';
}

/* Buildings */
#building {
  transition: 0.4s fill ease-in-out;
}
.building-a {
  height: 180px;
  width: 120px;
  fill: #455a64;
}
.building-a1 {
  height: 180px;
  width: 120px;
  fill: #1976D2;
}
.building-a2 {
  height: 180px;
  width: 120px;
  fill: #388E3C;
}
#a0 {
  opacity: 1;
}
#a1 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}
#a2 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}

/* Rooms */
#room {
  fill: #607d8b;
  transition: 0.4s fill ease-in-out;
}

/* Paths */
#generalpath {
  fill: white;
}
.path {
  transition: 0.3s opacity ease-in-out;
}
#a0path1, #a0path2, #a0path3, #a001pathty, #a002path, #a003path, #a004path, #a0stairpath {
  fill: #F44336;
  opacity: 0;
}

/* Form */
fieldset {
  border: none;
}
select {
  font-family: Roboto;
  background: white;
  color: black;
  padding: 5px;
  margin: 5px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
}
button {
  margin-top: 12px;
}
#selectroomA {
  background: #40C4FF;
}
#selectroomB {
  background: #00E676;
}

/* Buttons */
.buttons {
  display: block;
}
.upButton, .downButton {
  font-family: Roboto;
  background: #EEE;
  color: black;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: pointer;
  float: right;
}
.upButton, .downButton:hover {
  box-shadow: 2px 2px 6px #37474F;
  background-color: white;
}
#button i {
  margin-top: 4px;
  font-size: 22px;
}
.disabled {
  font-family: Roboto;
  background: #CCC;
  color: grey;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: default;
  float: right;
}
/* Toolbar */
#toolbartop {
  width: 77%;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #607D8B;
  color: white;
}
.selection {
  display: block;
  padding-right: 10px;
  white-space: nowrap;
}
.selection select {
  vertical-align: middle;
  margin-left: 10px;
}
#A {
  float: left;
}
#B {
  float: left;
}
#submit {
  width: 77%;
  height: 30px;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #455A64;
  color: white;
  text-align: center;
  cursor: pointer;
  transition: 0.4s background-color ease-in-out;
}
#submit:hover {
  background-color: #546E7A;
}</code>```

    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

      <form method="post">

          <fieldset class="ui-field-contain">

              <select name="selectroomA" id="selectroomA">
                <option value="null">Selecteer startpunt</option>
                <optgroup label="A-gebouw">
                  <option value="a001">A001</option>
                  <option value="a002">A002</option>
                  <option value="a003">A003</option>
                  <option value="a004">A004</option>
                  <option value="a005">A005</option>
                </optgroup>
              </select>

            <select name="selectroomB" id="selectroomB">
              <option value="null">Selecteer bestemming</option>
              <optgroup label="A-gebouw">
                <option value="a001">A001</option>
                <option value="a002">A002</option>
                <option value="a003">A003</option>
                <option value="a004">A004</option>
                <option value="a005">A005</option>
              </optgroup>
            </select>

          </fieldset>

      </form>

arrow_upward

arrow_downward

Maak route

    <svg class="map-box" xmlns="http://www.w3.org/2000/svg">
      <g id="a0">

        <g class="staircase">
          <rect x='160px' y='16px' height='35px' width='26px' id="building" fill="#455a64" />
          <rect x='175px' y='40px' height='10px' width='11px' fill="#2196f3"/>

          <rect x='175px' y='39px' height='4px' width='11px' fill="#2196f3"/>
          <rect x='175px' y='33px' height='4px' width='11px' fill="#2994E7"/>
          <rect x='175px' y='27px' height='4px' width='11px' fill="#368DCF"/>
          <rect x='160px' y='16px' height='9px' width='26px' fill="#3E8AC2"/>
          <rect x='160px' y='27px' height='4px' width='11px' fill="#4B85AE"/>
          <rect x='160px' y='33px' height='4px' width='11px' fill="#5A7F95"/>
          <rect x='160px' y='39px' height='4px' width='11px' fill="#607D8B"/>
        </g>

        <rect x='130px' y='50px' class="building-a" id="building"/>
        <rect x='330px' y='50px' class="building-a" id="building"/>

        <rect x='213px' y='200px' width="35px" height="30px" id="room" class="a001"/>

        <rect x='130px' y='110px' width="30px" height="57px" id="room" class="a002"/>

        <rect x='130px' y='50px' width="30px" height="57px" id="room" class="a003"/>

        <rect x='130px' y='170px' width="30px" height="50px" id="room" class="a004"/>
        <rect x='130px' y='200px' width="80px" height="30px" id="room" class="a004"/>

        <rect x='185px' y='50px' width="25px" height="40px" id="room" class="a007"/>

        <rect x='164px' y='179px' width="85px" height="17px" id="generalpath"/>
        <rect x='164px' y='50px' width="17px" height="137px" id="generalpath"/>

        <rect x='169px' y='185px' width="65px" height="7px" id="a0path1" class="path"/>
        <rect x='169px' y='135px' width="7px" height="50px" id="a0path2" class="path"/>
        <rect x='169px' y='75px' width="7px" height="60px" id="a0path3" class="path"/>

        <rect x='228px' y='185px' width="7px" height="15px" id="a001path" class="path"/>
        <rect x='160px' y='135px' width="15px" height="7px" id="a002path" class="path"/>
        <rect x='160px' y='75px' width="15px" height="7px" id="a003path" class="path"/>
        <rect x='160px' y='185px' width="15px" height="7px" id="a004path" class="path"/>

        <rect x='169px' y='50px' width="7px" height="60px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="16" height="5px" id="a0stairpath" class="path"/>
        <rect x='178px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
      </g>

      <g id="a1">

        <rect x='160px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='160px' y='16px' height='10px' width='26px' id="building" fill="#1976D2"/>
        <rect x='175px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='175px' y='40px' height='10px' width='11px' fill="#4CAF50"/>

        <rect x='175px' y='39px' height='4px' width='11px' fill="#4CAF50"/>
        <rect x='175px' y='33px' height='4px' width='11px' fill="#41A977"/>
        <rect x='175px' y='27px' height='4px' width='11px' fill="#3DA788"/>
        <rect x='160px' y='16px' height='9px' width='26px' fill="#36A2A5"/>
        <rect x='160px' y='27px' height='4px' width='11px' fill="#2E9EBE"/>
        <rect x='160px' y='33px' height='4px' width='11px' fill="#279AD9"/>
        <rect x='160px' y='39px' height='4px' width='11px' fill="#2196F3"/>

        <rect x='130px' y='50px' class="building-a1" id="building"/>

      </g>

      <g id="a2">
        <rect x='130px' y='50px' class="building-a2" id="building"/>
      </g>
    </svg>

```

Body:
Hello fellow programmers, i'm trying to make a website that makes a route description, but I can't assign a variable to the input form.
I am trying to assign the variable "Bval" (B value) To the green select form, and "Aval" (A value) To the blue select form. Could anyone point out the issue in this code?

$(document).ready(function() {

  $('#selectroomA').change(function() {
   Aval = $('#selectroomA').value;
  });

 $('#selectroomB').change(function() {
  Bval = $('#selectroomB').value;
 });

 $('#submit').click(function() {
      console.log('clicked');
  if (Aval === "a001") {
            console.log('Aval = a001');
   if (Bval === "a001") {
              console.log('Bval = a001');
     alert('Je bent al in de A001');
   }
  } else {
          console.log('error with if statements');
        }
 });
});

body {
  margin: 0px;
  padding: 0px;
  font-family: Roboto;
}

.map-box {
  width: 600px;
  height: 300px;
  background: lightgrey;
  overflow: scroll;
}
.svg-container {
  width: 80%;
  margin-left: 10%;
  margin-right: 10%;
  overflow: scroll;
  background: lightgrey;
}
.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 1px;  /* Preferred icon size */
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;
  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;
  /* Support for IE. */
  font-feature-settings: 'liga';
}

/* Buildings */
#building {
  transition: 0.4s fill ease-in-out;
}
.building-a {
  height: 180px;
  width: 120px;
  fill: #455a64;
}
.building-a1 {
  height: 180px;
  width: 120px;
  fill: #1976D2;
}
.building-a2 {
  height: 180px;
  width: 120px;
  fill: #388E3C;
}
#a0 {
  opacity: 1;
}
#a1 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}
#a2 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}

/* Rooms */
#room {
  fill: #607d8b;
  transition: 0.4s fill ease-in-out;
}

/* Paths */
#generalpath {
  fill: white;
}
.path {
  transition: 0.3s opacity ease-in-out;
}
#a0path1, #a0path2, #a0path3, #a001pathty, #a002path, #a003path, #a004path, #a0stairpath {
  fill: #F44336;
  opacity: 0;
}

/* Form */
fieldset {
  border: none;
}
select {
  font-family: Roboto;
  background: white;
  color: black;
  padding: 5px;
  margin: 5px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
}
button {
  margin-top: 12px;
}
#selectroomA {
  background: #40C4FF;
}
#selectroomB {
  background: #00E676;
}

/* Buttons */
.buttons {
  display: block;
}
.upButton, .downButton {
  font-family: Roboto;
  background: #EEE;
  color: black;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: pointer;
  float: right;
}
.upButton, .downButton:hover {
  box-shadow: 2px 2px 6px #37474F;
  background-color: white;
}
#button i {
  margin-top: 4px;
  font-size: 22px;
}
.disabled {
  font-family: Roboto;
  background: #CCC;
  color: grey;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: default;
  float: right;
}
/* Toolbar */
#toolbartop {
  width: 77%;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #607D8B;
  color: white;
}
.selection {
  display: block;
  padding-right: 10px;
  white-space: nowrap;
}
.selection select {
  vertical-align: middle;
  margin-left: 10px;
}
#A {
  float: left;
}
#B {
  float: left;
}
#submit {
  width: 77%;
  height: 30px;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #455A64;
  color: white;
  text-align: center;
  cursor: pointer;
  transition: 0.4s background-color ease-in-out;
}
#submit:hover {
  background-color: #546E7A;
}

    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

      <form method="post">

          <fieldset class="ui-field-contain">

              <select name="selectroomA" id="selectroomA">
                <option value="null">Selecteer startpunt</option>
                <optgroup label="A-gebouw">
                  <option value="a001">A001</option>
                  <option value="a002">A002</option>
                  <option value="a003">A003</option>
                  <option value="a004">A004</option>
                  <option value="a005">A005</option>
                </optgroup>
              </select>

            <select name="selectroomB" id="selectroomB">
              <option value="null">Selecteer bestemming</option>
              <optgroup label="A-gebouw">
                <option value="a001">A001</option>
                <option value="a002">A002</option>
                <option value="a003">A003</option>
                <option value="a004">A004</option>
                <option value="a005">A005</option>
              </optgroup>
            </select>

          </fieldset>

      </form>

arrow_upward

arrow_downward

Maak route

    <svg class="map-box" xmlns="http://www.w3.org/2000/svg">
      <g id="a0">

        <g class="staircase">
          <rect x='160px' y='16px' height='35px' width='26px' id="building" fill="#455a64" />
          <rect x='175px' y='40px' height='10px' width='11px' fill="#2196f3"/>

          <rect x='175px' y='39px' height='4px' width='11px' fill="#2196f3"/>
          <rect x='175px' y='33px' height='4px' width='11px' fill="#2994E7"/>
          <rect x='175px' y='27px' height='4px' width='11px' fill="#368DCF"/>
          <rect x='160px' y='16px' height='9px' width='26px' fill="#3E8AC2"/>
          <rect x='160px' y='27px' height='4px' width='11px' fill="#4B85AE"/>
          <rect x='160px' y='33px' height='4px' width='11px' fill="#5A7F95"/>
          <rect x='160px' y='39px' height='4px' width='11px' fill="#607D8B"/>
        </g>

        <rect x='130px' y='50px' class="building-a" id="building"/>
        <rect x='330px' y='50px' class="building-a" id="building"/>

        <rect x='213px' y='200px' width="35px" height="30px" id="room" class="a001"/>

        <rect x='130px' y='110px' width="30px" height="57px" id="room" class="a002"/>

        <rect x='130px' y='50px' width="30px" height="57px" id="room" class="a003"/>

        <rect x='130px' y='170px' width="30px" height="50px" id="room" class="a004"/>
        <rect x='130px' y='200px' width="80px" height="30px" id="room" class="a004"/>

        <rect x='185px' y='50px' width="25px" height="40px" id="room" class="a007"/>

        <rect x='164px' y='179px' width="85px" height="17px" id="generalpath"/>
        <rect x='164px' y='50px' width="17px" height="137px" id="generalpath"/>

        <rect x='169px' y='185px' width="65px" height="7px" id="a0path1" class="path"/>
        <rect x='169px' y='135px' width="7px" height="50px" id="a0path2" class="path"/>
        <rect x='169px' y='75px' width="7px" height="60px" id="a0path3" class="path"/>

        <rect x='228px' y='185px' width="7px" height="15px" id="a001path" class="path"/>
        <rect x='160px' y='135px' width="15px" height="7px" id="a002path" class="path"/>
        <rect x='160px' y='75px' width="15px" height="7px" id="a003path" class="path"/>
        <rect x='160px' y='185px' width="15px" height="7px" id="a004path" class="path"/>

        <rect x='169px' y='50px' width="7px" height="60px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="16" height="5px" id="a0stairpath" class="path"/>
        <rect x='178px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
      </g>

      <g id="a1">

        <rect x='160px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='160px' y='16px' height='10px' width='26px' id="building" fill="#1976D2"/>
        <rect x='175px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='175px' y='40px' height='10px' width='11px' fill="#4CAF50"/>

        <rect x='175px' y='39px' height='4px' width='11px' fill="#4CAF50"/>
        <rect x='175px' y='33px' height='4px' width='11px' fill="#41A977"/>
        <rect x='175px' y='27px' height='4px' width='11px' fill="#3DA788"/>
        <rect x='160px' y='16px' height='9px' width='26px' fill="#36A2A5"/>
        <rect x='160px' y='27px' height='4px' width='11px' fill="#2E9EBE"/>
        <rect x='160px' y='33px' height='4px' width='11px' fill="#279AD9"/>
        <rect x='160px' y='39px' height='4px' width='11px' fill="#2196F3"/>

        <rect x='130px' y='50px' class="building-a1" id="building"/>

      </g>

      <g id="a2">
        <rect x='130px' y='50px' class="building-a2" id="building"/>
      </g>
    </svg>

Does anyone know what i did wrong? If so thanks in advance.

Body:
change .value to .val() as you are using jquery

$(document).ready(function() {
  $('#selectroomA').change(function() {
   Aval = $('#selectroomA').val();
  });

 $('#selectroomB').change(function() {
  Bval = $('#selectroomB').val();
 });

 $('#submit').click(function() {
    console.log('clicked',Aval);
  if (Aval === "a001" && Bval === "a001"){
      console.log('Je bent al in de A001');
  }else{
      console.log('error with if statements');
    }
 });
});

body {
  margin: 0px;
  padding: 0px;
  font-family: Roboto;
}

.map-box {
  width: 600px;
  height: 300px;
  background: lightgrey;
  overflow: scroll;
}
.svg-container {
  width: 80%;
  margin-left: 10%;
  margin-right: 10%;
  overflow: scroll;
  background: lightgrey;
}
.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 1px;  /* Preferred icon size */
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;
  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;
  /* Support for IE. */
  font-feature-settings: 'liga';
}

/* Buildings */
#building {
  transition: 0.4s fill ease-in-out;
}
.building-a {
  height: 180px;
  width: 120px;
  fill: #455a64;
}
.building-a1 {
  height: 180px;
  width: 120px;
  fill: #1976D2;
}
.building-a2 {
  height: 180px;
  width: 120px;
  fill: #388E3C;
}
#a0 {
  opacity: 1;
}
#a1 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}
#a2 {
  opacity: 0;
  transition: 0.4s opacity ease-in-out;
}

/* Rooms */
#room {
  fill: #607d8b;
  transition: 0.4s fill ease-in-out;
}

/* Paths */
#generalpath {
  fill: white;
}
.path {
  transition: 0.3s opacity ease-in-out;
}
#a0path1, #a0path2, #a0path3, #a001pathty, #a002path, #a003path, #a004path, #a0stairpath {
  fill: #F44336;
  opacity: 0;
}

/* Form */
fieldset {
  border: none;
}
select {
  font-family: Roboto;
  background: white;
  color: black;
  padding: 5px;
  margin: 5px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
}
button {
  margin-top: 12px;
}
#selectroomA {
  background: #40C4FF;
}
#selectroomB {
  background: #00E676;
}

/* Buttons */
.buttons {
  display: block;
}
.upButton, .downButton {
  font-family: Roboto;
  background: #EEE;
  color: black;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: pointer;
  float: right;
}
.upButton, .downButton:hover {
  box-shadow: 2px 2px 6px #37474F;
  background-color: white;
}
#button i {
  margin-top: 4px;
  font-size: 22px;
}
.disabled {
  font-family: Roboto;
  background: #CCC;
  color: grey;
  transition: 0.4s all ease-in-out;
  border-radius: 2px;
  text-align: center;
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  cursor: default;
  float: right;
}
/* Toolbar */
#toolbartop {
  width: 77%;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #607D8B;
  color: white;
}
.selection {
  display: block;
  padding-right: 10px;
  white-space: nowrap;
}
.selection select {
  vertical-align: middle;
  margin-left: 10px;
}
#A {
  float: left;
}
#B {
  float: left;
}
#submit {
  width: 77%;
  height: 30px;
  padding-top: 10px;
  padding-left: 2%;
  padding-right: 1%;
  margin-left: 10%;
  margin-right: 7%;
  background-color: #455A64;
  color: white;
  text-align: center;
  cursor: pointer;
  transition: 0.4s background-color ease-in-out;
}
#submit:hover {
  background-color: #546E7A;
}

<html>
  <head>
   <script
  src="https://code.jquery.com/jquery-3.2.1.min.js"
  integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  crossorigin="anonymous"></script>
    <script src="code.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  </head>
  <body>
    <div id="toolbartop">
      <form method="post">
        <div class="selection">
          <fieldset class="ui-field-contain">
            <div id="A">
              <select name="selectroomA" id="selectroomA">
                <option value="null">Selecteer startpunt</option>
                <optgroup label="A-gebouw">
                  <option value="a001">A001</option>
                  <option value="a002">A002</option>
                  <option value="a003">A003</option>
                  <option value="a004">A004</option>
                  <option value="a005">A005</option>
                </optgroup>
              </select>
            </div>
            <div id="B">
            <select name="selectroomB" id="selectroomB">
              <option value="null">Selecteer bestemming</option>
              <optgroup label="A-gebouw">
                <option value="a001">A001</option>
                <option value="a002">A002</option>
                <option value="a003">A003</option>
                <option value="a004">A004</option>
                <option value="a005">A005</option>
              </optgroup>
            </select>
            </div>
          </fieldset>
        </div>
      </form>
      <div class="buttons">
        <div id="button" class="upButton" onselectstart="return false"><i class="material-icons">arrow_upward</i></div>
        <div id="button" class="downButton" onselectstart="return false"><i class="material-icons">arrow_downward</i></div>
      </div>
    </div>
    <div id="submit" onselectstart="return false">Maak route</div>

    <div class="svg-container">
    <svg class="map-box" xmlns="http://www.w3.org/2000/svg">
      <g id="a0">
        <!-- Staircase -->
        <g class="staircase">
          <rect x='160px' y='16px' height='35px' width='26px' id="building" fill="#455a64" />
          <rect x='175px' y='40px' height='10px' width='11px' fill="#2196f3"/>

          <rect x='175px' y='39px' height='4px' width='11px' fill="#2196f3"/>
          <rect x='175px' y='33px' height='4px' width='11px' fill="#2994E7"/>
          <rect x='175px' y='27px' height='4px' width='11px' fill="#368DCF"/>
          <rect x='160px' y='16px' height='9px' width='26px' fill="#3E8AC2"/>
          <rect x='160px' y='27px' height='4px' width='11px' fill="#4B85AE"/>
          <rect x='160px' y='33px' height='4px' width='11px' fill="#5A7F95"/>
          <rect x='160px' y='39px' height='4px' width='11px' fill="#607D8B"/>
        </g>

        <!-- Building -->
        <rect x='130px' y='50px' class="building-a" id="building"/>
        <rect x='330px' y='50px' class="building-a" id="building"/>

        <!-- Rooms -->
        <rect x='213px' y='200px' width="35px" height="30px" id="room" class="a001"/>

        <rect x='130px' y='110px' width="30px" height="57px" id="room" class="a002"/>

        <rect x='130px' y='50px' width="30px" height="57px" id="room" class="a003"/>

        <rect x='130px' y='170px' width="30px" height="50px" id="room" class="a004"/>
        <rect x='130px' y='200px' width="80px" height="30px" id="room" class="a004"/>

        <rect x='185px' y='50px' width="25px" height="40px" id="room" class="a007"/>

        <!-- General Path -->
        <rect x='164px' y='179px' width="85px" height="17px" id="generalpath"/>
        <rect x='164px' y='50px' width="17px" height="137px" id="generalpath"/>

        <!-- Specific paths -->
        <rect x='169px' y='185px' width="65px" height="7px" id="a0path1" class="path"/>
        <rect x='169px' y='135px' width="7px" height="50px" id="a0path2" class="path"/>
        <rect x='169px' y='75px' width="7px" height="60px" id="a0path3" class="path"/>

        <rect x='228px' y='185px' width="7px" height="15px" id="a001path" class="path"/>
        <rect x='160px' y='135px' width="15px" height="7px" id="a002path" class="path"/>
        <rect x='160px' y='75px' width="15px" height="7px" id="a003path" class="path"/>
        <rect x='160px' y='185px' width="15px" height="7px" id="a004path" class="path"/>

        <rect x='169px' y='50px' width="7px" height="60px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
        <rect x='163px' y='18px' width="16" height="5px" id="a0stairpath" class="path"/>
        <rect x='178px' y='18px' width="5" height="32px" id="a0stairpath" class="path"/>
      </g>

      <g id="a1">
        <!-- Staircase -->
        <rect x='160px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='160px' y='16px' height='10px' width='26px' id="building" fill="#1976D2"/>
        <rect x='175px' y='16px' height='35px' width='11px' id="building" fill="#1976D2"/>
        <rect x='175px' y='40px' height='10px' width='11px' fill="#4CAF50"/>

        <rect x='175px' y='39px' height='4px' width='11px' fill="#4CAF50"/>
        <rect x='175px' y='33px' height='4px' width='11px' fill="#41A977"/>
        <rect x='175px' y='27px' height='4px' width='11px' fill="#3DA788"/>
        <rect x='160px' y='16px' height='9px' width='26px' fill="#36A2A5"/>
        <rect x='160px' y='27px' height='4px' width='11px' fill="#2E9EBE"/>
        <rect x='160px' y='33px' height='4px' width='11px' fill="#279AD9"/>
        <rect x='160px' y='39px' height='4px' width='11px' fill="#2196F3"/>

        <!-- Building -->
        <rect x='130px' y='50px' class="building-a1" id="building"/>

      </g>

      <g id="a2">
        <rect x='130px' y='50px' class="building-a2" id="building"/>
      </g>
    </svg>
    </div>
  </body>
</html>


问:
How can I see the request headers made by curl when sending a request to the server?
I want to see the request headers made by curl when I am sending a request to the server. How can I check that?

答:
I know this is a little late, but my favoured method for doing this is netcat, as you get exactly what curl sent; this can differ from the --trace or --trace-ascii options which won't show non-ASCII characters properly (they just show as dots or need to be decoded).

You can do this as very easily by opening two terminal windows, in the first type:

```<code>nc -l localhost 12345
</code>```

This opens a listening process on port 12345 of your local machine.

In the second terminal window enter your curl command, for example:

```<code>curl --form 'foo=bar' localhost:12345
</code>```

In the first terminal window you will see exactly what curl sent in the request.

Now of course nc won't send anything in response (unless you type it in yourself), so you will need to interrupt the curl command (control-c) and repeat the process for each test.

However, this is a useful option for simply debugging your request, as you're not involving a round-trip anywhere, or producing bogus, iterative requests somewhere until you get it right; once you're happy with the command, simply redirect it to a valid URL and you're good to go.

You can do the same for any cURL library as well, simply edit your request to point to the local nc listener until you're happy with it.

OwnerDisplayName: leela

Body:
I know this is a little late, but my favoured method for doing this is netcat, as you get exactly what curl sent; this can differ from the --trace or --trace-ascii options which won't show non-ASCII characters properly (they just show as dots or need to be decoded).

You can do this as very easily by opening two terminal windows, in the first type:

nc -l localhost 12345

This opens a listening process on port 12345 of your local machine.

In the second terminal window enter your curl command, for example:

curl --form 'foo=bar' localhost:12345

In the first terminal window you will see exactly what curl sent in the request.

Now of course nc won't send anything in response (unless you type it in yourself), so you will need to interrupt the curl command (control-c) and repeat the process for each test.

However, this is a useful option for simply debugging your request, as you're not involving a round-trip anywhere, or producing bogus, iterative requests somewhere until you get it right; once you're happy with the command, simply redirect it to a valid URL and you're good to go.

You can do the same for any cURL library as well, simply edit your request to point to the local nc listener until you're happy with it.


问:
Return words before specific character from wordpress the_title();
I am trying to get words before specific character in WordPress the_title().

My WordPress post titles always looks something like this "How To - Make Things Happen".

How can I return all the words before the "-" in PHP, for example get "How To" from "How To - Make Things"

I am trying to use all words before "-" and a keyword within the post page.

I have seen a similar solution here: Get first word in string php the_title WordPress but it doesn't  fit perfectly as I am trying to get all words before a specific character

答:
Just remove the index from above answer by Narek.
Try this:</p>

```<code>$title = current(explode('-', 'How To - Make Things Happen'));

echo $title;
</code>```

Body:
Just remove the index from above answer by Narek.
Try this:

$title = current(explode('-', 'How To - Make Things Happen'));

echo $title;


答:
```<code>wget -r http://yoursite.com
</code>```

Should be sufficient and grab images/media. There are plenty of options you can feed it.

Note: I believe wget nor any other program supports downloading images specified through CSS - so you may need to do that yourself manually.

Here may be some useful arguments: http://www.linuxjournal.com/content/downloading-entire-web-site-wget

Title: What's the best way to save a complete webpage on a linux server?

Body:
I need to archive complete pages including any linked images etc. on my linux server. Looking for the best solution. Is there a way to save all assets and then relink them all to work in the same directory?

I've thought about using curl, but I'm unsure of how to do all of this. Also, will I maybe need PHP-DOM?

Is there a way to use firefox on the server and copy the temp files after the address has been loaded or similar?

Any and all input welcome.

Edit:

It seems as though wget is 'not' going to work as the files need to be rendered. I have firefox installed on the server, is there a way to load the url in firefox and then grab the temp files and clear the temp files after?

Body:
wget -r http://yoursite.com

Should be sufficient and grab images/media. There are plenty of options you can feed it.

Note: I believe wget nor any other program supports downloading images specified through CSS - so you may need to do that yourself manually.

Here may be some useful arguments: http://www.linuxjournal.com/content/downloading-entire-web-site-wget


问:
looping through an array backwards from current position
I am quite new to java and android so be patient with me. I have an xml layout containing two buttons. One containing text of "previous" and the other "next". I also have a class containing array of strings which loops in an ascending order in a textView when a "next" button is clicked.

What i want is that i want the array to loop backwards from its current position when the "previous" button is clicked. Any ideas?

Question Class

```<code>// This file contains questions from QuestionBank
class Question{
    // array of questions
    private String mQuestions [] = {
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
    // method returns number of questions
    int getLength(){
        return mQuestions.length;
    }

    // method returns question from array textQuestions[] based on array index
    String getQuestion(int a) {
        return mQuestions[a];
    }
}
</code>```

Main Activity.java

```<code>     public class MainActivityextends AppCompatActivity {
                private QuestionLibraryBeginner mQuestionLibrary = new QuestionLibraryBeginner();
                private int mQuestionNumber = 1; // current question number
            //initialising navigation buttons
                private Button mPrevious;
                private Button mNext;
            private TextView mQuestionText;
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_beginner_review);
                    mPrevious = (Button) findViewById(R.id.previous);
                    mNext = (Button) findViewById(R.id.next);
  mQuestionText = (TextView) findViewById(R.id.txtQuestion);
                    // receive the current question number from last activity by Intent

        Intent intent = getIntent();
             currentQuestionNumber = intent.getIntExtra("quizNumber", 0); // receiving the number of questions the user has attempted from previous activity
                    mNext.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
    // checking against total number of questions the user has attempted instead of total number of questions from Question Class
    if (mQuestionNumber < currentQuestionNumber) {
             updateQuestion();
                        }
                    });
                    mPrevious.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
            // i want it to loop backwards from here
                        }
                    });

            // logic to update question from array
                private void updateQuestion() {
                    if (mQuestionNumber < mQuestionLibrary.getLength()) {
                        mQuestionText.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
                        mQuestionNumber++;
                    }
                }

            }
</code>```

答:
It can be done by just adding a flag to mention the move,

```<code>mNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateQuestion(true);
        });
mPrevious.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateQuestion(false);
            }
        });
</code>```

And the method would look like:

```<code>private void updateQuestion(boolean forward) {
        if(forward && mQuestionNumber < mQuestionLibrary.getLength())
            mQuestionNumber++
        else if (mQuestionNumber>1)
            mQuestionNumber--;
        mQuestionText.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
}
</code>```

Body:
I am quite new to java and android so be patient with me. I have an xml layout containing two buttons. One containing text of "previous" and the other "next". I also have a class containing array of strings which loops in an ascending order in a textView when a "next" button is clicked.

What i want is that i want the array to loop backwards from its current position when the "previous" button is clicked. Any ideas?

Question Class

// This file contains questions from QuestionBank
class Question{
    // array of questions
    private String mQuestions [] = {
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
    // method returns number of questions
    int getLength(){
        return mQuestions.length;
    }

    // method returns question from array textQuestions[] based on array index
    String getQuestion(int a) {
        return mQuestions[a];
    }
}

Main Activity.java

     public class MainActivityextends AppCompatActivity {
                private QuestionLibraryBeginner mQuestionLibrary = new QuestionLibraryBeginner();
                private int mQuestionNumber = 1; // current question number
            //initialising navigation buttons
                private Button mPrevious;
                private Button mNext;
            private TextView mQuestionText;
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_beginner_review);
                    mPrevious = (Button) findViewById(R.id.previous);
                    mNext = (Button) findViewById(R.id.next);
  mQuestionText = (TextView) findViewById(R.id.txtQuestion);
                    // receive the current question number from last activity by Intent

        Intent intent = getIntent();
             currentQuestionNumber = intent.getIntExtra("quizNumber", 0); // receiving the number of questions the user has attempted from previous activity
                    mNext.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
    // checking against total number of questions the user has attempted instead of total number of questions from Question Class
    if (mQuestionNumber < currentQuestionNumber) {
             updateQuestion();
                        }
                    });
                    mPrevious.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
            // i want it to loop backwards from here
                        }
                    });

            // logic to update question from array
                private void updateQuestion() {
                    if (mQuestionNumber < mQuestionLibrary.getLength()) {
                        mQuestionText.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
                        mQuestionNumber++;
                    }
                }

            }

Body:
It can be done by just adding a flag to mention the move,

mNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateQuestion(true);
        });
mPrevious.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateQuestion(false);
            }
        });

And the method would look like:

private void updateQuestion(boolean forward) {
        if(forward && mQuestionNumber < mQuestionLibrary.getLength())
            mQuestionNumber++
        else if (mQuestionNumber>1)
            mQuestionNumber--;
        mQuestionText.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
}


问:
linking the fields in php
```<code>Table_gnews|
+-------------------+
| gnewsid=>int      |
| gnewsh=>varchar   |
| gnewsd=>varchar   |

Data:
gnewsh:test
gnewsd:leadstart.in/blog
</code>```

PHP code below

```<code><?php

$hostname = "localhost";
$username = "gb";
$password = "123";
$dbname = "test_database";
$limitStart = $_POST['limitStart'];
$limitCount = 100;
if(isset($limitStart ) || !empty($limitStart)) {
$con = mysqli_connect($hostname, $username, $password, $dbname);
$query = "SELECT * FROM gnews ORDER BY gnewsid limit $limitStart, $limitCount";
$result = mysqli_query($con, $query);
$res = array();
while($result1 = mysqli_fetch_assoc($result)) {
$res[$result1['gnewsid']] ='<h3>' . <a href="$result1["gnewsd"]" target="_blank">"$result1["gnewsh"]"</a> . '</h3>';
}
echo json_encode($res);
}
?>
</code>```

What I want:
When I click "test" it will open "leadstart.in/blog" in a separate tab.
I tried in this way: But no result

```<code>$res[$result1['gnewsid']] ='<h3>' . <a href="$result1["gnewsd"]" target="_blank">"$result1["gnewsh"]"</a> . '</h3>';
</code>```

Where  is the fault?
Any Help

答:
Try like this:</p>

```<code>$res[$result1['gnewsid']] ='<h3> <a href="'.$result1['gnewsd'].'" target="_tab">'.$result1['gnewsh'].'</a></h3>';
</code>```

Title: linking the fields in php

Body:
Table_gnews|
+-------------------+
| gnewsid=>int      |
| gnewsh=>varchar   |
| gnewsd=>varchar   |

Data:
gnewsh:test
gnewsd:leadstart.in/blog

PHP code below

<?php

$hostname = "localhost";
$username = "gb";
$password = "123";
$dbname = "test_database";
$limitStart = $_POST['limitStart'];
$limitCount = 100;
if(isset($limitStart ) || !empty($limitStart)) {
$con = mysqli_connect($hostname, $username, $password, $dbname);
$query = "SELECT * FROM gnews ORDER BY gnewsid limit $limitStart, $limitCount";
$result = mysqli_query($con, $query);
$res = array();
while($result1 = mysqli_fetch_assoc($result)) {
$res[$result1['gnewsid']] ='
' . "$result1["gnewsh"]" . '
';
}
echo json_encode($res);
}
?>

What I want:
When I click "test" it will open "leadstart.in/blog" in a separate tab.
I tried in this way: But no result

$res[$result1['gnewsid']] ='
' . "$result1["gnewsh"]" . '
';

Where  is the fault?
Any Help

Body:
Try like this:

$res[$result1['gnewsid']] ='<h3> <a href="'.$result1['gnewsd'].'" target="_tab">'.$result1['gnewsh'].'</a></h3>';


问:
Date failing to update, but returning true for Update (Rails ActiveRecord)
I have a Rails model called user that has a birthday field with type date in Postgres.

My first issue is that I'm not sure how to update the value of a user. If I pass in a string like "10/10/1980", it does not update.

The second issue is that even when the birthday is not updated, Rails returns true for the User.update(user_params) action

My two questions:

How can I update a date field?

How can I make sure that rails throws an error if an incorrect date is passed in?

How can I update a date field?

Update method from controller below. Fairly standard from scaffolding.

```<code>  # PATCH/PUT /users/1
  # PATCH/PUT /users/1.json
  def update
    respond_to do |format|
      puts(user_params)
      if @user.update(user_params)
        format.html { redirect_to @user, notice: 'User was successfully updated.' }
        format.json { render :show, status: :ok, location: @user }
      else
        format.html { render :edit }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end
</code>```

Edit: Params:

```<code>  def user_params
    params.require(:user)
          .permit(:points, :payment_option, :first_name, :last_name,
                  :payment_email, :phone_number, :facebook_id, :profile_pic_url,
                  :locale, :timezone, :gender, :email, :country, :city,
                  :age_group, :birthday, :employment_status, :occupation,
                  :education_level, :income_bracket)
  end
</code>```

Rails log (note that I added a puts(user_params) after the update statement.

```<code>Started PATCH "/api/v1/users/1" for 127.0.0.1 at 2017-12-07 19:16:37 +0800
Processing by UsersController#update as JSON
  Parameters: {"user"=>{"birthday"=>"12dsafkljfsldk"}, "id"=>"1"}
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
Can't verify CSRF token authenticity.
{"birthday"=>"10/10/1900"}
   (0.2ms)  BEGIN
   (0.1ms)  COMMIT
  Rendering users/show.json.jbuilder
  Rendered users/_user.json.jbuilder (0.6ms)
  Rendered users/show.json.jbuilder (1.6ms)
Completed 200 OK in 31ms (Views: 5.9ms | ActiveRecord: 3.1ms)
</code>```

I was hoping that I could use before_update to parse the date string into a Date object before saving, but it doesn't look like self.birthday is even showing up in the model.

答:
Place this line in your ApplicationController

```<code> protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
</code>```

If it doesn't work then. Try to skip the action

```<code>skip_before_action :verify_authenticity_token
</code>```

Body:
I have a Rails model called user that has a birthday field with type date in Postgres.

My first issue is that I'm not sure how to update the value of a user. If I pass in a string like "10/10/1980", it does not update.

The second issue is that even when the birthday is not updated, Rails returns true for the User.update(user_params) action

My two questions:

How can I update a date field?

How can I make sure that rails throws an error if an incorrect date is passed in?

How can I update a date field?

Update method from controller below. Fairly standard from scaffolding.

  # PATCH/PUT /users/1
  # PATCH/PUT /users/1.json
  def update
    respond_to do |format|
      puts(user_params)
      if @user.update(user_params)
        format.html { redirect_to @user, notice: 'User was successfully updated.' }
        format.json { render :show, status: :ok, location: @user }
      else
        format.html { render :edit }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

Edit: Params:

  def user_params
    params.require(:user)
          .permit(:points, :payment_option, :first_name, :last_name,
                  :payment_email, :phone_number, :facebook_id, :profile_pic_url,
                  :locale, :timezone, :gender, :email, :country, :city,
                  :age_group, :birthday, :employment_status, :occupation,
                  :education_level, :income_bracket)
  end

Rails log (note that I added a puts(user_params) after the update statement.

Started PATCH "/api/v1/users/1" for 127.0.0.1 at 2017-12-07 19:16:37 +0800
Processing by UsersController#update as JSON
  Parameters: {"user"=>{"birthday"=>"12dsafkljfsldk"}, "id"=>"1"}
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
Can't verify CSRF token authenticity.
{"birthday"=>"10/10/1900"}
   (0.2ms)  BEGIN
   (0.1ms)  COMMIT
  Rendering users/show.json.jbuilder
  Rendered users/_user.json.jbuilder (0.6ms)
  Rendered users/show.json.jbuilder (1.6ms)
Completed 200 OK in 31ms (Views: 5.9ms | ActiveRecord: 3.1ms)

I was hoping that I could use before_update to parse the date string into a Date object before saving, but it doesn't look like self.birthday is even showing up in the model.

Body:
Place this line in your ApplicationController

 protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }

If it doesn't work then. Try to skip the action

skip_before_action :verify_authenticity_token


问:
Get form attribute value with PHP
Is there a way to get submitted form's attribute value using PHP, when the submit button is clicked?

I have a form which has attribute data-id: someid, I need to get this value.

答:
There is no direct way to get the data attribute value in PHP.
You have to first get data-attribute, set this value to hidden field and then use PHP to get it.</p>

Title: Get form attribute value with PHP


问:
How to get the list of attendees and their email addresses from calendar's event in Swift?
I want to get the attendees list of the calendar's event, and I dont know how to do it in Swift 3. I also want to get the email address of any event's attendee to contact them through my app.
Does anyone can help me?

Thanks.

I retrieve the events with this fuction :

```<code>func loadEvents() {

    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "dd-MM-yyyy"

    let date = Date()
    let calendar2 = Calendar.current
    let components = calendar2.dateComponents([.year, .month, .day], from: date)

    let year =  components.year
    let month = components.month
    let day = components.day

    let startDate = dateFormatter.date(from: "\(day ?? 01)" + "-" + "\(month ?? 01)" + "-" + "\(year ?? 2017)")
    let endDate = dateFormatter.date(from: "31-12-" + "\(year ?? 2099)")

    if let startDate = startDate, let endDate = endDate {
        let eventStore = EKEventStore()

        let eventsPredicate = eventStore.predicateForEvents(withStart: startDate, end: endDate, calendars: [calendar])

        self.events = eventStore.events(matching: eventsPredicate).sorted() {
            (e1: EKEvent, e2: EKEvent) -> Bool in

            return e1.startDate.compare(e2.startDate) == ComparisonResult.orderedAscending
        }

    }
}
</code>```

And I list them inside a UITableView like this:

```<code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell")!
        cell.textLabel?.text = events?[(indexPath as NSIndexPath).row].title
        cell.detailTextLabel?.text = formatDate(events?[(indexPath as NSIndexPath).row].startDate)
        return cell
}
</code>```

But when I'm trying to get attendees for one event like this:

```<code>if (events?[(indexPath as IndexPath).row].hasAttendees)! {
      let eventsAttendees: [EKParticipant]! = events?[(indexPath as IndexPath).row].attendees
}
</code>```

I always have eventsAttendees = nil

I dont understand.

答:
I got name and email of event attendees like this:</p>

```<code>for attendee in event.attendees {
    let email = (attendee.url.absoluteString).replacingOccurrences(of: "mailto:", with: "")
    let name = attendee.name ?? ""
}
</code>```

Body:
I want to get the attendees list of the calendar's event, and I dont know how to do it in Swift 3. I also want to get the email address of any event's attendee to contact them through my app.
Does anyone can help me?

Thanks.

I retrieve the events with this fuction :

func loadEvents() {

    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "dd-MM-yyyy"

    let date = Date()
    let calendar2 = Calendar.current
    let components = calendar2.dateComponents([.year, .month, .day], from: date)

    let year =  components.year
    let month = components.month
    let day = components.day

    let startDate = dateFormatter.date(from: "\(day ?? 01)" + "-" + "\(month ?? 01)" + "-" + "\(year ?? 2017)")
    let endDate = dateFormatter.date(from: "31-12-" + "\(year ?? 2099)")

    if let startDate = startDate, let endDate = endDate {
        let eventStore = EKEventStore()

        let eventsPredicate = eventStore.predicateForEvents(withStart: startDate, end: endDate, calendars: [calendar])

        self.events = eventStore.events(matching: eventsPredicate).sorted() {
            (e1: EKEvent, e2: EKEvent) -> Bool in

            return e1.startDate.compare(e2.startDate) == ComparisonResult.orderedAscending
        }

    }
}

And I list them inside a UITableView like this:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell")!
        cell.textLabel?.text = events?[(indexPath as NSIndexPath).row].title
        cell.detailTextLabel?.text = formatDate(events?[(indexPath as NSIndexPath).row].startDate)
        return cell
}

But when I'm trying to get attendees for one event like this:

if (events?[(indexPath as IndexPath).row].hasAttendees)! {
      let eventsAttendees: [EKParticipant]! = events?[(indexPath as IndexPath).row].attendees
}

I always have eventsAttendees = nil

I dont understand.

Body:
I got name and email of event attendees like this:

for attendee in event.attendees {
    let email = (attendee.url.absoluteString).replacingOccurrences(of: "mailto:", with: "")
    let name = attendee.name ?? ""
}


问:
Prolog - Backtracking through a set of dynamic options
I'm trying to trigger backtracking on a goal but in a dynamic way, if it's possible. To better exemplify my issue let's say we have the following PROLOG code:

```<code>num(1).
num(2).
num(3).
num(4).
num(5).
</code>```

Then I head to SWI-Prolog and call: num(X). This triggers backtracking looking for all solutions, by typing ; .

What I would like is to remove those facts (num(1),num(2), etc) and replace that code with something thata generates those facts dynamically. Is there any way in which I can achieve this? Someting of the sorts,maybe?

```<code>num(X):- for X in 1..5
</code>```

that yields the same solutions as the code above?

As far as I know, the findall predicate returns a list, which is not what I'm looking for. I would like to backtrack through all answers and look through them using ; in the console.

答:
Yes there is, and you were already very close!</p>

```<code>:- use_module(library(clpfd)).

num(X) :-
   X in 1..5.

?- num(X).
   X in 1..5.

?- num(X), X #>3.
   X in 4..5.

?- num(X), labeling([], [X]).
   X = 1
;  X = 2
;  X = 3
;  X = 4
;  X = 5.
</code>```

Body:
I'm trying to trigger backtracking on a goal but in a dynamic way, if it's possible. To better exemplify my issue let's say we have the following PROLOG code:

num(1).
num(2).
num(3).
num(4).
num(5).

Then I head to SWI-Prolog and call: num(X). This triggers backtracking looking for all solutions, by typing ; .

What I would like is to remove those facts (num(1),num(2), etc) and replace that code with something thata generates those facts dynamically. Is there any way in which I can achieve this? Someting of the sorts,maybe?

num(X):- for X in 1..5

that yields the same solutions as the code above?

As far as I know, the findall predicate returns a list, which is not what I'm looking for. I would like to backtrack through all answers and look through them using ; in the console.

Body:
Yes there is, and you were already very close!

:- use_module(library(clpfd)).

num(X) :-
   X in 1..5.

?- num(X).
   X in 1..5.

?- num(X), X #>3.
   X in 4..5.

?- num(X), labeling([], [X]).
   X = 1
;  X = 2
;  X = 3
;  X = 4
;  X = 5.


问:
Breaking Django views into seperate directories and files
I'm quite new to Django and I'm enjoying it a lot. I have broken my app's views into different files and placed them in a directory called app/views/(view files).

I have made an __init__.py file in the views directory this has caused me to have to use myproj.app.views.views in my site code. Which of coarse not very digestible.

Any ideas around this. Or is renaming my views directory to something else the way forward.

Thanks.

答:
My user profile app account has three views files: views.py, views_login.py, and views_profile.py.  Maybe it's not the cleanest, but it separates the three parts of account pretty well for my needs.  My apps/account/urls.py therefore looks like this:

```<code>from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^foo1$', 'apps.account.views.foo1'),
    (r'^foo2$', 'apps.account.views.foo2'),
    (r'^bar1$', 'apps.account.views_login.bar1'),
    (r'^bar2$', 'apps.account.views_login.bar2'),
    (r'^baz1$', 'apps.account.views_profile.baz1'),
    (r'^baz2$', 'apps.account.views_profile.baz2'),
)
</code>```

Body:
My user profile app account has three views files: views.py, views_login.py, and views_profile.py.  Maybe it's not the cleanest, but it separates the three parts of account pretty well for my needs.  My apps/account/urls.py therefore looks like this:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^foo1$', 'apps.account.views.foo1'),
    (r'^foo2$', 'apps.account.views.foo2'),
    (r'^bar1$', 'apps.account.views_login.bar1'),
    (r'^bar2$', 'apps.account.views_login.bar2'),
    (r'^baz1$', 'apps.account.views_profile.baz1'),
    (r'^baz2$', 'apps.account.views_profile.baz2'),
)


问:
XCASParsingException while trying to deserialize xmi into CAS object
I have made Ruta scripts run from Java and have converted the resulting CAS object into an xmi file as below;

```<code>FileOutputStream fileOutputStream = new FileOutputStream(outputXmiFile);
XmiCasSerializer.serialize(cas, fileOutputStream);
</code>```

When I try to convert it back into a CAS object (on another server), as below;

```<code>FileInputStream fileInputStream = new FileInputStream(xmiFile);
XmlCasDeserializer.deserialize(fileInputStream, cas);
</code>```

I get the below exception;

```<code>XCASParsingException: Error parsing XCAS or XMI-CAS from source <unknown> at line <unknown>, column <unknown>: unknown type: NULL.
</code>```

A snapshot of the exception.

答:
Ya Thanks ! It worked !

import org.apache.uima.util.CasIOUtils;

CAS to XMI

```<code>CasIOUtils.save(cas, fileOutputStream, SerialFormat.XMI);
</code>```

XMI to CAS

```<code>CasIOUtils.load(fileInputStream, cas);
</code>```

Body:
I have made Ruta scripts run from Java and have converted the resulting CAS object into an xmi file as below;

FileOutputStream fileOutputStream = new FileOutputStream(outputXmiFile);
XmiCasSerializer.serialize(cas, fileOutputStream);

When I try to convert it back into a CAS object (on another server), as below;

FileInputStream fileInputStream = new FileInputStream(xmiFile);
XmlCasDeserializer.deserialize(fileInputStream, cas);

I get the below exception;

XCASParsingException: Error parsing XCAS or XMI-CAS from source <unknown> at line <unknown>, column <unknown>: unknown type: NULL.

A snapshot of the exception.

Body:
Ya Thanks ! It worked !

import org.apache.uima.util.CasIOUtils;

CAS to XMI

CasIOUtils.save(cas, fileOutputStream, SerialFormat.XMI);

XMI to CAS

CasIOUtils.load(fileInputStream, cas);


问:
Scraping multiple pages beautiful soup
Im trying to scrap multiple pages for links to documents. so i set up a string to vary the page number (in the example below from page 1 to page 6) - i loop the string into the url - but when I parse for the links with beautiful soup - i only get the high range - ie i overwite all of the previous pages.

the code...

```<code>from requests import get
from bs4 import BeautifulSoup
pages = [str(i) for i in range(1,6)]
for page in pages:
    response = get('http://www.sedar.com/FindCompanyDocuments.do?lang=EN&page_no=' + page + '&company_search=All+%28or+type+a+name%29&document_selection=24&industry_group=A&FromDate=01&FromMonth=01&FromYear=2017&ToDate=06&ToMonth=12&ToYear=2017&Variable=DocType')
page_html = BeautifulSoup(response.text, 'html.parser')

for link in page_html.find_all('a'):
   print(link.get('title'))
</code>```

with 6 pages i was expecting around 600 links - but as I say, I seem to be only get the last part of the range. (BTW - the output link is fine and correct i will prefix the http address at a later stage. As i newbie, im guessing there is a simple soltuion i havent seen (not for want of finding :))

```<code>None
&docClass=24&issuerNo=00040114&issuerType=03&projectNo=02637890&docId=4133021
None
&docClass=24&issuerNo=00005620&issuerType=03&projectNo=02700766&docId=4219364
None
&docClass=24&issuerNo=00005620&issuerType=03&projectNo=02700766&docId=4219365
</code>```

答:
you should indent the last 3 lines, so they're part of the iteration. It was only processing the last part after all the iterations were complete.</p>

```<code>for page in pages:
    response = get('http://www.sedar.com/FindCompanyDocuments.do?lang=EN&page_no=' + page + '&company_search=All+%28or+type+a+name%29&document_selection=24&industry_group=A&FromDate=01&FromMonth=01&FromYear=2017&ToDate=06&ToMonth=12&ToYear=2017&Variable=DocType')
    page_html = BeautifulSoup(response.text, 'html.parser')

    for link in page_html.find_all('a'):
        print(link.get('title'))
</code>```

Title: Scraping multiple pages beautiful soup

Body:
Im trying to scrap multiple pages for links to documents. so i set up a string to vary the page number (in the example below from page 1 to page 6) - i loop the string into the url - but when I parse for the links with beautiful soup - i only get the high range - ie i overwite all of the previous pages.

the code...

from requests import get
from bs4 import BeautifulSoup
pages = [str(i) for i in range(1,6)]
for page in pages:
    response = get('http://www.sedar.com/FindCompanyDocuments.do?lang=EN&page_no=' + page + '&company_search=All+%28or+type+a+name%29&document_selection=24&industry_group=A&FromDate=01&FromMonth=01&FromYear=2017&ToDate=06&ToMonth=12&ToYear=2017&Variable=DocType')
page_html = BeautifulSoup(response.text, 'html.parser')

for link in page_html.find_all('a'):
   print(link.get('title'))

with 6 pages i was expecting around 600 links - but as I say, I seem to be only get the last part of the range. (BTW - the output link is fine and correct i will prefix the http address at a later stage. As i newbie, im guessing there is a simple soltuion i havent seen (not for want of finding :))

None
&docClass=24&issuerNo=00040114&issuerType=03&projectNo=02637890&docId=4133021
None
&docClass=24&issuerNo=00005620&issuerType=03&projectNo=02700766&docId=4219364
None
&docClass=24&issuerNo=00005620&issuerType=03&projectNo=02700766&docId=4219365

Body:
you should indent the last 3 lines, so they're part of the iteration. It was only processing the last part after all the iterations were complete.

for page in pages:
    response = get('http://www.sedar.com/FindCompanyDocuments.do?lang=EN&page_no=' + page + '&company_search=All+%28or+type+a+name%29&document_selection=24&industry_group=A&FromDate=01&FromMonth=01&FromYear=2017&ToDate=06&ToMonth=12&ToYear=2017&Variable=DocType')
    page_html = BeautifulSoup(response.text, 'html.parser')

    for link in page_html.find_all('a'):
        print(link.get('title'))


问:
Changing navigation bar color in Swift
I am using a Picker View to allow the user to choose the colour theme for the entire app.

I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible).

I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour?

The Picker View is set up, I'm just looking for the code to change the UI colours.

答:
In Swift 4

You can change the color of navigation bar. Just use this below code snippet in viewDidLoad()

Navigation Bar color

```<code>self.navigationController?.navigationBar.barTintColor = UIColor.white
</code>```

Navigation Bar Text Color

```<code>self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.purple]
</code>```

For iOS 11 Large Title Navigation Bar, you need to use largeTitleTextAttributes property

```<code>self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.purple]
</code>```

ContentLicense: CC BY-SA 4.0

Title: Changing navigation bar color in Swift

Body:
In Swift 4

You can change the color of navigation bar. Just use this below code snippet in viewDidLoad()

Navigation Bar color

self.navigationController?.navigationBar.barTintColor = UIColor.white

Navigation Bar Text Color

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.purple]

For iOS 11 Large Title Navigation Bar, you need to use largeTitleTextAttributes property

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.purple]


问:
Can not find Custom HTTP Response headers in Angular 4.4.0-RC.0
I am trying to send some custom HTTP headers so that from client-end so that I can know the cause of the problem and show proper message to user. I am unable to get the response header from the below code (it shows null).

```<code>this.myService.getAllUsers().subscribe(results => {
    console.log(results)
},
error => {
    console.log(error.headers.get("ErrorCode"));
});
</code>```

But from the browser (chrome) I can see that I have the headers in the response.
    Look at the image here

I was expecting the see the value "INVALID_SESSION" as the console output.

But getting null instead. Can anyone help?

答:
Rather use map and catch from rxjs
See this: http://www.syntaxsuccess.com/viewarticle/error-handling-in-rxjs
or this: Angular2 Http with RXJS Observable TypeError: this.http.get(...).map(...).catch is not a function

Body:
I am trying to send some custom HTTP headers so that from client-end so that I can know the cause of the problem and show proper message to user. I am unable to get the response header from the below code (it shows null).

this.myService.getAllUsers().subscribe(results => {
    console.log(results)
},
error => {
    console.log(error.headers.get("ErrorCode"));
});

But from the browser (chrome) I can see that I have the headers in the response.
    Look at the image here

I was expecting the see the value "INVALID_SESSION" as the console output.

But getting null instead. Can anyone help?


问:
Are asp.net AJAX page methods very secure?
We're currentlly thinking about secureity in our applications.

Our preferred method of getting data from the back end is to use jQuery AJAX functions to directly access .aspx pages with page methods on them (without using a scriptmanager), as described brilliantly by Dave Ward here...

http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

So, my question is, how secure is this?

I've read a bit about XSS and same origin policies etc. Are these all automatically handled by ASP.NET or do we have to explicitly do something to make our apps safe?

Thanks, Jon

答:
ASP.NET won't automatically escape XSS or set cookies to prevent against CSRF, you'll need to

Wikipedia has good pages on both:
http://en.wikipedia.org/wiki/Cross-site_scripting
http://en.wikipedia.org/wiki/CSRF

Microsoft has an article on preventing CSS, but I couldn't turn up a todo for dealing with CSRF.

OwnerDisplayName: jonhobbs

LastEditorDisplayName: Fabian Steeg


问:
parse "strange" date format
Hi I have trouble have parse date in this format:

```<code>1295716379
</code>```

I don’t what kind of date format is it.

Human readable value of this string is:

```<code>22. 1. 2011, 18.12
</code>```

Also I don’t know that this format is some cowboy coder format or it is some "standard".

And if it is possible parse string on the top to human readable format, for examle in C#, Java, C++.

Thank

答:
It looks like a unix timestamp.

You can parse them like so:

C#: Parsing unix time in C#

C++: Converting a unix time to a human readable format

Java: Unix epoch time to Java Date object

Further links: Epoch Converter.com.

Title: parse "strange" date format

Body:
Hi I have trouble have parse date in this format:

1295716379

I don’t what kind of date format is it.

Human readable value of this string is:

22. 1. 2011, 18.12

Also I don’t know that this format is some cowboy coder format or it is some "standard".

And if it is possible parse string on the top to human readable format, for examle in C#, Java, C++.

Thank


问:
"Public Directory Warning - Public directory is empty" on firebase deploy
I have a firebase app with the following hosting configuration:

```<code>{
  "firebase": "the-world-table",
  "public": "app",
  "ignore": [
    "firebase.json",
    "**.*",
    "**/node_modules/**"
  ]
}
</code>```

The app directory is not empty (it has an index.html and a javascript file in it). However, when I deploy I get the following warning:

```<code>Preparing to deploy Public Directory...
Public Directory Warning - Public directory is empty, removing site
progress: 100%
Sucessfully removed
</code>```

And when I browse to the static files, they aren't found. Any ideas what is wrong here?

答:
firebase is looking by default in folder public for file index.html.

if in angular4 for example the index.html exists in folder dist you have to go into firebase.json and paste there:

```<code>{
    "hosting": {
        "public": "dist"
    }
}
</code>```

this is direct the firebase to look for index.html in dist folder or whatever is folder call instead public.
of cores you have that your file call index.html.

after that:

```<code>firebase deploy
</code>```

probably will work

Body:
I have a firebase app with the following hosting configuration:

{
  "firebase": "the-world-table",
  "public": "app",
  "ignore": [
    "firebase.json",
    "**.*",
    "**/node_modules/**"
  ]
}

The app directory is not empty (it has an index.html and a javascript file in it). However, when I deploy I get the following warning:

Preparing to deploy Public Directory...
Public Directory Warning - Public directory is empty, removing site
progress: 100%
Sucessfully removed

And when I browse to the static files, they aren't found. Any ideas what is wrong here?

Body:
firebase is looking by default in folder public for file index.html.

if in angular4 for example the index.html exists in folder dist you have to go into firebase.json and paste there:

{
    "hosting": {
        "public": "dist"
    }
}

this is direct the firebase to look for index.html in dist folder or whatever is folder call instead public.
of cores you have that your file call index.html.

after that:

firebase deploy

probably will work


问:
AttributeError: 'EC2' object has no attribute 'tag_resources'
I run following code and get error:

```<code>#!python -u

from boto3 import client

def is_tags():
 response = client('ec2', 'us-east-1').tag_resources(
 ResourceARNList=[
 'arn:aws:ec2:us-east-1::image/ami-55ef662f'
    ],
    Tags=[
        {
         'Key': 'Name',
         'Value': 'john',
        },
    ],
    )
if __name__ == '__main__':
    is_tags()
</code>```

It is throwing the following error:

```<code>AttributeError: 'EC2' object has no attribute 'tag_resources'
</code>```

What am I doing wrong?

答:
You are using the library incorrectly, the client object has no attribute called tag_resources, due to which the call to it is failing.

You can refer the correct usage from the boto3 documentation for Tag in EC2:

```<code>import boto3

ec2 = boto3.resource('ec2', 'us-east-1')
tag = ec2.Tag('resource_id','key','value')
</code>```

EDIT: I am not sure if there is a single API for tagging multiple type of resources that consistently works. You seem to be following this API, in which case, you have to define your client correctly, like:

```<code>client = boto3.client('resourcegroupstaggingapi', 'us-east-1')
</code>```

Body:
I run following code and get error:

#!python -u

from boto3 import client

def is_tags():
 response = client('ec2', 'us-east-1').tag_resources(
 ResourceARNList=[
 'arn:aws:ec2:us-east-1::image/ami-55ef662f'
    ],
    Tags=[
        {
         'Key': 'Name',
         'Value': 'john',
        },
    ],
    )
if __name__ == '__main__':
    is_tags()

It is throwing the following error:

AttributeError: 'EC2' object has no attribute 'tag_resources'

What am I doing wrong?

Body:
You are using the library incorrectly, the client object has no attribute called tag_resources, due to which the call to it is failing.

You can refer the correct usage from the boto3 documentation for Tag in EC2:

import boto3

ec2 = boto3.resource('ec2', 'us-east-1')
tag = ec2.Tag('resource_id','key','value')

EDIT: I am not sure if there is a single API for tagging multiple type of resources that consistently works. You seem to be following this API, in which case, you have to define your client correctly, like:

client = boto3.client('resourcegroupstaggingapi', 'us-east-1')


问:
Is there any way I can pass dynamic data to a component in Angular?

I am trying to pass data that is dynamic to a child component. But I always get the data as undefined in the child component. Below is what I am doing.

ParentComponent.ts

```<code>results: any[];
ngOnInit() {
this.http.get('url').subscribe(data => this.results = data);
}
</code>```

ParentComponent.html

```<code><app-childComponent [dataNeeded]=results></app-childComponent>
</code>```

ChildComponent.ts

```<code>@Input('dataNeeded') dataNeeded: any[];
ngOnInit() {
 console.log(dataNeeded); //Always undefiend
}
</code>```

So as expected, it doesn't wait for the asynchronous call and returns me undefined. How do i pass the dynamic data to the component?

答:
You might try OnChanges lifecycle hook method.

In your case, you would need to add it to your child component like so:

```<code>ngOnChanges(changes) {
  if (changes['dataNeeded'] && this.dataNeeded) {
    console.log(this.dataNeeded);
  }
}
</code>```

PS Also I just noticed the wrong syntax in your ChildComponent.ts, it is missing this:

```<code>ngOnInit() {
 console.log(this.dataNeeded);
}
</code>```

Body:
I am trying to pass data that is dynamic to a child component. But I always get the data as undefined in the child component. Below is what I am doing.

ParentComponent.ts

results: any[];
ngOnInit() {
this.http.get('url').subscribe(data => this.results = data);
}

ParentComponent.html

<app-childComponent [dataNeeded]=results></app-childComponent>

ChildComponent.ts

@Input('dataNeeded') dataNeeded: any[];
ngOnInit() {
 console.log(dataNeeded); //Always undefiend
}

So as expected, it doesn't wait for the asynchronous call and returns me undefined. How do i pass the dynamic data to the component?

Body:
You might try OnChanges lifecycle hook method.

In your case, you would need to add it to your child component like so:

ngOnChanges(changes) {
  if (changes['dataNeeded'] && this.dataNeeded) {
    console.log(this.dataNeeded);
  }
}

PS Also I just noticed the wrong syntax in your ChildComponent.ts, it is missing this:

ngOnInit() {
 console.log(this.dataNeeded);
}