问:
How to use control operator after a heredoc in bash
I'm writing a bash script to create MySQL database automatically. The bash script is like the following (please ignore those variable $db_name, $db_pwd...):

```<code>#!/bin/bash
sudo mysql -u root << EOF
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
    quit
EOF
printf "Done"
</code>```

I want the database creation to be completed successfully and the print command runs afterwards. But I can not put the && after EOF, like:

```<code>#!/bin/bash
sudo mysql -u root << EOF
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
    quit
EOF &&
printf "Done"
</code>```

It will show the error like:

```<code>invalid command name "EOF"
    while executing
"EOF &&"
</code>```

How can I do it?

答:
An easy workaround is to exit if mysql fails.

```<code>sudo mysql -u root << EOF || exit
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
EOF
echo "Done"
</code>```

Or you could add set -e to cause any failed command to immediately exit the script.

```<code>#!/bin/bash
set -e

sudo mysql -u root << EOF
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
EOF
echo "Done"
</code>```

Body:
I'm writing a bash script to create MySQL database automatically. The bash script is like the following (please ignore those variable $db_name, $db_pwd...):

#!/bin/bash
sudo mysql -u root << EOF
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
    quit
EOF
printf "Done"

I want the database creation to be completed successfully and the print command runs afterwards. But I can not put the && after EOF, like:

#!/bin/bash
sudo mysql -u root << EOF
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
    quit
EOF &&
printf "Done"

It will show the error like:

invalid command name "EOF"
    while executing
"EOF &&"

How can I do it?

Body:
An easy workaround is to exit if mysql fails.

sudo mysql -u root << EOF || exit
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
EOF
echo "Done"

Or you could add set -e to cause any failed command to immediately exit the script.

#!/bin/bash
set -e

sudo mysql -u root << EOF
    CREATE DATABASE $db_name;
    CREATE USER $db_user IDENTIFIED BY $db_pwd;
    GRANT ALL PRIVILEGES ON $db_name.* TO $db_user;
EOF
echo "Done"


来源: stackexchange

问:
proguard warning: the configuration keeps the entry point....but not the descriptor class
I've configured:

```<code>-keep ,allowoptimization,allowobfuscation,allowshrinking public class     org.jf.dexlib2.dexbacked.** {
    *;
}
</code>```

but still getting the warning:

```<code> Note: the configuration keeps the entry point 'com.trusteer.trf.dex_parser { int get_strings_count(org.jf.dexlib2.dexbacked.DexBackedDexFile); }', but not the descriptor class 'org.jf.dexlib2.dexbacked.DexBackedDexFile'
</code>```

I am using proguard version 4.7 (in Android SDK)

What should I do?

答:
In my case this problem appears when I add to build.gradle

```<code>minifyEnable true
</code>```

Official instructions: https://flutter.dev/docs/deployment/android

Bug https://github.com/flutter/flutter/issues/19250

Sample proguard-rules.pro file:

```<code>#Flutter Wrapper
-ignorewarnings
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I've configured:

-keep ,allowoptimization,allowobfuscation,allowshrinking public class     org.jf.dexlib2.dexbacked.** {
    *;
}

but still getting the warning:

 Note: the configuration keeps the entry point 'com.trusteer.trf.dex_parser { int get_strings_count(org.jf.dexlib2.dexbacked.DexBackedDexFile); }', but not the descriptor class 'org.jf.dexlib2.dexbacked.DexBackedDexFile'

I am using proguard version 4.7 (in Android SDK)

What should I do?

Body:
In my case this problem appears when I add to build.gradle

minifyEnable true

Official instructions: https://flutter.dev/docs/deployment/android

Bug https://github.com/flutter/flutter/issues/19250

Sample proguard-rules.pro file:

#Flutter Wrapper
-ignorewarnings
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }

ContentLicense: CC BY-SA 4.0


问:
Does git pull change HEAD?
I understand how git checkout changes the HEAD pointer but what about git pull?

HEAD can be seen as the 'current branch' but when you execute git pull and your current branch is altered. Does it affect HEAD pointer? Why?

答:
Usually HEAD is a double-indirection to a commit. git checkout manipulates the first indirection, git commit, git merge, git pull and other commands the second.

Example: After git checkout master the file .git/HEAD contains

```<code>ref: refs/heads/master
</code>```

which is a "symbolic reference" to a branch ref (see git help symbolic-ref). Doing git checkout develop gives you

```<code>ref: refs/heads/develop
</code>```

git pull (which is either git fetch; git merge or git fetch; git rebase) will not touch the .git/HEAD but manipulate .git/refs/heads/master (and/or git./packed-refs).

So the answer is: git pull does not manipulate HEAD but the ref HEAD points to. The effect is that HEAD points to another commit.

Title: Does git pull change HEAD?

Body:
Usually HEAD is a double-indirection to a commit. git checkout manipulates the first indirection, git commit, git merge, git pull and other commands the second.

Example: After git checkout master the file .git/HEAD contains

ref: refs/heads/master

which is a "symbolic reference" to a branch ref (see git help symbolic-ref). Doing git checkout develop gives you

ref: refs/heads/develop

git pull (which is either git fetch; git merge or git fetch; git rebase) will not touch the .git/HEAD but manipulate .git/refs/heads/master (and/or git./packed-refs).

So the answer is: git pull does not manipulate HEAD but the ref HEAD points to. The effect is that HEAD points to another commit.


问:
I am finding the second largest number from the array list, but I get runtime-error when the input arr is 6,6,6,6,6,6,6,6,6,5
when i compiled this program in VSCode, I got IndexError. Is there any other solution?</p>

```<code>#here is my sample code
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    x = len(arr)
    arr.sort()
    for i in range(0, x-1):
        #removing redundant values
        if arr[i] == max(arr):
            arr.remove(arr[i])

    arr.remove(max(arr))
    print(max(arr))
</code>```

答:
split using split(',') when input is 6,6,6,6,6,6,6,6,6,5

arr = list(map(int, input().split(',')))

Body:
when i compiled this program in VSCode, I got IndexError. Is there any other solution?

#here is my sample code
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    x = len(arr)
    arr.sort()
    for i in range(0, x-1):
        #removing redundant values
        if arr[i] == max(arr):
            arr.remove(arr[i])

    arr.remove(max(arr))
    print(max(arr))


问:
How to merger this sql server query?
I have this query

```<code>select count(*) as COUNT_A, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NOT NULL
group by datepart(yyyy, [Tgl_Perolehan])
</code>```

and this

```<code>select count(*) as COUNT_B, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NULL
group by datepart(yyyy, [Tgl_Perolehan])
</code>```

The difference is only IS NOT NULL and IS NULL and the result is

+---------+--------+
| COUNT_A  |  year  |
+----------+--------+
| 12       | 1991   |
| 15       | 1993   |
| 24       | 1998   |
+----------+--------+

I want make like this

+---------+---------+--------+
| COUNT_A  | COUNT_B |  year  |
+----------+---------+--------+
| 12       | 23      | 1991   |
| 15       | 33      | 1993   |
| 24       | 13      | 1998   |
+----------+---------+--------+

and I try like this

```<code>select (select count(*) as COUNT_A, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NOT NULL
group by datepart(yyyy, [Tgl_Perolehan])),
(select count(*) as COUNT_B, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NULL
group by datepart(yyyy, [Tgl_Perolehan]))
</code>```

But didn't fix my problem.
I have use CASE WHEN, but still didn't fix the problem.
How to merge and fix their?
Thanks.

答:
Try this using co-related subquery</p>

```<code>SELECT   Datepart(yyyy, o.[Tgl_Perolehan]) AS [Tgl_Perolehan] ,
         (
                SELECT Count(*)
                FROM   [table_name] i
                WHERE  i.<somid> = o.<somid>
                AND    i.sertifikat_nomor  IS NOT NULL ) AS AS count_a ,
         (
                SELECT count(*)
                FROM   [table_name] ii
                WHERE  ii.<somid> = o.<somid>
                AND    ii.sertifikat_nomor IS NULL) AS AS count_b
FROM     [table_name] o
GROUP BY datepart(yyyy,o.[Tgl_Perolehan])
</code>```

Title: How to merger this sql server query?

Body:
I have this query

select count(*) as COUNT_A, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NOT NULL
group by datepart(yyyy, [Tgl_Perolehan])

and this

select count(*) as COUNT_B, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NULL
group by datepart(yyyy, [Tgl_Perolehan])

The difference is only IS NOT NULL and IS NULL and the result is

+---------+--------+
| COUNT_A  |  year  |
+----------+--------+
| 12       | 1991   |
| 15       | 1993   |
| 24       | 1998   |
+----------+--------+

I want make like this

+---------+---------+--------+
| COUNT_A  | COUNT_B |  year  |
+----------+---------+--------+
| 12       | 23      | 1991   |
| 15       | 33      | 1993   |
| 24       | 13      | 1998   |
+----------+---------+--------+

and I try like this

select (select count(*) as COUNT_A, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NOT NULL
group by datepart(yyyy, [Tgl_Perolehan])),
(select count(*) as COUNT_B, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NULL
group by datepart(yyyy, [Tgl_Perolehan]))

But didn't fix my problem.
I have use CASE WHEN, but still didn't fix the problem.
How to merge and fix their?
Thanks.

Body:
Try this using co-related subquery

SELECT   Datepart(yyyy, o.[Tgl_Perolehan]) AS [Tgl_Perolehan] ,
         (
                SELECT Count(*)
                FROM   [table_name] i
                WHERE  i.<somid> = o.<somid>
                AND    i.sertifikat_nomor  IS NOT NULL ) AS AS count_a ,
         (
                SELECT count(*)
                FROM   [table_name] ii
                WHERE  ii.<somid> = o.<somid>
                AND    ii.sertifikat_nomor IS NULL) AS AS count_b
FROM     [table_name] o
GROUP BY datepart(yyyy,o.[Tgl_Perolehan])


答:
put sudo into round brackets:</p>

```<code>#!/bin/bash
(sudo mysql -u root << EOF
   ...
EOF
) && [next command]
</code>```

Title: How to use control operator after a heredoc in bash

Body:
put sudo into round brackets:

#!/bin/bash
(sudo mysql -u root << EOF
   ...
EOF
) && [next command]


问:
Navigating to DialogFragment produces IllegalArgumentException if button pressed quickly?
My Navigation graph has two destinations, a Fragment and a DialogFragment. The Fragment contains a Button that navigates to the DialogFragment when pressed.

Everything works as expected, except if I click the button very quickly. Doing so can trigger a

IllegalArgumentException: navigation destination
  com.example.app:id/show_dialog is unknown to this NavController

To fix this, I ensure that the current destination is the Fragment containing the show_dialog action:

```<code>val navController = findNavController()
val currentDest = navController.currentDestination?.id

if (currentDest == R.id.test_fragment) {
    navController.navigate(TestFragmentDirections.showDialog())
}
</code>```

Making this change appears to fix the issue. However, I would like to know:

Why is it necessary to wrap the navigate call with a conditional statement in this situation?

答:
Your question is just based on the Android inside Architecture and is also dependent on the hardware performance. Just wrap it in a try/catch block:

```<code>try{
  findNavController().navigate(TestFragmentDirections.showDialog())
}catch(e: IllegalArgumentException){
    e.printStackTrace
}
</code>```

Body:
My Navigation graph has two destinations, a Fragment and a DialogFragment. The Fragment contains a Button that navigates to the DialogFragment when pressed.

Everything works as expected, except if I click the button very quickly. Doing so can trigger a

IllegalArgumentException: navigation destination
  com.example.app:id/show_dialog is unknown to this NavController

To fix this, I ensure that the current destination is the Fragment containing the show_dialog action:

val navController = findNavController()
val currentDest = navController.currentDestination?.id

if (currentDest == R.id.test_fragment) {
    navController.navigate(TestFragmentDirections.showDialog())
}

Making this change appears to fix the issue. However, I would like to know:

Why is it necessary to wrap the navigate call with a conditional statement in this situation?

Body:
Your question is just based on the Android inside Architecture and is also dependent on the hardware performance. Just wrap it in a try/catch block:

try{
  findNavController().navigate(TestFragmentDirections.showDialog())
}catch(e: IllegalArgumentException){
    e.printStackTrace
}


问:
Why this sprintf statement crashing?
```<code>char filebuf[256];
path current = current_path();
std::cout<<"CurrentWorking "<<current<<endl;
string _UserDir = "TTiTraceLogs";
sprintf(filebuf,"%s/%s",current,_UserDir); ///crashing here
</code>```

If I format only current, then it is ok.

```<code>sprintf(filebuf,"%s",current);
</code>```

Output:

```<code>CurrentWorking D:/working/eclipse_projects/sadftp/CollectTTiTraceSept10_1009_174
_higher/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Release
</code>```

答:
Since _UserDir is a C++ string, you'll need to get its C string to call sprintf(), which is a C function.

```<code>sprintf(filebuf,"%s/%s",current,_UserDir.c_str());  // gets C string
</code>```

Also, what is a path? If it isn't like a typedef for char*, then you can't just sprintf() that either. It may be that operator<<() is overloaded for path, which is why the std::cout works.

Title: Why this sprintf statement crashing?

Body:
char filebuf[256];
path current = current_path();
std::cout<<"CurrentWorking "<<current<<endl;
string _UserDir = "TTiTraceLogs";
sprintf(filebuf,"%s/%s",current,_UserDir); ///crashing here

If I format only current, then it is ok.

sprintf(filebuf,"%s",current);

Output:

CurrentWorking D:/working/eclipse_projects/sadftp/CollectTTiTraceSept10_1009_174
_higher/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Release

Body:
Since _UserDir is a C++ string, you'll need to get its C string to call sprintf(), which is a C function.

sprintf(filebuf,"%s/%s",current,_UserDir.c_str());  // gets C string

Also, what is a path? If it isn't like a typedef for char*, then you can't just sprintf() that either. It may be that operator<<() is overloaded for path, which is why the std::cout works.


问:
How to make left menu height grow according to the content on the right
I want the menu on the left to grow according to the content in the right, instead of setting the height of all the sections available.

In this case I would want the menu on the left to finish below the Choice 10 of the content in the right and then the menu would have a scroll (which I have already added in CSS).

Thanks in advance ! :)

@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i');
* {
  font-family: Roboto, sans-serif !important;
}

@media screen and (max-width: 1300px) {
  .wrapper,
  .disclaimer {
    width: 90vw !important;
  }
}

ol {
  text-align: left;
}

.answered {
  font-weight: 900;
}

.answered::after {
  content: '•';
  color: black;
  margin-left: 10px;
  font-size: 15px;
}

.sections-choices {
  display: flex;
  align-items: flex-start;
  border: 1px solid #ddeafa;
  margin: 0 25px 15px 25px;
  width: 95%;
  margin-bottom: 15px;
  background-color: white;
  /* height: 300px;
                min-height: 300px;
                max-height: 350px; */
}

.sections {
  color: gainsboro;
  text-align: left;
  font-size: 13px;
  background-color: white;
  text-decoration: none;
  width: 20%;
  height: inherit;
  overflow-y: scroll;
}

.sections .question-select {
  margin-left: 10px;
}

.sections h4 {
  padding: 5px 0 5px 15px;
  background-color: #3a3838;
  color: white;
  margin-top: 0;
}

.sections .intro-text {
  padding-top: 2.5px;
  padding-bottom: 2.5px;
}

.sections a {
  text-decoration: none;
  color: black;
  padding-left: 15px;
}

.choices {
  color: black;
  font-size: 14px;
  text-align: left;
  width: 80%;
  padding-bottom: 15px;
  height: inherit;
}

.choices-section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: auto;
  background-color: #3a3838;
}

.choices-section-title h4 {
  margin: 0;
  padding: 15px 15px;
  color: white;
}

.choices-title {
  padding: 10px 15px 0 15px;
  line-height: 19px;
}

.help-text {
  padding: 5px 15px 0 15px;
  text-align: right;
  font-size: 11px;
}

.help-text p {
  margin: 0;
}

.choices-radio {
  padding: 15px 15px 0 25px;
}

.choices-radio label {
  /* word-wrap: break-word; */
  white-space: normal;
}

.choices-radio input {
  margin-bottom: 10px;
}

/* TOOLTIP */

.tooltip {
  position: relative;
  font-size: 12px;
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  flex-direction: row;
  color: black;
}

.tooltip img {
  margin-right: 5px;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 300px;
  background-color: #f7f7f7;
  color: black;
  text-align: left;
  border-radius: 6px;
  padding: 10px;
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
  top: -5px;
  right: 105%;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}

/* CHANGE RADIO BUTTONS ASPECT */

/* The container */

.radio-style {
  display: block;
  position: relative;
  padding-left: 25px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 13px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Hide the browser's default radio button */

.radio-style input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

/* Create a custom radio button */

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 18px;
  width: 18px;
  background-color: gainsboro;
  border-radius: 50%;
}

/* On mouse-over, add a grey background color */

.radio-style:hover input~.checkmark {
  background-color: #ccc;
}

/* When the radio button is checked, add a blue background */

.radio-style input:checked~.checkmark {
  background-color: black;
}

/* Create the indicator (the dot/circle - hidden when not checked) */

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

/* Show the indicator (dot/circle) when checked */

.radio-style input:checked~.checkmark:after {
  display: block;
}

/* Style the indicator (dot/circle) */

.radio-style .checkmark:after {
  top: 6px;
  left: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
}

/* SCROLLBAR */

/* width */

 ::-webkit-scrollbar {
  width: 8px;
}

/* Track */

 ::-webkit-scrollbar-track {
  background: #f1f1f1;
}

/* Handle */

 ::-webkit-scrollbar-thumb {
  background: #888;
}

/* Handle on hover */

 ::-webkit-scrollbar-thumb:hover {
  background: #555;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>

<body style="margin: 0 auto; max-height: 70vh; background-color: #DCE3EA; text-align: center; margin-top: 15px; font-family: Roboto Condensed, sans-serif;">
  <div class="wrapper" style="padding: 15px 0; width: 70vw; margin: 0 auto; background-color: #ffffff; border-radius: 3px; border: 1px solid #c8c8c8;
    box-shadow: 2px 2px 8px #a8a8a8;">

    <div class="sections-choices">
      <div class="sections">
        <h4>1. Section 1</h4>
        <p class="question-select">Question 1</p>
        <p class="question-select">Question 2</p>
        <p class="question-select">Question 3</p>
        <p class="question-select">Question 4</p>

        <h4>2. Section 2</h4>
        <p class="question-select">Question 1</p>
        <p class="question-select">Question 2</p>

        <h4>3. Section 3</h4>
        <p class="question-select">Question 1</p>
        <p class="question-select">Question 2</p>
        <p class="question-select">Question 3</p>

        <h4>4. Section 4</h4>
        <p class="question-select">Question 1</p>

        <h4>5. Section 5</h4>
        <p class="question-select">Question 1</p>
        <p class="question-select">Question 2</p>
        <p class="question-select">Question 3</p>

        <h4>6. Section 6</h4>
        <p class="question-select">Question 1</p>
        <p class="question-select">Question 2</p>
        <p class="question-select">Question 3</p>
        <p class="question-select">Question 4</p>
        <p class="question-select">Question 5</p>
      </div>
      <div class="choices">
        <div class="choices-section-title">
          <h4>Section 1 out of 6</h4>
          <h4>Question 1 out of 4</h4>
        </div>
        <div class="choices-title"><b>1. This is Question 1 ?</b></div>
        <div class="help-text">
          <div class="tooltip">
            <img src="" width="18px"> More information
            <span class="tooltiptext"> Tooltip text </span>
          </div>
        </div>
        <div class="choices-radio">
          <label class="radio-style">Choice 1
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 2
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 3
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 4
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 5
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 6
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 7
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 8
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 9
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>

          <label class="radio-style">Choice 10
                                <input type="radio" value="choice1" name="choice1"><br>
                                <span class="checkmark"></span>
                            </label>
        </div>
      </div>
    </div>
  </div>
</body>

</html></code>```

答:
$( document ).ready(function() {

var height = $(".choices").height();

console.log(height);

$(".sections-choices").css("height",height);

});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>        @import url('https://fonts.googleapis.com/css?family=Roboto:400,400i');

        * {
            font-family: Roboto, sans-serif !important;
        }

        @media screen and (max-width: 1300px) {

            .wrapper,
            .disclaimer {
                width: 90vw !important;
            }
        }

        body {
          height:438px;
        }

        .wrapper {
          height:438px;
        }

        ol {
            text-align: left;
        }

        .answered {
            font-weight: 900;
        }

        .answered::after {
            content: '•';
            color: black;
            margin-left: 10px;
            font-size: 15px;
        }

        .sections-choices {
            display: flex;
            align-items: flex-start;
            border: 1px solid #ddeafa;
            margin: 0 25px 15px 25px;
            width: 95%;
            margin-bottom: 15px;
            background-color: white;
            /* height: 300px;
            min-height: 300px;
            max-height: 350px; */

        }

        .sections {
            color: gainsboro;
            text-align: left;
            font-size: 13px;
            background-color: white;
            text-decoration: none;
            width: 20%;
            overflow: scroll;
            height:100%;
        }

        .sections .question-select {
            margin-left: 10px;
        }

        .sections h4 {
            padding: 5px 0 5px 15px;
            background-color: #3a3838;
            color: white;
            margin-top: 0;
        }

        .sections .intro-text {
            padding-top: 2.5px;
            padding-bottom: 2.5px;
        }

        .sections a {
            text-decoration: none;
            color: black;
            padding-left: 15px;
        }

        .choices {
            color: black;
            font-size: 14px;
            text-align: left;
            width: 80%;
            padding-bottom: 15px;
            height: inherit;
        }

        .choices-section-title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: auto;
            background-color: #3a3838;
        }

        .choices-section-title h4 {
            margin: 0;
            padding: 15px 15px;
            color: white;
        }

        .choices-title {
            padding: 10px 15px 0 15px;
            line-height: 19px;
        }

        .help-text {
            padding: 5px 15px 0 15px;
            text-align: right;
            font-size: 11px;
        }

        .help-text p {
            margin: 0;
        }

        .choices-radio {
            padding: 15px 15px 0 25px;
        }

        .choices-radio label {
            /* word-wrap: break-word; */
            white-space: normal;
        }

        .choices-radio input {
            margin-bottom: 10px;
        }

        /* TOOLTIP */

        .tooltip {
            position: relative;
            font-size: 12px;
            display: inline-flex;
            justify-content: flex-end;
            align-items: center;
            flex-direction: row;
            color: black;
        }

        .tooltip img {
            margin-right: 5px;
        }

        .tooltip .tooltiptext {
            visibility: hidden;
            width: 300px;
            background-color: #f7f7f7;
            color: black;
            text-align: left;
            border-radius: 6px;
            padding: 10px;
            /* Position the tooltip */
            position: absolute;
            z-index: 1;
            top: -5px;
            right: 105%;
        }

        .tooltip:hover .tooltiptext {
            visibility: visible;
        }

        /* CHANGE RADIO BUTTONS ASPECT */

        /* The container */

        .radio-style {
            display: block;
            position: relative;
            padding-left: 25px;
            margin-bottom: 12px;
            cursor: pointer;
            font-size: 13px;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        /* Hide the browser's default radio button */

        .radio-style input {
            position: absolute;
            opacity: 0;
            cursor: pointer;
        }

        /* Create a custom radio button */

        .checkmark {
            position: absolute;
            top: 0;
            left: 0;
            height: 18px;
            width: 18px;
            background-color: gainsboro;
            border-radius: 50%;
        }

        /* On mouse-over, add a grey background color */

        .radio-style:hover input~.checkmark {
            background-color: #ccc;
        }

        /* When the radio button is checked, add a blue background */

        .radio-style input:checked~.checkmark {
            background-color: black;
        }

        /* Create the indicator (the dot/circle - hidden when not checked) */

        .checkmark:after {
            content: "";
            position: absolute;
            display: none;
        }

        /* Show the indicator (dot/circle) when checked */

        .radio-style input:checked~.checkmark:after {
            display: block;
        }

        /* Style the indicator (dot/circle) */

        .radio-style .checkmark:after {
            top: 6px;
            left: 6px;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: white;
        }

        /* SCROLLBAR */
        /* width */

        ::-webkit-scrollbar {
            width: 8px;
        }

        /* Track */

        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }

        /* Handle */

        ::-webkit-scrollbar-thumb {
            background: #888;
        }

        /* Handle on hover */

        ::-webkit-scrollbar-thumb:hover {
            background: #555;
        }</code>```

1. Section 1

Question 1

Question 2

Question 3

Question 4

2. Section 2

Question 1

Question 2

3. Section 3

Question 1

Question 2

Question 3

4. Section 4

Question 1

5. Section 5

Question 1

Question 2

Question 3

6. Section 6

Question 1

Question 2

Question 3

Question 4

Question 5

Section 1 out of 6

Question 1 out of 4

1. This is Question 1 ?

                         More information
                         Tooltip text

                    Choice 1
                        <input type="radio" value="choice1" name="choice1">

                    Choice 2
                        <input type="radio" value="choice1" name="choice1">

                    Choice 3
                        <input type="radio" value="choice1" name="choice1">

                    Choice 4
                        <input type="radio" value="choice1" name="choice1">

                    Choice 5
                        <input type="radio" value="choice1" name="choice1">

                    Choice 6
                        <input type="radio" value="choice1" name="choice1">

                    Choice 7
                        <input type="radio" value="choice1" name="choice1">

                    Choice 8
                        <input type="radio" value="choice1" name="choice1">

                    Choice 9
                        <input type="radio" value="choice1" name="choice1">

                    Choice 10
                        <input type="radio" value="choice1" name="choice1">

```

Body:
I want the menu on the left to grow according to the content in the right, instead of setting the height of all the sections available.

In this case I would want the menu on the left to finish below the Choice 10 of the content in the right and then the menu would have a scroll (which I have already added in CSS).

Thanks in advance ! :)

@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i');
* {
  font-family: Roboto, sans-serif !important;
}

@media screen and (max-width: 1300px) {
  .wrapper,
  .disclaimer {
    width: 90vw !important;
  }
}

ol {
  text-align: left;
}

.answered {
  font-weight: 900;
}

.answered::after {
  content: '•';
  color: black;
  margin-left: 10px;
  font-size: 15px;
}

.sections-choices {
  display: flex;
  align-items: flex-start;
  border: 1px solid #ddeafa;
  margin: 0 25px 15px 25px;
  width: 95%;
  margin-bottom: 15px;
  background-color: white;
  /* height: 300px;
                min-height: 300px;
                max-height: 350px; */
}

.sections {
  color: gainsboro;
  text-align: left;
  font-size: 13px;
  background-color: white;
  text-decoration: none;
  width: 20%;
  height: inherit;
  overflow-y: scroll;
}

.sections .question-select {
  margin-left: 10px;
}

.sections h4 {
  padding: 5px 0 5px 15px;
  background-color: #3a3838;
  color: white;
  margin-top: 0;
}

.sections .intro-text {
  padding-top: 2.5px;
  padding-bottom: 2.5px;
}

.sections a {
  text-decoration: none;
  color: black;
  padding-left: 15px;
}

.choices {
  color: black;
  font-size: 14px;
  text-align: left;
  width: 80%;
  padding-bottom: 15px;
  height: inherit;
}

.choices-section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: auto;
  background-color: #3a3838;
}

.choices-section-title h4 {
  margin: 0;
  padding: 15px 15px;
  color: white;
}

.choices-title {
  padding: 10px 15px 0 15px;
  line-height: 19px;
}

.help-text {
  padding: 5px 15px 0 15px;
  text-align: right;
  font-size: 11px;
}

.help-text p {
  margin: 0;
}

.choices-radio {
  padding: 15px 15px 0 25px;
}

.choices-radio label {
  /* word-wrap: break-word; */
  white-space: normal;
}

.choices-radio input {
  margin-bottom: 10px;
}

/* TOOLTIP */

.tooltip {
  position: relative;
  font-size: 12px;
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  flex-direction: row;
  color: black;
}

.tooltip img {
  margin-right: 5px;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 300px;
  background-color: #f7f7f7;
  color: black;
  text-align: left;
  border-radius: 6px;
  padding: 10px;
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
  top: -5px;
  right: 105%;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}

/* CHANGE RADIO BUTTONS ASPECT */

/* The container */

.radio-style {
  display: block;
  position: relative;
  padding-left: 25px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 13px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Hide the browser's default radio button */

.radio-style input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

/* Create a custom radio button */

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 18px;
  width: 18px;
  background-color: gainsboro;
  border-radius: 50%;
}

/* On mouse-over, add a grey background color */

.radio-style:hover input~.checkmark {
  background-color: #ccc;
}

/* When the radio button is checked, add a blue background */

.radio-style input:checked~.checkmark {
  background-color: black;
}

/* Create the indicator (the dot/circle - hidden when not checked) */

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

/* Show the indicator (dot/circle) when checked */

.radio-style input:checked~.checkmark:after {
  display: block;
}

/* Style the indicator (dot/circle) */

.radio-style .checkmark:after {
  top: 6px;
  left: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
}

/* SCROLLBAR */

/* width */

 ::-webkit-scrollbar {
  width: 8px;
}

/* Track */

 ::-webkit-scrollbar-track {
  background: #f1f1f1;
}

/* Handle */

 ::-webkit-scrollbar-thumb {
  background: #888;
}

/* Handle on hover */

 ::-webkit-scrollbar-thumb:hover {
  background: #555;
}

<!DOCTYPE html>

1. Section 1

Question 1

Question 2

Question 3

Question 4

2. Section 2

Question 1

Question 2

3. Section 3

Question 1

Question 2

Question 3

4. Section 4

Question 1

5. Section 5

Question 1

Question 2

Question 3

6. Section 6

Question 1

Question 2

Question 3

Question 4

Question 5

Section 1 out of 6

Question 1 out of 4

1. This is Question 1 ?

             More information
             Tooltip text

          Choice 1
                                <input type="radio" value="choice1" name="choice1">

          Choice 2
                                <input type="radio" value="choice1" name="choice1">

          Choice 3
                                <input type="radio" value="choice1" name="choice1">

          Choice 4
                                <input type="radio" value="choice1" name="choice1">

          Choice 5
                                <input type="radio" value="choice1" name="choice1">

          Choice 6
                                <input type="radio" value="choice1" name="choice1">

          Choice 7
                                <input type="radio" value="choice1" name="choice1">

          Choice 8
                                <input type="radio" value="choice1" name="choice1">

          Choice 9
                                <input type="radio" value="choice1" name="choice1">

          Choice 10
                                <input type="radio" value="choice1" name="choice1">

Body:
$( document ).ready(function() {

var height = $(".choices").height();

console.log(height);

$(".sections-choices").css("height",height);

});

        @import url('https://fonts.googleapis.com/css?family=Roboto:400,400i');

        * {
            font-family: Roboto, sans-serif !important;
        }

        @media screen and (max-width: 1300px) {

            .wrapper,
            .disclaimer {
                width: 90vw !important;
            }
        }

        body {
          height:438px;
        }

        .wrapper {
          height:438px;
        }

        ol {
            text-align: left;
        }

        .answered {
            font-weight: 900;
        }

        .answered::after {
            content: '•';
            color: black;
            margin-left: 10px;
            font-size: 15px;
        }

        .sections-choices {
            display: flex;
            align-items: flex-start;
            border: 1px solid #ddeafa;
            margin: 0 25px 15px 25px;
            width: 95%;
            margin-bottom: 15px;
            background-color: white;
            /* height: 300px;
            min-height: 300px;
            max-height: 350px; */

        }

        .sections {
            color: gainsboro;
            text-align: left;
            font-size: 13px;
            background-color: white;
            text-decoration: none;
            width: 20%;
            overflow: scroll;
            height:100%;
        }

        .sections .question-select {
            margin-left: 10px;
        }

        .sections h4 {
            padding: 5px 0 5px 15px;
            background-color: #3a3838;
            color: white;
            margin-top: 0;
        }

        .sections .intro-text {
            padding-top: 2.5px;
            padding-bottom: 2.5px;
        }

        .sections a {
            text-decoration: none;
            color: black;
            padding-left: 15px;
        }

        .choices {
            color: black;
            font-size: 14px;
            text-align: left;
            width: 80%;
            padding-bottom: 15px;
            height: inherit;
        }

        .choices-section-title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: auto;
            background-color: #3a3838;
        }

        .choices-section-title h4 {
            margin: 0;
            padding: 15px 15px;
            color: white;
        }

        .choices-title {
            padding: 10px 15px 0 15px;
            line-height: 19px;
        }

        .help-text {
            padding: 5px 15px 0 15px;
            text-align: right;
            font-size: 11px;
        }

        .help-text p {
            margin: 0;
        }

        .choices-radio {
            padding: 15px 15px 0 25px;
        }

        .choices-radio label {
            /* word-wrap: break-word; */
            white-space: normal;
        }

        .choices-radio input {
            margin-bottom: 10px;
        }

        /* TOOLTIP */

        .tooltip {
            position: relative;
            font-size: 12px;
            display: inline-flex;
            justify-content: flex-end;
            align-items: center;
            flex-direction: row;
            color: black;
        }

        .tooltip img {
            margin-right: 5px;
        }

        .tooltip .tooltiptext {
            visibility: hidden;
            width: 300px;
            background-color: #f7f7f7;
            color: black;
            text-align: left;
            border-radius: 6px;
            padding: 10px;
            /* Position the tooltip */
            position: absolute;
            z-index: 1;
            top: -5px;
            right: 105%;
        }

        .tooltip:hover .tooltiptext {
            visibility: visible;
        }

        /* CHANGE RADIO BUTTONS ASPECT */

        /* The container */

        .radio-style {
            display: block;
            position: relative;
            padding-left: 25px;
            margin-bottom: 12px;
            cursor: pointer;
            font-size: 13px;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        /* Hide the browser's default radio button */

        .radio-style input {
            position: absolute;
            opacity: 0;
            cursor: pointer;
        }

        /* Create a custom radio button */

        .checkmark {
            position: absolute;
            top: 0;
            left: 0;
            height: 18px;
            width: 18px;
            background-color: gainsboro;
            border-radius: 50%;
        }

        /* On mouse-over, add a grey background color */

        .radio-style:hover input~.checkmark {
            background-color: #ccc;
        }

        /* When the radio button is checked, add a blue background */

        .radio-style input:checked~.checkmark {
            background-color: black;
        }

        /* Create the indicator (the dot/circle - hidden when not checked) */

        .checkmark:after {
            content: "";
            position: absolute;
            display: none;
        }

        /* Show the indicator (dot/circle) when checked */

        .radio-style input:checked~.checkmark:after {
            display: block;
        }

        /* Style the indicator (dot/circle) */

        .radio-style .checkmark:after {
            top: 6px;
            left: 6px;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: white;
        }

        /* SCROLLBAR */
        /* width */

        ::-webkit-scrollbar {
            width: 8px;
        }

        /* Track */

        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }

        /* Handle */

        ::-webkit-scrollbar-thumb {
            background: #888;
        }

        /* Handle on hover */

        ::-webkit-scrollbar-thumb:hover {
            background: #555;
        }

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body style="margin: 0 auto; max-height: 70vh; background-color: #DCE3EA; text-align: center; margin-top: 15px; font-family: Roboto Condensed, sans-serif;">
    <div class="wrapper">

        <div class="sections-choices">
            <div class="sections">
                <h4>1. Section 1</h4>
                <p class="question-select"><a href="">Question 1</a></p>
                <p class="question-select"><a href="">Question 2</a></p>
                <p class="question-select"><a href="">Question 3</a></p>
                <p class="question-select"><a href="">Question 4</a></p>

                <h4>2. Section 2</h4>
                <p class="question-select"><a href="">Question 1</a></p>
                <p class="question-select"><a href="">Question 2</a></p>

                <h4>3. Section 3</h4>
                <p class="question-select"><a href="">Question 1</a></p>
                <p class="question-select"><a href="">Question 2</a></p>
                <p class="question-select"><a href="">Question 3</a></p>

                <h4>4. Section 4</h4>
                <p class="question-select"><a href="">Question 1</a></p>

                <h4>5. Section 5</h4>
                <p class="question-select"><a href="">Question 1</a></p>
                <p class="question-select"><a href="">Question 2</a></p>
                <p class="question-select"><a href="">Question 3</a></p>

                <h4>6. Section 6</h4>
                <p class="question-select"><a href="">Question 1</a></p>
                <p class="question-select"><a href="">Question 2</a></p>
                <p class="question-select"><a href="">Question 3</a></p>
                <p class="question-select"><a href="">Question 4</a></p>
                <p class="question-select"><a href="">Question 5</a></p>
            </div>
            <div class="choices">
                <div class="choices-section-title">
                    <h4>Section 1 out of 6</h4>
                    <h4>Question 1 out of 4</h4>
                </div>
                <div class="choices-title"><b>1. This is Question 1 ?</b></div>
                <div class="help-text">
                    <div class="tooltip">
                        <img src="" width="18px"> More information
                        <span class="tooltiptext"> Tooltip text </span>
                    </div>
                </div>
                <div class="choices-radio">
                    <label class="radio-style">Choice 1
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 2
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 3
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 4
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 5
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 6
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 7
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 8
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 9
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>

                    <label class="radio-style">Choice 10
                        <input type="radio" value="choice1" name="choice1"><br>
                        <span class="checkmark"></span>
                    </label>
                </div>
            </div>
        </div>
    </div>
</body>


问:
Java library for Java to EDI conversion
I am looking for a Java library that does Java to EDI conversion -
more specifically an EDI 835 format used in Healthcare.
Although a lot of libraries promise Java to EDI conversion, there is no
documentation or code samples available for the same on their sites.
Here is a list of libraries I have tried so far with no luck:

    1. EdiReader(EdiWriter is commercial and does not have a trial download).

    2. Smooks(No trial download and documentation does not mention Java to EDI conversion).

    3. Open Business Objects - OBOE from americancoders.com(Has a trial download but Java to    EDI not mentioned).

    4. Oakland data transformer(This doesn't even let me download the library and docs).

Does anyone know other solutions that might be helpful ?

I am open to any commercial solution too.

Thanks!

答:
I agree that there are very few open source libraries in the market which can help on EDI to xml conversion. Many of them have not been updated for years. I visited the "Smooks" site and it seems, that the project has been discontinued.

If you are okay with paying for a solution, you may give EDI parser from Progress a try.

It comes with a free trial version for 15 days and the apis are very easy to use and integrate in your project.

It does not only support EDI to xml conversion, but also EDI to CSV conversion (you have the option to decide the delimiter).

Title: Java library for Java to EDI conversion


问:
Converting Java class structure to yml file
I have a complex model class in Java that has attributes of different class. I wanted to get the schema of the class in yml format for better readability. I was able get the structure of the class to a JSON file but I feel that yml is less cluttered and easy to ready.

Example
From

```<code>public class Phone {
    public String name;
    public String number;
}
</code>```

To

```<code>Phone:
    fields:
      name:
        type: String
      number:
        type: String
</code>```

答:
From RAM to File

If your use case is to just serialize your existing objects, without reading them first, you might try the approach from this answer using Jackson; it just writes to a file an example object.

```<code>// Create an ObjectMapper mapper for YAML
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

// Write object as YAML file
mapper.writeValue(new File("/path/to/yaml/file"), example);
</code>```

Body:
I have a complex model class in Java that has attributes of different class. I wanted to get the schema of the class in yml format for better readability. I was able get the structure of the class to a JSON file but I feel that yml is less cluttered and easy to ready.

Example
From

public class Phone {
    public String name;
    public String number;
}

To

Phone:
    fields:
      name:
        type: String
      number:
        type: String

Body:
From RAM to File

If your use case is to just serialize your existing objects, without reading them first, you might try the approach from this answer using Jackson; it just writes to a file an example object.

// Create an ObjectMapper mapper for YAML
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

// Write object as YAML file
mapper.writeValue(new File("/path/to/yaml/file"), example);


问:
How to get the cell object in tableView:(UITableView *)tableView heightForRowAtIndexPath function?
I wand to know the content of the cell when returning the heightForRowAtIndexPath. In this function how do I get the cell object?

```<code>- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

}
</code>```

If I try this

```<code> [tableView cellForRowAtIndexPath:indexPath]
</code>```

it fails and goes off in an infinite loop.

Any idea?

答:
Call self (the delegate) rather than the tableView itself.</p>

```<code>id cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
</code>```

Body:
I wand to know the content of the cell when returning the heightForRowAtIndexPath. In this function how do I get the cell object?

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

}

If I try this

 [tableView cellForRowAtIndexPath:indexPath]

it fails and goes off in an infinite loop.

Any idea?

Body:
Call self (the delegate) rather than the tableView itself.

id cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];


问:
Count frequency of text in list in dataframe
I’m new to python / pandas but have a question which I’ll ask logically to help me learn

I have a dataframe called parties with the following data

```<code>(index)    name                  invitees
0            birthday party     [mike, peter]
1            Retirement          [peter]
2            office opening     [simon, mike, peter]
</code>```

I’d like to be able to create a dictionary which will show the distinct names from the invitees column along with frequency e.g. something like this

```<code>mike: 2, peter: 3, simon: 1
</code>```

I’ve tried to find something similar on here but I’m not too sure of the right terminology to use.

Any help would be greatly appreciated
Thanks a lot

答:
just for fun

```<code>df['invitees'].apply(pd.Series).unstack().reset_index(name='n').drop('level_1', axis=1).dropna().groupby('n').count().to_dict()['level_0']
</code>```

```<code>{'mike': 2, 'peter': 3, 'simon': 1}
</code>```

Body:
I’m new to python / pandas but have a question which I’ll ask logically to help me learn

I have a dataframe called parties with the following data

(index)    name                  invitees
0            birthday party     [mike, peter]
1            Retirement          [peter]
2            office opening     [simon, mike, peter]

I’d like to be able to create a dictionary which will show the distinct names from the invitees column along with frequency e.g. something like this

mike: 2, peter: 3, simon: 1

I’ve tried to find something similar on here but I’m not too sure of the right terminology to use.

Any help would be greatly appreciated
Thanks a lot

Body:
just for fun

df['invitees'].apply(pd.Series).unstack().reset_index(name='n').drop('level_1', axis=1).dropna().groupby('n').count().to_dict()['level_0']

{'mike': 2, 'peter': 3, 'simon': 1}


问:
HikariPool-1 - Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)
i,m creating a simple maven project with spring boot and hibernate and i want to create my table in mysqlDB with hibernate.when i run my spring application its not creating my table and i have no error but title massage will appear and i think this is the cause of my problem

```<code>`2019-05-31 14:02:54.781  INFO 25517 --- [  restartedMain] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)`
</code>```

pom.xml:

```<code>`<?xml version="1.0" encoding="UTF-8"?>
</code>```

http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0

```<code><groupId>Example</groupId>
<artifactId>Example</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.5.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
        <version>2.0.0.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
        <version>2.0.0.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.12.Final</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.2</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.0.1.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>5.0.1.RELEASE</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.16</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
</dependencies>
</code>```

`

application.properties:

```<code>spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.datasource.password=dani861
spring.datasource.username=root
spring.jooq.sql-dialect=org.hibernate.dialect.MySQLDialect
</code>```

RUN:

```<code>2019-05-31 14:35:54.116  INFO 26667 --- [  restartedMain] c.e.configuration.SpringConfiguration    : Starting SpringConfiguration on Daniyal with PID 26667 (/home/daniyal/IdeaProjects/Example/target/classes started by daniyal in /home/daniyal/IdeaProjects/Example)
2019-05-31 14:35:54.119  INFO 26667 --- [  restartedMain] c.e.configuration.SpringConfiguration    : No active profile set, falling back to default profiles: default
2019-05-31 14:35:54.164  INFO 26667 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-05-31 14:35:54.165  INFO 26667 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-05-31 14:35:54.848  INFO 26667 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-05-31 14:35:54.869  INFO 26667 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 repository interfaces.
2019-05-31 14:35:55.259  INFO 26667 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$4830e052] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-05-31 14:35:55.598  INFO 26667 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-05-31 14:35:55.631  INFO 26667 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-31 14:35:55.631  INFO 26667 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
2019-05-31 14:35:55.715  INFO 26667 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-05-31 14:35:55.715  INFO 26667 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1550 ms
2019-05-31 14:35:55.868  INFO 26667 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-05-31 14:35:56.075  INFO 26667 --- [  restartedMain] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)
2019-05-31 14:35:56.077  INFO 26667 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-05-31 14:35:56.117  INFO 26667 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-05-31 14:35:56.163  INFO 26667 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.12.Final}
2019-05-31 14:35:56.164  INFO 26667 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000205: Loaded properties from resource hibernate.properties: {jdbc.url=jdbc:mysql://localhost/3306/test, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.show_sql=true, jdbc.user=root, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=create-drop, jdbc.driverClassName=org.h2.Driver, jdbc.pass=dani861}
2019-05-31 14:35:56.192  INFO 26667 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-05-31 14:35:56.282  INFO 26667 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-05-31 14:35:56.306  INFO 26667 --- [  restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
2019-05-31 14:35:56.454  INFO 26667 --- [  restartedMain] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@cf13b9f'
2019-05-31 14:35:56.456  INFO 26667 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-05-31 14:35:56.473  INFO 26667 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2019-05-31 14:35:56.680  INFO 26667 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-31 14:35:56.717  WARN 26667 --- [  restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-05-31 14:35:56.957  INFO 26667 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-31 14:35:56.960  INFO 26667 --- [  restartedMain] c.e.configuration.SpringConfiguration    : Started SpringConfiguration in 3.121 seconds (JVM running for 3.414)
</code>```

答:
Looking at your log, it seems to me that hibernate is using properties from hibernate.properties

```<code>2019-05-31 14:35:56.164  INFO 26667 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000205: Loaded properties from resource hibernate.properties: {jdbc.url=jdbc:mysql://localhost/3306/test, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.show_sql=true, jdbc.user=root, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=create-drop, jdbc.driverClassName=org.h2.Driver, jdbc.pass=dani861}
</code>```

This line is showing that it's trying to use the H2 Database as driver and dialect.

In your pom.xml, you are declaring all de dependencies to spring data jpa e hibernate but using spring boot it makes more sense if you use the spring-boot-starter-jpa dependency. It provides auto-configuration classes to help you.

Take a look at this guide: Link

Body:
i,m creating a simple maven project with spring boot and hibernate and i want to create my table in mysqlDB with hibernate.when i run my spring application its not creating my table and i have no error but title massage will appear and i think this is the cause of my problem

`2019-05-31 14:02:54.781  INFO 25517 --- [  restartedMain] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)`

pom.xml:

`<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0

<groupId>Example</groupId>
<artifactId>Example</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.5.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
        <version>2.0.0.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
        <version>2.0.0.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.12.Final</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.2</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.0.1.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>5.0.1.RELEASE</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.16</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
</dependencies>

`

application.properties:

spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.datasource.password=dani861
spring.datasource.username=root
spring.jooq.sql-dialect=org.hibernate.dialect.MySQLDialect

RUN:

2019-05-31 14:35:54.116  INFO 26667 --- [  restartedMain] c.e.configuration.SpringConfiguration    : Starting SpringConfiguration on Daniyal with PID 26667 (/home/daniyal/IdeaProjects/Example/target/classes started by daniyal in /home/daniyal/IdeaProjects/Example)
2019-05-31 14:35:54.119  INFO 26667 --- [  restartedMain] c.e.configuration.SpringConfiguration    : No active profile set, falling back to default profiles: default
2019-05-31 14:35:54.164  INFO 26667 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-05-31 14:35:54.165  INFO 26667 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-05-31 14:35:54.848  INFO 26667 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-05-31 14:35:54.869  INFO 26667 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 repository interfaces.
2019-05-31 14:35:55.259  INFO 26667 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$4830e052] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-05-31 14:35:55.598  INFO 26667 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-05-31 14:35:55.631  INFO 26667 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-31 14:35:55.631  INFO 26667 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
2019-05-31 14:35:55.715  INFO 26667 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-05-31 14:35:55.715  INFO 26667 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1550 ms
2019-05-31 14:35:55.868  INFO 26667 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-05-31 14:35:56.075  INFO 26667 --- [  restartedMain] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)
2019-05-31 14:35:56.077  INFO 26667 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-05-31 14:35:56.117  INFO 26667 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-05-31 14:35:56.163  INFO 26667 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.12.Final}
2019-05-31 14:35:56.164  INFO 26667 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000205: Loaded properties from resource hibernate.properties: {jdbc.url=jdbc:mysql://localhost/3306/test, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.show_sql=true, jdbc.user=root, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=create-drop, jdbc.driverClassName=org.h2.Driver, jdbc.pass=dani861}
2019-05-31 14:35:56.192  INFO 26667 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-05-31 14:35:56.282  INFO 26667 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-05-31 14:35:56.306  INFO 26667 --- [  restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
2019-05-31 14:35:56.454  INFO 26667 --- [  restartedMain] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@cf13b9f'
2019-05-31 14:35:56.456  INFO 26667 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-05-31 14:35:56.473  INFO 26667 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2019-05-31 14:35:56.680  INFO 26667 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-31 14:35:56.717  WARN 26667 --- [  restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-05-31 14:35:56.957  INFO 26667 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-31 14:35:56.960  INFO 26667 --- [  restartedMain] c.e.configuration.SpringConfiguration    : Started SpringConfiguration in 3.121 seconds (JVM running for 3.414)

Body:
Looking at your log, it seems to me that hibernate is using properties from hibernate.properties

2019-05-31 14:35:56.164  INFO 26667 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000205: Loaded properties from resource hibernate.properties: {jdbc.url=jdbc:mysql://localhost/3306/test, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.show_sql=true, jdbc.user=root, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=create-drop, jdbc.driverClassName=org.h2.Driver, jdbc.pass=dani861}

This line is showing that it's trying to use the H2 Database as driver and dialect.

In your pom.xml, you are declaring all de dependencies to spring data jpa e hibernate but using spring boot it makes more sense if you use the spring-boot-starter-jpa dependency. It provides auto-configuration classes to help you.

Take a look at this guide: Link


问:
Three time same class instance but slightly different instance values
I have a class with a bunch of instance variables. Now I want to create three instances of this class, where most of the values are same, but only a few of them have different values. Are there some possibilities or concepts to do this without (deep) cloning one instance? Are subclasses for these instances the best way?

I have thought about cloning one instance, but my classes are deep nested and also this seems to be inefficient.

This is the class I have. In my case, most of the variables stay the same but shortDescription has different values among those three instances.

export default class Event extends Base {
  public id!: number;
  public afterbuyId!: number;
  public shopId!: number;

  public name!: string;
  public sellingPrice!: number;
  public taxRate!: number;
  public level!: number;
  public shortDescription!: string;
  public startDate!: Date;
  public startTime!: Date;
  public endDate!: Date;
  public endTime!: Date;
  public quantityCheckProduct!: boolean;
  public active!: boolean;

  public venues: Venue[] = [];
  public bundles: Bundle[] = [];
  public paymentMethods: PaymentMethod[] = [];
  public deliveryMethods: DeliveryMethod[] = [];
  public categories: Category[] = [];
}
```

Ignore the fact, that the variables are public.

答:
Ok, I already found a solution. I'll return an array of objects consisting of the needed variables and their values:

public generateRequestObject(): any {
    return [
      {
        "name": this.name,
        "sellingPrice": this.sellingPrice
      },
      {
        "name": `MP ${this.name}`,
        "sellingPrice": this.sellingPrice
      }
    ];
  }
```

Body:
I have a class with a bunch of instance variables. Now I want to create three instances of this class, where most of the values are same, but only a few of them have different values. Are there some possibilities or concepts to do this without (deep) cloning one instance? Are subclasses for these instances the best way?

I have thought about cloning one instance, but my classes are deep nested and also this seems to be inefficient.

This is the class I have. In my case, most of the variables stay the same but shortDescription has different values among those three instances.

export default class Event extends Base {
  public id!: number;
  public afterbuyId!: number;
  public shopId!: number;

  public name!: string;
  public sellingPrice!: number;
  public taxRate!: number;
  public level!: number;
  public shortDescription!: string;
  public startDate!: Date;
  public startTime!: Date;
  public endDate!: Date;
  public endTime!: Date;
  public quantityCheckProduct!: boolean;
  public active!: boolean;

  public venues: Venue[] = [];
  public bundles: Bundle[] = [];
  public paymentMethods: PaymentMethod[] = [];
  public deliveryMethods: DeliveryMethod[] = [];
  public categories: Category[] = [];
}

Ignore the fact, that the variables are public.


问:
How to change the position of the object when the window size is changed?
As in the title. I would like objects moving on the board to change position propositionally to change the size of the window. How to do it?</p>

答:
You can use the componentResized method to recalculate the pieces' positions based on the actual frame size

public static void main(String[] args) {
    JPanel panel = new JPanel() {
      @Override
      public Dimension getPreferredSize() {
        return new Dimension(200, 200);
      }
    };
    panel.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
        System.out.println("Resized to " + e.getComponent().getSize());
      }
      @Override
      public void componentMoved(ComponentEvent e) {
        System.out.println("Moved to " + e.getComponent().getLocation());
      }
    });
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("test", panel);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(tabbedPane);
    frame.pack();

    frame.setVisible(true);
}
```


问:
SELECT AVG(invoiceamount) per debtor where date< date row
I have a SQL table with the following columns: Invoice ID, debtor ID, invoice date and invoice amount. where invoice ID is unique.

I'm trying to create an extra column with the average invoice amount. So per row I want the average invoice amount of the debtor, but only of the invoices where the invoice date <= the invoicedate of the column.

I'm not sure where to start, all ideas are welcome

答:
You want to use window functions:

```<code>select t.*,
       avg(invoice_amount) over (partition by debtor_id order by invoice_date) as running_average
from t;
</code>```

I strongly recommend this over a correlated subquery because it should be much faster -- even if you attempt to optimize the correlated subquery with indexes.

Body:
You want to use window functions:

select t.*,
       avg(invoice_amount) over (partition by debtor_id order by invoice_date) as running_average
from t;

I strongly recommend this over a correlated subquery because it should be much faster -- even if you attempt to optimize the correlated subquery with indexes.


问:
What is the most useful script you've written for everyday life?
Just wondering what little scripts/programs people here have written that helps one with his or her everyday life (aka not work related).

Anything goes, groundbreaking or not. For me right now, it's a small python script to calculate running pace given distance and time elapsed.

答:
Well an AutoHotkey script that make my life within reach of only a keyboard:

often used app, folder, etc. within
one win+ combination. That often means activating the application if already launched, and else launch the application

"double-click" of ctrl to launch Launchy - which leads to a few keypresses from my not so often used apps

add a bunch of missing keyboard shortcuts in windows explorer (XP) such as create new folder, toggle hidden file/show file extension, Ctrl-Enter to open any file as text file in emacs, open command line window (cmd and cygwin shell) with the current path set, etc. etc.

Windows manipulation: move, resize, send to next monitor, max/minimize, toggle always on top, change transparency, etc etc. all with just key combinations

Misc such as hibernate, eject external drives, google any selected word (in any app where ctrl-c as copy works), shutdown timer, etc. etc. Everything with just one key combination

This keyboard script just make me such a happy-camper; and it is in fact the major reason that I'm still using windows instead of linux as my primary platform since autohotkey only works on windows.

OwnerDisplayName: Kyle Walsh

ContentLicense: CC BY-SA 2.5

LastEditorDisplayName: Kyle Walsh

OwnerDisplayName: polyglot


问:
How to make height of a dijit Accordionpane dynamic
I can't figure out how to tell the accordioncontainer to set height of its accordion pane to auto so that the height of the pane is dynamic depending on its content.

In the following code I am adding two panes to an accordioncontainer. One has height of 10px and another has 90px but in both cases the height of the accordion pane is calculated to 10px. Looks like its always taking the height of the first one.

```<code>var accordionContainer = new dijit.layout.AccordionContainer({'id':'accContainer'}).placeAt("test");
var accordPane = new dijit.layout.ContentPane({"title": "test", "content":"<div style='height:10px'>sdfsdfsdf</div>"});
var accordPane2 = new dijit.layout.ContentPane({"title": "test1", "content":"<div style='height:90px'>sdfsdfsdf</div>"});

accordionContainer.addChild(accordPane);
accordionContainer.addChild(accordPane2, 1);
accordPane.startup();
accordPane2.startup();
accordionContainer.startup();
accordionContainer.selectChild(accordPane2);
</code>```

I am using dojo 1.3.2

答: Now you can also just use dijit.TitlePanes with no container at all.  You can pass open: false when you instantiate the panes to start them off closed.  I think enclosing them in a dojox.widget.TitleGroup will emulate the behavior of having 1 open at a time.

Body:
I can't figure out how to tell the accordioncontainer to set height of its accordion pane to auto so that the height of the pane is dynamic depending on its content.

In the following code I am adding two panes to an accordioncontainer. One has height of 10px and another has 90px but in both cases the height of the accordion pane is calculated to 10px. Looks like its always taking the height of the first one.

var accordionContainer = new dijit.layout.AccordionContainer({'id':'accContainer'}).placeAt("test");
var accordPane = new dijit.layout.ContentPane({"title": "test", "content":"
sdfsdfsdf
"});
var accordPane2 = new dijit.layout.ContentPane({"title": "test1", "content":"
sdfsdfsdf
"});

accordionContainer.addChild(accordPane);
accordionContainer.addChild(accordPane2, 1);
accordPane.startup();
accordPane2.startup();
accordionContainer.startup();
accordionContainer.selectChild(accordPane2);

I am using dojo 1.3.2


问:
Want to have checkbox already checked when data is loaded
I am using bootstrap-table (https://bootstrap-table.com/) and loading data via json.  All data is currently loading correctly - an id field, checkbox field, and name. I load the data into an array, then into the table. However, I want certain records to have the checkbox already selected, depending on certain things.  How do I pass this via the array below?

The scenario below does not work.

Here is how I am preparing my array in php:

```<code>$user_accounts[] = array(
  'id' => $i,
  'selected' => 'true',          -- this is the checkbox
  'name' => $name
);
</code>```

My table is set up with these columns:

```<code>{ field: 'id', colspan: 1 },
{ field: 'bs-checkbox' },
{ field: 'name', align: center }
</code>```

I get my data from an ajax call:

```<code>$.ajax
.....
success:  function(data);
var opts = $.parseJSON(data);
$('.userTable').bootstrapTable(load,opts);
</code>```

I thought sending 'true' to the checkbox would cause the checkbox to be checked, but that does not seem to be the case.

My HTML is set up as follows:

```<code><th data-field="id"></th>
<th data-field="state" data-checkbox=true"></th>
<th data-field="cn">Name</th>
<th data-field="selected">Selected</th>
</code>```

答:
You can use the built-in bootstrap-table check method as:

```<code>$('.userTable').bootstrapTable('check', 1);
</code>```

Where 1 is the row index that of the row that you want to be checked.

In your case you should place this code after table has loaded.

Body:
I am using bootstrap-table (https://bootstrap-table.com/) and loading data via json.  All data is currently loading correctly - an id field, checkbox field, and name. I load the data into an array, then into the table. However, I want certain records to have the checkbox already selected, depending on certain things.  How do I pass this via the array below?

The scenario below does not work.

Here is how I am preparing my array in php:

$user_accounts[] = array(
  'id' => $i,
  'selected' => 'true',          -- this is the checkbox
  'name' => $name
);

My table is set up with these columns:

{ field: 'id', colspan: 1 },
{ field: 'bs-checkbox' },
{ field: 'name', align: center }

I get my data from an ajax call:

$.ajax
.....
success:  function(data);
var opts = $.parseJSON(data);
$('.userTable').bootstrapTable(load,opts);

I thought sending 'true' to the checkbox would cause the checkbox to be checked, but that does not seem to be the case.

My HTML is set up as follows:

Name
Selected

Body:
You can use the built-in bootstrap-table check method as:

$('.userTable').bootstrapTable('check', 1);

Where 1 is the row index that of the row that you want to be checked.

In your case you should place this code after table has loaded.


问:
PHP redirect buttons in DataTables are not working
I'm generating a table using PHP that will retrieve records from a MySQL database. I'm new to DataTables, and my problem is that the "View Products" button that generates along with the table doesn't work. Clicking the button should redirect to a new page with an entirely different table.

here's a screenshot of what it looks like, just in case I'm not making any sense

Here's the entire code for the page.

<!DOCTYPE html>

  <title></title>
  <link rel="stylesheet" type="text/css" href="\WEBDEV\css\reset.css">
  <link rel="stylesheet" type="text/css" href="\WEBDEV\css\stylesheet.css">
  <link rel="stylesheet" type="text/css" href="\WEBDEV\css\og_stylesheet.css">

  <?php include "includes/header.php" ?>

  <?php session_start();

?>

                    Supplier ID
                    Name
                    Address
                    Contact Number
                    Supplier Details

                  <?php
                      $conn = mysqli_connect("localhost", "root", "", "web_db");
                      $query = "SELECT * FROM Suppliers";
                      $search = mysqli_query($conn, $query);
                        if(mysqli_num_rows($search) > 0 ){
                          while($row = mysqli_fetch_array($search)){
                          ?>
                    <form action="supplierdetails.php" method="POST">

                          <?= $row['supplier_id']?>

                        <input type="hidden" value=< ?=$row[ 'supplier_id']?> name = "sup_id">
                        <input type="hidden" value=< ?=$row[ 'name']?> name = "name">

                          <?= $row['name']?>

                          <?= $row['address']?>

                          <?= $row['contactnumber']?>

                        <input type="submit" name="sub" value="View Products" class="btn btn-info" onclick="sample()">

                    </form>
                    <?php
                          }
                        }
                      ?>

  -->

```

The buttons work perfectly before I added DataTables, by the way. I also found out that a table with hard-coded data (as in without PHP) also have buttons that work fine. I'm pretty much at my wits end here. Any help will be appreciated.

答:
Remove the onclick="sample()"
Add this in a document.ready

```<code>$(".btn-info").on("click", function() {
    window.alert(document.getElementById("name").getAttribute("value"));
});
</code>```

Maybe use a window.alert('test');
since I dont see the element with the id name anywhere

Body:
I'm generating a table using PHP that will retrieve records from a MySQL database. I'm new to DataTables, and my problem is that the "View Products" button that generates along with the table doesn't work. Clicking the button should redirect to a new page with an entirely different table.

here's a screenshot of what it looks like, just in case I'm not making any sense

Here's the entire code for the page.

<!DOCTYPE html>

  <title></title>
  <link rel="stylesheet" type="text/css" href="\WEBDEV\css\reset.css">
  <link rel="stylesheet" type="text/css" href="\WEBDEV\css\stylesheet.css">
  <link rel="stylesheet" type="text/css" href="\WEBDEV\css\og_stylesheet.css">

  <?php include "includes/header.php" ?>

  <?php session_start();

?>

                    Supplier ID
                    Name
                    Address
                    Contact Number
                    Supplier Details

                  <?php
                      $conn = mysqli_connect("localhost", "root", "", "web_db");
                      $query = "SELECT * FROM Suppliers";
                      $search = mysqli_query($conn, $query);
                        if(mysqli_num_rows($search) > 0 ){
                          while($row = mysqli_fetch_array($search)){
                          ?>
                    <form action="supplierdetails.php" method="POST">

                          <?= $row['supplier_id']?>

                        <input type="hidden" value=< ?=$row[ 'supplier_id']?> name = "sup_id">
                        <input type="hidden" value=< ?=$row[ 'name']?> name = "name">

                          <?= $row['name']?>

                          <?= $row['address']?>

                          <?= $row['contactnumber']?>

                        <input type="submit" name="sub" value="View Products" class="btn btn-info" onclick="sample()">

                    </form>
                    <?php
                          }
                        }
                      ?>

  -->

The buttons work perfectly before I added DataTables, by the way. I also found out that a table with hard-coded data (as in without PHP) also have buttons that work fine. I'm pretty much at my wits end here. Any help will be appreciated.

Body:
Remove the onclick="sample()"
Add this in a document.ready

$(".btn-info").on("click", function() {
    window.alert(document.getElementById("name").getAttribute("value"));
});

Maybe use a window.alert('test');
since I dont see the element with the id name anywhere


问:
Reshaping database using reshape package
I would like to reshaping some rows of my database. In particular I have some row that it replicate for the Id column. I would like to convert this row in column. I provide a code that it represent a example of my database.
I'm trying with t() and reshape but it doesn't do that I would. Can anyone give me any suggestions?</p>

```<code>test<-data.frame(Id=c(1,1,2,3),
    St=c(20,80,80,20),
    gap=seq(0.02,0.08,by=0.02),
    gip=c(0.23,0.60,0.86,2.09),
    gat=c(0.0107,0.989,0.337,0.663))
</code>```

Body:
I would like to reshaping some rows of my database. In particular I have some row that it replicate for the Id column. I would like to convert this row in column. I provide a code that it represent a example of my database.
I'm trying with t() and reshape but it doesn't do that I would. Can anyone give me any suggestions?

test<-data.frame(Id=c(1,1,2,3),
    St=c(20,80,80,20),
    gap=seq(0.02,0.08,by=0.02),
    gip=c(0.23,0.60,0.86,2.09),
    gat=c(0.0107,0.989,0.337,0.663))

Body:
setNames(data.frame(t(test))[2:nrow(data.frame(t(test))),], test$Id)

          1      1      2      3
St  20.0000 80.000 80.000 20.000
gap  0.0200  0.040  0.060  0.080
gip  0.2300  0.600  0.860  2.090
gat  0.0107  0.989  0.337  0.663

It helps to provide an expected output. It this what you expected?


问:
How to write a string algorithm
given a FASTA text file (Rosalind_gc.txt), I am supposed to go through each DNA record and identify the percentage (%) of Guanine-Cytosine (GC) content.

Example of this is :

Sample Dataset:

```<code>>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT
</code>```

Sample output:

Rosalind_0808
60.919540

So basically go through each string, count the amt of times G/C show up and then divide that total by the length of each string. My issue is learning how to identify the breaks in code (i.e. >Rosalind_6404 ). I would like an example of this code without using Biopython and also with the biopython approach.

答:
Since you're looking for a Biopython solution, here is a very simple one:

```<code>from Bio import SeqIO
from Bio.SeqUtils import GC

for r in SeqIO.parse('Rosalind_gc.fa', 'fasta'):
    print(r.id, GC(r.seq))
</code>```

Outputs:

```<code>Rosalind_6404 53.75
Rosalind_5959 53.57142857142857
Rosalind_0808 60.91954022988506
</code>```

Title: How to write a string algorithm

Body:
given a FASTA text file (Rosalind_gc.txt), I am supposed to go through each DNA record and identify the percentage (%) of Guanine-Cytosine (GC) content.

Example of this is :

Sample Dataset:

>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT

Sample output:

Rosalind_0808
60.919540

So basically go through each string, count the amt of times G/C show up and then divide that total by the length of each string. My issue is learning how to identify the breaks in code (i.e. >Rosalind_6404 ). I would like an example of this code without using Biopython and also with the biopython approach.

Body:
Since you're looking for a Biopython solution, here is a very simple one:

from Bio import SeqIO
from Bio.SeqUtils import GC

for r in SeqIO.parse('Rosalind_gc.fa', 'fasta'):
    print(r.id, GC(r.seq))

Outputs:

Rosalind_6404 53.75
Rosalind_5959 53.57142857142857
Rosalind_0808 60.91954022988506