问:
Having trouble putting 4 images in a 2 by 2 square to fit on half of the page in HTML/CSS
I've tried everything. Need Help PLEASE! Wanting to get the wire frame images in a 2 by 2 on the right side of the page. Being able to be responsive at the sametime.

any help will be appreciated soo much!

.flex-container {
    display: -webkit-flex;
 display: flex;
 -webkit-flex-direction: row;
 column-count:2;
 width: 100%;
 height: 25%;

}

.flex-item1 {

    font-family: sans-serif;
    width: 400px;
    height:auto;
    padding:50px;
    margin: 0,0,40px,0;
    text-align: justify;

}

.flex-item2 {

    font-family: sans-serif;
    width: 100px;
    height: 100px;
    align-items:center;
    display:flex;
    flex-wrap: wrap;

}

h1{

    text-align: center;
}

h2 {
    text-align: center;
    font-family: sans-serif;
    margin: 0;
    padding-left:200%;
    padding-top: 20px;
    width: 100%;
    height: auto;

}
.wireframe-container{

    position:fixed;
    width:100%;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    padding: 0px;
    text-align:center;

}

.wire{

    position:relative;
    display:inline-block;
    width:30%; max-width:180px;
    vertical-align: middle;
    margin:0 10px;
    padding-left:10px;

}

.desc {

    margin: 10px;
    padding-bottom:100px;

}

 ```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" type="text/css" href="Assignment 1.css"/>

<title>Page Title</title>

</head>

<body>

  <img src="ass 1 background.png" class="responsive-image">

<div class="flex-container">

    <div class="flex-item1">
    Creating an app designed for mobile devices (smart phones and tablets). Able to use the smart phones camera or tablet to view the picture in real-time. Jager is centred around the old-style game of I Spy/Scavenger hunt played usually by kids. This focus would be part of the Mahuki Gamelab team. Creating games used for education in fun ways to help get children involved in the seasonal museum exhibitions.
        <br><br>
       <h1>Abstract</h1>
        <br><br>
    To create a game for mobile devices, tablets and smart phones. An app that uses augmented reality technology to involve users in the environment around them. The game is a scavenger hunt / I SPY type of game played using your smart phone or tablet’s built-in camera to view the world through. The app will generate an object to make the user search for from a list of pre-programmed items and paths. The app will give users a hint or a clue to the general area or direction of the object. A timer and a score will be used to create competition between children.  Students should be able to compare scores and time, from a type of leader board system. Animations and buttons will be projected onto user’s screens in real time off the objects. Users can gain achievements and badges for doing certain task also.
    </div>

<div class="flex-item2">

    <h2>Wireframes</h2>

     <div class="wireframes-container">

         <div class="wire">

           <img src="wire1.png"style="width:10em; height:15em;" />

           <div class="desc">phone</div>

            <img src="wire2.png"style="width:15em; height:15em;" />

            <div class="desc">tablet</div>

         <img src="wire4.png"style="width:10em; height:15em;" />

        <div class="desc">AR mode</div>

         <img src="wire3.png"style="width:15em; height:15em;" />
        <div class="desc">AR mode</div>

        </div>

        </div>

    </div>

    </div>

</body>

</html></code>```

答:
You can get items to lie next to each other using display: inline-block and then adjust the width of the container so that only two of the images have space. I also had to remove the max-width property on .wire. By doing that and then wrapping each wire-frame image in a div.grid-item you get this (note the two extra css rules I added at the bottom):

.flex-container {
    display: -webkit-flex;
 display: flex;
 -webkit-flex-direction: row;
 column-count:2;
 width: 100%;
 height: 25%;

}

.flex-item1 {

    font-family: sans-serif;
    width: 400px;
    height:auto;
    padding:50px;
    margin: 0,0,40px,0;
    text-align: justify;

}

.flex-item2 {

    font-family: sans-serif;
    width: 100px;
    height: 100px;
    align-items:center;
    display:flex;
    flex-wrap: wrap;

}

h1{

    text-align: center;
}

h2 {
    text-align: center;
    font-family: sans-serif;
    margin: 0;
    padding-left:200%;
    padding-top: 20px;
    width: 100%;
    height: auto;

}
.wireframe-container{

    position:fixed;
    width:100%;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    padding: 0px;
    text-align:center;

}

.wire{

    position:relative;
    display:inline-block;
    width:30%;
    vertical-align: middle;
    margin:0 10px;
    padding-left:10px;

}

.desc {

    margin: 10px;
    padding-bottom:100px;

}

.wire {
  width: 26em;
}

.grid-item {
  display: inline-block;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><img src="ass 1 background.png" class="responsive-image">

<div class="flex-container">

  <div class="flex-item1">
    Creating an app designed for mobile devices (smart phones and tablets). Able to use the smart phones camera or tablet to view the picture in real-time. Jager is centred around the old-style game of I Spy/Scavenger hunt played usually by kids. This focus
    would be part of the Mahuki Gamelab team. Creating games used for education in fun ways to help get children involved in the seasonal museum exhibitions.
    <br><br>
    <h1>Abstract</h1>
    <br><br> To create a game for mobile devices, tablets and smart phones. An app that uses augmented reality technology to involve users in the environment around them. The game is a scavenger hunt / I SPY type of game played using your smart phone
    or tablet’s built-in camera to view the world through. The app will generate an object to make the user search for from a list of pre-programmed items and paths. The app will give users a hint or a clue to the general area or direction of the object.
    A timer and a score will be used to create competition between children. Students should be able to compare scores and time, from a type of leader board system. Animations and buttons will be projected onto user’s screens in real time off the objects.
    Users can gain achievements and badges for doing certain task also.
  </div>

  <div class="flex-item2">

    <h2>Wireframes</h2>

    <div class="wireframes-container">

      <div class="wire">
        <div class="grid-item">

            <img src="wire1.png" style="width:10em; height:15em;" />

          <div class="desc">phone</div>
        </div>

        <div class="grid-item">

            <img src="wire2.png" style="width:15em; height:15em;" />

          <div class="desc">tablet</div>
        </div>

        <div class="grid-item">

            <img src="wire4.png" style="width:10em; height:15em;" />

          <div class="desc">AR mode</div>
        </div>

        <div class="grid-item">

            <img src="wire3.png" style="width:15em; height:15em;" />
            <div class="desc">AR mode</div>

        </div>
      </div>

    </div>

  </div>

</div></code>```

Body:
I've tried everything. Need Help PLEASE! Wanting to get the wire frame images in a 2 by 2 on the right side of the page. Being able to be responsive at the sametime.

any help will be appreciated soo much!

.flex-container {
    display: -webkit-flex;
 display: flex;
 -webkit-flex-direction: row;
 column-count:2;
 width: 100%;
 height: 25%;

}

.flex-item1 {

    font-family: sans-serif;
    width: 400px;
    height:auto;
    padding:50px;
    margin: 0,0,40px,0;
    text-align: justify;

}

.flex-item2 {

    font-family: sans-serif;
    width: 100px;
    height: 100px;
    align-items:center;
    display:flex;
    flex-wrap: wrap;

}

h1{

    text-align: center;
}

h2 {
    text-align: center;
    font-family: sans-serif;
    margin: 0;
    padding-left:200%;
    padding-top: 20px;
    width: 100%;
    height: auto;

}
.wireframe-container{

    position:fixed;
    width:100%;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    padding: 0px;
    text-align:center;

}

.wire{

    position:relative;
    display:inline-block;
    width:30%; max-width:180px;
    vertical-align: middle;
    margin:0 10px;
    padding-left:10px;

}

.desc {

    margin: 10px;
    padding-bottom:100px;

}

<!DOCTYPE html>

    <link rel="stylesheet" type="text/css" href="Assignment 1.css"/>

<title>Page Title</title>

    Creating an app designed for mobile devices (smart phones and tablets). Able to use the smart phones camera or tablet to view the picture in real-time. Jager is centred around the old-style game of I Spy/Scavenger hunt played usually by kids. This focus would be part of the Mahuki Gamelab team. Creating games used for education in fun ways to help get children involved in the seasonal museum exhibitions.

Abstract

    To create a game for mobile devices, tablets and smart phones. An app that uses augmented reality technology to involve users in the environment around them. The game is a scavenger hunt / I SPY type of game played using your smart phone or tablet’s built-in camera to view the world through. The app will generate an object to make the user search for from a list of pre-programmed items and paths. The app will give users a hint or a clue to the general area or direction of the object. A timer and a score will be used to create competition between children.  Students should be able to compare scores and time, from a type of leader board system. Animations and buttons will be projected onto user’s screens in real time off the objects. Users can gain achievements and badges for doing certain task also.

Wireframes

phone

tablet

AR mode

AR mode

Body:
You can get items to lie next to each other using display: inline-block and then adjust the width of the container so that only two of the images have space. I also had to remove the max-width property on .wire. By doing that and then wrapping each wire-frame image in a div.grid-item you get this (note the two extra css rules I added at the bottom):

.flex-container {
    display: -webkit-flex;
 display: flex;
 -webkit-flex-direction: row;
 column-count:2;
 width: 100%;
 height: 25%;

}

.flex-item1 {

    font-family: sans-serif;
    width: 400px;
    height:auto;
    padding:50px;
    margin: 0,0,40px,0;
    text-align: justify;

}

.flex-item2 {

    font-family: sans-serif;
    width: 100px;
    height: 100px;
    align-items:center;
    display:flex;
    flex-wrap: wrap;

}

h1{

    text-align: center;
}

h2 {
    text-align: center;
    font-family: sans-serif;
    margin: 0;
    padding-left:200%;
    padding-top: 20px;
    width: 100%;
    height: auto;

}
.wireframe-container{

    position:fixed;
    width:100%;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    padding: 0px;
    text-align:center;

}

.wire{

    position:relative;
    display:inline-block;
    width:30%;
    vertical-align: middle;
    margin:0 10px;
    padding-left:10px;

}

.desc {

    margin: 10px;
    padding-bottom:100px;

}

.wire {
  width: 26em;
}

.grid-item {
  display: inline-block;
}

<img src="ass 1 background.png" class="responsive-image">

<div class="flex-container">

  <div class="flex-item1">
    Creating an app designed for mobile devices (smart phones and tablets). Able to use the smart phones camera or tablet to view the picture in real-time. Jager is centred around the old-style game of I Spy/Scavenger hunt played usually by kids. This focus
    would be part of the Mahuki Gamelab team. Creating games used for education in fun ways to help get children involved in the seasonal museum exhibitions.
    <br><br>
    <h1>Abstract</h1>
    <br><br> To create a game for mobile devices, tablets and smart phones. An app that uses augmented reality technology to involve users in the environment around them. The game is a scavenger hunt / I SPY type of game played using your smart phone
    or tablet’s built-in camera to view the world through. The app will generate an object to make the user search for from a list of pre-programmed items and paths. The app will give users a hint or a clue to the general area or direction of the object.
    A timer and a score will be used to create competition between children. Students should be able to compare scores and time, from a type of leader board system. Animations and buttons will be projected onto user’s screens in real time off the objects.
    Users can gain achievements and badges for doing certain task also.
  </div>

  <div class="flex-item2">

    <h2>Wireframes</h2>

    <div class="wireframes-container">

      <div class="wire">
        <div class="grid-item">
          <a target="_blank" href="wire1.png">
            <img src="wire1.png" style="width:10em; height:15em;" />
          </a>
          <div class="desc">phone</div>
        </div>

        <div class="grid-item">
          <a target="_blank" href="wire2.png">
            <img src="wire2.png" style="width:15em; height:15em;" />
          </a>
          <div class="desc">tablet</div>
        </div>

        <div class="grid-item">
          <a target="_blank" href="wire4.png">
            <img src="wire4.png" style="width:10em; height:15em;" />
          </a>
          <div class="desc">AR mode</div>
        </div>

        <div class="grid-item">
          <a target="_blank" href="wire3.png">
            <img src="wire3.png" style="width:15em; height:15em;" />
            <div class="desc">AR mode</div>
          </a>
        </div>
      </div>

    </div>

  </div>

</div>


来源: stackexchange

问:
How to monitor GlassFish thread pool via asadmin interface
I'm trying to use the asadmin interface to monitor a thread-pool on GlassFish 3.1.1.  I'm executing the following command:

```<code>asadmin get -m server.network.my-listener.thread-pool.*
</code>```

and I'm getting data back, but most of it has lastsampletime = -1 (so the related data is zero; and is worthless).

Note: I've also tried the REST interface, which I believe asadmin delegates to, and the JMX interface.  Same problem: much of the data has lastsampletime = -1.

I've already turned monitoring to HIGH for all modules.  What am I missing?

答:
To instantly enable monitoring without restart use enable-monitoring command

```<code>enable-monitoring
enable-monitoring --modules jvm=LOW
enable-monitoring --modules thread-pool=HIGH
enable-monitoring --modules http-service=HIGH
enable-monitoring --modules jdbc-connection-pool=HIGH
</code>```

The trick is that thread-pool and http-service modules must have high level to get monitoring info.

For more info refer https://docs.oracle.com/cd/E26576_01/doc.312/e24928/monitoring.htm#GSADG00558

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to use the asadmin interface to monitor a thread-pool on GlassFish 3.1.1.  I'm executing the following command:

asadmin get -m server.network.my-listener.thread-pool.*

and I'm getting data back, but most of it has lastsampletime = -1 (so the related data is zero; and is worthless).

Note: I've also tried the REST interface, which I believe asadmin delegates to, and the JMX interface.  Same problem: much of the data has lastsampletime = -1.

I've already turned monitoring to HIGH for all modules.  What am I missing?

Body:
To instantly enable monitoring without restart use enable-monitoring command

enable-monitoring
enable-monitoring --modules jvm=LOW
enable-monitoring --modules thread-pool=HIGH
enable-monitoring --modules http-service=HIGH
enable-monitoring --modules jdbc-connection-pool=HIGH

The trick is that thread-pool and http-service modules must have high level to get monitoring info.

For more info refer https://docs.oracle.com/cd/E26576_01/doc.312/e24928/monitoring.htm#GSADG00558


问:
How to correctly syntax a chained promise function
I have a list that I would like it to go through a function and make some fixes on that list, so I can use it later.

Because its function is depended on the result of the previous, I decided to use the chained defer, to wait one another.

```<code>    var $q = Promise;
  $scope.list = function(scan_result) {

  return $q.resolve(scan_result)
    .then(function(scan_result) {
      // Creates an object list with bssid and signal
      const ap_list = scan_result.map(str => {
        return {
          bssid: str.match(/BSSID:\s(\S*)/)[1],
          signal: str.match(/Signal:\s(\S*)/)[1]
        }
      });
      console.log("1st Then:");
      console.log(ap_list);
      return ap_list;
    })

  .then(function(ap_list) {
  //Sort the elements Highest to Lowest Signal Level
  ap_list.sort(function(a, b) {
    return b.signal - a.signal;
  });
  console.log("2nd Then:");
  console.log(ap_list);
  return ap_list;
})

  .then(function(ap_list) {
    //Removes the elements that have signal bellow -50
    for (var i = 0; i < ap_list.length; i++) {
      if (ap_list[i].signal < -50) {
        ap_list.splice(i, 1);
      }
    }
    console.log("3rd Then:");
    console.log(ap_list);
    return ap_list;
  })

  .then(function(ap_list) {
    //From the list keep the highest 3
    //console.log(ap_list);
    console.log("4th Then:");
    console.log(ap_list.slice(0, 3));
    return ap_list.slice(0, 3);
  })
}

$scope.checkin = function() {
  var scan_result = $scope.getList();
  console.log(scan_result);
  $scope.list(scan_result)
    .then(function(result) {
      //console.log(result);
    })
}
</code>```

When I output the result of the $scope.list() function on the console, it says the promise is pending and the status equals to 0.

So, definitely something is wrong here. Im not a defer guru so I kindly ask for your help.

答:
Your $scope.list function returns promise, so you have to wait result from it.

```<code>$scope.list()
   .then(function(result) {
      console.log(result);
   })
</code>```

Body:
I have a list that I would like it to go through a function and make some fixes on that list, so I can use it later.

Because its function is depended on the result of the previous, I decided to use the chained defer, to wait one another.

    var $q = Promise;
  $scope.list = function(scan_result) {

  return $q.resolve(scan_result)
    .then(function(scan_result) {
      // Creates an object list with bssid and signal
      const ap_list = scan_result.map(str => {
        return {
          bssid: str.match(/BSSID:\s(\S*)/)[1],
          signal: str.match(/Signal:\s(\S*)/)[1]
        }
      });
      console.log("1st Then:");
      console.log(ap_list);
      return ap_list;
    })

  .then(function(ap_list) {
  //Sort the elements Highest to Lowest Signal Level
  ap_list.sort(function(a, b) {
    return b.signal - a.signal;
  });
  console.log("2nd Then:");
  console.log(ap_list);
  return ap_list;
})

  .then(function(ap_list) {
    //Removes the elements that have signal bellow -50
    for (var i = 0; i < ap_list.length; i++) {
      if (ap_list[i].signal < -50) {
        ap_list.splice(i, 1);
      }
    }
    console.log("3rd Then:");
    console.log(ap_list);
    return ap_list;
  })

  .then(function(ap_list) {
    //From the list keep the highest 3
    //console.log(ap_list);
    console.log("4th Then:");
    console.log(ap_list.slice(0, 3));
    return ap_list.slice(0, 3);
  })
}

$scope.checkin = function() {
  var scan_result = $scope.getList();
  console.log(scan_result);
  $scope.list(scan_result)
    .then(function(result) {
      //console.log(result);
    })
}

When I output the result of the $scope.list() function on the console, it says the promise is pending and the status equals to 0.

So, definitely something is wrong here. Im not a defer guru so I kindly ask for your help.

Body:
Your $scope.list function returns promise, so you have to wait result from it.

$scope.list()
   .then(function(result) {
      console.log(result);
   })


问:
R plotly dynamic line width
I have multiple paths in my data, separated by NAs to build separated bar data, for which I'm trying to implement dynamic widths based on another value in that observation (column z below).

Reproducible Example:

```<code>  index <- c(1,1,NA,2,2)
  value <- c(50,51,NA,51,52)
  width <- c(3,3,NA,5,5)
  data <- data.frame(x = index,
                 y = value,
                 z = width)

  p <- plot_ly(data, x = x, y = y, mode = "lines",
           marker = list(color = '#ff2626'),
           line = list(width = data$z))
</code>```

Where I am trying to reference column z for the line = list(width = data$z) paramter.

Can this be done in the Plotly for R package, or does the line width need to be fixed?

答:
```<code>index <- c(1,1,NA,2,2)
value <- c(50,51,NA,51,52)
width <- c(3,3,NA,5,5)
data <- data.frame(x = index, y = value, z = width)

# first, create an empty plotly object
p <- plot_ly(type = "scatter", mode = "lines+markers", marker = list(color = '#ff2626'))

# second, every third line a new lines definition begins. Loop through lines in steps of 3 and add lines
for (i in seq(1, nrow(data), by = 3)){
  p <- p %>% add_trace(x=data[i,"x"], y=data[i:(i+1), "y"], line=list(width=data[i,"z"]))
}
</code>```

Title: R plotly dynamic line width

Body:
I have multiple paths in my data, separated by NAs to build separated bar data, for which I'm trying to implement dynamic widths based on another value in that observation (column z below).

Reproducible Example:

  index <- c(1,1,NA,2,2)
  value <- c(50,51,NA,51,52)
  width <- c(3,3,NA,5,5)
  data <- data.frame(x = index,
                 y = value,
                 z = width)

  p <- plot_ly(data, x = x, y = y, mode = "lines",
           marker = list(color = '#ff2626'),
           line = list(width = data$z))

Where I am trying to reference column z for the line = list(width = data$z) paramter.

Can this be done in the Plotly for R package, or does the line width need to be fixed?


问:
Read & extract objects out of properties file with the following format in java/spring
My entity class

```<code>    public class User {

        String name;
        String userName;
        String password;
        String[] roles;

        static class ROLES {
            static String ADMIN="ADMINISTRATOR";
            static String USER="USER";
        }

        public User(){

        }

        public User(String name, String userName, String password, String... roles) {
            this.name = name;
            this.userName = userName;
            this.password = password;
            this.roles = roles;
        }
    }
</code>```

Format of the properties file

```<code>user[0].name=Sujal Mandal
user[0].userName=sujal12
user[0].password=sujal123
user[0].roles=ADMIN,USER,SUPER_USER
user[1].name=Busra Ercelik
user[1].userName=busra12
user[1].password=busra123
user[1].roles=USER
</code>```

I would like to write an util class which will read the properties file & return me the objects of Users

What would be the best way of doing this in Java/Spring boot enviornment?

答:
The simplest solution is shown below where in you need to use @ConfigurationProperties:

```<code>@Component
@ConfigurationProperties("myproject")
public class UsersPopulator {

 private List<User> users;//all users will be populated from application.properties

//add getter method

}
</code>```

Your application.properties file looks like the below:

```<code>myproject.users[0].name=Sujal Mandal
myproject.users[0].userName=sujal12
myproject.users[0].password=sujal123
myproject.users[0].roles=ADMIN,USER,SUPER USER
myproject.users[1].name=Busra Ercelik
myproject.users[1].userName=busra12
myproject.users[1].password=busra123
myproject.users[1].roles=USER
</code>```

You need to ensure that @EnableConfigurationProperties is added to the launcher class file.

Body:
My entity class

    public class User {

        String name;
        String userName;
        String password;
        String[] roles;

        static class ROLES {
            static String ADMIN="ADMINISTRATOR";
            static String USER="USER";
        }

        public User(){

        }

        public User(String name, String userName, String password, String... roles) {
            this.name = name;
            this.userName = userName;
            this.password = password;
            this.roles = roles;
        }
    }

Format of the properties file

user[0].name=Sujal Mandal
user[0].userName=sujal12
user[0].password=sujal123
user[0].roles=ADMIN,USER,SUPER_USER
user[1].name=Busra Ercelik
user[1].userName=busra12
user[1].password=busra123
user[1].roles=USER

I would like to write an util class which will read the properties file & return me the objects of Users

What would be the best way of doing this in Java/Spring boot enviornment?

Body:
The simplest solution is shown below where in you need to use @ConfigurationProperties:

@Component
@ConfigurationProperties("myproject")
public class UsersPopulator {

 private List<User> users;//all users will be populated from application.properties

//add getter method

}

Your application.properties file looks like the below:

myproject.users[0].name=Sujal Mandal
myproject.users[0].userName=sujal12
myproject.users[0].password=sujal123
myproject.users[0].roles=ADMIN,USER,SUPER USER
myproject.users[1].name=Busra Ercelik
myproject.users[1].userName=busra12
myproject.users[1].password=busra123
myproject.users[1].roles=USER

You need to ensure that @EnableConfigurationProperties is added to the launcher class file.


问:
Jekyll or Hugo theme with multilanguage support
I'd like to start designing a website using Jekyll or Hugo. The plan is to publish it on GitHub or GitLab pages.

After hours of searching I'm pretty confused about all the facts. Hugo support natively a multilanguage utility while Jekyll not. There are some plugins for Jekyll but plugins are not supported on GitHub pages anyway.

With Jekyll I tried to follow this solution without any concrete solution for the translation of the layouts while with Hugo I've found the instruction pretty confused (but that's my fault).

What I'm looking for is a theme (Jekyll or Hugo it doesn't matter) that is already designed with 2 (or more) languages.

答:
I localized a Jekyll theme to output to German and Japanese here. It depends what requirements you're trying to support. We sent out translated files to a translation agency and then reimported them back into the project.

My strategy in defining the theme was to put each language in its own collection. Each collection defines default values for top nav and footer to be in that language.

Additionally, I used a different config file for each language. The language's config file defined strings for that language. File names and URLs remained in English.


问:
scala: assign null to primitive
I am trying to assign null to a variable which is Double like this:

```<code>var foo = 0.0
foo = null
</code>```

However, this gives an error that null cannot be implicitly converted to Double

So I do this instead:

```<code>foo = null.asInstanceOf[Double]
</code>```

however the new value for foo is 0.0

How can I set the value to null?

答:
You can't. Double is a value type, and you can only assign null to reference types. Instead, the Scala compiler replaces null with a default value of 0.0.

See default values in the SLS 4.2:

```<code>default  type
0        Int or one of its subrange types
0L       Long
0.0f     Float
0.0d     Double
false    Boolean
</code>```

You cannot assign Java primitives to null, either. And while Scala's Double isn't truly a primitive (it is actually a class in Scala), it needs to compile down to double in Java byte code. Instead, you should use Option[Double] if you want to represent a value that is missing entirely, and try to never use null in Scala.

Title: scala: assign null to primitive

Body:
I am trying to assign null to a variable which is Double like this:

var foo = 0.0
foo = null

However, this gives an error that null cannot be implicitly converted to Double

So I do this instead:

foo = null.asInstanceOf[Double]

however the new value for foo is 0.0

How can I set the value to null?

Body:
You can't. Double is a value type, and you can only assign null to reference types. Instead, the Scala compiler replaces null with a default value of 0.0.

See default values in the SLS 4.2:

default  type
0        Int or one of its subrange types
0L       Long
0.0f     Float
0.0d     Double
false    Boolean

You cannot assign Java primitives to null, either. And while Scala's Double isn't truly a primitive (it is actually a class in Scala), it needs to compile down to double in Java byte code. Instead, you should use Option[Double] if you want to represent a value that is missing entirely, and try to never use null in Scala.


问:
How to get an array of records in php
I execute an SQL query with php, this is the code:

```<code>$get_inspection_dates_query = "SELECT `date`
                                            FROM `vehicles` INNER JOIN `inspection_dates` ON `plate` = `id_vehicle`
                                            WHERE `plate` = '$vehicle_plate'";
$result_set = $connection->query($get_inspection_dates_query);
$inspection_dates = $result_set->fetchAll(PDO::FETCH_NUM);
</code>```

inspection_dates is:

```<code>Array
(
[0] => Array
    (
        [0] => 2012-01-01
    )

[1] => Array
    (
        [0] => 2013-01-01
    )

)
</code>```

but I don't want this.
I simply want an array of records, without the columns (even because I select only one column, so I don't need to have an array inside the array), something like this:

```<code>Array
(
    [0] = 2012-01-01
    [1] = 2013-01-01
)
</code>```

I know that I could reach something like this with a while loop and fetch ($row = $result_set->fetch()), but I think it's a bit tricky.
Is there any other method to obtain that array quickly?

答:
To change you inspection_dates to what you want you could use:

```<code>$whatYouWant = array_column($inspection_dates,0);
</code>```

Title: How to get an array of records in php

Body:
I execute an SQL query with php, this is the code:

$get_inspection_dates_query = "SELECT `date`
                                            FROM `vehicles` INNER JOIN `inspection_dates` ON `plate` = `id_vehicle`
                                            WHERE `plate` = '$vehicle_plate'";
$result_set = $connection->query($get_inspection_dates_query);
$inspection_dates = $result_set->fetchAll(PDO::FETCH_NUM);

inspection_dates is:

Array
(
[0] => Array
    (
        [0] => 2012-01-01
    )

[1] => Array
    (
        [0] => 2013-01-01
    )

)

but I don't want this.
I simply want an array of records, without the columns (even because I select only one column, so I don't need to have an array inside the array), something like this:

Array
(
    [0] = 2012-01-01
    [1] = 2013-01-01
)

I know that I could reach something like this with a while loop and fetch ($row = $result_set->fetch()), but I think it's a bit tricky.
Is there any other method to obtain that array quickly?

Body:
To change you inspection_dates to what you want you could use:

$whatYouWant = array_column($inspection_dates,0);


问:
Create a devise user from Ruby console
Any idea on how to create and save a new User object with devise from the ruby console?

When I tried to save it, I'm getting always false. I guess I'm missing something but I'm unable to find any related info.

答:
You should be able to do this using

```<code>u = User.new(:email => "user@name.com", :password => 'password', :password_confirmation => 'password')
u.save
</code>```

if this returns false, you can call

```<code>u.errors
</code>```

to see what's gone wrong.

Title: Create a devise user from Ruby console

Body:
You should be able to do this using

u = User.new(:email => "user@name.com", :password => 'password', :password_confirmation => 'password')
u.save

if this returns false, you can call

u.errors

to see what's gone wrong.

ContentLicense: CC BY-SA 2.5


问:
WIN 32 API - passing multiple Flags - Why the 'OR' and not 'AND'
When calling win32 API native functions, why do we pass multiple flags in an 'Or' rather than in an 'And' ?

for example: SetWindowPos function at its last parameter accepts UINT uFlags

When you want to pass more than one value to it, for example, from VBA you declare it and call it:

```<code>SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
</code>```

my question is - why the 'or' in between the flags (SWP_NOACTIVATE, SWP_SHOWWINDOW , etc ...) and not an 'and' ?

答:
The 'OR' operator preserves the values of the combined flags.
if you are familiar with bitwise operators, take these two values for example:

```<code>0b0010
0b0001
</code>```

if you evaluate these expressions using the AND operator.

```<code>    0010
AND 0001
    ----
    0000
</code>```

you'll get 0b0000 representing none of the original flag values.
on the other hand, using the OR operator

```<code>    0010
OR  0001
    ----
    0011
</code>```

will get you an expression representing the combined value of the flags.

Body:
When calling win32 API native functions, why do we pass multiple flags in an 'Or' rather than in an 'And' ?

for example: SetWindowPos function at its last parameter accepts UINT uFlags

When you want to pass more than one value to it, for example, from VBA you declare it and call it:

SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

my question is - why the 'or' in between the flags (SWP_NOACTIVATE, SWP_SHOWWINDOW , etc ...) and not an 'and' ?

Body:
The 'OR' operator preserves the values of the combined flags.
if you are familiar with bitwise operators, take these two values for example:

0b0010
0b0001

if you evaluate these expressions using the AND operator.

    0010
AND 0001
    ----
    0000

you'll get 0b0000 representing none of the original flag values.
on the other hand, using the OR operator

    0010
OR  0001
    ----
    0011

will get you an expression representing the combined value of the flags.


问:
setBackgroundColor exception
I am trying to change the background color of the activity whenever the toggle button is pressed, but I am getting "Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setBackgroundColor(int)' on a null object reference" Error.

Here is my onCreate code in my main activity

```<code>delegate = AppCompatDelegate.create(this, this);
    delegate.onCreate(savedInstanceState);
    delegate.setContentView(R.layout.activity_main);
    Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
    delegate.setSupportActionBar(toolbar);

    mScreen = (LinearLayout) findViewById(R.id.main);
    mScreen.setBackgroundColor(getResources().getColor(R.color.red));

    final ToggleButton start = (ToggleButton) findViewById(R.id.button);
    start.setText("START");
    start.setOnCheckedChangeListener(new    CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                startStepService();
                bindStepService();
                mScreen.setBackgroundColor(getResources().getColor(R.color.white));
                mIsRunning = true;
                start.setText("STOP");

            } else {
                unbindStepService();
                stopStepService();
                mScreen.setBackgroundColor(getResources().getColor(R.color.red));
                start.setText("START");
                mIsRunning = false;
            }
        }
    });

}
</code>```

and my XML for both my layout. One is a Coordinator Layout with the layout that I am changing included inside.

activity_main.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.sp.service9.Pedometer">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/main"
        android:id="@+id/include" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="124dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_margin="@dimen/fab_margin"
        android:onClick="showAlert"
        app:backgroundTint="?attr/colorPrimaryDark"
        app:layout_anchor="@+id/include"
        app:layout_anchorGravity="bottom|center_horizontal"
        app:srcCompat="@drawable/giftboxblue" />

</android.support.design.widget.CoordinatorLayout>
</code>```

and main.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:paddingTop="50dp"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Pedometer">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:srcCompat="@android:color/transparent"
        android:id="@+id/imageView2" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="Welcome, "
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:id="@+id/textView3"
            android:layout_weight="1" />

        <TextView
            android:text="TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:layout_weight="1" />

    </LinearLayout>

    <TextView
        android:textSize="30sp"
        android:layout_width="wrap_content"
        android:layout_height="59dp"
        android:layout_span="4"
        android:layout_gravity="center"
        android:id="@+id/StepTracker" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="268dp"
        android:layout_gravity="center">

        <ProgressBar
            android:id="@+id/circular_progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="275dp"
            android:layout_height="260dp"
            android:indeterminate="false"
            android:progress="2"
            android:foregroundGravity="center"
            android:progressDrawable="@drawable/circular_progressbar"
            android:layout_weight="1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/step_value"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="4"
            android:gravity="center_vertical|center_horizontal"
            android:text="0"
            android:textSize="60sp"
            android:layout_weight="1"
            android:layout_marginTop="88dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" />

    </RelativeLayout>

    <ToggleButton
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Button" />

</LinearLayout>
</code>```

答:
You do not have a widget named R.id.main.

You have a layout that tries to set that widget ID (main.xml). However, your <include> tag then overwrites that widget ID with a different value (@+id/include).

Either change your Java code to use R.id.include, or perhaps remove the android:id attribute from the <include>.

Title: setBackgroundColor exception

Body:
I am trying to change the background color of the activity whenever the toggle button is pressed, but I am getting "Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setBackgroundColor(int)' on a null object reference" Error.

Here is my onCreate code in my main activity

delegate = AppCompatDelegate.create(this, this);
    delegate.onCreate(savedInstanceState);
    delegate.setContentView(R.layout.activity_main);
    Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
    delegate.setSupportActionBar(toolbar);

    mScreen = (LinearLayout) findViewById(R.id.main);
    mScreen.setBackgroundColor(getResources().getColor(R.color.red));

    final ToggleButton start = (ToggleButton) findViewById(R.id.button);
    start.setText("START");
    start.setOnCheckedChangeListener(new    CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                startStepService();
                bindStepService();
                mScreen.setBackgroundColor(getResources().getColor(R.color.white));
                mIsRunning = true;
                start.setText("STOP");

            } else {
                unbindStepService();
                stopStepService();
                mScreen.setBackgroundColor(getResources().getColor(R.color.red));
                start.setText("START");
                mIsRunning = false;
            }
        }
    });

}

and my XML for both my layout. One is a Coordinator Layout with the layout that I am changing included inside.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.sp.service9.Pedometer">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/main"
        android:id="@+id/include" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="124dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_margin="@dimen/fab_margin"
        android:onClick="showAlert"
        app:backgroundTint="?attr/colorPrimaryDark"
        app:layout_anchor="@+id/include"
        app:layout_anchorGravity="bottom|center_horizontal"
        app:srcCompat="@drawable/giftboxblue" />

</android.support.design.widget.CoordinatorLayout>

and main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:paddingTop="50dp"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Pedometer">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:srcCompat="@android:color/transparent"
        android:id="@+id/imageView2" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="Welcome, "
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:id="@+id/textView3"
            android:layout_weight="1" />

        <TextView
            android:text="TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:layout_weight="1" />

    </LinearLayout>

    <TextView
        android:textSize="30sp"
        android:layout_width="wrap_content"
        android:layout_height="59dp"
        android:layout_span="4"
        android:layout_gravity="center"
        android:id="@+id/StepTracker" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="268dp"
        android:layout_gravity="center">

        <ProgressBar
            android:id="@+id/circular_progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="275dp"
            android:layout_height="260dp"
            android:indeterminate="false"
            android:progress="2"
            android:foregroundGravity="center"
            android:progressDrawable="@drawable/circular_progressbar"
            android:layout_weight="1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/step_value"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="4"
            android:gravity="center_vertical|center_horizontal"
            android:text="0"
            android:textSize="60sp"
            android:layout_weight="1"
            android:layout_marginTop="88dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" />

    </RelativeLayout>

    <ToggleButton
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Button" />

</LinearLayout>


问:
Canvas: Simply moving a rectangle from left to right
I am very new to canvas and I am just trying to build a basic function, so a rectangle can move from left to right. It seems like I just don't understand the logic.

This is what I have so far:

```<code>var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d'),
    x;

function draw() {
  ctx.beginPath();
  ctx.rect(x, 20, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + 20;
}

draw();

setInterval(draw, 1);
</code>```

https://jsfiddle.net/tj7d29fw/

Why is that code wrong and how would be the correct logic of moving a rectangle?

Any help would be appreciated!

答:
It seems like you don't initialize your x variable to a number, so it doesn't move. I personalized a little bit your jsfiddle:

```<code>var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d'),
    x = 0;

function draw() {
  ctx.beginPath();
  ctx.rect(x, 20, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + 1.2;
}

draw();

setInterval(draw, 1);
</code>```

I link it hoping it helps:

https://jsfiddle.net/tj7d29fw/3/

Body:
I am very new to canvas and I am just trying to build a basic function, so a rectangle can move from left to right. It seems like I just don't understand the logic.

This is what I have so far:

var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d'),
    x;

function draw() {
  ctx.beginPath();
  ctx.rect(x, 20, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + 20;
}

draw();

setInterval(draw, 1);

https://jsfiddle.net/tj7d29fw/

Why is that code wrong and how would be the correct logic of moving a rectangle?

Any help would be appreciated!

Body:
It seems like you don't initialize your x variable to a number, so it doesn't move. I personalized a little bit your jsfiddle:

var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d'),
    x = 0;

function draw() {
  ctx.beginPath();
  ctx.rect(x, 20, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + 1.2;
}

draw();

setInterval(draw, 1);

I link it hoping it helps:

https://jsfiddle.net/tj7d29fw/3/


问:
synchronous ajax error with yii2 activeform
The below view is rendered by ajax and returned from controller to JS which puts view inside correct container :

```<code>$page =  $this->renderAjax("view", [
                                "dataProvider" => $dataProvider
                     ]) ;
        Yii::$app->response->format = 'json';
        return array("error"=>false,"page"=>$page);
</code>```

View :

```<code><?=
    ListView::widget([
        'id'=>'dataListId',
        'dataProvider' => $dataProvider,
        'itemOptions' => ['class' => 'item'],
        'itemView' => '_dataItemView',
        'summary'=>'',
        'emptyText'=>$emptyPage
    ])
?>

<?=
         $this->render("_activeFormPage")
?>
</code>```

messages?id=1:950 Synchronous XMLHttpRequest on the main thread is
  deprecated because of its detrimental effects to the end user's
  experience. For more help, check https://xhr.spec.whatwg.org/.

But this gives above error in chrome for synchronous XMLhttprequest on full refresh where I simulate ajax by trigger click on button which does ajax and gets above data. As soon as line to render _activeFormPage is commented, error goes away.

How can we get rid of synchronous ajax error since in javascript async has been left to default while making ajax calls from jquery

Body:
The below view is rendered by ajax and returned from controller to JS which puts view inside correct container :

$page =  $this->renderAjax("view", [
                                "dataProvider" => $dataProvider
                     ]) ;
        Yii::$app->response->format = 'json';
        return array("error"=>false,"page"=>$page);

View :

<?=
    ListView::widget([
        'id'=>'dataListId',
        'dataProvider' => $dataProvider,
        'itemOptions' => ['class' => 'item'],
        'itemView' => '_dataItemView',
        'summary'=>'',
        'emptyText'=>$emptyPage
    ])
?>

<?=
         $this->render("_activeFormPage")
?>

messages?id=1:950 Synchronous XMLHttpRequest on the main thread is
  deprecated because of its detrimental effects to the end user's
  experience. For more help, check https://xhr.spec.whatwg.org/.

But this gives above error in chrome for synchronous XMLhttprequest on full refresh where I simulate ajax by trigger click on button which does ajax and gets above data. As soon as line to render _activeFormPage is commented, error goes away.

How can we get rid of synchronous ajax error since in javascript async has been left to default while making ajax calls from jquery

Body:
After some debugging found solution , will post here for rest of yii2 folks ->

This is due to <script> tags coming in  controller's output i.e HTML to  ajax success callback which uses it for updating dom using jquery .html

We need to prefetch these javascript so that yii2 does not have to include a new script tag lazily on renderAjax, since it is already there. So in depends of AppAsset file, I specifically added imports to ActiveFormAsset and ValidationAsset which were culprit in my case

public $depends = [
        'yii\web\YiiAsset',
        'yii\widgets\ActiveFormAsset',
        'yii\validators\ValidationAsset',
        'yii\grid\GridViewAsset',
        'yii\bootstrap\BootstrapPluginAsset',
        '\odaialali\yii2toastr\ToastrAsset'
    ];


问:
Project upgraded from Google Cardboard to Google VR runs in Unity but fails when building for iOS (XCode or Unity Cloud Build)
I started my project using Google Cardboard then I imported the new GoogleVR package to replace it. When I hit play in Unity my project works fine but when I try to build it for iOS I get errors on both the Xcode project and the Unity Cloud build project.

On Xcode:

```<code>ld: warning: arm64 function not 4-byte aligned: ltmp0 from /Users/gamedev/Desktop/VR1-iOS/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
 ld: warning: arm64 function not 4-byte aligned: _unwind_tester from /Users/gamedev/Desktop/VR1-iOS/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
 Undefined symbols for architecture arm64:
   "_endSettingsDialog", referenced from:
       -[DismissDialogViewController viewDidAppear:] in libvrunity.a(unity.o)
 ld: symbol(s) not found for architecture arm64
 clang: error: linker command failed with exit code 1 (use -v to see invocation)
</code>```

on Unity cloud build:

```<code>[xcode] Undefined symbols for architecture armv7:
 9352:        [xcode]   "_endSettingsDialog", referenced from:
 9353:        [xcode]       -[DismissDialogViewController viewDidAppear:] in libvrunity.a(unity.o)
 9354:        [xcode]   "_isOpenGLAPI", referenced from:
 9355:        [xcode]       RegisterMonoModules() in RegisterMonoModules.o
 9356:        [xcode] ld: symbol(s) not found for architecture armv7
 9357:        [xcode] clang: error: linker command failed with exit code 1 (use -v to see invocation)
 9358:        [xcode] Showing first 200 warnings only
 9359:        [xcode] ** ARCHIVE FAILED **
 9360:        [xcode] The following build commands failed:
 9361:        [xcode]     Ld /BUILD_PATH/Library/Developer/Xcode/DerivedData/Unity-iPhone-gccgnjkpqhormzcosgksevxlzeea/Build/Intermediates/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/APPLICATION_PATH/vr1.app/vr1 normal armv7
 9362:        [xcode] (1 failure)
</code>```

I've noticed that most of the answers to this kind of problem refer to SourceTree (This is what I'm using) ignoring .dll file when pushing the source code. At the moment I don't have any .gitignore file in my working directory.

UPDATE
I have upgraded to Unity 5.6 and the errors changed a bit:

```<code>"_endSettingsDialog", referenced from:
-[DismissDialogViewController viewDidAppear:] in libvrunity.a(unity.o)

Undefined symbols for architecture arm64:
  "_isOpenGLAPI", referenced from:
      _iOSDevice_isOpenGLAPI_m3529398287 in Bulk_Assembly-CSharp_0.o
     (maybe you meant: _iOSDevice_isOpenGLAPI_m3529398287)
ld: symbol(s) not found for architecture arm64
</code>```

when checking between the libraries linked (in Build Settings) I noticed I had both libvrunity.a and libgvrunity.a so I removed the first one and the error is disappeared, but I still have the second about OpenGL. The strange thing is that the project work flawlessly in unity.

答: It seems you have missing files or some old one not removed: I'd suggest to remove all iOS plugins and re-import the correct ones once again.</p>

Body:
I started my project using Google Cardboard then I imported the new GoogleVR package to replace it. When I hit play in Unity my project works fine but when I try to build it for iOS I get errors on both the Xcode project and the Unity Cloud build project.

On Xcode:

ld: warning: arm64 function not 4-byte aligned: ltmp0 from /Users/gamedev/Desktop/VR1-iOS/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
 ld: warning: arm64 function not 4-byte aligned: _unwind_tester from /Users/gamedev/Desktop/VR1-iOS/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
 Undefined symbols for architecture arm64:
   "_endSettingsDialog", referenced from:
       -[DismissDialogViewController viewDidAppear:] in libvrunity.a(unity.o)
 ld: symbol(s) not found for architecture arm64
 clang: error: linker command failed with exit code 1 (use -v to see invocation)

on Unity cloud build:

[xcode] Undefined symbols for architecture armv7:
 9352:        [xcode]   "_endSettingsDialog", referenced from:
 9353:        [xcode]       -[DismissDialogViewController viewDidAppear:] in libvrunity.a(unity.o)
 9354:        [xcode]   "_isOpenGLAPI", referenced from:
 9355:        [xcode]       RegisterMonoModules() in RegisterMonoModules.o
 9356:        [xcode] ld: symbol(s) not found for architecture armv7
 9357:        [xcode] clang: error: linker command failed with exit code 1 (use -v to see invocation)
 9358:        [xcode] Showing first 200 warnings only
 9359:        [xcode] ** ARCHIVE FAILED **
 9360:        [xcode] The following build commands failed:
 9361:        [xcode]     Ld /BUILD_PATH/Library/Developer/Xcode/DerivedData/Unity-iPhone-gccgnjkpqhormzcosgksevxlzeea/Build/Intermediates/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/APPLICATION_PATH/vr1.app/vr1 normal armv7
 9362:        [xcode] (1 failure)

I've noticed that most of the answers to this kind of problem refer to SourceTree (This is what I'm using) ignoring .dll file when pushing the source code. At the moment I don't have any .gitignore file in my working directory.

UPDATE
I have upgraded to Unity 5.6 and the errors changed a bit:

"_endSettingsDialog", referenced from:
-[DismissDialogViewController viewDidAppear:] in libvrunity.a(unity.o)

Undefined symbols for architecture arm64:
  "_isOpenGLAPI", referenced from:
      _iOSDevice_isOpenGLAPI_m3529398287 in Bulk_Assembly-CSharp_0.o
     (maybe you meant: _iOSDevice_isOpenGLAPI_m3529398287)
ld: symbol(s) not found for architecture arm64

when checking between the libraries linked (in Build Settings) I noticed I had both libvrunity.a and libgvrunity.a so I removed the first one and the error is disappeared, but I still have the second about OpenGL. The strange thing is that the project work flawlessly in unity.


问:
How can I optimize if-else statement to be more simple?
Im working with the code below in developing simple ios app using objective-C.Is that have another way to optimize this code:

```<code> if ([segue.identifier isEqualToString:@"showCommitDetail"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    CommitDetailsTableViewController *destViewController = segue.destinationViewController;

      RepoObject *repoObj = [self.RepoListArray objectAtIndex:indexPath.row];
    NSString *repoCommit_url = [repoObj.Commit_url stringByReplacingOccurrencesOfString:@"{/sha}" withString:@""];

if (indexPath.row == 0) {
    NSString *SpringBootURL = repoCommit_url;
    self.commit_url = SpringBootURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"Spring-Integration-in-Action";
}else if (indexPath.row == 1){
    NSString *SpringFrameworkURL = repoCommit_url;
    self.commit_url = SpringFrameworkURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-jdbc-ext";
}else if (indexPath.row == 2){
    NSString *SpringAmqpURL = repoCommit_url;
    self.commit_url = SpringAmqpURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-commons";
}else if (indexPath.row == 3){
    NSString *SpringIdeURL = repoCommit_url;
    self.commit_url = SpringIdeURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-graph";
}else{
    NSString *SpringIntegratURL = repoCommit_url;
    self.commit_url = SpringIntegratURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-document-examples";
}

}
</code>```

Beside that, how can i assign title directly without hard-coding it like i did above.?

答:
```<code>if ([segue.identifier isEqualToString:@"showCommitDetail"]) {
    NSInteger selectedRow = [self.tableView indexPathForSelectedRow].row;
    CommitDetailsTableViewController *destViewController = segue.destinationViewController;

    RepoObject *repoObj = [self.RepoListArray objectAtIndex:selectedRow];
    self.commit_url = [repoObj.Commit_url stringByReplacingOccurrencesOfString:@"{/sha}" withString:@""];
    destViewController.CommitRepoURL = self.commit_url;

    NSString *title;
    switch (selectedRow) {
        case 0:
            title = @"Spring-Integration-in-Action";
            break;
        case 1:
            title = @"spring-data-jdbc-ext";
            break;
        case 2:
            title = @"spring-data-commons";
            break;
        case 3:
            title = @"spring-data-graph";
            break;
        default:
            title = @"spring-data-document-examples";
            break;
    }
    destViewController.navigationItem.title = title;
}
</code>```

Body:
Im working with the code below in developing simple ios app using objective-C.Is that have another way to optimize this code:

 if ([segue.identifier isEqualToString:@"showCommitDetail"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    CommitDetailsTableViewController *destViewController = segue.destinationViewController;

      RepoObject *repoObj = [self.RepoListArray objectAtIndex:indexPath.row];
    NSString *repoCommit_url = [repoObj.Commit_url stringByReplacingOccurrencesOfString:@"{/sha}" withString:@""];

if (indexPath.row == 0) {
    NSString *SpringBootURL = repoCommit_url;
    self.commit_url = SpringBootURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"Spring-Integration-in-Action";
}else if (indexPath.row == 1){
    NSString *SpringFrameworkURL = repoCommit_url;
    self.commit_url = SpringFrameworkURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-jdbc-ext";
}else if (indexPath.row == 2){
    NSString *SpringAmqpURL = repoCommit_url;
    self.commit_url = SpringAmqpURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-commons";
}else if (indexPath.row == 3){
    NSString *SpringIdeURL = repoCommit_url;
    self.commit_url = SpringIdeURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-graph";
}else{
    NSString *SpringIntegratURL = repoCommit_url;
    self.commit_url = SpringIntegratURL;
    destViewController.CommitRepoURL = self.commit_url;
    destViewController.navigationItem.title = @"spring-data-document-examples";
}

}

Beside that, how can i assign title directly without hard-coding it like i did above.?

ContentLicense: CC BY-SA 4.0


问:
bind dropdown with XML file
I have this XML file:

```<code><questions>
  <question id="title">
    <option>
      <text>Mr</text>
      <value>Mr</value>
    </option>
    <option>
      <text>Ms</text>
      <value>Ms</value>
    </option>
  </question>
  <question id="organisation">
    <option>
      <text>org1</text>
      <value>org1</value>
    </option>
    <option>
      <text>org2</text>
      <value>org2</value>
    </option>
  </question>
</questions>
</code>```

How do I bind each question to a specific drop-down in c#?

Thanks

答: You could use the XmlDataSource class to bind the XML data to your control. </p>

Title: bind dropdown with XML file

Body:
I have this XML file:

<questions>
  <question id="title">
    <option>
      <text>Mr</text>
      <value>Mr</value>
    </option>
    <option>
      <text>Ms</text>
      <value>Ms</value>
    </option>
  </question>
  <question id="organisation">
    <option>
      <text>org1</text>
      <value>org1</value>
    </option>
    <option>
      <text>org2</text>
      <value>org2</value>
    </option>
  </question>
</questions>

How do I bind each question to a specific drop-down in c#?

Thanks


问:
Make a div as heigh as needed
In my example below when the content in the top right div is too high, the content of the bottom div flows over the content of the top div.

I would like the top div to push the bottom div down so that content in both divs stays visible in the situation below.

How could I solve this?

.left {
  background-color: grey;
  min-height: 200px;
  float: left;
}

.right {
  height: auto;
  float: left;
}

.top {
  background-color: lightblue;
  height: 150px;

}

.bottom {
  background-color: lightgreen;
  height: 50px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrapper">
  <div class="left">
    left
  </div>
  <div class="right">
    <div class="top">
      top right<br/> top right<br/> top right<br/> top right<br/> top right<br/> top right<br/>top right<br/>top right<br/>top right<br/>

    </div>
    <div class="bottom">
      bottom right
    </div>

  </div>

  <div></code>```

Edit

What I didn't mention before is that the bottom div should be on the bottom by default. This means that if there is enough space the bottom line of the bottom div should align with the bottom line of the left div

答:
Here attached is a snippet showing what you want to achieve. Getting the left div to grow with the parent would however maybe need a little javascript (but that's not part of the question anyways). Cheers

.left {
  background-color: grey;
  min-height: 200px;
  float: left;
}

.right {
  height: auto;
  float: left;
}

.top {
  background-color: lightblue;

  /* changes here */
  min-height: 150px;
  height: auto;
}

.bottom {
  background-color: lightgreen;
  height: 50px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrapper">
  <div class="left">
    left
  </div>
  <div class="right">
    <div class="top">
      top right<br/> top right<br/> top right<br/> top right<br/> top right<br/> top right<br/>top right<br/>top right<br/>top right<br/>

    </div>
    <div class="bottom">
      bottom right
    </div>

  </div>

  <div></code>```

Title: Make a div as heigh as needed

Body:
In my example below when the content in the top right div is too high, the content of the bottom div flows over the content of the top div.

I would like the top div to push the bottom div down so that content in both divs stays visible in the situation below.

How could I solve this?

.left {
  background-color: grey;
  min-height: 200px;
  float: left;
}

.right {
  height: auto;
  float: left;
}

.top {
  background-color: lightblue;
  height: 150px;

}

.bottom {
  background-color: lightgreen;
  height: 50px;
}

    left

      top right
 top right
 top right
 top right
 top right
 top right
top right
top right
top right

      bottom right

Edit

What I didn't mention before is that the bottom div should be on the bottom by default. This means that if there is enough space the bottom line of the bottom div should align with the bottom line of the left div

Body:
Here attached is a snippet showing what you want to achieve. Getting the left div to grow with the parent would however maybe need a little javascript (but that's not part of the question anyways). Cheers

.left {
  background-color: grey;
  min-height: 200px;
  float: left;
}

.right {
  height: auto;
  float: left;
}

.top {
  background-color: lightblue;

  /* changes here */
  min-height: 150px;
  height: auto;
}

.bottom {
  background-color: lightgreen;
  height: 50px;
}

<div class="wrapper">
  <div class="left">
    left
  </div>
  <div class="right">
    <div class="top">
      top right<br/> top right<br/> top right<br/> top right<br/> top right<br/> top right<br/>top right<br/>top right<br/>top right<br/>

    </div>
    <div class="bottom">
      bottom right
    </div>

  </div>

  <div>


问:
Compile error in RegExp pattern with double quotes
I want to search a string picked from .txt file for numbers enclosed in double quotes. I am doing all this with Excel macros. Example data:

```<code>"08134789316498"
"022"
</code>```

My code:

```<code>Set oRegex1 = CreateObject("VBScript.RegExp")
oRegex1.Pattern = "(\"[0-9]+\"])"
</code>```

But the above line is giving error:

"Compile Error: Expected end of statement"

Note: I have already added references to "Microsoft VBScript Regular Expressions 5.5" and "Microsoft VBScript Regular Expressions 1.0"

答:
You don't need to escape the double quotes from the regexp point of view, but from the vbscript/vba point of view. </p>

```<code>oRegex1.Pattern = "(""[0-9]+""\])"
                    ^^      ^^   quotes escaped inside string by doubling them
</code>```

Body:
I want to search a string picked from .txt file for numbers enclosed in double quotes. I am doing all this with Excel macros. Example data:

"08134789316498"
"022"

My code:

Set oRegex1 = CreateObject("VBScript.RegExp")
oRegex1.Pattern = "(\"[0-9]+\"])"

But the above line is giving error:

"Compile Error: Expected end of statement"

Note: I have already added references to "Microsoft VBScript Regular Expressions 5.5" and "Microsoft VBScript Regular Expressions 1.0"

Body:
You don't need to escape the double quotes from the regexp point of view, but from the vbscript/vba point of view.

oRegex1.Pattern = "(""[0-9]+""\])"
                    ^^      ^^   quotes escaped inside string by doubling them


问:
PyQt5 pip installation error 13. Permission denied
I'm trying to install PyQt5 with the command pip install PyQt5

but I get an error instead.

I use Python 3.5, windows 10.

error:

```<code>C:\WINDOWS\system32>pip install PyQt5

Collecting PyQt5
  Using cached PyQt5-5.7-cp35-none-win_amd64.whl
Collecting sip (from PyQt5)
  Using cached sip-4.18.1-cp35-none-win_amd64.whl
Installing collected packages: sip, PyQt5
Exception:
Traceback (most recent call last):
  File "c:\anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\anaconda3\lib\site-packages\pip\commands\install.py", line 317, in run
    prefix=options.prefix_path,
  File "c:\anaconda3\lib\site-packages\pip\req\req_set.py", line 742, in install
    **kwargs
  File "c:\anaconda3\lib\site-packages\pip\req\req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "c:\anaconda3\lib\site-packages\pip\req\req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "c:\anaconda3\lib\site-packages\pip\wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "c:\anaconda3\lib\site-packages\pip\wheel.py", line 324, in clobber
    shutil.copyfile(srcfile, destfile)
  File "c:\anaconda3\lib\shutil.py", line 115, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'c:\\anaconda3\\Lib\\site-packages\\sip.pyd'
</code>```

答: If your Python 3.x was installed to its preferred (default) location C:\ Program Files \Pyton3x and if you are running your code not with elevated privileges in OS (not as administrator), then consider giving all user permissions to Python installation folder.

Body:
I'm trying to install PyQt5 with the command pip install PyQt5

but I get an error instead.

I use Python 3.5, windows 10.

error:

C:\WINDOWS\system32>pip install PyQt5

Collecting PyQt5
  Using cached PyQt5-5.7-cp35-none-win_amd64.whl
Collecting sip (from PyQt5)
  Using cached sip-4.18.1-cp35-none-win_amd64.whl
Installing collected packages: sip, PyQt5
Exception:
Traceback (most recent call last):
  File "c:\anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\anaconda3\lib\site-packages\pip\commands\install.py", line 317, in run
    prefix=options.prefix_path,
  File "c:\anaconda3\lib\site-packages\pip\req\req_set.py", line 742, in install
    **kwargs
  File "c:\anaconda3\lib\site-packages\pip\req\req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "c:\anaconda3\lib\site-packages\pip\req\req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "c:\anaconda3\lib\site-packages\pip\wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "c:\anaconda3\lib\site-packages\pip\wheel.py", line 324, in clobber
    shutil.copyfile(srcfile, destfile)
  File "c:\anaconda3\lib\shutil.py", line 115, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'c:\\anaconda3\\Lib\\site-packages\\sip.pyd'


问:
Python - add one dictionary to another
I want to update one dictionary with another in Python, but if there are some same arguments, their values should be added.
For example:

```<code>a = {"word_1" : 1, "word_2": 2}
b = {"word_2" : 5, "word_3": 7}
</code>```

Output must be:

```<code>{"word_1" : 1, "word_2": 7, "word_3": 7}
</code>```

I have googled a lot, but in most answers values rewrites, I want to add them
Here is my solution:

```<code>    for i in a.keys():
        if i in b.keys():
            b[i] += a[i]
        else:
            b[i] = a[i]
</code>```

Is there most efficient way to do it?

答:
Use a Counter, which is a special kind of dictionary for counting objects.

```<code>from collections import Counter

a = Counter({"word_1" : 1, "word_2": 2})
b = Counter({"word_2" : 5, "word_3": 7})
print(a + b)
</code>```

prints

```<code>Counter({'word_2': 7, 'word_3': 7, 'word_1': 1})
</code>```

Title: Python - add one dictionary to another

Body:
I want to update one dictionary with another in Python, but if there are some same arguments, their values should be added.
For example:

a = {"word_1" : 1, "word_2": 2}
b = {"word_2" : 5, "word_3": 7}

Output must be:

{"word_1" : 1, "word_2": 7, "word_3": 7}

I have googled a lot, but in most answers values rewrites, I want to add them
Here is my solution:

    for i in a.keys():
        if i in b.keys():
            b[i] += a[i]
        else:
            b[i] = a[i]

Is there most efficient way to do it?

Body:
Use a Counter, which is a special kind of dictionary for counting objects.

from collections import Counter

a = Counter({"word_1" : 1, "word_2": 2})
b = Counter({"word_2" : 5, "word_3": 7})
print(a + b)

prints

Counter({'word_2': 7, 'word_3': 7, 'word_1': 1})


问:
Ajax Validation on JSF
I want to validate required fields on diferent forms when i push on save (Toolbar.xhtml). How can i do this? Thanks in advance

I have the following code:

Father.xhtml

```<code>..
<ui:include src="/jsf/Toolbar.xhtml"/>
<ui:include src="/jsf/Adquisicion.xhtml"/>
..
</code>```

Toolbar.xhtml

```<code><ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      >

 <ui:insert name="toolbarComponent">
  <h:form name="ToolbarForm" >
    <a4j:commandLink id="save" action="#{backingBean1.save}"/>
  </h:form>
 </ui:insert>

</ui:composition>
</code>```

Adquisicion.xhtml

```<code><ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich">

 <ui:insert name="component">
   <a4j:form id="Adquisicion">
     <rich:panel>
       <f:facet name="header">
          <h:outputText value="Header" />
       </f:facet>
       <h:panelGrid columns="3">
  <h:outputText value="Name" />
  <h:inputText id="nameId" value="#{adquisicion.name}"                 style="width:500px;" required="true" requiredMessage="Required" >
            <a4j:support event="onblur"/>
         </h:inputText>
  <rich:message for="nameId" style="color: red;"/>
     </rich:panel>
   <a4j:form>
 </ui:insert>
<ui:composition>
</code>```

答: The input fields have to go in the same <h:form> (or <a4j:form>, whatever you like) as the command link/button.

Title: Ajax Validation on JSF

Body:
I want to validate required fields on diferent forms when i push on save (Toolbar.xhtml). How can i do this? Thanks in advance

I have the following code:

Father.xhtml

..
<ui:include src="/jsf/Toolbar.xhtml"/>
<ui:include src="/jsf/Adquisicion.xhtml"/>
..

Toolbar.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      >

 <ui:insert name="toolbarComponent">
  <h:form name="ToolbarForm" >
    <a4j:commandLink id="save" action="#{backingBean1.save}"/>
  </h:form>
 </ui:insert>

</ui:composition>

Adquisicion.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich">

 <ui:insert name="component">
   <a4j:form id="Adquisicion">
     <rich:panel>
       <f:facet name="header">
          <h:outputText value="Header" />
       </f:facet>
       <h:panelGrid columns="3">
  <h:outputText value="Name" />
  <h:inputText id="nameId" value="#{adquisicion.name}"                 style="width:500px;" required="true" requiredMessage="Required" >
            <a4j:support event="onblur"/>
         </h:inputText>
  <rich:message for="nameId" style="color: red;"/>
     </rich:panel>
   <a4j:form>
 </ui:insert>
<ui:composition>


问:
c# ensure all operations to complete or none
I have following code:

```<code>File.Copy(pathSource, pathDestination);   //copy file
ID3v2TagToDB(pathSource, pathDestination); //read his tags and save them to DB
ID3v2TagToTXT(pathSource, pathDestination); //read his tags and save them to txt
dgv.Rows[chosen[i]].DefaultCellStyle.BackColor = Color.GreenYellow; //color green datagridview row if copy and read successfull
</code>```

I want to ensure that each operation is successfull. If any of them failed, I need to rollback all previous ones.

And also, warn user about error that ocurred, and operation that ocurred in.

答:
There is no built in way to do this. you will need to think about what your application does and provide ways of undoing each operation.

For instance, you can delete the file you copied, you can delete the rows you inserted, and likewise remove the text you wrote to file.

Look into exception handling

Body:
I have following code:

File.Copy(pathSource, pathDestination);   //copy file
ID3v2TagToDB(pathSource, pathDestination); //read his tags and save them to DB
ID3v2TagToTXT(pathSource, pathDestination); //read his tags and save them to txt
dgv.Rows[chosen[i]].DefaultCellStyle.BackColor = Color.GreenYellow; //color green datagridview row if copy and read successfull

I want to ensure that each operation is successfull. If any of them failed, I need to rollback all previous ones.

And also, warn user about error that ocurred, and operation that ocurred in.


问:
CSS tabs with arrows and full background color hovers
I got the following tab bar navigation which I would like to do in CSS only:

On this screen, I have marked the last element "Endergebnis" as .active or :hover.

I thought about creating the arrows as pseudo elements with position: absolute, although about multiple elements using transform: rotate(x deg), but in every solution I do not know how to give each tab a full filling background-color.

Can anybody give me a good hint?

答:
Here are two options to do this:

You create a triangle with CSS. In your example, you would need to have 2 triangles overlapping each other, because creating a triangle with CSS requires borders, and you cannot add a border to a border. You can use the following snippet:

.box {
  background: green;
  color: white;
  border: 2px solid black;
  border-right: 0;
  display: inline-block;
  height: 40px;
  position: relative;
}
.box + .box {
  border-left: 0;
  padding-left: 24px;
}
.box:after,
.box:before {
  content: "";
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;

  border-left: 20px solid green;
  position: absolute;
  right: -20px;
  top: 0;
  z-index: 2;
}
.box:before {
  border-top: 21px solid transparent;
  border-bottom: 21px solid transparent;
  border-left: 21px solid black;
  top: -1px;
  right: -21px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="box">Website</div><div class="box">About Me</div><div class="box">Contact</div></code>```

You can create a regular quadratic element and rotate it 45deg with the following statement. You need to make sure to have the correct z-index set.

```<code> transform: rotate(45deg);
</code>```

I would go for the second option, as you are much more flexible.

Edit by sudipto

Here's how you can do it without using CSS transformation:
(I am using transparent borders with the :before and :after pseudo classes instead.)

body {
  background: #eff4f7;
  padding: 30px;
}

.breadcrumb-wrap {
  font-family: sans-serif;
  font-size: 15.5px;
  font-weight: bold;
  color: #64768a;
  border: 2px solid #d7dade;
  border-radius: 5px;
}

.breadcrumb-title {
  font-size: 22px;
  padding: 10px 20px;
}

.breadcrumb {
  list-style: none;
  overflow: hidden;
  padding: 0;
  margin: 0;
  border-top: 2px solid #d7dade;
}

.breadcrumb li {
  float: left;
}

.breadcrumb li a {
  color: #64768a;
  text-decoration: none;
  padding: 20px 0px 20px 50px;
  background: #ffffff;
  position: relative;
  display: block;
  float: left;
}

.breadcrumb li a:after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-bottom: 50px solid transparent;
  border-left: 30px solid #ffffff;
  position: absolute;
  top: 50%;
  margin-top: -50px;
  left: 100%;
  z-index: 2;
}

.breadcrumb li a:before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-bottom: 50px solid transparent;
  border-left: 30px solid #d7dade;
  position: absolute;
  top: 50%;
  margin-top: -50px;
  margin-left: 2px;
  left: 100%;
  z-index: 1;
}

.breadcrumb li:first-child a {
  padding-left: 20px;
}

.breadcrumb li:last-child a {
  background: #eff4f7;
  color: #64768a;
  cursor: default;
}

.breadcrumb li:last-child a:hover {
  background: #ffffff;
}

.breadcrumb li:last-child a:after {
  border-left-color: #eff4f7;
}

.breadcrumb li:last-child a:hover:after {
  border-left-color: #ffffff;
}

.breadcrumb li a:hover {
  background: #eef3f6;
}

.breadcrumb li a:hover:after {
  border-left-color: #eef3f6;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="breadcrumb-wrap">
  <div class="breadcrumb-title">Teams</div>
  <ul class="breadcrumb">
    <li>Meldungen</li>
    <li>Zulassung</li>
    <li>Endergebnis</li>
  </ul>
</div></code>```

Body:
Here are two options to do this:

You create a triangle with CSS. In your example, you would need to have 2 triangles overlapping each other, because creating a triangle with CSS requires borders, and you cannot add a border to a border. You can use the following snippet:

.box {
  background: green;
  color: white;
  border: 2px solid black;
  border-right: 0;
  display: inline-block;
  height: 40px;
  position: relative;
}
.box + .box {
  border-left: 0;
  padding-left: 24px;
}
.box:after,
.box:before {
  content: "";
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;

  border-left: 20px solid green;
  position: absolute;
  right: -20px;
  top: 0;
  z-index: 2;
}
.box:before {
  border-top: 21px solid transparent;
  border-bottom: 21px solid transparent;
  border-left: 21px solid black;
  top: -1px;
  right: -21px;
}

<div class="box">Website</div><div class="box">About Me</div><div class="box">Contact</div>

You can create a regular quadratic element and rotate it 45deg with the following statement. You need to make sure to have the correct z-index set.

 transform: rotate(45deg);

I would go for the second option, as you are much more flexible.

Edit by sudipto

Here's how you can do it without using CSS transformation:
(I am using transparent borders with the :before and :after pseudo classes instead.)

body {
  background: #eff4f7;
  padding: 30px;
}

.breadcrumb-wrap {
  font-family: sans-serif;
  font-size: 15.5px;
  font-weight: bold;
  color: #64768a;
  border: 2px solid #d7dade;
  border-radius: 5px;
}

.breadcrumb-title {
  font-size: 22px;
  padding: 10px 20px;
}

.breadcrumb {
  list-style: none;
  overflow: hidden;
  padding: 0;
  margin: 0;
  border-top: 2px solid #d7dade;
}

.breadcrumb li {
  float: left;
}

.breadcrumb li a {
  color: #64768a;
  text-decoration: none;
  padding: 20px 0px 20px 50px;
  background: #ffffff;
  position: relative;
  display: block;
  float: left;
}

.breadcrumb li a:after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-bottom: 50px solid transparent;
  border-left: 30px solid #ffffff;
  position: absolute;
  top: 50%;
  margin-top: -50px;
  left: 100%;
  z-index: 2;
}

.breadcrumb li a:before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-bottom: 50px solid transparent;
  border-left: 30px solid #d7dade;
  position: absolute;
  top: 50%;
  margin-top: -50px;
  margin-left: 2px;
  left: 100%;
  z-index: 1;
}

.breadcrumb li:first-child a {
  padding-left: 20px;
}

.breadcrumb li:last-child a {
  background: #eff4f7;
  color: #64768a;
  cursor: default;
}

.breadcrumb li:last-child a:hover {
  background: #ffffff;
}

.breadcrumb li:last-child a:after {
  border-left-color: #eff4f7;
}

.breadcrumb li:last-child a:hover:after {
  border-left-color: #ffffff;
}

.breadcrumb li a:hover {
  background: #eef3f6;
}

.breadcrumb li a:hover:after {
  border-left-color: #eef3f6;
}

<div class="breadcrumb-wrap">
  <div class="breadcrumb-title">Teams</div>
  <ul class="breadcrumb">
    <li><a href="#">Meldungen</a></li>
    <li><a href="#">Zulassung</a></li>
    <li><a href="#">Endergebnis</a></li>
  </ul>
</div>


问:
What is the right way to work with InnoDBs lack of 2nd col auto_increment support?
I am using Mysql 5.1. Because I need transactions I wanted to switch a database from MyISAM to InnoDB, but then I learned I can't because I have a primary key that contains two columns (businessunitID and invoiceID) while one (invoiceID) being an auto increment column:

```<code>CREATE TABLE invoice (invoiceID INT auto_increment, businessunitID
INT(2), date DATETIME, PRIMARY KEY (businessunitID, invoiceID));
</code>```

This design makes sense, because there are businessunits (like branches) and each has its own set of issued invoices with an ordinal number (invoiceID) where it is not allowed that a number in between is missing.

There are enough answers on stackoverflow that it does not work with InnoDB:

What is wrong with this mysql query?

But my question is: What should I do? Do I really have to migrate very basic database logic to program logic making the application much less failure proof? It is just right to define auto increment at a database level, you'll never know from where the data populating the database could all come from. (Here is an article adressing this: http://weblogs.sqlteam.com/jeffs/archive/2007/08/23/composite_primary_keys.aspx - 100% agree.)

So is there another solution I still can get my desired behaviour with InnoDB?

答:
I discuss a possible solution for your problem in my blog on converting from MyISAM:  https://mariadb.com/kb/en/mariadb/converting-tables-from-myisam-to-innodb/

```<code>BEGIN;
SELECT @id := MAX(id)+1 FROM foo WHERE businessunitID = 123 FOR UPDATE;
INSERT INTO foo
    (businessunitID, id, ...)
    VALUES
    (123, @id, ...);
...
COMMIT;
</code>```

I say "possible solution" because there could be edge cases involving ROLLBACK and crashing that leave gaps.

Please also note that the above code has the same problem that InnoDB has:

Delete the hightest ID

Shutdown the server (gracefully or not)

Startup and allocate an ID -- you will "reuse" the deleted ID.  (This is "fixed" in 8.0 for InnoDB, but not in the above code.)

Addenda

AUTO_INCREMENT protects itself from multiple connections, etc.

Neither engine will ever* duplicate an AUTO_INCREMENT id, regardless of what locking you do or don't do.

2nd column is a feature of MyISAM, unavailable in InnoDB (except by some kludge like my code, above).

"Burning ids" (gaps in AUTO_INCREMENT) is possible, in many ways, in both engines.

With InnoDB, everything between BEGIN and COMMIT either entirely succeeds or is entirely rolled back; no partial commit (unlike MyISAM).  This applies even across power failures.

But note...  Once you have grabbed @id (in my code), the transactional semantics apply only because of FOR UPDATE.  A SELECT with FOR UPDATE announces that you intend to change what was selected -- that is, "locks" it (MAX(ID)).

Footnote:  There are two obscure ways to duplicate AUTO_INCREMENT:

Dual master, but inserting into both.

The delete-shutdown-restart, as mentioned above.

Alternate solution

```<code>invoiceID ... AUTO_INCREMENT,
...
PRIMARY KEY (businessunitID, invoiceID),
INDEX(invoiceID)
</code>```

AUTO_INCREMENT requires that the id be first in some index, nothing else.

What you lose with this solution, is any hint of the ids being consecutive (1,2,3,...) for a given busineessunit.  They will be monotonically increasing.

Body:
I am using Mysql 5.1. Because I need transactions I wanted to switch a database from MyISAM to InnoDB, but then I learned I can't because I have a primary key that contains two columns (businessunitID and invoiceID) while one (invoiceID) being an auto increment column:

CREATE TABLE invoice (invoiceID INT auto_increment, businessunitID
INT(2), date DATETIME, PRIMARY KEY (businessunitID, invoiceID));

This design makes sense, because there are businessunits (like branches) and each has its own set of issued invoices with an ordinal number (invoiceID) where it is not allowed that a number in between is missing.

There are enough answers on stackoverflow that it does not work with InnoDB:

What is wrong with this mysql query?

But my question is: What should I do? Do I really have to migrate very basic database logic to program logic making the application much less failure proof? It is just right to define auto increment at a database level, you'll never know from where the data populating the database could all come from. (Here is an article adressing this: http://weblogs.sqlteam.com/jeffs/archive/2007/08/23/composite_primary_keys.aspx - 100% agree.)

So is there another solution I still can get my desired behaviour with InnoDB?

Body:
I discuss a possible solution for your problem in my blog on converting from MyISAM:  https://mariadb.com/kb/en/mariadb/converting-tables-from-myisam-to-innodb/

BEGIN;
SELECT @id := MAX(id)+1 FROM foo WHERE businessunitID = 123 FOR UPDATE;
INSERT INTO foo
    (businessunitID, id, ...)
    VALUES
    (123, @id, ...);
...
COMMIT;

I say "possible solution" because there could be edge cases involving ROLLBACK and crashing that leave gaps.

Please also note that the above code has the same problem that InnoDB has:

Delete the hightest ID

Shutdown the server (gracefully or not)

Startup and allocate an ID -- you will "reuse" the deleted ID.  (This is "fixed" in 8.0 for InnoDB, but not in the above code.)

Addenda

AUTO_INCREMENT protects itself from multiple connections, etc.

Neither engine will ever* duplicate an AUTO_INCREMENT id, regardless of what locking you do or don't do.

2nd column is a feature of MyISAM, unavailable in InnoDB (except by some kludge like my code, above).

"Burning ids" (gaps in AUTO_INCREMENT) is possible, in many ways, in both engines.

With InnoDB, everything between BEGIN and COMMIT either entirely succeeds or is entirely rolled back; no partial commit (unlike MyISAM).  This applies even across power failures.

But note...  Once you have grabbed @id (in my code), the transactional semantics apply only because of FOR UPDATE.  A SELECT with FOR UPDATE announces that you intend to change what was selected -- that is, "locks" it (MAX(ID)).

Footnote:  There are two obscure ways to duplicate AUTO_INCREMENT:

Dual master, but inserting into both.

The delete-shutdown-restart, as mentioned above.

Alternate solution

invoiceID ... AUTO_INCREMENT,
...
PRIMARY KEY (businessunitID, invoiceID),
INDEX(invoiceID)

AUTO_INCREMENT requires that the id be first in some index, nothing else.

What you lose with this solution, is any hint of the ids being consecutive (1,2,3,...) for a given busineessunit.  They will be monotonically increasing.


问:
Getting sequence of td when button pressed
I have made a table with one button in each td and 4 td in each tr, I want to get the sequence of the td when the corresponding button is pressed, but I am getting sequence 0-4 because parent changes after next row. Is there a way to get the sequence of buttons from 0-11. here is my jQuery code.

```<code>$('.act-butn').on('click', function() {
        var btnClicked = $(this).parent().index();
        $('.activity1').text(btnClicked);
});
</code>```

and here is my Table

```<code><table class="beta" width=443 id="logButtons">
  <center>
    <tr>
      <td><input type='button' name='Production' value='Production' id="actB1" class="act-butn" /></td>
      <td> <input type='button' name='Break' value='Break' id="actB2" class="act-butn" /></td>
      <td> <input type='button' name='Medical' value='Medical' class="act-butn" /></td>
      <td> <input type='button' name='Comfort Break' value='Comfort Break' class="act-butn" /></td>
    </tr>
    <tr>
      <td> <input type='button' name='Meeting' value='Meeting' class="act-butn" /></td>
      <td> <input type='button' name='Training' value='Training' class="act-butn" /></td>
      <td> <input type='button' name='Business Improvement' value='Bus. Improvement' class="act-butn" /></td>
      <td> <input type='button' name='Idle' value='Idle' class="act-butn" /></td>
    </tr>
    <tr>
      <td> <input type='button' name='Downtime' value='Downtime' class="act-butn" /></td>
      <td> <input type='button' name='Follow up' value='Follow up' class="act-butn" /></td>
      <td> <input type='button' name='one-to-one' value='one to one' class="act-butn" /></td>
      <td> <input type='button' name='Coaching' value='Coaching' class="act-butn" /></td>
    </tr>
  </center>
</table>
</code>```

Please suggest changes.

答:
If you want to get the <input> index you need a collection of all those inputs to index against

```<code>var $inputs = $('.act-butn').on('click', function() {
     // index of `this` in `$inputs` collection
     var btnClicked = $inputs.index(this);
     $('.activity1').text(btnClicked);
});
</code>```

Or if you want  index within all  based on input clicked:

```<code>var $td = $('.act-butn').on('click', function() {
     var btnClicked = $td.index( $(this).parent() );
     $('.activity1').text(btnClicked);
}).parent();
</code>```

DEMO

Body:
I have made a table with one button in each td and 4 td in each tr, I want to get the sequence of the td when the corresponding button is pressed, but I am getting sequence 0-4 because parent changes after next row. Is there a way to get the sequence of buttons from 0-11. here is my jQuery code.

$('.act-butn').on('click', function() {
        var btnClicked = $(this).parent().index();
        $('.activity1').text(btnClicked);
});

and here is my Table

      <input type='button' name='Production' value='Production' id="actB1" class="act-butn" />
       <input type='button' name='Break' value='Break' id="actB2" class="act-butn" />
       <input type='button' name='Medical' value='Medical' class="act-butn" />
       <input type='button' name='Comfort Break' value='Comfort Break' class="act-butn" />

       <input type='button' name='Meeting' value='Meeting' class="act-butn" />
       <input type='button' name='Training' value='Training' class="act-butn" />
       <input type='button' name='Business Improvement' value='Bus. Improvement' class="act-butn" />
       <input type='button' name='Idle' value='Idle' class="act-butn" />

       <input type='button' name='Downtime' value='Downtime' class="act-butn" />
       <input type='button' name='Follow up' value='Follow up' class="act-butn" />
       <input type='button' name='one-to-one' value='one to one' class="act-butn" />
       <input type='button' name='Coaching' value='Coaching' class="act-butn" />

Please suggest changes.

Body:
If you want to get the <input> index you need a collection of all those inputs to index against

var $inputs = $('.act-butn').on('click', function() {
     // index of `this` in `$inputs` collection
     var btnClicked = $inputs.index(this);
     $('.activity1').text(btnClicked);
});

Or if you want <td> index within all <td> based on input clicked:

var $td = $('.act-butn').on('click', function() {
     var btnClicked = $td.index( $(this).parent() );
     $('.activity1').text(btnClicked);
}).parent();

DEMO