问:
Media query visual bug, unexpected behavior mobile response
I am working on a homework assignment that should generate the following results:

On desktop:

On mobile:

On tablet:

Right now I am getting the proper desktop component but the mobile component is not loading properly at all.

Here are some screen shots of how my result looks on tablet:

And on mobile:

I don't see exactly where I am going wrong in terms of my code. Attached is the css and html I am working with.

Any clue as to what's wrong would really help me out. I am using Google chrome, Microsoft edge, and opera emulator to test.

/* pacific.css for assignment #5 by Caleb Latimer*/

*{
      box-sizing: border-box;
}
body{
      background-color: #FFFFFF;
      color : #666666;
      font-family: Verdana;
      background-image: url(images/background.jpg);
}
h1{
      background-color: #000033;
      color : #FFFFFF;
      font-family: Georgia;
      line-height: 200%;
      background-image: url(images/sunset.jpg);
      background-repeat: no-repeat;
      padding-left: 20px;
      height: 72px;
      margin-bottom: 0;
      background-position: right;
}

h2{
      color: #3399CC;
      font-family: Georgia;
}
dt{
      color: #000033;
      font-weight: bold;
}
.resort{
      color: #000033;
      font-size: 1.2em;
}
footer{
      font-size: .70em;
      font-style: italic;
      text-align: center;
      padding: 10px 10px 10px 10px;
      background-color: #FFFFFF;
      margin-left: 170px;
}
#wrapper{
      width: 80%;
      margin-right: auto;
      margin-left: auto;
      background-color: #90C7E3;
      min-width: 700px;
      max-width: 1024px;
      box-shadow: 5px 5px 5px #828282;
}
h3{
      color: #000033;
}
main{
      padding-left: 20px;
      padding-right: 20px;
      display:block;
}
#homehero{
      height: 300px;
      background-image: url(images/coast.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#yurthero{
      height: 300px;
      background-image: url(images/yurt.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#trailhero{
      height: 300px;
      background-image: url(images/trail.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
 nav ul li a{
      text-decoration: none;

}
nav a:link{
      color: #000033;
}
nav a:visited{
      color: #344873;
}
nav a:hover{
      color: #FFFFFF;
}
.left-column{
      font-weight: bold;
      background-color: inherit;
      float: left;
      width: 160px;
      /*padding-top: 20px 5px 0 20px; works for some reason?*/
      padding-top: 20px;
      padding-right: 5px;
      padding-bottom: 0px;
      padding-left: 0px;

      position: relative;
}
.left-column ul li{
      list-style: none;
      list-style-type: none;
      margin: 0;
      padding-left: 0;
}
.right-column{
      background-color: #FFFFFF;
      margin-left: 170px;
      padding-top: 1px;
      padding-bottom: 1px;
}
header,nav,main,footer{
      display: block;
}
#mobile{
  display: none;
}
#desktop{
  display: inline;
}

/* CSS media queries below */
@media only screen and (max-width: 1024px){
  body{
    margin: 0;
    padding: 0;
    background-image: none;
  }
  #wrapper{
    width:auto;
    min-width: 0;
    margin:0;
    box-shadow: none;
  }
  h1{
    margin: 0;
  }
  nav{
    float:none;
    width:auto;
    padding: 0.5em;
  }
  nav li{
    display:inline-block;
  }
  nav a{
    padding: 1em;
  }
  main{
    padding: 1em;
    margin-left: 0;
    font-size: 90%;
  }
  footer{
    margin:0;
  }
  #homehero{
    margin-left: 0;
  }
  #yurthero{
    margin-left: 0;
  }
  #trailhero{
    margin-left: 0;
  }
}

@media only all and (max-width: 768px){
  h1{
    height: 100%;
    font-size: 1.5em;
    padding-left: 0.3em;
  }
  nav{
    padding: 0;
  }
  nav ul{
    margin: 0;
    padding: 0;
  }
  nav li{
    display: block;
    margin: 0;
    padding: 0;
  }
  nav a{
    display: block;
    padding:0.2em;
    font-size:1.3em;
    border-bottom-width: 1px;
    border-bottom-color: #330000;
  }
  main{
    padding-top: 0.1em;
    padding-right: 0.6em;
    padding-bottom: 0.1em;
    padding-left: 0.4em;
  }
  #homehero{
    display: none;
  }
  #yurthero{
    display:none;
  }
  #trailhero{
    display:none;
  }
  footer{
    padding: 0;
  }
  #mobile{
    display: inline;
  }
  #desktop{
    display: none;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!-- Chapter 5 Homework by Caleb Latimer -->
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>Pacific Trails Resort</title>
    <!-- [if lt IE 9]>
    <script src = "http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif] -->
    <link rel="stylesheet" href="pacific.css" /> <!-- Uses the pacific.css stylesheet inside of folder -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!-- viewport tag configuration -->
  </head>
  <body>
        <div id="wrapper">
             <header>
                     <h1>Pacific Trails Resort</h1>
             </header>

          <nav class = "left-column">
           <ul>
            <li>Home</li>
            <li>Yurts</li>
            <li>Activities</li>
            <li>Reservations </li><!-- Doesn't lead anywhere no requirements given -->
          </ul>
          </nav>

          <div id ="homehero"></div>
          <main class = "right-column">
            <h2>Enjoy Nature in Luxury</h2>

            <p>
              <span class="resort">Pacific Trails Resort</span> offers a special lodging experience on the California North Coast. Relax in serenity with panoramic views of the Pacific Ocean.
            </p>

            <ul>
              <li>Private yurts with decks overlooking the ocean</li>
              <li>Activities lodge with fireplace and gift shop</li>
              <li>Nightly fine dining at the Overlook Cafe</li>
              <li>Heated outdoor pool and whirlpool</li>
              <li>Guided hiking tours of the redwoods</li>
            </ul>

            <div>
              <span class="resort">Pacific Trails Resort</span> <br />
              12010 Pacific Trails Road <br />
              Zephyr, CA 95555<br /><br />
              888-555-5555<br />
              <span id="desktop">888-555-5555</span>
            </div>

          </main>

          <footer>
            Copyright © 2016 Pacific Trails Resort <br />
            Caleb@Latimer.com
          </footer>
        </div>
  </body>
</html></code>```

答:
I solved my own issue, the problem was with the media queries. I had css that defined .left-column & .right-column but I never overwrote it in proper context of the queries. Below is the modified CSS which solves the problem:

```<code>/* pacific.css for assignment #5 by Caleb Latimer*/
*{
  box-sizing: border-box;
}
body{
      background-color: #FFFFFF;
      color : #666666;
      font-family: Verdana;
      background-image: url(images/background.jpg);
}
h1{
      background-color: #000033;
      color : #FFFFFF;
      font-family: Georgia;
      line-height: 200%;
      background-image: url(images/sunset.jpg);
      background-repeat: no-repeat;
      padding-left: 20px;
      height: 72px;
      margin-bottom: 0;
      background-position: right;
}
h2{
      color: #3399CC;
      font-family: Georgia;
}
dt{
      color: #000033;
      font-weight: bold;
}
.resort{
      color: #000033;
      font-size: 1.2em;
}
footer{
      font-size: .70em;
      font-style: italic;
      text-align: center;
      padding: 10px 10px 10px 10px;
      background-color: #FFFFFF;
      margin-left: 170px;
}
#wrapper{
      width: 80%;
      margin-right: auto;
      margin-left: auto;
      background-color: #90C7E3;
      min-width: 700px;
      max-width: 1024px;
      box-shadow: 5px 5px 5px #828282;
}
h3{
      color: #000033;
}
main{
      padding-left: 20px;
      padding-right: 20px;
      display:block;
}
#homehero{
      height: 300px;
      background-image: url(images/coast.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#yurthero{
      height: 300px;
      background-image: url(images/yurt.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#trailhero{
      height: 300px;
      background-image: url(images/trail.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
 nav ul li a{
      text-decoration: none;
}
nav a:link{
      color: #000033;
}
nav a:visited{
      color: #344873;
}
nav a:hover{
      color: #FFFFFF;
}
.left-column{
      font-weight: bold;
      background-color: inherit;
      float: left;
      width: 160px;
      padding-top: 20px;
      padding-right: 5px;
      padding-bottom: 0px;
      padding-left: 0px;
      position: relative;
}
.left-column ul li{
      list-style: none;
      list-style-type: none;
      margin: 0;
      padding-left: 0;
}
.right-column{
      background-color: #FFFFFF;
      margin-left: 170px;
      padding-top: 1px;
      padding-bottom: 1px;
}
header,nav,main,footer{
      display: block;
}
#mobile{
  display: none;
}
#desktop{
  display: inline;
}

/* CSS media queries below */
@media only screen and (max-width: 1024px){
  body{
    margin: 0;
    padding: 0;
    background-image: none;
}
  #wrapper{
    width:auto;
    min-width: 0;
    margin:0;
    box-shadow: none;
}
  h1{
    margin: 0;
}
nav ul{
  padding-left: 0px;
}
  nav{
    float:none;
    width:auto;
    padding: 0.5em;
}
  nav li{
    display:inline-block;
}
  nav a{
    padding: 1em;
}
  main{
    padding: 1em;
    margin-left: 0;
    font-size: 90%;
}
  footer{
    margin:0;
  }
  #homehero{
    margin-left: 0;
  }
  #yurthero{
    margin-left: 0;
  }
  #trailhero{
    margin-left: 0;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 5px;
    padding-bottom: 0px;
    padding-left: 0px;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}

@media only all and (max-width: 768px){
  h1{
    height: 100%;
    font-size: 1.5em;
    padding-left: 0.3em;
  }
  nav{
    padding: 0;
  }
  nav a{
    display: block;
    padding:0.2em;
    font-size:1.3em;
  }
  nav ul{
    margin: 0;
    padding: 0;
  }
  nav li{
    display: block;
    margin: 0;
    padding: 0;
    border: solid;
    border-width: 1px;
    border-color: #330000;
  }
  main{
    padding-top: 0.1em;
    padding-right: 0.6em;
    padding-bottom: 0.1em;
    padding-left: 0.4em;
  }
  #homehero{
    display: none;
  }
  #yurthero{
    display:none;
  }
  #trailhero{
    display:none;
  }
  footer{
    padding: 0;
  }
  #mobile{
    display: inline;
  }
  #desktop{
    display: none;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 0px;
    padding-bottom: 0px;
    padding-left: 0px;
    position:relative;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}
</code>```

and here's the snippet

/* pacific.css for assignment #5 by Caleb Latimer*/
*{
  box-sizing: border-box;
}
body{
      background-color: #FFFFFF;
      color : #666666;
      font-family: Verdana;
      background-image: url(images/background.jpg);
}
h1{
      background-color: #000033;
      color : #FFFFFF;
      font-family: Georgia;
      line-height: 200%;
      background-image: url(images/sunset.jpg);
      background-repeat: no-repeat;
      padding-left: 20px;
      height: 72px;
      margin-bottom: 0;
      background-position: right;
}
h2{
      color: #3399CC;
      font-family: Georgia;
}
dt{
      color: #000033;
      font-weight: bold;
}
.resort{
      color: #000033;
      font-size: 1.2em;
}
footer{
      font-size: .70em;
      font-style: italic;
      text-align: center;
      padding: 10px 10px 10px 10px;
      background-color: #FFFFFF;
      margin-left: 170px;
}
#wrapper{
      width: 80%;
      margin-right: auto;
      margin-left: auto;
      background-color: #90C7E3;
      min-width: 700px;
      max-width: 1024px;
      box-shadow: 5px 5px 5px #828282;
}
h3{
      color: #000033;
}
main{
      padding-left: 20px;
      padding-right: 20px;
      display:block;
}
#homehero{
      height: 300px;
      background-image: url(images/coast.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#yurthero{
      height: 300px;
      background-image: url(images/yurt.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#trailhero{
      height: 300px;
      background-image: url(images/trail.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
 nav ul li a{
      text-decoration: none;
}
nav a:link{
      color: #000033;
}
nav a:visited{
      color: #344873;
}
nav a:hover{
      color: #FFFFFF;
}
.left-column{
      font-weight: bold;
      background-color: inherit;
      float: left;
      width: 160px;
      padding-top: 20px;
      padding-right: 5px;
      padding-bottom: 0px;
      padding-left: 0px;
      position: relative;
}
.left-column ul li{
      list-style: none;
      list-style-type: none;
      margin: 0;
      padding-left: 0;
}
.right-column{
      background-color: #FFFFFF;
      margin-left: 170px;
      padding-top: 1px;
      padding-bottom: 1px;
}
header,nav,main,footer{
      display: block;
}
#mobile{
  display: none;
}
#desktop{
  display: inline;
}

/* CSS media queries below */
@media only screen and (max-width: 1024px){
  body{
    margin: 0;
    padding: 0;
    background-image: none;
}
  #wrapper{
    width:auto;
    min-width: 0;
    margin:0;
    box-shadow: none;
}
  h1{
    margin: 0;
}
nav ul{
  padding-left: 0px;
}
  nav{
    float:none;
    width:auto;
    padding: 0.5em;
}
  nav li{
    display:inline-block;
}
  nav a{
    padding: 1em;
}
  main{
    padding: 1em;
    margin-left: 0;
    font-size: 90%;
}
  footer{
    margin:0;
  }
  #homehero{
    margin-left: 0;
  }
  #yurthero{
    margin-left: 0;
  }
  #trailhero{
    margin-left: 0;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 5px;
    padding-bottom: 0px;
    padding-left: 0px;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}

@media only all and (max-width: 768px){
  h1{
    height: 100%;
    font-size: 1.5em;
    padding-left: 0.3em;
  }
  nav{
    padding: 0;
  }
  nav a{
    display: block;
    padding:0.2em;
    font-size:1.3em;
  }
  nav ul{
    margin: 0;
    padding: 0;
  }
  nav li{
    display: block;
    margin: 0;
    padding: 0;
    border: solid;
    border-width: 1px;
    border-color: #330000;
  }
  main{
    padding-top: 0.1em;
    padding-right: 0.6em;
    padding-bottom: 0.1em;
    padding-left: 0.4em;
  }
  #homehero{
    display: none;
  }
  #yurthero{
    display:none;
  }
  #trailhero{
    display:none;
  }
  footer{
    padding: 0;
  }
  #mobile{
    display: inline;
  }
  #desktop{
    display: none;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 0px;
    padding-bottom: 0px;
    padding-left: 0px;
    position:relative;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!-- Chapter 5 Homework by Caleb Latimer -->
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>Pacific Trails Resort</title>
    <!-- [if lt IE 9]>
    <script src = "http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif] -->
    <link rel="stylesheet" href="pacific.css" /> <!-- Uses the pacific.css stylesheet inside of folder -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!-- viewport tag configuration -->
  </head>
  <body>
        <div id="wrapper">
             <header>
                     <h1>Pacific Trails Resort</h1>
             </header>

          <nav class = "left-column">
           <ul>
            <li>Home</li>
            <li>Yurts</li>
            <li>Activities</li>
            <li>Reservations </li><!-- Doesn't lead anywhere no requirements given -->
          </ul>
          </nav>

          <div id ="homehero"></div>
          <main class = "right-column">
            <h2>Enjoy Nature in Luxury</h2>

            <p>
              <span class="resort">Pacific Trails Resort</span> offers a special lodging experience on the California North Coast. Relax in serenity with panoramic views of the Pacific Ocean.
            </p>

            <ul>
              <li>Private yurts with decks overlooking the ocean</li>
              <li>Activities lodge with fireplace and gift shop</li>
              <li>Nightly fine dining at the Overlook Cafe</li>
              <li>Heated outdoor pool and whirlpool</li>
              <li>Guided hiking tours of the redwoods</li>
            </ul>

            <div>
              <span class="resort">Pacific Trails Resort</span> <br />
              12010 Pacific Trails Road <br />
              Zephyr, CA 95555<br /><br />
              888-555-5555<br />
              <span id="desktop">888-555-5555</span>
            </div>

          </main>

          <footer>
            Copyright © 2016 Pacific Trails Resort <br />
            Caleb@Latimer.com
          </footer>
        </div>
  </body>
</html></code>```

Body:
I am working on a homework assignment that should generate the following results:

On desktop:

On mobile:

On tablet:

Right now I am getting the proper desktop component but the mobile component is not loading properly at all.

Here are some screen shots of how my result looks on tablet:

And on mobile:

I don't see exactly where I am going wrong in terms of my code. Attached is the css and html I am working with.

Any clue as to what's wrong would really help me out. I am using Google chrome, Microsoft edge, and opera emulator to test.

/* pacific.css for assignment #5 by Caleb Latimer*/

*{
      box-sizing: border-box;
}
body{
      background-color: #FFFFFF;
      color : #666666;
      font-family: Verdana;
      background-image: url(images/background.jpg);
}
h1{
      background-color: #000033;
      color : #FFFFFF;
      font-family: Georgia;
      line-height: 200%;
      background-image: url(images/sunset.jpg);
      background-repeat: no-repeat;
      padding-left: 20px;
      height: 72px;
      margin-bottom: 0;
      background-position: right;
}

h2{
      color: #3399CC;
      font-family: Georgia;
}
dt{
      color: #000033;
      font-weight: bold;
}
.resort{
      color: #000033;
      font-size: 1.2em;
}
footer{
      font-size: .70em;
      font-style: italic;
      text-align: center;
      padding: 10px 10px 10px 10px;
      background-color: #FFFFFF;
      margin-left: 170px;
}
#wrapper{
      width: 80%;
      margin-right: auto;
      margin-left: auto;
      background-color: #90C7E3;
      min-width: 700px;
      max-width: 1024px;
      box-shadow: 5px 5px 5px #828282;
}
h3{
      color: #000033;
}
main{
      padding-left: 20px;
      padding-right: 20px;
      display:block;
}
#homehero{
      height: 300px;
      background-image: url(images/coast.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#yurthero{
      height: 300px;
      background-image: url(images/yurt.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#trailhero{
      height: 300px;
      background-image: url(images/trail.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
 nav ul li a{
      text-decoration: none;

}
nav a:link{
      color: #000033;
}
nav a:visited{
      color: #344873;
}
nav a:hover{
      color: #FFFFFF;
}
.left-column{
      font-weight: bold;
      background-color: inherit;
      float: left;
      width: 160px;
      /*padding-top: 20px 5px 0 20px; works for some reason?*/
      padding-top: 20px;
      padding-right: 5px;
      padding-bottom: 0px;
      padding-left: 0px;

      position: relative;
}
.left-column ul li{
      list-style: none;
      list-style-type: none;
      margin: 0;
      padding-left: 0;
}
.right-column{
      background-color: #FFFFFF;
      margin-left: 170px;
      padding-top: 1px;
      padding-bottom: 1px;
}
header,nav,main,footer{
      display: block;
}
#mobile{
  display: none;
}
#desktop{
  display: inline;
}

/* CSS media queries below */
@media only screen and (max-width: 1024px){
  body{
    margin: 0;
    padding: 0;
    background-image: none;
  }
  #wrapper{
    width:auto;
    min-width: 0;
    margin:0;
    box-shadow: none;
  }
  h1{
    margin: 0;
  }
  nav{
    float:none;
    width:auto;
    padding: 0.5em;
  }
  nav li{
    display:inline-block;
  }
  nav a{
    padding: 1em;
  }
  main{
    padding: 1em;
    margin-left: 0;
    font-size: 90%;
  }
  footer{
    margin:0;
  }
  #homehero{
    margin-left: 0;
  }
  #yurthero{
    margin-left: 0;
  }
  #trailhero{
    margin-left: 0;
  }
}

@media only all and (max-width: 768px){
  h1{
    height: 100%;
    font-size: 1.5em;
    padding-left: 0.3em;
  }
  nav{
    padding: 0;
  }
  nav ul{
    margin: 0;
    padding: 0;
  }
  nav li{
    display: block;
    margin: 0;
    padding: 0;
  }
  nav a{
    display: block;
    padding:0.2em;
    font-size:1.3em;
    border-bottom-width: 1px;
    border-bottom-color: #330000;
  }
  main{
    padding-top: 0.1em;
    padding-right: 0.6em;
    padding-bottom: 0.1em;
    padding-left: 0.4em;
  }
  #homehero{
    display: none;
  }
  #yurthero{
    display:none;
  }
  #trailhero{
    display:none;
  }
  footer{
    padding: 0;
  }
  #mobile{
    display: inline;
  }
  #desktop{
    display: none;
  }
}

<!DOCTYPE html>

    <meta charset="utf-8">
    <title>Pacific Trails Resort</title>

    <link rel="stylesheet" href="pacific.css" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0">

Pacific Trails Resort

Home

Yurts

Activities

Reservations

Enjoy Nature in Luxury

              Pacific Trails Resort offers a special lodging experience on the California North Coast. Relax in serenity with panoramic views of the Pacific Ocean.

Private yurts with decks overlooking the ocean

Activities lodge with fireplace and gift shop

Nightly fine dining at the Overlook Cafe

Heated outdoor pool and whirlpool

Guided hiking tours of the redwoods

              Pacific Trails Resort

              12010 Pacific Trails Road

              Zephyr, CA 95555

              888-555-5555

              888-555-5555

            Copyright © 2016 Pacific Trails Resort

            Caleb@Latimer.com

Body:
I solved my own issue, the problem was with the media queries. I had css that defined .left-column & .right-column but I never overwrote it in proper context of the queries. Below is the modified CSS which solves the problem:

/* pacific.css for assignment #5 by Caleb Latimer*/
*{
  box-sizing: border-box;
}
body{
      background-color: #FFFFFF;
      color : #666666;
      font-family: Verdana;
      background-image: url(images/background.jpg);
}
h1{
      background-color: #000033;
      color : #FFFFFF;
      font-family: Georgia;
      line-height: 200%;
      background-image: url(images/sunset.jpg);
      background-repeat: no-repeat;
      padding-left: 20px;
      height: 72px;
      margin-bottom: 0;
      background-position: right;
}
h2{
      color: #3399CC;
      font-family: Georgia;
}
dt{
      color: #000033;
      font-weight: bold;
}
.resort{
      color: #000033;
      font-size: 1.2em;
}
footer{
      font-size: .70em;
      font-style: italic;
      text-align: center;
      padding: 10px 10px 10px 10px;
      background-color: #FFFFFF;
      margin-left: 170px;
}
#wrapper{
      width: 80%;
      margin-right: auto;
      margin-left: auto;
      background-color: #90C7E3;
      min-width: 700px;
      max-width: 1024px;
      box-shadow: 5px 5px 5px #828282;
}
h3{
      color: #000033;
}
main{
      padding-left: 20px;
      padding-right: 20px;
      display:block;
}
#homehero{
      height: 300px;
      background-image: url(images/coast.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#yurthero{
      height: 300px;
      background-image: url(images/yurt.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#trailhero{
      height: 300px;
      background-image: url(images/trail.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
 nav ul li a{
      text-decoration: none;
}
nav a:link{
      color: #000033;
}
nav a:visited{
      color: #344873;
}
nav a:hover{
      color: #FFFFFF;
}
.left-column{
      font-weight: bold;
      background-color: inherit;
      float: left;
      width: 160px;
      padding-top: 20px;
      padding-right: 5px;
      padding-bottom: 0px;
      padding-left: 0px;
      position: relative;
}
.left-column ul li{
      list-style: none;
      list-style-type: none;
      margin: 0;
      padding-left: 0;
}
.right-column{
      background-color: #FFFFFF;
      margin-left: 170px;
      padding-top: 1px;
      padding-bottom: 1px;
}
header,nav,main,footer{
      display: block;
}
#mobile{
  display: none;
}
#desktop{
  display: inline;
}

/* CSS media queries below */
@media only screen and (max-width: 1024px){
  body{
    margin: 0;
    padding: 0;
    background-image: none;
}
  #wrapper{
    width:auto;
    min-width: 0;
    margin:0;
    box-shadow: none;
}
  h1{
    margin: 0;
}
nav ul{
  padding-left: 0px;
}
  nav{
    float:none;
    width:auto;
    padding: 0.5em;
}
  nav li{
    display:inline-block;
}
  nav a{
    padding: 1em;
}
  main{
    padding: 1em;
    margin-left: 0;
    font-size: 90%;
}
  footer{
    margin:0;
  }
  #homehero{
    margin-left: 0;
  }
  #yurthero{
    margin-left: 0;
  }
  #trailhero{
    margin-left: 0;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 5px;
    padding-bottom: 0px;
    padding-left: 0px;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}

@media only all and (max-width: 768px){
  h1{
    height: 100%;
    font-size: 1.5em;
    padding-left: 0.3em;
  }
  nav{
    padding: 0;
  }
  nav a{
    display: block;
    padding:0.2em;
    font-size:1.3em;
  }
  nav ul{
    margin: 0;
    padding: 0;
  }
  nav li{
    display: block;
    margin: 0;
    padding: 0;
    border: solid;
    border-width: 1px;
    border-color: #330000;
  }
  main{
    padding-top: 0.1em;
    padding-right: 0.6em;
    padding-bottom: 0.1em;
    padding-left: 0.4em;
  }
  #homehero{
    display: none;
  }
  #yurthero{
    display:none;
  }
  #trailhero{
    display:none;
  }
  footer{
    padding: 0;
  }
  #mobile{
    display: inline;
  }
  #desktop{
    display: none;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 0px;
    padding-bottom: 0px;
    padding-left: 0px;
    position:relative;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}

and here's the snippet

/* pacific.css for assignment #5 by Caleb Latimer*/
*{
  box-sizing: border-box;
}
body{
      background-color: #FFFFFF;
      color : #666666;
      font-family: Verdana;
      background-image: url(images/background.jpg);
}
h1{
      background-color: #000033;
      color : #FFFFFF;
      font-family: Georgia;
      line-height: 200%;
      background-image: url(images/sunset.jpg);
      background-repeat: no-repeat;
      padding-left: 20px;
      height: 72px;
      margin-bottom: 0;
      background-position: right;
}
h2{
      color: #3399CC;
      font-family: Georgia;
}
dt{
      color: #000033;
      font-weight: bold;
}
.resort{
      color: #000033;
      font-size: 1.2em;
}
footer{
      font-size: .70em;
      font-style: italic;
      text-align: center;
      padding: 10px 10px 10px 10px;
      background-color: #FFFFFF;
      margin-left: 170px;
}
#wrapper{
      width: 80%;
      margin-right: auto;
      margin-left: auto;
      background-color: #90C7E3;
      min-width: 700px;
      max-width: 1024px;
      box-shadow: 5px 5px 5px #828282;
}
h3{
      color: #000033;
}
main{
      padding-left: 20px;
      padding-right: 20px;
      display:block;
}
#homehero{
      height: 300px;
      background-image: url(images/coast.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#yurthero{
      height: 300px;
      background-image: url(images/yurt.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
#trailhero{
      height: 300px;
      background-image: url(images/trail.jpg);
      background-size: 100% 100%;
      margin-left: 170px;
}
 nav ul li a{
      text-decoration: none;
}
nav a:link{
      color: #000033;
}
nav a:visited{
      color: #344873;
}
nav a:hover{
      color: #FFFFFF;
}
.left-column{
      font-weight: bold;
      background-color: inherit;
      float: left;
      width: 160px;
      padding-top: 20px;
      padding-right: 5px;
      padding-bottom: 0px;
      padding-left: 0px;
      position: relative;
}
.left-column ul li{
      list-style: none;
      list-style-type: none;
      margin: 0;
      padding-left: 0;
}
.right-column{
      background-color: #FFFFFF;
      margin-left: 170px;
      padding-top: 1px;
      padding-bottom: 1px;
}
header,nav,main,footer{
      display: block;
}
#mobile{
  display: none;
}
#desktop{
  display: inline;
}

/* CSS media queries below */
@media only screen and (max-width: 1024px){
  body{
    margin: 0;
    padding: 0;
    background-image: none;
}
  #wrapper{
    width:auto;
    min-width: 0;
    margin:0;
    box-shadow: none;
}
  h1{
    margin: 0;
}
nav ul{
  padding-left: 0px;
}
  nav{
    float:none;
    width:auto;
    padding: 0.5em;
}
  nav li{
    display:inline-block;
}
  nav a{
    padding: 1em;
}
  main{
    padding: 1em;
    margin-left: 0;
    font-size: 90%;
}
  footer{
    margin:0;
  }
  #homehero{
    margin-left: 0;
  }
  #yurthero{
    margin-left: 0;
  }
  #trailhero{
    margin-left: 0;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 5px;
    padding-bottom: 0px;
    padding-left: 0px;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}

@media only all and (max-width: 768px){
  h1{
    height: 100%;
    font-size: 1.5em;
    padding-left: 0.3em;
  }
  nav{
    padding: 0;
  }
  nav a{
    display: block;
    padding:0.2em;
    font-size:1.3em;
  }
  nav ul{
    margin: 0;
    padding: 0;
  }
  nav li{
    display: block;
    margin: 0;
    padding: 0;
    border: solid;
    border-width: 1px;
    border-color: #330000;
  }
  main{
    padding-top: 0.1em;
    padding-right: 0.6em;
    padding-bottom: 0.1em;
    padding-left: 0.4em;
  }
  #homehero{
    display: none;
  }
  #yurthero{
    display:none;
  }
  #trailhero{
    display:none;
  }
  footer{
    padding: 0;
  }
  #mobile{
    display: inline;
  }
  #desktop{
    display: none;
  }
  .left-column{
    font-weight: bold;
    background-color: inherit;
    float: none;
    padding-top: 0px;
    padding-right: 0px;
    padding-bottom: 0px;
    padding-left: 0px;
    position:relative;
    width: 100%;
  }
  .right-column{
    background-color: #FFFFFF;
    margin-left: 0px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
}

<!-- Chapter 5 Homework by Caleb Latimer -->
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>Pacific Trails Resort</title>
    <!-- [if lt IE 9]>
    <script src = "http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif] -->
    <link rel="stylesheet" href="pacific.css" /> <!-- Uses the pacific.css stylesheet inside of folder -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!-- viewport tag configuration -->
  </head>
  <body>
        <div id="wrapper">
             <header>
                     <h1>Pacific Trails Resort</h1>
             </header>

          <nav class = "left-column">
           <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="yurts.html">Yurts</a></li>
            <li><a href="activities.html">Activities</a></li>
            <li><a href="reservations.html">Reservations</a> </li><!-- Doesn't lead anywhere no requirements given -->
          </ul>
          </nav>

          <div id ="homehero"></div>
          <main class = "right-column">
            <h2>Enjoy Nature in Luxury</h2>

            <p>
              <span class="resort">Pacific Trails Resort</span> offers a special lodging experience on the California North Coast. Relax in serenity with panoramic views of the Pacific Ocean.
            </p>

            <ul>
              <li>Private yurts with decks overlooking the ocean</li>
              <li>Activities lodge with fireplace and gift shop</li>
              <li>Nightly fine dining at the Overlook Cafe</li>
              <li>Heated outdoor pool and whirlpool</li>
              <li>Guided hiking tours of the redwoods</li>
            </ul>

            <div>
              <span class="resort">Pacific Trails Resort</span> <br />
              12010 Pacific Trails Road <br />
              Zephyr, CA 95555<br /><br />
              <a id="mobile" href="tel:888-555-5555">888-555-5555</a><br />
              <span id="desktop">888-555-5555</span>
            </div>

          </main>

          <footer>
            Copyright &copy; 2016 Pacific Trails Resort <br />
            <a href = "mailto:Caleb@Latimer.com">Caleb@Latimer.com</a>
          </footer>
        </div>
  </body>
</html>


来源: stackexchange

问:
SymPy: Union of symbolic Interval
I have two Sympy interval (Interval(1, m), Interval(1, m+1)) where m>=1.
I want to make the Union of those 2 intervals. The result should be [1,m+1]

Unfortunately I was not able to pass to Sympy the constraint on m.

Where is my actual code with the 'too mush general' answer:

```<code>m = symbols('m', integer=True)
Union(Interval(1, m), Interval(1, m+1))
>> [1, m] U [1, m + 1]
</code>```

I tried to use the reduce function without any success...

Any help would be greatly appreciated.

Thank you!

答:
We can get the desired output by creating a new interval12 like so:

```<code>m=Symbol('m',positive=True)
interval1 = Interval(0,m)
interval2 = Interval(0,m+4)
union12 = interval1.union(interval2)
interval12 = Interval(union12.inf,union12.sup)
print interval1, interval2, interval12
</code>```

output:

```<code>[0, m] [0, m + 4] [0, m + 4]
</code>```

ContentLicense: CC BY-SA 3.0

Title: SymPy: Union of symbolic Interval

Body:
I have two Sympy interval (Interval(1, m), Interval(1, m+1)) where m>=1.
I want to make the Union of those 2 intervals. The result should be [1,m+1]

Unfortunately I was not able to pass to Sympy the constraint on m.

Where is my actual code with the 'too mush general' answer:

m = symbols('m', integer=True)
Union(Interval(1, m), Interval(1, m+1))
>> [1, m] U [1, m + 1]

I tried to use the reduce function without any success...

Any help would be greatly appreciated.

Thank you!

Body:
We can get the desired output by creating a new interval12 like so:

m=Symbol('m',positive=True)
interval1 = Interval(0,m)
interval2 = Interval(0,m+4)
union12 = interval1.union(interval2)
interval12 = Interval(union12.inf,union12.sup)
print interval1, interval2, interval12

output:

[0, m] [0, m + 4] [0, m + 4]


问:
ms-access shorten vba code
I'm using the following code alot in my project:

```<code>txtVoornaam.Locked = False
txtVoornaam.BorderStyle = 4
txtVoornaam.BorderColor = RGB(255, 165, 0

txtAchternaam.Locked = False
txtAchternaam.BorderStyle = 4
txtAchternaam.BorderColor = RGB(255, 165, 0)

txtAfdeling.Locked = False
txtAfdeling.BorderStyle = 4
txtAfdeling.BorderColor = RGB(255, 165, 0)
</code>```

I wonder if there is a way to not display this in my code or shorten this. The code gets very long if i use this a few times..

答:
Whenever you need to repeat a set of instructions, instead of copy+pasta'ing code your first reaction should be to ask yourself "how can I avoid copying this chunk over and over?" - and the solution is pretty much always to extract a method and parameterize it.

So you take one of the repeated chunks:

```<code>txtAchternaam.Locked = False
txtAchternaam.BorderStyle = 4
txtAchternaam.BorderColor = RGB(255, 165, 0)
</code>```

and then copy it one last time in a new scope:

```<code>Private Sub RenameMe()
    txtAchternaam.Locked = False
    txtAchternaam.BorderStyle = 4
    txtAchternaam.BorderColor = RGB(255, 165, 0)
End Sub
</code>```

Then you extract the parameters:

```<code>Private Sub RenameMe(ByVal target As Control)
    target.Locked = False
    target.BorderStyle = 4
    target.BorderColor = RGB(255, 165, 0)
End Sub
</code>```

Then you replace the repeated chunks with calls to that new procedure:

```<code>RenameMe txtVoornaam
RenameMe txtAchternaam
RenameMe txtAfdeling
</code>```

Or if that's still tedious you can iterate controls and call that procedure in the loop body - whatever works best for you.

And if you need more flexibility, extract more parameters and make them Optional as needed:

```<code>Private Sub RenameMe(ByVal target As Control, Optional ByVal lockCtrl As Boolean = False, Optional ByVal brdrStyle As Long = 4, Optional ByVal brdrColor As Long = 42495)
    target.Locked = lockCtrl
    target.BorderStyle = brdrStyle
    target.BorderColor = brdrColor
End Sub
</code>```

Now the hard part is to give RenameMe a meaningful name that properly conveys what's going on here. I'd suggest FormatControl or something along these lines.

Title: ms-access shorten vba code

Body:
I'm using the following code alot in my project:

txtVoornaam.Locked = False
txtVoornaam.BorderStyle = 4
txtVoornaam.BorderColor = RGB(255, 165, 0

txtAchternaam.Locked = False
txtAchternaam.BorderStyle = 4
txtAchternaam.BorderColor = RGB(255, 165, 0)

txtAfdeling.Locked = False
txtAfdeling.BorderStyle = 4
txtAfdeling.BorderColor = RGB(255, 165, 0)

I wonder if there is a way to not display this in my code or shorten this. The code gets very long if i use this a few times..

Body:
Whenever you need to repeat a set of instructions, instead of copy+pasta'ing code your first reaction should be to ask yourself "how can I avoid copying this chunk over and over?" - and the solution is pretty much always to extract a method and parameterize it.

So you take one of the repeated chunks:

txtAchternaam.Locked = False
txtAchternaam.BorderStyle = 4
txtAchternaam.BorderColor = RGB(255, 165, 0)

and then copy it one last time in a new scope:

Private Sub RenameMe()
    txtAchternaam.Locked = False
    txtAchternaam.BorderStyle = 4
    txtAchternaam.BorderColor = RGB(255, 165, 0)
End Sub

Then you extract the parameters:

Private Sub RenameMe(ByVal target As Control)
    target.Locked = False
    target.BorderStyle = 4
    target.BorderColor = RGB(255, 165, 0)
End Sub

Then you replace the repeated chunks with calls to that new procedure:

RenameMe txtVoornaam
RenameMe txtAchternaam
RenameMe txtAfdeling

Or if that's still tedious you can iterate controls and call that procedure in the loop body - whatever works best for you.

And if you need more flexibility, extract more parameters and make them Optional as needed:

Private Sub RenameMe(ByVal target As Control, Optional ByVal lockCtrl As Boolean = False, Optional ByVal brdrStyle As Long = 4, Optional ByVal brdrColor As Long = 42495)
    target.Locked = lockCtrl
    target.BorderStyle = brdrStyle
    target.BorderColor = brdrColor
End Sub

Now the hard part is to give RenameMe a meaningful name that properly conveys what's going on here. I'd suggest FormatControl or something along these lines.


问:
cucumber giving null pointer exception with multiple scenario in feature file
Test Steps

```<code>public class TestSmoke {
        WebDriver driver;
        @Given("^open firefox and start application$")jjj
        public void open_firefox_and_start_application() throws Throwable {
            driver=new FirefoxDriver();
            driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
            driver.get("https://example.com");

        }
    **Scenario 1**
        @When("^I click on Login$")
        public void I_click_on_Login() throws Throwable {
            driver.findElement(By.xpath("//a[contains(.,'Login')]")).click();

        }

        @When("^enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
        public void enter_valid_and_valid(String uname, String pass) throws Throwable {
            driver.findElement(By.id("Username")).sendKeys(uname);
            driver.findElement(By.id("Password")).sendKeys(pass);

        }

        @Then("^Click on login and User should be able to login successfully$")
        public void Click_on_login_and_User_should_be_able_to_login_successfully() throws Throwable {
            driver.findElement(By.id("loginUser")).click();

        }
</code>```

jkjbjkkjhjknjkbjkhjkbjbjbbjbnmbbnmb

```<code>        **Scenario 2:**
        @Given("^Click on shop for carts$")
        public void Click_on_shop_for_carts() throws Throwable {
            hhjbhbhgjbkjbhlhihjbhbb
            driver.findElement(By.xpath("//span[text()='Shop for Parts']")).click();

        }

        @Given("^select plates$")
        public void select_plates() throws Throwable {
            driver.findElement(By.xpath("//a[contains(.,'Plates ')]")).click();

        }

        @When("^I click on drsired product$")
        public void I_click_on_drsired_product() throws Throwable {
            driver.findElement(By.xpath("//a[@data-itemnumber='PLT01096096046']")).click();
        }

        @When("^click on item increment$")
        public void click_on_item_increment() throws Throwable {
            WebElement ele=driver.findElement(By.xpath("//i[contains(@class,'fa fa-caret-up')]"));
            for(int i=0;i<=3;i++)
            {
                ele.click();
            }

        }

        @When("^Click on buy now$")
        public void Click_on_buy_now() throws Throwable {
            driver.findElement(By.xpath("//button[contains(.,'Buy Now')]")).click();

        }

        @Then("^Product should be added to the cart successfully$")
        public void Product_should_be_added_to_the_cart_successfully() throws Throwable {

        }
</code>```

Feature File
Feature: Test test Smoke scenario

```<code> Scenario: Test login with valid credentials
    Given open firefox and start application
    When I click on Login
    And enter valid "s@yopmail.com" and valid "passw0rd"
    Then Click on login and User should be able to login successfully

    Scenario: Test shop for cart
    Given Click on shop for carts
    And select plates
    When I click on drsired product
    And click on item increment
    And Click on buy now
    Then Product should be added to the cart successfully

</code>```

Test runner

```<code>@RunWith(Cucumber.class)
@Cucumber.Options(features="features",glue={"steps"})
public class TestRunnr {
</code>```

While i am running this cucumber script its throwing an NullPointer Exception :

```<code>java.lang.NullPointerException
    at steps.testmoke.Click_on_shop_for_carts(testSmoke.java:47)
    at ?.Given Click on shop for carts(MyApplication.feature:11)
</code>```

First scenario is executing successfully but second scenario is not executing.I am login in a ecommerce website and try to click on shop for parts .

答:
Each scenario creates a fresh instance of all the step definitions.
In your case you instantiate the driver in the Given step public void open_firefox_and_start_application() so the first scenario is successful.
Now for the second scenario a new instance of your class has a webdriver which is null and you are not calling the earlier step to instantiate it.

You can use a static webdriver, but you will run into issues with parallel tests. If you are planning for parallel tests look up ThreadLocal to make sure your webdriver is attached to the specific thread.

Another way could be to move the login tests to a separate file. For the other scenarios move the login steps into the Background cucumber tag. This way the webdriver will be instantiated for each scenario. But you will need to decide if you want to keep logged in across scenarios, delete cookies or a new browser for each scenario.

ContentLicense: CC BY-SA 4.0

Body:
Test Steps

public class TestSmoke {
        WebDriver driver;
        @Given("^open firefox and start application$")jjj
        public void open_firefox_and_start_application() throws Throwable {
            driver=new FirefoxDriver();
            driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
            driver.get("https://example.com");

        }
    **Scenario 1**
        @When("^I click on Login$")
        public void I_click_on_Login() throws Throwable {
            driver.findElement(By.xpath("//a[contains(.,'Login')]")).click();

        }

        @When("^enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
        public void enter_valid_and_valid(String uname, String pass) throws Throwable {
            driver.findElement(By.id("Username")).sendKeys(uname);
            driver.findElement(By.id("Password")).sendKeys(pass);

        }

        @Then("^Click on login and User should be able to login successfully$")
        public void Click_on_login_and_User_should_be_able_to_login_successfully() throws Throwable {
            driver.findElement(By.id("loginUser")).click();

        }

jkjbjkkjhjknjkbjkhjkbjbjbbjbnmbbnmb

        **Scenario 2:**
        @Given("^Click on shop for carts$")
        public void Click_on_shop_for_carts() throws Throwable {
            hhjbhbhgjbkjbhlhihjbhbb
            driver.findElement(By.xpath("//span[text()='Shop for Parts']")).click();

        }

        @Given("^select plates$")
        public void select_plates() throws Throwable {
            driver.findElement(By.xpath("//a[contains(.,'Plates ')]")).click();

        }

        @When("^I click on drsired product$")
        public void I_click_on_drsired_product() throws Throwable {
            driver.findElement(By.xpath("//a[@data-itemnumber='PLT01096096046']")).click();
        }

        @When("^click on item increment$")
        public void click_on_item_increment() throws Throwable {
            WebElement ele=driver.findElement(By.xpath("//i[contains(@class,'fa fa-caret-up')]"));
            for(int i=0;i<=3;i++)
            {
                ele.click();
            }

        }

        @When("^Click on buy now$")
        public void Click_on_buy_now() throws Throwable {
            driver.findElement(By.xpath("//button[contains(.,'Buy Now')]")).click();

        }

        @Then("^Product should be added to the cart successfully$")
        public void Product_should_be_added_to_the_cart_successfully() throws Throwable {

        }

Feature File
Feature: Test test Smoke scenario

 Scenario: Test login with valid credentials
    Given open firefox and start application
    When I click on Login
    And enter valid "s@yopmail.com" and valid "passw0rd"
    Then Click on login and User should be able to login successfully

    Scenario: Test shop for cart
    Given Click on shop for carts
    And select plates
    When I click on drsired product
    And click on item increment
    And Click on buy now
    Then Product should be added to the cart successfully

Test runner

@RunWith(Cucumber.class)
@Cucumber.Options(features="features",glue={"steps"})
public class TestRunnr {

While i am running this cucumber script its throwing an NullPointer Exception :

java.lang.NullPointerException
    at steps.testmoke.Click_on_shop_for_carts(testSmoke.java:47)
    at ?.Given Click on shop for carts(MyApplication.feature:11)

First scenario is executing successfully but second scenario is not executing.I am login in a ecommerce website and try to click on shop for parts .


问:
How to fetch all the fields form database in Asp.NET MVC?
I have an application in Asp.NET MVC with Entity Data Model. Now I have a model for state_master table where I have only one property 'State_Name' and in database table I have 2 fields 'State_ID' which is auto incremented and 'State_Name' for which I will insert the data.
Now as I have only one property in Model I am not able to fetch both the fields 'State_ID' and 'State_Name' using this model. This is the issue which I am facing.

State Model File :

```<code>using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace ViewData.Models
{
 public class state_model
      {
        [Key]
        public string state_name { get; set; }
       }
 }
</code>```

View File :

```<code>@using ViewData.Models
@{
   Layout = null;
 }

  <!DOCTYPE html>
  <html>
  <head>
  <meta name="viewport" content="width=device-width" />
  <title>state_view</title>
  </head>
  <body>
   <div>
   <ul>
      @foreach (var state in ViewData["states"] as   IList<state_model>)
          {
            <li>
               @state.state_name
            </li>
           }
   </ul>
   </div>
   </body>
   </html>
</code>```

Controller File :

```<code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ViewData.DataAccessLayer;
using ViewData.Models;
namespace ViewData.Controllers
{
 public class StateController : Controller
    {
     // GET: State
     public ActionResult Index()
        {
         DataLayer dl = new DataLayer();
         IList<state_model> data = (from o in dl.states select o).ToList();
         ViewData["states"] = data;
         return View("state_view");
         }
     }
 }
</code>```

答:
You need to create a View Model for state to fetch and bind all the fields from database. For example,

```<code>public class state_ViewModel
  {
    [Key]
    public int state_Id { get; set; } //check with your data type
    public string state_name { get; set; }
   }
</code>```

So in your controller method, You can use this one for fetch and bind. And for insert record you can use state_model

And in your action method,

```<code>public ActionResult Index()
    {
     DataLayer dl = new DataLayer();
     IList<state_ViewModel> data = (from o in dl.states select o).ToList();
     ViewData["states"] = data;
     return View("state_view");
     }
</code>```

See, View Model is nothing but rendering your data in your view.
To know more about view model click here

Body:
I have an application in Asp.NET MVC with Entity Data Model. Now I have a model for state_master table where I have only one property 'State_Name' and in database table I have 2 fields 'State_ID' which is auto incremented and 'State_Name' for which I will insert the data.
Now as I have only one property in Model I am not able to fetch both the fields 'State_ID' and 'State_Name' using this model. This is the issue which I am facing.

State Model File :

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace ViewData.Models
{
 public class state_model
      {
        [Key]
        public string state_name { get; set; }
       }
 }

View File :

@using ViewData.Models
@{
   Layout = null;
 }

  <!DOCTYPE html>

  <meta name="viewport" content="width=device-width" />
  <title>state_view</title>

      @foreach (var state in ViewData["states"] as   IList<state_model>)
          {

               @state.state_name

           }

Controller File :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ViewData.DataAccessLayer;
using ViewData.Models;
namespace ViewData.Controllers
{
 public class StateController : Controller
    {
     // GET: State
     public ActionResult Index()
        {
         DataLayer dl = new DataLayer();
         IList<state_model> data = (from o in dl.states select o).ToList();
         ViewData["states"] = data;
         return View("state_view");
         }
     }
 }

Body:
You need to create a View Model for state to fetch and bind all the fields from database. For example,

public class state_ViewModel
  {
    [Key]
    public int state_Id { get; set; } //check with your data type
    public string state_name { get; set; }
   }

So in your controller method, You can use this one for fetch and bind. And for insert record you can use state_model

And in your action method,

public ActionResult Index()
    {
     DataLayer dl = new DataLayer();
     IList<state_ViewModel> data = (from o in dl.states select o).ToList();
     ViewData["states"] = data;
     return View("state_view");
     }

See, View Model is nothing but rendering your data in your view.
To know more about view model click here


问:
Which Operating Systems support native (inotify-like) file watching in Java
The JavaDoc for java.nio.file.WatchService states;

The implementation ... is
  intended to map directly on to the native file event notification
  facility where available, or to use a primitive mechanism, such as
  polling, when a native facility is not available.

I assume this means it will try a lightweight, native mechanism when it can (something like inotify on Linux) and poll if it can not.

Is that correct?

What operating systems are likely or unlikely to provide such a facility? Distro level for Linux would be really useful or can I assume that if the JVM runs on *unix, it will be supported?

答:
This should have probably been a comment, but it's too big to post it as such...

I am looking at jdk-9 sources (could easily be searched in the jdk-8 repo as well), but here is some relevant to your question comments:

```<code>   /**
     * Linux implementation of WatchService based on inotify.
     *
     * In summary a background thread polls inotify plus a socket used for the wakeup
     * mechanism. Requests to add or remove a watch, or close the watch service,
     * cause the thread to wakeup and process the request. Events are processed
     * by the thread which causes it to signal/queue the corresponding watch keys.
     */

 class LinuxWatchService  extends AbstractWatchService
</code>```

And for windows:

```<code>/*
 * Win32 implementation of WatchService based on ReadDirectoryChangesW.
 */

class WindowsWatchService extends AbstractWatchService
</code>```

And so on.. you can find all the available implementations under:

```<code> jdk/src/java.base/{windows|unix|solaris|linux...}/classes/sun/nio/fs/
</code>```

As what OS actually supports this, it seems like that would require for you to look at the actual distro.

Body:
This should have probably been a comment, but it's too big to post it as such...

I am looking at jdk-9 sources (could easily be searched in the jdk-8 repo as well), but here is some relevant to your question comments:

   /**
     * Linux implementation of WatchService based on inotify.
     *
     * In summary a background thread polls inotify plus a socket used for the wakeup
     * mechanism. Requests to add or remove a watch, or close the watch service,
     * cause the thread to wakeup and process the request. Events are processed
     * by the thread which causes it to signal/queue the corresponding watch keys.
     */

 class LinuxWatchService  extends AbstractWatchService

And for windows:

/*
 * Win32 implementation of WatchService based on ReadDirectoryChangesW.
 */

class WindowsWatchService extends AbstractWatchService

And so on.. you can find all the available implementations under:

 jdk/src/java.base/{windows|unix|solaris|linux...}/classes/sun/nio/fs/

As what OS actually supports this, it seems like that would require for you to look at the actual distro.


问:
compiler error C2248:'QObject::Qobject':cannot access private member declared in class 'QObject'
Hi Everyone i have a foo class

Code in foo.h

```<code>namespace GUI
{
class Foo : public QObject
{
Q_OBJECT

public:
explicit Foo(QObject *parent = 0);
virtual ~Foo();
....

};
}
</code>```

Now this is working and compiling fine but i want to save this custom c++ class using QSettings and one of the step is registering your class with Q_DECLARE_METATYPE

and therefore as soon as i put this line
    Q_DECLARE_METATYPE(Foo)
at the end of my foo.h file i get these compiler error C2248:'QObject::Qobject':cannot access private member declared in class 'QObject' and which when clicked only takes me to last line of my connection.h header file and gives no other information as to what might be wrong i,e the error point me to

```<code>  Class Foo
  {

  };<---- point me here
  Q_DECLARE_METATYPE(Foo)
</code>```

I know that QObject cannot be copied and this is related to it but i have no idea what maybe wrong here and how can i rectify it.
Thanks in advance

答:
I know that QObject cannot be copied and this is related to it but i
  have no idea what maybe wrong here and how can i rectify it.

So declare a copy constructor, then it will be ok.

```<code>...
Foo(const Foo &_other);
...
</code>```

Body:
Hi Everyone i have a foo class

Code in foo.h

namespace GUI
{
class Foo : public QObject
{
Q_OBJECT

public:
explicit Foo(QObject *parent = 0);
virtual ~Foo();
....

};
}

Now this is working and compiling fine but i want to save this custom c++ class using QSettings and one of the step is registering your class with Q_DECLARE_METATYPE

and therefore as soon as i put this line
    Q_DECLARE_METATYPE(Foo)
at the end of my foo.h file i get these compiler error C2248:'QObject::Qobject':cannot access private member declared in class 'QObject' and which when clicked only takes me to last line of my connection.h header file and gives no other information as to what might be wrong i,e the error point me to

  Class Foo
  {

  };<---- point me here
  Q_DECLARE_METATYPE(Foo)

I know that QObject cannot be copied and this is related to it but i have no idea what maybe wrong here and how can i rectify it.
Thanks in advance

Body:
I know that QObject cannot be copied and this is related to it but i
  have no idea what maybe wrong here and how can i rectify it.

So declare a copy constructor, then it will be ok.

...
Foo(const Foo &_other);
...


问:
SQLite don't order by date
I need a selection of all the elements of the table, sorted according to the column where there are dates

this is the table create code:

```<code>String query = "CREATE TABLE IF NOT EXISTS "+ TABLE_NAME +" ( "+
            " id INTEGER PRIMARY KEY,"+
            " "+ COLUMN_LIST +" TEXT,"+
            " "+ COLUMN_PRICE + " TEXT,"+
            " "+ COLUMN_EXPIRY + " NUMERIC,"+
            " "+ COLUMN_DATE +" NUMERIC,"+
            " f_k INTEGER,"+
            " FOREIGN KEY(f_k) REFERENCES user(id)"+
            " ON DELETE CASCADE"+
            ")";
</code>```

This is the code to insert elements in the column that I need to be ordered:

```<code>try{
    VAL.put( COLUMN_EXPIRY, String.valueOf( new SimpleDateFormat( "dd-MM-yyyy" ).parse( items.get( 2 ).toString() ) ) );
}catch( ParseException e ){
    e.printStackTrace();
}
</code>```

the items.get( 2 ).toString() is stringDate variable:

```<code>int day = date.getDayOfMonth();
int month = date.getMonth() + 1;
int year = date.getYear();

stringDate = Integer.toString( day ) +"-"+ Integer.toString( month ) +"-"+ Integer.toString( year );
</code>```

the code of select element:

```<code>final String QUERY = SELECT_ALL + t;
final String ORDER = " ORDER BY DATE("+ COLUMN_EXPIRY +") DESC";
final Cursor RESULT = DB.rawQuery( QUERY + ORDER, null );
</code>```

the result does not satisfy me. the dates are not in order.
Also some elements of the column are null and I would put down the list using a different order taken by another column.

thank you

答:
When creating table, your COLUMN_EXPIRY is having improper data type to be treated as date/time.

Change it as below and you should be good to go:

```<code>...
" "+ COLUMN_EXPIRY + " DATETIME,"+
...
</code>```

Title: SQLite don't order by date

Body:
I need a selection of all the elements of the table, sorted according to the column where there are dates

this is the table create code:

String query = "CREATE TABLE IF NOT EXISTS "+ TABLE_NAME +" ( "+
            " id INTEGER PRIMARY KEY,"+
            " "+ COLUMN_LIST +" TEXT,"+
            " "+ COLUMN_PRICE + " TEXT,"+
            " "+ COLUMN_EXPIRY + " NUMERIC,"+
            " "+ COLUMN_DATE +" NUMERIC,"+
            " f_k INTEGER,"+
            " FOREIGN KEY(f_k) REFERENCES user(id)"+
            " ON DELETE CASCADE"+
            ")";

This is the code to insert elements in the column that I need to be ordered:

try{
    VAL.put( COLUMN_EXPIRY, String.valueOf( new SimpleDateFormat( "dd-MM-yyyy" ).parse( items.get( 2 ).toString() ) ) );
}catch( ParseException e ){
    e.printStackTrace();
}

the items.get( 2 ).toString() is stringDate variable:

int day = date.getDayOfMonth();
int month = date.getMonth() + 1;
int year = date.getYear();

stringDate = Integer.toString( day ) +"-"+ Integer.toString( month ) +"-"+ Integer.toString( year );

the code of select element:

final String QUERY = SELECT_ALL + t;
final String ORDER = " ORDER BY DATE("+ COLUMN_EXPIRY +") DESC";
final Cursor RESULT = DB.rawQuery( QUERY + ORDER, null );

the result does not satisfy me. the dates are not in order.
Also some elements of the column are null and I would put down the list using a different order taken by another column.

thank you

Body:
When creating table, your COLUMN_EXPIRY is having improper data type to be treated as date/time.

Change it as below and you should be good to go:

...
" "+ COLUMN_EXPIRY + " DATETIME,"+
...


问:
how to select values from 3 tables + count()
I have three Tables :

```<code>tbl_Publisher [Publisher_ID, addr,account-num,...,city];
tbl_Title [Title_ID, frequency, publisher,.., Publisher_ID];
tbl_Invoice [Invoice_ID, ordered_Date,...,Title_ID];
</code>```

I would like to return a list of Titles by Publisher and each Title has the count number of Invoices it contains. in one result set.
I'm using a stored procedure as following :

```<code>PROCEDURE [dbo].[usp_GetTitlesbyPublisher]
    -- Add the parameters for the stored procedure here
    @PublisherID INT

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.

    -- Insert statements for procedure here
    SELECT Title_ID,TitleName,pub_type,Frequency , Holdings ,tbl_Title.publisher ,section ,tbl_Title.Publisher_ID  from tbl_Title, tbl_Publisher
    where tbl_Title.Publisher_ID = tbl_Publisher.Publisher_ID
    and @PublisherID = tbl_Publisher.Publisher_ID

END
</code>```

How can I return the number of Invoice by each Title ?

答:
Not checked the syntax on this.</p>

```<code>SELECT COUNT(tbl_Invoice.Invoice_ID) 'InvoiceCount',Title_ID,TitleName,pub_type,Frequency, Holdings ,tbl_Title.publisher ,section ,tbl_Title.Publisher_ID
FROM tbl_Title
INNER JOIN tbl_Publisher ON tbl_Publisher.Publisher_ID = tbl_Title.Publisher_ID
INNER JOIN tbl_Invoice ON tbl_Invoice.Invoice_ID = tbl_Title.Invoice_ID
WHERE tbl_Publisher.Publisher_ID = @PublisherID
GROUP BY
    Title_ID,TitleName,pub_type,Frequency, Holdings ,tbl_Title.publisher ,section ,tbl_Title.Publisher_ID
</code>```

Body:
I have three Tables :

tbl_Publisher [Publisher_ID, addr,account-num,...,city];
tbl_Title [Title_ID, frequency, publisher,.., Publisher_ID];
tbl_Invoice [Invoice_ID, ordered_Date,...,Title_ID];

I would like to return a list of Titles by Publisher and each Title has the count number of Invoices it contains. in one result set.
I'm using a stored procedure as following :

PROCEDURE [dbo].[usp_GetTitlesbyPublisher]
    -- Add the parameters for the stored procedure here
    @PublisherID INT

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.

    -- Insert statements for procedure here
    SELECT Title_ID,TitleName,pub_type,Frequency , Holdings ,tbl_Title.publisher ,section ,tbl_Title.Publisher_ID  from tbl_Title, tbl_Publisher
    where tbl_Title.Publisher_ID = tbl_Publisher.Publisher_ID
    and @PublisherID = tbl_Publisher.Publisher_ID

END

How can I return the number of Invoice by each Title ?

Body:
Not checked the syntax on this.

SELECT COUNT(tbl_Invoice.Invoice_ID) 'InvoiceCount',Title_ID,TitleName,pub_type,Frequency, Holdings ,tbl_Title.publisher ,section ,tbl_Title.Publisher_ID
FROM tbl_Title
INNER JOIN tbl_Publisher ON tbl_Publisher.Publisher_ID = tbl_Title.Publisher_ID
INNER JOIN tbl_Invoice ON tbl_Invoice.Invoice_ID = tbl_Title.Invoice_ID
WHERE tbl_Publisher.Publisher_ID = @PublisherID
GROUP BY
    Title_ID,TitleName,pub_type,Frequency, Holdings ,tbl_Title.publisher ,section ,tbl_Title.Publisher_ID


问:
How to avoid TypeError: callback.apply is not a function and Callback was already called ? node js
I got   ++TypeError: callback.apply is not a function
and    ++Callback was already called.

this is my code:

```<code>var toFix = {
    'Mercedes': 'Mercedes-Benz'
  };

  var toUpdate = {
    'A-CLASSE': 'Classe A',
    'CLASSE A': 'Classe A',
  };

  async.series([

    function (cb) {
      console.log('Clean cars...');

      async.forEachOfSeries(toFix, function (to, from, cb) {
        console.log(`FixMakeForCars ${from} -> ${to}`);
        Car.update({'make': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'make': to}}, {multi: true}, cb);

      }, cb);

      async.forEachOfSeries(toUpdate, function (to, from, cb) {
        console.log(`UpdateModelForCars ${from} -> ${to}`);
        Car.update({'model': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'model': to}}, {multi: true}, cb);

      }, cb);

    },

    function (cb) {
      console.log('Clean car models...');

      async.forEachOfSeries(toFix, function (to, from, cb) {
        console.log(`FixCarModelMake ${from} -> ${to}`);
        CarModel.update(
          {'make': {$exists: true}}, {'model': {$exists: true}}, {'year': {$exists: true}},
          {'make': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'make': to}}, {multi: true}, cb);
      }, cb);

        async.forEachOfSeries(toUpdate, function (to, from, cb) {
          console.log(`UpdateModel ${from} -> ${to}`);
          CarModel.update(
            {'make':{ $exists: true}}, {'model':{ $exists: true}}, {'year':{ $exists: true}},
            {'car.model': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'car.model': to}}, {multi: true}, cb);
        }, cb);
    },

  ], function () {}
  );

};
</code>```

this is carModel schema.

```<code>var schema = new mongoose.Schema({
  make: {type: String, trim: true, required: true},
  model: {type: String, trim: true, required: true},
  year: {type: Number},
  enabled: {type: Boolean, default: false},
  range: {type: String, enum: _.values(Range)},
  premium: {type: Boolean, default: false},
  picture: {},
  status: {type: String, enum: _.values(CarModelStatus), default: CarModelStatus.DRAFT}
});

schema.index({model: 1, make: 1, year: 1}, {unique: true});
</code>```

What should I do please?

and this the error in terminal:

[

```<code>2017-03-31T12:29:15.219Z] DEBUG: job/306 on f2a8df0485ee: FixCarModelMake Mercedes -> Mercedes-Benz (env=development)
    caller: {
      "line": "269",
      "pos": "17",
      "file": "job/apply-updates/3.8.1-update-to-Mercedes-Benz.js"
    }
[2017-03-31T12:29:15.237Z] ERROR: job/306 on f2a8df0485ee: (env=development)
    TypeError: callback.apply is not a function
        at /sources/node_modules/mongoose/lib/model.js:3411:16
</code>```

thanks for helping me.

答:
There are a lot of Errors in your code

There is mismatch of the query and update orders in CarModel update method, the mongoose update have 4 parameters

Model.update(conditions, update, options, callback)

Inside One function in .series array you are performing two Other async function with callbacks, which will definitely throw an error

Callback was already Called

Look at this Code Below and use

```<code>async.series([
    function (cb) {
        console.log('Clean cars...');
        // .eachOfSeries
        async.eachOfSeries(toFix, function (to, from, cb) {
            console.log(`FixMakeForCars ${from} -> ${to}`);
            Car.update({ 'make': { $regex: S(from).trim().s, $options: 'i' } }, { $set: { 'make': to } }, { multi: true }, function (err, res) {
                if (err) return cb(err);
                cb();
            });
        }, cb);
    },

    function (cb) {
        async.eachOfSeries(toUpdate, function (to, from, cb) {
            console.log(`UpdateModelForCars ${from} -> ${to}`);
            Car.update({ 'model': { $regex: S(from).trim().s, $options: 'i' } }, { $set: { 'model': to } }, { multi: true }, function (err, res) {
                if (err) return cb(err);
                cb()
            });
        }, cb);
    },

    function (cb) {
        console.log('Clean car models...');
        async.eachOfSeries(toFix, function (to, from, cb) {
            console.log(`FixCarModelMake ${from} -> ${to}`);
            // formed the valid query, no mismatch of orders
            let query = {
                'make': { $exists: true },
                'model': { $exists: true },
                'year': { $exists: true },
                'make': { $regex: S(from).trim().s, $options: 'i' }
            }
            CarModel.update(query, { $set: { 'make': to } }, { multi: true } , function (err, res) {
                if (err) return cb(err);
                cb()
            })
        }, cb);
    },

    function (cb) {
        async.eachOfSeries(toUpdate, function (to, from, cb) {
            console.log(`UpdateModel ${from} -> ${to}`);
             // formed the valid query, no mismatch of orders
            var query = {
                'make': { $exists: true },
                'model': { $exists: true },
                'year': { $exists: true },
                'model': { $regex: S(from).trim().s, $options: 'i' }
            }
            CarModel.update(query, { $set: { 'model': to } }, { multi: true } , function (err, res) {
                if (err) return cb(err);
                cb()
            })
        }, cb );
    }
  ], function () {

  }
  );
</code>```

Body:
I got   ++TypeError: callback.apply is not a function
and    ++Callback was already called.

this is my code:

var toFix = {
    'Mercedes': 'Mercedes-Benz'
  };

  var toUpdate = {
    'A-CLASSE': 'Classe A',
    'CLASSE A': 'Classe A',
  };

  async.series([

    function (cb) {
      console.log('Clean cars...');

      async.forEachOfSeries(toFix, function (to, from, cb) {
        console.log(`FixMakeForCars ${from} -> ${to}`);
        Car.update({'make': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'make': to}}, {multi: true}, cb);

      }, cb);

      async.forEachOfSeries(toUpdate, function (to, from, cb) {
        console.log(`UpdateModelForCars ${from} -> ${to}`);
        Car.update({'model': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'model': to}}, {multi: true}, cb);

      }, cb);

    },

    function (cb) {
      console.log('Clean car models...');

      async.forEachOfSeries(toFix, function (to, from, cb) {
        console.log(`FixCarModelMake ${from} -> ${to}`);
        CarModel.update(
          {'make': {$exists: true}}, {'model': {$exists: true}}, {'year': {$exists: true}},
          {'make': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'make': to}}, {multi: true}, cb);
      }, cb);

        async.forEachOfSeries(toUpdate, function (to, from, cb) {
          console.log(`UpdateModel ${from} -> ${to}`);
          CarModel.update(
            {'make':{ $exists: true}}, {'model':{ $exists: true}}, {'year':{ $exists: true}},
            {'car.model': {$regex: S(from).trim().s, $options: 'i'}}, {$set: {'car.model': to}}, {multi: true}, cb);
        }, cb);
    },

  ], function () {}
  );

};

this is carModel schema.

var schema = new mongoose.Schema({
  make: {type: String, trim: true, required: true},
  model: {type: String, trim: true, required: true},
  year: {type: Number},
  enabled: {type: Boolean, default: false},
  range: {type: String, enum: _.values(Range)},
  premium: {type: Boolean, default: false},
  picture: {},
  status: {type: String, enum: _.values(CarModelStatus), default: CarModelStatus.DRAFT}
});

schema.index({model: 1, make: 1, year: 1}, {unique: true});

What should I do please?

and this the error in terminal:

[

2017-03-31T12:29:15.219Z] DEBUG: job/306 on f2a8df0485ee: FixCarModelMake Mercedes -> Mercedes-Benz (env=development)
    caller: {
      "line": "269",
      "pos": "17",
      "file": "job/apply-updates/3.8.1-update-to-Mercedes-Benz.js"
    }
[2017-03-31T12:29:15.237Z] ERROR: job/306 on f2a8df0485ee: (env=development)
    TypeError: callback.apply is not a function
        at /sources/node_modules/mongoose/lib/model.js:3411:16

thanks for helping me.

Body:
There are a lot of Errors in your code

There is mismatch of the query and update orders in CarModel update method, the mongoose update have 4 parameters

Model.update(conditions, update, options, callback)

Inside One function in .series array you are performing two Other async function with callbacks, which will definitely throw an error

Callback was already Called

Look at this Code Below and use

async.series([
    function (cb) {
        console.log('Clean cars...');
        // .eachOfSeries
        async.eachOfSeries(toFix, function (to, from, cb) {
            console.log(`FixMakeForCars ${from} -> ${to}`);
            Car.update({ 'make': { $regex: S(from).trim().s, $options: 'i' } }, { $set: { 'make': to } }, { multi: true }, function (err, res) {
                if (err) return cb(err);
                cb();
            });
        }, cb);
    },

    function (cb) {
        async.eachOfSeries(toUpdate, function (to, from, cb) {
            console.log(`UpdateModelForCars ${from} -> ${to}`);
            Car.update({ 'model': { $regex: S(from).trim().s, $options: 'i' } }, { $set: { 'model': to } }, { multi: true }, function (err, res) {
                if (err) return cb(err);
                cb()
            });
        }, cb);
    },

    function (cb) {
        console.log('Clean car models...');
        async.eachOfSeries(toFix, function (to, from, cb) {
            console.log(`FixCarModelMake ${from} -> ${to}`);
            // formed the valid query, no mismatch of orders
            let query = {
                'make': { $exists: true },
                'model': { $exists: true },
                'year': { $exists: true },
                'make': { $regex: S(from).trim().s, $options: 'i' }
            }
            CarModel.update(query, { $set: { 'make': to } }, { multi: true } , function (err, res) {
                if (err) return cb(err);
                cb()
            })
        }, cb);
    },

    function (cb) {
        async.eachOfSeries(toUpdate, function (to, from, cb) {
            console.log(`UpdateModel ${from} -> ${to}`);
             // formed the valid query, no mismatch of orders
            var query = {
                'make': { $exists: true },
                'model': { $exists: true },
                'year': { $exists: true },
                'model': { $regex: S(from).trim().s, $options: 'i' }
            }
            CarModel.update(query, { $set: { 'model': to } }, { multi: true } , function (err, res) {
                if (err) return cb(err);
                cb()
            })
        }, cb );
    }
  ], function () {

  }
  );


问:
App crashes randomly on viewWillDisappear()
I'm new to Swift, and I find some strange crashes in my app.

The Fabric reports said crashes occurred in viewWillDisappear().

I have two ViewControllers.User tap button in A viewcontroller then they move to B viewcontroller to input something, they user go back, and A get information from B.

I use a delegate to complete this task.

B:

```<code>class LessonNameTagTableViewController: UITableViewController {

...

var delegate:PassingData?

override func viewWillDisappear(_ animated: Bool) {

    lessonName = (tableView.cellForRow(at: IndexPath(row: 0, section: 0))?.viewWithTag(1) as! UITextField ).text!

    delegate?.changeLessonNameTag(name: lessonName, tag: tagColor)
    super.viewWillDisappear(animated)

}
...
}
</code>```

A:

```<code>class LessonEditTableViewController: UITableViewController,PassingData {
var lesson :Lesson?
...
func changeLessonNameTag(name:String,tag:UIColor){
    self.lesson!.lessonName = name
    self.lesson!.lessonTagColor = tag
    tableView.reloadData()

}
...
}
</code>```

The crash happened randomly, I've tested it on my device, and nothing happened.But others said they could repeat this crashes.

I wonder whether I'm using delegate right or it's caused by other reasons.

答:
My gut reaction is that one of the object's you're force unwrapping is in fact nil.

Instead of force unwrapping it using the !, you should safely unwrap it and fail gracefully if it is not present:

```<code>func changeLesson(name: String, tag: UIColor) {    //Updated formatting and method declaration to fit with current Swift standards
    guard let lesson = lesson else {    //Don't need to reference self here
        return
    }

    lesson.lessonName = name
    lesson.lessonTagColor = tag

    tableView.reloadData()
}
</code>```

See @orxelm's answer for how to safely unwrap your text value in B

Always be very wary when using the ! operator. Even if you think you can guarantee that the object will not ever be nil.

Body:
I'm new to Swift, and I find some strange crashes in my app.

The Fabric reports said crashes occurred in viewWillDisappear().

I have two ViewControllers.User tap button in A viewcontroller then they move to B viewcontroller to input something, they user go back, and A get information from B.

I use a delegate to complete this task.

B:

class LessonNameTagTableViewController: UITableViewController {

...

var delegate:PassingData?

override func viewWillDisappear(_ animated: Bool) {

    lessonName = (tableView.cellForRow(at: IndexPath(row: 0, section: 0))?.viewWithTag(1) as! UITextField ).text!

    delegate?.changeLessonNameTag(name: lessonName, tag: tagColor)
    super.viewWillDisappear(animated)

}
...
}

A:

class LessonEditTableViewController: UITableViewController,PassingData {
var lesson :Lesson?
...
func changeLessonNameTag(name:String,tag:UIColor){
    self.lesson!.lessonName = name
    self.lesson!.lessonTagColor = tag
    tableView.reloadData()

}
...
}

The crash happened randomly, I've tested it on my device, and nothing happened.But others said they could repeat this crashes.

I wonder whether I'm using delegate right or it's caused by other reasons.

Body:
My gut reaction is that one of the object's you're force unwrapping is in fact nil.

Instead of force unwrapping it using the !, you should safely unwrap it and fail gracefully if it is not present:

func changeLesson(name: String, tag: UIColor) {    //Updated formatting and method declaration to fit with current Swift standards
    guard let lesson = lesson else {    //Don't need to reference self here
        return
    }

    lesson.lessonName = name
    lesson.lessonTagColor = tag

    tableView.reloadData()
}

See @orxelm's answer for how to safely unwrap your text value in B

Always be very wary when using the ! operator. Even if you think you can guarantee that the object will not ever be nil.


问:
Angularjs multiplication operation in html
I am using http get request to get data and show it in my directive, gauge directive has value attribute that takes number, i am binding like this value="" attribute from ng-repeat in html. The problem is the value i'm getting from get request is in decimal like 0.23 etc but i need to multiply this value with 100 to show it in percentage, is it possible in angularjs to do something like this.
I tried like

```<code><div id="main" ng-repeat="n in myObject">

<gage name="name" id="myGage-n.id" value=n.myValuex100>

</div>
</code>```

But when i check in developer toolbar the value attribute shows value=n.myValuex100 as is. It's not replacing it with the multiplied value , in this case expected value is "23"

Please suggest if i'm missing something or need to do in a different way

答:
You can directly use your multiplication formula in {{}} expression

For example 1

```<code>{{5*5}}
</code>```

For example 2

```<code>{{number*5}}
</code>```

Refer following example

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
 $scope.number = 10;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html ng-app="myApp">
<div ng-controller="MyCtrl">
  Hello, multiplication is {{5*5}} ! <br>
  Hello, multiplication is {{number*5}} !
</div>
</html></code>```

Body:
I am using http get request to get data and show it in my directive, gauge directive has value attribute that takes number, i am binding like this value="" attribute from ng-repeat in html. The problem is the value i'm getting from get request is in decimal like 0.23 etc but i need to multiply this value with 100 to show it in percentage, is it possible in angularjs to do something like this.
I tried like

<gage name="name" id="myGage-n.id" value=n.myValuex100>

But when i check in developer toolbar the value attribute shows value=n.myValuex100 as is. It's not replacing it with the multiplied value , in this case expected value is "23"

Please suggest if i'm missing something or need to do in a different way

Body:
You can directly use your multiplication formula in {{}} expression

For example 1

{{5*5}}

For example 2

{{number*5}}

Refer following example

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
 $scope.number = 10;
}

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html ng-app="myApp">
<div ng-controller="MyCtrl">
  Hello, multiplication is {{5*5}} ! <br>
  Hello, multiplication is {{number*5}} !
</div>
</html>


问:
case with multiple conditions to produce output even when some conditons are not met
I have written a query that makes use of a multi-conditional CASE statement to perform an analyze of table data, based on an aggregate function, for example:

```<code>select country,
(case when country in ('DE','FR','IT') then 'Europe'
when country in ('CH','JP','SK') then 'Asia'
when country in ('US','CN') then 'North America'
else 'Other' end) as 'Continent',
count(*) as NR
from citizenship
group by country,
(case when country in ('DE','FR','IT') then 'Europe'
when country in ('CH','JP','SK') then 'Asia'
when country in ('US','CN') then 'North America'
else 'Other' end)
</code>```

Things are pretty straight forward until now, but I need that when there are 0 rows in the table to meet one of the case conditions, to have it displayed in the output, like with a NULL or some other predefined value, such as:

```<code> | COUNTRY | Continent | NR |
 |   IT    |   Europe  | 5  |
 |         |   Asia    | 0  |
</code>```

and so on...

Is it possible to be achieved, considering that the real query is like 500 rows long, due to many conditions applied in when clauses, and the table has nearly 60M rows? Also in this environment I can not create additional db objects.

答:
You can try something like this:

```<code>CREATE TABLE continents (NAME VARCHAR(30))
INSERT INTO continents VALUES ('Europe');
INSERT INTO continents VALUES ('Asia');
INSERT INTO continents VALUES ('North America');
INSERT INTO continents VALUES ('Other');
 SELECT * FROM continents

 CREATE TABLE citizenship (country VARCHAR(2));
 INSERT INTO citizenship VALUES ('DE')
  INSERT INTO citizenship VALUES ('IT')
  INSERT INTO citizenship VALUES ('IT')

SELECT A.NAME AS CONTINENT, B.COUNTRY, COALESCE(NR,0) AS NR
FROM continents A
LEFT JOIN (
select country
    ,case when country in ('DE','FR','IT') then 'Europe'
    when country in ('CH','JP','SK') then 'Asia'
    when country in ('US','CN') then 'North America'
    else 'Other' end as Continent
    ,COALESCE(count(*),0) as NR
from citizenship
group by country,
(case when country in ('DE','FR','IT') then 'Europe'
when country in ('CH','JP','SK') then 'Asia'
when country in ('US','CN') then 'North America'
else 'Other' end)
) B ON A.name = B.CONTINENT
</code>```

Output:

```<code>    CONTINENT                      COUNTRY NR
------------------------------ ------- -----------
Europe                         DE      1
Europe                         IT      2
Asia                           NULL    0
North America                  NULL    0
Other                          NULL    0
</code>```

Body:
I have written a query that makes use of a multi-conditional CASE statement to perform an analyze of table data, based on an aggregate function, for example:

select country,
(case when country in ('DE','FR','IT') then 'Europe'
when country in ('CH','JP','SK') then 'Asia'
when country in ('US','CN') then 'North America'
else 'Other' end) as 'Continent',
count(*) as NR
from citizenship
group by country,
(case when country in ('DE','FR','IT') then 'Europe'
when country in ('CH','JP','SK') then 'Asia'
when country in ('US','CN') then 'North America'
else 'Other' end)

Things are pretty straight forward until now, but I need that when there are 0 rows in the table to meet one of the case conditions, to have it displayed in the output, like with a NULL or some other predefined value, such as:

 | COUNTRY | Continent | NR |
 |   IT    |   Europe  | 5  |
 |         |   Asia    | 0  |

and so on...

Is it possible to be achieved, considering that the real query is like 500 rows long, due to many conditions applied in when clauses, and the table has nearly 60M rows? Also in this environment I can not create additional db objects.

Body:
You can try something like this:

CREATE TABLE continents (NAME VARCHAR(30))
INSERT INTO continents VALUES ('Europe');
INSERT INTO continents VALUES ('Asia');
INSERT INTO continents VALUES ('North America');
INSERT INTO continents VALUES ('Other');
 SELECT * FROM continents

 CREATE TABLE citizenship (country VARCHAR(2));
 INSERT INTO citizenship VALUES ('DE')
  INSERT INTO citizenship VALUES ('IT')
  INSERT INTO citizenship VALUES ('IT')

SELECT A.NAME AS CONTINENT, B.COUNTRY, COALESCE(NR,0) AS NR
FROM continents A
LEFT JOIN (
select country
    ,case when country in ('DE','FR','IT') then 'Europe'
    when country in ('CH','JP','SK') then 'Asia'
    when country in ('US','CN') then 'North America'
    else 'Other' end as Continent
    ,COALESCE(count(*),0) as NR
from citizenship
group by country,
(case when country in ('DE','FR','IT') then 'Europe'
when country in ('CH','JP','SK') then 'Asia'
when country in ('US','CN') then 'North America'
else 'Other' end)
) B ON A.name = B.CONTINENT

Output:

    CONTINENT                      COUNTRY NR
------------------------------ ------- -----------
Europe                         DE      1
Europe                         IT      2
Asia                           NULL    0
North America                  NULL    0
Other                          NULL    0


问:
Difference between two structure variable declaration?
I am doing hash implementation. I have sample program below.

```<code>#define HASHSIZE 25

struct HashTable {
        char key[50];
        char val[50];
};

int main() {

        struct HashTable *hashtab[HASHSIZE];  // declaration - 1

        struct HashTable hashtab2[HASHSIZE];  // declaration - 2
}
</code>```

declaration-1:

```<code>struct HashTable *hashtab[HASHSIZE];
</code>```

declaration-2:

```<code>struct HashTable hashtab2[HASHSIZE];
</code>```

As per my understanding, both declarations are seems to be doing same in memory layout of allocation. Like, allocating HASHSIZE of array of struct HashTable and variable pointing to the [0]th element of array of structs.

But, Still I feel that there is some difference that I might not be able to get it.

I want to know if there is a difference, how does one differ from another in memory layout (OR) allocation/accessing.

答:
```<code>struct HashTable *hashtab[HASHSIZE];
</code>```

Declares an array of pointers to struct HashTable. This array will be be on the stack. You will have to afterwards dynamically allocate the memory for the struct itself, which will be on the heap and may not be contiguous with the other struct allocations. If used to the full, the memory will be equal to the size of the array of pointers plus the size of all the allocated structures (in your example: HASHSIZE [times] sizeof(struct HashTable *) + HASHSIZE times [times] sizeof(struct HashTable)), but will be shared between heap and stack (majority on the heap).

```<code>struct HashTable hashtab2[HASHSIZE];
</code>```

Declares an array of struct HashTable. Array elements are contiguous and on the stack. Memory used will be equal to the size of the array (in your example: HASHSIZE*sizeof(struct HashTable)), regardless of how many elements in the array are used.

Body:
I am doing hash implementation. I have sample program below.

#define HASHSIZE 25

struct HashTable {
        char key[50];
        char val[50];
};

int main() {

        struct HashTable *hashtab[HASHSIZE];  // declaration - 1

        struct HashTable hashtab2[HASHSIZE];  // declaration - 2
}

declaration-1:

struct HashTable *hashtab[HASHSIZE];

declaration-2:

struct HashTable hashtab2[HASHSIZE];

As per my understanding, both declarations are seems to be doing same in memory layout of allocation. Like, allocating HASHSIZE of array of struct HashTable and variable pointing to the [0]th element of array of structs.

But, Still I feel that there is some difference that I might not be able to get it.

I want to know if there is a difference, how does one differ from another in memory layout (OR) allocation/accessing.

Body:
struct HashTable *hashtab[HASHSIZE];

Declares an array of pointers to struct HashTable. This array will be be on the stack. You will have to afterwards dynamically allocate the memory for the struct itself, which will be on the heap and may not be contiguous with the other struct allocations. If used to the full, the memory will be equal to the size of the array of pointers plus the size of all the allocated structures (in your example: HASHSIZE [times] sizeof(struct HashTable *) + HASHSIZE times [times] sizeof(struct HashTable)), but will be shared between heap and stack (majority on the heap).

struct HashTable hashtab2[HASHSIZE];

Declares an array of struct HashTable. Array elements are contiguous and on the stack. Memory used will be equal to the size of the array (in your example: HASHSIZE*sizeof(struct HashTable)), regardless of how many elements in the array are used.


问:
Bash script to check running process
I wrote a bash-script to check if a process is running. It doesn't work since the ps command always returns exit code 1. When I run the ps command from the command-line, the $? is correctly set, but within the script it is always 1. Any idea?

```<code>#!/bin/bash
SERVICE=$1

ps -a | grep -v grep | grep $1 > /dev/null
result=$?
echo "exit code: ${result}"
if [ "${result}" -eq "0" ] ; then
    echo "`date`: $SERVICE service running, everything is fine"
else
    echo "`date`: $SERVICE is not running"
fi
</code>```

Bash version: GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)

答:
```
#!/bin/bash
ps axho comm| grep $1 > /dev/null
result=$?
echo "exit code: ${result}"
if [ "${result}" -eq "0" ] ; then
echo "`date`: $SERVICE service running, everything is fine"
else
echo "`date`: $SERVICE is not running"
/etc/init.d/$1 restart
fi
```

Something like this

Title: Bash script to check running process

Body:
I wrote a bash-script to check if a process is running. It doesn't work since the ps command always returns exit code 1. When I run the ps command from the command-line, the $? is correctly set, but within the script it is always 1. Any idea?

#!/bin/bash
SERVICE=$1

ps -a | grep -v grep | grep $1 > /dev/null
result=$?
echo "exit code: ${result}"
if [ "${result}" -eq "0" ] ; then
    echo "`date`: $SERVICE service running, everything is fine"
else
    echo "`date`: $SERVICE is not running"
fi

Bash version: GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)

Body:
#!/bin/bash
ps axho comm| grep $1 > /dev/null
result=$?
echo "exit code: ${result}"
if [ "${result}" -eq "0" ] ; then
echo "`date`: $SERVICE service running, everything is fine"
else
echo "`date`: $SERVICE is not running"
/etc/init.d/$1 restart
fi

Something like this


问:
Hive - Error in acquiring locks
Hive is aborting execution and logging:

```<code>No rows affected (0.005 seconds)
No rows affected (0.059 seconds)
Error: Error while processing statement: FAILED: Error in acquiring locks: Locks on the underlying objects cannot be acquired. retry after some time (state=42000,code=10)

Closing: 0: jdbc:hive2://
</code>```

Can someone give some tip how to troubleshoot this?

hive version is 0.14 in a horton distribution
  hive.support.concurrency=true;  hive.txn.manager=DummyTxnManager

答:
In some cases, queries can lead to dead lock. I suggest having a closer look at your query to identify any dead lock pattern.

The locking documentation might help.

I don't suggest disabling the concurrency but instead, using the configuration documentation customize

hive.lock.numretries

hive.unlock.numretries

hive.lock.sleep.between.retries

Title: Hive - Error in acquiring locks

Body:
Hive is aborting execution and logging:

No rows affected (0.005 seconds)
No rows affected (0.059 seconds)
Error: Error while processing statement: FAILED: Error in acquiring locks: Locks on the underlying objects cannot be acquired. retry after some time (state=42000,code=10)

Closing: 0: jdbc:hive2://

Can someone give some tip how to troubleshoot this?

hive version is 0.14 in a horton distribution
  hive.support.concurrency=true;  hive.txn.manager=DummyTxnManager


问:
How to move cursor to front of line and end of line in textWrangler
Currently I'm using mac OX system and wants to move cursor to front and end of line freely with keyboard alone, is there any way of doing it?

I tried shift + end, ctrl + end, not working.

Thanks!

答: You can use Cmd + → to go to the end of a line and Cmd + ← to go to the beginning.


问:
Best way to implement shortest path algorithm with directed graph

Lets assume i have a weighted undirected graph with edges and wanted to find the shortest path as well as all possible paths that i could follow from the startpoint to the endpoint with distances, what would be the best way to implement this? Breadth depth search and k paths algorithm seem to offer reasonable solutions, although im not sure which is best

答:
Sorry, can't post this as comments...

If you need all possible paths, you can't do really better than "tree" traversal (BFS or DFS for instance). Note that you'll need to consider each node as many times as it can be reached from the start (the "tree" is much bigger than the original graph - even infinite if you have cycles in your graph, but let's assume you don't).

To get the smallest path, you could look for it in your list in the end; or preferably, you could use a Dijkstra-like order for your tree traversal, so the shortest path will be the first to come up.