问:
Is it OK to remove Prefix.pch file from the Xcode project?
The Xcode project generates Prefix.pch file automatically. When I deleted this file and tried to build, I got build error saying '*_Prefix.pch' file is missing.

Is Prefix.pch file is a must for compiling with Xcode?

How can I build without the Prefix.pch file?

答:
In Xcode, go to your target's build settings (Command-Option-E, build tab) and uncheck Precompile Prefix Header (GCC_PRECOMPILE_PREFIX_HEADER). You can also remove the value of the Prefix Header setting if you wish.

Prefix headers are compiled and stored in a cache, and then automatically included in every file during compilation. This can speed up compilation, and lets you include a file without adding an import statement to every file using it. They are not required, and actually slow compilation whenever you change them.


来源: stackexchange

问:
My app resets data when it is minimized
i made an android game once i minimize it,
it resets data and refresh the timer like you started the game from the scratch
how can i make it Don't do this

i think the problem is on the OnStart function

```<code>  protected void onStart() {
    super.onStart();

    // Reset score
    Configs.score = 0;
    scoreTxt.setText(String.valueOf(Configs.score));

    // Set progressBar and start the gameTimer
    pb = (ProgressBar)findViewById(R.id.gbProgressBar);
    progress = 0;
    pb.setProgress((int) progress);
    startGameTimer();

    // Get a random circle for letters
    Random r = new Random();
    randomCircle = r.nextInt(Configs.circlesArray.length);

    // Reset taps count
    tapsCount = -1;

    // Get a random word from words string-array
    getRandomWord();
}
</code>```

答:
onStart is called every time the app starts. onCreate on the other hand, is only called when the app starts or after the activity process has been killed and restarted. Usually the last scenario means after onStop is called and the activity process is killed, but it isn't destroyed yet.

Move that code to onCreate, otherwise it calls that every time the app is reopened which resets it

ContentLicense: CC BY-SA 3.0

Title: My app resets data when it is minimized

Body:
i made an android game once i minimize it,
it resets data and refresh the timer like you started the game from the scratch
how can i make it Don't do this

i think the problem is on the OnStart function

  protected void onStart() {
    super.onStart();

    // Reset score
    Configs.score = 0;
    scoreTxt.setText(String.valueOf(Configs.score));

    // Set progressBar and start the gameTimer
    pb = (ProgressBar)findViewById(R.id.gbProgressBar);
    progress = 0;
    pb.setProgress((int) progress);
    startGameTimer();

    // Get a random circle for letters
    Random r = new Random();
    randomCircle = r.nextInt(Configs.circlesArray.length);

    // Reset taps count
    tapsCount = -1;

    // Get a random word from words string-array
    getRandomWord();
}


问:
How to center a div (CSS loader)
JS Fiddle: fiddle and here is the code:

.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="loader"></div></code>```

How do I centre it horizontally & vertically?

I tried:

```<code>position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
</code>```

But transform:translate(-50%,-50%); do not work

答:
Several ways to do it.

Using flexbox. This would work in any container anywhere on the page.

body {  /* or some wrapper, if you plan to have other things in body */
  min-height: 100vh; /* this just expands the body height so the vertical alignment is visible in the snippet */
  display: flex;
  justify-content: center; /* center horizontally */
  align-items: center; /* center vertically */
}

.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="loader"></div></code>```

Using position: absolute. This centers the div relative to the document, not loader's parent element.

.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;

  /* i added this: */
  position: absolute;
  left: calc(50% - 120px / 2); /* 50 % of body width minus half of .loader size… */
  top: calc(50% - 120px / 2);  /* …and the same thing with height */
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="loader"></div></code>```

Title: How to center a div (CSS loader)

Body:
JS Fiddle: fiddle and here is the code:

.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

How do I centre it horizontally & vertically?

I tried:

position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);

But transform:translate(-50%,-50%); do not work

Body:
Several ways to do it.

Using flexbox. This would work in any container anywhere on the page.

body {  /* or some wrapper, if you plan to have other things in body */
  min-height: 100vh; /* this just expands the body height so the vertical alignment is visible in the snippet */
  display: flex;
  justify-content: center; /* center horizontally */
  align-items: center; /* center vertically */
}

.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

<div class="loader"></div>

Using position: absolute. This centers the div relative to the document, not loader's parent element.

.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;

  /* i added this: */
  position: absolute;
  left: calc(50% - 120px / 2); /* 50 % of body width minus half of .loader size… */
  top: calc(50% - 120px / 2);  /* …and the same thing with height */
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

<div class="loader"></div>


问:
loess on grouped data in plotly does not work properly
I want to create a plot with loess on grouped data in plotly. It does not work properly, because it produces only one line. It seems it's a bug.</p>

```<code>df <- data.frame(
         id  = rep(1:1000, 3),
         value = c(rnorm(1000,mean = 2),
                   rnorm(1000,mean = 4),
                   rnorm(1000,mean = 6)),
         var = rep(LETTERS[1:3], each = 1000))

# ggplot2 - it works as it should be
ggplot(df, aes(id, value, color  = var)) +
  geom_smooth(method = "loess")

# plotly - it doesn't work properly
df %>%
  plot_ly(x = ~id) %>%
  add_markers( y = ~value, color = ~var) %>%
  add_lines(y = ~fitted(loess(value ~ id)), color = ~var)
</code>```

答:
This is expected behavior since you are not fitting loess by group in the add_lines call.

Here is an approach in which you first calculate the fit by group and then plot

```<code>library(tidyverse)
library(plotly)

df %>%
  group_by(var) %>%
  mutate(fit = fitted(loess(value ~ id))) %>%
  plot_ly(x = ~id) %>%
  add_markers( y = ~value, color = ~var, alpha = 0.5) %>%
  add_lines(y = ~fit, color = ~var)
</code>```

Body:
I want to create a plot with loess on grouped data in plotly. It does not work properly, because it produces only one line. It seems it's a bug.

df <- data.frame(
         id  = rep(1:1000, 3),
         value = c(rnorm(1000,mean = 2),
                   rnorm(1000,mean = 4),
                   rnorm(1000,mean = 6)),
         var = rep(LETTERS[1:3], each = 1000))

# ggplot2 - it works as it should be
ggplot(df, aes(id, value, color  = var)) +
  geom_smooth(method = "loess")

# plotly - it doesn't work properly
df %>%
  plot_ly(x = ~id) %>%
  add_markers( y = ~value, color = ~var) %>%
  add_lines(y = ~fitted(loess(value ~ id)), color = ~var)

Body:
This is expected behavior since you are not fitting loess by group in the add_lines call.

Here is an approach in which you first calculate the fit by group and then plot

library(tidyverse)
library(plotly)

df %>%
  group_by(var) %>%
  mutate(fit = fitted(loess(value ~ id))) %>%
  plot_ly(x = ~id) %>%
  add_markers( y = ~value, color = ~var, alpha = 0.5) %>%
  add_lines(y = ~fit, color = ~var)


问:
How to call Stored Procedure in Entity Framework 6 (Code-First)?
I am very new to Entity Framework 6 and I want to implement stored procedures in my project. I have a stored procedure as follows:

```<code>ALTER PROCEDURE [dbo].[insert_department]
    @Name [varchar](100)
AS
BEGIN
    INSERT [dbo].[Departments]([Name])
    VALUES (@Name)

    DECLARE @DeptId int

    SELECT @DeptId = [DeptId]
    FROM [dbo].[Departments]
    WHERE @@ROWCOUNT > 0 AND [DeptId] = SCOPE_IDENTITY()

    SELECT t0.[DeptId]
    FROM [dbo].[Departments] AS t0
    WHERE @@ROWCOUNT > 0 AND t0.[DeptId] = @DeptId
END
</code>```

Department class:

```<code>public class Department
{
    public int DepartmentId { get; set; }
    public string Name { get; set; }
}

modelBuilder
.Entity<Department>()
.MapToStoredProcedures(s =>
s.Update(u => u.HasName("modify_department")
               .Parameter(b => b.Department, "department_id")
               .Parameter(b => b.Name, "department_name"))
 .Delete(d => d.HasName("delete_department")
               .Parameter(b => b.DepartmentId, "department_id"))
 .Insert(i => i.HasName("insert_department")
               .Parameter(b => b.Name, "department_name")));

protected void btnSave_Click(object sender, EventArgs e)
{
    string department = txtDepartment.text.trim();

    // here I want to call the stored procedure to insert values
}
</code>```

My problem is: how can I call the stored procedure and pass parameters into it?

答:
```<code>public IList<Models.StandardRecipeDetail> GetRequisitionDetailBySearchCriteria(Guid subGroupItemId, Guid groupItemId)
{
    var query = this.UnitOfWork.Context.Database.SqlQuery<Models.StandardRecipeDetail>("SP_GetRequisitionDetailBySearchCriteria @SubGroupItemId,@GroupItemId",
    new System.Data.SqlClient.SqlParameter("@SubGroupItemId", subGroupItemId),
    new System.Data.SqlClient.SqlParameter("@GroupItemId", groupItemId));
    return query.ToList();
}
</code>```

Body:
I am very new to Entity Framework 6 and I want to implement stored procedures in my project. I have a stored procedure as follows:

ALTER PROCEDURE [dbo].[insert_department]
    @Name [varchar](100)
AS
BEGIN
    INSERT [dbo].[Departments]([Name])
    VALUES (@Name)

    DECLARE @DeptId int

    SELECT @DeptId = [DeptId]
    FROM [dbo].[Departments]
    WHERE @@ROWCOUNT > 0 AND [DeptId] = SCOPE_IDENTITY()

    SELECT t0.[DeptId]
    FROM [dbo].[Departments] AS t0
    WHERE @@ROWCOUNT > 0 AND t0.[DeptId] = @DeptId
END

Department class:

public class Department
{
    public int DepartmentId { get; set; }
    public string Name { get; set; }
}

modelBuilder
.Entity<Department>()
.MapToStoredProcedures(s =>
s.Update(u => u.HasName("modify_department")
               .Parameter(b => b.Department, "department_id")
               .Parameter(b => b.Name, "department_name"))
 .Delete(d => d.HasName("delete_department")
               .Parameter(b => b.DepartmentId, "department_id"))
 .Insert(i => i.HasName("insert_department")
               .Parameter(b => b.Name, "department_name")));

protected void btnSave_Click(object sender, EventArgs e)
{
    string department = txtDepartment.text.trim();

    // here I want to call the stored procedure to insert values
}

My problem is: how can I call the stored procedure and pass parameters into it?


问:
how to get cursor position in soft keyboard in landscape
How to get cursor position in soft keyboard in landscape. In portrait mode I can use OnTouchListener but in landscape mode, the OnTouchListener does not work on full screen soft keyboard.

```<code>editText.setOnTouchListener(new View.OnTouchListener() {
      @Override
      public boolean onTouch(View view, MotionEvent motionEvent) {
            cursorPosition = editText.getOffsetForPosition(motionEvent.getX(), motionEvent.getY()); // will give you the position of the nearest chracter.
            return false;
      }
});
</code>```

In short, how can I do what above does on landscape full screen keyboard..

答:
You are right, OnTouchListener  will not work in fullscreen mode of EditText. However, if it is helpful for you, you can use a listener which is called when a cursor position is changed. To do that, extend EditText and override its onSelectionChanged method:

```<code>public class CustomEditText extends EditText
{
    public CustomEditText(Context context)
    {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    @Override
    protected void onSelectionChanged(int selStart, int selEnd)
    {
        super.onSelectionChanged(selStart, selEnd);
       // here you get cursor position change
    }
}
</code>```

Body:
How to get cursor position in soft keyboard in landscape. In portrait mode I can use OnTouchListener but in landscape mode, the OnTouchListener does not work on full screen soft keyboard.

editText.setOnTouchListener(new View.OnTouchListener() {
      @Override
      public boolean onTouch(View view, MotionEvent motionEvent) {
            cursorPosition = editText.getOffsetForPosition(motionEvent.getX(), motionEvent.getY()); // will give you the position of the nearest chracter.
            return false;
      }
});

In short, how can I do what above does on landscape full screen keyboard..

Body:
You are right, OnTouchListener  will not work in fullscreen mode of EditText. However, if it is helpful for you, you can use a listener which is called when a cursor position is changed. To do that, extend EditText and override its onSelectionChanged method:

public class CustomEditText extends EditText
{
    public CustomEditText(Context context)
    {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    @Override
    protected void onSelectionChanged(int selStart, int selEnd)
    {
        super.onSelectionChanged(selStart, selEnd);
       // here you get cursor position change
    }
}


问:
How to change output format of material 2 date-picker
I am using angular material 2 Date-Picker component

The only string input it understands is in ISO date format

Ex. "2017-11-13T10:39:28.300Z"

But i want to patch my form control with locale date value

Ex. "11/13/2017, 4:09:46 PM"

So that it output the later format and even expects this format.

How can i do this? Is there a way to not use ISO but custom formats?

Some Thoughts:

Should i write customDateAdaptor?

Update:

https://stackblitz.com/edit/angular-material-moment-adapter-example-bqvm2f

i have tried to implement custom dateAdaptor by extending nativeDateAdaptor

答:
you can change it's format like this:</p>

```<code> const Date = Date.replace(/-/g, '/')
</code>```

Body:
you can change it's format like this:

 const Date = Date.replace(/-/g, '/')


问:
Log in not working using scrapy
I have written scrapy code for log in to a site. first i tried for one site. It worked well. But then i changed the url and tried for other site. It is not working for that site. I used the same code without any change. What would be the problem?

```<code>        # -*- coding: utf-8 -*-
import scrapy
from scrapy.http import FormRequest
from scrapy.utils.response import open_in_browser

class QuoteSpider(scrapy.Spider):
    name = 'Quote'
    allowed_domains = ["quotes.toscrape.com"]
    start_urls = (
        'http://quotes.toscrape.com/login',
    )

    def parse(self, response):
        token=response.xpath('//input[@name="csrf_token"]/@value').extract_first()

        return FormRequest.from_response(response,formdata={'csrf_token':token,'password':'foo','username':'foo'},callback=self.scape_home_page)

    def scape_home_page(self, response):
        open_in_browser(response)
</code>```

This worked well.

```<code>    # -*- coding: utf-8 -*-
import scrapy
from scrapy.http import FormRequest
from scrapy.utils.response import open_in_browser

class BucketsSpider(scrapy.Spider):
    name = 'buckets'
    allowed_domains = ['http://collegekart.in/login']
    start_urls = ['http://collegekart.in/login/']

    def parse(self, response):
        token=response.xpath('//meta[@name="csrf-token"]/@content').extract_first()
        print(token)
        return FormRequest.from_response(response,formdata={'csrf-token':token,'password':'*********','username':'**************'},callback=self.scape_home_page)

    def scape_home_page(self, response):
        open_in_browser(response)
        print("yes")
</code>```

This is not working. Please help to solve this.

答: Here change the response url accordingly, this wil  solve the problem.</p>

Title: Log in not working using scrapy

Body:
I have written scrapy code for log in to a site. first i tried for one site. It worked well. But then i changed the url and tried for other site. It is not working for that site. I used the same code without any change. What would be the problem?

        # -*- coding: utf-8 -*-
import scrapy
from scrapy.http import FormRequest
from scrapy.utils.response import open_in_browser

class QuoteSpider(scrapy.Spider):
    name = 'Quote'
    allowed_domains = ["quotes.toscrape.com"]
    start_urls = (
        'http://quotes.toscrape.com/login',
    )

    def parse(self, response):
        token=response.xpath('//input[@name="csrf_token"]/@value').extract_first()

        return FormRequest.from_response(response,formdata={'csrf_token':token,'password':'foo','username':'foo'},callback=self.scape_home_page)

    def scape_home_page(self, response):
        open_in_browser(response)

This worked well.

    # -*- coding: utf-8 -*-
import scrapy
from scrapy.http import FormRequest
from scrapy.utils.response import open_in_browser

class BucketsSpider(scrapy.Spider):
    name = 'buckets'
    allowed_domains = ['http://collegekart.in/login']
    start_urls = ['http://collegekart.in/login/']

    def parse(self, response):
        token=response.xpath('//meta[@name="csrf-token"]/@content').extract_first()
        print(token)
        return FormRequest.from_response(response,formdata={'csrf-token':token,'password':'*********','username':'**************'},callback=self.scape_home_page)

    def scape_home_page(self, response):
        open_in_browser(response)
        print("yes")

This is not working. Please help to solve this.


问:
DBCC CHECKIDENT Sets Identity to 0
I'm using this code to reset the identity on a table:

```<code>DBCC CHECKIDENT('TableName', RESEED, 0)
</code>```

This works fine most of the time, with the first insert I do inserting 1 into the Id column. However, if I drop the DB and recreate it (using scripts I've written) and then call DBCC CHECKIDENT, the first item inserted will have an ID of 0.

Any ideas?

EDIT: After researching I found out I didn't read the documentation properly - "The current identity value is set to the new_reseed_value. If no rows have been inserted to the table since it was created, the first row inserted after executing DBCC CHECKIDENT will use new_reseed_value as the identity. Otherwise, the next row inserted will use new_reseed_value + 1. "

答:
As you pointed out in your question it is a documented behavior. I still find it strange though. I use to repopulate the test database and even though I do not rely on the values of identity fields it was a bit of annoying to have different values when populating the database for the first time from scratch and after removing all data and populating again.

A possible solution is to use truncate to clean the table instead of delete. But then you need to drop all the constraints and recreate them afterwards

In that way it always behaves as a newly created table and there is no need to call DBCC CHECKIDENT. The first identity value will be the one specified in the table definition and it will be the same no matter if you insert the data for the first time or for the N-th

ContentLicense: CC BY-SA 4.0

Title: DBCC CHECKIDENT Sets Identity to 0

Body:
I'm using this code to reset the identity on a table:

DBCC CHECKIDENT('TableName', RESEED, 0)

This works fine most of the time, with the first insert I do inserting 1 into the Id column. However, if I drop the DB and recreate it (using scripts I've written) and then call DBCC CHECKIDENT, the first item inserted will have an ID of 0.

Any ideas?

EDIT: After researching I found out I didn't read the documentation properly - "The current identity value is set to the new_reseed_value. If no rows have been inserted to the table since it was created, the first row inserted after executing DBCC CHECKIDENT will use new_reseed_value as the identity. Otherwise, the next row inserted will use new_reseed_value + 1. "

OwnerDisplayName: kristof

ContentLicense: CC BY-SA 2.5

LastEditorDisplayName: kristof


问:
How can I run each junit test as if running newly every time?
In Junit, I have 2 tests. If I run individually, it is taking 4sec each. But if I run together also it is taking 4-5sec. I expected 8secs.

In both the tests, only input varies.

It is not spring project. It is not using databases.

It uses Aspose word to create MS-Word from xml.

How can I run each test as if running newly every time.?

答: I have found that JIT compiler in java is doing optimization when a method is running frequently. This is the reason for the performance improvement.</p>


问:
PHP undefined index database issues
I am having issues with displaying the database table. My database table (activities) have the following value, ID (Primary Key), type, title, description and picture. I am trying to retrieve and display title,description and picture in a table format but is facing an  error

"Notice: Undefined index: title, Notice: Undefined index: description
  and Notice: Undefined index: picture"

which I am unable to solve it.
Below are my php code:

```<code>      <div class="col-md-4 col-md-offset-1">
           <div id="content">
               <table><?php
                $servername = "localhost";
                $username = "root";
                $password = "";
                $dbname = "sentosa_resort";

                $conn = new mysqli($servername, $username, $password,
               $dbname);
               // Check connection
               if ($conn->connect_error) {
                   die("Connection failed: " . $conn->connect_error);
               }

                $query = "SELECT title,description,picture FROM activites";
                $result = $conn->query($sql);;

                 // start a table tag in the HTML

                while($row=mysqli_fetch_array($result)){
                    $title = $row['title'];
                    $description = $row['description'];
                   $picture = $row['picture'];
                    echo "<tr>";
                    echo "<td>" . $title . "</td>";
                    echo "<td>" . $description . "</td>";
                     echo "<td>" . $picture . "</td>";
                    echo "</tr>";
                }
                ?></table>
                </div>
          </div>
</code>```

答:
There is error in your code and that is:

```<code> $query = "SELECT title,description,picture FROM activites";
 $result = $conn->query($sql);; // here is error
</code>```

Please do change change the above error line similar to below:

```<code>$result = $conn->query($query);
</code>```

Solution: Changed $sql to $query because your query string is stored in $query variable not $sql and removed extra semicolon

Title: PHP undefined index database issues

Body:
I am having issues with displaying the database table. My database table (activities) have the following value, ID (Primary Key), type, title, description and picture. I am trying to retrieve and display title,description and picture in a table format but is facing an  error

"Notice: Undefined index: title, Notice: Undefined index: description
  and Notice: Undefined index: picture"

which I am unable to solve it.
Below are my php code:

<?php
                $servername = "localhost";
                $username = "root";
                $password = "";
                $dbname = "sentosa_resort";

                $conn = new mysqli($servername, $username, $password,
               $dbname);
               // Check connection
               if ($conn->connect_error) {
                   die("Connection failed: " . $conn->connect_error);
               }

                $query = "SELECT title,description,picture FROM activites";
                $result = $conn->query($sql);;

                 // start a table tag in the HTML

                while($row=mysqli_fetch_array($result)){
                    $title = $row['title'];
                    $description = $row['description'];
                   $picture = $row['picture'];
                    echo "
";
                    echo "" . $title . "	";
                    echo "" . $description . "	";
                     echo "" . $picture . "	";
                    echo "
";
                }
                ?>

Body:
There is error in your code and that is:

 $query = "SELECT title,description,picture FROM activites";
 $result = $conn->query($sql);; // here is error

Please do change change the above error line similar to below:

$result = $conn->query($query);

Solution: Changed $sql to $query because your query string is stored in $query variable not $sql and removed extra semicolon


问:
Template implementation segmentation error;
Everything was working before I introduced templates to my code
EDIT:
Here is the problem to which I was able to narrow it down, thanks to your tips:

In file included from main.cpp:4:
stack.cpp: In member function void Stack<TYPE>::push(Stack<TYPE>&, TYPE)':
stack.cpp:35: error:node' is not a type

I wonder if a similar problem could appear later in the pop function, but it seems like it does not.

I'm confused as to why it seems to insist that node is not a type.

EDIT#2:
this statement in the main.cpp file is now causing trouble. I have moved all the definitions out of stack.cpp to stack.h. After this Stack<int> list;my compiles says Segmentation fault (core dumped).

stack.h:

```<code>#include <iostream>

using namespace std;

template <typename TYPE>
struct node {
    TYPE data;
    node<Type> *next;
    node(){
        data = NULL;
        next = NULL;
    }
    ~node(){
        if (data!=0)
            delete next;
    }
    explicit node(int i){
        data = i;
    }
};
template <typename TYPE>
class Stack {
private:
    node<TYPE> *top;
    void init();
public:
    Stack(); // default constructor
    virtual ~Stack(); // destructor
    bool empty();
    void push(Stack&,TYPE);
    TYPE pop(Stack&);
    int peek();
    void clear();
    ostream& printf(ostream&, node<TYPE> *);
    ostream& print(ostream&);
    ostream& sequentialPrint(Stack&,ostream&);
    ostream& reversePrint(Stack&,ostream&);
    friend ostream& operator<<(ostream&, Stack&);

};
</code>```

stack.cpp:

```<code>template <typename TYPE>
void Stack<TYPE>::push(Stack<TYPE> &s, TYPE i) {
    node<TYPE> * n = new node(i);
    n->next = top;
    top = n;
}
template <typename TYPE>
TYPE Stack<TYPE>::pop(Stack<TYPE> &s){
    if (empty()) {
        cerr<<"Stack is empty \n";
    }
    TYPE temp = s.top->data;
    top = top->next;
    return temp;
}
</code>```

答:
friend ostream& operator<<(ostream&, Stack&); is not needed

you can't define template methods in cpp file. Every element of template which is template parameter depended must be defined in header file.

Body:
Everything was working before I introduced templates to my code
EDIT:
Here is the problem to which I was able to narrow it down, thanks to your tips:

In file included from main.cpp:4:
stack.cpp: In member function void Stack<TYPE>::push(Stack<TYPE>&, TYPE)':
stack.cpp:35: error:node' is not a type

I wonder if a similar problem could appear later in the pop function, but it seems like it does not.

I'm confused as to why it seems to insist that node is not a type.

EDIT#2:
this statement in the main.cpp file is now causing trouble. I have moved all the definitions out of stack.cpp to stack.h. After this Stack<int> list;my compiles says Segmentation fault (core dumped).

stack.h:

#include <iostream>

using namespace std;

template <typename TYPE>
struct node {
    TYPE data;
    node<Type> *next;
    node(){
        data = NULL;
        next = NULL;
    }
    ~node(){
        if (data!=0)
            delete next;
    }
    explicit node(int i){
        data = i;
    }
};
template <typename TYPE>
class Stack {
private:
    node<TYPE> *top;
    void init();
public:
    Stack(); // default constructor
    virtual ~Stack(); // destructor
    bool empty();
    void push(Stack&,TYPE);
    TYPE pop(Stack&);
    int peek();
    void clear();
    ostream& printf(ostream&, node<TYPE> *);
    ostream& print(ostream&);
    ostream& sequentialPrint(Stack&,ostream&);
    ostream& reversePrint(Stack&,ostream&);
    friend ostream& operator<<(ostream&, Stack&);

};

stack.cpp:

template <typename TYPE>
void Stack<TYPE>::push(Stack<TYPE> &s, TYPE i) {
    node<TYPE> * n = new node(i);
    n->next = top;
    top = n;
}
template <typename TYPE>
TYPE Stack<TYPE>::pop(Stack<TYPE> &s){
    if (empty()) {
        cerr<<"Stack is empty \n";
    }
    TYPE temp = s.top->data;
    top = top->next;
    return temp;
}


问:
Why parameters pass wrong registry Windows
I registred protocol in registry Windows

REGEDIT4

```<code>[HKEY_CLASSES_ROOT\vnc]
@="URL:VNC Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\vnc\shell]

[HKEY_CLASSES_ROOT\vnc\shell\open]

[HKEY_CLASSES_ROOT\vnc\shell\open\command]
@="\"C:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe" "%1"
</code>```

Then. I try to run

But programm run not correct

Instead of addresses, it adds the word vnc. How can I remove this word?

答:
The reason it doesn't work is because VNCViewer doesn't understand "vnc:192.168.4.107" as a valid argument.

You need to create a custom handler which removes the vnc: and passes the rest of the string to the executable.

Thankfully, someone already did this on the UltraVNC forums:

```<code>ECHO OFF
SET S=%1
SET S=###%S%###
SET S=%S:"###=%
SET S=%S:###"=%
SET S=%S:###=%
SET S=%S:vnc:=%
start "VNCViewer" "C:\Program Files\UltraVNC\vncviewer.exe" -connect %S%
</code>```

Body:
I registred protocol in registry Windows

REGEDIT4

[HKEY_CLASSES_ROOT\vnc]
@="URL:VNC Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\vnc\shell]

[HKEY_CLASSES_ROOT\vnc\shell\open]

[HKEY_CLASSES_ROOT\vnc\shell\open\command]
@="\"C:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe" "%1"

Then. I try to run

But programm run not correct

Instead of addresses, it adds the word vnc. How can I remove this word?

Body:
The reason it doesn't work is because VNCViewer doesn't understand "vnc:192.168.4.107" as a valid argument.

You need to create a custom handler which removes the vnc: and passes the rest of the string to the executable.

Thankfully, someone already did this on the UltraVNC forums:

ECHO OFF
SET S=%1
SET S=###%S%###
SET S=%S:"###=%
SET S=%S:###"=%
SET S=%S:###=%
SET S=%S:vnc:=%
start "VNCViewer" "C:\Program Files\UltraVNC\vncviewer.exe" -connect %S%


问:
Vim / vi Survival Guide
What are the essential vim commands?  What does a new-user need to know to keep themselves from getting into trouble?  One command per comment, please.</p>

答:
Sometimes it's nice to reformat a buffer (i.e. re-tab, align braces, etc). I recently learned a time saver for this:

```<code>gg=G
</code>```

For example... it would turn the following:

```<code>if ( !flag )
{
  // Do something special
  }
else
   {
 // Do another special thing
}
</code>```

into the following:

```<code>if ( !flag )
{
    // Do something special
}
else
{
    // Do another special thing
}
</code>```

Or if you had an xml file that you're hoping to re-indent because the format is all screwy you could run the above command and turn something like the following:

```<code><root>
<addressBook>
    <contact first="Frank" last="Tank"/>
        <contact first="Foo" last="Man"/>
    </addressBook>
</root>
</code>```

into something a bit more human readable like the following:

```<code><root>
    <addressBook>
        <contact first="Frank" last="Tank"/>
        <contact first="Foo" last="Man"/>
    </addressBook>
</root>
</code>```

OwnerDisplayName: tsellon

Title: Vim / vi Survival Guide

LastEditorDisplayName: scraimer

Body:
Sometimes it's nice to reformat a buffer (i.e. re-tab, align braces, etc). I recently learned a time saver for this:

gg=G

For example... it would turn the following:

if ( !flag )
{
  // Do something special
  }
else
   {
 // Do another special thing
}

into the following:

if ( !flag )
{
    // Do something special
}
else
{
    // Do another special thing
}

Or if you had an xml file that you're hoping to re-indent because the format is all screwy you could run the above command and turn something like the following:

<root>
<addressBook>
    <contact first="Frank" last="Tank"/>
        <contact first="Foo" last="Man"/>
    </addressBook>
</root>

into something a bit more human readable like the following:

<root>
    <addressBook>
        <contact first="Frank" last="Tank"/>
        <contact first="Foo" last="Man"/>
    </addressBook>
</root>


答:
This css should help: </p>

```<code>object {
   pointer-events: none;
}
</code>```

Title: jQuery click event on DIV containing an <object>

Body:
I have made a couple custom SVG buttons that self-contain CSS code for aesthetic changes on :hover as shown in the code snippet example.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="0.506945in" height="0.1125in" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
viewBox="0 0 4494 997"
 xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs>

 </defs>
 <g id="butWrap">
   <rect id="butBox" x="31" y="31" width="4433" height="936"/>
   <g id="butTxt">
    <path class="fil1" d="M373 626l-18 0 0 -238 -82 0 0 -16 183 0 0 16 -83 0 0 238zm138 -111l0 111 -17 0 0 -254 60 0c32,0 55,5 70,17 15,12 23,29 23,53 0,17 -5,31 -14,43 -9,12 -22,20 -41,25l69 116 -21 0 -66 -111 -63 0zm0 -15l49 0c21,0 38,-5 50,-15 12,-9 18,-23 18,-42 0,-19 -6,-34 -18,-42 -11,-9 -30,-14 -57,-14l-42 0 0 113zm317 36l-103 0 -36 90 -20 0 103 -255 11 0 100 255 -20 0 -35 -90zm-97 -16l91 0 -35 -91c-3,-8 -6,-18 -10,-30 -3,11 -7,21 -10,30l-36 91zm382 -24c0,43 -12,75 -34,97 -22,22 -55,33 -99,33l-61 0 0 -254 69 0c41,0 72,10 93,31 21,22 32,53 32,93zm-20 1c0,-36 -9,-64 -28,-82 -18,-19 -45,-28 -81,-28l-47 0 0 223 42 0c76,0 114,-37 114,-113zm217 129l-139 0 0 -254 139 0 0 16 -121 0 0 96 114 0 0 17 -114 0 0 109 121 0 0 16zm364 -127c0,40 -10,72 -30,95 -20,24 -48,36 -84,36 -35,0 -63,-12 -83,-36 -20,-23 -30,-55 -30,-96 0,-40 10,-72 30,-95 21,-24 48,-35 84,-35 35,0 63,11 83,35 20,23 30,55 30,96zm-208 0c0,36 8,64 24,84 17,20 40,30 70,30 31,0 54,-10 71,-30 16,-19 24,-48 24,-84 0,-37 -8,-65 -24,-85 -17,-19 -40,-29 -70,-29 -31,0 -54,10 -70,29 -17,20 -25,48 -25,85zm452 127l-18 0 -151 -226 -1 0c1,27 2,47 2,61l0 165 -17 0 0 -254 17 0 151 225 1 0c-1,-21 -2,-41 -2,-59l0 -166 18 0 0 254z"/>
     <path class="fil1" d="M3464 372l0 16 -88 0 0 238 -18 0 0 -238 -128 0 0 238 -15 0 -179 -233 0 233 -16 0 -6 0 -12 -29 0 0 -32 -72 0 0 -8 -18 -10 -22 0 0 -43 -99 -105 240 -20 0 115 -254 22 0 99 217 0 -217 24 0 169 222 0 -222c84,0 167,0 251,0l0 0z"/>
     <path class="fil1" d="M2518 609c43,-3 62,-22 62,-58 0,-29 -17,-44 -52,-44l-52 0c-48,0 -71,-22 -71,-64 0,-41 25,-64 75,-70 14,-2 21,-1 34,-1 100,0 198,0 297,0l0 16 -87 0 0 238 -19 0 0 -238c-64,0 -127,0 -191,1 -11,0 -21,0 -33,1 -38,5 -57,22 -57,53 0,31 17,46 52,46l52 0c47,0 70,21 70,62 0,42 -32,74 -70,75l0 0 -156 0 -16 0 0 -17 0 -216 -179 233 -15 0c0,-85 0,-170 0,-254l17 0c0,74 0,148 0,222l170 -222 23 0 0 237 146 0 0 0z"/>
     <rect class="fil2" x="2094" y="372" width="16.8761" height="254.244"/>
     <path class="fil1" d="M3504 377l0 -10 0 -6 7 0 90 0c43,0 76,11 98,32 20,19 30,47 32,83 -21,-69 -52,-98 -133,-99 -25,0 -56,0 -94,0l0 0z"/>
     <path class="fil1" d="M3500 630l0 -143 30 0 0 121 64 0c34,0 59,-9 75,-27 17,-19 25,-47 25,-85 0,-33 -8,-58 -25,-74 -16,-16 -41,-24 -75,-24l-31 0 -33 0 -30 0 0 -13c37,0 68,0 93,0 80,2 112,30 133,99 1,4 1,8 1,12 0,47 -12,81 -34,105 -22,23 -55,35 -99,35l-88 0 -6 0 0 -6 0 0z"/>
     <path class="fil1" d="M4214 621l0 14c-56,2 -92,-29 -109,-70 -2,-4 -4,-8 -5,-13 -1,5 -3,9 -4,13 -17,41 -54,72 -110,70l0 -28c44,1 71,-22 84,-53 6,-13 9,-29 9,-44 1,-15 -2,-31 -7,-45 -12,-36 -41,-66 -86,-68l0 -14c49,3 87,30 108,96 7,20 9,41 15,62 18,53 51,84 105,80l0 0 0 0z"/>
     <path class="fil1" d="M4222 390c-45,2 -75,32 -87,69 -5,14 -7,30 -7,45 0,15 4,30 9,43 13,32 41,55 84,54l0 14c-54,3 -87,-27 -105,-80 -6,-21 -9,-42 -15,-63 -21,-65 -59,-93 -108,-96l-1 14 2 -28c58,3 96,41 111,88l2 5 2 -5c15,-47 53,-85 112,-88l1 28 0 0zm-113 160c-1,-1 -1,-2 -2,-4l0 0c1,2 1,3 2,4zm-116 79l0 -28 0 0 0 28zm4 -28c41,-1 68,-23 80,-54l1 0c1,-3 2,-6 3,-9 2,-6 3,-12 4,-18 0,-2 1,-4 1,-5 0,-4 0,-7 0,-11 0,-5 0,-11 0,-17 0,6 0,12 0,17 0,4 0,7 0,11 0,1 -1,3 -1,5 -1,6 -2,12 -4,18 -1,3 -2,6 -3,9l-1 0c-12,31 -39,53 -80,54zm88 -116c0,-1 0,-2 0,-3 0,1 0,2 0,3zm-11 -39c-2,-4 -4,-8 -6,-12 2,4 4,8 6,12zm-10 -17c0,-1 -1,-2 -1,-2 0,0 1,1 1,2z"/>
     <path class="fil1" d="M3765 591c0,40 29,46 56,45l126 -3 0 -10c-53,0 -98,0 -135,-1 -1,0 -1,-1 -2,-1 -32,-2 -45,-33 -45,-75l0 45z"/>
     <path class="fil1" d="M3951 613l0 -10 -125 -3c-12,0 -26,0 -26,-19l0 -72 134 -3 0 -22 -134 -3 0 -73c0,-9 0,-20 21,-20l130 -1 0 -21 -130 -5c-27,-1 -51,12 -51,47l0 129c0,42 13,73 45,75 0,0 1,0 2,0 37,2 82,2 134,1l0 0z"/>
   </g>
 </g>
</svg>

They work flawlessly as in, when I add them to my website and hover over, the aesthetic transformations trigger successfully, but when I try to tie an click event it just won't work. This is the HTML I use:

<object type="image/svg+xml" data="img/button.svg"></object>

I suspect this is related with the way I compose the HTML side, embedding an object (and not the usual img tag) within a div. I tried different things such as in-line HTML onclick and jQuery triggers, and the close I've got to making it work was with a simple:

$(".button").click(function() {
    alert('This button has been clicked.');
});

But somehow looks like the object eclipses the div since if I click on the sides of the button (still inside the div area) it triggers the alert(), but it does nothing at all if I click over the button (over the object area) itself.

I was not aware that an object could behave this way, could someone explain why this happens, if perhaps what I am doing is considered bad practice, and if there is any workaround?

Thanks.

Body:
This css should help:

object {
   pointer-events: none;
}


问:
ncl: /lib/x86_64-linux-gnu/libssl.so.10: version `libssl.so.10' not found (required by ncl)
This is in reference to running the WRF model in my system. I am trying to run the file plotgrids.ncl to ensure that the domain is in the right location before running geogrid.exe . Running the following command in my terminal(ubuntu)
ncl util/plotgrids.ncl
gives me the following error:

ncl: /lib/x86_64-linux-gnu/libssl.so.10: version 'libssl.so.10' not found (required by ncl)
ncl: /lib/x86_64-linux-gnu/libcrypto.so.10: version 'libcrypto.so.10' not found (required by ncl)

答:
at one NCL 6.4.0 installation at Ubuntu 10.10 the solution was
searching a compat-openssl10 package, as
compat-openssl10-1.0.2j-9.fc26.x86_64.rpm
turn it into a .deb package by doing this steps:

```<code>apt-get install libdpkg-perl
alien compat-openssl10-1.0.2j-9.fc26.x86_64.rpm
dpkg -i compat-openssl10_1.0.2j-10_amd64.deb

find / -name libssl.so.*
</code>```

will now show it at /usr/lib/ libssl.so.10

NCL will still complain about GLIBC version
at this case that was solved by editing

```<code>vi /etc/apt/sources.list
:%s/maverick/wily/g

apt-get update
apt-get install libc6
</code>```

this still shows as 2.15 with

```<code>ldd --version
</code>```

however now the test works with

```<code>ng4ex xy01n -clean
</code>```

Body:
at one NCL 6.4.0 installation at Ubuntu 10.10 the solution was
searching a compat-openssl10 package, as
compat-openssl10-1.0.2j-9.fc26.x86_64.rpm
turn it into a .deb package by doing this steps:

apt-get install libdpkg-perl
alien compat-openssl10-1.0.2j-9.fc26.x86_64.rpm
dpkg -i compat-openssl10_1.0.2j-10_amd64.deb

find / -name libssl.so.*

will now show it at /usr/lib/ libssl.so.10

NCL will still complain about GLIBC version
at this case that was solved by editing

vi /etc/apt/sources.list
:%s/maverick/wily/g

apt-get update
apt-get install libc6

this still shows as 2.15 with

ldd --version

however now the test works with

ng4ex xy01n -clean


问:
Is this a thread-safe implementation of Singleton?
I read the Wikipeida's Singleton introduction, and wrote this Singleton class. Could there be any thread safety issue?

```<code> public class Engine {

    private static volatile Engine instance = null;
    private final Pipeline pipeline;

    private Engine() {
        pipeline = createEngine(SystemProperties.LANGUAGE);

    }

    public static Engine getInstance() {
        if (instance == null) {
            synchronized (Engine.class) {
                if (instance == null) {
                    instance = new Engine();
                }
            }
        }
        return instance;
    }

    private Pipeline createEngine(Constants.Language langauge) {
        Pipeline pipeline;
        if (langauge == Constants.Language.Chinese) {
            Properties props = IOUtils.readProperties("properties/chinese.properties");
            pipeline = new Pipeline(props);
        } else if (langauge == Constants.Language.English) {
            Properties props = IOUtils.readProperties("properties/english.properties");
            pipeline = new Pipeline(props);
        } else {
            throw new IllegalStateException("Unknow langauge not supported!");
        }
        return pipeline;
    }
}
</code>```

Client code to use it:

```<code>    private List<String> segment(String str) {

            Engine ENGINE = Engine.getInstance();
            List<String> tokens = new ArrayList<>();
             ...
            try {
                ENGINE.annotate(tokens);
            }catch(Exception e){
                log.warn("can't annotate this sentence:" + str);
            }
            ...

            return tokens;
        }
</code>```

答:
YES.
Globally :
The easier way to create a thread-safe singleton class is to make the global access method synchronized
Only one thread can execute this method at a time.
It reduces the performance because of cost associated with the synchronized method .
To avoid this extra overhead every time, double checked locking principle is used.
In this approach, the synchronized block is used inside the if condition(how you do it) with an additional check to ensure that only one instance of singleton class is created.
Also please note that the singleton can be destroyed via reflection. To avoid this problem Joshua Bloch suggests the use of Enum to implement Singleton design pattern. As Java ensures that any enum value is instantiated only once in a Java program .

```<code>public enum EnumSingleton {

INSTANCE;

public static void doSomething(){
    //do something
}
</code>```

}

Just suggestion to understand fully the singleton pattern with all   it will be better to read it in GO4 book or o'reilly headfirst design patterns also Joshua Bloch Effective Java 2nd edition . There is a chapter about singleton .

Body:
I read the Wikipeida's Singleton introduction, and wrote this Singleton class. Could there be any thread safety issue?

 public class Engine {

    private static volatile Engine instance = null;
    private final Pipeline pipeline;

    private Engine() {
        pipeline = createEngine(SystemProperties.LANGUAGE);

    }

    public static Engine getInstance() {
        if (instance == null) {
            synchronized (Engine.class) {
                if (instance == null) {
                    instance = new Engine();
                }
            }
        }
        return instance;
    }

    private Pipeline createEngine(Constants.Language langauge) {
        Pipeline pipeline;
        if (langauge == Constants.Language.Chinese) {
            Properties props = IOUtils.readProperties("properties/chinese.properties");
            pipeline = new Pipeline(props);
        } else if (langauge == Constants.Language.English) {
            Properties props = IOUtils.readProperties("properties/english.properties");
            pipeline = new Pipeline(props);
        } else {
            throw new IllegalStateException("Unknow langauge not supported!");
        }
        return pipeline;
    }
}

Client code to use it:

    private List<String> segment(String str) {

            Engine ENGINE = Engine.getInstance();
            List<String> tokens = new ArrayList<>();
             ...
            try {
                ENGINE.annotate(tokens);
            }catch(Exception e){
                log.warn("can't annotate this sentence:" + str);
            }
            ...

            return tokens;
        }

Body:
YES.
Globally :
The easier way to create a thread-safe singleton class is to make the global access method synchronized
Only one thread can execute this method at a time.
It reduces the performance because of cost associated with the synchronized method .
To avoid this extra overhead every time, double checked locking principle is used.
In this approach, the synchronized block is used inside the if condition(how you do it) with an additional check to ensure that only one instance of singleton class is created.
Also please note that the singleton can be destroyed via reflection. To avoid this problem Joshua Bloch suggests the use of Enum to implement Singleton design pattern. As Java ensures that any enum value is instantiated only once in a Java program .

public enum EnumSingleton {

INSTANCE;

public static void doSomething(){
    //do something
}

}

Just suggestion to understand fully the singleton pattern with all   it will be better to read it in GO4 book or o'reilly headfirst design patterns also Joshua Bloch Effective Java 2nd edition . There is a chapter about singleton .


问:
List containing lists (matrix) as input() with python 3
I'm trying to convert a given input to a list containing lists as shown in the command-line code below:

```<code>matrix = input('asking')
asking[[2, 0, 4],[1, 2, 4],[4, 4, 2]]
matrix
'[[2, 0, 4],[1, 2, 4],[4, 4, 2]]'
</code>```

desired output:

```<code>[[2,0,4],[1,2,4],[4,4,2]]
</code>```

Attempts

```<code>list(matrix)
['[', '[', '2', ',', ' ', '0', ',', ' ', '4', ']', ',', ' ', '[', '1', ',', ' ', '2', ',', ' ', '4', ']', ',', ' ', '[', '4', ',', ' ', '4', ',', ' ', '2', ']', ']']

x = [int(a) for a in matrix]
builtins.TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

matrix.split(',')
['[[2', '0', '4]', '[1', '2', '4]', '[4', '4', '2]]']
</code>```

Code:

```<code>fin_result = 0

def perform_check():
    print("Enter form \n [[a,b,c] \n [d,e,f] \n [g,h,i]]")
    #ask_for_input = [[4,-1,1],[4,5,3],[-2,0,0]]
    ask_for_input = [[2,0,4],[1,2,4],[4,4,2]]
    print(type(ask_for_input))

    #call function to cont
    calculate_determinate_matrix(ask_for_input)

def calculate_determinate_matrix(matrix3x3):
    matrix_list2x2 = []

    matrix_list2x2.append([[matrix3x3[1][1], matrix3x3[1][2]], [matrix3x3[2][1], matrix3x3[2][2]]])

    matrix_list2x2.append([[matrix3x3[1][0], matrix3x3[1][2]],[matrix3x3[2][0], matrix3x3[2][2]]])

    matrix_list2x2.append([[matrix3x3[1][0], matrix3x3[1][1]],[matrix3x3[2][0], matrix3x3[2][1]]])

    count = 0
    for count, matrix_2x2 in enumerate(matrix_list2x2):
        if count % 2 == 1:
            calculate_2x2_matrix(matrix_2x2, matrix3x3[0][count] * -1)
        else:
            calculate_2x2_matrix(matrix_2x2, matrix3x3[0][count])

def calculate_2x2_matrix(matrix, mult):
    global fin_result
    result = matrix[0][0] * matrix[1][1]
    result_2 = matrix[0][1] * matrix[1][0]
    fin_result += mult * (result - result_2)

def main():
    perform_check()
    print(fin_result)

if __name__ == "__main__":
    main()
</code>```

Clearly this code needs work, but I can't figure this in terms of list comprehension.

答:
An alternative to json.loads is ast.literal_eval. It has the advantage that it recognizes Python syntax even if it was invalid JSON, like single-quoted strings. In your exact case, it doesn't make a difference:

```<code>import ast
matrix = '[[2, 0, 4],[1, 2, 4],[4, 4, 2]]'
matrix = ast.literal_eval(matrix)
</code>```

Body:
I'm trying to convert a given input to a list containing lists as shown in the command-line code below:

matrix = input('asking')
asking[[2, 0, 4],[1, 2, 4],[4, 4, 2]]
matrix
'[[2, 0, 4],[1, 2, 4],[4, 4, 2]]'

desired output:

[[2,0,4],[1,2,4],[4,4,2]]

Attempts

list(matrix)
['[', '[', '2', ',', ' ', '0', ',', ' ', '4', ']', ',', ' ', '[', '1', ',', ' ', '2', ',', ' ', '4', ']', ',', ' ', '[', '4', ',', ' ', '4', ',', ' ', '2', ']', ']']

x = [int(a) for a in matrix]
builtins.TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

matrix.split(',')
['[[2', '0', '4]', '[1', '2', '4]', '[4', '4', '2]]']

Code:

fin_result = 0

def perform_check():
    print("Enter form \n [[a,b,c] \n [d,e,f] \n [g,h,i]]")
    #ask_for_input = [[4,-1,1],[4,5,3],[-2,0,0]]
    ask_for_input = [[2,0,4],[1,2,4],[4,4,2]]
    print(type(ask_for_input))

    #call function to cont
    calculate_determinate_matrix(ask_for_input)

def calculate_determinate_matrix(matrix3x3):
    matrix_list2x2 = []

    matrix_list2x2.append([[matrix3x3[1][1], matrix3x3[1][2]], [matrix3x3[2][1], matrix3x3[2][2]]])

    matrix_list2x2.append([[matrix3x3[1][0], matrix3x3[1][2]],[matrix3x3[2][0], matrix3x3[2][2]]])

    matrix_list2x2.append([[matrix3x3[1][0], matrix3x3[1][1]],[matrix3x3[2][0], matrix3x3[2][1]]])

    count = 0
    for count, matrix_2x2 in enumerate(matrix_list2x2):
        if count % 2 == 1:
            calculate_2x2_matrix(matrix_2x2, matrix3x3[0][count] * -1)
        else:
            calculate_2x2_matrix(matrix_2x2, matrix3x3[0][count])

def calculate_2x2_matrix(matrix, mult):
    global fin_result
    result = matrix[0][0] * matrix[1][1]
    result_2 = matrix[0][1] * matrix[1][0]
    fin_result += mult * (result - result_2)

def main():
    perform_check()
    print(fin_result)

if __name__ == "__main__":
    main()

Clearly this code needs work, but I can't figure this in terms of list comprehension.

Body:
An alternative to json.loads is ast.literal_eval. It has the advantage that it recognizes Python syntax even if it was invalid JSON, like single-quoted strings. In your exact case, it doesn't make a difference:

import ast
matrix = '[[2, 0, 4],[1, 2, 4],[4, 4, 2]]'
matrix = ast.literal_eval(matrix)


问:
JavaFX 2 Creating a Custom Pane
I have seen several custom JavaFX control tutorials around, but no tutorials on how to create a custom pane layout. I ask because I am trying to create a flowing two-sided (think form-like (name,value) pairs) layout pane with titles. I have previously done the control in WPF, and am "migrating" it to JavaFX. Are there any places I could look for learning how to make a custom layout pane aside from the OpenJDK sources?

To clarify: I an looking for how to create a custom pane layout manager and not custom controls

答:
I hope the TableView in JavaFX will serve your requirement of creating a form like structure. Ideally you should go for custom layouts only when no existing layouts serve your purpose. Here is the link to learn more about creating custom layouts:
https://docs.oracle.com/javase/tutorial/uiswing/layout/custom.html</p>

Title: JavaFX 2 Creating a Custom Pane


问:
Xamarin Forms on iOS left margin issue on ListViews
I have an existing Xamarin Forms iOS app, that I want to rebuild in order to fix some issues. I update my Visual Studio for Mac and updates my NuGet packages. The Xamarin.Forms package is upgraded to version 2.4.0.74863. I compile the app, and everything works, except that ListViews gets an extra margin on the left side. The yellow area indicates this.

The same Android Xamarin Forms app does not have this extra margin.

Is this a known Xamarin Forms/iOS issue? And is there a workaround to solve this issue?

答:
Seems like an issue with Xamarin.Forms for iOS introduced in Xamarin.Forms version 2.4.0.74863

It is an issue only on iOS 11.

See https://bugzilla.xamarin.com/show_bug.cgi?id=60636


问:
OpenNETCF: is it free to use?
I downloaded all the OpenNETCF dlls. Is it free? Or will it stop working after a year?</p>

答: If you are talking about the CodePlex project, it is open source. I have not looked at the license, but it will not magically stop working.</p>

Title: OpenNETCF: is it free to use?


问:
How I can get formated string from List array in Java?
Sorry, I'm beginner in Java. I work with Spring and Hibernate and I have problem. In Internet I can't find solution.

My Controller:

```<code>List<User> theModerators = userDAO.findAllModerators();

theModel.addAttribute("moderators", theModerators); return "moderators";
</code>```

moderators.jsp:

```<code><c:forEach items="${moderators}" var="m">
     <div>${m.firstName}</div>
     <c:forEach items="${m.companies}" var="company">
         <div>${company.compName}</div>
     </c:forEach>
</c:forEach>
</code>```

I have problem with with company.compName. I want to get formated string with commas (ex: I got "MicrosoftApple", but I want - "Microsoft, Apple").

I know about join, for ex:

```<code>String allCompanies = String.join(", ", userCompanies);
</code>```

But I can't add allCompanies string  to theModerators, or create new array like theModerators but with allCompanies string.

I have worked with PHP/Laravel, and there I used joins into collections.

But in Java I can't do it.

答:
The following should work

```<code><c:forEach items="${moderators}" var="m">
     <div>${m.firstName}</div>
      <div>
     <c:forEach items="${m.companies}" var="company" varStatus="item">
         ${company.compName}
         <c:if test="${!item.last}">,</c:if>
     </c:forEach>
    </div>
</c:forEach>
</code>```

I have made use of varStatus to avoid the last comma

Body:
Sorry, I'm beginner in Java. I work with Spring and Hibernate and I have problem. In Internet I can't find solution.

My Controller:

List<User> theModerators = userDAO.findAllModerators();

theModel.addAttribute("moderators", theModerators); return "moderators";

moderators.jsp:

<c:forEach items="${moderators}" var="m">

${m.firstName}

     <c:forEach items="${m.companies}" var="company">

${company.compName}

     </c:forEach>
</c:forEach>

I have problem with with company.compName. I want to get formated string with commas (ex: I got "MicrosoftApple", but I want - "Microsoft, Apple").

I know about join, for ex:

String allCompanies = String.join(", ", userCompanies);

But I can't add allCompanies string  to theModerators, or create new array like theModerators but with allCompanies string.

I have worked with PHP/Laravel, and there I used joins into collections.

But in Java I can't do it.

Body:
The following should work

<c:forEach items="${moderators}" var="m">
     <div>${m.firstName}</div>
      <div>
     <c:forEach items="${m.companies}" var="company" varStatus="item">
         ${company.compName}
         <c:if test="${!item.last}">,</c:if>
     </c:forEach>
    </div>
</c:forEach>

I have made use of varStatus to avoid the last comma


问:
How can i keep my web receiving mysql data
first of all.. sorry for my english, i'll try my best!

I have a web application where i show info about Data stored in my Mysql. I Would like to make it more dynamic and if some new information appear in my DB then update my web content without a refresh. I was thinking about Ajax. Every minute send an ajax function asking for some new data... but it's not a good idea 'cause it can be stressing for my server.

What's the best way to do it?

Thanks a lot for your time!

答:
You could use something like Firebase which automatically pushes data to the client when changes occur in the backend database, but that means that you would have to store all your data in Firebase instead of in your Mysql database.

Apart from a service like that, one option is to use an ajax call to fetch new data, but only when new data is available. I don't know how your data is structured, or what kind of data it is, but one solution to minimize the load on your server is to have a database table with a timestamp column that's updated every time relevant data is changed, added or deleted in your database. Use ajax to fetch only this timestamp every minute and if the timestamp has changed since you last checked it, make another ajax call to fetch the actual data.


问:
Splitting XML file into multiple files based on labels using python
I have a large xml file that contains the details of image annotations.  A sample of the same is as follows:

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
        <tag name="Perimeter-Vivon" color="#032585"/>
    </tags>
    <images>
        <image file="/var/www/html/beacon.com/resources/videos/ST2_20170812/ST_2_20170812-0005.jpg">
            <box top="253" left="166" width="56" height="24">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="255" left="229" width="61" height="21">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="290" width="58" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="361" width="56" height="20">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="417" width="63" height="22">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="486" width="63" height="20">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="504" left="329" width="51" height="29">
                <label>ScoreBoard-Vivon</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

I want this file to be split based on their tag names.  This file has two tags viz - ScoreBoard and Perimeter.  I want to create two different xmls out of this for each tag.  The desired output would be as follows:

for ScoreBoard-Vivon.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
    </tags>
    <images>
        <image file="/var/www/html/beacon.com/resources/videos/ST2_20170812/ST_2_20170812-0005.jpg">
            <box top="504" left="329" width="51" height="29">
                <label>ScoreBoard-Vivon</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

For Perimeter-Vivon.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-Vivon" color="#032585"/>
    </tags>
    <images>
        <image file="/var/www/html/beacon.com/resources/videos/ST2_20170812/ST_2_20170812-0005.jpg">
            <box top="253" left="166" width="56" height="24">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="255" left="229" width="61" height="21">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="290" width="58" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="361" width="56" height="20">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="417" width="63" height="22">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="486" width="63" height="20">
                <label>Perimeter-Vivon</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

I have 350-400 such tags.  How can I split them into individual files.

New Example:

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-SVT" color="#f9e99c"/>
        <tag name="Perimeter-Vivon" color="#032585"/>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
        <tag name="Perimeter-StarSports" color="#12dadd"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0011.jpg">
            <box top="505" left="327" width="56" height="29">
                <label>ScoreBoard-Vivon</label>
            </box>
            <box top="218" left="387" width="67" height="24">
                <label>Perimeter-SVT</label>
            </box>
        </image>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0005.jpg">
            <box top="254" left="159" width="64" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="255" left="225" width="61" height="20">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="285" width="63" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="253" left="357" width="58" height="24">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="424" width="56" height="25">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="256" left="484" width="65" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="507" left="326" width="58" height="26">
                <label>ScoreBoard-Vivon</label>
            </box>
        </image>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0009.jpg">
            <box top="249" left="400" width="59" height="29">
                <label>Perimeter-StarSports</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

答:
The following (XSLT 2.0) stylesheet:

```<code><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:template match="//dataset/tags">
      <xsl:for-each select="./tag">
            <xsl:variable name="tagName" select="@name" />

                <xsl:result-document method="xml" href="{$tagName}.xml">
                    <dataset>
                        <xsl:copy-of select="/dataset/name"/>
                        <xsl:copy-of select="/dataset/comment"/>
                        <tags>
                            <xsl:copy-of select="/dataset/tags/tag[./@name = $tagName]"/>
                        </tags>
                        <images>
                        <xsl:for-each select="/dataset/images/image[./box/label/text() = $tagName]">
                            <image>
                                <xsl:copy-of select="./@file"/>
                                <xsl:copy-of select="./box[./label[./text() = $tagName]]"/>
                            </image>
                        </xsl:for-each>
                        </images>
                    </dataset>
                </xsl:result-document>

      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
</code>```

When applied to your input produces the following results:

Perimeter-SVT.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-SVT" color="#f9e99c"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0011.jpg">
            <box top="218" left="387" width="67" height="24">
                <label>Perimeter-SVT</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

Perimeter-Vivon.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-Vivon" color="#032585"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0005.jpg">
            <box top="254" left="159" width="64" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="255" left="225" width="61" height="20">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="285" width="63" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="253" left="357" width="58" height="24">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="424" width="56" height="25">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="256" left="484" width="65" height="23">
                <label>Perimeter-Vivon</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

ScoreBoard-Vivon.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0011.jpg">
            <box top="505" left="327" width="56" height="29">
                <label>ScoreBoard-Vivon</label>
            </box>
        </image>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0005.jpg">
            <box top="507" left="326" width="58" height="26">
                <label>ScoreBoard-Vivon</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

Perimeter-StarSports.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-StarSports" color="#12dadd"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0009.jpg">
            <box top="249" left="400" width="59" height="29">
                <label>Perimeter-StarSports</label>
            </box>
        </image>
    </images>
</dataset>
</code>```

Body:
I have a large xml file that contains the details of image annotations.  A sample of the same is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
        <tag name="Perimeter-Vivon" color="#032585"/>
    </tags>
    <images>
        <image file="/var/www/html/beacon.com/resources/videos/ST2_20170812/ST_2_20170812-0005.jpg">
            <box top="253" left="166" width="56" height="24">
                Perimeter-Vivon
            </box>
            <box top="255" left="229" width="61" height="21">
                Perimeter-Vivon
            </box>
            <box top="254" left="290" width="58" height="23">
                Perimeter-Vivon
            </box>
            <box top="254" left="361" width="56" height="20">
                Perimeter-Vivon
            </box>
            <box top="254" left="417" width="63" height="22">
                Perimeter-Vivon
            </box>
            <box top="254" left="486" width="63" height="20">
                Perimeter-Vivon
            </box>
            <box top="504" left="329" width="51" height="29">
                ScoreBoard-Vivon
            </box>
        </image>
    </images>
</dataset>

I want this file to be split based on their tag names.  This file has two tags viz - ScoreBoard and Perimeter.  I want to create two different xmls out of this for each tag.  The desired output would be as follows:

for ScoreBoard-Vivon.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
    </tags>
    <images>
        <image file="/var/www/html/beacon.com/resources/videos/ST2_20170812/ST_2_20170812-0005.jpg">
            <box top="504" left="329" width="51" height="29">
                ScoreBoard-Vivon
            </box>
        </image>
    </images>
</dataset>

For Perimeter-Vivon.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-Vivon" color="#032585"/>
    </tags>
    <images>
        <image file="/var/www/html/beacon.com/resources/videos/ST2_20170812/ST_2_20170812-0005.jpg">
            <box top="253" left="166" width="56" height="24">
                Perimeter-Vivon
            </box>
            <box top="255" left="229" width="61" height="21">
                Perimeter-Vivon
            </box>
            <box top="254" left="290" width="58" height="23">
                Perimeter-Vivon
            </box>
            <box top="254" left="361" width="56" height="20">
                Perimeter-Vivon
            </box>
            <box top="254" left="417" width="63" height="22">
                Perimeter-Vivon
            </box>
            <box top="254" left="486" width="63" height="20">
                Perimeter-Vivon
            </box>
        </image>
    </images>
</dataset>

I have 350-400 such tags.  How can I split them into individual files.

New Example:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-SVT" color="#f9e99c"/>
        <tag name="Perimeter-Vivon" color="#032585"/>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
        <tag name="Perimeter-StarSports" color="#12dadd"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0011.jpg">
            <box top="505" left="327" width="56" height="29">
                ScoreBoard-Vivon
            </box>
            <box top="218" left="387" width="67" height="24">
                Perimeter-SVT
            </box>
        </image>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0005.jpg">
            <box top="254" left="159" width="64" height="23">
                Perimeter-Vivon
            </box>
            <box top="255" left="225" width="61" height="20">
                Perimeter-Vivon
            </box>
            <box top="254" left="285" width="63" height="23">
                Perimeter-Vivon
            </box>
            <box top="253" left="357" width="58" height="24">
                Perimeter-Vivon
            </box>
            <box top="254" left="424" width="56" height="25">
                Perimeter-Vivon
            </box>
            <box top="256" left="484" width="65" height="23">
                Perimeter-Vivon
            </box>
            <box top="507" left="326" width="58" height="26">
                ScoreBoard-Vivon
            </box>
        </image>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0009.jpg">
            <box top="249" left="400" width="59" height="29">
                Perimeter-StarSports
            </box>
        </image>
    </images>
</dataset>

Body:
The following (XSLT 2.0) stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:template match="//dataset/tags">
      <xsl:for-each select="./tag">
            <xsl:variable name="tagName" select="@name" />

                <xsl:result-document method="xml" href="{$tagName}.xml">
                    <dataset>
                        <xsl:copy-of select="/dataset/name"/>
                        <xsl:copy-of select="/dataset/comment"/>
                        <tags>
                            <xsl:copy-of select="/dataset/tags/tag[./@name = $tagName]"/>
                        </tags>
                        <images>
                        <xsl:for-each select="/dataset/images/image[./box/label/text() = $tagName]">
                            <image>
                                <xsl:copy-of select="./@file"/>
                                <xsl:copy-of select="./box[./label[./text() = $tagName]]"/>
                            </image>
                        </xsl:for-each>
                        </images>
                    </dataset>
                </xsl:result-document>

      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

When applied to your input produces the following results:

Perimeter-SVT.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-SVT" color="#f9e99c"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0011.jpg">
            <box top="218" left="387" width="67" height="24">
                <label>Perimeter-SVT</label>
            </box>
        </image>
    </images>
</dataset>

Perimeter-Vivon.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-Vivon" color="#032585"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0005.jpg">
            <box top="254" left="159" width="64" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="255" left="225" width="61" height="20">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="285" width="63" height="23">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="253" left="357" width="58" height="24">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="254" left="424" width="56" height="25">
                <label>Perimeter-Vivon</label>
            </box>
            <box top="256" left="484" width="65" height="23">
                <label>Perimeter-Vivon</label>
            </box>
        </image>
    </images>
</dataset>

ScoreBoard-Vivon.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="ScoreBoard-Vivon" color="#bf5786"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0011.jpg">
            <box top="505" left="327" width="56" height="29">
                <label>ScoreBoard-Vivon</label>
            </box>
        </image>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0005.jpg">
            <box top="507" left="326" width="58" height="26">
                <label>ScoreBoard-Vivon</label>
            </box>
        </image>
    </images>
</dataset>

Perimeter-StarSports.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name>dataset containing bounding box labels on images</name>
    <comment>created by BBTag</comment>
    <tags>
        <tag name="Perimeter-StarSports" color="#12dadd"/>
    </tags>
    <images>
        <image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0009.jpg">
            <box top="249" left="400" width="59" height="29">
                <label>Perimeter-StarSports</label>
            </box>
        </image>
    </images>
</dataset>


问:
What is the typecast of an element created with componentsSeparatedByString?
I need to extract some info from a number of strings in infoArray. The layout for each element in infoArray looks like @"NO,YES,YES,YES,YES,NO,NO,YES", etc.

When I use the following:

```<code>[splitArray setArray:[[infoArray objectAtIndex: i] componentsSeparatedByString:@","]];
</code>```

I can access whatever I need in the new splitArray with something like:

```<code>NSLog(@"Result = %@", [infoArray objectAtIndex: 0]);
</code>```

and in this case it will print out correctly. The problem is when I need to use it next for conditions:

```<code>if([infoArray objectAtIndex: 0] == @"YES"){
    //do something
}
</code>```

The above code obviously doesn't work even if the value was "YES".  I believe the typecast is wrong.  I'm a bit of a newbie.  Any suggestions?

答:
You should modify your question with the additional data instead of answering your own question.

To answer your question, use:

```<code>[[splitArray objectAtIndex: 0] isEqualToString:@"YES"]
</code>```

Body:
I need to extract some info from a number of strings in infoArray. The layout for each element in infoArray looks like @"NO,YES,YES,YES,YES,NO,NO,YES", etc.

When I use the following:

[splitArray setArray:[[infoArray objectAtIndex: i] componentsSeparatedByString:@","]];

I can access whatever I need in the new splitArray with something like:

NSLog(@"Result = %@", [infoArray objectAtIndex: 0]);

and in this case it will print out correctly. The problem is when I need to use it next for conditions:

if([infoArray objectAtIndex: 0] == @"YES"){
    //do something
}

The above code obviously doesn't work even if the value was "YES".  I believe the typecast is wrong.  I'm a bit of a newbie.  Any suggestions?

Body:
You should modify your question with the additional data instead of answering your own question.

To answer your question, use:

[[splitArray objectAtIndex: 0] isEqualToString:@"YES"]


问:
MongoDB: How to search array consist nothing outside of specific values?
Let's say that I have a set of data below:

```<code>{_id: "something", array: ["a", "b", "c", "d"]},  // 1
{_id: "something", array: ["a", "b", "d"]},  // 2
{_id: "something", array: ["b", "c", "d"]},  // 3
{_id: "something", array: ["a", "d"]},  // 4
{_id: "something", array: ["a", "b"]},  // 5
{_id: "something", array: ["d"]},  // 6
{_id: "something", array: ["c"]},  // 7
{_id: "something", array: []},  // 8
{_id: "something"},  // 9
{_id: "something", array: ["a", "b", "c", "d", "e", "f", etc...]},  // 10
</code>```

I want to find the documents that have the array consist nothing outside of "a" and "d" in the array. So the wanted output should be 4th, 6th, 8th and 9th from the data. How should I write the query?

Both $in and $nin could not get what I want (as using $nin will require me to input too much possibilities in the query).

Another note, I am using MongoDB v3.2 with Mongoose.

Addon note after receiving answers:

- P.S. In this example, "a" and "d" is just example of 2 exclusion. However in actual implementation, it is a value inserted choosed by user. So it does not limit to 2 exclusion, which could later be "b", "c" and "d", or even more values base on user input.

答:
The following will work:</p>

```<code>db.examples.aggregate({
    $addFields: { // add a new field that holds...
        diff: { // ...all array values that are outside your allowed values
            $setDifference: [ "$array", [ "a", "d" ] ]
        }
    }
}, {
    $match: { // and use the newly added field to filter the result set
        $or: [ { diff: null }, { diff: [] } ]
    }
})
</code>```

Body:
Let's say that I have a set of data below:

{_id: "something", array: ["a", "b", "c", "d"]},  // 1
{_id: "something", array: ["a", "b", "d"]},  // 2
{_id: "something", array: ["b", "c", "d"]},  // 3
{_id: "something", array: ["a", "d"]},  // 4
{_id: "something", array: ["a", "b"]},  // 5
{_id: "something", array: ["d"]},  // 6
{_id: "something", array: ["c"]},  // 7
{_id: "something", array: []},  // 8
{_id: "something"},  // 9
{_id: "something", array: ["a", "b", "c", "d", "e", "f", etc...]},  // 10

I want to find the documents that have the array consist nothing outside of "a" and "d" in the array. So the wanted output should be 4th, 6th, 8th and 9th from the data. How should I write the query?

Both $in and $nin could not get what I want (as using $nin will require me to input too much possibilities in the query).

Another note, I am using MongoDB v3.2 with Mongoose.

Addon note after receiving answers:

- P.S. In this example, "a" and "d" is just example of 2 exclusion. However in actual implementation, it is a value inserted choosed by user. So it does not limit to 2 exclusion, which could later be "b", "c" and "d", or even more values base on user input.

Body:
The following will work:

db.examples.aggregate({
    $addFields: { // add a new field that holds...
        diff: { // ...all array values that are outside your allowed values
            $setDifference: [ "$array", [ "a", "d" ] ]
        }
    }
}, {
    $match: { // and use the newly added field to filter the result set
        $or: [ { diff: null }, { diff: [] } ]
    }
})


问:
Unable to view form page in Codeigniter
Unable to view form page in Codeigniter, When I try to open.

form.php
This is my view file in Codeigniter. I am newbie in Codeigniter, I am unable to solve this problem.

```<code><!DOCTYPE html>
<html>
<head>

<link href="<?php echo base_url().'assets/bootstrap.min.css'; ?>" rel="stylesheet" type='text/css'>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <style>
 .error{color:red}
 </style>
</head>
<body>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">

<h1>Student Registraion</h1>

<?php
echo form_open();
  echo form_label('First Name');
  $data=[
  'name'=>'fname',
  'class'=>'form-control',
  'id'=>'fname',
  'value'=>isset($dta['fname'])?$dta['fname']:''
  ];
  echo form_input($data);
  echo form_error('fname');

  echo form_label('Last Name');
  $data=[
  'name'=>'lname',
  'class'=>'form-control',
  'id'=>'lname',
  'value'=>isset($dta['lname'])?$dta['lname']:''
  ];
  echo form_input($data);
  echo form_error('email');
   echo form_label('Email');

  $data=[
  'name'=>'email',
  'class'=>'form-control',
  'id'=>'email',
  'value'=>isset($dta['email'])?$dta['email']:''
  ];

  echo form_input($data);

  echo form_label('Mobile Number');

  $data=[
  'name'=>'mobile',
  'class'=>'form-control',
  'id'=>'mobile',
  'value'=>isset($dta['mobile'])?$dta['mobile']:''
  ];

  echo form_input($data);
   echo form_error('mobile');
    echo form_label('Message');
  $data=[
  'name'=>'message',
  'class'=>'form-control',
  'id'=>'message',
  'value'=>isset($dta['message'])?$dta['message']:''
  ];
  echo form_textarea($data).br(1);
  echo form_submit('submit','submit','class="btn btn-success"');
  echo form_close();
?>
</div>
<div class="col-md-3"></div>
</div>

</body>
</html>
</code>```

home.php

Unable to view form page in Codeigniter, When I try to open.

When I open my insert form It gives me error, I have attached error screenshot.

```<code><?php

class home extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->model('select');
        $this->load->helper(array('form','url','html'));
        $this->load->library(array('form_validation','session'));

    }

   function records()
   {

       $ytl['dta']=$this->users->datas();
       //$this->load->view('info',$ytl);
       //echo "```controller";print_r($ytl);
   }
   function primezone()
   {

           $ytl['dta']=$this->users->datas();
            echo "```controller";print_r($ytl);
   }

    function form($id)
    {
    //die($id);
    if($this->input->post())
    {
        //echo"```";print_r( $this->input->post());die;
        $this->form_validation->set_rules('fname','First Name','required|min_length[5]');
        $this->form_validation->set_rules('lname','Last Name','required|callback_check_picture[lname]');

        //$this->form_validation->set_rules('email','Email','required');

        $this->form_validation->set_rules('mobile','Mobile Number','required|callback_valid_phone_number[mobile]');

        $this->form_validation->set_error_delimiters('
', '
');
        if($this->form_validation->run()==True)
        {
        $data=[
        'fname'=>$this->input->post('fname'),
        'lname'=>$this->input->post('lname'),
        'email'=>$this->input->post('email'),
        'mobile'=>$this->input->post('mobile'),
        'message'=>$this->input->post('message'),
        ];
        $ytl=$this->select->insertdata($data);
        if($ytl)
        {
            $this->session->set_flashdata('message', 'Successfully Added.');
     redirect('home');
        }
        }else
        {
                //$this->load->view('form');
        }

    }
    $ytl['dta']=$this->select->getDataById($id);
    //echo "```";print_r($ytl);die;
    $this->load->view('form',$ytl);

}
public function check_picture($a){
   if(!is_numeric($a))
   {
       return true;
   }else{
     $this->form_validation->set_message('check_picture', 'Please enter only char value');
     return False;
}
}

function valid_phone_number($value)
{
    $value = strlen($value);
    //echo $value;die;
    if ($value == 10) {
        return true;
    }
    else
    {
        $this->form_validation->set_message('valid_phone_number', 'Mobile number not in range'); //{10}
    return false;
    }
}

    public function index()

     {
         //load the database
         //$this->load->database();
         //load the model
         $this->load->model('select');
         //load the method of model
         $data['h']=$this->select->select();
         //return the data in view
         $this->load->view('fetch_view', $data);
      }

}

?>
</code>```

select.php

This is my model. Unable to view form page in Codeigniter, When I try to open.

```<code><?php

class select extends CI_model

{
    function __construct()
      {
         // Call the Model constructor
         parent::__construct();
     $this->load->database();
      }

    function datas()
    {
        $pzi=[
        'name'=>'pratibha',
        'email'=>'pratibha@gmail.com',
        'mobile'=>998858585,
        'address'=>'noida'

        ];

        return $pzi;
    }

    function insertdata($data)
    {
        $this->load->database();
        return $this->db->insert('student',
        $data);
    }

    public function select()
      {
         //data is retrive from this query

         $query = $this->db->get('student');
         return $query;
      }

    function getDataById($id)
    {
        $this->db->select('*');
        $this->db->where('id',$id);
        $this->db->from('student');
      $query = $this->db->get()->row_array();
         return $query;
    }
}

?>
</code>```

答:
If you're updating a record, you'd need to pass in an ID for that record. Then if the ID exists you can update, otherwise you insert as you are currently doing.

So in your controller:

```<code>$data=[
        'id'=>!empty($this->input->post('id')) ? $this->input->post('id') : null,
        'fname'=>$this->input->post('fname'),
        'lname'=>$this->input->post('lname'),
        'email'=>$this->input->post('email'),
        'mobile'=>$this->input->post('mobile'),
        'message'=>$this->input->post('message'),
        ];
</code>```

And in your model:

```<code>function insertdata($data)
    {
        if(!empty($data['id'])) {
            $this->db->where('id', $data['id'])->update('student',$data);
            return $data['id'];
        } else {
            unset($data['id']);
            $this->db->insert('student',  $data);
            return $this->db->insert_id();
        }
    }
</code>```

This assumes your table has a column called id. Change if required...

Title: Unable to view form page in Codeigniter

Body:
Unable to view form page in Codeigniter, When I try to open.

form.php
This is my view file in Codeigniter. I am newbie in Codeigniter, I am unable to solve this problem.

<!DOCTYPE html>

<link href="<?php echo base_url().'assets/bootstrap.min.css'; ?>" rel="stylesheet" type='text/css'>

Student Registraion

<?php
echo form_open();
  echo form_label('First Name');
  $data=[
  'name'=>'fname',
  'class'=>'form-control',
  'id'=>'fname',
  'value'=>isset($dta['fname'])?$dta['fname']:''
  ];
  echo form_input($data);
  echo form_error('fname');

  echo form_label('Last Name');
  $data=[
  'name'=>'lname',
  'class'=>'form-control',
  'id'=>'lname',
  'value'=>isset($dta['lname'])?$dta['lname']:''
  ];
  echo form_input($data);
  echo form_error('email');
   echo form_label('Email');

  $data=[
  'name'=>'email',
  'class'=>'form-control',
  'id'=>'email',
  'value'=>isset($dta['email'])?$dta['email']:''
  ];

  echo form_input($data);

  echo form_label('Mobile Number');

  $data=[
  'name'=>'mobile',
  'class'=>'form-control',
  'id'=>'mobile',
  'value'=>isset($dta['mobile'])?$dta['mobile']:''
  ];

  echo form_input($data);
   echo form_error('mobile');
    echo form_label('Message');
  $data=[
  'name'=>'message',
  'class'=>'form-control',
  'id'=>'message',
  'value'=>isset($dta['message'])?$dta['message']:''
  ];
  echo form_textarea($data).br(1);
  echo form_submit('submit','submit','class="btn btn-success"');
  echo form_close();
?>

home.php

Unable to view form page in Codeigniter, When I try to open.

When I open my insert form It gives me error, I have attached error screenshot.

<?php

class home extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->model('select');
        $this->load->helper(array('form','url','html'));
        $this->load->library(array('form_validation','session'));

    }

   function records()
   {

       $ytl['dta']=$this->users->datas();
       //$this->load->view('info',$ytl);
       //echo "
controller";print_r($ytl);
   }
   function primezone()
   {

           $ytl['dta']=$this->users->datas();
            echo "
controller";print_r($ytl);
   }

    function form($id)
    {
    //die($id);
    if($this->input->post())
    {
        //echo"
";print_r( $this->input->post());die;
        $this->form_validation->set_rules('fname','First Name','required|min_length[5]');
        $this->form_validation->set_rules('lname','Last Name','required|callback_check_picture[lname]');

        //$this->form_validation->set_rules('email','Email','required');

        $this->form_validation->set_rules('mobile','Mobile Number','required|callback_valid_phone_number[mobile]');

        $this->form_validation->set_error_delimiters('
', '
');
        if($this->form_validation->run()==True)
        {
        $data=[
        'fname'=>$this->input->post('fname'),
        'lname'=>$this->input->post('lname'),
        'email'=>$this->input->post('email'),
        'mobile'=>$this->input->post('mobile'),
        'message'=>$this->input->post('message'),
        ];
        $ytl=$this->select->insertdata($data);
        if($ytl)
        {
            $this->session->set_flashdata('message', 'Successfully Added.');
     redirect('home');
        }
        }else
        {
                //$this->load->view('form');
        }

    }
    $ytl['dta']=$this->select->getDataById($id);
    //echo "
";print_r($ytl);die;
    $this->load->view('form',$ytl);

}
public function check_picture($a){
   if(!is_numeric($a))
   {
       return true;
   }else{
     $this->form_validation->set_message('check_picture', 'Please enter only char value');
     return False;
}
}

function valid_phone_number($value)
{
    $value = strlen($value);
    //echo $value;die;
    if ($value == 10) {
        return true;
    }
    else
    {
        $this->form_validation->set_message('valid_phone_number', 'Mobile number not in range'); //{10}
    return false;
    }
}

    public function index()

     {
         //load the database
         //$this->load->database();
         //load the model
         $this->load->model('select');
         //load the method of model
         $data['h']=$this->select->select();
         //return the data in view
         $this->load->view('fetch_view', $data);
      }

}

?>

select.php

This is my model. Unable to view form page in Codeigniter, When I try to open.

<?php

class select extends CI_model

{
    function __construct()
      {
         // Call the Model constructor
         parent::__construct();
     $this->load->database();
      }

    function datas()
    {
        $pzi=[
        'name'=>'pratibha',
        'email'=>'pratibha@gmail.com',
        'mobile'=>998858585,
        'address'=>'noida'

        ];

        return $pzi;
    }

    function insertdata($data)
    {
        $this->load->database();
        return $this->db->insert('student',
        $data);
    }

    public function select()
      {
         //data is retrive from this query

         $query = $this->db->get('student');
         return $query;
      }

    function getDataById($id)
    {
        $this->db->select('*');
        $this->db->where('id',$id);
        $this->db->from('student');
      $query = $this->db->get()->row_array();
         return $query;
    }
}

?>

Body:
If you're updating a record, you'd need to pass in an ID for that record. Then if the ID exists you can update, otherwise you insert as you are currently doing.

So in your controller:

$data=[
        'id'=>!empty($this->input->post('id')) ? $this->input->post('id') : null,
        'fname'=>$this->input->post('fname'),
        'lname'=>$this->input->post('lname'),
        'email'=>$this->input->post('email'),
        'mobile'=>$this->input->post('mobile'),
        'message'=>$this->input->post('message'),
        ];

And in your model:

function insertdata($data)
    {
        if(!empty($data['id'])) {
            $this->db->where('id', $data['id'])->update('student',$data);
            return $data['id'];
        } else {
            unset($data['id']);
            $this->db->insert('student',  $data);
            return $this->db->insert_id();
        }
    }

This assumes your table has a column called id. Change if required...