问:
Scanning Bigtable by prefix with Python SDKs
I'm trying to perform searches by multiple prefixes at Google Cloud Bigtable with the Python SDK. I'm using read_rows, and I can't see a good way to search by prefix explicitly.

My first option is RowSet + RowRange. I'm testing three queries, and the times that I'm getting are ~1.5s, ~3.5s and ~4.2s, which are an order of magnitude slower than the searches with the Node SDK (which has a filter option) ~0.19, ~0.13, ~0.46.

The second option is using RowFilterChain + RowKeyRegexFilter. Performance is terrible for two of the queries: ~3.1s, ~70s, ~75s ~0.124s, ~72s, ~69s. It looks like it's doing a full scan. This is the code section:

```<code>            regex = f'^{prefix}.*'.encode()
            filters.append(RowKeyRegexFilter(regex))
</code>```

My third option is using the alternative Happybase-based SDK, which has prefix filtering. With that, I'm getting ~36s, ~3s, ~1s ~0.4, ~0.1, ~0.17. The first query involves multiple prefixes, and it doesn't seem to have support for multiple filtering in the same request, so I'm performing as many requests as prefixes and then concatenating the iterators. The other two seem to leverage the prefix filter.

UPDATE: I deleted the first times because there was a mistake with the environment. After doing it properly, times are not bad for range query, but it seems to be room for improvement, as Happybase tests are still faster when they leverage prefix search.

Would appreciate help about using multiple prefix searches in Happybase, or actual prefix search in the main Python SDK.

答:
The read_rows method have two parameters start_key and end_key that you can use to filter efficiently rows based on the row key (see docs). Behind the scenes, this method performs a Scan, so that's why this is probably the most efficient way to filter rows based on their row keys.

For example, let's suppose you have the following row keys in your table :

```<code>a
aa
b
bb
bbb
</code>```

and you want to retrieve all rows with a row key prefixed by a, you can run :

```<code>rows_with_prefix_a = my_table.read_rows(start_key="a", end_key="b")
</code>```

This will only scan rows between a and b (b excluded), so this will return all rows with row key prefix a (a and aa in the previous example).

Body:
I'm trying to perform searches by multiple prefixes at Google Cloud Bigtable with the Python SDK. I'm using read_rows, and I can't see a good way to search by prefix explicitly.

My first option is RowSet + RowRange. I'm testing three queries, and the times that I'm getting are ~1.5s, ~3.5s and ~4.2s, which are an order of magnitude slower than the searches with the Node SDK (which has a filter option) ~0.19, ~0.13, ~0.46.

The second option is using RowFilterChain + RowKeyRegexFilter. Performance is terrible for two of the queries: ~3.1s, ~70s, ~75s ~0.124s, ~72s, ~69s. It looks like it's doing a full scan. This is the code section:

            regex = f'^{prefix}.*'.encode()
            filters.append(RowKeyRegexFilter(regex))

My third option is using the alternative Happybase-based SDK, which has prefix filtering. With that, I'm getting ~36s, ~3s, ~1s ~0.4, ~0.1, ~0.17. The first query involves multiple prefixes, and it doesn't seem to have support for multiple filtering in the same request, so I'm performing as many requests as prefixes and then concatenating the iterators. The other two seem to leverage the prefix filter.

UPDATE: I deleted the first times because there was a mistake with the environment. After doing it properly, times are not bad for range query, but it seems to be room for improvement, as Happybase tests are still faster when they leverage prefix search.

Would appreciate help about using multiple prefix searches in Happybase, or actual prefix search in the main Python SDK.

Body:
The read_rows method have two parameters start_key and end_key that you can use to filter efficiently rows based on the row key (see docs). Behind the scenes, this method performs a Scan, so that's why this is probably the most efficient way to filter rows based on their row keys.

For example, let's suppose you have the following row keys in your table :

a
aa
b
bb
bbb

and you want to retrieve all rows with a row key prefixed by a, you can run :

rows_with_prefix_a = my_table.read_rows(start_key="a", end_key="b")

This will only scan rows between a and b (b excluded), so this will return all rows with row key prefix a (a and aa in the previous example).


来源: stackexchange

问:
React disable and enable button based on parent input function and click of button
So basically i have a parent component which uses a child button component. Basically currently when the input validation is not correct it will keep the button disabled. However now I have tried to disable the button on click. The button is currently a pure component and i started to use hooks but not sure how i can still get the validation running.

Code is below

```<code><ChildButton
            onClick={() => {
              this.checkSomething= this.checkCreds();
            }}
            enabled={this.validateInput()}
          />
</code>```

My pure component currently looks like this:

```<code>export function AButton({ onClick, enabled, text }) {
  const [disabled, setDisabled] = useState(!enabled);

  function handleClick() {
    setDisabled(!disabled);
    //onClick();
  }
  return (
    <Button
      style={{ display: "block", margin: "auto" }}
      id="next-button"
      onClick={handleClick}
      disabled={disabled}
    >
      {text}
    </Button>
  );
}
</code>```

So i can get the disable button to work in both scenairos. As the enabled is always being passed down into this pure component so need to keep setting state of it.

答:
I ended up using useEffect from react hooks

```<code>useEffect(() => setDisabled(!enabled), [enabled]);
</code>```

This will check every time the enabled props is updated from the parent. Similar to how componentDidUpdate would work

ContentLicense: CC BY-SA 4.0

Body:
So basically i have a parent component which uses a child button component. Basically currently when the input validation is not correct it will keep the button disabled. However now I have tried to disable the button on click. The button is currently a pure component and i started to use hooks but not sure how i can still get the validation running.

Code is below

<ChildButton
            onClick={() => {
              this.checkSomething= this.checkCreds();
            }}
            enabled={this.validateInput()}
          />

My pure component currently looks like this:

export function AButton({ onClick, enabled, text }) {
  const [disabled, setDisabled] = useState(!enabled);

  function handleClick() {
    setDisabled(!disabled);
    //onClick();
  }
  return (
    <Button
      style={{ display: "block", margin: "auto" }}
      id="next-button"
      onClick={handleClick}
      disabled={disabled}
    >
      {text}
    </Button>
  );
}

So i can get the disable button to work in both scenairos. As the enabled is always being passed down into this pure component so need to keep setting state of it.

Body:
I ended up using useEffect from react hooks

useEffect(() => setDisabled(!enabled), [enabled]);

This will check every time the enabled props is updated from the parent. Similar to how componentDidUpdate would work


问:
Eclipse removes external imports after saving the java file
I have imported a few external library imports in a java file.
After saving the file eclipse auto removes these imports.

Quick googling showed me results about organizing imports. But these are disabled in eclipse work-space.

How should I prevent this behavior?

答:
It was in fact inside Save Actions.

Although the Perform the selected actions on save was unchecked, these settings were enabled inside Configure Project Specific Settings and the corresponding project.


问:
Make radio buttons checked /unchecked

$("input[type='radio']").each(function() {
  if ($(this).is(":checked")) {
    $(this).css('background', 'blue');
  }
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="radio" data="cool" name="cool" checked="checked">
<input type="radio" data="cool" name="cool">
<input type="radio" data="cool" name="cool"></code>```

My approach is to first check if my inputs are :checked and if they are, put some CSS class with the background color. I achieve that, the next thing I want to is to remove that :checked when users click on radio button or any other (better) idea. After the form is submitted, this code checks if inputs are:checked, the problem is when I want to select another radio button I get something like this:

1 and 2 radio buttons are selected, it  should be only 2 :checked

答:
You need to add the else to remove the blue color like :

```<code>$("input[type='radio']").each(function () {
   if ($(this).is(":checked")) {
      $(this).css('background', 'blue');
   }else{
     $(this).css('background', 'white');
   }
});
</code>```

You could also attach a click event for those radios like :

```<code>$("body").on("click", "input[type='radio']", function () {
    $("input[type='radio']").css('background', 'white');
    $(this).css('background', 'blue');
});
</code>```

Title: Make radio buttons checked /unchecked

Body:
$("input[type='radio']").each(function() {
  if ($(this).is(":checked")) {
    $(this).css('background', 'blue');
  }
});

<input type="radio" data="cool" name="cool" checked="checked">
<input type="radio" data="cool" name="cool">
<input type="radio" data="cool" name="cool">

My approach is to first check if my inputs are :checked and if they are, put some CSS class with the background color. I achieve that, the next thing I want to is to remove that :checked when users click on radio button or any other (better) idea. After the form is submitted, this code checks if inputs are:checked, the problem is when I want to select another radio button I get something like this:

1 and 2 radio buttons are selected, it  should be only 2 :checked

Body:
You need to add the else to remove the blue color like :

$("input[type='radio']").each(function () {
   if ($(this).is(":checked")) {
      $(this).css('background', 'blue');
   }else{
     $(this).css('background', 'white');
   }
});

You could also attach a click event for those radios like :

$("body").on("click", "input[type='radio']", function () {
    $("input[type='radio']").css('background', 'white');
    $(this).css('background', 'blue');
});


问:
Which approach is better - comment attribute in each table vs one comment table
Currently, I have a bunch of tables in my system which need to store one comment per row (not by content type or anything else - just simple one comment per row and no history tracking). Is there any advantage to creating a comment table and having a FK to it from all other tables which need comments as opposed to just directly creating a comment column in each of those tables?

Is there any advantage on the physical DB side - in terms of database performance for these 2 approaches?

答:
It's really impossible to comment (cough) meaningfully on performance without testing. You're the only one in a reasonable position to do that.

At the logical level, a comment about the data in a row should be stored with the row.

Some dbms will move wide columns internally to a secondary storage area. This speeds up access to rows when you don't select the comment column (fewer physical reads), but it slows down access when you do select the comment column (reads from a different part of the internal data structures). You might not notice the difference unless you're selecting many thousands of rows out of millions of rows. (But, again, testing . . .)

ContentLicense: CC BY-SA 3.0


问:
Do I commit the package-lock.json file created by npm 5?
npm 5 was released today and one of the new features include deterministic installs with the creation of a package-lock.json file.

Is this file supposed to be kept in source control?

I'm assuming it's similar to yarn.lock and composer.lock, both of which are supposed to be kept in source control.

答:
Yes, it's a standard practice to commit package-lock.json.

The main reason for committing package-lock.json is that everyone in the project is on the same package version.

Pros:

If you follow strict versioning and don't allow updating to major versions automatically to save yourself from backward-incompatible changes in third-party packages committing package-lock helps a lot.

If you update a particular package, it gets updated in package-lock.json and everyone using the repository gets updated to that particular version when they take the pull of your changes.

Cons:

It can make your pull requests look ugly :)

npm install won't make sure that everyone in the project is on the same package version. npm ci will help with this.


问:
How to fetch sequelize js records for today
I have a table which looks similar to the below table. I am trying to find the sum of all prices for TODAY.

```<code>| id| price |       created        |
|---|-------|----------------------|
| 0 |  500  | 2018-04-02 11:40:48  |
| 1 | 2000  | 2018-04-02 11:40:48  |
| 2 | 4000  | 2018-07-02 11:40:48  |
</code>```

The below code is what i came up with but it doesn't seem to work.

```<code>const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
    where: {
      created: TODAY,
    },
});
console.log(SUM);
</code>```

Value of SUM is 0 even though there are entries for today. I also tried the following but it too didn't work.

```<code>const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
    where: {
      created: Sequelize.DATE(TODAY),
    },
});
console.log(SUM);
</code>```

The SQL statement queried on the terminal is as follows.

Executing (default): SELECT sum(`price`) AS `sum` FROM `orders` AS `orders` WHERE `orders`.`created` = '2019-05-27 18:30:00';

答:
Add DATE FUNCTION to do date comparision without considering time</p>

```<code>const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
    where: {
      sequelize.fn('CURRENT_DATE'): {$eq:  sequelize.fn('date_trunc', 'day', sequelize.col('created'))}
    },
});
console.log(SUM);
</code>```

Body:
I have a table which looks similar to the below table. I am trying to find the sum of all prices for TODAY.

| id| price |       created        |
|---|-------|----------------------|
| 0 |  500  | 2018-04-02 11:40:48  |
| 1 | 2000  | 2018-04-02 11:40:48  |
| 2 | 4000  | 2018-07-02 11:40:48  |

The below code is what i came up with but it doesn't seem to work.

const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
    where: {
      created: TODAY,
    },
});
console.log(SUM);

Value of SUM is 0 even though there are entries for today. I also tried the following but it too didn't work.

const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
    where: {
      created: Sequelize.DATE(TODAY),
    },
});
console.log(SUM);

The SQL statement queried on the terminal is as follows.

Executing (default): SELECT sum(`price`) AS `sum` FROM `orders` AS `orders` WHERE `orders`.`created` = '2019-05-27 18:30:00';

Body:
Add DATE FUNCTION to do date comparision without considering time

const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
    where: {
      sequelize.fn('CURRENT_DATE'): {$eq:  sequelize.fn('date_trunc', 'day', sequelize.col('created'))}
    },
});
console.log(SUM);


问:
load html, css and js files from a zip file into the webView
I have an endpoint that send me a zip file with html , js and css files (a local web project). My question is there a solution to load the web project in a webkitview without changing the relative paths in the html files and if not is there an other solution ? I thought about loading the html file as string and then inject the css and js to the webkit but I will not access to the images because they have their relative paths in html page. Thank you for your help !

答:
For this type of case, you can use Cross-Platform Application Development. ie. Cordova, which will provide support directly to add and render your assets as native application.

or you can load html file directly to web view:

```<code>if let url = Bundle.main.url(forResource: "home", withExtension: "html") {
            webview.loadRequest(URLRequest(url: url))
        }
</code>```

Body:
For this type of case, you can use Cross-Platform Application Development. ie. Cordova, which will provide support directly to add and render your assets as native application.

or you can load html file directly to web view:

if let url = Bundle.main.url(forResource: "home", withExtension: "html") {
            webview.loadRequest(URLRequest(url: url))
        }


问:
Create test programmatically
Quick question :
 Can I programmatically create tests in visual studio and have them displayed into the Test Explorer  ? is it doable ?

I'm using the logic of Data driven tests so i can actually do all my tests but they are displayed in only one test in the Test Explorer because this method uses only one [TestMethod]

so is there a way to do something in the logic of :

```<code>foreach(item in list)
{
     // Create a "[TestMethod]" that will be displayed in the Test Explorer
}
</code>```

The "foreach" is already done with the Data driven tests but maybe there is another way that allow to cycle through my data and create a Test for each entry ?
Thanks :)

答:
If you are using MSTEST for testing, you will have to write a custom datasource.
Then your test will be displayed as multiple test in test explorer.

https://learn.microsoft.com/en-us/visualstudio/test/how-to-create-a-data-driven-unit-test?view=vs-2019

In case of NUnit you can use TestCase attribute this behavior

http://nunit.org/docs/2.5/testCase.html

In case of XUnit you can use Theory and InlineData for achieving this behavior

https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test#adding-more-features

Title: Create test programmatically

Body:
Quick question :
 Can I programmatically create tests in visual studio and have them displayed into the Test Explorer  ? is it doable ?

I'm using the logic of Data driven tests so i can actually do all my tests but they are displayed in only one test in the Test Explorer because this method uses only one [TestMethod]

so is there a way to do something in the logic of :

foreach(item in list)
{
     // Create a "[TestMethod]" that will be displayed in the Test Explorer
}

The "foreach" is already done with the Data driven tests but maybe there is another way that allow to cycle through my data and create a Test for each entry ?
Thanks :)


问:
System.Timers.Timer vs System.Threading.Timer
I have been checking out some of the possible timers lately, and System.Threading.Timer and System.Timers.Timer are the ones that look needful to me (since they support thread pooling).

I am making a game, and I plan on using all types of events, with different intervals, etc.

Which would be the best?

答:
In his book "CLR Via C#", Jeff Ritcher discourages using System.Timers.Timer, this timer is derived from System.ComponentModel.Component, allowing it to be used in design surface of Visual Studio. So that it would be only useful if you want a timer on a design surface.

He prefers to use System.Threading.Timer for background tasks on a thread pool thread.


问:
Animation not working on input type button, but working on button tag
As I am trying for animation on input type button it is not working, but animation is working for  tag and  tag</p>

答: the correct selector should be input[type="button"]


问:
What does JSON stringify do in react native
i am new to react native application development.I have some confusion regarding JSON.stringify method.Here is my code.

```<code>fetch('http://link.com', {
        method: 'POST',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'multipart/form-data',
        },
        body: formData

    }).then((response) => response.json())
    .then((responseJson) => {
        this.setState({
            loading_status: false
        })

        if (!responseJson.error) {

            var id = responseJson.result.id
            var roles_id = responseJson.result.roles_id

            AsyncStorage.multiSet([
                ['user_id', id.toString()],
                ['roles_id', roles_id.toString()],

            ]);

        } else {
            //error

        }

    }).catch((error) => {
        console.error(error);

        Platform.OS === 'android' ? ToastAndroid.show("Connection Error !", ToastAndroid.SHORT) : Alert.alert("Connection Error !")

        return;
    });
</code>```

But main problem arises when i started to make build for that.What i saw is that value which is not in string produces error while writing or reading data from async storage.
It gives me error in ios build something like.
NSnull cannot be converted into NSString
So i changed my code to something like this

```<code> if (!responseJson.error) {

    var id = JSON.stringify(responseJson.result.id)
    var roles_id = JSON.stringify(responseJson.result.roles_id)

    AsyncStorage.multiSet([
        ['user_id', id],
        ['roles_id', roles_id],

    ]);
}
</code>```

Now this works fine in ios build.So my doubt is that how can i parse a json or is there any standart way to parse json in react native so that i did not face problem which is faced while making ios build for react native.

答: JSON.stringify() is used to convert JSON into a string. To parse the string data JSON.parse() is used.</p>

Body:
i am new to react native application development.I have some confusion regarding JSON.stringify method.Here is my code.

fetch('http://link.com', {
        method: 'POST',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'multipart/form-data',
        },
        body: formData

    }).then((response) => response.json())
    .then((responseJson) => {
        this.setState({
            loading_status: false
        })

        if (!responseJson.error) {

            var id = responseJson.result.id
            var roles_id = responseJson.result.roles_id

            AsyncStorage.multiSet([
                ['user_id', id.toString()],
                ['roles_id', roles_id.toString()],

            ]);

        } else {
            //error

        }

    }).catch((error) => {
        console.error(error);

        Platform.OS === 'android' ? ToastAndroid.show("Connection Error !", ToastAndroid.SHORT) : Alert.alert("Connection Error !")

        return;
    });

But main problem arises when i started to make build for that.What i saw is that value which is not in string produces error while writing or reading data from async storage.
It gives me error in ios build something like.
NSnull cannot be converted into NSString
So i changed my code to something like this

 if (!responseJson.error) {

    var id = JSON.stringify(responseJson.result.id)
    var roles_id = JSON.stringify(responseJson.result.roles_id)

    AsyncStorage.multiSet([
        ['user_id', id],
        ['roles_id', roles_id],

    ]);
}

Now this works fine in ios build.So my doubt is that how can i parse a json or is there any standart way to parse json in react native so that i did not face problem which is faced while making ios build for react native.


问:
Weka will not open on MacOS
I have installed the latest version of Weka(3.9.3). I have also ensured that both Java and MacOS are up to date on my machine.

When I double-click the Weka icon to open it, it bounces for a few seconds and never opens.

I have downloaded Weka 3.8.3 to see if that makes any difference, but the same thing happened.

Any ideas on why this is happening?

答:
I was facing a similar issue but it worked for me when I start weka on the command line.

Change directory into the weka-3-8-0 directory

cd /Applications/weka-3-8-0

invoke the jvm with the weka.jar file located in the above directory

java -jar weka.jar

Title: Weka will not open on MacOS


问:
Type overloading macro
I have a bunch of printf debug helper macros and it would be pretty cool to have to not specify the type, is there anything you can do to allow something like macro overloading in c(can be gcc specific if its available in gcc 4.3). I thought maybe typeof but apparently that doesn't work.

example macro(I also have some ascii terminal color stuff that I can't remember of the top of my head)

```<code>#ifdef _DEBUG
#define DPRINT_INT(x) printf("int %s is equal to %i at line %i",#x,x,__LINE__);
.
.
.
#else
#define DPRINT_INT(x)
.
.
.
#endif
</code>```

答:
How about the following macro? It still requires you to pick the print format but you won't have to redefine all possible cases and it works on MSVC as well:

```<code>#define DPRINT(t,v) printf("The variable '%s' is equal to '%" ## #t ## "' on line %d.\n",#v,v, __LINE__)
</code>```

To use it:

```<code>int var = 5;
const char *str = "test";
DPRINT(i,var);
DPRINT(s,str);
</code>```

Title: Type overloading macro

Body:
I have a bunch of printf debug helper macros and it would be pretty cool to have to not specify the type, is there anything you can do to allow something like macro overloading in c(can be gcc specific if its available in gcc 4.3). I thought maybe typeof but apparently that doesn't work.

example macro(I also have some ascii terminal color stuff that I can't remember of the top of my head)

#ifdef _DEBUG
#define DPRINT_INT(x) printf("int %s is equal to %i at line %i",#x,x,__LINE__);
.
.
.
#else
#define DPRINT_INT(x)
.
.
.
#endif

Body:
How about the following macro? It still requires you to pick the print format but you won't have to redefine all possible cases and it works on MSVC as well:

#define DPRINT(t,v) printf("The variable '%s' is equal to '%" ## #t ## "' on line %d.\n",#v,v, __LINE__)

To use it:

int var = 5;
const char *str = "test";
DPRINT(i,var);
DPRINT(s,str);


问:
Display data in desired form ,using php
I'm trying to get this output

```<code>Province
 1.city 1 33poits
 2.city 2 33poits
 3.city 3 33poits
</code>```

and what my current output is

```<code>Province
 1.city 1 33points
Province
 2.city 2 33points
Province
 3.city 3 33points
</code>```

please help just a newbie here, below is my php code

<?php
$sql = "SELECT * FROM ccty WHERE ID=".$ID;
$results = $mysqli->query($sql);

if ($results->num_rows > 0) {
    while ($row = $results->fetch_object()) {
    ?>

<?= $row->PID; ?>
            <?= $row->SPID; ?><?= $row->points; ?>

    <?php
    }
} else {
    echo "No record available!";
}
?>
```

答:
For one, your table-structure is invalid.

To only print the PID once per group, store the previous PID in a variable and check against it - only print it if its different from before.

You should also be using a prepared statement instead of a direct query.

<?php
$sql = "SELECT PID, SPID, points FROM ccty WHERE ID=? ORDER BY PID";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $ID);
$stmt->execute();
$stmt->bind_result($PID, $SPID, $points);
if ($stmt->num_rows) {
    echo '
';

    $previousPID = null;
    while ($stmt->fetch()) {
        if ($PID != $previousPID) {
            echo '
'.$PID.'
';
            $previousPID = $PID;
        }
        ?>

            <?= $SPID." ".$points; ?>

        <?php
    }
    echo '
';
} else {
   echo "No records available!";
}
```

Title: Display data in desired form ,using php

Body:
I'm trying to get this output

Province
 1.city 1 33poits
 2.city 2 33poits
 3.city 3 33poits

and what my current output is

Province
 1.city 1 33points
Province
 2.city 2 33points
Province
 3.city 3 33points

please help just a newbie here, below is my php code

<?php
$sql = "SELECT * FROM ccty WHERE ID=".$ID;
$results = $mysqli->query($sql);

if ($results->num_rows > 0) {
    while ($row = $results->fetch_object()) {
    ?>

<?= $row->PID; ?>
            <?= $row->SPID; ?><?= $row->points; ?>

    <?php
    }
} else {
    echo "No record available!";
}
?>

Body:
For one, your table-structure is invalid.

To only print the PID once per group, store the previous PID in a variable and check against it - only print it if its different from before.

You should also be using a prepared statement instead of a direct query.

<?php
$sql = "SELECT PID, SPID, points FROM ccty WHERE ID=? ORDER BY PID";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $ID);
$stmt->execute();
$stmt->bind_result($PID, $SPID, $points);
if ($stmt->num_rows) {
    echo '<table>';

    $previousPID = null;
    while ($stmt->fetch()) {
        if ($PID != $previousPID) {
            echo '<tr><td>'.$PID.'</td></tr>';
            $previousPID = $PID;
        }
        ?>
        <tr>
            <td><?= $SPID." ".$points; ?></td>
        </tr>
        <?php
    }
    echo '</table>';
} else {
   echo "No records available!";
}


问:
Getting rows sorted by date (only first unique instance on one column) in Postgresql
So I have a table called  "reports" organized as:

```<code>id | stock_id | type | time_period | report_date
</code>```

type can either be "Cash_Flow", "Income_Statement" or "Balance_Sheet", time_period can either be "quarterly" or "yearly", report_date  is a date. What I'd want to do is essentially get only the most recent (sorted by report_date) reports for each stock_id.

So if  a stock has a "Cash_Flow", "Income_Statement", and "Balance_Sheet" quaterly reports for both 2019-04-30 and 2019-01-30 and yearly reports for 2019-04-30 as well, I'd only want to get the most recent quarterly reports for each stock and not return any yearly reports or any older reports. So let's say there's 100 stocks witih a total of 8 quarters for each report type in the table (2400 rows total for quarterly reports) and 2 yearly reports for each type (600 row yearly reports).

So I'm currently running postgresql 10.8 on Ubuntu 18.04. I don't usually write raw sql (usually use an ORM), so sorry if the answer  is really simple.

So I've tried the following for each report, but it returns all rows(as expected), whereas I'd only want the most recent. I think the solution would likely require a distinct, but I can't get to seem that working with the orderby.

SELECT *
FROM public.reports where time_period='quarterly' and type='Cash_Flow'  group by id, stock_id order by report_date desc;
```

I'd want a select query that would only return 300 rows, containing only the most recent 3 (Income_Statement, Balance_Sheet, Cash_Flow) reports for each of the 100 stocks or if its easier 3 queries for each of those 3 report  types returning 100 rows each.

答:
I'd want a select query that would only return 300 rows, containing only the most recent 3 reports for each of the 100 stocks.

Use window functions.  Assuming you have 100 stocks:

```<code>select r.*
from (select r.*,
             row_number() over (partition by stock_id, type order by report_date desc) as seqnum
      from public.reports r
      where time_period = 'quarterly' and
            type in ( 'Cash_Flow', 'Income_Statement', 'Balance_Sheet' )
     ) r
where seqnum = 1;
</code>```

Body:
So I have a table called  "reports" organized as:

id | stock_id | type | time_period | report_date

type can either be "Cash_Flow", "Income_Statement" or "Balance_Sheet", time_period can either be "quarterly" or "yearly", report_date  is a date. What I'd want to do is essentially get only the most recent (sorted by report_date) reports for each stock_id.

So if  a stock has a "Cash_Flow", "Income_Statement", and "Balance_Sheet" quaterly reports for both 2019-04-30 and 2019-01-30 and yearly reports for 2019-04-30 as well, I'd only want to get the most recent quarterly reports for each stock and not return any yearly reports or any older reports. So let's say there's 100 stocks witih a total of 8 quarters for each report type in the table (2400 rows total for quarterly reports) and 2 yearly reports for each type (600 row yearly reports).

So I'm currently running postgresql 10.8 on Ubuntu 18.04. I don't usually write raw sql (usually use an ORM), so sorry if the answer  is really simple.

So I've tried the following for each report, but it returns all rows(as expected), whereas I'd only want the most recent. I think the solution would likely require a distinct, but I can't get to seem that working with the orderby.

SELECT *
FROM public.reports where time_period='quarterly' and type='Cash_Flow'  group by id, stock_id order by report_date desc;

I'd want a select query that would only return 300 rows, containing only the most recent 3 (Income_Statement, Balance_Sheet, Cash_Flow) reports for each of the 100 stocks or if its easier 3 queries for each of those 3 report  types returning 100 rows each.

Body:
I'd want a select query that would only return 300 rows, containing only the most recent 3 reports for each of the 100 stocks.

Use window functions.  Assuming you have 100 stocks:

select r.*
from (select r.*,
             row_number() over (partition by stock_id, type order by report_date desc) as seqnum
      from public.reports r
      where time_period = 'quarterly' and
            type in ( 'Cash_Flow', 'Income_Statement', 'Balance_Sheet' )
     ) r
where seqnum = 1;


答:
Here is the link to report a crawling bug of Google Bot:

https://www.google.com/webmasters/tools/googlebot-report

Report a problem with how Googlebot crawls your site.
  You can report problems only for domain-level properties (for example, "www.example.com/")

The rate at which Google crawls your page depends on many factors:

The URLs we already know about
  Links from other web pages (within your site and on other sites)
  URLs listed in your Sitemap.
  For most sites, Googlebot shouldn't access your site more than once every few seconds on average.

Probably the report link was not easy to find since you need a Google Webmaster account and can apparently only report your own websites.

Title: How to report a bug of GoogleBot?

Body:
Over the last days, Google Bot tries to read one URL of our main site over and over again, leading to a DDOS attack :) Our website got very slow because of the massive requests of the Google Crawler.

Here an excerpt for the curious ones (or if a Google engineers reads this post):

66.249.76.54 - - [27/May/2019:06:31:23 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/tag/594749/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/user/impressum HTTP/1.0" 200 32603
66.249.76.54 - - [27/May/2019:06:31:23 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/403551/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/403551/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/bestusers HTTP/1.0" 200 32603
66.249.76.55 - - [27/May/2019:06:31:23 +0200] "GET /235432/tag/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/403551/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/403551/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/schreibregeln HTTP/1.0" 200 32603
66.249.76.54 - - [27/May/2019:06:31:23 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/403551/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/403551/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/594749/tag/chat HTTP/1.0" 200 32603

Or here (see the different IPs, so there are several bots):

66.249.76.54 - - [27/May/2019:09:24:42 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/386961/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/403551/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/user/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/punkte HTTP/1.0" 200 32587
66.249.76.55 - - [27/May/2019:09:24:42 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/403551/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/user/403551/agb HTTP/1.0" 200 32587
66.249.76.56 - - [27/May/2019:09:24:42 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/user/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/403551/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/403551/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/qa-theme/lounge/js/lounge.min.js?v=2019-01-17 HTTP/1.0" 200 32587
66.249.76.55 - - [27/May/2019:09:24:42 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/594749/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/luckentext-zum-thema-extrema-funktionenschar-ft-x-1-2-tx-2-2-t HTTP/1.0" 200 32587
66.249.76.58 - - [27/May/2019:09:24:42 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/323274/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/tag/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/323274/user/Lu HTTP/1.0" 200 32587
66.249.76.57 - - [27/May/2019:09:24:42 +0200] "GET /235432/~plot~+4x%5E2%3B+4%2Ax%5E2+++4%2A%281/32%29%2Ax+-+15%2A%281/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/154807/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/323274/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/235432/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/32)*x%20-%2015*(1/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/user/user/tag/tag/~plot~%204x%5E2;%204*x%5E2%20+%204*(1/badges HTTP/1.0" 200 32587

The false link that was leading to this problem:

~plot~ 4x^2; 4*x^2 + 4*(1/32)*x - 15*(1/32)^2; x; [[0.1]]~plot~

Where can I report a bug of GoogleBot?

There seems to be no official way how to report a bug.


问:
Set Angular 7 environment in Visual Studio 2015
I want to configure Angular 7 environment in Visual Studio 2015 or Visual Studio 2017 with an ASP.NET MVC project and also run from Visual Studio.</p>

答:
You have to do the following steps:

Step1. Create a folder “Angular App” inside your MVC application structure.

Step2. Create Angular application structure may be like:

o   App

   Modules
•   Module1
•   Module2
   Common
   Services

o   Webpack-config.js

o   Tsconfig.json

o   Enviorment.json

o   Package.json

Step2. Use Webpack to build your angular application.

Step3. Output of your build create bundle of Js file(s), include your bundled js and css file in. cshtml layout page.

Step4. Place your module startup angular selector in. cshtml page wherever you would like to bootstrap your angular application.


问:
add a class to the li element or the a?
I have a standard list of links:

```<code><li><a href="">one</a></li>
<li><a href="">two</a></li>
</code>```

If I want to add an extra class to one of the list items, should I add the class to the li or the a element? What is best practice?

Many thanks!

Cameron

答: What is it that you want to style, the list item or the anchor.  You probably want to style the anchor, so add it to that</p>

OwnerDisplayName: Cameron

ContentLicense: CC BY-SA 2.5

Title: add a class to the li element or the a?

Body:
I have a standard list of links:

one

two

If I want to add an extra class to one of the list items, should I add the class to the li or the a element? What is best practice?

Many thanks!

Cameron

OwnerDisplayName: Allen


问:
ShellExecute in suspend mode
Createprocess API has a option to create a process with CREATE_SUSPENDED flag. Similarly, is there any possiblity in ShellExecute APIs to create the process in suspended state. </p>

答: Shell execute while spawning a process is not invoking createprocess in windows 7. But that's opposite in windows 2008. Hence implemented wine code for shellexecute in win7 and made to work via createprocess for my application.</p>

Title: ShellExecute in suspend mode


问:
How do I verify if a file is being downloaded in Selenium Webdriver C#
How to verify file being downloaded. I am stuck at how do I retrieve the downloaded file when the "Download" button had been clicked.</p>

```<code>''  driver = new ChromeDriver();
        driver.Manage().Window.Maximize();
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
        driver.Navigate().GoToUrl("http://192.162.0.1/testing-admin/Login/Login.aspx");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_txtUserID")).SendKeys("Jojo");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_txtPassword")).SendKeys("Man15742368");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_cmdLogin")).Click();
        driver.Navigate().GoToUrl("http://192.162.0.1/testing-admin/User_Document/User_Document_Download.aspx");
      driver.FindElement(By.XPath("//a[@id='ctl00_MainContent_GV_ctl02_lnkDownloadFile']")).Click(); //download button
</code>```

答:
```<code>var Path = "drive path";
ChromeOptions co = new ChromeOptions();
co.AddAdditionalCapability("download.default_directory", Path);
driver = new ChromeDriver(co);
</code>```

Then you can you System.IO.DirectoryInfo for retrieving all downloaded file details into Path folder.

Body:
How to verify file being downloaded. I am stuck at how do I retrieve the downloaded file when the "Download" button had been clicked.

''  driver = new ChromeDriver();
        driver.Manage().Window.Maximize();
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
        driver.Navigate().GoToUrl("http://192.162.0.1/testing-admin/Login/Login.aspx");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_txtUserID")).SendKeys("Jojo");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_txtPassword")).SendKeys("Man15742368");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_cmdLogin")).Click();
        driver.Navigate().GoToUrl("http://192.162.0.1/testing-admin/User_Document/User_Document_Download.aspx");
      driver.FindElement(By.XPath("//a[@id='ctl00_MainContent_GV_ctl02_lnkDownloadFile']")).Click(); //download button

Body:
var Path = "drive path";
ChromeOptions co = new ChromeOptions();
co.AddAdditionalCapability("download.default_directory", Path);
driver = new ChromeDriver(co);

Then you can you System.IO.DirectoryInfo for retrieving all downloaded file details into Path folder.


问:
*Job Class* and Illuminate\Bus\Queueable define the same property ($connection) in the composition of *Job Class*
Despite the documentation declaring otherwise, attempting to set the connection name within a Job class can fail in Laravel with the error:</p>

```<code>[Job Class] and Illuminate\Bus\Queueable define the same property ($connection) in the composition of [Job Class]. However, the definition differs and is considered incompatible. Class was composed
</code>```

答:
I believe this is a compatibility issue between PHP 7.3 and Laravel 5.8. The error is raised because the Queueable trait has already defined the 'connection' class variable.

To fix the error, we just need to set the variable rather than declare it.

Broken job class:

```<code>class UpdateProductInventory implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $connection = 'database';
}
</code>```

Fixed job class:

```<code>class UpdateProductInventory implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $product;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->connection = 'database';
    }
}
</code>```

Body:
Despite the documentation declaring otherwise, attempting to set the connection name within a Job class can fail in Laravel with the error:

[Job Class] and Illuminate\Bus\Queueable define the same property ($connection) in the composition of [Job Class]. However, the definition differs and is considered incompatible. Class was composed

Body:
I believe this is a compatibility issue between PHP 7.3 and Laravel 5.8. The error is raised because the Queueable trait has already defined the 'connection' class variable.

To fix the error, we just need to set the variable rather than declare it.

Broken job class:

class UpdateProductInventory implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $connection = 'database';
}

Fixed job class:

class UpdateProductInventory implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $product;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->connection = 'database';
    }
}


问:
How to get which property of an object first mismatched in JUnit assertEquals?
I have a simple pojo class in the format as shown below.

class PojoClass {

    property1;
    ...
    propertyN;

    @override
    public int hashcode() {
        //implementation
    }

    @override
    public boolean equals(Object o) {
        //implementation
    }

    @override
    public String toString)() {
        return "PojoClass[property1= " + property1 ... propertyN + "]";
    }

}
```

In my test case I do what I need and I have an expected PojoClass object and actual PojoClass Object. In some cases even arrays (expected and actual) of objects of PojoClass. When assert fails, I get message that prints the toString of expected and actual.

toString is not convenient enough in this case as my PojoClass object contains 20 to 30 properties. I am having to manually check all the properties if they match or not. Is there any way in JUnit, to directly specify if which property of expected object did not match that of actual object?

答:
Solution using Gson. The basic idea behind this solution is to get the objects values from toString and de-serialize it into Json, and then use Maps.difference method in the Gson library to compare two Jsons and figure out which property(s)'s  or key(s)'s value is a mismatch.

Update Pojo's to string to return a stringified json of that
particular object of POJO

class PojoClass {

    property1;
    ...
    propertyN;

    @override
    public int hashcode() {
        //implementation
    }

    @override
    public boolean equals(Object o) {
        //implementation
    }

    @override
    public String toString)() {
        return new Gson().toJson(this);
    }

}
```

<ol start="2">
<li>Test case should look like this, as Hades pointed out.</li>
</ol>

<pre class="lang-java prettyprint-override"><code>@Test
public void pojoClassTest() throws Exception {
    List<PojoClass> sourcePojoList = getSourcePojoList();
    List<PojoClass> targetPojoList = getTargetPojoList();
    try {
        Assert.assertArrayEquals(sourcePojoList.toArray(), targetPojoList.toArray());
    }
    catch (ArrayComparisonFailure e) {
        Assert.fail(getMessage(e));
    }
}
</code>```

getMessage method is where we get the existing message from JUnit, create two Jsons and compare them. Refer this post for the comparison technique.

// The junit error message will be in following format
// java.lang.AssertionError: arrays first differed at element [0]; expected:<{json}> but was:<{json}>
// So we get both source and target Json, and throw in the magic of gson library
// We compare them using method mentioned in link above.
// Now the new message that will be asserted contains message like below (assuming property 1 of the object is the mismatch)
// not equal: value differences={property1=("expected","actual")}

private static String getMessage(AssertionError e) throws IOException {
    String msg = e.getMessage();
    String sourceJson = msg.substring(msg.indexOf("expected:<") + 10, msg.indexOf("> but was:"));
    String targetJson = msg.substring(msg.lastIndexOf("but was:<") + 9, msg.lastIndexOf(">"));
    Gson g = new Gson();
    Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
    Map<String, Object> firstMap = g.fromJson(sourceJson, mapType);
    Map<String, Object> secondMap = g.fromJson(targetJson, mapType);
    return Maps.difference(firstMap, secondMap).toString();
}
```

Body:
I have a simple pojo class in the format as shown below.

class PojoClass {

    property1;
    ...
    propertyN;

    @override
    public int hashcode() {
        //implementation
    }

    @override
    public boolean equals(Object o) {
        //implementation
    }

    @override
    public String toString)() {
        return "PojoClass[property1= " + property1 ... propertyN + "]";
    }

}

In my test case I do what I need and I have an expected PojoClass object and actual PojoClass Object. In some cases even arrays (expected and actual) of objects of PojoClass. When assert fails, I get message that prints the toString of expected and actual.

toString is not convenient enough in this case as my PojoClass object contains 20 to 30 properties. I am having to manually check all the properties if they match or not. Is there any way in JUnit, to directly specify if which property of expected object did not match that of actual object?

Body:
Solution using Gson. The basic idea behind this solution is to get the objects values from toString and de-serialize it into Json, and then use Maps.difference method in the Gson library to compare two Jsons and figure out which property(s)'s  or key(s)'s value is a mismatch.

Update Pojo's to string to return a stringified json of that
particular object of POJO

class PojoClass {

    property1;
    ...
    propertyN;

    @override
    public int hashcode() {
        //implementation
    }

    @override
    public boolean equals(Object o) {
        //implementation
    }

    @override
    public String toString)() {
        return new Gson().toJson(this);
    }

}

Test case should look like this, as Hades pointed out.

@Test
public void pojoClassTest() throws Exception {
    List<PojoClass> sourcePojoList = getSourcePojoList();
    List<PojoClass> targetPojoList = getTargetPojoList();
    try {
        Assert.assertArrayEquals(sourcePojoList.toArray(), targetPojoList.toArray());
    }
    catch (ArrayComparisonFailure e) {
        Assert.fail(getMessage(e));
    }
}

getMessage method is where we get the existing message from JUnit, create two Jsons and compare them. Refer this post for the comparison technique.

// The junit error message will be in following format
// java.lang.AssertionError: arrays first differed at element [0]; expected:<{json}> but was:<{json}>
// So we get both source and target Json, and throw in the magic of gson library
// We compare them using method mentioned in link above.
// Now the new message that will be asserted contains message like below (assuming property 1 of the object is the mismatch)
// not equal: value differences={property1=("expected","actual")}

private static String getMessage(AssertionError e) throws IOException {
    String msg = e.getMessage();
    String sourceJson = msg.substring(msg.indexOf("expected:<") + 10, msg.indexOf("> but was:"));
    String targetJson = msg.substring(msg.lastIndexOf("but was:<") + 9, msg.lastIndexOf(">"));
    Gson g = new Gson();
    Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
    Map<String, Object> firstMap = g.fromJson(sourceJson, mapType);
    Map<String, Object> secondMap = g.fromJson(targetJson, mapType);
    return Maps.difference(firstMap, secondMap).toString();
}


问:
How to fetch Build information in jenkins
I've build a sample project in Jenkins by cloning from the Github repo. Can I get all the Jenkins and Git build details (such as the last commit ID, Origin details, Jenkins build number, Build URL, workspace location of Jenkins, Last commit author name) in a HTML page (It should be created after jenkins build) after triggering a build in Jenkins? </p>

答:
Jenkins and Git provide global variables which can be directly accessed in jobs irrespective of pre build or post build actions.
You can check global variable list with below url.

```<code>http://your-jenkins-url-here/env-vars.html
</code>```

To access user defined variables, you can use below regex pattern:

${ENV,var="MY_VARIABLE_NAME"}

Body:
Jenkins and Git provide global variables which can be directly accessed in jobs irrespective of pre build or post build actions.
You can check global variable list with below url.

http://your-jenkins-url-here/env-vars.html

To access user defined variables, you can use below regex pattern:

${ENV,var="MY_VARIABLE_NAME"}


问:
How can you extract a integer number from a string in a function?
I want to input a string into a function and get the integer that's in it to compare the number with another expression. I've searched a lot but some don't work or give me this: ['6']. I can't compare that to a number so it can't work. Please Help.

```<code>{def numberC(card):
#numbers = []
#numbers.append(re.findall(\-?\d+, card))
#nums = re.compile(r"[+-]?\d+(?:\.\d+)?")
print(re.findall("\-?\d+", card))
return re.findall("\-?\d+", card)}
</code>```

That is the function I've made that doesn't work.

The string that goes into it looks like this "Red Card 10".

I then use this to compare them as a card battle.

```<code>{elif(card1 == card2):
    if(numberC(card1) < numberC(card2)):
        return "Player 2 is the Winner!"
    else:
        return "Player 1 is the Winner!"}
</code>```

The expected result is from "Red Card 10" I want just 10 that has a data type of an integer.

答:
You need to treat special cards cases, for the Ace, Jack, Queen, King and Joker (maybe). Feel free to change their values:

```<code>import re

SPECIAL_CARDS = {
  "ace": 1,
  "jack": 11,
  "queen": 12,
  "king": 13,
  "joker": 20
}

def numberC(card):
  card = card.lower()
  special = set(SPECIAL_CARDS) & set(card.split())
  if special:
    return SPECIAL_CARDS[special.pop()]
  result = re.search("\d+", card)
  if not result:
    return 0
  return int(result.group())

print(numberC("Red Card 10"))
print(numberC("10 Red Card"))
print(numberC("Ace Red Card"))
print(numberC("Black Jack Card"))
print(numberC("I am not a card"))
</code>```

Returns:

```<code>10
10
1
11
0
</code>```

Body:
I want to input a string into a function and get the integer that's in it to compare the number with another expression. I've searched a lot but some don't work or give me this: ['6']. I can't compare that to a number so it can't work. Please Help.

{def numberC(card):
#numbers = []
#numbers.append(re.findall(\-?\d+, card))
#nums = re.compile(r"[+-]?\d+(?:\.\d+)?")
print(re.findall("\-?\d+", card))
return re.findall("\-?\d+", card)}

That is the function I've made that doesn't work.

The string that goes into it looks like this "Red Card 10".

I then use this to compare them as a card battle.

{elif(card1 == card2):
    if(numberC(card1) < numberC(card2)):
        return "Player 2 is the Winner!"
    else:
        return "Player 1 is the Winner!"}

The expected result is from "Red Card 10" I want just 10 that has a data type of an integer.

Body:
You need to treat special cards cases, for the Ace, Jack, Queen, King and Joker (maybe). Feel free to change their values:

import re

SPECIAL_CARDS = {
  "ace": 1,
  "jack": 11,
  "queen": 12,
  "king": 13,
  "joker": 20
}

def numberC(card):
  card = card.lower()
  special = set(SPECIAL_CARDS) & set(card.split())
  if special:
    return SPECIAL_CARDS[special.pop()]
  result = re.search("\d+", card)
  if not result:
    return 0
  return int(result.group())

print(numberC("Red Card 10"))
print(numberC("10 Red Card"))
print(numberC("Ace Red Card"))
print(numberC("Black Jack Card"))
print(numberC("I am not a card"))

Returns:

10
10
1
11
0


问:
Is there a way to have a macro remove all paragraphs of a certain type?
Im creating an invoice Word Template on basis of Words Mail Merge. I get the necessary information via .csv file from a web application and create a table based on these informations. The data is given this way:

```<code>Person1 - InvoicePos1 - InvoicePos2 - InvoicePos3 - InvoicePos4
Person2 - InvoicePos1 - InvoicePos2 - InvoicePos3 - InvoicePos4
Person3 - InvoicePos1 - InvoicePos2 - InvoicePos3 - InvoicePos4
                              .
                              .
                              .
                              .
</code>```

There are different amounts of invoice types/ invoice positions so i have to create a dynamic table which works great so far.

My problem:
Word seems to automatically inserts a paragraph before each table that gets insert via a {IF}-Statement. Why do i know that its Word that inserts these paragraphs? Well the whole document is in Calibri size 12 but these Paragraphs are Times New Roman 10.

IMGUR-Link with (hopefully helpful images)

My question: Is there a way to create a macro that runs over the created document that disables/ hides each paragraph that is Times New Roman?

Ive tried different settings already to try to prevent the creation of these paragraphs but to no avail. So now im trying to hide these paragraphs after the document is created.

```<code>Sub HidePara()
    If /FoundParagraphs/.Font.Name = "Times New Roman" Then
        /FoundParagraphs/.Hidden = true
    End If
End Sub
</code>```

I know how to change the Hidden Attribute (which isnt hard at all .. )
But how would i look for either all paragraph marks (i would have to use the If-statement ive given) or (which would be better imho) filter for all paragraphs of the .Font.Name "Times New Roman".
I cant find any way to find the paragraph marks at all. But than again im pretty new to VBA and actually have no idea what im doing here. As VBA is really great. facepalm

答:
You can just delete them:</p>

```<code>Sub DelPara()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
    If oPara.Range.Font.Name = "Times New Roman" Then oPara.Range.Delete
Next oPara
End Sub
</code>```

Body:
Im creating an invoice Word Template on basis of Words Mail Merge. I get the necessary information via .csv file from a web application and create a table based on these informations. The data is given this way:

Person1 - InvoicePos1 - InvoicePos2 - InvoicePos3 - InvoicePos4
Person2 - InvoicePos1 - InvoicePos2 - InvoicePos3 - InvoicePos4
Person3 - InvoicePos1 - InvoicePos2 - InvoicePos3 - InvoicePos4
                              .
                              .
                              .
                              .

There are different amounts of invoice types/ invoice positions so i have to create a dynamic table which works great so far.

My problem:
Word seems to automatically inserts a paragraph before each table that gets insert via a {IF}-Statement. Why do i know that its Word that inserts these paragraphs? Well the whole document is in Calibri size 12 but these Paragraphs are Times New Roman 10.

IMGUR-Link with (hopefully helpful images)

My question: Is there a way to create a macro that runs over the created document that disables/ hides each paragraph that is Times New Roman?

Ive tried different settings already to try to prevent the creation of these paragraphs but to no avail. So now im trying to hide these paragraphs after the document is created.

Sub HidePara()
    If /FoundParagraphs/.Font.Name = "Times New Roman" Then
        /FoundParagraphs/.Hidden = true
    End If
End Sub

I know how to change the Hidden Attribute (which isnt hard at all .. )
But how would i look for either all paragraph marks (i would have to use the If-statement ive given) or (which would be better imho) filter for all paragraphs of the .Font.Name "Times New Roman".
I cant find any way to find the paragraph marks at all. But than again im pretty new to VBA and actually have no idea what im doing here. As VBA is really great. facepalm

Body:
You can just delete them:

Sub DelPara()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
    If oPara.Range.Font.Name = "Times New Roman" Then oPara.Range.Delete
Next oPara
End Sub


问:
How to close Menu in Ionic 4
I have just started ionic 4 and now i am searching a basic question,How to Close Menu in Ionic 4. ionic 4  has not properly documented till now. kindly anyone ans me.thanks in advance.</p>

答:
To close the Menu use this

Use menuCtrl in ts file in ionic 4

```<code>import { MenuController } from ‘@ionic/angular’;
</code>```

...

```<code>constructor(private menu: MenuController) {}
</code>```

//call this fn on click

```<code>openEnd() {
 this.menu.close();

 }
</code>```

OR in Html
use ion-menu-toggle

```<code><ion-menu-toggle>
<ion-item > My Button </ion-item>
</ion-menu-toggle>
</code>```

Title: How to close Menu in Ionic 4

Body:
To close the Menu use this

Use menuCtrl in ts file in ionic 4

import { MenuController } from ‘@ionic/angular’;

...

constructor(private menu: MenuController) {}

//call this fn on click

openEnd() {
 this.menu.close();

 }

OR in Html
use ion-menu-toggle

<ion-menu-toggle>
<ion-item > My Button </ion-item>
</ion-menu-toggle>


问:
Understand the utility of mocks with Jest
I can't understand at all the utility of mockings. See, I have the next module:

```<code>function Code() {
  this.generate = () => {
    const result = 'code124';
    return result;
  };
}

module.exports = Code;
</code>```

Now, I want to test it with jest:

```<code>const Code = require('../lib/code');

jest.mock('../lib/code', () => {
  return jest.fn().mockImplementation(() => {
    return {
      generate: () => [1, 2, 3]
    };
  });
});

describe('Code', () => {
  test('returns the code "code123"', () => {
    const code = new Code();
    expect(code.generate()).toBe('code123');
  });
});
</code>```

So... This test will be fine but... My code ain't so... what's the point about mocking if I can set a correct result even though my code is wrong?

答:
You're NOT supposed to mock the unit you're testing. You're supposed to mock it's dependencies.

for example:

whenever you have a dependency in the implementation:

```<code>const dependency = require('dependency');

function Code() {
  this.generate = () => {
    const result = 'code' + dependency.getNumber();
    return result;
  };
}

module.exports = Code;
</code>```

you'll be able to modify it's results to be able to test all scenarios without using the actual implementation of your dependency:

```<code>const dependency = require('dependency');
const Code = require('../lib/code');
jest.mock('dependency');

describe('Code', () => {

    describe('when dependency returns 123', () => {
      beforeAll(() => {
        dependency.getNumber.mockReturnValue('123');
      });

      it('should generate code123', () => {
        const code = new Code();
        expect(code.generate()).toEqual('code123');
      });
    });

    describe('when dependency returns 124', () => {
      beforeAll(() => {
        dependency.getNumber.mockReturnValue('124');
      });

      it('should generate code123', () => {
        const code = new Code();
        expect(code.generate()).toEqual('code124');
      });
    });

});
</code>```

Body:
I can't understand at all the utility of mockings. See, I have the next module:

function Code() {
  this.generate = () => {
    const result = 'code124';
    return result;
  };
}

module.exports = Code;

Now, I want to test it with jest:

const Code = require('../lib/code');

jest.mock('../lib/code', () => {
  return jest.fn().mockImplementation(() => {
    return {
      generate: () => [1, 2, 3]
    };
  });
});

describe('Code', () => {
  test('returns the code "code123"', () => {
    const code = new Code();
    expect(code.generate()).toBe('code123');
  });
});

So... This test will be fine but... My code ain't so... what's the point about mocking if I can set a correct result even though my code is wrong?

Body:
You're NOT supposed to mock the unit you're testing. You're supposed to mock it's dependencies.

for example:

whenever you have a dependency in the implementation:

const dependency = require('dependency');

function Code() {
  this.generate = () => {
    const result = 'code' + dependency.getNumber();
    return result;
  };
}

module.exports = Code;

you'll be able to modify it's results to be able to test all scenarios without using the actual implementation of your dependency:

const dependency = require('dependency');
const Code = require('../lib/code');
jest.mock('dependency');

describe('Code', () => {

    describe('when dependency returns 123', () => {
      beforeAll(() => {
        dependency.getNumber.mockReturnValue('123');
      });

      it('should generate code123', () => {
        const code = new Code();
        expect(code.generate()).toEqual('code123');
      });
    });

    describe('when dependency returns 124', () => {
      beforeAll(() => {
        dependency.getNumber.mockReturnValue('124');
      });

      it('should generate code123', () => {
        const code = new Code();
        expect(code.generate()).toEqual('code124');
      });
    });

});


问:
Any Core MIDI call causes app to become unresponsive
I've come across an issue with Core MIDI across a couple of iOS apps I work on, and another app I downloaded from the App Store.

What appears to be happening is the Core MIDI server crashes. After this happens, any interaction with Core MIDI functions or properties makes the calling app unresponsive. The following line is in AppDelegate's didFinishLaunchingWithOptions::

```<code>[MIDINetworkSession defaultSession].enabled = YES;
</code>```

Execution stops at this point, causing a forever hang when debugging or a #8badf00d crash otherwise.

This happens even if the Core MIDI function should return an OSStatus - the return value never comes back:

```<code>OSStatus s = MIDIObjectGetStringProperty(ref, kMIDIPropertyDisplayName, (CFStringRef*)&string);
</code>```

This call (which is in the PGMidi library) also hangs, with s not being returned. The only way to fix the issue is to restart the device.

The Core MIDI server becoming unresponsive seems related to running multiple Network Sessions from a connected Mac, but I haven't been able to pinpoint a way to replicate reliably. As well as my own apps (which use the MIKMIDI library), I have experienced unresponsive behaviour with midimittr, downloaded from the App Store.

Of course, I have no control over whether the Core MIDI Server becomes unresponsive. But is there a way to check the status of the MIDI server before making calls that may make my app unresponsive?

Update: 2019-05-10

I've found that I can get the iOS Core MIDI server into this unresponsive state by following these steps:

Set up a Network MIDI session on a Mac in Audio/MIDI Setup.

In iOS app, connect to that Network MIDI session.

Let Mac go to sleep naturally (invoking sleep from the Apple Menu doesn't appear to trigger the issue).

Once the Mac has gone to sleep do something in iOS app that will call Core MIDI.

So it's like the iOS Core MIDI server has lost connection to the Mac's MIDI network, but continues to try and execute.

Update: 2019-05-17

Apple responded to my bug report (#50657978) saying it is a duplicate of another report (#49583498) and will be closed. At the very least they are aware of the bug.

Update: 2019-07-17

This Core MIDI hang state can also be entered more quickly (for debugging purposes) by connecting the Core MIDI network via Audio Music Setup, then backgrounding your app and switching on Airplane mode on the iOS device.

答:
SEE BELOW FOR LATEST UPDATE AND FINAL SOLUTION

I've managed to come up with a partial solution to this problem. (Alas, as the root cause seems embedded in Apple's code a complete solution is not possible.)

In my AppDelegate I now run a routine which can detect whether calls to Core MIDI will time out:

```<code>func enableMIDINetworkSession() {
    let midiNetworkGroup = DispatchGroup()

    midiNetworkGroup.enter()
    DispatchQueue.global(qos: .background).async {
        MIDINetworkSession.default().isEnabled = true
        midiNetworkGroup.leave()
    }

    // If `midiNetworkGroup.leave()` is not reached in the closure above, then the result below will be `.timeOut`
    let midiNetworkTimeoutResult = midiNetworkGroup.wait(timeout: DispatchTime.now() + 10.0)

    switch midiNetworkTimeoutResult {
    case .timedOut:
        { ... }  // Calls to Core MIDI will cause app to hang. Handle as required. Note: app will crash anyway at some point in the future.

    case .success:
        break    // All good, continue as before
    }
}
</code>```

A thing to note here: if you intend to display an alert in the case that midiNetworkTimeoutResult == .timeOut then keep in mind that any calls to Core MIDI that occur straight after this may cause the alert to not be presented (as the main queue will be blocked).

Update: 2019-07-17

It's important to mention with the solution above that if you end up in the .timedOut case above, the app will crash at some point in the future anyway, as it catches up with the MIDINetworkSession.default().isEnabled call.

The gap before the crash is around 5 minutes, so there's enough time to display an alert and advise the user to restart their device.

Update: 2019-08-14

Recommended solution

It appears that this issue has been resolved by Apple in iOS 12.4. The solution then would be to advise your users to update to iOS 12.4 or later.

(Also, this issue seems only to affect iOS 12.2 and 12.3 versions.)

Body:
I've come across an issue with Core MIDI across a couple of iOS apps I work on, and another app I downloaded from the App Store.

What appears to be happening is the Core MIDI server crashes. After this happens, any interaction with Core MIDI functions or properties makes the calling app unresponsive. The following line is in AppDelegate's didFinishLaunchingWithOptions::

[MIDINetworkSession defaultSession].enabled = YES;

Execution stops at this point, causing a forever hang when debugging or a #8badf00d crash otherwise.

This happens even if the Core MIDI function should return an OSStatus - the return value never comes back:

OSStatus s = MIDIObjectGetStringProperty(ref, kMIDIPropertyDisplayName, (CFStringRef*)&string);

This call (which is in the PGMidi library) also hangs, with s not being returned. The only way to fix the issue is to restart the device.

The Core MIDI server becoming unresponsive seems related to running multiple Network Sessions from a connected Mac, but I haven't been able to pinpoint a way to replicate reliably. As well as my own apps (which use the MIKMIDI library), I have experienced unresponsive behaviour with midimittr, downloaded from the App Store.

Of course, I have no control over whether the Core MIDI Server becomes unresponsive. But is there a way to check the status of the MIDI server before making calls that may make my app unresponsive?

Update: 2019-05-10

I've found that I can get the iOS Core MIDI server into this unresponsive state by following these steps:

Set up a Network MIDI session on a Mac in Audio/MIDI Setup.

In iOS app, connect to that Network MIDI session.

Let Mac go to sleep naturally (invoking sleep from the Apple Menu doesn't appear to trigger the issue).

Once the Mac has gone to sleep do something in iOS app that will call Core MIDI.

So it's like the iOS Core MIDI server has lost connection to the Mac's MIDI network, but continues to try and execute.

Update: 2019-05-17

Apple responded to my bug report (#50657978) saying it is a duplicate of another report (#49583498) and will be closed. At the very least they are aware of the bug.

Update: 2019-07-17

This Core MIDI hang state can also be entered more quickly (for debugging purposes) by connecting the Core MIDI network via Audio Music Setup, then backgrounding your app and switching on Airplane mode on the iOS device.

Body:
SEE BELOW FOR LATEST UPDATE AND FINAL SOLUTION

I've managed to come up with a partial solution to this problem. (Alas, as the root cause seems embedded in Apple's code a complete solution is not possible.)

In my AppDelegate I now run a routine which can detect whether calls to Core MIDI will time out:

func enableMIDINetworkSession() {
    let midiNetworkGroup = DispatchGroup()

    midiNetworkGroup.enter()
    DispatchQueue.global(qos: .background).async {
        MIDINetworkSession.default().isEnabled = true
        midiNetworkGroup.leave()
    }

    // If `midiNetworkGroup.leave()` is not reached in the closure above, then the result below will be `.timeOut`
    let midiNetworkTimeoutResult = midiNetworkGroup.wait(timeout: DispatchTime.now() + 10.0)

    switch midiNetworkTimeoutResult {
    case .timedOut:
        { ... }  // Calls to Core MIDI will cause app to hang. Handle as required. Note: app will crash anyway at some point in the future.

    case .success:
        break    // All good, continue as before
    }
}

A thing to note here: if you intend to display an alert in the case that midiNetworkTimeoutResult == .timeOut then keep in mind that any calls to Core MIDI that occur straight after this may cause the alert to not be presented (as the main queue will be blocked).

Update: 2019-07-17

It's important to mention with the solution above that if you end up in the .timedOut case above, the app will crash at some point in the future anyway, as it catches up with the MIDINetworkSession.default().isEnabled call.

The gap before the crash is around 5 minutes, so there's enough time to display an alert and advise the user to restart their device.

Update: 2019-08-14

Recommended solution

It appears that this issue has been resolved by Apple in iOS 12.4. The solution then would be to advise your users to update to iOS 12.4 or later.

(Also, this issue seems only to affect iOS 12.2 and 12.3 versions.)


问:
Unable to run iOS 3.X app compiled with iOS SDK 4.3
I've recently upgraded to xCode 4.0.1 in order to use the latest iOS SDK (4.3). I'm currently doing development for iOS 3.X devices, but looking to expand into iOS 4.X in the near future.

The problem is, I can't seem to successfully run anything on my current 3.X devices. As I understand it, the 4.3 SDK supports compiling to all versions of iOS 3.0 and subsequent, and certainly I can compile such apps just fine. But if I try to run it in the simulator or on a device, it begins to load and then just crashes.

For now I'm simply trying to get the default window-based application running without any modifications. I've selected 4.3 as the base SDK, and set my deployment target to 3.0. I can select every version of iOS from 3.0 up as my build target, but only using 4.3 seems to actually work at all.

When I run the app on my phone, I get the following in the logs:

```<code>GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:56:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=arm-apple-darwin".tty /dev/ttys002
warning: Unable to read symbols from "dyld" (prefix __dyld_) (not yet mapped into memory).
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.3 (7E18)/Symbols/System/Library/Frameworks/UIKit.framework/UIKit (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols from "Foundation" (not yet mapped into memory).
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.3 (7E18)/Symbols/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
warning: Unable to read symbols from "libgcc_s.1.dylib" (not yet mapped into memory).
warning: Unable to read symbols from "libSystem.B.dylib" (not yet mapped into memory).
warning: Unable to read symbols from "libobjc.A.dylib" (not yet mapped into memory).
warning: Unable to read symbols from "CoreFoundation" (not yet mapped into memory).
target remote-mobile /tmp/.XcodeGDBRemote-18423-39
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
[Switching to process 11779 thread 0x0]
[Switching to process 11779 thread 0x0]
gdb stack crawl at point of internal error:
0   gdb-arm-apple-darwin                0x000000010010974a internal_vproblem + 308
1   gdb-arm-apple-darwin                0x0000000100109924 internal_verror + 27
2   gdb-arm-apple-darwin                0x00000001001099c2 align_down + 0
3   gdb-arm-apple-darwin                0x0000000100150c5e macosx_solib_add + 794
4   gdb-arm-apple-darwin                0x000000010016417c remote_macosx_complete_create_or_attach + 187
5   gdb-arm-apple-darwin                0x000000010016489e remote_macosx_create_inferior + 1252
6   gdb-arm-apple-darwin                0x000000010005f6c3 run_command_1 + 586
7   gdb-arm-apple-darwin                0x0000000100107b7f execute_command + 557
8   gdb-arm-apple-darwin                0x00000001000171e7 mi_execute_async_cli_command + 204
9   gdb-arm-apple-darwin                0x00000001000168e5 captured_mi_execute_command + 344
10  gdb-arm-apple-darwin                0x0000000100072a62 catch_exception + 57
11  gdb-arm-apple-darwin                0x000000010001443e mi_execute_command + 140
12  gdb-arm-apple-darwin                0x0000000100077721 process_event + 133
13  gdb-arm-apple-darwin                0x0000000100078435 gdb_do_one_event + 1049
14  gdb-arm-apple-darwin                0x0000000100072b49 catch_errors + 70
/SourceCache/gdb/gdb-1518/src/gdb/macosx/macosx-nat-dyld.c:1648: internal-error: unrecognized shared library breakpoint
A problem internal to GDB has been detected,
further debugging may prove unreliable.
</code>```

I'm guessing that somewhere along the line, the app's not being set up correctly to link to the 3.X version API, hence the "unable to read symbol" stuff appearing in the logs. I just can't seem to figure out how to rectify the situation.

Any suggestions gratefully appreciated!

答:
Open Build settings of your project

Specify key IOS DEPLOYMENT TARGET as  3.2

You compile for 4.3. But your app will run also on 3.2 devices.. .Pay attention to the methods that you call... If you use methods that are only in 4.3 framework you must check it at runtime using if([object respondsToSelector: ... otherwise your app will crash on previous iOS

Body:
I've recently upgraded to xCode 4.0.1 in order to use the latest iOS SDK (4.3). I'm currently doing development for iOS 3.X devices, but looking to expand into iOS 4.X in the near future.

The problem is, I can't seem to successfully run anything on my current 3.X devices. As I understand it, the 4.3 SDK supports compiling to all versions of iOS 3.0 and subsequent, and certainly I can compile such apps just fine. But if I try to run it in the simulator or on a device, it begins to load and then just crashes.

For now I'm simply trying to get the default window-based application running without any modifications. I've selected 4.3 as the base SDK, and set my deployment target to 3.0. I can select every version of iOS from 3.0 up as my build target, but only using 4.3 seems to actually work at all.

When I run the app on my phone, I get the following in the logs:

GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:56:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=arm-apple-darwin".tty /dev/ttys002
warning: Unable to read symbols from "dyld" (prefix __dyld_) (not yet mapped into memory).
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.3 (7E18)/Symbols/System/Library/Frameworks/UIKit.framework/UIKit (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols from "Foundation" (not yet mapped into memory).
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.3 (7E18)/Symbols/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
warning: Unable to read symbols from "libgcc_s.1.dylib" (not yet mapped into memory).
warning: Unable to read symbols from "libSystem.B.dylib" (not yet mapped into memory).
warning: Unable to read symbols from "libobjc.A.dylib" (not yet mapped into memory).
warning: Unable to read symbols from "CoreFoundation" (not yet mapped into memory).
target remote-mobile /tmp/.XcodeGDBRemote-18423-39
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
[Switching to process 11779 thread 0x0]
[Switching to process 11779 thread 0x0]
gdb stack crawl at point of internal error:
0   gdb-arm-apple-darwin                0x000000010010974a internal_vproblem + 308
1   gdb-arm-apple-darwin                0x0000000100109924 internal_verror + 27
2   gdb-arm-apple-darwin                0x00000001001099c2 align_down + 0
3   gdb-arm-apple-darwin                0x0000000100150c5e macosx_solib_add + 794
4   gdb-arm-apple-darwin                0x000000010016417c remote_macosx_complete_create_or_attach + 187
5   gdb-arm-apple-darwin                0x000000010016489e remote_macosx_create_inferior + 1252
6   gdb-arm-apple-darwin                0x000000010005f6c3 run_command_1 + 586
7   gdb-arm-apple-darwin                0x0000000100107b7f execute_command + 557
8   gdb-arm-apple-darwin                0x00000001000171e7 mi_execute_async_cli_command + 204
9   gdb-arm-apple-darwin                0x00000001000168e5 captured_mi_execute_command + 344
10  gdb-arm-apple-darwin                0x0000000100072a62 catch_exception + 57
11  gdb-arm-apple-darwin                0x000000010001443e mi_execute_command + 140
12  gdb-arm-apple-darwin                0x0000000100077721 process_event + 133
13  gdb-arm-apple-darwin                0x0000000100078435 gdb_do_one_event + 1049
14  gdb-arm-apple-darwin                0x0000000100072b49 catch_errors + 70
/SourceCache/gdb/gdb-1518/src/gdb/macosx/macosx-nat-dyld.c:1648: internal-error: unrecognized shared library breakpoint
A problem internal to GDB has been detected,
further debugging may prove unreliable.

I'm guessing that somewhere along the line, the app's not being set up correctly to link to the 3.X version API, hence the "unable to read symbol" stuff appearing in the logs. I just can't seem to figure out how to rectify the situation.

Any suggestions gratefully appreciated!


问:
SQL Combining two different tables
(P.S. I am still learning SQL and you can consider me a newbie)

I have 2 sample tables as follows:

Table 1

```<code>|Profile_ID|  |Img_Path|
</code>```

Table 2

```<code>|Profile_ID|  |UName|   |Default_Title|
</code>```

My scenario is, from the 2nd table, i need to fetch all the records that contain a certain word, for which i have the following query :

```<code>Select Profile_Id,UName from
Table2 Where
Contains(Default_Title, 'Test')

ORDER BY Profile_Id
OFFSET 5 ROWS
FETCH NEXT 20 ROWS ONLY
</code>```

(Note that i am setting the OFFSET due to requirements.)

Now, the scenario is, as soon as i retrieve 1 record from the 2nd table, i need to fetch the record from the 1st table based on the Profile_Id.

So, i need to return the following 2 results in one single statement :

```<code>|Profile_Id|   |Img_Path|

|Profile_Id|   |UName|
</code>```

And i need to return the results in side-by-side columns, like :

```<code>|Profile_Id|   |Img_Path|   |UName|
</code>```

(Note i had to merge 2 Profile_Id columns into one as they both contain same data)

I am still learning SQL and i am learning about Union, Join etc. but i am a bit confused as to which way to go.

答:
```<code>SELECT a.Profile_Id, a.Img_Path, b.UName
FROM table1 a INNER JOIN table2 b ON a.Profile_Id=b.Profile_Id
WHERE b.Default_Title = 'Test'
</code>```

Title: SQL Combining two different tables

Body:
(P.S. I am still learning SQL and you can consider me a newbie)

I have 2 sample tables as follows:

Table 1

|Profile_ID|  |Img_Path|

Table 2

|Profile_ID|  |UName|   |Default_Title|

My scenario is, from the 2nd table, i need to fetch all the records that contain a certain word, for which i have the following query :

Select Profile_Id,UName from
Table2 Where
Contains(Default_Title, 'Test')

ORDER BY Profile_Id
OFFSET 5 ROWS
FETCH NEXT 20 ROWS ONLY

(Note that i am setting the OFFSET due to requirements.)

Now, the scenario is, as soon as i retrieve 1 record from the 2nd table, i need to fetch the record from the 1st table based on the Profile_Id.

So, i need to return the following 2 results in one single statement :

|Profile_Id|   |Img_Path|

|Profile_Id|   |UName|

And i need to return the results in side-by-side columns, like :

|Profile_Id|   |Img_Path|   |UName|

(Note i had to merge 2 Profile_Id columns into one as they both contain same data)

I am still learning SQL and i am learning about Union, Join etc. but i am a bit confused as to which way to go.


问:
VideoView delays when starting to play a Multicast stream (just sometimes)
I have a simple Android application which contains a WebView to load my Web_Based application and a VideoView to play Video (using HTTP protocol) and Multicast Stream (Live TV using UDP Protocol).

The Web_Based application, Video Server and Live TV Server are in a local Server (Ubuntu 12.04) and so my Android Application is connected to them locally with Ethernet Cable (Not via Internet).

Also my Android Device is a STB with Android Version 6.

The Android application is developed to play Video or Live TV when it is starts just by clicking on a button.But the issue is that JUST SOMETIMES, when I turn the STB on (and instantly starting the Android application), there is a delay for about 30 seconds to start Live TV. This issue is not happening for Video at all.

A sample of Live TV stream is udp://239.0.0.1:1234

A sample of Video url is http://192.168.200.235/test.mp4

// This is a pert of my main function to play UDP Stream

```<code>PlayerActivity.videoView.stopPlayback();
final Uri video = Uri.parse("udp://"+url.replaceAll("\\s+",""));
PlayerActivity.getInstance().runOnUiThread(new Runnable() {
    @Override
    public void run() {
        PlayerActivity.videoView.setVisibility(View.GONE);
        PlayerActivity.videoView.setVisibility(View.VISIBLE);
        PlayerActivity.videoView.setVideoURI(video);
        PlayerActivity.videoView.start();

        PlayerActivity.videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.e("ERROR LOG FOR UDP STREAM",":( I don't get any error here !");
                return false;
            }
        });
    }
});
</code>```

答: Although Android can play UDP stream, but it's not built for this. So, it's better to use HSL or RTMP protocol for live stream playback and also for video file You can use HLS. </p>

Body:
I have a simple Android application which contains a WebView to load my Web_Based application and a VideoView to play Video (using HTTP protocol) and Multicast Stream (Live TV using UDP Protocol).

The Web_Based application, Video Server and Live TV Server are in a local Server (Ubuntu 12.04) and so my Android Application is connected to them locally with Ethernet Cable (Not via Internet).

Also my Android Device is a STB with Android Version 6.

The Android application is developed to play Video or Live TV when it is starts just by clicking on a button.But the issue is that JUST SOMETIMES, when I turn the STB on (and instantly starting the Android application), there is a delay for about 30 seconds to start Live TV. This issue is not happening for Video at all.

A sample of Live TV stream is udp://239.0.0.1:1234

A sample of Video url is http://192.168.200.235/test.mp4

// This is a pert of my main function to play UDP Stream

PlayerActivity.videoView.stopPlayback();
final Uri video = Uri.parse("udp://"+url.replaceAll("\\s+",""));
PlayerActivity.getInstance().runOnUiThread(new Runnable() {
    @Override
    public void run() {
        PlayerActivity.videoView.setVisibility(View.GONE);
        PlayerActivity.videoView.setVisibility(View.VISIBLE);
        PlayerActivity.videoView.setVideoURI(video);
        PlayerActivity.videoView.start();

        PlayerActivity.videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.e("ERROR LOG FOR UDP STREAM",":( I don't get any error here !");
                return false;
            }
        });
    }
});


问:
OTRS ITSMChange API service
Did anybody use to write services, connected with ITSMChangeManagement of OTRS? Is there any API to this thing? I need smth. like GenericTicketConnector. Thank you.

答: No, there is nothing with ITSMChangeManagement. Only Tickets, FAQ and ConfigItems can be used with the GenericInterface of the Community Edition </p>

Title: OTRS ITSMChange API service


问:
Why am I getting fatal: file is outside repository from Jenkins
I am trying to push a file on Git within a Jenkins job:

IN JENKINS I added a Windows shell command job and this is the first command:

```<code>git add "C:\Users\AMRABET\Documents\VSC\HW\index.html"
</code>```

But I got the following error:

```<code>fatal: C:\Users\AMRABET\Documents\VSC\HW\index.html: 'C:\Users\AMRABET\Documents\VSC\HW\index.html' is outside repository
</code>```

Same command works from Windows CMD. It works well from windows. My question is different because I only get it in Jenkins

Any help?

答:
As suggested in the comments I was just out of the git repo.

Actually when in Jenkins you do

```<code>cd C:\Location
AnotherShellAction
git add RandomFile
</code>```

the git action will be executed not from C:\Location you mentionned but from the default workspace.
It means that you need to enter the wanted Location again after every instruction. Good way would then be:

```<code>cd C:\Location
AnotherShellAction
cd C:\Location
git add RandomFile
</code>```

Body:
I am trying to push a file on Git within a Jenkins job:

IN JENKINS I added a Windows shell command job and this is the first command:

git add "C:\Users\AMRABET\Documents\VSC\HW\index.html"

But I got the following error:

fatal: C:\Users\AMRABET\Documents\VSC\HW\index.html: 'C:\Users\AMRABET\Documents\VSC\HW\index.html' is outside repository

Same command works from Windows CMD. It works well from windows. My question is different because I only get it in Jenkins

Any help?

Body:
As suggested in the comments I was just out of the git repo.

Actually when in Jenkins you do

cd C:\Location
AnotherShellAction
git add RandomFile

the git action will be executed not from C:\Location you mentionned but from the default workspace.
It means that you need to enter the wanted Location again after every instruction. Good way would then be:

cd C:\Location
AnotherShellAction
cd C:\Location
git add RandomFile