答:
```<code>SELECT ...
FROM ...
GROUP BY U.Id, U.[Name]
HAVING 2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (3, 4) THEN UI.ItemId END)
   AND 3 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (5, 6, 7) THEN UI.ItemId END)
   AND ...
</code>```

UI.ItemId IN (2, 7) OR UI.ItemId IN (3,4) OR UI.ItemId = 2

```<code>HAVING 2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (2, 7) THEN UI.ItemId END)
    OR 2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (3, 4) THEN UI.ItemId END)
    OR 1 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (2) THEN UI.ItemId END)
</code>```

If the condition means "one of 3 listed conditions, and no records out of matched condition", then modify each separate into

```<code>HAVING (     2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (2, 7) THEN UI.ItemId END)
         AND 0 = COUNT(DISTINCT CASE WHEN UI.ItemId NOT IN (2, 7) THEN UI.ItemId END)
       )
   OR ...
</code>```

Body:
Given this user and User's items table:

With this select below I'm able to get the candidates that have both item 3 and 4:

Select
     U.Id,
     U.[Name],
     STRING_AGG(UI.ItemId, ',') as Items
from Users U
     Left Join UserItems UI on UI.UserId = U.Id
Where (
     UI.ItemId IN (3, 4)
)
Group By U.Id, U.[Name]
Having Count(*) = 2

But how can I get all candidates using more conditions?
For example:

UI.ItemId IN (2, 7) OR UI.ItemId IN (3,4) OR UI.ItemId = 2

Any idea on how to solve this?

Body:
SELECT ...
FROM ...
GROUP BY U.Id, U.[Name]
HAVING 2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (3, 4) THEN UI.ItemId END)
   AND 3 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (5, 6, 7) THEN UI.ItemId END)
   AND ...

UI.ItemId IN (2, 7) OR UI.ItemId IN (3,4) OR UI.ItemId = 2

HAVING 2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (2, 7) THEN UI.ItemId END)
    OR 2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (3, 4) THEN UI.ItemId END)
    OR 1 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (2) THEN UI.ItemId END)

If the condition means "one of 3 listed conditions, and no records out of matched condition", then modify each separate into

HAVING (     2 = COUNT(DISTINCT CASE WHEN UI.ItemId IN (2, 7) THEN UI.ItemId END)
         AND 0 = COUNT(DISTINCT CASE WHEN UI.ItemId NOT IN (2, 7) THEN UI.ItemId END)
       )
   OR ...


来源: stackexchange

问:
DbUnit for C++?
We're developing in C++ under Linux and about to set up automated tests. We intend to use a testing framework like CppUnit oder CxxTest. We're using Ant to build the software and we will also use it to run the tests.

As some tests are going to involve database access, we are looking for a tool or framework which facilitates the tasks of preparing and cleaning up test data in the database - just like DbUnit (a JUnit extension) in the Java world.

Another option may be to employ the actual DbUnit - a Java VM is available. Making use of DbUnit's Ant task seems to be most promising. Any related field reports are welcome!

答: I would recommend boost unit testing.  You would probably have to use the setup and teardown to manually clean up the database.  Of course, you could build your own C++ DbUnit in ODBC.  IF you do let me know because I could use this as well!</p>

OwnerDisplayName: Tom

LastEditorDisplayName: Tom

ContentLicense: CC BY-SA 2.5

Title: DbUnit for C++?

OwnerDisplayName: bnantz


问:
How do I change Emacs' default font size and font type?
I am using Emacs 23.3. How can I change the font size and font type?</p>

答:
You can use the menu bar. Go to Options->Set Default Font....

After you choose a font, don't forget to press Options->Save Options—otherwise your new font will not be saved after you close Emacs.

ContentLicense: CC BY-SA 4.0

ContentLicense: CC BY-SA 3.0


问:
Piping into grep using cat returns error: no such file or directory
I am practicing on bash. When I try this command, I get an error: "grep: where: No such file or directory".</p>

```<code>cat file2.txt | tr " " "\n" | grep –i where | wc -l
</code>```

```<code>Content of file2.txt = 1 2 3 4 where 5 where 7 where

</code>```

答:
Multiple ways:

With GNU grep:

grep -oiw echo script.sh | wc -l
```

<ul>
<li><code>-o</code>: Output matches only.</li>
<li><code>-i</code>: Case-insensitive matches.</li>
<li><code>-w</code>: Whole word matches.</li>
<li><code>wc -l</code>: Counting matches.</li>
</ul>

<p>With <code>sed</code> to split commands into one per line:</p>

<pre class="lang-sh prettyprint-override"><code>sed 's/[[:space:][:punct:]]\+/\n/g' script.sh | grep -ciF echo
</code>```

sed 's/[[:space:][:punct:]]\+/\n/g': Replace all spaces, carriage returns, tabs, punctuation with a newline.

grep -ciF echo: Count lines with case-insensitive match of plain text echo (no RegEx).

Body:
I am practicing on bash. When I try this command, I get an error: "grep: where: No such file or directory".

cat file2.txt | tr " " "\n" | grep –i where | wc -l

Content of file2.txt = 1 2 3 4 where 5 where 7 where

Body:
Multiple ways:

With GNU grep:

grep -oiw echo script.sh | wc -l

-o: Output matches only.

-i: Case-insensitive matches.

-w: Whole word matches.

wc -l: Counting matches.

With sed to split commands into one per line:

sed 's/[[:space:][:punct:]]\+/\n/g' script.sh | grep -ciF echo

sed 's/[[:space:][:punct:]]\+/\n/g': Replace all spaces, carriage returns, tabs, punctuation with a newline.

grep -ciF echo: Count lines with case-insensitive match of plain text echo (no RegEx).


问:
Segmentation fault in C
When I try to run the following C program in my VS code it shows segmentation fault core dumped. How can I fix it?</p>

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

void read(student);
void display(student);

struct student {
    int roll, result;
    char name[20], depart[20], sex;
    float percent, marks[5];
};

void main() {
    struct student s;
    read(s);
}

void read(struct student std) {
    int c = 0, i;
    printf("enter the roll no:");
    scanf("%d", &std.roll);
    printf("enter the name:\n");
    scanf("%s", std.name);
    printf("enter Sex:\n");
    scanf(" %c", &std.sex);
    printf("Enter the department:\n");
    scanf("%s", std.depart);
    printf("enter the marks in 5 subjects:\n");
    for (i = 0; i < 5; i++) {
        scanf("%d", std.marks[i]);
    }
}
</code>```

答:
There are multiple problems in your code:

the prototypes void read(student); and void display(student); refer to an undefined type student.

it is problematic to call a function read because it conflicts with a similar function in the C library that makes a system call to read files. Either make it static or better rename it read_student.

You pass the student structure by value to the read function: read will only modify its argument, not the structure in the main function. read should receive a pointer to the structure in the caller's scope.

main should be defined as int main(void).

scanf() expects pointers to the destination variables. Passing the variable values as in scanf("%d", std.marks[i]) will definitely cause undefined behavior very likely resulting in a crash.

Here is a modified version:

#include <stdio.h>
#include <string.h>

struct student {
    int roll, result;
    char name[20], depart[20], sex;
    float percent, marks[5];
};

void read_student(struct student *);
void display_student(const struct student *);

int main() {
    struct student s;
    read_student(&s);
    return 0;
}

void read_student(struct student *std) {
    int i;
    printf("enter the roll no: ");
    scanf("%d", &std->roll);
    printf("enter the name:\n");
    scanf("%19s", std->name);
    printf("enter Sex:\n");
    scanf(" %c", &std->sex);
    printf("Enter the department:\n");
    scanf("%19s", std->depart);
    printf("enter the marks in 5 subjects:\n");
    for (i = 0; i < 5; i++) {
        scanf("%d", &std->marks[i]);
    }
}
```

OwnerDisplayName: Sudru

Title: Segmentation fault in C

Body:
When I try to run the following C program in my VS code it shows segmentation fault core dumped. How can I fix it?

#include <stdio.h>
#include <string.h>

void read(student);
void display(student);

struct student {
    int roll, result;
    char name[20], depart[20], sex;
    float percent, marks[5];
};

void main() {
    struct student s;
    read(s);
}

void read(struct student std) {
    int c = 0, i;
    printf("enter the roll no:");
    scanf("%d", &std.roll);
    printf("enter the name:\n");
    scanf("%s", std.name);
    printf("enter Sex:\n");
    scanf(" %c", &std.sex);
    printf("Enter the department:\n");
    scanf("%s", std.depart);
    printf("enter the marks in 5 subjects:\n");
    for (i = 0; i < 5; i++) {
        scanf("%d", std.marks[i]);
    }
}


问:
Combine multiple conditions with Having clause
Given this user and User's items table:

With this select below I'm able to get the candidates that have both item 3 and 4:

```<code>Select
     U.Id,
     U.[Name],
     STRING_AGG(UI.ItemId, ',') as Items
from Users U
     Left Join UserItems UI on UI.UserId = U.Id
Where (
     UI.ItemId IN (3, 4)
)
Group By U.Id, U.[Name]
Having Count(*) = 2
</code>```

But how can I get all candidates using more conditions?
For example:

UI.ItemId IN (2, 7) OR UI.ItemId IN (3,4) OR UI.ItemId = 2

Any idea on how to solve this?

答:
First, you are looking for matches between the two tables.  Use a JOIN rather than LEFT JOIN.

You can use a more complex having clause:

```<code>having (sum(case when ui.itemid = 2 then 1 else 0 end) > 0 and
        sum(case when ui.itemid = 7 then 1 else 0 end) > 0
       ) or
       (sum(case when ui.itemid = 3 then 1 else 0 end) > 0 and
        sum(case when ui.itemid = 4 then 1 else 0 end) > 0
       ) or
       sum(case when ui.itemid = 2 then 1 else 0 end) > 0
</code>```

Of course, the first condition is a subset of the last condition, so it is not necessary.  But this illustrates the basic idea.

If you know you have no duplicates -- as your original query suggests -- then I would also suggest:

```<code>having sum(case when ui.itemid in (2, 7) then 1 else 0 end) = 2 or
       sum(case when ui.itemid in (3, 4) then 1 else 0 end) = 2 or
       sum(case when ui.itemid = 2 then 1 else 0 end) = 1
</code>```

Body:
First, you are looking for matches between the two tables.  Use a JOIN rather than LEFT JOIN.

You can use a more complex having clause:

having (sum(case when ui.itemid = 2 then 1 else 0 end) > 0 and
        sum(case when ui.itemid = 7 then 1 else 0 end) > 0
       ) or
       (sum(case when ui.itemid = 3 then 1 else 0 end) > 0 and
        sum(case when ui.itemid = 4 then 1 else 0 end) > 0
       ) or
       sum(case when ui.itemid = 2 then 1 else 0 end) > 0

Of course, the first condition is a subset of the last condition, so it is not necessary.  But this illustrates the basic idea.

If you know you have no duplicates -- as your original query suggests -- then I would also suggest:

having sum(case when ui.itemid in (2, 7) then 1 else 0 end) = 2 or
       sum(case when ui.itemid in (3, 4) then 1 else 0 end) = 2 or
       sum(case when ui.itemid = 2 then 1 else 0 end) = 1


问:
list with lots of data in laravel
I have a bank with more than 10000 registered users.
It turns out that my method is listing everything and it causes a very slow return of data.

```<code>$users = \App\User::all();
</code>```

it is taking almost 40 seconds to show the list with the paginations.

How can I solve this? Filters?

答:
2 thing should be indicate:

First the relations of this model may be complex and maybe in rest of code you use lazy load instead of eager load.
But az you said in comments this model is not complex.

Second:maybe you test this query in phpmyadmin and it take time better and fast and it make you surprised.

Phpmyadmin use limit automatilcaly.you can chunck or paginate your records for this purpose and make your performance much better.

Title: list with lots of data in laravel

Body:
I have a bank with more than 10000 registered users.
It turns out that my method is listing everything and it causes a very slow return of data.

$users = \App\User::all();

it is taking almost 40 seconds to show the list with the paginations.

How can I solve this? Filters?


问:
Manually create the same dataframe returned from fromJSON function
I have a JSON string which returns a dataframe using jsonlite package.

```<code> library(jsonlite)
 d  <- fromJSON('[{"x":"A","value":100},{"x":"B","value":100},{"x":["A","B"],"value":20}]' )
</code>```

it gives me

```<code>     x value
1    A   100
2    B   100
3 A, B    20
</code>```

But I want to re-create the same dataframe manually. Class of column x is a list.

My attempt is as follows:

```<code>   data.frame(x = c("A","B",list(c("A","B"))),value = c(100,100,20))
</code>```

This gives me an error of differing no. of rows

答:
We can wrap with I on the list in base R

```<code>d1 <- data.frame(x = I(list("A", "B", c("A", "B"))), value = c(100, 100, 20))
d1
#      x value
#1    A   100
#2    B   100
#3 A, B    20
</code>```

It would add an attribute for "AsIs",

```<code>attr(d1$x, "class")
#[1] "AsIs"
</code>```

but it is the same data by ignoring the attributes

```<code>all.equal(d1, d, check.attributes = FALSE)
#[1] TRUE
</code>```

Or if we assign the attribute to NULL, it would be the same

```<code>attr(d1$x, "class") <- NULL
all.equal(d1, d)
#[1] TRUE
</code>```

and if we use a tibble, it is more direct`

```<code>library(tibble)
tibble(x = list("A", "B", c("A", "B")), value = c(100, 100, 20))
</code>```

Body:
I have a JSON string which returns a dataframe using jsonlite package.

 library(jsonlite)
 d  <- fromJSON('[{"x":"A","value":100},{"x":"B","value":100},{"x":["A","B"],"value":20}]' )

it gives me

     x value
1    A   100
2    B   100
3 A, B    20

But I want to re-create the same dataframe manually. Class of column x is a list.

My attempt is as follows:

   data.frame(x = c("A","B",list(c("A","B"))),value = c(100,100,20))

This gives me an error of differing no. of rows

Body:
We can wrap with I on the list in base R

d1 <- data.frame(x = I(list("A", "B", c("A", "B"))), value = c(100, 100, 20))
d1
#      x value
#1    A   100
#2    B   100
#3 A, B    20

It would add an attribute for "AsIs",

attr(d1$x, "class")
#[1] "AsIs"

but it is the same data by ignoring the attributes

all.equal(d1, d, check.attributes = FALSE)
#[1] TRUE

Or if we assign the attribute to NULL, it would be the same

attr(d1$x, "class") <- NULL
all.equal(d1, d)
#[1] TRUE

and if we use a tibble, it is more direct`

library(tibble)
tibble(x = list("A", "B", c("A", "B")), value = c(100, 100, 20))


问:
git log show everything _except_ tags
The situation:
I use tags in git to flag version releases. I also have a quick command to show me a simple graph in git with all my active dev branches:

```<code>git log --oneline --graph --simplify-by-decoration --all
</code>```

The issue is that this shows all of the tags, eating up a lot of real estate on the screen. Is there a way I can filter out the tags? I still want all of the other information (i.e. just the active development branches).

I've tried using --exclude="refs/tags/* to no avail - any other suggestions?

I've included an image of what my git log looks like with all the tags cluttering it.

答:
You can easily get close:

```<code>git log --graph --decorate --oneline \
        --simplify-by-decoration --branches --decorate-refs=refs/heads
</code>```

Add --decorate-refs=refs/remotes to include remote branches in the decoration, --remotes to include them in the starter tips.

Title: git log show everything _except_ tags

Body:
The situation:
I use tags in git to flag version releases. I also have a quick command to show me a simple graph in git with all my active dev branches:

git log --oneline --graph --simplify-by-decoration --all

The issue is that this shows all of the tags, eating up a lot of real estate on the screen. Is there a way I can filter out the tags? I still want all of the other information (i.e. just the active development branches).

I've tried using --exclude="refs/tags/* to no avail - any other suggestions?

I've included an image of what my git log looks like with all the tags cluttering it.

Body:
You can easily get close:

git log --graph --decorate --oneline \
        --simplify-by-decoration --branches --decorate-refs=refs/heads

Add --decorate-refs=refs/remotes to include remote branches in the decoration, --remotes to include them in the starter tips.


问:
Angular 8: Trying to use form data to format a string in a service, but page keeps reloading, variable not being reassigned form value
Basically, I want to take the zip code in the form, format a URL, make an API call on that URL, and then print data from the JSON to the screen.

I'm already formatting a URL and getting the data I need.
The problem is that I can't get the form data to store in a variable, and use that to format my URL.

Here's component.ts:

```<code>import { WeatherdataService } from '../services/weatherdata.service';
import { THIS_EXPR } from '@angular/compiler/src/output/output_ast';
import { FormControl,FormGroup } from '@angular/forms';
@Component({
  selector: 'app-dailyda',
  templateUrl: './dailyda.component.html',
  styleUrls: ['./dailyda.component.scss']
})
export class DailydaComponent implements OnInit {

  zipForm = new FormGroup({
    zipCode:new FormControl('37064') //Default value in quotes
  })
  zipcode = 60610;
  onSubmit() {
    this.zipcode = this.zipForm.value.zipCode;
    console.log(this.zipcode);
  }
  weather;
  temp;
  press;
  dry_da;
  //Crunch your numbers here, store it in a variable called result, etc.,
  //And in the template, {{ result }} will display that number.
  ISAT = 288.15;
  ISAP = 1013.25;
  expon = 0.234978134;
  // lapse_rate = 0.0065;
  // R = 8.3144598; Replaced all this with expon
  // g = 9.80665;
  // M = 0.028964; // This is the molar mass of DRY air.

  constructor(private weatherdataService: WeatherdataService) { }

  ngOnInit() {
    this.weatherdataService.getWeather(this.zipcode).subscribe((data)=>{
       // add zip code to .getWeather call
      this.weather = data;
      this.temp = this.weather.main.temp;
      this.press = this.weather.main.pressure;
      this.dry_da = Math.round(3.28084 * this.ISAT/0.0065 *(1 - ((this.press/this.ISAP)/(this.temp/this.ISAT))** (this.expon)));
    }
    )};

};
</code>```

Here's compnonent.html:
(I tried using ngSubmit(), but the submit button reloads my page, and nothing shows up.

```<code>    <label>
        Zip Code:
        <input type="text" [formControl]='zipCode'>
    </label>
    <button type="button" (click)="onSubmit()">Submit</button>
</form>
<div *ngIf = 'zipForm'>
    <p>Current Zip: {{ zipCode.value }}</p>
</div>
<div *ngIf = "weather"> <!-- *ngIf prevents errors, because of the
delay in retrieving JSON from the API. Once weather has a value, this
div is displayed.-->
    <h4> Density Altitude (assumes dry air): </h4>
    <h2><strong>{{ dry_da }} ft</strong></h2>
    <h4> Temp in Kelvins: </h4>
    <h2><strong>{{ temp }}</strong></h2>
    <h4> Static Atmospheric Pressure in hPa: </h4>
    <h2><strong>{{ press }}</strong></h2>
</div>
</code>```

Here's the service.ts:

```<code>import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class WeatherdataService {
  API_KEY = 'blahblahblah';

  constructor(private httpClient: HttpClient) { }

  public getWeather(zipcode){ // getWeather(zipcode)
    return this.httpClient.get(
`https://api.openweathermap.org/data/2.5/weather?zip=${zipcode}&appid=${this.API_KEY}`
);  // where to format with zip code
  }
}

</code>```

答:
To get a value inside a FormGroup, you first need to get the form control inside the form group to then get its value. So you need to do this:</p>

```<code>this.zipcode = this.zipForm.get('zipCode').value;
</code>```

Body:
Basically, I want to take the zip code in the form, format a URL, make an API call on that URL, and then print data from the JSON to the screen.

I'm already formatting a URL and getting the data I need.
The problem is that I can't get the form data to store in a variable, and use that to format my URL.

Here's component.ts:

import { WeatherdataService } from '../services/weatherdata.service';
import { THIS_EXPR } from '@angular/compiler/src/output/output_ast';
import { FormControl,FormGroup } from '@angular/forms';
@Component({
  selector: 'app-dailyda',
  templateUrl: './dailyda.component.html',
  styleUrls: ['./dailyda.component.scss']
})
export class DailydaComponent implements OnInit {

  zipForm = new FormGroup({
    zipCode:new FormControl('37064') //Default value in quotes
  })
  zipcode = 60610;
  onSubmit() {
    this.zipcode = this.zipForm.value.zipCode;
    console.log(this.zipcode);
  }
  weather;
  temp;
  press;
  dry_da;
  //Crunch your numbers here, store it in a variable called result, etc.,
  //And in the template, {{ result }} will display that number.
  ISAT = 288.15;
  ISAP = 1013.25;
  expon = 0.234978134;
  // lapse_rate = 0.0065;
  // R = 8.3144598; Replaced all this with expon
  // g = 9.80665;
  // M = 0.028964; // This is the molar mass of DRY air.

  constructor(private weatherdataService: WeatherdataService) { }

  ngOnInit() {
    this.weatherdataService.getWeather(this.zipcode).subscribe((data)=>{
       // add zip code to .getWeather call
      this.weather = data;
      this.temp = this.weather.main.temp;
      this.press = this.weather.main.pressure;
      this.dry_da = Math.round(3.28084 * this.ISAT/0.0065 *(1 - ((this.press/this.ISAP)/(this.temp/this.ISAT))** (this.expon)));
    }
    )};

};

Here's compnonent.html:
(I tried using ngSubmit(), but the submit button reloads my page, and nothing shows up.

        Zip Code:
        <input type="text" [formControl]='zipCode'>

    <button type="button" (click)="onSubmit()">Submit</button>
</form>

Current Zip: {{ zipCode.value }}

 Density Altitude (assumes dry air):

{{ dry_da }} ft

 Temp in Kelvins:

{{ temp }}

 Static Atmospheric Pressure in hPa:

{{ press }}

Here's the service.ts:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class WeatherdataService {
  API_KEY = 'blahblahblah';

  constructor(private httpClient: HttpClient) { }

  public getWeather(zipcode){ // getWeather(zipcode)
    return this.httpClient.get(
`https://api.openweathermap.org/data/2.5/weather?zip=${zipcode}&appid=${this.API_KEY}`
);  // where to format with zip code
  }
}

Body:
To get a value inside a FormGroup, you first need to get the form control inside the form group to then get its value. So you need to do this:

this.zipcode = this.zipForm.get('zipCode').value;


问:
Deleting records from the created form in c#
I m working with c#, in this i want to delete record from the form for that i have the following code..

```<code>     private void button3_Click(object sender, EventArgs e)
    {
        OleDbConnection con = new OleDbConnection();
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data  Source=C:\\Documents and Settings\\mayur patil\\My Documents\\Dairy_db\\tblCompany.mdb";
        con.Open();
        string sql = "DELETE FROM tblCompany WHERE (CoCode = 1)";

    }
</code>```

but i m not getting the answer...

答: You need to execute an OleCommand with your SQL and connection.

Body:
I m working with c#, in this i want to delete record from the form for that i have the following code..

     private void button3_Click(object sender, EventArgs e)
    {
        OleDbConnection con = new OleDbConnection();
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data  Source=C:\\Documents and Settings\\mayur patil\\My Documents\\Dairy_db\\tblCompany.mdb";
        con.Open();
        string sql = "DELETE FROM tblCompany WHERE (CoCode = 1)";

    }

but i m not getting the answer...


问:
Multiple GCR Project Registry Login in Jenkins Machine
We have our cloud setup on GCP with multiple projects. In our Jenkins machines, I can see multiple entries of docker registries. One of them is something like this:-

```<code>"https://gcr.io/abc-defghi-212121": {
                    "auth": "somethingsomethingsomething=",
                    "email": "not@val.id"
</code>```

I want to do same thing for another project which will be like:-

```<code>"https://gcr.io/jkl-mnopqr-313131": {
                    "auth": "somethingsomethingsomething=",
                    "email": "not@val.id"
</code>```

So that if I do docker login to both registries it should work. I have followed below links:-
https://cloud.google.com/container-registry/docs/advanced-authentication

there are different methods in this but still confused. Please help.

答:
The most common authentication method to use docker with container registry is using gcloud as a Docker credential helper. This authentication method is performed by running:
$ gcloud auth configure-docker

This will create a json file, ~/.docker/config.json, that will "tell" docker to authenticate in container registry using the gcloud current user.

However, I am assuming in your case it's Jenkins that builds and pushes your images to the container registry. You need to authenticate it, which I believe it's performed using the OAuth plugin. You can find it in the Jenkins interface:
Jenkins -> Credentials -> Global Credentials -> Add Credentials

Nevertheless, you could also refer to this documentation where explained how to troubleshoot common Container Registry and Docker issues. Also, make sure that you have the required permission to push or pull.

Body:
We have our cloud setup on GCP with multiple projects. In our Jenkins machines, I can see multiple entries of docker registries. One of them is something like this:-

"https://gcr.io/abc-defghi-212121": {
                    "auth": "somethingsomethingsomething=",
                    "email": "not@val.id"

I want to do same thing for another project which will be like:-

"https://gcr.io/jkl-mnopqr-313131": {
                    "auth": "somethingsomethingsomething=",
                    "email": "not@val.id"

So that if I do docker login to both registries it should work. I have followed below links:-
https://cloud.google.com/container-registry/docs/advanced-authentication

there are different methods in this but still confused. Please help.


问:
can't seen in kubernetes cluster
I create a yaml file to create rabbitmq kubernetes cluster. I can see pods. But when I write kubectl get deployment. I cant see there. I can't access to rabbitmq ui page.</p>

```<code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: rabbit
  name: rabbit
spec:
  ports:
  - port: 5672
    protocol: TCP
    name: mqtt
  - port: 15672
    protocol: TCP
    name: ui
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rabbit
spec:
  serviceName: rabbit
  replicas: 3
  selector:
    matchLabels:
      app: rabbit
  template:
    metadata:
      labels:
        app: rabbit
    spec:
      containers:
        - name: rabbitmq
          image: rabbitmq
      nodeSelector:
        rabbitmq: "clustered"
</code>```

答:
@arghya-sadhu's answer is correct.

NB I'm unfamiliar with RabbitMQ but you may need to use a different image (see 'Management Plugin`) to include the UI.

See below for more details.

You should be able to hack your way to the UI on one (!) of the Pods via:

PORT=8888
kubectl port-forward pod/rabbit-0 --namespace=${NAMESPACE} ${PORT}:15672
```

<p>And then browse <code>localhost:${PORT}</code> (if <code>8888</code> is unavailable, try another). </p>

<p>I <strong>suspect</strong> (!) this won't work unless you use the image with the management plugin. </p>

<h3>Plus</h3>

<ul>
<li>The <code>Service</code> needs to select the <code>StatefulSet</code>'s Pods</li>
</ul>

<p>Within the Service <code>spec</code> you should add perhaps:</p>

```selector:
  app: rabbit
```

<ul>
<li>Presumably (!?) you are using a private repo (because you have <code>imagePullSecrets</code>).</li>
</ul>

<p>If you don't and wish to use DockerHub, you may remove the <code>imagePullSecrets</code> section.</p>

<ul>
<li>It's useful to document (!) container ports albeit not mandatory:</li>
</ul>

<p>In the <code>StatefulSet</code></p>

```ports:
- containerPort: 5672
- containerPort: 15672
```

<h3>Debug</h3>

<pre class="lang-sh prettyprint-override"><code>NAMESPACE="default" # Or ...
</code>```

Ensure the StatefulSet is created:

kubectl get statesfulset/rabbit --namespace=${NAMESPACE}
```

<p>Check the Pods:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get pods --selector=app=rabbit --namespace=${NAMESPACE}
</code>```

You can check the the Pods are bound to a (!) Service:

kubectl describe endpoints/rabbit --namespace=${NAMESPACE}
```

<p><strong>NB</strong> You should see 3 addresses (one per Pod)</p>

<p>Get the NodePort either:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get service/rabbit --namespace=${NAMESPACE} --output=json
kubectl describe service/rabbit --namespace=${NAMESPACE}
</code>```

You will need to use the NodePort to access both the MQTT endpoint and the UI.

Title: can't seen in kubernetes cluster

Body:
I create a yaml file to create rabbitmq kubernetes cluster. I can see pods. But when I write kubectl get deployment. I cant see there. I can't access to rabbitmq ui page.

apiVersion: v1
kind: Service
metadata:
  labels:
    app: rabbit
  name: rabbit
spec:
  ports:
  - port: 5672
    protocol: TCP
    name: mqtt
  - port: 15672
    protocol: TCP
    name: ui
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rabbit
spec:
  serviceName: rabbit
  replicas: 3
  selector:
    matchLabels:
      app: rabbit
  template:
    metadata:
      labels:
        app: rabbit
    spec:
      containers:
        - name: rabbitmq
          image: rabbitmq
      nodeSelector:
        rabbitmq: "clustered"

Body:
@arghya-sadhu's answer is correct.

NB I'm unfamiliar with RabbitMQ but you may need to use a different image (see 'Management Plugin`) to include the UI.

See below for more details.

You should be able to hack your way to the UI on one (!) of the Pods via:

PORT=8888
kubectl port-forward pod/rabbit-0 --namespace=${NAMESPACE} ${PORT}:15672

And then browse localhost:${PORT} (if 8888 is unavailable, try another).

I suspect (!) this won't work unless you use the image with the management plugin.

Plus

The Service needs to select the StatefulSet's Pods

Within the Service spec you should add perhaps:

selector:
  app: rabbit

Presumably (!?) you are using a private repo (because you have imagePullSecrets).

If you don't and wish to use DockerHub, you may remove the imagePullSecrets section.

It's useful to document (!) container ports albeit not mandatory:

In the StatefulSet

ports:
- containerPort: 5672
- containerPort: 15672

Debug

NAMESPACE="default" # Or ...

Ensure the StatefulSet is created:

kubectl get statesfulset/rabbit --namespace=${NAMESPACE}

Check the Pods:

kubectl get pods --selector=app=rabbit --namespace=${NAMESPACE}

You can check the the Pods are bound to a (!) Service:

kubectl describe endpoints/rabbit --namespace=${NAMESPACE}

NB You should see 3 addresses (one per Pod)

Get the NodePort either:

kubectl get service/rabbit --namespace=${NAMESPACE} --output=json
kubectl describe service/rabbit --namespace=${NAMESPACE}

You will need to use the NodePort to access both the MQTT endpoint and the UI.


问:
HTML5 Canvas ctx.fill() fills outside the stroke area
I am working with the virtual sky library, https://github.com/slowe/VirtualSky. The library tries to show a visual representation of the sky. The library is built on html canvas. In the original code, the milky way line is drawn as a line with ctx.stroke() and everything works fine. I tried adding ctx.fill() to fill in the milky way area but for some coordinates/dates canvas fills outside the stroked area. I added the two images that represents the issue. In the filled version, notice that it fills also some other area outside the milky way line. I spent much time on the issue but couldn't figure out why the canvas fills outside the drawn area.

Without ctx.fill()

With ctx.fill()

Here is the code that draws the Milky Way line :

```<code>VirtualSky.prototype.drawGalaxy = function(colour){
    if(!this.galaxy || !this.showgalaxy) return this;
    if(!colour) colour = this.col.galaxy;
    this.ctx.beginPath();
    this.ctx.strokeStyle = colour;
    this.ctx.fillStyle = "rgba(255,255,255,0.4)";
    this.ctx.lineWidth = (this.gal.lineWidth || 0.75);
    this.ctx.lineJoin = "round";
    var p,pa,pb,i,c,maxl,dx,dy;
    maxl = this.maxLine(5);

    for(c = 0; c < this.galaxy.length; c++){

        // We will convert all the galaxy outline coordinates to radians
        if(!this.gal.processed){
            for(i = 1; i < this.galaxy[c].length; i++) this.galaxy[c][i] *= this.d2r;
        }

        // Get a copy of the current shape
        p = this.galaxy[c].slice(0);

        // Get the colour (first element)
        p.shift();
        // Set the initial point to null
        pa = null;

        // Now loop over joining the points
        for(i = 0; i < p.length; i+=2){
            pb = this.radec2xy(p[i], p[i+1]);
            if(i==0) this.ctx.moveTo(pb.x,pb.y);
            else{
                dx = Math.abs(pa.x-pb.x);
                dy = Math.abs(pa.y-pb.y);
                if(!isNaN(dx) && !isNaN(dy)){
                    // Basic error checking: if the line is very long we need to normalize to other side of sky
                    if(dx >= maxl || dy >= maxl) this.ctx.moveTo(pb.x,pb.y);
                    this.ctx.lineTo(pb.x,pb.y);
                }else{
                    this.ctx.moveTo(pb.x,pb.y);
                }
            }
            pa = pb;
        }
    }
    // We've converted the galaxy to radians
    this.gal.processed = true;
    this.ctx.stroke();

    this.ctx.fill();

//  I added this ctx.fill() here which causes the problem.

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

Json data for the milky way lines

{
  "galaxy": [
    ["#396bad", 254.1778, -21.5124, 253.6146, -22.5310, 253.2638, -27.7008, 251.9368, -29.7742, 249.7919, -29.7867, 247.8000, -28.4406, 246.5570, -26.9571, 244.6278, -25.8787, 242.5067, -26.0070, 241.5945, -25.3687, 240.7208, -23.0525, 239.5973, -22.3533, 238.6863, -23.5322, 238.7180, -25.7313, 239.4131, -28.0723, 238.6475, -30.8747, 239.9512, -34.4963, 240.4545, -37.0030, 238.8220, -39.1709, 235.6101, -41.6744, 234.5926, -42.9833, 235.6221, -44.6917, 235.5743, -46.4283, 232.6913, -48.4186, 228.3087, -49.7552, 225.9823, -50.6267, 221.4249, -52.5289, 216.0338, -54.6596, 209.0229, -55.3209, 202.9102, -56.0362, 196.2626, -56.3616, 191.7337, -57.1169, 184.7426, -59.1857, 180.5514, -58.8402, 175.1997, -58.5802, 170.6339, -57.6749, 168.3549, -56.2380, 163.3607, -54.7001, 159.2106, -51.3301, 154.8495, -47.2975, 150.0574, -45.2411, 146.8211, -44.7221, 145.5418, -45.4794, 145.6709, -46.1571, 149.5391, -48.3145, 150.7915, -49.6707, 150.0747, -51.0247, 147.4159, -49.8497, 144.3472, -47.8592, 142.7713, -47.5886, 142.7304, -48.1825, 141.8590, -48.7921, 143.8702, -51.7563, 146.7533, -53.8733, 146.7337, -54.7900, 145.4937, -55.0315, 136.3994, -53.7185, 133.1890, -53.9932, 132.3952, -55.2722, 133.9782, -56.3603, 137.5581, -56.8447, 142.3823, -56.7640, 147.1253, -56.7384, 149.2668, -57.3424, 151.0831, -57.4354, 153.9265, -58.4216, 157.9421, -58.9774, 159.0422, -59.6771, 157.5067, -60.3507, 155.1830, -59.7783, 151.9601, -59.2083, 149.2887, -59.3163, 148.3379, -59.9243, 149.9157, -61.4340, 154.0475, -62.1249, 155.9994, -62.2575, 159.2582, -63.5263, 165.5091, -63.4204, 167.1619, -62.8290, 170.1596, -61.3662, 172.9661, -61.4156, 176.0518, -62.9133, 179.3437, -64.2607, 181.9387, -65.3282, 184.3779, -69.3924, 188.2568, -70.9570, 194.7347, -71.2607, 199.7570, -70.2394, 204.1730, -68.8427, 209.0938, -67.8511, 216.7510, -68.0095, 221.9748, -67.1396, 227.5494, -66.2461, 234.5158, -64.3854, 240.5233, -61.8468, 244.0983, -60.4173, 251.3801, -59.1124, 253.2926, -57.4685, 254.7774, -56.3244, 261.4819, -54.4899, 265.8676, -50.8482, 268.8085, -48.0793, 269.9543, -46.3469, 270.5405, -43.6313, 270.6492, -42.3809, 271.0668, -41.1083, 273.1271, -38.6387, 274.8287, -36.5477, 276.5511, -33.8477, 275.4040, -33.1596, 275.2727, -30.5290, 276.8968, -28.1703, 277.9533, -25.4297, 278.6386, -22.3113, 279.4081, -19.7351, 280.9230, -17.4472, 281.9964, -15.6719, 282.8788, -13.6664, 283.3409, -11.0282, 284.5659, -8.4787, 285.8740, -5.6156, 287.7313, -3.1057, 289.7038, -1.0941, 290.4044, -0.0164, 290.7342, 1.1813, 291.9363, 0.4122, 292.8626, 0.7917, 295.5690, 0.8033, 297.0695, 1.1497, 297.0874, 2.1407, 295.9694, 2.3815, 294.6764, 2.5679, 294.4415, 3.7745, 295.0541, 5.1814, 296.9021, 5.9879, 297.7330, 6.5454, 297.6053, 8.4351, 298.6240, 10.2040, 298.1628, 13.5562, 299.1257, 15.5289, 302.8713, 15.4981, 305.5156, 16.1286, 308.1366, 16.6469, 308.7496, 18.5262, 307.5513, 19.8431, 307.7080, 20.7394, 309.0176, 21.5802, 308.7945, 23.5149, 309.4605, 24.2478, 310.5891, 24.9863, 310.3480, 26.0982, 308.9284, 26.8788, 309.1600, 27.5971, 311.8741, 29.1431, 313.3279, 32.0552, 313.9435, 35.1102, 314.9513, 36.1769, 319.2157, 38.0107, 320.5720, 39.7440, 321.0403, 40.9232, 321.8310, 41.6873, 323.6238, 44.8754, 325.1386, 46.0919, 328.0798, 46.8738, 332.6317, 47.1238, 338.1292, 47.4766, 344.7038, 47.6502, 346.4796, 47.7702, 351.3753, 46.7280, 355.1420, 46.2097, 359.5920, 46.1929, 4.3035, 46.2481, 8.0516, 45.6862, 10.5201, 45.7218, 12.3781, 45.1055, 16.3043, 45.2972, 19.0389, 44.8213, 23.6309, 45.0223, 30.7979, 43.0638, 32.8210, 42.8635, 40.6571, 43.7653, 43.6189, 43.8484, 46.6891, 42.5931, 45.3773, 41.6641, 41.7099, 41.8080, 39.3969, 41.6311, 36.5579, 40.8644, 36.3328, 39.9578, 39.0080, 38.9254, 43.4828, 39.0665, 47.0254, 39.2746, 50.5370, 39.3676, 53.6788, 39.5428, 55.7670, 38.8688, 57.1481, 37.3216, 57.2361, 35.7482, 56.6404, 33.7143, 57.1765, 32.1478, 58.8043, 30.8405, 59.9439, 30.9968, 61.4966, 33.3066, 61.4994, 36.0547, 61.1808, 38.6650, 61.7684, 40.0026, 63.8402, 40.1004, 71.4989, 34.6769, 75.3343, 31.9184, 79.7168, 29.0407, 81.0519, 25.1195, 82.1320, 22.0941, 83.6308, 17.4698, 85.5679, 15.1690, 86.9568, 12.6324, 87.7444, 8.8192, 91.3008, 6.1831, 92.8266, 2.6539, 94.6923, -2.1965, 97.7264, -6.0265, 102.5525, -9.6439, 104.6125, -11.6416, 105.1552, -14.2536, 108.2256, -18.5894, 109.6456, -25.3483, 111.2200, -27.2135, 111.2669, -32.1720, 114.7741, -37.8718, 116.9787, -42.4014, 117.0836, -45.1959, 116.1853, -48.6868, 118.8947, -50.1703, 123.5005, -49.9484, 125.9819, -48.8761, 122.1675, -44.3179, 122.4135, -42.9137, 124.6591, -42.8292, 129.1849, -46.1315, 132.5020, -47.4562, 134.3955, -47.4750, 135.7144, -46.3461, 131.5066, -42.8910, 132.0107, -42.0135, 137.8183, -45.2697, 139.3131, -45.0639, 139.6524, -44.1094, 136.9034, -40.6399, 136.6626, -38.9913, 139.6753, -40.1504, 144.8151, -42.6899, 150.5786, -42.3526, 153.6316, -43.0367, 155.7573, -42.5342, 156.1233, -41.0904, 152.5690, -38.5605, 148.4971, -37.7767, 141.2865, -38.2886, 135.1421, -35.9600, 129.8501, -32.1764, 126.2320, -28.4253, 122.1594, -21.3427, 118.5304, -12.7577, 116.3335, -8.7013, 112.8556, -6.4334, 109.1321, -2.3025, 108.1548, 0.0096, 107.9889, 5.4587, 106.7266, 8.9737, 103.4908, 11.8896, 101.3959, 15.0964, 99.5314, 17.7842, 97.6915, 19.7759, 96.9057, 21.2016, 90.6296, 24.9510, 88.0744, 27.4918, 86.0675, 31.0217, 85.2336, 32.7789, 81.6446, 36.8533, 79.8386, 39.1558, 78.6539, 44.2051, 77.5234, 45.5296, 73.0840, 46.1406, 69.0884, 46.5652, 66.4784, 48.5322, 65.0187, 50.6773, 63.1096, 51.4737, 60.4311, 51.8441, 60.2604, 52.7052, 63.6488, 52.7609, 65.6099, 53.0495, 68.0178, 52.7517, 68.0826, 53.7533, 63.1671, 54.9872, 57.4967, 55.4868, 58.4393, 56.1385, 60.5618, 56.2369, 62.6651, 56.7553, 62.6924, 57.7129, 59.3107, 59.2013, 50.7444, 59.4785, 45.7503, 59.6435, 43.3097, 60.6511, 38.7256, 61.5348, 35.7107, 62.5099, 30.2614, 62.7058, 27.5803, 63.4145, 23.1877, 65.0421, 18.5579, 65.6747, 13.7778, 67.5849, 11.2150, 68.1610, 7.5359, 67.6326, 5.1034, 66.7569, 2.2150, 66.1991, 0.2476, 66.2511, 355.2714, 64.4260, 350.1006, 62.9385, 344.4302, 62.4847, 339.3002, 60.4931, 333.4702, 58.8851, 331.1327, 59.4605, 330.9382, 61.9623, 340.6152, 65.1092, 343.2879, 66.7647, 343.3581, 70.1643, 341.1773, 70.8790, 336.6449, 73.1299, 333.5813, 75.1391, 324.6186, 76.5981, 322.6315, 75.9427, 319.0891, 73.7015, 314.8850, 71.0639, 315.6348, 68.7048, 315.4588, 66.8973, 313.0831, 64.8622, 312.0635, 62.5880, 314.0142, 60.2312, 313.6305, 59.4861, 311.8591, 59.3915, 309.8048, 58.5233, 310.2041, 57.1819, 306.9144, 55.9804, 304.6804, 54.7702, 305.2319, 53.7273, 307.7332, 52.9357, 308.4628, 52.2243, 308.0011, 51.7205, 306.5029, 51.7495, 304.1552, 50.3598, 302.5798, 48.5193, 302.1408, 47.1988, 300.7148, 46.6004, 299.0278, 47.0595, 297.2437, 46.8711, 295.7553, 46.0584, 294.7485, 44.4314, 292.7755, 41.4764, 288.6933, 39.1997, 287.4471, 37.8510, 287.5118, 36.7221, 289.2538, 36.0606, 290.9985, 36.0011, 292.6594, 35.2362, 292.3950, 34.1260, 291.2070, 33.2023, 288.4240, 33.0160, 287.0090, 32.3231, 286.5059, 31.2666, 287.0896, 29.6223, 286.5820, 27.3683, 285.1771, 25.5062, 283.1010, 23.9449, 281.0469, 22.8010, 279.4373, 21.4068, 279.1821, 19.6473, 279.7551, 18.2109, 280.9496, 17.7421, 282.6220, 17.1833, 283.2966, 16.1546, 283.0965, 15.0372, 281.5283, 14.0053, 280.0909, 12.9151, 278.6961, 11.5975, 277.0707, 10.5385, 275.4225, 9.5688, 273.4622, 8.5487, 270.9916, 7.3738, 269.3157, 5.7621, 268.8705, 4.4507, 269.5389, 3.1987, 271.0927, 2.6855, 273.2811, 2.5608, 275.4739, 3.3006, 278.1912, 5.0780, 281.9090, 8.5271, 284.1697, 11.3576, 286.2251, 14.0132, 286.3233, 15.1915, 286.1158, 15.5100, 285.7599, 16.6912, 286.7631, 18.2914, 287.1951, 19.3787, 286.9849, 20.8446, 289.3257, 22.5391, 291.9464, 25.4127, 292.4286, 28.5332, 293.4593, 30.5996, 297.2230, 32.4772, 299.7133, 35.0595, 303.4745, 35.0807, 304.1266, 34.0245, 303.6819, 30.3270, 300.8895, 28.8322, 296.8912, 28.3993, 294.9144, 27.6937, 294.5657, 26.6140, 296.1041, 25.9037, 297.3739, 25.6845, 297.8246, 24.4710, 295.9400, 22.7956, 293.0649, 21.4866, 291.1229, 20.8588, 290.3240, 19.7277, 290.6364, 18.7692, 292.0849, 18.3219, 293.1902, 17.8198, 293.1968, 16.4933, 292.2117, 15.0311, 290.2679, 13.8513, 288.7569, 12.5900, 288.6076, 10.9218, 288.7328, 9.7665, 287.2839, 8.8429, 285.5820, 8.1189, 284.2910, 7.0396, 283.2366, 5.8411, 282.9327, 3.8283, 282.5522, 3.2275, 280.8435, 2.7268, 279.3674, 2.2532, 278.3224, 1.3453, 278.2314, 0.7429, 279.1609, 1.5654, 279.5029, 0.9574, 279.8970, -0.2562, 281.6814, -0.8823, 283.4665, -1.5073, 284.0658, -2.4642, 282.9599, -3.4894, 281.1068, -3.6991, 279.0490, -4.0172, 278.1079, -5.1256, 278.2582, -6.7990, 279.0976, -9.4057, 278.6578, -11.6460, 277.3170, -14.1578, 276.1600, -16.6976, 275.8960, -19.1108, 275.5302, -21.8370, 274.9452, -24.2398, 272.9984, -26.4299, 270.0613, -28.0668, 268.2229, -29.8114, 268.5228, -30.2623, 267.9381, -32.1320, 267.1568, -33.2373, 265.0719, -33.6050, 262.2933, -32.3327, 261.2061, -30.0066, 261.2532, -27.8653, 261.7517, -26.3868, 262.0161, -24.8538, 263.5809, -22.8788, 265.0658, -21.1691, 265.8074, -19.4150, 266.6842, -18.7916, 268.0278, -18.7995, 268.7521, -17.4910, 268.3084, -15.3906, 266.9707, -13.3787, 264.9872, -12.4603, 262.4372, -12.2113, 260.5499, -13.2122, 258.4769, -14.8956, 256.1174, -16.7507, 254.4650, -18.3043, 253.6343, -20.3552, 254.1778, -21.5124, 254.1778, -21.5124, 254.1778, -21.5124],
    ["#396bad", 257.4284, -35.0782, 258.7567, -34.6776, 259.6113, -33.6806, 259.9750, -32.7946, 260.9776, -32.5946, 263.4189, -33.7211, 265.2841, -35.1551, 267.0684, -37.0106, 266.5317, -38.4758, 264.8234, -39.1661, 263.0403, -38.8168, 260.6629, -38.1140, 258.3247, -38.4735, 255.5110, -38.1878, 254.0470, -37.3602, 253.5295, -36.1222, 253.7763, -35.4603, 254.7476, -35.1875, 256.2938, -35.0264, 257.4284, -35.0782, 257.4284, -35.0782, 257.4284, -35.0782],
    ["#396bad", 254.4847, -39.5230, 255.2762, -39.2671, 257.3657, -39.9243, 258.7042, -41.3823, 258.3749, -43.2682, 257.0644, -43.3665, 254.3218, -40.8215, 254.6242, -40.4285, 254.4847, -39.5230, 254.4847, -39.5230, 254.4847, -39.5230],
    ["#396bad", 247.9505, -43.8132, 247.7714, -42.7233, 248.2105, -41.7101, 249.7280, -40.8373, 248.8720, -37.3180, 247.1054, -36.2799, 245.6020, -36.7984, 243.1195, -35.6949, 242.2253, -36.0340, 241.9943, -38.6050, 241.6221, -40.6326, 239.8163, -43.0489, 238.8334, -44.6762, 238.5119, -46.8016, 237.7857, -49.0401, 236.8718, -50.6695, 237.0713, -52.3828, 238.9693, -53.2821, 241.4236, -52.3398, 244.7950, -51.3601, 248.9798, -51.6343, 253.4436, -51.0624, 257.8767, -50.6966, 260.9423, -50.2581, 261.6140, -49.2459, 260.7624, -46.4869, 260.5888, -45.3986, 259.8614, -44.8904, 257.7870, -44.9484, 256.1962, -45.7995, 256.3613, -48.5425, 253.5419, -49.9573, 249.8040, -49.5087, 248.3220, -49.4156, 245.7227, -48.7635, 244.6261, -48.0299, 245.6396, -46.7119, 247.9407, -46.1849, 251.5170, -45.7312, 252.8143, -45.1508, 251.9638, -44.5626, 249.5206, -44.4962, 247.9505, -43.8132, 247.9505, -43.8132, 247.9505, -43.8132],
    ["#396bad", 231.8281, -52.4833, 233.5614, -52.5365, 234.4273, -52.7145, 236.0044, -53.8647, 236.5304, -55.8352, 237.3389, -57.1286, 230.3741, -58.8315, 226.4955, -59.1351, 221.0867, -60.4628, 220.9820, -59.2769, 221.7242, -59.0271, 223.2728, -57.1869, 226.5641, -55.0286, 228.1040, -54.5097, 229.9674, -52.9922, 231.8281, -52.4833, 231.8281, -52.4833, 231.8281, -52.4833],
    ["#396bad", 191.9931, -60.9308, 195.0383, -60.9157, 197.2513, -61.5730, 197.6589, -63.3081, 193.3910, -65.2609, 190.6198, -65.3102, 189.1651, -65.7997, 187.9019, -65.8296, 187.4866, -64.7787, 188.0292, -64.2788, 187.2718, -63.6037, 188.0759, -62.2722, 190.6559, -61.1093, 191.9931, -60.9308, 191.9931, -60.9308],
    ["#396bad", 132.7337, -37.5805, 133.0861, -38.9333, 132.3284, -39.7468, 129.7569, -39.4258, 127.1207, -38.0660, 124.9328, -36.1447, 124.8899, -34.6079, 124.7196, -32.9119, 125.9376, -32.1253, 127.3543, -32.6954, 128.6915, -33.7875, 129.6263, -35.1366, 131.7847, -36.5415, 132.7337, -37.5805, 132.7337, -37.5805],
    ["#396bad", 121.1825, -39.3994, 119.9070, -39.0295, 119.2840, -37.6001, 119.3245, -36.1550, 117.3621, -34.3430, 116.3134, -31.1424, 115.5167, -28.5014, 115.3112, -26.0891, 115.8367, -24.7060, 117.0334, -24.5218, 117.8897, -25.7087, 118.5145, -28.1509, 119.6664, -31.5362, 121.7083, -34.8713, 122.3366, -37.4519, 122.1419, -39.0037, 121.1825, -39.3994, 121.1825, -39.3994],
    ["#396bad", 305.9982, 40.1858, 309.8895, 39.3472, 311.2759, 37.2754, 311.2100, 35.4356, 310.1900, 34.7837, 308.6971, 34.9849, 307.5461, 36.5500, 305.0697, 37.7876, 304.5142, 39.0978, 305.1288, 40.0209, 305.9982, 40.1858]
  ]
}
```

答:
As it was already said that could come from your data.
One way to easily check their integrity is to draw a small rectangle at each point location.

This way you can avoid checking every single number.

Body:
I am working with the virtual sky library, https://github.com/slowe/VirtualSky. The library tries to show a visual representation of the sky. The library is built on html canvas. In the original code, the milky way line is drawn as a line with ctx.stroke() and everything works fine. I tried adding ctx.fill() to fill in the milky way area but for some coordinates/dates canvas fills outside the stroked area. I added the two images that represents the issue. In the filled version, notice that it fills also some other area outside the milky way line. I spent much time on the issue but couldn't figure out why the canvas fills outside the drawn area.

Without ctx.fill()

With ctx.fill()

Here is the code that draws the Milky Way line :

VirtualSky.prototype.drawGalaxy = function(colour){
    if(!this.galaxy || !this.showgalaxy) return this;
    if(!colour) colour = this.col.galaxy;
    this.ctx.beginPath();
    this.ctx.strokeStyle = colour;
    this.ctx.fillStyle = "rgba(255,255,255,0.4)";
    this.ctx.lineWidth = (this.gal.lineWidth || 0.75);
    this.ctx.lineJoin = "round";
    var p,pa,pb,i,c,maxl,dx,dy;
    maxl = this.maxLine(5);

    for(c = 0; c < this.galaxy.length; c++){

        // We will convert all the galaxy outline coordinates to radians
        if(!this.gal.processed){
            for(i = 1; i < this.galaxy[c].length; i++) this.galaxy[c][i] *= this.d2r;
        }

        // Get a copy of the current shape
        p = this.galaxy[c].slice(0);

        // Get the colour (first element)
        p.shift();
        // Set the initial point to null
        pa = null;

        // Now loop over joining the points
        for(i = 0; i
= maxl || dy >= maxl) this.ctx.moveTo(pb.x,pb.y);
                    this.ctx.lineTo(pb.x,pb.y);
                }else{
                    this.ctx.moveTo(pb.x,pb.y);
                }
            }
            pa = pb;
        }
    }
    // We've converted the galaxy to radians
    this.gal.processed = true;
    this.ctx.stroke();

    this.ctx.fill();

//  I added this ctx.fill() here which causes the problem.

    return this;
};

Json data for the milky way lines

{
  "galaxy": [
    ["#396bad", 254.1778, -21.5124, 253.6146, -22.5310, 253.2638, -27.7008, 251.9368, -29.7742, 249.7919, -29.7867, 247.8000, -28.4406, 246.5570, -26.9571, 244.6278, -25.8787, 242.5067, -26.0070, 241.5945, -25.3687, 240.7208, -23.0525, 239.5973, -22.3533, 238.6863, -23.5322, 238.7180, -25.7313, 239.4131, -28.0723, 238.6475, -30.8747, 239.9512, -34.4963, 240.4545, -37.0030, 238.8220, -39.1709, 235.6101, -41.6744, 234.5926, -42.9833, 235.6221, -44.6917, 235.5743, -46.4283, 232.6913, -48.4186, 228.3087, -49.7552, 225.9823, -50.6267, 221.4249, -52.5289, 216.0338, -54.6596, 209.0229, -55.3209, 202.9102, -56.0362, 196.2626, -56.3616, 191.7337, -57.1169, 184.7426, -59.1857, 180.5514, -58.8402, 175.1997, -58.5802, 170.6339, -57.6749, 168.3549, -56.2380, 163.3607, -54.7001, 159.2106, -51.3301, 154.8495, -47.2975, 150.0574, -45.2411, 146.8211, -44.7221, 145.5418, -45.4794, 145.6709, -46.1571, 149.5391, -48.3145, 150.7915, -49.6707, 150.0747, -51.0247, 147.4159, -49.8497, 144.3472, -47.8592, 142.7713, -47.5886, 142.7304, -48.1825, 141.8590, -48.7921, 143.8702, -51.7563, 146.7533, -53.8733, 146.7337, -54.7900, 145.4937, -55.0315, 136.3994, -53.7185, 133.1890, -53.9932, 132.3952, -55.2722, 133.9782, -56.3603, 137.5581, -56.8447, 142.3823, -56.7640, 147.1253, -56.7384, 149.2668, -57.3424, 151.0831, -57.4354, 153.9265, -58.4216, 157.9421, -58.9774, 159.0422, -59.6771, 157.5067, -60.3507, 155.1830, -59.7783, 151.9601, -59.2083, 149.2887, -59.3163, 148.3379, -59.9243, 149.9157, -61.4340, 154.0475, -62.1249, 155.9994, -62.2575, 159.2582, -63.5263, 165.5091, -63.4204, 167.1619, -62.8290, 170.1596, -61.3662, 172.9661, -61.4156, 176.0518, -62.9133, 179.3437, -64.2607, 181.9387, -65.3282, 184.3779, -69.3924, 188.2568, -70.9570, 194.7347, -71.2607, 199.7570, -70.2394, 204.1730, -68.8427, 209.0938, -67.8511, 216.7510, -68.0095, 221.9748, -67.1396, 227.5494, -66.2461, 234.5158, -64.3854, 240.5233, -61.8468, 244.0983, -60.4173, 251.3801, -59.1124, 253.2926, -57.4685, 254.7774, -56.3244, 261.4819, -54.4899, 265.8676, -50.8482, 268.8085, -48.0793, 269.9543, -46.3469, 270.5405, -43.6313, 270.6492, -42.3809, 271.0668, -41.1083, 273.1271, -38.6387, 274.8287, -36.5477, 276.5511, -33.8477, 275.4040, -33.1596, 275.2727, -30.5290, 276.8968, -28.1703, 277.9533, -25.4297, 278.6386, -22.3113, 279.4081, -19.7351, 280.9230, -17.4472, 281.9964, -15.6719, 282.8788, -13.6664, 283.3409, -11.0282, 284.5659, -8.4787, 285.8740, -5.6156, 287.7313, -3.1057, 289.7038, -1.0941, 290.4044, -0.0164, 290.7342, 1.1813, 291.9363, 0.4122, 292.8626, 0.7917, 295.5690, 0.8033, 297.0695, 1.1497, 297.0874, 2.1407, 295.9694, 2.3815, 294.6764, 2.5679, 294.4415, 3.7745, 295.0541, 5.1814, 296.9021, 5.9879, 297.7330, 6.5454, 297.6053, 8.4351, 298.6240, 10.2040, 298.1628, 13.5562, 299.1257, 15.5289, 302.8713, 15.4981, 305.5156, 16.1286, 308.1366, 16.6469, 308.7496, 18.5262, 307.5513, 19.8431, 307.7080, 20.7394, 309.0176, 21.5802, 308.7945, 23.5149, 309.4605, 24.2478, 310.5891, 24.9863, 310.3480, 26.0982, 308.9284, 26.8788, 309.1600, 27.5971, 311.8741, 29.1431, 313.3279, 32.0552, 313.9435, 35.1102, 314.9513, 36.1769, 319.2157, 38.0107, 320.5720, 39.7440, 321.0403, 40.9232, 321.8310, 41.6873, 323.6238, 44.8754, 325.1386, 46.0919, 328.0798, 46.8738, 332.6317, 47.1238, 338.1292, 47.4766, 344.7038, 47.6502, 346.4796, 47.7702, 351.3753, 46.7280, 355.1420, 46.2097, 359.5920, 46.1929, 4.3035, 46.2481, 8.0516, 45.6862, 10.5201, 45.7218, 12.3781, 45.1055, 16.3043, 45.2972, 19.0389, 44.8213, 23.6309, 45.0223, 30.7979, 43.0638, 32.8210, 42.8635, 40.6571, 43.7653, 43.6189, 43.8484, 46.6891, 42.5931, 45.3773, 41.6641, 41.7099, 41.8080, 39.3969, 41.6311, 36.5579, 40.8644, 36.3328, 39.9578, 39.0080, 38.9254, 43.4828, 39.0665, 47.0254, 39.2746, 50.5370, 39.3676, 53.6788, 39.5428, 55.7670, 38.8688, 57.1481, 37.3216, 57.2361, 35.7482, 56.6404, 33.7143, 57.1765, 32.1478, 58.8043, 30.8405, 59.9439, 30.9968, 61.4966, 33.3066, 61.4994, 36.0547, 61.1808, 38.6650, 61.7684, 40.0026, 63.8402, 40.1004, 71.4989, 34.6769, 75.3343, 31.9184, 79.7168, 29.0407, 81.0519, 25.1195, 82.1320, 22.0941, 83.6308, 17.4698, 85.5679, 15.1690, 86.9568, 12.6324, 87.7444, 8.8192, 91.3008, 6.1831, 92.8266, 2.6539, 94.6923, -2.1965, 97.7264, -6.0265, 102.5525, -9.6439, 104.6125, -11.6416, 105.1552, -14.2536, 108.2256, -18.5894, 109.6456, -25.3483, 111.2200, -27.2135, 111.2669, -32.1720, 114.7741, -37.8718, 116.9787, -42.4014, 117.0836, -45.1959, 116.1853, -48.6868, 118.8947, -50.1703, 123.5005, -49.9484, 125.9819, -48.8761, 122.1675, -44.3179, 122.4135, -42.9137, 124.6591, -42.8292, 129.1849, -46.1315, 132.5020, -47.4562, 134.3955, -47.4750, 135.7144, -46.3461, 131.5066, -42.8910, 132.0107, -42.0135, 137.8183, -45.2697, 139.3131, -45.0639, 139.6524, -44.1094, 136.9034, -40.6399, 136.6626, -38.9913, 139.6753, -40.1504, 144.8151, -42.6899, 150.5786, -42.3526, 153.6316, -43.0367, 155.7573, -42.5342, 156.1233, -41.0904, 152.5690, -38.5605, 148.4971, -37.7767, 141.2865, -38.2886, 135.1421, -35.9600, 129.8501, -32.1764, 126.2320, -28.4253, 122.1594, -21.3427, 118.5304, -12.7577, 116.3335, -8.7013, 112.8556, -6.4334, 109.1321, -2.3025, 108.1548, 0.0096, 107.9889, 5.4587, 106.7266, 8.9737, 103.4908, 11.8896, 101.3959, 15.0964, 99.5314, 17.7842, 97.6915, 19.7759, 96.9057, 21.2016, 90.6296, 24.9510, 88.0744, 27.4918, 86.0675, 31.0217, 85.2336, 32.7789, 81.6446, 36.8533, 79.8386, 39.1558, 78.6539, 44.2051, 77.5234, 45.5296, 73.0840, 46.1406, 69.0884, 46.5652, 66.4784, 48.5322, 65.0187, 50.6773, 63.1096, 51.4737, 60.4311, 51.8441, 60.2604, 52.7052, 63.6488, 52.7609, 65.6099, 53.0495, 68.0178, 52.7517, 68.0826, 53.7533, 63.1671, 54.9872, 57.4967, 55.4868, 58.4393, 56.1385, 60.5618, 56.2369, 62.6651, 56.7553, 62.6924, 57.7129, 59.3107, 59.2013, 50.7444, 59.4785, 45.7503, 59.6435, 43.3097, 60.6511, 38.7256, 61.5348, 35.7107, 62.5099, 30.2614, 62.7058, 27.5803, 63.4145, 23.1877, 65.0421, 18.5579, 65.6747, 13.7778, 67.5849, 11.2150, 68.1610, 7.5359, 67.6326, 5.1034, 66.7569, 2.2150, 66.1991, 0.2476, 66.2511, 355.2714, 64.4260, 350.1006, 62.9385, 344.4302, 62.4847, 339.3002, 60.4931, 333.4702, 58.8851, 331.1327, 59.4605, 330.9382, 61.9623, 340.6152, 65.1092, 343.2879, 66.7647, 343.3581, 70.1643, 341.1773, 70.8790, 336.6449, 73.1299, 333.5813, 75.1391, 324.6186, 76.5981, 322.6315, 75.9427, 319.0891, 73.7015, 314.8850, 71.0639, 315.6348, 68.7048, 315.4588, 66.8973, 313.0831, 64.8622, 312.0635, 62.5880, 314.0142, 60.2312, 313.6305, 59.4861, 311.8591, 59.3915, 309.8048, 58.5233, 310.2041, 57.1819, 306.9144, 55.9804, 304.6804, 54.7702, 305.2319, 53.7273, 307.7332, 52.9357, 308.4628, 52.2243, 308.0011, 51.7205, 306.5029, 51.7495, 304.1552, 50.3598, 302.5798, 48.5193, 302.1408, 47.1988, 300.7148, 46.6004, 299.0278, 47.0595, 297.2437, 46.8711, 295.7553, 46.0584, 294.7485, 44.4314, 292.7755, 41.4764, 288.6933, 39.1997, 287.4471, 37.8510, 287.5118, 36.7221, 289.2538, 36.0606, 290.9985, 36.0011, 292.6594, 35.2362, 292.3950, 34.1260, 291.2070, 33.2023, 288.4240, 33.0160, 287.0090, 32.3231, 286.5059, 31.2666, 287.0896, 29.6223, 286.5820, 27.3683, 285.1771, 25.5062, 283.1010, 23.9449, 281.0469, 22.8010, 279.4373, 21.4068, 279.1821, 19.6473, 279.7551, 18.2109, 280.9496, 17.7421, 282.6220, 17.1833, 283.2966, 16.1546, 283.0965, 15.0372, 281.5283, 14.0053, 280.0909, 12.9151, 278.6961, 11.5975, 277.0707, 10.5385, 275.4225, 9.5688, 273.4622, 8.5487, 270.9916, 7.3738, 269.3157, 5.7621, 268.8705, 4.4507, 269.5389, 3.1987, 271.0927, 2.6855, 273.2811, 2.5608, 275.4739, 3.3006, 278.1912, 5.0780, 281.9090, 8.5271, 284.1697, 11.3576, 286.2251, 14.0132, 286.3233, 15.1915, 286.1158, 15.5100, 285.7599, 16.6912, 286.7631, 18.2914, 287.1951, 19.3787, 286.9849, 20.8446, 289.3257, 22.5391, 291.9464, 25.4127, 292.4286, 28.5332, 293.4593, 30.5996, 297.2230, 32.4772, 299.7133, 35.0595, 303.4745, 35.0807, 304.1266, 34.0245, 303.6819, 30.3270, 300.8895, 28.8322, 296.8912, 28.3993, 294.9144, 27.6937, 294.5657, 26.6140, 296.1041, 25.9037, 297.3739, 25.6845, 297.8246, 24.4710, 295.9400, 22.7956, 293.0649, 21.4866, 291.1229, 20.8588, 290.3240, 19.7277, 290.6364, 18.7692, 292.0849, 18.3219, 293.1902, 17.8198, 293.1968, 16.4933, 292.2117, 15.0311, 290.2679, 13.8513, 288.7569, 12.5900, 288.6076, 10.9218, 288.7328, 9.7665, 287.2839, 8.8429, 285.5820, 8.1189, 284.2910, 7.0396, 283.2366, 5.8411, 282.9327, 3.8283, 282.5522, 3.2275, 280.8435, 2.7268, 279.3674, 2.2532, 278.3224, 1.3453, 278.2314, 0.7429, 279.1609, 1.5654, 279.5029, 0.9574, 279.8970, -0.2562, 281.6814, -0.8823, 283.4665, -1.5073, 284.0658, -2.4642, 282.9599, -3.4894, 281.1068, -3.6991, 279.0490, -4.0172, 278.1079, -5.1256, 278.2582, -6.7990, 279.0976, -9.4057, 278.6578, -11.6460, 277.3170, -14.1578, 276.1600, -16.6976, 275.8960, -19.1108, 275.5302, -21.8370, 274.9452, -24.2398, 272.9984, -26.4299, 270.0613, -28.0668, 268.2229, -29.8114, 268.5228, -30.2623, 267.9381, -32.1320, 267.1568, -33.2373, 265.0719, -33.6050, 262.2933, -32.3327, 261.2061, -30.0066, 261.2532, -27.8653, 261.7517, -26.3868, 262.0161, -24.8538, 263.5809, -22.8788, 265.0658, -21.1691, 265.8074, -19.4150, 266.6842, -18.7916, 268.0278, -18.7995, 268.7521, -17.4910, 268.3084, -15.3906, 266.9707, -13.3787, 264.9872, -12.4603, 262.4372, -12.2113, 260.5499, -13.2122, 258.4769, -14.8956, 256.1174, -16.7507, 254.4650, -18.3043, 253.6343, -20.3552, 254.1778, -21.5124, 254.1778, -21.5124, 254.1778, -21.5124],
    ["#396bad", 257.4284, -35.0782, 258.7567, -34.6776, 259.6113, -33.6806, 259.9750, -32.7946, 260.9776, -32.5946, 263.4189, -33.7211, 265.2841, -35.1551, 267.0684, -37.0106, 266.5317, -38.4758, 264.8234, -39.1661, 263.0403, -38.8168, 260.6629, -38.1140, 258.3247, -38.4735, 255.5110, -38.1878, 254.0470, -37.3602, 253.5295, -36.1222, 253.7763, -35.4603, 254.7476, -35.1875, 256.2938, -35.0264, 257.4284, -35.0782, 257.4284, -35.0782, 257.4284, -35.0782],
    ["#396bad", 254.4847, -39.5230, 255.2762, -39.2671, 257.3657, -39.9243, 258.7042, -41.3823, 258.3749, -43.2682, 257.0644, -43.3665, 254.3218, -40.8215, 254.6242, -40.4285, 254.4847, -39.5230, 254.4847, -39.5230, 254.4847, -39.5230],
    ["#396bad", 247.9505, -43.8132, 247.7714, -42.7233, 248.2105, -41.7101, 249.7280, -40.8373, 248.8720, -37.3180, 247.1054, -36.2799, 245.6020, -36.7984, 243.1195, -35.6949, 242.2253, -36.0340, 241.9943, -38.6050, 241.6221, -40.6326, 239.8163, -43.0489, 238.8334, -44.6762, 238.5119, -46.8016, 237.7857, -49.0401, 236.8718, -50.6695, 237.0713, -52.3828, 238.9693, -53.2821, 241.4236, -52.3398, 244.7950, -51.3601, 248.9798, -51.6343, 253.4436, -51.0624, 257.8767, -50.6966, 260.9423, -50.2581, 261.6140, -49.2459, 260.7624, -46.4869, 260.5888, -45.3986, 259.8614, -44.8904, 257.7870, -44.9484, 256.1962, -45.7995, 256.3613, -48.5425, 253.5419, -49.9573, 249.8040, -49.5087, 248.3220, -49.4156, 245.7227, -48.7635, 244.6261, -48.0299, 245.6396, -46.7119, 247.9407, -46.1849, 251.5170, -45.7312, 252.8143, -45.1508, 251.9638, -44.5626, 249.5206, -44.4962, 247.9505, -43.8132, 247.9505, -43.8132, 247.9505, -43.8132],
    ["#396bad", 231.8281, -52.4833, 233.5614, -52.5365, 234.4273, -52.7145, 236.0044, -53.8647, 236.5304, -55.8352, 237.3389, -57.1286, 230.3741, -58.8315, 226.4955, -59.1351, 221.0867, -60.4628, 220.9820, -59.2769, 221.7242, -59.0271, 223.2728, -57.1869, 226.5641, -55.0286, 228.1040, -54.5097, 229.9674, -52.9922, 231.8281, -52.4833, 231.8281, -52.4833, 231.8281, -52.4833],
    ["#396bad", 191.9931, -60.9308, 195.0383, -60.9157, 197.2513, -61.5730, 197.6589, -63.3081, 193.3910, -65.2609, 190.6198, -65.3102, 189.1651, -65.7997, 187.9019, -65.8296, 187.4866, -64.7787, 188.0292, -64.2788, 187.2718, -63.6037, 188.0759, -62.2722, 190.6559, -61.1093, 191.9931, -60.9308, 191.9931, -60.9308],
    ["#396bad", 132.7337, -37.5805, 133.0861, -38.9333, 132.3284, -39.7468, 129.7569, -39.4258, 127.1207, -38.0660, 124.9328, -36.1447, 124.8899, -34.6079, 124.7196, -32.9119, 125.9376, -32.1253, 127.3543, -32.6954, 128.6915, -33.7875, 129.6263, -35.1366, 131.7847, -36.5415, 132.7337, -37.5805, 132.7337, -37.5805],
    ["#396bad", 121.1825, -39.3994, 119.9070, -39.0295, 119.2840, -37.6001, 119.3245, -36.1550, 117.3621, -34.3430, 116.3134, -31.1424, 115.5167, -28.5014, 115.3112, -26.0891, 115.8367, -24.7060, 117.0334, -24.5218, 117.8897, -25.7087, 118.5145, -28.1509, 119.6664, -31.5362, 121.7083, -34.8713, 122.3366, -37.4519, 122.1419, -39.0037, 121.1825, -39.3994, 121.1825, -39.3994],
    ["#396bad", 305.9982, 40.1858, 309.8895, 39.3472, 311.2759, 37.2754, 311.2100, 35.4356, 310.1900, 34.7837, 308.6971, 34.9849, 307.5461, 36.5500, 305.0697, 37.7876, 304.5142, 39.0978, 305.1288, 40.0209, 305.9982, 40.1858]
  ]
}


问:
Javascript - avoid multiple array.filters being called
I have a piece of code that looks like:

```<code>const desktop = platform.filter(el => el == "desktop").length;
const mobile = platform.filter(el => el == "mobile").length;
const android = platform.filter(el => el == "android").length;
</code>```

and so on..

Basically I have an array that contains multiple entries of those strings and I want to collect the length of each property in a variable. The above works but I was wondering if there is a cleaner way to avoid filter through the array multiple times?

答:
Use reduce and build one generic object.

const platforms = ['desktop', 'android', 'desktop', 'android', 'mobile'];
const len = platforms.reduce(
  (acc, item) =>
    Object.assign(acc, { [item]: item in acc ? acc[item] + 1 : 1 }),
  {}
);

console.log(len['desktop'], len.mobile)```

Body:
I have a piece of code that looks like:

const desktop = platform.filter(el => el == "desktop").length;
const mobile = platform.filter(el => el == "mobile").length;
const android = platform.filter(el => el == "android").length;

and so on..

Basically I have an array that contains multiple entries of those strings and I want to collect the length of each property in a variable. The above works but I was wondering if there is a cleaner way to avoid filter through the array multiple times?


问:
Autofill field on a click using django and javascript
I started to make a code to autofill a field when I click in a value that I already used in old requests so I did this:

to get the value from the loop in the javascript code:

```<code>{% for x in request.session.query_x reversed %}
var x_point = "{{x}}"
{% endfor %}

function autoFill() {
  document.getElementById('input1').value = x_point;
}
</code>```

the list was created from a loop and I want to click in each value at time to fill the field (html) - I got the list and everything works well in this part:

```<code>  {% for x in request.session.query_x reversed %}
      X: <a href="#" onClick="autoFill();">{{x}}</a><br>
  {% endfor %}
</code>```

the field that will receive the value:

```<code><div class="form-group floating-label-form-group controls mb-0 pb-2"><label>X</label><input class="form-control" type="text" id="input1" required="" placeholder="X"<br>
</code>```

The point is that any value from the loop that I click I got the first value from the loop not the right one from the position. What I missing here?

答:
You're overwriting x_point value on each iteration:

```<code>{% for x in request.session.query_x reversed %}
    var x_point = "{{x}}"
{% endfor %}
</code>```

Send event as parameter, so you can avoid link default behaviour and get inner text:

```<code>{% for x in request.session.query_x reversed %}
    X: <a href="#" onClick="autoFill(event);">{{x}}</a><br>
{% endfor %}

function autoFill(e) {
    // Avoid default link behaviour (scroll to #)
    e.preventDefault();
    // Assign link text
    document.getElementById('input1').value = e.target.innerText;
}
</code>```

Body:
I started to make a code to autofill a field when I click in a value that I already used in old requests so I did this:

to get the value from the loop in the javascript code:

{% for x in request.session.query_x reversed %}
var x_point = "{{x}}"
{% endfor %}

function autoFill() {
  document.getElementById('input1').value = x_point;
}

the list was created from a loop and I want to click in each value at time to fill the field (html) - I got the list and everything works well in this part:

  {% for x in request.session.query_x reversed %}
      X: {{x}}

  {% endfor %}

the field that will receive the value:

X<input class="form-control" type="text" id="input1" required="" placeholder="X"

The point is that any value from the loop that I click I got the first value from the loop not the right one from the position. What I missing here?

Body:
You're overwriting x_point value on each iteration:

{% for x in request.session.query_x reversed %}
    var x_point = "{{x}}"
{% endfor %}

Send event as parameter, so you can avoid link default behaviour and get inner text:

{% for x in request.session.query_x reversed %}
    X: <a href="#" onClick="autoFill(event);">{{x}}</a><br>
{% endfor %}

function autoFill(e) {
    // Avoid default link behaviour (scroll to #)
    e.preventDefault();
    // Assign link text
    document.getElementById('input1').value = e.target.innerText;
}


问:
How to parse iOS Firebase Storage error code in Swift?
How can I parse the following Firebase Storage error in Swift?

```<code>storageRef.delete { (error) in
    if let error = error {
        print(error)
    }
}
</code>```

Print console:

```<code>Error Domain=FIRStorageErrorDomain Code=-13010 "Object images/users/UBTXiedh11fT0s0BydkMuXk2k622/xyz.jpg does not exist." UserInfo={object=images/users/UBTXiedh11fT0s0BydkMuXk2k622/xyz.jpg, ResponseBody={
  "error": {
    "code": 404,
    "message": "Not Found.  Could not delete object",
    "status": "DELETE_OBJECT"
  }
}, bucket=someApp-10010010.appspot.com, data={length = 121, bytes = 0x7b0a2020 22657272 6f72223a 207b0a20 ... 54220a20 207d0a7d }, data_content_type=application/json; charset=UTF-8, NSLocalizedDescription=Object images/users/UBTXiedh11fT0s0BydkMuXk2k622/xyz.jpg does not exist., ResponseErrorDomain=com.google.HTTPStatus, ResponseErrorCode=404}
</code>```

I know there is StorageErrorCode but I do not know how to get the raw value into it.

```<code>if let errorCode = StorageErrorCode(rawValue: Int) {
    ...
}
</code>```

The goal is to be able to switch on the error code itself (i.e. 404).

答:
You must cast your error as NSError to get from it the code value (Int).  Then you can switch on the StorageErrorCode object (enum) using the error code as the raw value.

```<code>storageRef.delete { (error) in
    if let error = error as NSError? {
        let code = StorageErrorCode(rawValue: error.code)

        switch code {
        case .objectNotFound:
            print("object not found") // this is your 404
        default:
            break
        }
    }
}
</code>```

The documentation on this is very thin.

Body:
How can I parse the following Firebase Storage error in Swift?

storageRef.delete { (error) in
    if let error = error {
        print(error)
    }
}

Print console:

Error Domain=FIRStorageErrorDomain Code=-13010 "Object images/users/UBTXiedh11fT0s0BydkMuXk2k622/xyz.jpg does not exist." UserInfo={object=images/users/UBTXiedh11fT0s0BydkMuXk2k622/xyz.jpg, ResponseBody={
  "error": {
    "code": 404,
    "message": "Not Found.  Could not delete object",
    "status": "DELETE_OBJECT"
  }
}, bucket=someApp-10010010.appspot.com, data={length = 121, bytes = 0x7b0a2020 22657272 6f72223a 207b0a20 ... 54220a20 207d0a7d }, data_content_type=application/json; charset=UTF-8, NSLocalizedDescription=Object images/users/UBTXiedh11fT0s0BydkMuXk2k622/xyz.jpg does not exist., ResponseErrorDomain=com.google.HTTPStatus, ResponseErrorCode=404}

I know there is StorageErrorCode but I do not know how to get the raw value into it.

if let errorCode = StorageErrorCode(rawValue: Int) {
    ...
}

The goal is to be able to switch on the error code itself (i.e. 404).

Body:
You must cast your error as NSError to get from it the code value (Int).  Then you can switch on the StorageErrorCode object (enum) using the error code as the raw value.

storageRef.delete { (error) in
    if let error = error as NSError? {
        let code = StorageErrorCode(rawValue: error.code)

        switch code {
        case .objectNotFound:
            print("object not found") // this is your 404
        default:
            break
        }
    }
}

The documentation on this is very thin.


问:
Drupal 6: altering the profile form
I've added several fields to user profile using the standard profile tool. Now I want to validate data entered by a user; for example, I added a field called "email" and I want to let the users enter only valid emails to this field.

How can I achieve this?

答: You can select the field type "email" for profile fields that will automatically validate, but if you wish to do it manually, use hook_form_alter to add a validation callback to the form. Here's an article that covers the concept - http://befused.com/drupal/additional-validation-function</p>

Title: Drupal 6: altering the profile form


问:
How to scrape data other then stock data from yahoo finance
I'm wanting to scrape data on different shoe companies. I am trying to scrape the EPS from yahoo-finance however I cant find anywhere how to do this. The only way I see so far is finding stock data as open,close etc. How can I scrape data from yahoo-fiance that is not stock data.</p>

答:
Here is another approach for you.  Notice: by changing the URL, you can or delete different metrics to download.</p>

```<code>import requests
from bs4 import BeautifulSoup

base_url = 'http://finviz.com/screener.ashx?v=152&s=ta_topgainers&o=price&c=0,1,2,3,4,5,6,7,25,63,64,65,66,67'
html = requests.get(base_url)
soup = BeautifulSoup(html.content, "html.parser")
main_div = soup.find('div', attrs = {'id':'screener-content'})

light_rows = main_div.find_all('tr', class_="table-light-row-cp")
dark_rows = main_div.find_all('tr', class_="table-dark-row-cp")

data = []
for rows_set in (light_rows, dark_rows):
    for row in rows_set:
        row_data = []
        for cell in row.find_all('td'):
            val = cell.a.get_text()
            row_data.append(val)
        data.append(row_data)

#   sort rows to maintain original order
data.sort(key=lambda x: int(x[0]))
import pandas
pandas.DataFrame(data).to_csv("C:/Users/ryans/OneDrive/Desktop/today.csv", header=False)
</code>```

Body:
Here is another approach for you.  Notice: by changing the URL, you can or delete different metrics to download.

import requests
from bs4 import BeautifulSoup

base_url = 'http://finviz.com/screener.ashx?v=152&s=ta_topgainers&o=price&c=0,1,2,3,4,5,6,7,25,63,64,65,66,67'
html = requests.get(base_url)
soup = BeautifulSoup(html.content, "html.parser")
main_div = soup.find('div', attrs = {'id':'screener-content'})

light_rows = main_div.find_all('tr', class_="table-light-row-cp")
dark_rows = main_div.find_all('tr', class_="table-dark-row-cp")

data = []
for rows_set in (light_rows, dark_rows):
    for row in rows_set:
        row_data = []
        for cell in row.find_all('td'):
            val = cell.a.get_text()
            row_data.append(val)
        data.append(row_data)

#   sort rows to maintain original order
data.sort(key=lambda x: int(x[0]))
import pandas
pandas.DataFrame(data).to_csv("C:/Users/ryans/OneDrive/Desktop/today.csv", header=False)


问:
Pattern matching in database
I want to search every rows of specific column and if it matches with the string that is stored in an array or list the condition is update the status column in the db.

Note: My code is reading from text file and writing to the db but when on comparison it doesnt works

```<code>      if(textFileStrings.equals(dbtext))
         pstmt.setInt(status,0);
         prepareStatement.updateQuery();
</code>```

答:
try adding brackets, thus:</p>

```<code>  if(textFileStrings.equals(dbtext)) {
     pstmt.setInt(status,0);
     prepareStatement.updateQuery(); }
</code>```

Title: Pattern matching in database

Body:
I want to search every rows of specific column and if it matches with the string that is stored in an array or list the condition is update the status column in the db.

Note: My code is reading from text file and writing to the db but when on comparison it doesnt works

      if(textFileStrings.equals(dbtext))
         pstmt.setInt(status,0);
         prepareStatement.updateQuery();

Body:
try adding brackets, thus:

  if(textFileStrings.equals(dbtext)) {
     pstmt.setInt(status,0);
     prepareStatement.updateQuery(); }


问:
Moving rectangle to location using deltatime
I'm trying to have a simple rectangle move from current location to the clicked location on the canvas. When I provide a constant speed, the rectangle appears and moves fine. But when I multiply it by deltatime the rectangle doesn't appear anymore. I'm using requestAnimationFrame as the draw loop.

canvas.js

```<code>window.addEventListener('DOMContentLoaded', (event) => {
    let canvas = document.getElementById("gamecanvas");
    let ctx = canvas.getContext('2d');
    var oldframetime = 0;
    var x = 0;
    var y = 0;
    var dstx = 0;
    var dsty = 0;
    var deltatime = 0;
    var speed = 5;
    function getmousepos(evt){
        var rect = canvas.getBoundingClientRect();
        return {
          x: evt.clientX - rect.left,
          y: evt.clientY - rect.top
        };
    }
    canvas.addEventListener("mousedown",e=>{
        let coord = getmousepos(e);
        dstx = coord.x;
        dsty = coord.y;
    });
    function movetowards(current,target,maxdistancedelta){
        if(Math.abs(target - current)<=maxdistancedelta){
            return target;
        }
        return current+Math.sign(target - current) * maxdistancedelta;
    }
    function tick(timestamp){
        deltatime = (timestamp - oldframetime)/1000;

        var step = deltatime*speed;
        var newlocx = movetowards(x,dstx-50,5);
        var newlocy = movetowards(y,dsty-50,5);

        ctx.clearRect(0,0,canvas.clientWidth,canvas.clientHeight);
        ctx.fillStyle = 'green';
        ctx.fillRect(newlocx,newlocy,100,100);

        x = newlocx;
        y = newlocy;
        console.log(newlocx+":"+newlocy);
        oldframetime = timestamp;
        requestAnimationFrame(tick);
    }
    requestAnimationFrame(function(){
        tick();
    });
});
</code>```

In that example, newlocx and newlocy both print NaN:NaN
But if I choose not to use step and give it a constant speed of like 5, then it works fine.

```<code>    function tick(timestamp){
        deltatime = (timestamp - oldframetime)/1000;

        var step = deltatime*speed;
        var newlocx = movetowards(x,dstx-50,5);
        var newlocy = movetowards(y,dsty-50,5);

        ctx.clearRect(0,0,canvas.clientWidth,canvas.clientHeight);
        ctx.fillStyle = 'green';
        ctx.fillRect(newlocx,newlocy,100,100);

        x = newlocx;
        y = newlocy;
        console.log(newlocx+":"+newlocy);
        oldframetime = timestamp;
        requestAnimationFrame(tick);
    }
</code>```

The print is also accurate now. Why does multiplyng step by deltatime prevent the rectangle from moving? Or even appearing?

Here's the HTML if anyone's interested.

index.html

```<code><html>
    <head>
        <script src="canvas.js"></script>
    </head>
    <body>
        <canvas id="gamecanvas" width="2000" height="1000"></canvas>
    </body>
</html>
</code>```

答:
I have checked and found out the issue is in the first statement of tick function. When program starts then value of parameter is undefined. And thats why first statement of tick function result in NaN.

Just use some default value for parameter "timestamp". Its working now but speed is low and i hope you are aware about it.

Line to check:
function tick(timestamp=10)

function tick(timestamp=10) {
  deltatime = (timestamp - oldframetime) / 1000;

  var step = deltatime * speed;
  var newlocx = movetowards(x, dstx - 50, 5);
  var newlocy = movetowards(y, dsty - 50, 5);

  ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
  ctx.fillStyle = 'green';
  ctx.fillRect(newlocx, newlocy, 100, 100);

  x = newlocx;
  y = newlocy;
  console.log(newlocx + ":" + newlocy);
  oldframetime = timestamp;
  requestAnimationFrame(tick);
}```

Body:
I'm trying to have a simple rectangle move from current location to the clicked location on the canvas. When I provide a constant speed, the rectangle appears and moves fine. But when I multiply it by deltatime the rectangle doesn't appear anymore. I'm using requestAnimationFrame as the draw loop.

canvas.js

window.addEventListener('DOMContentLoaded', (event) => {
    let canvas = document.getElementById("gamecanvas");
    let ctx = canvas.getContext('2d');
    var oldframetime = 0;
    var x = 0;
    var y = 0;
    var dstx = 0;
    var dsty = 0;
    var deltatime = 0;
    var speed = 5;
    function getmousepos(evt){
        var rect = canvas.getBoundingClientRect();
        return {
          x: evt.clientX - rect.left,
          y: evt.clientY - rect.top
        };
    }
    canvas.addEventListener("mousedown",e=>{
        let coord = getmousepos(e);
        dstx = coord.x;
        dsty = coord.y;
    });
    function movetowards(current,target,maxdistancedelta){
        if(Math.abs(target - current)<=maxdistancedelta){
            return target;
        }
        return current+Math.sign(target - current) * maxdistancedelta;
    }
    function tick(timestamp){
        deltatime = (timestamp - oldframetime)/1000;

        var step = deltatime*speed;
        var newlocx = movetowards(x,dstx-50,5);
        var newlocy = movetowards(y,dsty-50,5);

        ctx.clearRect(0,0,canvas.clientWidth,canvas.clientHeight);
        ctx.fillStyle = 'green';
        ctx.fillRect(newlocx,newlocy,100,100);

        x = newlocx;
        y = newlocy;
        console.log(newlocx+":"+newlocy);
        oldframetime = timestamp;
        requestAnimationFrame(tick);
    }
    requestAnimationFrame(function(){
        tick();
    });
});

In that example, newlocx and newlocy both print NaN:NaN
But if I choose not to use step and give it a constant speed of like 5, then it works fine.

    function tick(timestamp){
        deltatime = (timestamp - oldframetime)/1000;

        var step = deltatime*speed;
        var newlocx = movetowards(x,dstx-50,5);
        var newlocy = movetowards(y,dsty-50,5);

        ctx.clearRect(0,0,canvas.clientWidth,canvas.clientHeight);
        ctx.fillStyle = 'green';
        ctx.fillRect(newlocx,newlocy,100,100);

        x = newlocx;
        y = newlocy;
        console.log(newlocx+":"+newlocy);
        oldframetime = timestamp;
        requestAnimationFrame(tick);
    }

The print is also accurate now. Why does multiplyng step by deltatime prevent the rectangle from moving? Or even appearing?

Here's the HTML if anyone's interested.

index.html

        <canvas id="gamecanvas" width="2000" height="1000"></canvas>


问:
How to make a JAR from simplegraph with underlying sources from tinkerpop/gremlin
I have made a JAR from SimpleGraph which I want to use it in a separat project.
In my own project I can see and use the direct classes of SimpleGraph like ExcelSystem etc. but can not use the underlying classes as Vertex etc. from Tinkerpop/Gremlin.
Is there a way to include these into the JAR generation?</p>

答:
The installation instructions at http://www.bitplan.com/index.php/SimpleGraph-Installation have been updated according to your question.

To include simplegraph as a single jar dependency for your project you might want to run:

```<code>cd com.bitplan.simplegraph/simplegraph-bundle
mvn install -D skipTests -D gpg.skip -P createAssembly
</code>```

which will create a jar-with-dependencies.jar

Body:
The installation instructions at http://www.bitplan.com/index.php/SimpleGraph-Installation have been updated according to your question.

To include simplegraph as a single jar dependency for your project you might want to run:

cd com.bitplan.simplegraph/simplegraph-bundle
mvn install -D skipTests -D gpg.skip -P createAssembly

which will create a jar-with-dependencies.jar


问:
Using RelativeLayout dynamically and setting margins in px, dp, inch, mm
My application is just a modified ImageViewer with the options of zooming and dragging.
Containing that modified Imageviewer there is a RelativeLayout (that I want to use as an AbsoluteLayout).

Then, new elements can be added to the layout to situate them in certain points of the image. The position (x, y) in pixels of the elements is in a database so I guess there is no other way that adding them programmatically, and not with XML.

Then the position of those elements is updated every time that a dragging or zooming action is performed.

The problem is that somehow the pixels of the image are not matching with the pixels in the RelativeLayout! So the items are "more or less" situated but not in the proper place (the further from (0,0) the bigger is the error).

Things I've tried already:

Try different conversions because maybe the problem is related to the difference of densities between the Bitmap and the Layout:

```<code>Resources r = getResources();
float x = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics());
</code>```

Try to use different methods in the layout to set the margins:

```<code>RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = (int) newPosition.x;
params.topMargin = (int) newPosition.y;
element.setLayoutParams(params);
</code>```

I also wanted to use the options available for the RelativeLayout in XML but I really cant find it programmatically but I can find the way to specify the dimension, I mean:

```<code>android:layout_marginLeft ="50px" // or "50mm", or dp, or inches...
</code>```

答: Try this: for Relative Layout you can set the margins like this: params.setMargins(left, top, right, bottom);

Body:
My application is just a modified ImageViewer with the options of zooming and dragging.
Containing that modified Imageviewer there is a RelativeLayout (that I want to use as an AbsoluteLayout).

Then, new elements can be added to the layout to situate them in certain points of the image. The position (x, y) in pixels of the elements is in a database so I guess there is no other way that adding them programmatically, and not with XML.

Then the position of those elements is updated every time that a dragging or zooming action is performed.

The problem is that somehow the pixels of the image are not matching with the pixels in the RelativeLayout! So the items are "more or less" situated but not in the proper place (the further from (0,0) the bigger is the error).

Things I've tried already:

Try different conversions because maybe the problem is related to the difference of densities between the Bitmap and the Layout:

Resources r = getResources();
float x = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics());

Try to use different methods in the layout to set the margins:

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = (int) newPosition.x;
params.topMargin = (int) newPosition.y;
element.setLayoutParams(params);

I also wanted to use the options available for the RelativeLayout in XML but I really cant find it programmatically but I can find the way to specify the dimension, I mean:

android:layout_marginLeft ="50px" // or "50mm", or dp, or inches...


问:
Python- Dot Product of a Slice of Row of Matrix with Slice of a Vector
I am trying to write a simple code for Gaussian Elimination.

```<code>import numpy as np

def g_elimination(A,B):
    n=A.shape[0]
    for i in range(0,n-1):# Pivot Rows where 1st pivot is Row 0
        for j in range(i+1,n):#Rows to transform exclude Row 0
            B[j]=B[j]-(A[j,i]/A[i,i])*B[i]
            A[j]=A[j]-np.dot(A[j,i]/A[i,i],A[i])

def back_substitution(X,A,B):
    n=B.shape[0]
    for i in reversed(range(0,n)):
        X[i]=(B[i]-np.dot([X[:i]],A[i:,:i]))/A[i,i]

A=np.array([[4.0,-2,1],[-2,4,-2],[1,-2,4]])
B=np.array([11,-16,17],dtype='float64')
X=np.zeros(B.shape)

g_elimination(A,B)
back_substitution(X,A,B)
</code>```

During the back substitution phase, I am trying to find the dot product of the slice of row of matrix
A with slice of vector X. I am getting an error

```<code>Traceback (most recent call last):
  File "main.py", line 25, in <module>
    back_substitution(X,A,B)
  File "main.py", line 16, in back_substitution
    X[i]=(B[i]-np.dot([X[:i]],A[i:,:i]))/A[i,i]
  File "<__array_function__ internals>", line 5, in dot
ValueError: shapes (1,2) and (1,2) not aligned: 2 (dim 1) != 1 (dim 0)
</code>```

Could anyone please help me correct this error.

答:
help me correct this error.

For the example data you gave, the terms of np.dot end up being 1d and 2d, if you switch them around np.dot(2d,1d) that error goes away. Unfortunately I'm not familiar with your calc/process so I don't really know if this is what you want. Since one of the terms is 1d I wonder whether you intended it to be a scalar.

```<code>def back_substitution(X,A,B):
    n=B.shape[0]
    for i in reversed(range(0,n)):
        #X[i]=(B[i]-np.dot([X[:i]],A[i:,:i]))/A[i,i]
        q = X[:i]
        r = A[i:,:i]
        s = A[i,i]
        t = B[i]
        try:
            #u = np.dot([q],r)
            #u = np.dot(q,r)
            #u = np.dot(r,q)
            little,big = sorted([q,r],key=lambda w: w.ndim)
            u = np.dot(big,little)
        except ValueError as e:
            print(e)
            print(q)
            print(r)
            print(q.shape,r.shape)
            print('*****')
        v = (t-u)/s
        X[i] = v
        #print(X)
</code>```

This gets rid of the original ValueError that you asked about - but now X[i] = v complains that you are trying to set an array element with a sequence. Again being unfamiliar with what you are trying to do, I don't know what the solution is.

Body:
I am trying to write a simple code for Gaussian Elimination.

import numpy as np

def g_elimination(A,B):
    n=A.shape[0]
    for i in range(0,n-1):# Pivot Rows where 1st pivot is Row 0
        for j in range(i+1,n):#Rows to transform exclude Row 0
            B[j]=B[j]-(A[j,i]/A[i,i])*B[i]
            A[j]=A[j]-np.dot(A[j,i]/A[i,i],A[i])

def back_substitution(X,A,B):
    n=B.shape[0]
    for i in reversed(range(0,n)):
        X[i]=(B[i]-np.dot([X[:i]],A[i:,:i]))/A[i,i]

A=np.array([[4.0,-2,1],[-2,4,-2],[1,-2,4]])
B=np.array([11,-16,17],dtype='float64')
X=np.zeros(B.shape)

g_elimination(A,B)
back_substitution(X,A,B)

During the back substitution phase, I am trying to find the dot product of the slice of row of matrix
A with slice of vector X. I am getting an error

Traceback (most recent call last):
  File "main.py", line 25, in <module>
    back_substitution(X,A,B)
  File "main.py", line 16, in back_substitution
    X[i]=(B[i]-np.dot([X[:i]],A[i:,:i]))/A[i,i]
  File "<__array_function__ internals>", line 5, in dot
ValueError: shapes (1,2) and (1,2) not aligned: 2 (dim 1) != 1 (dim 0)

Could anyone please help me correct this error.

Body:
help me correct this error.

For the example data you gave, the terms of np.dot end up being 1d and 2d, if you switch them around np.dot(2d,1d) that error goes away. Unfortunately I'm not familiar with your calc/process so I don't really know if this is what you want. Since one of the terms is 1d I wonder whether you intended it to be a scalar.

def back_substitution(X,A,B):
    n=B.shape[0]
    for i in reversed(range(0,n)):
        #X[i]=(B[i]-np.dot([X[:i]],A[i:,:i]))/A[i,i]
        q = X[:i]
        r = A[i:,:i]
        s = A[i,i]
        t = B[i]
        try:
            #u = np.dot([q],r)
            #u = np.dot(q,r)
            #u = np.dot(r,q)
            little,big = sorted([q,r],key=lambda w: w.ndim)
            u = np.dot(big,little)
        except ValueError as e:
            print(e)
            print(q)
            print(r)
            print(q.shape,r.shape)
            print('*****')
        v = (t-u)/s
        X[i] = v
        #print(X)

This gets rid of the original ValueError that you asked about - but now X[i] = v complains that you are trying to set an array element with a sequence. Again being unfamiliar with what you are trying to do, I don't know what the solution is.


问:
Synchronize YouTube video playback for users connected to server via JavaFX
I'm new to JavaFX and Socket Programming. I'm working on a desktop application in which users will connect to a server and put YouTube link in textbox and the video will be streamed synchronously to all the users connected to server. Everything will happen in application without use of external browser. I will be using JavaFX for the GUI and Socket for network. I'm looking for some guidance on how can i implement it properly. Thanks.</p>

答:
You can use WebView to load youtube video.
There is some limitations to play youtube video in media player.
So webview will the best solution

```<code>package com.jenkov.javafx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class WebViewExample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle("JavaFX WebView Example");

        WebView webView = new WebView();

        webView.getEngine().load("https://www.youtube.com/watch?v=asdfghj");

        VBox vBox = new VBox(webView);
        Scene scene = new Scene(vBox, 960, 600);

        primaryStage.setScene(scene);
        primaryStage.show();

    }
}
</code>```

Please see the answer Play a Youtube video using JavaFX

Body:
You can use WebView to load youtube video.
There is some limitations to play youtube video in media player.
So webview will the best solution

package com.jenkov.javafx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class WebViewExample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle("JavaFX WebView Example");

        WebView webView = new WebView();

        webView.getEngine().load("https://www.youtube.com/watch?v=asdfghj");

        VBox vBox = new VBox(webView);
        Scene scene = new Scene(vBox, 960, 600);

        primaryStage.setScene(scene);
        primaryStage.show();

    }
}

Please see the answer Play a Youtube video using JavaFX


问:
Listbox: WM_CHAR time interval for searching items
The Microsoft documentation of WM_CHAR for the listbox control states this (emphasis of short interval is mine):

WM_CHAR
Moves  selection to the first item that begins with the character that the user typed. If the list box has the LBS_OWNERDRAW style, no action occurs. Multiple characters that are typed within a short interval are treated as a group, and the first item that begins with that series of characters is selected.

They mention a short interval.

Does anybody know if the duration of this interval can be obtained somehow?

I have an onwer draw listbox where the bahaviour described above does not occur (which is the normal documented behaviour), and I'm emulating this myself using an interval of 1.5 seconds (which seems to be more or less the duration of the short interval).

Everything works fine, but rather than using a hard coded duration of 1.5 seconds, I'd like to retrieve this duration from somewhere (registry, some API I'm not aware of, ...) so the interval is the one used by the default behaviour of a list box.

答:
in my test i found that ListBox use time returned by GetDoubleClickTime() and multiple it on 4.

so interval = 4 * GetDoubleClickTime() or GetDoubleClickTime() << 2.

we can test this by change double-click time with SetDoubleClickTime function
for example

```<code>UINT t = GetDoubleClickTime();
SetDoubleClickTime(4000);
test();
SetDoubleClickTime(t);
</code>```

or by hook and modify GetDoubleClickTime return value or change asm code under debugger (for not change even temporary global windows settings). anyway change return value from GetDoubleClickTime have visible effect for ListBox behavior

Body:
in my test i found that ListBox use time returned by GetDoubleClickTime() and multiple it on 4.

so interval = 4 * GetDoubleClickTime() or GetDoubleClickTime() << 2.

we can test this by change double-click time with SetDoubleClickTime function
for example

UINT t = GetDoubleClickTime();
SetDoubleClickTime(4000);
test();
SetDoubleClickTime(t);

or by hook and modify GetDoubleClickTime return value or change asm code under debugger (for not change even temporary global windows settings). anyway change return value from GetDoubleClickTime have visible effect for ListBox behavior


问:
The method addFilter(SerializablePredicate) in the type InMemoryDataProvider is not applicable for the arguments (( desc) -> {})
I am playing around with Vaadin and now I am trying to add a filter to a Grid that gets it data via JPA and a MySQL DB. It should be very simple and I am rigorously following the examples shown here. All seems to be going well until I get this eponymous error message.

This is how I have set up the class data communication.

```<code>    @Autowired
    CoreRepository crp;
    @Id("descriptionFilter")
    private TextField descriptionFilter;
    List<db> list = crp.findAll();
    ListDataProvider<db> ldp = DataProvider.ofCollection(list);
    grid.setDataProvider(ldp);
</code>```

And the filtering:

```<code>    /* Filtration */
    descriptionFilter.addValueChangeListener( e->
    {
        Notification.show(e.getValue());

        ldp.addFilter(desc ->
        {
            StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue()); //<< I get the error here
        });
    });
    descriptionFilter.setValueChangeMode(ValueChangeMode.EAGER);
</code>```

However, I get this error and I do not understand how this is happening

The method addFilter(SerializablePredicate) in the
  type InMemoryDataProvider is not applicable for the
  arguments (( desc) -> {})

What could I be possibly doing wrong?

答:
It has to be a SerializablePredicate, so it must return a boolean:

```<code>ldp.addFilter(desc ->
{
    return StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue());
})
</code>```

or even simpler:

```<code>ldp.addFilter(desc -> StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue()));
</code>```

Body:
I am playing around with Vaadin and now I am trying to add a filter to a Grid that gets it data via JPA and a MySQL DB. It should be very simple and I am rigorously following the examples shown here. All seems to be going well until I get this eponymous error message.

This is how I have set up the class data communication.

    @Autowired
    CoreRepository crp;
    @Id("descriptionFilter")
    private TextField descriptionFilter;
    List<db> list = crp.findAll();
    ListDataProvider<db> ldp = DataProvider.ofCollection(list);
    grid.setDataProvider(ldp);

And the filtering:

    /* Filtration */
    descriptionFilter.addValueChangeListener( e->
    {
        Notification.show(e.getValue());

        ldp.addFilter(desc ->
        {
            StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue()); //<< I get the error here
        });
    });
    descriptionFilter.setValueChangeMode(ValueChangeMode.EAGER);

However, I get this error and I do not understand how this is happening

The method addFilter(SerializablePredicate) in the
  type InMemoryDataProvider is not applicable for the
  arguments (( desc) -> {})

What could I be possibly doing wrong?

Body:
It has to be a SerializablePredicate, so it must return a boolean:

ldp.addFilter(desc ->
{
    return StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue());
})

or even simpler:

ldp.addFilter(desc -> StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue()));