问:
text-overflow ellipsis is not working properly
I recently changed my news ticker to a CSS version.  My problem is the I am trying to use the "text-overflow: ellipsis" and it just is not working.  I have tried placing the styles everywhere without success.  Can anyone help me?  I have created a basic codepen.  The class in GREEN is my problem.

https://codepen.io/lepew/pen/pdwNaL

body {
  background-color: black;
}

#page_Wrap {
  /* Flexbox setup */
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  xflex-flow: column nowrap;
  -webkit-flex-flow: column;
  -moz-flex-flow: column;
  -ms-flex-flow: column;
  flex-flow: column;
  /* Basic styling */
  width: 94%;
  margin: 0 auto;
  max-width: 1280px;
  border: 1px solid red;
}

header {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-flex: 0;
  -moz-box-flex: 0;
  -ms-flex: 0;
  -webkit-flex: 0;
  flex: 0;
  min-height: 100px;
}

#head_Logo,
#head_Note {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 77px;
  flex: 0 0 77px;
  width: 77px;
  height: 90px;
  border: 1px solid yellow;
}

#head_Area {
  -webkit-box-flex: 2;
  -ms-flex: 2;
  flex: 2;
  -webkit-flex-flow: column nowrap;
  -moz-flex-flow: column nowrap;
  -ms-flex-flow: column nowrap;
  flex-flow: column nowrap;
  min-width: 0;
}

.wrap_News {
  height: 45px;
  border: 1px solid lime;
}

.news_Area {
  color: #0FF;
  position: absolute;
  overflow: hidden;
  xmargin-right: 115px;
  xright: 0;
  xleft: 116px;
  opacity: 0;
  -moz-opacity: 0;
  filter: alpha(opacity=0);
}

.news_Text {
  padding: 0 5px;
  font: bold 18px Arial, Helvetica, sans-serif;
  height: 45px;
  overflow: hidden;
  line-height: 45px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.wrap_News:hover .news_Area {
  -webkit-animation-play-state: paused;
  -moz-animation-play-state: paused;
  -o-animation-play-state: paused;
  animation-play-state: paused;
}

.news_Area:nth-child(1) {
  -webkit-animation: cycle 15s 0s infinite linear;
  -moz-animation: cycle 15s 0s infinite linear;
  -o-animation: cycle 15s 0s infinite linear;
  animation: cycle 15s 0s infinite linear;
}

.news_Area:nth-child(2) {
  -webkit-animation: cycle 15s 5s infinite linear;
  -moz-animation: cycle 15s 5s infinite linear;
  -o-animation: cycle 15s 5s infinite linear;
  animation: cycle 15s 5s infinite linear;
}

.news_Area:nth-child(3) {
  -webkit-animation: cycle 15s 10s infinite linear;
  -moz-animation: cycle 15s 10s infinite linear;
  -o-animation: cycle 15s 10s infinite linear;
  animation: cycle 15s 10s infinite linear;
}

@keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-moz-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-webkit-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-ms-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-o-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="page_Wrap">

  <header>
    <div id="head_Logo">
    </div>
    <!-- end of #head_Logo -->

    <div id="head_Area">

      <div class="wrap_News">
        <div class="news_Area">
          <div class="news_Text">This is top secret.  Read more</div>
        </div>
        <!-- end of #news_Area -->
        <div class="news_Area">
          <div class="news_Text">
            This is to see what happens if a lot of text is placed here and is just blah blah blah blah blah blah.
          </div>
          <!-- end of #wrap_News -->
        </div>
        <!-- end of #news_Area -->
        <div class="news_Area">
          <div class="news_Text">Part 3 here</div>
        </div>
        <!-- end of #news_Area -->
      </div>
      <!-- end of #wrap_News -->

    </div>
    <!-- end of #head_Area -->
    <div id="head_Note">
      <!--  HERE  -->
    </div>
    <!-- end of #head_Note -->
  </header>
  <!-- end of #header -->

</div>
<!-- end of #page_Wrap --></code>```

答:
You need to set a width or a max-width to have an efficient text-overflow and also set the direct parent in position:relative; so it is the reference to calculate the space where stand those absolute children.

body {
  background-color: black;
}

#page_Wrap {
  /* Flexbox setup */
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  xflex-flow: column nowrap;
  -webkit-flex-flow: column;
  -moz-flex-flow: column;
  -ms-flex-flow: column;
  flex-flow: column;
  /* Basic styling */
  width: 94%;
  margin: 0 auto;
  max-width: 1280px;
  border: 1px solid red;
}

header {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-flex: 0;
  -moz-box-flex: 0;
  -ms-flex: 0;
  -webkit-flex: 0;
  flex: 0;
  min-height: 100px;
}

#head_Logo,
#head_Note {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 77px;
  flex: 0 0 77px;
  width: 77px;
  height: 90px;
  border: 1px solid yellow;
}

#head_Area {
  -webkit-box-flex: 2;
  -ms-flex: 2;
  flex: 2;
  -webkit-flex-flow: column nowrap;
  -moz-flex-flow: column nowrap;
  -ms-flex-flow: column nowrap;
  flex-flow: column nowrap;
  min-width: 0;
  position:relative;/*update*/
}

.wrap_News {
  height: 45px;
  border: 1px solid lime;
}

.news_Area {
  color: #0FF;
  opacity: 0;
  -moz-opacity: 0;
  filter: alpha(opacity=0);
}

.news_Text {
  position:absolute;
  padding: 0 5px;
  font: bold 18px Arial, Helvetica, sans-serif;
  height: 45px;
  overflow: hidden;
  line-height: 45px;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width:100%;/*update*/
}

.wrap_News:hover .news_Area {
  -webkit-animation-play-state: paused;
  -moz-animation-play-state: paused;
  -o-animation-play-state: paused;
  animation-play-state: paused;
}

.news_Area:nth-child(1) {
  -webkit-animation: cycle 15s 0s infinite linear;
  -moz-animation: cycle 15s 0s infinite linear;
  -o-animation: cycle 15s 0s infinite linear;
  animation: cycle 15s 0s infinite linear;
}

.news_Area:nth-child(2) {
  -webkit-animation: cycle 15s 5s infinite linear;
  -moz-animation: cycle 15s 5s infinite linear;
  -o-animation: cycle 15s 5s infinite linear;
  animation: cycle 15s 5s infinite linear;
}

.news_Area:nth-child(3) {
  -webkit-animation: cycle 15s 10s infinite linear;
  -moz-animation: cycle 15s 10s infinite linear;
  -o-animation: cycle 15s 10s infinite linear;
  animation: cycle 15s 10s infinite linear;
}

@keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-moz-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-webkit-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-ms-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-o-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="page_Wrap">

  <header>
    <div id="head_Logo">
    </div>
    <!-- end of #head_Logo -->

    <div id="head_Area">

      <div class="wrap_News">
        <div class="news_Area">
          <div class="news_Text">This is top secret.  Read more</div>
        </div>
        <!-- end of #news_Area -->
        <div class="news_Area">
          <div class="news_Text">
            This is to see what happens if a lot of text is placed here and is just blah blah blah blah blah blah.
          </div>
          <!-- end of #wrap_News -->
        </div>
        <!-- end of #news_Area -->
        <div class="news_Area">
          <div class="news_Text">Part 3 here</div>
        </div>
        <!-- end of #news_Area -->
      </div>
      <!-- end of #wrap_News -->

    </div>
    <!-- end of #head_Area -->
    <div id="head_Note">
      <!--  HERE  -->
    </div>
    <!-- end of #head_Note -->
  </header>
  <!-- end of #header -->

</div>
<!-- end of #page_Wrap --></code>```

Body:
I recently changed my news ticker to a CSS version.  My problem is the I am trying to use the "text-overflow: ellipsis" and it just is not working.  I have tried placing the styles everywhere without success.  Can anyone help me?  I have created a basic codepen.  The class in GREEN is my problem.

https://codepen.io/lepew/pen/pdwNaL

body {
  background-color: black;
}

#page_Wrap {
  /* Flexbox setup */
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  xflex-flow: column nowrap;
  -webkit-flex-flow: column;
  -moz-flex-flow: column;
  -ms-flex-flow: column;
  flex-flow: column;
  /* Basic styling */
  width: 94%;
  margin: 0 auto;
  max-width: 1280px;
  border: 1px solid red;
}

header {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-flex: 0;
  -moz-box-flex: 0;
  -ms-flex: 0;
  -webkit-flex: 0;
  flex: 0;
  min-height: 100px;
}

#head_Logo,
#head_Note {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 77px;
  flex: 0 0 77px;
  width: 77px;
  height: 90px;
  border: 1px solid yellow;
}

#head_Area {
  -webkit-box-flex: 2;
  -ms-flex: 2;
  flex: 2;
  -webkit-flex-flow: column nowrap;
  -moz-flex-flow: column nowrap;
  -ms-flex-flow: column nowrap;
  flex-flow: column nowrap;
  min-width: 0;
}

.wrap_News {
  height: 45px;
  border: 1px solid lime;
}

.news_Area {
  color: #0FF;
  position: absolute;
  overflow: hidden;
  xmargin-right: 115px;
  xright: 0;
  xleft: 116px;
  opacity: 0;
  -moz-opacity: 0;
  filter: alpha(opacity=0);
}

.news_Text {
  padding: 0 5px;
  font: bold 18px Arial, Helvetica, sans-serif;
  height: 45px;
  overflow: hidden;
  line-height: 45px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.wrap_News:hover .news_Area {
  -webkit-animation-play-state: paused;
  -moz-animation-play-state: paused;
  -o-animation-play-state: paused;
  animation-play-state: paused;
}

.news_Area:nth-child(1) {
  -webkit-animation: cycle 15s 0s infinite linear;
  -moz-animation: cycle 15s 0s infinite linear;
  -o-animation: cycle 15s 0s infinite linear;
  animation: cycle 15s 0s infinite linear;
}

.news_Area:nth-child(2) {
  -webkit-animation: cycle 15s 5s infinite linear;
  -moz-animation: cycle 15s 5s infinite linear;
  -o-animation: cycle 15s 5s infinite linear;
  animation: cycle 15s 5s infinite linear;
}

.news_Area:nth-child(3) {
  -webkit-animation: cycle 15s 10s infinite linear;
  -moz-animation: cycle 15s 10s infinite linear;
  -o-animation: cycle 15s 10s infinite linear;
  animation: cycle 15s 10s infinite linear;
}

@keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-moz-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-webkit-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-ms-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-o-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

This is top secret.  Read more

            This is to see what happens if a lot of text is placed here and is just blah blah blah blah blah blah.

Part 3 here

Body:
You need to set a width or a max-width to have an efficient text-overflow and also set the direct parent in position:relative; so it is the reference to calculate the space where stand those absolute children.

body {
  background-color: black;
}

#page_Wrap {
  /* Flexbox setup */
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  xflex-flow: column nowrap;
  -webkit-flex-flow: column;
  -moz-flex-flow: column;
  -ms-flex-flow: column;
  flex-flow: column;
  /* Basic styling */
  width: 94%;
  margin: 0 auto;
  max-width: 1280px;
  border: 1px solid red;
}

header {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-flex: 0;
  -moz-box-flex: 0;
  -ms-flex: 0;
  -webkit-flex: 0;
  flex: 0;
  min-height: 100px;
}

#head_Logo,
#head_Note {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 77px;
  flex: 0 0 77px;
  width: 77px;
  height: 90px;
  border: 1px solid yellow;
}

#head_Area {
  -webkit-box-flex: 2;
  -ms-flex: 2;
  flex: 2;
  -webkit-flex-flow: column nowrap;
  -moz-flex-flow: column nowrap;
  -ms-flex-flow: column nowrap;
  flex-flow: column nowrap;
  min-width: 0;
  position:relative;/*update*/
}

.wrap_News {
  height: 45px;
  border: 1px solid lime;
}

.news_Area {
  color: #0FF;
  opacity: 0;
  -moz-opacity: 0;
  filter: alpha(opacity=0);
}

.news_Text {
  position:absolute;
  padding: 0 5px;
  font: bold 18px Arial, Helvetica, sans-serif;
  height: 45px;
  overflow: hidden;
  line-height: 45px;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width:100%;/*update*/
}

.wrap_News:hover .news_Area {
  -webkit-animation-play-state: paused;
  -moz-animation-play-state: paused;
  -o-animation-play-state: paused;
  animation-play-state: paused;
}

.news_Area:nth-child(1) {
  -webkit-animation: cycle 15s 0s infinite linear;
  -moz-animation: cycle 15s 0s infinite linear;
  -o-animation: cycle 15s 0s infinite linear;
  animation: cycle 15s 0s infinite linear;
}

.news_Area:nth-child(2) {
  -webkit-animation: cycle 15s 5s infinite linear;
  -moz-animation: cycle 15s 5s infinite linear;
  -o-animation: cycle 15s 5s infinite linear;
  animation: cycle 15s 5s infinite linear;
}

.news_Area:nth-child(3) {
  -webkit-animation: cycle 15s 10s infinite linear;
  -moz-animation: cycle 15s 10s infinite linear;
  -o-animation: cycle 15s 10s infinite linear;
  animation: cycle 15s 10s infinite linear;
}

@keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-moz-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-webkit-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-ms-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

@-o-keyframes cycle {
  0% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  2% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  31% {
    filter: alpha(opacity=100);
    opacity: 1;
  }
  33% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
  100% {
    filter: alpha(opacity=0);
    opacity: 0;
  }
}

<div id="page_Wrap">

  <header>
    <div id="head_Logo">
    </div>
    <!-- end of #head_Logo -->

    <div id="head_Area">

      <div class="wrap_News">
        <div class="news_Area">
          <div class="news_Text">This is top secret.&nbsp;&nbsp;<a href="#">Read more</a></div>
        </div>
        <!-- end of #news_Area -->
        <div class="news_Area">
          <div class="news_Text">
            This is to see what happens if a lot of text is placed here and is just blah blah blah blah blah blah.
          </div>
          <!-- end of #wrap_News -->
        </div>
        <!-- end of #news_Area -->
        <div class="news_Area">
          <div class="news_Text">Part 3 here</div>
        </div>
        <!-- end of #news_Area -->
      </div>
      <!-- end of #wrap_News -->

    </div>
    <!-- end of #head_Area -->
    <div id="head_Note">
      <!--  HERE  -->
    </div>
    <!-- end of #head_Note -->
  </header>
  <!-- end of #header -->

</div>
<!-- end of #page_Wrap -->


来源: stackexchange

问:
How to run a Java program (distributed as a Windows exe) under Linux?
I have a very simple JAVA app that is distributed as a single Windows executable file and I would like to run it on a Linux computer. I could extract the content of the exe file with 7-zip, but I don't know what to do next.

There are multiple levels of subfolders with .class files and image files for the software's user interface (no source files).

The root folder doesn't contain any class files, but it contains many subfolders, including a META-INF subfolder. This META-INF folder contains one MANIFEST.MF file, in which there is a line like this:
Main-Class: subfolder1.subfolder2.Software

How can I make it run? Is there a way to run it on a Linux computer's JVM?

答:
You likely cannot do what you are looking to do using the .exe as that is a program that was compiled specifically for Windows. To get it to run on Linux, you would either have to recompile it to a runnable file on Linux, or make it a jar file. </p>

<p>Making it a .jar file would allow it to run on any machine that has a Java Virtual Machine installed on it and would allow your program to be platform independent. </p>

ContentLicense: CC BY-SA 3.0

Body:
You likely cannot do what you are looking to do using the .exe as that is a program that was compiled specifically for Windows. To get it to run on Linux, you would either have to recompile it to a runnable file on Linux, or make it a jar file.

Making it a .jar file would allow it to run on any machine that has a Java Virtual Machine installed on it and would allow your program to be platform independent.


问:
VNImageRequestHandler init with pixels data
I would like to use a VNImageRequestHandler with raw pixels data. The method initWithData:options: of VNImageRequestHandler is not documented, and I can't find any example using this. What is the accepted format, and what is this "options" parameter ?

Apple documentation (empty) page : https://developer.apple.com/documentation/vision/vnimagerequesthandler/2866551-initwithdata?language=objc

答: Note that a CVPixelBuffer is basically a wrapper around raw pixel data. You can easily create one that points at your own pixel data using CVPixelBufferCreateWithBytes().


问:
Castle Windsor - Register component for eventhandler
I am new to IoC and especially Castle Windsor. I'm trying to register component for eventpublisher which look like this:

```<code>  container.Register(Component.For<IEventPublisher>().ImplementedBy<EventPublisher>());
</code>```

I'm sure that the container register code above is correct, but I get another error message which says:

Can't create component 'Network.Infrastructure.Event.EventPublisher' as it has dependencies to be satisfied.'Network.Infrastructure.Event.EventPublisher' is waiting for the following dependencies:- Service 'System.Collections.Generic.IEnumerable`1[[Network.Infrastructure.Event.IEventListener, Network.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.

I have also tried to register IEventListener, but with no luck.

ArticleService.cs

```<code>   public class ArticleService : IArticleService
{
    private readonly IArticleRepository _articleRpRepository;
    private readonly IUnitOfWork _unitOfWork;

    **Declaring the field for IEventPublisher**
    private readonly IEventPublisher _eventPublisher;

    public ArticleService(IArticleRepository articleRpRepository, IUnitOfWork unitOfWork, IEventPublisher eventListener)
    {
        _articleRpRepository = articleRpRepository;
        _eventPublisher = eventListener;
        _unitOfWork = unitOfWork;
    }

    public Article CreateArticle(Article article)
    {
            **Using the publish from eventpublish class**
            _eventPublisher.Publish(new MyEvent { Message = "Something is done" });

            article.Created = DateTime.Now;
            _articleRpRepository.Add(article);
            SaveChanges();

            return article;
        }

    }
</code>```

EventPublisher.cs

```<code>  public class EventPublisher : IEventPublisher
    {

   private readonly IEnumerable<IEventListener> _listeners;

   public EventPublisher(IEnumerable<IEventListener> listeners)
    {
        _listeners = listeners;
    }

    public void Publish<TPayload>(TPayload payload) where TPayload : class
    {
        var handlersForPayload = _listeners.OfType<IEventListener<TPayload();
        foreach (var handler in handlersForPayload)
        {
            handler.Handle(payload);
        }
    }
}
</code>```

IEventListener.cs

```<code>public interface IEventListener
 {}

public interface IEventListener<in TPayload> : IEventListener where TPayload : class
{

    void Handle(TPayload payload);
}
</code>```

答:
You need to add CollectionResolver to the container and than register your listeners.

```<code>container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));
</code>```

More info about resolvers here:

https://github.com/castleproject/Windsor/blob/master/docs/resolvers.md

Body:
I am new to IoC and especially Castle Windsor. I'm trying to register component for eventpublisher which look like this:

  container.Register(Component.For<IEventPublisher>().ImplementedBy<EventPublisher>());

I'm sure that the container register code above is correct, but I get another error message which says:

Can't create component 'Network.Infrastructure.Event.EventPublisher' as it has dependencies to be satisfied.'Network.Infrastructure.Event.EventPublisher' is waiting for the following dependencies:- Service 'System.Collections.Generic.IEnumerable`1[[Network.Infrastructure.Event.IEventListener, Network.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.

I have also tried to register IEventListener, but with no luck.

ArticleService.cs

   public class ArticleService : IArticleService
{
    private readonly IArticleRepository _articleRpRepository;
    private readonly IUnitOfWork _unitOfWork;

    **Declaring the field for IEventPublisher**
    private readonly IEventPublisher _eventPublisher;

    public ArticleService(IArticleRepository articleRpRepository, IUnitOfWork unitOfWork, IEventPublisher eventListener)
    {
        _articleRpRepository = articleRpRepository;
        _eventPublisher = eventListener;
        _unitOfWork = unitOfWork;
    }

    public Article CreateArticle(Article article)
    {
            **Using the publish from eventpublish class**
            _eventPublisher.Publish(new MyEvent { Message = "Something is done" });

            article.Created = DateTime.Now;
            _articleRpRepository.Add(article);
            SaveChanges();

            return article;
        }

    }

EventPublisher.cs

  public class EventPublisher : IEventPublisher
    {

   private readonly IEnumerable<IEventListener> _listeners;

   public EventPublisher(IEnumerable<IEventListener> listeners)
    {
        _listeners = listeners;
    }

    public void Publish<TPayload>(TPayload payload) where TPayload : class
    {
        var handlersForPayload = _listeners.OfType<IEventListener<TPayload();
        foreach (var handler in handlersForPayload)
        {
            handler.Handle(payload);
        }
    }
}

IEventListener.cs

public interface IEventListener
 {}

public interface IEventListener<in TPayload> : IEventListener where TPayload : class
{

    void Handle(TPayload payload);
}

Body:
You need to add CollectionResolver to the container and than register your listeners.

container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));

More info about resolvers here:

https://github.com/castleproject/Windsor/blob/master/docs/resolvers.md


问:
How to apply

 tags to a text field
I've got a varchar() field in SQL Server that has some carriage return/linefeeds between paragraph marks.

I'd like to turn it into properly formatted HTML.

For instance:

---------- before ----------

The quick brown fox jumped over the lazy dog.  Then he got bored and went to bed.  After that, he played with his friends.

The next day, he and his friends had a big party.

---------- after -----------

The quick brown fox jumped over the lazy dog.  Then he got bored and went to bed.  After that, he played with his friends.

The next day, he and his friends had a big party.

What's the right way to do this?  Obviously regular expressions would be a good way to go, but I can't figure out how to trap the beginning of field along with the crlf (carriage return/linefeed) combo in a sane way.

Any regex geniuses out there?  Would love some help.  Thanks if so!

答:
If the string initially comes from user input so that you don't have total control over it, you have to properly html encode it before putting the paragraph tags in</p>

```<code>yourString="p" + text.Replace("\r\n","<p></p>") + "</p>";
</code>```

OwnerDisplayName: Steve Murch

LastEditorDisplayName: MarkusQ

ContentLicense: CC BY-SA 2.5

Title:
How to apply

 tags to a text field

Body:
If the string initially comes from user input so that you don't have total control over it, you have to properly html encode it before putting the paragraph tags in

yourString="p" + text.Replace("\r\n","<p></p>") + "</p>";


问:
php curl access unknown url ,Why curl_exec no return false,echo should output failed

curl access unknown url,Why curl_exec return true.It should output failed.

答:
you probably use a shitty DNS that doesn't actually return NXDOMAIN for non-existing domains, but redirects you to some shitty ads-server instead. DNS's doing this includes OpenDNS, Freenom DNS, and some DNSs set by viruses, iirc.

try doing

```<code>curl_setopt_array($ch,array(CURLOPT_DNS_LOCAL_IP4=>'8.8.8.8',CURLOPT_DNS_LOCAL_IP6=>'2001:4860:4860:0:0:0:0:8888'));
</code>```

first. this should force curl to use GoogleDNS, which doesn't do shit like that.

but note that these flags were first added to PHP in version 7.0.7

Body:
you probably use a shitty DNS that doesn't actually return NXDOMAIN for non-existing domains, but redirects you to some shitty ads-server instead. DNS's doing this includes OpenDNS, Freenom DNS, and some DNSs set by viruses, iirc.

try doing

curl_setopt_array($ch,array(CURLOPT_DNS_LOCAL_IP4=>'8.8.8.8',CURLOPT_DNS_LOCAL_IP6=>'2001:4860:4860:0:0:0:0:8888'));

first. this should force curl to use GoogleDNS, which doesn't do shit like that.

but note that these flags were first added to PHP in version 7.0.7


问:
C Program Crashing when Reallocing One Element Larger (2x)
I am a beginner to C and am trying to learn dynamic memory allocation in the simplest way - I have a program that manages student records and I have a few problems with it that I cannot for the life of me figure out even after hours and hours of googleing/stackoverflowing -- Here is what this program is to accomplish:

Take in student records

Add and Delete Records ( THESE ARE THE COMMANDS THAT DO NOT WORK)

Sort student records

Find a few extra values from these records

Here is what happens to create this error as found in GDB debugger (the problem comes with the addRecord function and the freeMemory function):

```<code>    *** Error in `/home/a.out': realloc(): invalid next size:
    0x0000000000c42060 ***
    Aborted
</code>```

And when compiled with GCC and ran outside of the GDB debugger it will just seg fault.

This only happens when I do these set of options in the program:

1) ADD A RECORD

2) DELETE A RECORD

3) ADD A RECORD ( THEN CRASHES )

or

1) ADD A RECORD

2) ADD A RECORD ( THEN CRASHES )

I'm not sure whats causing this and I have no idea how to fix it, can anyone help direct me in the right direction? I've tried adding a free after the realloc success in the freeMemory function but to no avail this then causes the program to crash upon deletion of an added record.

Here is the code:

```<code>    #include <stdio.h>
#include <stdlib.h>

// Declare functions:
void printMenu();
void printRecords(char** fn, char** ln, float* s);
void addRecord(char** fn, char** ln, float* s);
void deleteRecord(char** fn, char** ln, float* s);
int freeMemory(char** fn, char** ln, float* s, char* n, int matches);
int findName(char** ln,char* n);

static int records; // global records variable

int main(){
    int i, j;
    int choice;
    int option = -1;

    printf("WELCOME TO THE STUDENT RECORD MANAGER 100 V 1.0! \n");
    printf("Please indicate the number of student records you want to enter (min 5, max 15): \n");
    scanf("%d",&records);

    if(records < 5 || records > 15){
        printf("You must enter more than five and less than 15... terminating. \n");
        return 0;
    }

    // Declare arrays
    char** firstNames;
    char** lastNames;
    float* scores;

    // Declare variables
    char* search = malloc(64);

    firstNames  =   malloc(records*sizeof(*firstNames));
    lastNames   =   malloc(records*sizeof(*lastNames));
    scores      =   malloc(records*sizeof(float));

    printf("Please enter the records now (ex. firstName lastName score ENTER):\n");
    // Gather Records
    for(i = 0; i < records; i ++){
        printf("%d ",i+1);
        firstNames[i] = malloc(254 * sizeof(char));
        lastNames[i] = malloc(254 * sizeof(char));
        //scores[i] = malloc(sizeof(float));
        scanf("%s %s %f",firstNames[i], lastNames[i], &scores[i]);
    }

    // Generate menu and do actions
    do{
        printMenu();
        scanf("%d",&choice);

        switch(choice){
            case 1:
                printRecords(firstNames, lastNames, scores);
                break;
            case 2:
                addRecord(firstNames, lastNames, scores);
                break;
            case 3:
                deleteRecord(firstNames, lastNames, scores);
                break;
            case 0:
                return 0;
        }
    }
    while(1);
    return 0;
}

// Print user menu
void printMenu(){
    printf("\tMain Menu\t\n"
        "============================\n"
        " > Print records (press 1) \n"
        " > Add a new record (press 2) \n"
        " > Delete a record (press 3) \n"
        " > Exit the program (press 0)\n"
        "============================\n"
        "Please select an option: ");
}

// Print all user records
void printRecords(char** fn, char** ln, float* s){
    int i;
    printf("THERE ARE %d RECORDS \n",records);
    for(i=0;i<records;i++)
        printf("(%d) First name: %s | Last name: %s | Score: %0.2f \n",i,fn[i],ln[i],s[i]); // will start at the first item and go i amount in the index
}

// Add user record
void addRecord(char** fn, char**ln, float* s){
    char** tempPtr;
    float* tempFPtr;
    printf("Please input the values that you'd like to add (ex. firstName lastName score ENTER): \n");
    if(records+1 < 15){ // if the array is not larger than maximum value when we make it larger

        // lets reallocate the arrays
        tempPtr = realloc(fn, (records+1)*sizeof(*fn));
        if(tempPtr){
            printf("ALLOCATION successfully");
            fn = tempPtr;
        }
        else{
            printf("FAILED");
            // Realloc Failed
        }
        tempPtr = realloc(ln, (records+1)*sizeof(*ln));
        if(tempPtr){
            printf("ALLOCATION successfully");
            ln = tempPtr;
        }
        else{
            printf("FAILED");
            // Realloc Failed
        }
        /*tempFPtr = realloc(s, records+1*sizeof(float));
        if(tempFPtr){
            s = tempFPtr;
        }*/
        printf("There are now %d items.. \n", records);
        fn[records] = malloc(64); // in the LAST value of all arrays
        ln[records] = malloc(64);
        scanf("%s %s %f",fn[records], ln[records], &s[records]);
        printf("(%d) > ADDED -> First name: %s | Last name: %s | Score: %0.2f \n",records,fn[records],ln[records],s[records]);
        int i;
        records++; // increment by one
        printf("There are now %d items.. \n", records);
        printf(" > Record successfully added.\n");
    }
    else{
        printf(" > You have hit the max amount of records allowed for this program (15).\n");
    }

}

// Delete all instances of user record by (last Name)
void deleteRecord(char** fn, char**ln, float* s){
    char* lastName = malloc(32 * sizeof(char*));
    printf("What is the last name of the student you would like to delete? \n");
    scanf("%s", lastName);

    // searching for that record
    int matches = findName(ln, lastName);
    if(matches && records-matches > 4){ // this means it doesn't go below minimum 5
        if(freeMemory(fn, ln, s, lastName, matches)){
            printf(" > Record successfully deleted.\n");
            free(lastName);
        }
    }
    else{
        printf(" > Either no matches were found or deleting this value would put the number of records at less than 5. \n");
    }

}

// Extension of deleteRecord that does duplication to push 'delete' lastName to the end, then reallocates array to cut it off the end
int freeMemory(char** fn, char** ln, float* s, char* n, int matches){
    int i,j;

    /* LOGIC:
        - REALLOCATE ARRAY BY X LESS SIZE AFTER PUSHING THE VALUES TO BE REMOVED TO THE END
        - NEED TO DO THIS FOR THREE ARRAYS
        - TO REMOVE:
            - RUN THROUGH X AMOUNT OF TIMES PUSHING EACH SPECIFIC REMOVAL VALUE (IE) 1st found match
            - TO THE END
            SHIFT
                - FOUND 1st MATCH
                - MATCH = MATCH + 1
                - MATCH + ! = MATCH + 2
                - ETC UNTIL YOU HAVE A DUPLICATE AT THE END, THEN REALLOCATE BY 1 LESS
    */
    char** tempPtr = NULL;
    float* tempFPtr = NULL;
    for(i=0;i<matches;i++){ // gonna go through as many times as matches
        int match = 0;
        // let's make sure the name isn't on the end of the array before we do all this junk
        if(strcmp(n,*(ln+records-1)) == 0){
            printf("FN");
            tempPtr = realloc(fn, (records-1)*sizeof(*fn));
            if(tempPtr){
                fn = tempPtr;
                printf("FN PASSED");
                //free(fn[records]);
            }
            else{
                // Realloc Failed
                printf("FN FAILED");
            }
            printf("LN");
            tempPtr = realloc(ln, (records-1)*sizeof(*ln));
            if(tempPtr){
                ln = tempPtr;
                printf("LN PASSED");
                //free(ln[records]);
            }
            else{
                printf("LN FAILED");
                // Realloc Failed
            }

            records--;
        }
        else{
            // lets find the first match by going through each last name
            for(j=0;j<records-1;j++){
                // Lets find first match
                if(strcmp(n,ln[j]) == 0){ // accessing index
                    // lets start copying
                    *(ln+j) = *(ln+j+1);
                    *(fn+j) = *(fn+j+1);
                    *(s+j)  = *(s+j+1);
                    match = 1;
                }
                else if(match){
                    // already copied first val so lets start copying the rest until we get to the end.
                    *(ln+j) = *(ln+j+1);
                    *(fn+j) = *(fn+j+1);
                    *(s+j)  = *(s+j+1);
                }

            }
            printf("FN");
            tempPtr = realloc(fn, (records-1)*sizeof(*fn));
            if(tempPtr){
                fn = tempPtr;
                printf("FN PASSED");
                //free(fn[records]);
            }
            else{
                // Realloc Failed
                printf("FN FAILED");
            }
            printf("LN");
            tempPtr = realloc(ln, (records-1)*sizeof(*ln));
            if(tempPtr){
                ln = tempPtr;
                printf("LN PASSED");
                //free(ln[records]);
            }
            else{
                printf("LN FAILED");
                // Realloc Failed
            }

            /*tempFPtr = realloc(s, records-1*sizeof(float));
            if(tempFPtr){
                s = tempFPtr;
                printf("S PASSED");
            }
            else{
                printf("s FAILED ");
            }*/

            records--;
            match = 0;
        }
    }
    return 1;
}

// Finds how many instances of a last name are present
int findName(char** ln,char* n){
    int i, counter=0;

    for(i=0;i<records-1;i++){
        if(strcmp(n,*(ln+i)) == 0){
            counter++;
        }
    }
    return counter;
}
</code>```

答:
The error appears to be in your function addRecord. You have the expression

```<code>tempPtr = safe_trim(ln, records+1*sizeof(*ln));
</code>```

Which is giving a size of records + (sizeof (*ln)) because of C operator precedence. Multiplication comes before addition. The line should be changed to:

```<code>tempPtr = safe_trim(ln, (records + 1) * sizeof(*ln));
</code>```

Also because safe_trim always return a valid pointer, either the original or the resized, this check

```<code>tempPtr = safe_trim(fn, records+1*sizeof(*fn));
if(tempPtr){
    printf("ALLOCATION successfully");
    fn = tempPtr;
}
else{
    printf("FAILED");
    // Realloc Failed
}
</code>```

will never follow the else branch and won't handle allocation failures. Replacing calls to safe_trim with realloc shouldn't have any affect on the program except to allow detecting allocation failures.

Body:
I am a beginner to C and am trying to learn dynamic memory allocation in the simplest way - I have a program that manages student records and I have a few problems with it that I cannot for the life of me figure out even after hours and hours of googleing/stackoverflowing -- Here is what this program is to accomplish:

Take in student records

Add and Delete Records ( THESE ARE THE COMMANDS THAT DO NOT WORK)

Sort student records

Find a few extra values from these records

Here is what happens to create this error as found in GDB debugger (the problem comes with the addRecord function and the freeMemory function):

    *** Error in `/home/a.out': realloc(): invalid next size:
    0x0000000000c42060 ***
    Aborted

And when compiled with GCC and ran outside of the GDB debugger it will just seg fault.

This only happens when I do these set of options in the program:

1) ADD A RECORD

2) DELETE A RECORD

3) ADD A RECORD ( THEN CRASHES )

or

1) ADD A RECORD

2) ADD A RECORD ( THEN CRASHES )

I'm not sure whats causing this and I have no idea how to fix it, can anyone help direct me in the right direction? I've tried adding a free after the realloc success in the freeMemory function but to no avail this then causes the program to crash upon deletion of an added record.

Here is the code:

    #include <stdio.h>
#include <stdlib.h>

// Declare functions:
void printMenu();
void printRecords(char** fn, char** ln, float* s);
void addRecord(char** fn, char** ln, float* s);
void deleteRecord(char** fn, char** ln, float* s);
int freeMemory(char** fn, char** ln, float* s, char* n, int matches);
int findName(char** ln,char* n);

static int records; // global records variable

int main(){
    int i, j;
    int choice;
    int option = -1;

    printf("WELCOME TO THE STUDENT RECORD MANAGER 100 V 1.0! \n");
    printf("Please indicate the number of student records you want to enter (min 5, max 15): \n");
    scanf("%d",&records);

    if(records < 5 || records > 15){
        printf("You must enter more than five and less than 15... terminating. \n");
        return 0;
    }

    // Declare arrays
    char** firstNames;
    char** lastNames;
    float* scores;

    // Declare variables
    char* search = malloc(64);

    firstNames  =   malloc(records*sizeof(*firstNames));
    lastNames   =   malloc(records*sizeof(*lastNames));
    scores      =   malloc(records*sizeof(float));

    printf("Please enter the records now (ex. firstName lastName score ENTER):\n");
    // Gather Records
    for(i = 0; i < records; i ++){
        printf("%d ",i+1);
        firstNames[i] = malloc(254 * sizeof(char));
        lastNames[i] = malloc(254 * sizeof(char));
        //scores[i] = malloc(sizeof(float));
        scanf("%s %s %f",firstNames[i], lastNames[i], &scores[i]);
    }

    // Generate menu and do actions
    do{
        printMenu();
        scanf("%d",&choice);

        switch(choice){
            case 1:
                printRecords(firstNames, lastNames, scores);
                break;
            case 2:
                addRecord(firstNames, lastNames, scores);
                break;
            case 3:
                deleteRecord(firstNames, lastNames, scores);
                break;
            case 0:
                return 0;
        }
    }
    while(1);
    return 0;
}

// Print user menu
void printMenu(){
    printf("\tMain Menu\t\n"
        "============================\n"
        " > Print records (press 1) \n"
        " > Add a new record (press 2) \n"
        " > Delete a record (press 3) \n"
        " > Exit the program (press 0)\n"
        "============================\n"
        "Please select an option: ");
}

// Print all user records
void printRecords(char** fn, char** ln, float* s){
    int i;
    printf("THERE ARE %d RECORDS \n",records);
    for(i=0;i<records;i++)
        printf("(%d) First name: %s | Last name: %s | Score: %0.2f \n",i,fn[i],ln[i],s[i]); // will start at the first item and go i amount in the index
}

// Add user record
void addRecord(char** fn, char**ln, float* s){
    char** tempPtr;
    float* tempFPtr;
    printf("Please input the values that you'd like to add (ex. firstName lastName score ENTER): \n");
    if(records+1 < 15){ // if the array is not larger than maximum value when we make it larger

        // lets reallocate the arrays
        tempPtr = realloc(fn, (records+1)*sizeof(*fn));
        if(tempPtr){
            printf("ALLOCATION successfully");
            fn = tempPtr;
        }
        else{
            printf("FAILED");
            // Realloc Failed
        }
        tempPtr = realloc(ln, (records+1)*sizeof(*ln));
        if(tempPtr){
            printf("ALLOCATION successfully");
            ln = tempPtr;
        }
        else{
            printf("FAILED");
            // Realloc Failed
        }
        /*tempFPtr = realloc(s, records+1*sizeof(float));
        if(tempFPtr){
            s = tempFPtr;
        }*/
        printf("There are now %d items.. \n", records);
        fn[records] = malloc(64); // in the LAST value of all arrays
        ln[records] = malloc(64);
        scanf("%s %s %f",fn[records], ln[records], &s[records]);
        printf("(%d) > ADDED -> First name: %s | Last name: %s | Score: %0.2f \n",records,fn[records],ln[records],s[records]);
        int i;
        records++; // increment by one
        printf("There are now %d items.. \n", records);
        printf(" > Record successfully added.\n");
    }
    else{
        printf(" > You have hit the max amount of records allowed for this program (15).\n");
    }

}

// Delete all instances of user record by (last Name)
void deleteRecord(char** fn, char**ln, float* s){
    char* lastName = malloc(32 * sizeof(char*));
    printf("What is the last name of the student you would like to delete? \n");
    scanf("%s", lastName);

    // searching for that record
    int matches = findName(ln, lastName);
    if(matches && records-matches > 4){ // this means it doesn't go below minimum 5
        if(freeMemory(fn, ln, s, lastName, matches)){
            printf(" > Record successfully deleted.\n");
            free(lastName);
        }
    }
    else{
        printf(" > Either no matches were found or deleting this value would put the number of records at less than 5. \n");
    }

}

// Extension of deleteRecord that does duplication to push 'delete' lastName to the end, then reallocates array to cut it off the end
int freeMemory(char** fn, char** ln, float* s, char* n, int matches){
    int i,j;

    /* LOGIC:
        - REALLOCATE ARRAY BY X LESS SIZE AFTER PUSHING THE VALUES TO BE REMOVED TO THE END
        - NEED TO DO THIS FOR THREE ARRAYS
        - TO REMOVE:
            - RUN THROUGH X AMOUNT OF TIMES PUSHING EACH SPECIFIC REMOVAL VALUE (IE) 1st found match
            - TO THE END
            SHIFT
                - FOUND 1st MATCH
                - MATCH = MATCH + 1
                - MATCH + ! = MATCH + 2
                - ETC UNTIL YOU HAVE A DUPLICATE AT THE END, THEN REALLOCATE BY 1 LESS
    */
    char** tempPtr = NULL;
    float* tempFPtr = NULL;
    for(i=0;i<matches;i++){ // gonna go through as many times as matches
        int match = 0;
        // let's make sure the name isn't on the end of the array before we do all this junk
        if(strcmp(n,*(ln+records-1)) == 0){
            printf("FN");
            tempPtr = realloc(fn, (records-1)*sizeof(*fn));
            if(tempPtr){
                fn = tempPtr;
                printf("FN PASSED");
                //free(fn[records]);
            }
            else{
                // Realloc Failed
                printf("FN FAILED");
            }
            printf("LN");
            tempPtr = realloc(ln, (records-1)*sizeof(*ln));
            if(tempPtr){
                ln = tempPtr;
                printf("LN PASSED");
                //free(ln[records]);
            }
            else{
                printf("LN FAILED");
                // Realloc Failed
            }

            records--;
        }
        else{
            // lets find the first match by going through each last name
            for(j=0;j<records-1;j++){
                // Lets find first match
                if(strcmp(n,ln[j]) == 0){ // accessing index
                    // lets start copying
                    *(ln+j) = *(ln+j+1);
                    *(fn+j) = *(fn+j+1);
                    *(s+j)  = *(s+j+1);
                    match = 1;
                }
                else if(match){
                    // already copied first val so lets start copying the rest until we get to the end.
                    *(ln+j) = *(ln+j+1);
                    *(fn+j) = *(fn+j+1);
                    *(s+j)  = *(s+j+1);
                }

            }
            printf("FN");
            tempPtr = realloc(fn, (records-1)*sizeof(*fn));
            if(tempPtr){
                fn = tempPtr;
                printf("FN PASSED");
                //free(fn[records]);
            }
            else{
                // Realloc Failed
                printf("FN FAILED");
            }
            printf("LN");
            tempPtr = realloc(ln, (records-1)*sizeof(*ln));
            if(tempPtr){
                ln = tempPtr;
                printf("LN PASSED");
                //free(ln[records]);
            }
            else{
                printf("LN FAILED");
                // Realloc Failed
            }

            /*tempFPtr = realloc(s, records-1*sizeof(float));
            if(tempFPtr){
                s = tempFPtr;
                printf("S PASSED");
            }
            else{
                printf("s FAILED ");
            }*/

            records--;
            match = 0;
        }
    }
    return 1;
}

// Finds how many instances of a last name are present
int findName(char** ln,char* n){
    int i, counter=0;

    for(i=0;i<records-1;i++){
        if(strcmp(n,*(ln+i)) == 0){
            counter++;
        }
    }
    return counter;
}

Body:
The error appears to be in your function addRecord. You have the expression

tempPtr = safe_trim(ln, records+1*sizeof(*ln));

Which is giving a size of records + (sizeof (*ln)) because of C operator precedence. Multiplication comes before addition. The line should be changed to:

tempPtr = safe_trim(ln, (records + 1) * sizeof(*ln));

Also because safe_trim always return a valid pointer, either the original or the resized, this check

tempPtr = safe_trim(fn, records+1*sizeof(*fn));
if(tempPtr){
    printf("ALLOCATION successfully");
    fn = tempPtr;
}
else{
    printf("FAILED");
    // Realloc Failed
}

will never follow the else branch and won't handle allocation failures. Replacing calls to safe_trim with realloc shouldn't have any affect on the program except to allow detecting allocation failures.


问:
How do you reset state when keys are not known? (i.e. dynamic forms)
I'm using es6 syntax setState({[name]: value}) to track dynamically added inputs in form and everything is working fine. I'm wondering about clearing state after form submit. I'll submit my solution but I'd be interested in hearing opinions on a better way of clearing the state, or maybe managing dynamic state shape in general.

According to @DavidL.Walsh (see link below) adding fields to state that were not defined in initial state is wrong. But what about dynamic forms in which you don't know the number of inputs or their names.
https://stackoverflow.com/a/34845925/4634544

答:
fyi, @Rick Jolly's idea is to nest the form state. So initial state would be:
state = { form: {} }

Updating state would look like:
this.setState(prevState => ({ form: { ...prevState.form, [name]: value }
 }))

And resetting state would look like:
this.setState({ form: {} })

Thanks Rick!


问:
How to make a Python list based on another list
I have a master list and then a whole bunch (100s) of sublists cherry-picked from the master list. However, over time items in the master list will be removed. I want to also remove those items from each of the sublists. I imagine having a list that is only pointers to the master list. As the pointer goes stale then the list gets smaller. The sublists are normally in objects not easily accessible at the point where the master list is edited. Is this possible?</p>

```<code>master = ["first","last","middle","top","bottom","left","right","inside"]

sides = []
sides.append(master[2])
sides.append(master[3])
sides.append(master[4])

centre = []
centre.append(master[0])
centre.append(master[2])
centre.append(master[7])

print(master)
['first', 'last', 'middle', 'top', 'bottom', 'left', 'right', 'inside']
print(sides)
['middle', 'top', 'bottom']
print(centre)
['first', 'middle', 'inside']

master.remove("middle")

print(master)
['first', 'last', 'top', 'bottom', 'left', 'right', 'inside']
print(sides) # Ideal outcome
['top', 'bottom']
print(centre) # Ideal outcome
['first', 'inside']
</code>```

答: As modifying lists wasn't possible programatically without an iterative step I think the problem is better answered using a database query rather than a list data structure. Thanks @DeepSpace for a good answer</p>

Body:
I have a master list and then a whole bunch (100s) of sublists cherry-picked from the master list. However, over time items in the master list will be removed. I want to also remove those items from each of the sublists. I imagine having a list that is only pointers to the master list. As the pointer goes stale then the list gets smaller. The sublists are normally in objects not easily accessible at the point where the master list is edited. Is this possible?

master = ["first","last","middle","top","bottom","left","right","inside"]

sides = []
sides.append(master[2])
sides.append(master[3])
sides.append(master[4])

centre = []
centre.append(master[0])
centre.append(master[2])
centre.append(master[7])

print(master)
['first', 'last', 'middle', 'top', 'bottom', 'left', 'right', 'inside']
print(sides)
['middle', 'top', 'bottom']
print(centre)
['first', 'middle', 'inside']

master.remove("middle")

print(master)
['first', 'last', 'top', 'bottom', 'left', 'right', 'inside']
print(sides) # Ideal outcome
['top', 'bottom']
print(centre) # Ideal outcome
['first', 'inside']


问:
Moving texts from one div to another while also changing its background color, font and text color
I've been trying to move the input texts from the first page to the second page with the help of jquery, while also trying making sure that the changes chosen in the first page only show up to the second page after the print button has been pressed but I haven't gotten it to work and I'm wondering what it is that I'm doing wrong.

document.getElementById("page2").style.display = 'none'; // Hide div with name 'page2'
document.getElementById("reset").addEventListener("click", function() {
  // body...
});
document.getElementById("byt1").addEventListener("click", function() {
  document.getElementById("page1").style.display = 'none'; // Hide div with name 'page1'
  document.getElementById("page2").style.display = 'block'; // Show div with name 'page2'
  function changecolor(color) {
    var color = document.getElementById("select_bgcolor").value;
    document.getElementById.style.backgroundColor = select_bgcolor.value;
  }
  // Move text from input field in page 1 to presenting area in page 2
  document.getElementById("area1").innerHTML = document.getElementById("txt1").value;
  document.getElementById("area3").innerHTML = document.getElementById("txt2").value;
  document.getElementById("area2").innerHTML = document.getElementById("txt3").value;
  document.getElementById("area4").innerHTML = document.getElementById("txt4").value;
  document.getElementById("area5").innerHTML = document.getElementById("txt5").value;
  document.getElementById("area6").innerHTML = document.getElementById("txt6").value;
});
document.getElementById("byt2").addEventListener("click", function() {
  document.getElementById("page1").style.display = 'block';
  document.getElementById("page2").style.display = 'none';
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="page1">
  <h2>Order your business card here:</h2>
  <p>
    Company... <input type="text" id="txt1" />
  </p>
  <p>
    Last name... <input type="text" id="txt2" />
  </p>
  <p>
    First name... <input type="text" id="txt3" />
  </p>
  <p>
    Titel... <input type="text" id="txt4" />
  </p>
  <p>
    Telefon... <input type="text" id="txt5" />
  </p>
  <p>
    E-mail... <input type="text" id="txt6" />
  </p>
  <form>
    Background color <select id="select_bgcolor" onchange="byt1">
        <option value="lightblue">Light blue</option>
        <option value="lighyellow">Light yellow</option>
        <option value="white">White</option>
        <option value="turquoise">Turquoise</option>
      </select>
  </form>
  </p>
  <p>
    <form>
      Text color <select id="select_txtcolor" onchange="byt1">
        <option value="black">Black</option>
        <option value="blue">Blue</option>
        <option value="red">Red</option>
        <option value="darkgreen">Dark green</option>
      </select>
    </form>
  </p>
  <p>
    <form>
      font <select id="select_txtfont" onchange="byt1">
        <option value="verdana">Verdana</option>
        <option value="Arial">Arial</option>
        <option value="tahoma">Tahoma</option>
        <option value="impact">Impact</option>
      </select>
    </form>
  </p>
  <p>
    <input type="button" id="reset" value="Reset" />
    <input type="button" id="byt1" value="Print" />
  </p>
</div>

<div id="page2">
  <h2>Page 2</h2>

  <p id="area"></p>
  <input type="button" id="byt2" value="Back to page 1" />
</div></code>```

答:
Here goes a working fiddle : JS Fiddle Link

You have lots of typos in the code.

```<code>document.getElementById("txt").value
</code>```

Should be :

```<code>document.getElementById("txt1").value.
</code>```

Also, I didn't get why the following method has been placed inside the print button click handler and never called inside it :

```<code>function changecolor(color)
{
   var color = document.getElementById("select_bgcolor").value;
   document.getElementById.style.backgroundColor = select_bgcolor.value;
}
</code>```

I removed the method and replaced it with the following :

```<code>document.getElementById("area").style.backgroundColor = document.getElementById("select_bgcolor").value;
</code>```

Again, why is there are onchange events assigned to the select boxes?

```<code><select id="select_txtcolor" onchange="byt1">
</code>```

The Lightyellow color option as well has a typo :
It should be lightyellow instead of lighyellow

```<code><option value="lighyellow">Light yellow</option>
</code>```

Body:
I've been trying to move the input texts from the first page to the second page with the help of jquery, while also trying making sure that the changes chosen in the first page only show up to the second page after the print button has been pressed but I haven't gotten it to work and I'm wondering what it is that I'm doing wrong.

document.getElementById("page2").style.display = 'none'; // Hide div with name 'page2'
document.getElementById("reset").addEventListener("click", function() {
  // body...
});
document.getElementById("byt1").addEventListener("click", function() {
  document.getElementById("page1").style.display = 'none'; // Hide div with name 'page1'
  document.getElementById("page2").style.display = 'block'; // Show div with name 'page2'
  function changecolor(color) {
    var color = document.getElementById("select_bgcolor").value;
    document.getElementById.style.backgroundColor = select_bgcolor.value;
  }
  // Move text from input field in page 1 to presenting area in page 2
  document.getElementById("area1").innerHTML = document.getElementById("txt1").value;
  document.getElementById("area3").innerHTML = document.getElementById("txt2").value;
  document.getElementById("area2").innerHTML = document.getElementById("txt3").value;
  document.getElementById("area4").innerHTML = document.getElementById("txt4").value;
  document.getElementById("area5").innerHTML = document.getElementById("txt5").value;
  document.getElementById("area6").innerHTML = document.getElementById("txt6").value;
});
document.getElementById("byt2").addEventListener("click", function() {
  document.getElementById("page1").style.display = 'block';
  document.getElementById("page2").style.display = 'none';
});

Order your business card here:

    Company... <input type="text" id="txt1" />

    Last name... <input type="text" id="txt2" />

    First name... <input type="text" id="txt3" />

    Titel... <input type="text" id="txt4" />

    Telefon... <input type="text" id="txt5" />

    E-mail... <input type="text" id="txt6" />

  <form>
    Background color <select id="select_bgcolor" onchange="byt1">
        <option value="lightblue">Light blue</option>
        <option value="lighyellow">Light yellow</option>
        <option value="white">White</option>
        <option value="turquoise">Turquoise</option>
      </select>
  </form>

    <form>
      Text color <select id="select_txtcolor" onchange="byt1">
        <option value="black">Black</option>
        <option value="blue">Blue</option>
        <option value="red">Red</option>
        <option value="darkgreen">Dark green</option>
      </select>
    </form>

    <form>
      font <select id="select_txtfont" onchange="byt1">
        <option value="verdana">Verdana</option>
        <option value="Arial">Arial</option>
        <option value="tahoma">Tahoma</option>
        <option value="impact">Impact</option>
      </select>
    </form>

    <input type="button" id="reset" value="Reset" />
    <input type="button" id="byt1" value="Print" />

Page 2

  <input type="button" id="byt2" value="Back to page 1" />

Body:
Here goes a working fiddle : JS Fiddle Link

You have lots of typos in the code.

document.getElementById("txt").value

Should be :

document.getElementById("txt1").value.

Also, I didn't get why the following method has been placed inside the print button click handler and never called inside it :

function changecolor(color)
{
   var color = document.getElementById("select_bgcolor").value;
   document.getElementById.style.backgroundColor = select_bgcolor.value;
}

I removed the method and replaced it with the following :

document.getElementById("area").style.backgroundColor = document.getElementById("select_bgcolor").value;

Again, why is there are onchange events assigned to the select boxes?

<select id="select_txtcolor" onchange="byt1">

The Lightyellow color option as well has a typo :
It should be lightyellow instead of lighyellow

<option value="lighyellow">Light yellow</option>


问:
Is there a keyboard shortcut to multi-select matching strings in MySQL Workbench?
I've been reading MySQL Workbench documentation, and can't find the answer anywhere because I keep searching for "multi-select by string", and since SELECT is a function in MySQL, it's not finding relevant results.

Say I have a SQL file that has multiple statements in it like this:

```<code>SELECT * FROM tbl_example WHERE name = "John" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Martha" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Robert" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Alice" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Emily" AND job = "dev";
</code>```

This is a very simple example - imagine the actual thing could be hundreds of lines.

What I need to do is change every instance of a certain string, in this case, "dev" to "designer". In some IDE's, there is a shortcut to select one instance, and then hit the shortcut key to multi-select more instances as it finds them. In Sublime, on my Mac, this is CMD + D. In PHP/WebStorm, it's Ctrl + G. Is there a way to do this in MySQL Workbench?

I've attached a GIF to show what I'm trying to do.

答:
Seems like you are looking for a "Search and Replace All" function to edit all occurances of a word in a sql script.  I believe you can get to that easily through the text editor menu system, though I don't have a copy of workbench handy.  The keyboard shorcut, as requested orginally, should be listed with the command, I think.

Check out https://dev.mysql.com/doc/workbench/en/wb-keys.html

Body:
I've been reading MySQL Workbench documentation, and can't find the answer anywhere because I keep searching for "multi-select by string", and since SELECT is a function in MySQL, it's not finding relevant results.

Say I have a SQL file that has multiple statements in it like this:

SELECT * FROM tbl_example WHERE name = "John" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Martha" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Robert" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Alice" AND job = "dev";
SELECT * FROM tbl_example WHERE name = "Emily" AND job = "dev";

This is a very simple example - imagine the actual thing could be hundreds of lines.

What I need to do is change every instance of a certain string, in this case, "dev" to "designer". In some IDE's, there is a shortcut to select one instance, and then hit the shortcut key to multi-select more instances as it finds them. In Sublime, on my Mac, this is CMD + D. In PHP/WebStorm, it's Ctrl + G. Is there a way to do this in MySQL Workbench?

I've attached a GIF to show what I'm trying to do.


问:
Application that will connect speak with ADFS via SAML and OAuth
I need to write java application that logs users via ADFS. ADFS can use SAML protocol or OAuth. Is it possible to configure my application to speak via both protocols, depending which protocol is used on the ADFS side? ANDF is I have in my application ~200 ADFS servers, does every ADFS server URL have the same signature as https://adfs.DOMAIN/adfs/ls/idpinitiatedsignon.aspx, so I can unify it only by the domain name, or an ADFS server can have login URL like :
https://domain/adfsLogin.html, so it depends on server configuration?</p>

答:
ADFS 4.0 (Server 2016) can do SAML 2.0, WS-Federation and OpenID Connect / OAuth.

If you want your client to do all three, it needs three client side stacks.

Each ADFS has a federated service name e.g. login-company-adfs/adfs/ls/...

It should not be the domain name or the machine name.

There is no standard for this.


问:
Building Chromium (Ubuntu) - Linker Error
I am trying to build chromium from scratch Checking out and building Chromium on Linux. I am using a virtual machine with 20GB RAM and 150GB HDD running a clean Ubuntu 16.04 LTS.

I am compiling with using the "-finstrument-functions" flag.

However when I try to build I get a wired error message (see below). To me it  looks like a linking problem. But I do not know how to fix it.

```<code>[21/33890] SOLINK ./libcommon.so
FAILED: libcommon.so libcommon.so.TOC
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm" --sofile="./libcommon.so" --tocfile="./libcommon.so.TOC" --output="./libcommon.so"  -- ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--no-as-needed -lpthread -Wl,--as-needed -fuse-ld=lld -Wl,--icf=all -m64 -Werror -Wl,--gdb-index -nostdlib++ --sysroot=../../build/linux/debian_jessie_amd64-sysroot -L../../build/linux/debian_jessie_amd64-sysroot/lib/x86_64-linux-gnu -Wl,-rpath-link=../../build/linux/debian_jessie_amd64-sysroot/lib/x86_64-linux-gnu -L../../build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu -Wl,-rpath-link=../../build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu -o "./libcommon.so" -Wl,-soname="libcommon.so" @"./libcommon.so.rsp"
/home/chromtest/chromium/src/out/Default/../../third_party/llvm-build/Release+Asserts/bin/ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string()
>>> referenced by gcm_messages.cc
>>>               obj/components/gcm_driver/common/common/gcm_messages.o:(gcm::OutgoingMessage::OutgoingMessage())

/home/chromtest/chromium/src/out/Default/../../third_party/llvm-build/Release+Asserts/bin/ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__zero()
>>> referenced by gcm_messages.cc

[... more lines ...]

/home/chromtest/chromium/src/out/Default/../../third_party/llvm-build/Release+Asserts/bin/ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[22/33890] CXX obj/components/keyed_service/core/core/dependency_graph.o
[23/33890] ACTION //components/resources:about_credits(//build/toolchain/linux:clang_x64)
ninja: build stopped: subcommand failed.
</code>```

答:
There are dedicated Chrome build instructions for clang, have you followed those?

https://chromium.googlesource.com/chromium/src/+/master/docs/clang.md

This linking error suggests that the code fails to link against the C++ runtime, which is usually libc++ for clang (as opposed to libstdc++ of gcc). Chrome uses clang by default, so you should have a working clang/libc++ toolchain installed.

Alternatively, you could try building with gcc instead, as explained in the above link.

Body:
I am trying to build chromium from scratch Checking out and building Chromium on Linux. I am using a virtual machine with 20GB RAM and 150GB HDD running a clean Ubuntu 16.04 LTS.

I am compiling with using the "-finstrument-functions" flag.

However when I try to build I get a wired error message (see below). To me it  looks like a linking problem. But I do not know how to fix it.

[21/33890] SOLINK ./libcommon.so
FAILED: libcommon.so libcommon.so.TOC
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm" --sofile="./libcommon.so" --tocfile="./libcommon.so.TOC" --output="./libcommon.so"  -- ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--no-as-needed -lpthread -Wl,--as-needed -fuse-ld=lld -Wl,--icf=all -m64 -Werror -Wl,--gdb-index -nostdlib++ --sysroot=../../build/linux/debian_jessie_amd64-sysroot -L../../build/linux/debian_jessie_amd64-sysroot/lib/x86_64-linux-gnu -Wl,-rpath-link=../../build/linux/debian_jessie_amd64-sysroot/lib/x86_64-linux-gnu -L../../build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu -Wl,-rpath-link=../../build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu -o "./libcommon.so" -Wl,-soname="libcommon.so" @"./libcommon.so.rsp"
/home/chromtest/chromium/src/out/Default/../../third_party/llvm-build/Release+Asserts/bin/ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string()
>>> referenced by gcm_messages.cc
>>>               obj/components/gcm_driver/common/common/gcm_messages.o:(gcm::OutgoingMessage::OutgoingMessage())

/home/chromtest/chromium/src/out/Default/../../third_party/llvm-build/Release+Asserts/bin/ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__zero()
>>> referenced by gcm_messages.cc

[... more lines ...]

/home/chromtest/chromium/src/out/Default/../../third_party/llvm-build/Release+Asserts/bin/ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[22/33890] CXX obj/components/keyed_service/core/core/dependency_graph.o
[23/33890] ACTION //components/resources:about_credits(//build/toolchain/linux:clang_x64)
ninja: build stopped: subcommand failed.


问:
Save toggleClass state of dynamically generated divs and store with Cookie/LocalStorage
I am trying to save my toggleClass state of multiple dynamically generated divs and store them with LocalStorage, so they're available either on page refresh or re-visiting the page. I stuck in the middle of my code and have no more ideas.
Any solutions i found here, will not work, either they refer to a single element or they use a mix of addClass/removeClass and save state.

Saving with Cookie would be an option too.

Html:

```<code><div id="row_parent_41" class="parent">
<div id="page_41">
<span class="showhide" id="more_2"><img src="plus.png" /></span>
</div>

<div id="holder_41" class="child">stuff goes here</div>
</code>```

jQuery:

```<code>var inactiveHolder = localStorage.getItem('child') == 'true';
$(".showhide").on('click', function() {
$(this).closest(".parent").find(".child").slideToggle().toggleClass('inactiveHolder');
$('.child').toggleClass('clicked', inactiveHolder );
return false;
});
</code>```

答:
Does this code work for you?</p>

```<code>var inactiveHolder = localStorage.getItem('child');

// set initial state
if (inactiveHolder == 'true') {
    $('.child').addClass('clicked');
}

// change localstorage and class
$('.showhide').on('click', function() {
    var element = $(this).closest(".parent").find(".child");
    $(element).slideToggle().toggleClass('clicked');
    localstorage.setItem('child', $(element).hasClass('clicked'));
    return false;
});
</code>```

Body:
I am trying to save my toggleClass state of multiple dynamically generated divs and store them with LocalStorage, so they're available either on page refresh or re-visiting the page. I stuck in the middle of my code and have no more ideas.
Any solutions i found here, will not work, either they refer to a single element or they use a mix of addClass/removeClass and save state.

Saving with Cookie would be an option too.

Html:

stuff goes here

jQuery:

var inactiveHolder = localStorage.getItem('child') == 'true';
$(".showhide").on('click', function() {
$(this).closest(".parent").find(".child").slideToggle().toggleClass('inactiveHolder');
$('.child').toggleClass('clicked', inactiveHolder );
return false;
});

Body:
Does this code work for you?

var inactiveHolder = localStorage.getItem('child');

// set initial state
if (inactiveHolder == 'true') {
    $('.child').addClass('clicked');
}

// change localstorage and class
$('.showhide').on('click', function() {
    var element = $(this).closest(".parent").find(".child");
    $(element).slideToggle().toggleClass('clicked');
    localstorage.setItem('child', $(element).hasClass('clicked'));
    return false;
});


问:
How to copy a directory structure but only include certain files (using windows batch files)
As the title says, how can I recursively copy a directory structure but only include some files. E.g given the following directory structure:

```<code>folder1
  folder2
    folder3
      data.zip
      info.txt
      abc.xyz
    folder4
    folder5
      data.zip
      somefile.exe
      someotherfile.dll
</code>```

The files data.zip and info.txt can appear everywhere in the directory structure. How can I copy the full directory structure, but only include files named data.zip and info.txt (all other files should be ignored)?

The resulting directory structure should look like this:

```<code>copy_of_folder1
  folder2
    folder3
      data.zip
      info.txt
    folder4
    folder5
      data.zip
</code>```

答:
```<code>XCOPY /S folder1\data.zip copy_of_folder1
XCOPY /S folder1\info.txt copy_of_folder1
</code>```

EDIT: If you want to preserve the empty folders (which, on rereading your post, you seem to) use /E instead of /S.

OwnerDisplayName: Martin

Body:
As the title says, how can I recursively copy a directory structure but only include some files. E.g given the following directory structure:

folder1
  folder2
    folder3
      data.zip
      info.txt
      abc.xyz
    folder4
    folder5
      data.zip
      somefile.exe
      someotherfile.dll

The files data.zip and info.txt can appear everywhere in the directory structure. How can I copy the full directory structure, but only include files named data.zip and info.txt (all other files should be ignored)?

The resulting directory structure should look like this:

copy_of_folder1
  folder2
    folder3
      data.zip
      info.txt
    folder4
    folder5
      data.zip

Body:
XCOPY /S folder1\data.zip copy_of_folder1
XCOPY /S folder1\info.txt copy_of_folder1

EDIT: If you want to preserve the empty folders (which, on rereading your post, you seem to) use /E instead of /S.

OwnerDisplayName: gkrogers

LastEditorDisplayName: gkrogers


问:
How to find the class name & title of a program in c++?
The question is how to find the class name from running programs and title of those programs. I know there already exist some scanning tools like WinDowse or spy++ from visual studio, but what I am asking you is how to make programs like those in our own source code, what function to use, is there some open source program that can help? Code appreciated, link's also :)

答:
Use EnumWindows to enumerate all top-level windows and get their handle.

Pass the handle to GetWindowText and GetClassName to get the window title and window class respectively.

Example:

```<code>EnumWindows(EnumProc, 0);

...

BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam) {
  TCHAR title[256];
  TCHAR className[256];

  GetWindowText(hWnd, title, 256);
  MessageBox(NULL, title, NULL, MB_OK);

  GetClassName(hWnd, className, 256);
  MessageBox(NULL, className, NULL, MB_OK);

  return TRUE;
}
</code>```

Body:
Use EnumWindows to enumerate all top-level windows and get their handle.

Pass the handle to GetWindowText and GetClassName to get the window title and window class respectively.

Example:

EnumWindows(EnumProc, 0);

...

BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam) {
  TCHAR title[256];
  TCHAR className[256];

  GetWindowText(hWnd, title, 256);
  MessageBox(NULL, title, NULL, MB_OK);

  GetClassName(hWnd, className, 256);
  MessageBox(NULL, className, NULL, MB_OK);

  return TRUE;
}


问:
Reading an .eml (outlook email) file using c#
I'm writing a service that cleans files by removing all malicious content. I'm using Interop Excel & Word api's like this:

Excel

```<code>    var excelApp = new Microsoft.Office.Interop.Excel.Application();
    excelApp.Visible = false;
    excelApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
    try
    {
        var workbook = excelApp.Workbooks.Open(fileToClean.InputFileName);
</code>```

Word

```<code>    var wordApp = new Microsoft.Office.Interop.Word.Application
    {
        Visible = false,
        AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
    };

    try
    {
        var wordDoc = wordApp.Documents.Open(fileToClean.InputFileName, false, true);
</code>```

I'm trying to find a similar way to open .eml Outlook files.
I can't find any way of opening a .eml file using the Outlook Interop.

答:
EML file format is not native for Outlook - MSG format is (you can open an MSG file using Namespace.GetSharedItem). Even if Outlook will be happy to open an EML file for you if you double click on it in Windows Explorer.

To read an EML file, you would need to either parse it explicitly in your code, or to use one of numerous MIME processing libraries. If using Redemption (I am its author) is an option, you can create a temporary MSG file and import EML file into it.

The following code will create an MSG file and import an EML file into it using Redemption (RDOSession object):

```<code>  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = outlookApp.Session.MAPIOBJECT
  set Msg = Session.CreateMessageFromMsgFile("C:\Temp\temp.msg")
  Msg.Import "C:\Temp\test.eml", 1024
  Msg.Save
  MsgBox Msg.Subject
</code>```

You can then use the message (RDOMail) to access it various properties (Subject, Body, etc.)

Also keep in mind no Office app (Excel, Word, or Outlook) can be used from a Windows service (such as IIS).

Body:
I'm writing a service that cleans files by removing all malicious content. I'm using Interop Excel & Word api's like this:

Excel

    var excelApp = new Microsoft.Office.Interop.Excel.Application();
    excelApp.Visible = false;
    excelApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
    try
    {
        var workbook = excelApp.Workbooks.Open(fileToClean.InputFileName);

Word

    var wordApp = new Microsoft.Office.Interop.Word.Application
    {
        Visible = false,
        AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
    };

    try
    {
        var wordDoc = wordApp.Documents.Open(fileToClean.InputFileName, false, true);

I'm trying to find a similar way to open .eml Outlook files.
I can't find any way of opening a .eml file using the Outlook Interop.

Body:
EML file format is not native for Outlook - MSG format is (you can open an MSG file using Namespace.GetSharedItem). Even if Outlook will be happy to open an EML file for you if you double click on it in Windows Explorer.

To read an EML file, you would need to either parse it explicitly in your code, or to use one of numerous MIME processing libraries. If using Redemption (I am its author) is an option, you can create a temporary MSG file and import EML file into it.

The following code will create an MSG file and import an EML file into it using Redemption (RDOSession object):

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = outlookApp.Session.MAPIOBJECT
  set Msg = Session.CreateMessageFromMsgFile("C:\Temp\temp.msg")
  Msg.Import "C:\Temp\test.eml", 1024
  Msg.Save
  MsgBox Msg.Subject

You can then use the message (RDOMail) to access it various properties (Subject, Body, etc.)

Also keep in mind no Office app (Excel, Word, or Outlook) can be used from a Windows service (such as IIS).

ContentLicense: CC BY-SA 4.0


问:
Remove everything after delimiter in filenames via batch script
say I have a set of files, batch script, and subdirectories "Numbers" and "NoNumbers" in a "Files" directory in Windows, like so:

```<code><Files>
    <Numbers>
    <NoNumbers>
    updatefiles.bat
    Alpha.txt
    Alpha #306.txt
    Beta.txt
    Gamma.txt
    Gamma #402.txt
    Epsilon.txt
    Epsilon #862.txt
</code>```

and I want to move all of the files containing #XXX into a subdirectory "Numbers" and all of the ones that do not contain #XXX into a subdirectory "NoNumbers"

After the move, I want to remove the last 4 characters of the files in the "Numbers" directory (eg. Alpha #306.txt renamed to Alpha.txt).

I also want to do all of this using relative paths (e.g. the "Files" directory may be anywhere on any Windows drive).

The end result would look like this:

```<code><Files>
    <Numbers>
        Alpha.json
        Beta.json
        Gamma.json
        Epsilon.json
    <NoNumbers>
        Alpha.json
        Beta.json
        Gamma.json
        Epsilon.json
</code>```

What would the easiest way to do this be with the batch script updatefiles.bat?

Thanks!

EDIT: Here are my initial attempts (tried to do it in pieces first):

Attempting to move the files containing # to subdirectory "Numbers"

ren *.txt *.json
for /f "eol=: delims=" %%F in ('dir /b^|find "#"') do move /Y "%%F" "Numbers"
```

<p>Attempting to cut off the last 4 characters and .txt extension:</p>

<pre class="lang-dos prettyprint-override"><code>for %%i in ("*.txt") do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off last 9 chars
ren "%fname%" "%fname:~0,-9%.json"
goto :eof
</code>```

Now I need to combine those into one .bat that uses relative paths

EDIT 2: Here's what I've come up with as the combined script:

setlocal
ren *.txt *.json
for /f "eol=: delims=" %%F in ('dir /b^|find "#"') do move /Y "%%F" "Numbers"
for /f "eol=: delims=" %%G in ('dir /b^|find ".json"') do move /Y "%%G" "NoNumbers"
CD /D %~dp0\Numbers
for %%i in ("*.json") do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off last 10 chars, then appends .json
ren "%fname%" "%fname:~0,-10%.json"
goto :eof
```

It renames the .txt to .json, moves all .json files that have "#" in them to the "Numbers" directory, moves everything else to the "NoNumbers" directory, changes to the "Numbers" directory, removes the last 10 characters of each file, and adds back the .json extension. I'm sure there's a more efficient way but it does what I need it to do now.

答:
It appears that from your example result that you also want files with no "#" copied as is to the NoNumber directory. Is that correct?

This script detects the presence of the "#" character in the file name by comparing the filename to one which has had all "#" characters replaced with nothing.

```<code>SETLOCAL ENABLEDELAYEDEXPANSION

FOR %%i IN ("*.txt") DO (
    SET "BNAME=%%~ni"
    SET "TNAME=!BNAME:#=!

    IF "!BNAME!" NEQ "!TNAME!" (
        REM A # was found
        REM NB: This assumes that there is a space before the #
        MOVE "%%~i" "NoNumbers\!TNAME:~0,-4!.json"
    ) ELSE (
        COPY /Y "%%~i" "NoNumbers\!BNAME!.json"
        MOVE "%%~i" "Numbers\!BNAME!.json"
    )
)
</code>```

This script does nothing to detect filename collisions. What happens if both BETA #101.txt and BETA #102.txt exist?

Body:
say I have a set of files, batch script, and subdirectories "Numbers" and "NoNumbers" in a "Files" directory in Windows, like so:

<Files>
    <Numbers>
    <NoNumbers>
    updatefiles.bat
    Alpha.txt
    Alpha #306.txt
    Beta.txt
    Gamma.txt
    Gamma #402.txt
    Epsilon.txt
    Epsilon #862.txt

and I want to move all of the files containing #XXX into a subdirectory "Numbers" and all of the ones that do not contain #XXX into a subdirectory "NoNumbers"

After the move, I want to remove the last 4 characters of the files in the "Numbers" directory (eg. Alpha #306.txt renamed to Alpha.txt).

I also want to do all of this using relative paths (e.g. the "Files" directory may be anywhere on any Windows drive).

The end result would look like this:

<Files>
    <Numbers>
        Alpha.json
        Beta.json
        Gamma.json
        Epsilon.json
    <NoNumbers>
        Alpha.json
        Beta.json
        Gamma.json
        Epsilon.json

What would the easiest way to do this be with the batch script updatefiles.bat?

Thanks!

EDIT: Here are my initial attempts (tried to do it in pieces first):

Attempting to move the files containing # to subdirectory "Numbers"

ren *.txt *.json
for /f "eol=: delims=" %%F in ('dir /b^|find "#"') do move /Y "%%F" "Numbers"

Attempting to cut off the last 4 characters and .txt extension:

for %%i in ("*.txt") do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off last 9 chars
ren "%fname%" "%fname:~0,-9%.json"
goto :eof

Now I need to combine those into one .bat that uses relative paths

EDIT 2: Here's what I've come up with as the combined script:

setlocal
ren *.txt *.json
for /f "eol=: delims=" %%F in ('dir /b^|find "#"') do move /Y "%%F" "Numbers"
for /f "eol=: delims=" %%G in ('dir /b^|find ".json"') do move /Y "%%G" "NoNumbers"
CD /D %~dp0\Numbers
for %%i in ("*.json") do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off last 10 chars, then appends .json
ren "%fname%" "%fname:~0,-10%.json"
goto :eof

It renames the .txt to .json, moves all .json files that have "#" in them to the "Numbers" directory, moves everything else to the "NoNumbers" directory, changes to the "Numbers" directory, removes the last 10 characters of each file, and adds back the .json extension. I'm sure there's a more efficient way but it does what I need it to do now.

Body:
It appears that from your example result that you also want files with no "#" copied as is to the NoNumber directory. Is that correct?

This script detects the presence of the "#" character in the file name by comparing the filename to one which has had all "#" characters replaced with nothing.

SETLOCAL ENABLEDELAYEDEXPANSION

FOR %%i IN ("*.txt") DO (
    SET "BNAME=%%~ni"
    SET "TNAME=!BNAME:#=!

    IF "!BNAME!" NEQ "!TNAME!" (
        REM A # was found
        REM NB: This assumes that there is a space before the #
        MOVE "%%~i" "NoNumbers\!TNAME:~0,-4!.json"
    ) ELSE (
        COPY /Y "%%~i" "NoNumbers\!BNAME!.json"
        MOVE "%%~i" "Numbers\!BNAME!.json"
    )
)

This script does nothing to detect filename collisions. What happens if both BETA #101.txt and BETA #102.txt exist?


问:
Pandas, how to count the occurance within grouped dataframe and create new column?
How do I get the count of each values within the group using pandas ?

In the below table, I have Group and the Value column, and I want to generate a new column called count, which should contain the total nunmber of occurance of that value within the group.

my df dataframe is as follows (without the count column):

```<code>-------------------------
| Group| Value | Count? |
-------------------------
|   A  |    10 |      3 |
|   A  |    20 |      2 |
|   A  |    10 |      3 |
|   A  |    10 |      3 |
|   A  |    20 |      2 |
|   A  |    30 |      1 |
-------------------------
|   B  |    20 |      3 |
|   B  |    20 |      3 |
|   B  |    20 |      3 |
|   B  |    10 |      1 |
-------------------------
|   C  |    20 |      2 |
|   C  |    20 |      2 |
|   C  |    10 |      2 |
|   C  |    10 |      2 |
-------------------------
</code>```

I can get the counts using this:

```<code>df.groupby(['group','value']).value.count()
</code>```

but this is just to view, I am having difficuly putting the results back to the dataframe as new columns.

答:
Using transform

```<code>df['count?']=df.groupby(['group','value']).value.transform('count').values
</code>```

Body:
How do I get the count of each values within the group using pandas ?

In the below table, I have Group and the Value column, and I want to generate a new column called count, which should contain the total nunmber of occurance of that value within the group.

my df dataframe is as follows (without the count column):

-------------------------
| Group| Value | Count? |
-------------------------
|   A  |    10 |      3 |
|   A  |    20 |      2 |
|   A  |    10 |      3 |
|   A  |    10 |      3 |
|   A  |    20 |      2 |
|   A  |    30 |      1 |
-------------------------
|   B  |    20 |      3 |
|   B  |    20 |      3 |
|   B  |    20 |      3 |
|   B  |    10 |      1 |
-------------------------
|   C  |    20 |      2 |
|   C  |    20 |      2 |
|   C  |    10 |      2 |
|   C  |    10 |      2 |
-------------------------

I can get the counts using this:

df.groupby(['group','value']).value.count()

but this is just to view, I am having difficuly putting the results back to the dataframe as new columns.

Body:
Using transform

df['count?']=df.groupby(['group','value']).value.transform('count').values


问:
When global_variables_initializer() is actually required
```<code>import tensorflow as tf
x = tf.constant(35, name='x')
y = tf.Variable(x + 5, name='y')
# model = tf.global_variables_initializer()
with tf.Session() as session:
        print("x = ", session.run(x))
        # session.run(model)
        print("y = ", session.run(y))
</code>```

I was not able to understand when global_variables_initializer() is actually required. In the above code, if we uncomment lines 4 & 7, I can execute the code and see the values. If I run as-is, I see a crash.

My question is which variables it is initializing. x is a constant which does not need initialization and y is variable which is not being initialized but is used as an arithmetic operation.

答:
The tf.global_variables_initializer just initializes all variables that tf.global_variables() would list. This actually makes much sense in a distributed environment where the graph might be located in different computing nodes in a cluster.

In such a case, tf.global_variables_initializer() which is just an alias for tf.variables_initializer(tf.global_variables()) would initialize all the variables in all the computing nodes, where the graph is placed.

Body:
import tensorflow as tf
x = tf.constant(35, name='x')
y = tf.Variable(x + 5, name='y')
# model = tf.global_variables_initializer()
with tf.Session() as session:
        print("x = ", session.run(x))
        # session.run(model)
        print("y = ", session.run(y))

I was not able to understand when global_variables_initializer() is actually required. In the above code, if we uncomment lines 4 & 7, I can execute the code and see the values. If I run as-is, I see a crash.

My question is which variables it is initializing. x is a constant which does not need initialization and y is variable which is not being initialized but is used as an arithmetic operation.


问:
How to copy all files created between two dates using Command prompt?
I have written code in window batch file (eq. getFiles.bat ) that get all files within select date range.
eq.

```<code>xcopy /S /D:01-10-2011  *.* C:\todaysFiles
</code>```

But I want get all files in between two dates including From date and To date.

 file extension is .cmd or .bat

答:
The title of this question is slightly misleading. Based on the questioner's xcopy example, I believe the questioner wants to know "How to copy all files created...", not how to get all files (which I equate with list).

The questioner also states "file extension is .cmd or .bat". This could mean that the questioner wants to copy only files with these extensions but I think it means the questioner would like a batch script solution.

To use the following solution, open a command prompt and chdir to the folder where the files to be copied are located. Then enter the commands listed below, changing the SET values as appropriate.

```<code>SET DESTINATION=C:\destination
SET DATE_FROM=01/01/2005
SET DATE_TO=01/01/2007
> nul forfiles /S /D +%DATE_FROM% /C "cmd /C if @isdir==FALSE 2> nul forfiles /M @file /D -%DATE_TO% && > con ( echo @path && copy /V @path %DESTINATION% )"
</code>```

Note: this will copy files in subfolders as well as files in the top-level folder.

The SET values could be hard-coded directly into the > nul forfiles... line, meaning only one line is required, but for clarity I've used variable substitution.

A caveat is that it is based on date modified (original question asked for date created)

Credit to aschipfl (https://stackoverflow.com/a/36585535/1754517) for providing the inspiration for my answer.

Body:
I have written code in window batch file (eq. getFiles.bat ) that get all files within select date range.
eq.

xcopy /S /D:01-10-2011  *.* C:\todaysFiles

But I want get all files in between two dates including From date and To date.

 file extension is .cmd or .bat

Body:
The title of this question is slightly misleading. Based on the questioner's xcopy example, I believe the questioner wants to know "How to copy all files created...", not how to get all files (which I equate with list).

The questioner also states "file extension is .cmd or .bat". This could mean that the questioner wants to copy only files with these extensions but I think it means the questioner would like a batch script solution.

To use the following solution, open a command prompt and chdir to the folder where the files to be copied are located. Then enter the commands listed below, changing the SET values as appropriate.

SET DESTINATION=C:\destination
SET DATE_FROM=01/01/2005
SET DATE_TO=01/01/2007
> nul forfiles /S /D +%DATE_FROM% /C "cmd /C if @isdir==FALSE 2> nul forfiles /M @file /D -%DATE_TO% && > con ( echo @path && copy /V @path %DESTINATION% )"

Note: this will copy files in subfolders as well as files in the top-level folder.

The SET values could be hard-coded directly into the > nul forfiles... line, meaning only one line is required, but for clarity I've used variable substitution.

A caveat is that it is based on date modified (original question asked for date created)

Credit to aschipfl (https://stackoverflow.com/a/36585535/1754517) for providing the inspiration for my answer.