问:
wxWidgets Drop Files eventhandler initialization problem (invalid static_cast)
I am trying to make a simple program to drop files on a list using C++ with a (wxWidgets) wxListCtrl.

Tools I use: Code::Blocks 20.03, MinGW 17.1, wxWidgets 3.1.3, wxFormBuilder 3.9.0.

OS: Windows 10 Pro.

I tried the following: (in a function SetupGUI() which is called in the DnD_SimpleFrame class constructor.)

```<code>m_listCtrl1 = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_HEADER|wxLC_REPORT );
m_listCtrl1->DragAcceptFiles(true);
m_listCtrl1->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(DnD_SimpleFrame::OnDropFiles), NULL, this);
</code>```

The function to be called on dropping the files (from explorer) is:

```<code>bool DnD_SimpleFrame::OnDropFiles(wxArrayString &filenames)
{
    size_t nFiles = filenames.GetCount();
    wxString str;
    str.Printf( "%d files dropped", (int)nFiles);

    m_listCtrl1->DeleteAllItems();
    if (m_listCtrl1 != NULL)
    {
        m_listCtrl1->InsertItem(0, str);
        for ( size_t n = 1; n < (nFiles+1); n++ )
            m_listCtrl1->InsertItem(n, filenames[n]);
    }
    return true;
}
</code>```

The build messages on the m_listCtrl1->Connect(...); line are:

```<code>||=== Build: Debug in DnD_Simple (compiler: GNU GCC Compiler) ===|
F:\Data\__C++\wxApps\DnD_Simple\DnD_SimpleMain.cpp||In member function 'void DnD_SimpleFrame::SetupGUI()':|
F:\SDKs\wx313\include\wx\event.h|149|error: invalid static_cast from type 'bool (DnD_SimpleFrame::*)(wxArrayString&)' to type 'wxDropFilesEventFunction' {aka 'void (wxEvtHandler::*)(wxDropFilesEvent&)'}|
F:\SDKs\wx313\include\wx\event.h|4196|note: in expansion of macro 'wxEVENT_HANDLER_CAST'|
F:\Data\__C++\wxApps\DnD_Simple\DnD_SimpleMain.cpp|92|note: in expansion of macro 'wxDropFilesEventHandler'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
</code>```

What am I doing wrong here (or am forgetting)?

答:
If you carefully look at the error message:

```<code>error: invalid static_cast from type 'bool (DnD_SimpleFrame::*)(wxArrayString&)' to type 'wxDropFilesEventFunction' {aka 'void (wxEvtHandler::*)(wxDropFilesEvent&)'}
</code>```

you can see that it says that it can't convert something from one type to the other one.

The types may be difficult to parse if you're new to C++, but you should be able to see that these are function pointers (in fact, pointers to a class member). And looking at your code, you should also be able to see that the first is them is the type of your DnD_SimpleFrame::OnDropFiles function and hence the problem is that it can't be converted to the expected function type.

Finally, the reason for this is just that your function doesn't have the right parameter type: you're supposed to give wxWidgets something taking wxDropFilesEvent&, but your function takes wxArrayString& instead. You will have to change it to take wxDropFilesEvent& event and then use GetFiles() method of the event object to get the actual files.

On a completely different topic, you should use Bind() and not Connect() in the new code. If you're following a tutorial which uses the latter, it's a good sign that it's very outdated. Your code still wouldn't have compiled with Bind(), but the error messages would have been slightly simpler.

Body:
I am trying to make a simple program to drop files on a list using C++ with a (wxWidgets) wxListCtrl.

Tools I use: Code::Blocks 20.03, MinGW 17.1, wxWidgets 3.1.3, wxFormBuilder 3.9.0.

OS: Windows 10 Pro.

I tried the following: (in a function SetupGUI() which is called in the DnD_SimpleFrame class constructor.)

m_listCtrl1 = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_HEADER|wxLC_REPORT );
m_listCtrl1->DragAcceptFiles(true);
m_listCtrl1->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(DnD_SimpleFrame::OnDropFiles), NULL, this);

The function to be called on dropping the files (from explorer) is:

bool DnD_SimpleFrame::OnDropFiles(wxArrayString &filenames)
{
    size_t nFiles = filenames.GetCount();
    wxString str;
    str.Printf( "%d files dropped", (int)nFiles);

    m_listCtrl1->DeleteAllItems();
    if (m_listCtrl1 != NULL)
    {
        m_listCtrl1->InsertItem(0, str);
        for ( size_t n = 1; n < (nFiles+1); n++ )
            m_listCtrl1->InsertItem(n, filenames[n]);
    }
    return true;
}

The build messages on the m_listCtrl1->Connect(...); line are:

||=== Build: Debug in DnD_Simple (compiler: GNU GCC Compiler) ===|
F:\Data\__C++\wxApps\DnD_Simple\DnD_SimpleMain.cpp||In member function 'void DnD_SimpleFrame::SetupGUI()':|
F:\SDKs\wx313\include\wx\event.h|149|error: invalid static_cast from type 'bool (DnD_SimpleFrame::*)(wxArrayString&)' to type 'wxDropFilesEventFunction' {aka 'void (wxEvtHandler::*)(wxDropFilesEvent&)'}|
F:\SDKs\wx313\include\wx\event.h|4196|note: in expansion of macro 'wxEVENT_HANDLER_CAST'|
F:\Data\__C++\wxApps\DnD_Simple\DnD_SimpleMain.cpp|92|note: in expansion of macro 'wxDropFilesEventHandler'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

What am I doing wrong here (or am forgetting)?

Body:
If you carefully look at the error message:

error: invalid static_cast from type 'bool (DnD_SimpleFrame::*)(wxArrayString&)' to type 'wxDropFilesEventFunction' {aka 'void (wxEvtHandler::*)(wxDropFilesEvent&)'}

you can see that it says that it can't convert something from one type to the other one.

The types may be difficult to parse if you're new to C++, but you should be able to see that these are function pointers (in fact, pointers to a class member). And looking at your code, you should also be able to see that the first is them is the type of your DnD_SimpleFrame::OnDropFiles function and hence the problem is that it can't be converted to the expected function type.

Finally, the reason for this is just that your function doesn't have the right parameter type: you're supposed to give wxWidgets something taking wxDropFilesEvent&, but your function takes wxArrayString& instead. You will have to change it to take wxDropFilesEvent& event and then use GetFiles() method of the event object to get the actual files.

On a completely different topic, you should use Bind() and not Connect() in the new code. If you're following a tutorial which uses the latter, it's a good sign that it's very outdated. Your code still wouldn't have compiled with Bind(), but the error messages would have been slightly simpler.


来源: stackexchange

问:
Push rejected, failed to compile Python app error Discord.py
When I try to push my I get this error:

```<code>C:\Users\emirs\PycharmProjects\discordmasterbot>git push heroku master
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote:        Collecting git+https://github.com/Rapptz/discord.py@rewrite (from -r
/tmp/build_9aeec3d177cff34ed7cd7b5bc8e84eca/requirements.txt (line 1))
remote:          Cloning https://github.com/Rapptz/discord.py (to revision rewrite) to /tmp/pip-req-build-pexa63lg
build-pexa63lg
remote:          Running command git clone -q https://github.com/Rapptz/discord.py /tmp/pip-req-
build-pexa63lg
remote:          WARNING: Did not find branch or tag 'rewrite', assuming revision or ref.
remote:          Running command git checkout -q rewrite
remote:          error: pathspec 'rewrite' did not match any file(s) known to git.
remote:        ERROR: Command errored out with exit status 1: git checkout -q rewrite Check the logs
for full command output.
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to discordmasterbot.
remote:
To https://git.heroku.com/discordmasterbot.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/discordmasterbot.git'
</code>```

And my requirements.txt is like that:

```<code>discord.py==1.3.3
PyNaCl==1.3.0
pandas
dnspython==1.16.0
async-timeout==3.0.1
</code>```

And my programs "import" section:

```<code>import json
import os
import random
import shutil
from os import system
from random import randint
import praw
import discord
import youtube_dl
from discord.ext import commands, tasks
from discord.utils import get
import aiohttp
from itertools import cycle
</code>```

I really want to host my bot in Heroku, but I can't! I think that It might be a problem with the requirements.txt and so thats why I've put my whole import section

答:
git+https://github.com/Rapptz/discord.py@rewrite no longer exists, as rewrite is now the master branch and the async version (0.16.x) has been deprecated.

You can just replace that line in requirements.txt with discord.py==1.3.3 (most recent version at the time of this answer) or remove @rewrite from the end.

ContentLicense: CC BY-SA 4.0

Body:
When I try to push my I get this error:

C:\Users\emirs\PycharmProjects\discordmasterbot>git push heroku master
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote:        Collecting git+https://github.com/Rapptz/discord.py@rewrite (from -r
/tmp/build_9aeec3d177cff34ed7cd7b5bc8e84eca/requirements.txt (line 1))
remote:          Cloning https://github.com/Rapptz/discord.py (to revision rewrite) to /tmp/pip-req-build-pexa63lg
build-pexa63lg
remote:          Running command git clone -q https://github.com/Rapptz/discord.py /tmp/pip-req-
build-pexa63lg
remote:          WARNING: Did not find branch or tag 'rewrite', assuming revision or ref.
remote:          Running command git checkout -q rewrite
remote:          error: pathspec 'rewrite' did not match any file(s) known to git.
remote:        ERROR: Command errored out with exit status 1: git checkout -q rewrite Check the logs
for full command output.
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to discordmasterbot.
remote:
To https://git.heroku.com/discordmasterbot.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/discordmasterbot.git'

And my requirements.txt is like that:

discord.py==1.3.3
PyNaCl==1.3.0
pandas
dnspython==1.16.0
async-timeout==3.0.1

And my programs "import" section:

import json
import os
import random
import shutil
from os import system
from random import randint
import praw
import discord
import youtube_dl
from discord.ext import commands, tasks
from discord.utils import get
import aiohttp
from itertools import cycle

I really want to host my bot in Heroku, but I can't! I think that It might be a problem with the requirements.txt and so thats why I've put my whole import section


问:
No implementation found for void com.organization.app.Activity.a() in Release
What I'm trying to do is simply invoke a native function from my Java android activity that is implemented in my C++ codebase. The signature can be anything, but let's define it as void fooBar().

My workspace is organized in a tree structure of gradle projects, all of them "com.android.library" projects except for the app which is an "com.android.application".
All of the projects contain some form of C++ code, and a few of them contain Java classes. The activity class is in the root project ("Core"). The native implementation of the function is in a .cpp file in the same project.

This is the error output from the logcat:

```<code>E/com.organization.app: No implementation found for void com.organization.app.Activity.a() (tried Java_com_organization_app_Activity_a and Java_com_organization_app_Activity_a__)
E/AndroidRuntime: FATAL EXCEPTION: Thread-9
    Process: com.organization.app, PID: 3607
    java.lang.UnsatisfiedLinkError: No implementation found for void com.organization.app.Activity.a() (tried Java_com_organization_app_Activity_a and Java_com_organization_app_Activity_a__)
        at com.organization.app.Activity.a(Native Method)
        at com.organization.app.Activity.onStart(Unknown Source:0)
</code>```

While building for Debug, I can invoke this fooBar() function faultless, but in Release it tries to load the function using a different name. Namely, a(). There's nothing wrong with the function signature on the native end, because if I simply change the function name to Java_com_organization_app_Activity_a, it is invoked successfully.
I have also tried adding more functions, and the new names for those functions became b() and c(), respectively.

It doesn't seem to matter where I invoke the function either, so the fact that it says onStart here is uninteresting.

I tried searching for someone with a similar problem, but all of them were problems with the function signature in C/C++.

答:
I found the solution.

I did some cross-referencing between Debug and Release and found out that either turning off minifyEnabled or removing the proguard file declaration made the exception go away. After that, I looked into the proguard file I was using (which happened to be the default one for optimization) and saw two interesting sections.

```<code># For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}
</code>```

^ This section should have made sure my native functions were not discarded from the binary. Why this happens, I still have no clue.

```<code># Understand the @Keep support annotation.
-keep class android.support.annotation.Keep
</code>```

^ This section gave me the idea to use @Keep to force it to not discard the function. After some testing and making sure, it turns out this was a valid solution.

I will do some further testing to find the root cause of the shrinker not keeping my native functions, but since I found the solution I will mark this as solved. Hope this helps anyone that comes across this in the future.

Body:
What I'm trying to do is simply invoke a native function from my Java android activity that is implemented in my C++ codebase. The signature can be anything, but let's define it as void fooBar().

My workspace is organized in a tree structure of gradle projects, all of them "com.android.library" projects except for the app which is an "com.android.application".
All of the projects contain some form of C++ code, and a few of them contain Java classes. The activity class is in the root project ("Core"). The native implementation of the function is in a .cpp file in the same project.

This is the error output from the logcat:

E/com.organization.app: No implementation found for void com.organization.app.Activity.a() (tried Java_com_organization_app_Activity_a and Java_com_organization_app_Activity_a__)
E/AndroidRuntime: FATAL EXCEPTION: Thread-9
    Process: com.organization.app, PID: 3607
    java.lang.UnsatisfiedLinkError: No implementation found for void com.organization.app.Activity.a() (tried Java_com_organization_app_Activity_a and Java_com_organization_app_Activity_a__)
        at com.organization.app.Activity.a(Native Method)
        at com.organization.app.Activity.onStart(Unknown Source:0)

While building for Debug, I can invoke this fooBar() function faultless, but in Release it tries to load the function using a different name. Namely, a(). There's nothing wrong with the function signature on the native end, because if I simply change the function name to Java_com_organization_app_Activity_a, it is invoked successfully.
I have also tried adding more functions, and the new names for those functions became b() and c(), respectively.

It doesn't seem to matter where I invoke the function either, so the fact that it says onStart here is uninteresting.

I tried searching for someone with a similar problem, but all of them were problems with the function signature in C/C++.

Body:
I found the solution.

I did some cross-referencing between Debug and Release and found out that either turning off minifyEnabled or removing the proguard file declaration made the exception go away. After that, I looked into the proguard file I was using (which happened to be the default one for optimization) and saw two interesting sections.

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

^ This section should have made sure my native functions were not discarded from the binary. Why this happens, I still have no clue.

# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep

^ This section gave me the idea to use @Keep to force it to not discard the function. After some testing and making sure, it turns out this was a valid solution.

I will do some further testing to find the root cause of the shrinker not keeping my native functions, but since I found the solution I will mark this as solved. Hope this helps anyone that comes across this in the future.


问:
How to select all using "__in" in drf on empty list?
For example, if i had to select specific ids I can do this using:
id_list=[1,4,7]

Blog.objects.filter(pk__in=id_list)
```

But the problem is id_list is being populated using filters selected in front end.
so initially id_list will be empty(id_list=[])

so, is there a way to select all the ids using Blog.objects.filter(pk__in=id_list) when id_list is empty?

答:
You can do</p>

```<code>if len(id_list) == 0:
     queryset = Blog.objects.all()
else:
     queryset = Blog.objects.filter(pk__in=id_list)
</code>```

Body:
For example, if i had to select specific ids I can do this using:
id_list=[1,4,7]

Blog.objects.filter(pk__in=id_list)

But the problem is id_list is being populated using filters selected in front end.
so initially id_list will be empty(id_list=[])

so, is there a way to select all the ids using Blog.objects.filter(pk__in=id_list) when id_list is empty?

Body:
You can do

if len(id_list) == 0:
     queryset = Blog.objects.all()
else:
     queryset = Blog.objects.filter(pk__in=id_list)


Title: Is it possible to sort Numpy 2D array like dictionary characters are matching

Body:
I would like to sort them as given below:

First it will check '0th' col & if all values are different, then it will sort by interchanging the rows up & down.

If '0th' column contains same values, then it will place them consecutive rows & sorting depends on the value of 1st col. If further matches, process continues f

As the row index 2 & 3 have the same values in 0, 1, 2 the column. So by checking at 3rd col it decides the position of row for these two rows. Please help. Thanks in advance.
NB: As we compare words in dictionary to search, I also want to compare like that.

Input Array:

[23.339,    0.015,  0.008,  0.0071,     0.079,  0.001]
[20.759,    0.024,  0.020,  0.0161,     0.1282, 0.030]
[17.352,    0.063,  0.024,  0.0187,     0.1484, 0.039]
[17.352,    0.063,  0.024,  0.008,  0.128,  0.035]
[23.339,    0.015,  0.001,  0.204,  1.819,  0.762]
[17.352,    1.645,  1.045,  0.779,  1.106,  0.821]
[14.556,    0.061,  0.058,  0.0071,     0.1016, 0.005]

Output Array:

[14.556,    0.061,  0.058,  0.0071,     0.1016, 0.005]
[**17.352,  0.063,  0.024,**    0.008,  0.128,  0.035]
[**17.352,  0.063,  0.024,**    0.0187,     0.1484, 0.039]
[17.352,    1.645,  1.045,  0.779,  1.106,  0.821]
[20.759,    0.024,  0.020,  0.0161, 0.1282, 0.030]
[**23.339,  0.015,**    0.001,  0.204,  1.819,  0.762]
[**23.339,  0.015,**    0.008,  0.0071, 0.079,  0.001]

Body:
Yes, you can do that like so:

import pandas as pd

x =[[23.339, 0.015, 0.008, 0.0071, 0.079, 0.001],
    [20.759, 0.024, 0.020, 0.0161, 0.1282, 0.030],
    [17.352, 0.063, 0.024, 0.0187, 0.1484, 0.039],
    [17.352, 0.063, 0.024, 0.008, 0.128, 0.035],
    [23.339, 0.015, 0.001, 0.204, 1.819, 0.762],
    [17.352, 1.645, 1.045, 0.779, 1.106, 0.821],
    [14.556, 0.061, 0.058, 0.0071, 0.1016, 0.005]]

df = pd.DataFrame(x)
df.sort_values(by=list(df.keys()), inplace=True)
print(df)
#        0      1      2       3       4      5
#6  14.556  0.061  0.058  0.0071  0.1016  0.005
#3  17.352  0.063  0.024  0.0080  0.1280  0.035
#2  17.352  0.063  0.024  0.0187  0.1484  0.039
#5  17.352  1.645  1.045  0.7790  1.1060  0.821
#1  20.759  0.024  0.020  0.0161  0.1282  0.030
#4  23.339  0.015  0.001  0.2040  1.8190  0.762
#0  23.339  0.015  0.008  0.0071  0.0790  0.001


问:
Transform array of arrays to a single array
I would like to expand a list of arrays into a single array, so for example:

```<code>a = [array([1,2,3]), array([4,5,6]), array([7,8,9,])]
</code>```

To become:

```<code>a = [array([1,2,3,4,5,6,7,8,9])]
</code>```

How do I do this?

答:
You can use reshape of Numpy to do it:-

```<code>a=[[1,2,3],[3,4,5],[6,7,8]]
print("Before:" , a)
import numpy as np
a=np.reshape(a,9)
print("After:",a)
</code>```

The output:

```<code>Before: [[1, 2, 3], [3, 4, 5], [6, 7, 8]]
After: [1 2 3 3 4 5 6 7 8]
</code>```

Hope this is what you want.

Body:
I would like to expand a list of arrays into a single array, so for example:

a = [array([1,2,3]), array([4,5,6]), array([7,8,9,])]

To become:

a = [array([1,2,3,4,5,6,7,8,9])]

How do I do this?

Body:
You can use reshape of Numpy to do it:-

a=[[1,2,3],[3,4,5],[6,7,8]]
print("Before:" , a)
import numpy as np
a=np.reshape(a,9)
print("After:",a)

The output:

Before: [[1, 2, 3], [3, 4, 5], [6, 7, 8]]
After: [1 2 3 3 4 5 6 7 8]

Hope this is what you want.


问:
How Python interact with JVM inside Spark
I am writing Python code to develop some Spark applications. I am really curious how Python interact with running JVM and started reading the source code of Spark.

I can see that in the end, all the Spark transformations/actions ended up be calling certain jvm methods in the following way.

```<code>self._jvm.java.util.ArrayList(),
self._jvm.PythonAccumulatorParam(host, port))
self._jvm.org.apache.spark.util.Utils.getLocalDir(self._jsc.sc().conf())
self._jvm.org.apache.spark.util.Utils.createTempDir(local_dir, "pyspark") \
            .getAbsolutePath()
...
</code>```

As a Python programmer, I am really curious what is going on with this _jvm object. However, I have briefly read all the source code under pyspark and only found _jvm to be an attribute of Context class, beyond that, I know nothing about neither _jvm's attributes nor methods.

Can anyone help me understand how pyspark translate into JVM operations? should I read some scala code and see if _jvm is defined there?

答: It uses py4j. There is a special protocol to translate python calls into JVM calls. All of this you can find in Pyspark code, see java_gateway.py</p>

ContentLicense: CC BY-SA 3.0

Body:
I am writing Python code to develop some Spark applications. I am really curious how Python interact with running JVM and started reading the source code of Spark.

I can see that in the end, all the Spark transformations/actions ended up be calling certain jvm methods in the following way.

self._jvm.java.util.ArrayList(),
self._jvm.PythonAccumulatorParam(host, port))
self._jvm.org.apache.spark.util.Utils.getLocalDir(self._jsc.sc().conf())
self._jvm.org.apache.spark.util.Utils.createTempDir(local_dir, "pyspark") \
            .getAbsolutePath()
...

As a Python programmer, I am really curious what is going on with this _jvm object. However, I have briefly read all the source code under pyspark and only found _jvm to be an attribute of Context class, beyond that, I know nothing about neither _jvm's attributes nor methods.

Can anyone help me understand how pyspark translate into JVM operations? should I read some scala code and see if _jvm is defined there?


问:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'where clause'
Title

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'where clause' (SQL: select * from outcomes where (user_id = 37 and todos.outcome_id = outcomes.id) and outcomes.deleted_at is null)

In my laravel project I want to get the list of all task there corresponding Outcome values but this gives an error

```<code>  public function kanban()
    {
        $outcomes = Outcome::with('todos')
        ->where(function ($query) {
            $query->select(DB::raw(1))
                  ->from('todos')
                  ->where('user_id','=',Auth::user()->id)
                  ->whereRaw('todos.outcome_id = outcomes.id');
        })
        ->get();
        return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
    }
</code>```

Here My Todo model

```<code>
<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Todo extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'todos';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

        'todoable_id',
        'todoable_type',
        'title',
        'description',
        'admin_id',
        'user_id',
        'project_id',
        'priority',
        'outcome_id',
        'tasktype_id',
        'started_at',
        'due_time',
        'completed_at',
    ];
    public function outcome() {

        return $this->belongsTo('App\Outcome');
    }

    public function user() {

        return $this->belongsTo('App\User');
    }

    public function todoable()
    {
        return $this->morphTo();
    }

}
</code>```

Outcome Model

```<code><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Outcome extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'outcomes';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

        'name'

    ];

    public function todos() {

        return $this->hasMany('App\Todo');
    }
}

</code>```

Output I want basically

答:
If my suggestion right, you might get result with something like this:Brakcets are missing in previous so I've edited, Now this one is working what I want actually</p>

```<code>$outcomes = Outcome::with(['todos' => function ($query) {
    $query->where('user_id', Auth::user()->id);
}])->get();
</code>```

Body:
Title

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'where clause' (SQL: select * from outcomes where (user_id = 37 and todos.outcome_id = outcomes.id) and outcomes.deleted_at is null)

In my laravel project I want to get the list of all task there corresponding Outcome values but this gives an error

  public function kanban()
    {
        $outcomes = Outcome::with('todos')
        ->where(function ($query) {
            $query->select(DB::raw(1))
                  ->from('todos')
                  ->where('user_id','=',Auth::user()->id)
                  ->whereRaw('todos.outcome_id = outcomes.id');
        })
        ->get();
        return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
    }

Here My Todo model

<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Todo extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'todos';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

        'todoable_id',
        'todoable_type',
        'title',
        'description',
        'admin_id',
        'user_id',
        'project_id',
        'priority',
        'outcome_id',
        'tasktype_id',
        'started_at',
        'due_time',
        'completed_at',
    ];
    public function outcome() {

        return $this->belongsTo('App\Outcome');
    }

    public function user() {

        return $this->belongsTo('App\User');
    }

    public function todoable()
    {
        return $this->morphTo();
    }

}

Outcome Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Outcome extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'outcomes';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

        'name'

    ];

    public function todos() {

        return $this->hasMany('App\Todo');
    }
}

Output I want basically

Body:
If my suggestion right, you might get result with something like this:Brakcets are missing in previous so I've edited, Now this one is working what I want actually

$outcomes = Outcome::with(['todos' => function ($query) {
    $query->where('user_id', Auth::user()->id);
}])->get();


问:
Fix/avoid/ignore recursive reference error?
I need two class libraries that reference each other.

Why? One is compiled in C# and the other in VB.NET.

It would be better if I could somehow merge the assemblies programmatically, without requiring external programs or even the extended framework.

答:
Compile your assemblies via assembly linker tool into multimodule assembly.
For example:
http://blogs.msdn.com/b/junfeng/archive/2004/07/15/183813.aspx</p>


问:
Transform Entity-object into an Object with framework the MapStruct
I have an entity that gets "userType" during a query to the database.

public class OrderEntityXml {

    @Id
    @SequenceGenerator(name = "jpa.Sequence.t.order", sequenceName = "T_ORDER_SEQ", allocationSize = 1)
    @GeneratedValue(generator = "jpa.Sequence.t.order", strategy = GenerationType.SEQUENCE)
    private Long id;

    private String customer;

    @Type(type = "Order")
    @Column(name = "order_xml")
    private Order order;

    public OrderEntityXml() {
    }
```

<p>There is an container for getting from an entity. </p>

<p>This container is using by Jackson. </p>

<p>This container also is using marshaller and unmarshaller</p>

<pre class="lang-java prettyprint-override"><code>@XmlRootElement
@JacksonXmlRootElement(localName = "order")
public class Order implements Serializable {

    private String customer;

    @XmlElement(name = "orderItem")
    @JacksonXmlProperty(localName = "orderItem")
    @JacksonXmlElementWrapper(useWrapping = false)
    private List<OrderItem> orderItems = new ArrayList<>();

    public Order() {
    }
</code>```

public class OrderItem {

    private String sku;

    private Double price;

    public OrderItem() {
    }
```

<p>I have set up a MapStruct.</p>

<ul>
<li>CycleAvoidingMappingContext - ( This is necessary to avoid Cycling (and the appearance of stack overflow))</li>
</ul>

<pre class="lang-java prettyprint-override"><code>@Component
public class CycleAvoidingMappingContext {

    private Map<Object, Object> knownInstances = new IdentityHashMap<Object, Object>();

    @BeforeMapping
    public <T> T getMappedInstance(Object source, @TargetType Class<T> targetType) {

        T t = (T) knownInstances.get(source);
        return t;
    }

    @BeforeMapping
    public void storeMappedInstance(Object source, @MappingTarget Object target) {
        knownInstances.put( source, target );
    }
}
</code>```

public interface CommonMapper<D, E> {

    D toDto(E e, @Context CycleAvoidingMappingContext context);

    E toEntity(D d, @Context CycleAvoidingMappingContext context);

    Iterable<D> toListDto(Iterable<E> entityList);

    Iterable<E> toListEntity(Iterable<D> dtoList);

}

```

<ul>
<li>MapperUtils - (This is utils for MapStruct)</li>
</ul>

<pre class="lang-java prettyprint-override"><code>
public static Order convertToDto(OrderEntityXml orderEntityXml){
        Order order = new Order();

        String customer = orderEntityXml.getCustomer();
        order.setCustomer(customer);

        Order xmlOrder = orderEntityXml.getOrder();
        List<OrderItem> orderItems = xmlOrder.getOrderItems();
        order.setOrderItems(orderItems);

        return order;
    }

    public static OrderEntityXml convertToEntity(Order order){

        OrderEntityXml orderEntityXml = new OrderEntityXml();
        String customer = order.getCustomer();
        orderEntityXml.setCustomer(customer);

        List<OrderItem> orderItems = order.getOrderItems();

        Order orderInEntity = new Order();

        orderInEntity.setOrderItems(orderItems);
        orderInEntity.setCustomer(customer);

        orderEntityXml.setOrder(orderInEntity);

        return orderEntityXml;
    }
</code>```

OrderDtoMapper - It is basic interface for me, for classes generation

@Mapper(componentModel = "spring")
public interface OrderDtoMapper extends CommonMapper<Order, OrderEntityXml> {

    @Override
    default Order toDto(OrderEntityXml orderEntityXml, CycleAvoidingMappingContext context) {

        return convertToDto(orderEntityXml);
    }

    @Override
    default OrderEntityXml toEntity(Order order, CycleAvoidingMappingContext context) {

        return convertToEntity(order);
    }

    @Override
    default Iterable<Order> toListDto(Iterable<OrderEntityXml> entityList) {

        Iterable<Order> collect = StreamSupport.stream(entityList.spliterator(), false)
            .map(MapperUtils::convertToDto)
            .collect(Collectors.toList());

        return collect;
    }
}
```

For each data type, you will have to make your own utilities, and this is cumbersome.

Сan I remove extra code and configure it via MapStruct interfaces ?
I suspect I've complicated the code.

Сan anyone tell you what needs to be tweaked or what technology can be applied to mapStruct to make the code unified

答:
Looking at the posted entities I don't see why you need to use CycleAvoidingMappingContext. There is no cyclic dependency between your objects.

In order to avoid the manual code you've written you can use the MapStruct @Mapping annotation to customize how certain fields need to be mapped.

So in your case it would be something like:

```<code>@Mapper(componentModel = "spring")
public interface OrderDtoMapper extends CommonMapper<Order, OrderEntityXml> {

    @Override
    @Mapping(target = "orderItems", source = "order.orderItems")
    Order toDto(OrderEntityXml orderEntityXml, @Context CycleAvoidingMappingContext context);

    @Override
    @Mapping(target = "order", source = "order")
    OrderEntityXml toEntity(Order order, CycleAvoidingMappingContext context);

    Order cloneOrder(Order order);
}
</code>```

The only customizations you need are the following:

For toDto to tell MapStruct that when you are mapping from OrderEntityXml to Order you want to map the order.orderItems into the orderItems.

For toEntity to tell MapStruct that you when you are mapping from Order to OrderEntityXml you want to map the method order parameters into the order of the `OrderEntityXml

Additionally we add Order cloneOrder(Order) so that MapStruct creates a new object when mapping between Order otherwise the same object will be used.

The customer in both cases will be automatically mapped, since it matches on both sides.

There is no need to provide custom method for the Iterable mapping because MapStruct will do that automatically for you. It knows

Body:
I have an entity that gets "userType" during a query to the database.

public class OrderEntityXml {

    @Id
    @SequenceGenerator(name = "jpa.Sequence.t.order", sequenceName = "T_ORDER_SEQ", allocationSize = 1)
    @GeneratedValue(generator = "jpa.Sequence.t.order", strategy = GenerationType.SEQUENCE)
    private Long id;

    private String customer;

    @Type(type = "Order")
    @Column(name = "order_xml")
    private Order order;

    public OrderEntityXml() {
    }

There is an container for getting from an entity.

This container is using by Jackson.

This container also is using marshaller and unmarshaller

@XmlRootElement
@JacksonXmlRootElement(localName = "order")
public class Order implements Serializable {

    private String customer;

    @XmlElement(name = "orderItem")
    @JacksonXmlProperty(localName = "orderItem")
    @JacksonXmlElementWrapper(useWrapping = false)
    private List<OrderItem> orderItems = new ArrayList<>();

    public Order() {
    }

public class OrderItem {

    private String sku;

    private Double price;

    public OrderItem() {
    }

I have set up a MapStruct.

CycleAvoidingMappingContext - ( This is necessary to avoid Cycling (and the appearance of stack overflow))

@Component
public class CycleAvoidingMappingContext {

    private Map<Object, Object> knownInstances = new IdentityHashMap<Object, Object>();

    @BeforeMapping
    public <T> T getMappedInstance(Object source, @TargetType Class<T> targetType) {

        T t = (T) knownInstances.get(source);
        return t;
    }

    @BeforeMapping
    public void storeMappedInstance(Object source, @MappingTarget Object target) {
        knownInstances.put( source, target );
    }
}

public interface CommonMapper<D, E> {

    D toDto(E e, @Context CycleAvoidingMappingContext context);

    E toEntity(D d, @Context CycleAvoidingMappingContext context);

    Iterable<D> toListDto(Iterable<E> entityList);

    Iterable<E> toListEntity(Iterable<D> dtoList);

}

MapperUtils - (This is utils for MapStruct)

public static Order convertToDto(OrderEntityXml orderEntityXml){
        Order order = new Order();

        String customer = orderEntityXml.getCustomer();
        order.setCustomer(customer);

        Order xmlOrder = orderEntityXml.getOrder();
        List<OrderItem> orderItems = xmlOrder.getOrderItems();
        order.setOrderItems(orderItems);

        return order;
    }

    public static OrderEntityXml convertToEntity(Order order){

        OrderEntityXml orderEntityXml = new OrderEntityXml();
        String customer = order.getCustomer();
        orderEntityXml.setCustomer(customer);

        List<OrderItem> orderItems = order.getOrderItems();

        Order orderInEntity = new Order();

        orderInEntity.setOrderItems(orderItems);
        orderInEntity.setCustomer(customer);

        orderEntityXml.setOrder(orderInEntity);

        return orderEntityXml;
    }

OrderDtoMapper - It is basic interface for me, for classes generation

@Mapper(componentModel = "spring")
public interface OrderDtoMapper extends CommonMapper<Order, OrderEntityXml> {

    @Override
    default Order toDto(OrderEntityXml orderEntityXml, CycleAvoidingMappingContext context) {

        return convertToDto(orderEntityXml);
    }

    @Override
    default OrderEntityXml toEntity(Order order, CycleAvoidingMappingContext context) {

        return convertToEntity(order);
    }

    @Override
    default Iterable<Order> toListDto(Iterable<OrderEntityXml> entityList) {

        Iterable<Order> collect = StreamSupport.stream(entityList.spliterator(), false)
            .map(MapperUtils::convertToDto)
            .collect(Collectors.toList());

        return collect;
    }
}

For each data type, you will have to make your own utilities, and this is cumbersome.

Сan I remove extra code and configure it via MapStruct interfaces ?
I suspect I've complicated the code.

Сan anyone tell you what needs to be tweaked or what technology can be applied to mapStruct to make the code unified

Body:
Looking at the posted entities I don't see why you need to use CycleAvoidingMappingContext. There is no cyclic dependency between your objects.

In order to avoid the manual code you've written you can use the MapStruct @Mapping annotation to customize how certain fields need to be mapped.

So in your case it would be something like:

@Mapper(componentModel = "spring")
public interface OrderDtoMapper extends CommonMapper<Order, OrderEntityXml> {

    @Override
    @Mapping(target = "orderItems", source = "order.orderItems")
    Order toDto(OrderEntityXml orderEntityXml, @Context CycleAvoidingMappingContext context);

    @Override
    @Mapping(target = "order", source = "order")
    OrderEntityXml toEntity(Order order, CycleAvoidingMappingContext context);

    Order cloneOrder(Order order);
}

The only customizations you need are the following:

For toDto to tell MapStruct that when you are mapping from OrderEntityXml to Order you want to map the order.orderItems into the orderItems.

For toEntity to tell MapStruct that you when you are mapping from Order to OrderEntityXml you want to map the method order parameters into the order of the `OrderEntityXml

Additionally we add Order cloneOrder(Order) so that MapStruct creates a new object when mapping between Order otherwise the same object will be used.

The customer in both cases will be automatically mapped, since it matches on both sides.

There is no need to provide custom method for the Iterable mapping because MapStruct will do that automatically for you. It knows


问:
How to post message on twitter wall using twitter integrate android app
I would like to integrate Twitter into my Android application so that I can post messages to Twitter.</p>

答: You can send the appropriate Intent to start the default twitter application


问:
Handling nested case statements in Redshift
I am writing a Redshift query which require use of multiple case statements.

Pretext:
Customers can associated with more than one organizations like, sweet or salt etc.

Ask :
We have to check that customers associated with 'SWEETS' organization are picked first, if no affiliation with 'SWEETS' is available , than we have to take id of that organization where flag = 1.

I have to use a case statement in redshift to derive the result.

There are three different tables, customer table, organization  table and 3 table that determines how customers are associated with organization.

![enter image description here][1]

Code that I have tried is below , but after executing this , I am still getting the two organization ids, instead of one id which should be of sweet org.

```<code>SELECT customer_id
     , organization_id
FROM      customer_details  AS customer
LEFT JOIN organization      AS org
       ON customer.customer_id
      AND organization_id = CASE WHEN organization_id IN (SELECT organization_id
                                                            FROM organization_type
                                                           WHERE organization_type = 'SWEET')
                                 THEN organization_id
                            ELSE org.organization_id END
</code>```

答:
You can use window functions:</p>

```<code>select customer_id, organization_id
from (select c.customer_id, o.organization_id,
             row_number() over (partition by o.customer_id order by o.organization_type = 'SWEET' desc) as seqnum
      from customer_details c left join
           organization o
           on c.customer_id = o.organization_id
     ) co
where seqnum = 1;
</code>```

Body:
I am writing a Redshift query which require use of multiple case statements.

Pretext:
Customers can associated with more than one organizations like, sweet or salt etc.

Ask :
We have to check that customers associated with 'SWEETS' organization are picked first, if no affiliation with 'SWEETS' is available , than we have to take id of that organization where flag = 1.

I have to use a case statement in redshift to derive the result.

There are three different tables, customer table, organization  table and 3 table that determines how customers are associated with organization.

![enter image description here][1]

Code that I have tried is below , but after executing this , I am still getting the two organization ids, instead of one id which should be of sweet org.

SELECT customer_id
     , organization_id
FROM      customer_details  AS customer
LEFT JOIN organization      AS org
       ON customer.customer_id
      AND organization_id = CASE WHEN organization_id IN (SELECT organization_id
                                                            FROM organization_type
                                                           WHERE organization_type = 'SWEET')
                                 THEN organization_id
                            ELSE org.organization_id END

Body:
You can use window functions:

select customer_id, organization_id
from (select c.customer_id, o.organization_id,
             row_number() over (partition by o.customer_id order by o.organization_type = 'SWEET' desc) as seqnum
      from customer_details c left join
           organization o
           on c.customer_id = o.organization_id
     ) co
where seqnum = 1;


问:
SFML Cross-compilation for Windows on Linux
I'm trying to compile a simple program with SFML (basic helloworld but with a big green circle). I'm supposed to build the program on Linux for Linux and Windows. When I compile for Linux the program compile and run perfectly, however when I try to compile the Windows Executable, I get the following error:

 /usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-graphics
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-window
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-system
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/BrickShooter.dir/build.make:215: BrickShooter.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/BrickShooter.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
```

<p>I tried to change the setting in my Cmake without success (add_library, include_directories) but so far nothing worked.
Here is my CMakeLists.txt:</p>

```cmake_minimum_required(VERSION 3.16)
project(BrickShooter)

set(CMAKE_CXX_STANDARD 14)

add_executable(BrickShooter main.cpp GameObjects/Block.cpp GameObjects/Block.h GameObjects/Player.cpp GameObjects/Player.h GameObjects/Shoot.cpp GameObjects/Shoot.h SysObjects/Game.cpp SysObjects/Game.h SysObjects/Store.cpp SysObjects/Store.h SysObjects/Menu.cpp SysObjects/Menu.h SysObjects/Backup.cpp SysObjects/Backup.h SysObjects/SysGame.cpp SysObjects/SysGame.h)

target_link_libraries (BrickShooter sfml-graphics sfml-window sfml-system)
```

<p>And my toolchain for Windows:</p>

```# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
#    *) install cross compiler: `sudo apt-get install mingw-w64`
#    *) cd build
#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/windows.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(SFML_INCLUDE_DIR "gitlab_ci/SFML-2.5.1-WIN/include")
include_directories(gitlab_ci/SFML-2.5.1-WIN/include)
set(SFML_LIBRARY_DIR "gitlab_ci/SFML-2.5.1-WIN/lib")
set(SFML_DIR "gitlab_ci/SFML-2.5.1-WIN/lib/cmake/SFML")

```

<p>I'm using the following command to manually build the program:</p>

<pre class="lang-sh prettyprint-override"><code>cmake gitlab_ci/SFML-2.5.1-WIN/ -DCMAKE_TOOLCHAIN_FILE=gitlab_ci/windows.cmake CMakeLists.txt && make
</code>```

Where gitlab_ci/SFML-2.5.1-WIN is where I stored the includes, libs, etc for Windows. I'm on Ubuntu 20.04 LTS and I have installed everything I needed with the following commands:

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential libsfml-dev cmake doxygen mingw-w64 curl unzip
curl -O https://www.sfml-dev.org/files/SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
unzip SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
mv SFML-2.5.1 gitlab_ci/SFML-2.5.1-WIN
rm SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
```

答:
Thanks to @tsyvarev here is the solution that worked for me:
I added this line to my toolchain for Windows

```<code>link_directories(gitlab_ci/SFML-2.5.1-WIN/lib)
</code>```

The final result is:

```<code># Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
#    *) install cross compiler: `sudo apt-get install mingw-w64`
#    *) cd build
#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/windows.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(SFML_INCLUDE_DIR "gitlab_ci/SFML-2.5.1-WIN/include")
include_directories(gitlab_ci/SFML-2.5.1-WIN/include)
set(SFML_LIBRARY_DIR "gitlab_ci/SFML-2.5.1-WIN/lib")
link_directories(gitlab_ci/SFML-2.5.1-WIN/lib)
set(SFML_DIR "gitlab_ci/SFML-2.5.1-WIN/lib/cmake/SFML")
</code>```

and this give the following output:

cmake gitlab_ci/SFML-2.5.1-WIN/ -DCMAKE_TOOLCHAIN_FILE=gitlab_ci/windows.cmake CMakeLists.txt && make
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/shared/school/Ynov/Home_Work/uf_dev_log_13/repo_gitlab
Scanning dependencies of target BrickShooter
[ 10%] Building CXX object CMakeFiles/BrickShooter.dir/main.cpp.obj
[ 20%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Block.cpp.obj
[ 30%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Player.cpp.obj
[ 40%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Shoot.cpp.obj
[ 50%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Game.cpp.obj
[ 60%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Store.cpp.obj
[ 70%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Menu.cpp.obj
[ 80%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Backup.cpp.obj
[ 90%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/SysGame.cpp.obj
[100%] Linking CXX executable BrickShooter.exe
[100%] Built target BrickShooter
```

Here is the link to the CMake docs about link_directories()

Body:
I'm trying to compile a simple program with SFML (basic helloworld but with a big green circle). I'm supposed to build the program on Linux for Linux and Windows. When I compile for Linux the program compile and run perfectly, however when I try to compile the Windows Executable, I get the following error:

 /usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-graphics
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-window
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-system
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/BrickShooter.dir/build.make:215: BrickShooter.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/BrickShooter.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I tried to change the setting in my Cmake without success (add_library, include_directories) but so far nothing worked.
Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(BrickShooter)

set(CMAKE_CXX_STANDARD 14)

add_executable(BrickShooter main.cpp GameObjects/Block.cpp GameObjects/Block.h GameObjects/Player.cpp GameObjects/Player.h GameObjects/Shoot.cpp GameObjects/Shoot.h SysObjects/Game.cpp SysObjects/Game.h SysObjects/Store.cpp SysObjects/Store.h SysObjects/Menu.cpp SysObjects/Menu.h SysObjects/Backup.cpp SysObjects/Backup.h SysObjects/SysGame.cpp SysObjects/SysGame.h)

target_link_libraries (BrickShooter sfml-graphics sfml-window sfml-system)

And my toolchain for Windows:

# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
#    *) install cross compiler: `sudo apt-get install mingw-w64`
#    *) cd build
#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/windows.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(SFML_INCLUDE_DIR "gitlab_ci/SFML-2.5.1-WIN/include")
include_directories(gitlab_ci/SFML-2.5.1-WIN/include)
set(SFML_LIBRARY_DIR "gitlab_ci/SFML-2.5.1-WIN/lib")
set(SFML_DIR "gitlab_ci/SFML-2.5.1-WIN/lib/cmake/SFML")

I'm using the following command to manually build the program:

cmake gitlab_ci/SFML-2.5.1-WIN/ -DCMAKE_TOOLCHAIN_FILE=gitlab_ci/windows.cmake CMakeLists.txt && make

Where gitlab_ci/SFML-2.5.1-WIN is where I stored the includes, libs, etc for Windows. I'm on Ubuntu 20.04 LTS and I have installed everything I needed with the following commands:

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential libsfml-dev cmake doxygen mingw-w64 curl unzip
curl -O https://www.sfml-dev.org/files/SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
unzip SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
mv SFML-2.5.1 gitlab_ci/SFML-2.5.1-WIN
rm SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip

Body:
Thanks to @tsyvarev here is the solution that worked for me:
I added this line to my toolchain for Windows

link_directories(gitlab_ci/SFML-2.5.1-WIN/lib)

The final result is:

# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
#    *) install cross compiler: `sudo apt-get install mingw-w64`
#    *) cd build
#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/windows.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(SFML_INCLUDE_DIR "gitlab_ci/SFML-2.5.1-WIN/include")
include_directories(gitlab_ci/SFML-2.5.1-WIN/include)
set(SFML_LIBRARY_DIR "gitlab_ci/SFML-2.5.1-WIN/lib")
link_directories(gitlab_ci/SFML-2.5.1-WIN/lib)
set(SFML_DIR "gitlab_ci/SFML-2.5.1-WIN/lib/cmake/SFML")

and this give the following output:

cmake gitlab_ci/SFML-2.5.1-WIN/ -DCMAKE_TOOLCHAIN_FILE=gitlab_ci/windows.cmake CMakeLists.txt && make
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/shared/school/Ynov/Home_Work/uf_dev_log_13/repo_gitlab
Scanning dependencies of target BrickShooter
[ 10%] Building CXX object CMakeFiles/BrickShooter.dir/main.cpp.obj
[ 20%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Block.cpp.obj
[ 30%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Player.cpp.obj
[ 40%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Shoot.cpp.obj
[ 50%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Game.cpp.obj
[ 60%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Store.cpp.obj
[ 70%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Menu.cpp.obj
[ 80%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Backup.cpp.obj
[ 90%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/SysGame.cpp.obj
[100%] Linking CXX executable BrickShooter.exe
[100%] Built target BrickShooter

Here is the link to the CMake docs about link_directories()


问:
Error in plot_model(type="diag") : arguments imply differing number of rows error
I was doing a regression analysis and made regression model with this code,

```<code>regrs_2 <- lm(gii.score ~ hof.pdi + hof.idv + hof.mas + hof.uai + hof.ltowvs +
                hof.ivr + ctnt.dummy.asia + ctnt.dummy.europe + ctnt.dummy.noram +
                ctnt.dummy.africa + ctnt.dummy.oceania, data = data)
library(sjPlot)
plot_model(regrs_2, type="diag")
</code>```

and run this code:

```<code>sjPlot::plot_model(regrs_2,type="diag")
</code>```

At this time, an error occurred, saying:

Error in data.frame(x = fitted_, y = res_) :
  arguments imply differing number of rows: 61, 60**
```

<p>But when I changed the <code>type=</code> argument of <code>plot_model</code> from <code>"diag"</code> to <code>"std"</code> or <code>"est"</code> there is no error. </p>

<p>How can I resolve this problem? </p>

<p>This is my <code>data</code>:</p>

```structure(list(X = c(4L, 5L, 11L, 31L, 32L, 41L, 57L, 91L, 93L,
94L, 1L, 2L, 3L, 6L, 7L, 8L, 9L, 10L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L,
30L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 42L, 43L, 44L, 45L,
46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 58L, 59L,
60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L,
73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L,
86L, 87L, 88L, 89L, 90L, 92L), ctnt = structure(c(6L, 3L, 6L,
5L, 3L, 6L, 6L, 3L, 6L, 6L, 2L, 2L, 2L, 4L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 3L, 3L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 2L, 2L,
2L, 2L, 1L, 1L, 3L, 1L, 2L, 3L, 3L, 3L, 3L), .Label = c("남아메리카",
"북아메리카", "아시아", "아프리카", "오세아니아", "유럽"), class = "factor"),
    c_code = c(7L, 20L, 34L, 61L, 62L, 90L, 351L, 971L, 994L,
    995L, 1L, 1L, 1L, 27L, 30L, 31L, 32L, 33L, 36L, 39L, 40L,
    41L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 51L, 52L, 54L, 55L,
    56L, 57L, 58L, 60L, 63L, 64L, 65L, 66L, 81L, 82L, 84L, 86L,
    91L, 92L, 98L, 212L, 213L, 223L, 226L, 233L, 234L, 250L,
    251L, 255L, 256L, 260L, 263L, 352L, 353L, 354L, 355L, 356L,
    357L, 358L, 359L, 370L, 371L, 372L, 373L, 374L, 375L, 380L,
    381L, 382L, 385L, 387L, 420L, 421L, 502L, 503L, 506L, 507L,
    593L, 598L, 852L, 868L, 876L, 880L, 962L, 966L, 972L), country = structure(c(73L,
    27L, 80L, 6L, 43L, 86L, 71L, 3L, 8L, 33L, 16L, 25L, 87L,
    79L, 37L, 62L, 11L, 32L, 40L, 47L, 72L, 82L, 7L, 36L, 24L,
    81L, 65L, 70L, 34L, 68L, 58L, 4L, 13L, 17L, 19L, 91L, 55L,
    69L, 63L, 77L, 84L, 49L, 51L, 92L, 18L, 42L, 66L, 44L, 61L,
    2L, 56L, 15L, 35L, 64L, 74L, 30L, 83L, 88L, 93L, 94L, 54L,
    45L, 41L, 1L, 57L, 22L, 31L, 14L, 53L, 52L, 29L, 59L, 5L,
    10L, 89L, 76L, 60L, 21L, 12L, 23L, 78L, 38L, 28L, 20L, 67L,
    26L, 90L, 39L, 85L, 48L, 9L, 50L, 75L, 46L), .Label = c("Albania",
    "Algeria", "Arab countries", "Argentina", "Armenia", "Australia",
    "Austria", "Azerbaijan", "Bangladesh", "Belarus", "Belgium",
    "Bosnia", "Brazil", "Bulgaria", "Burkina Faso", "Canada",
    "Chile", "China", "Colombia", "Costa Rica", "Croatia", "Cyprus",
    "Czech Rep", "Denmark", "Dominican Rep", "Ecuador", "Egypt",
    "El Salvador", "Estonia", "Ethiopia", "Finland", "France",
    "Georgia", "Germany", "Ghana", "Great Britain", "Greece",
    "Guatemala", "Hong Kong", "Hungary", "Iceland", "India",
    "Indonesia", "Iran", "Ireland", "Israel", "Italy", "Jamaica",
    "Japan", "Jordan", "Korea South", "Latvia", "Lithuania",
    "Luxembourg", "Malaysia", "Mali", "Malta", "Mexico", "Moldova",
    "Montenegro", "Morocco", "Netherlands", "New Zealand", "Nigeria",
    "Norway", "Pakistan", "Panama", "Peru", "Philippines", "Poland",
    "Portugal", "Romania", "Russia", "Rwanda", "Saudi Arabia",
    "Serbia", "Singapore", "Slovak", "South Africa", "Spain",
    "Sweden", "Switzerland", "Tanzania", "Thailand", "Trinidad and Tobago",
    "Turkey", "U.S.A.", "Uganda", "Ukraine", "Uruguay", "Venezuela",
    "Vietnam", "Zambia", "Zimbabwe"), class = "factor"), hof.pdi = c(44L,
    NA, 24L, 11L, 39L, 31L, 28L, 40L, NA, NA, 12L, NA, 13L, NA,
    26L, 11L, 30L, 33L, 17L, 20L, 43L, 9L, 2L, 10L, 4L, 7L, 7L,
    33L, 10L, 29L, 41L, 19L, 34L, 28L, 32L, 41L, 1L, 45L, 5L,
    37L, 29L, 21L, 26L, 35L, 40L, 38L, 22L, 25L, 35L, NA, NA,
    NA, NA, NA, NA, NA, NA, NA, NA, NA, 13L, 6L, NA, NA, 23L,
    NA, 8L, 35L, 14L, 15L, 13L, NA, NA, NA, NA, 42L, NA, 36L,
    NA, 24L, 1L, 46L, 31L, 10L, 46L, 39L, 27L, 33L, 18L, 16L,
    40L, NA, NA, 3L), hof.idv = c(21L, NA, 25L, 46L, 4L, 19L,
    13L, 20L, NA, NA, 44L, NA, 47L, NA, 17L, 44L, 40L, 38L, 44L,
    41L, 14L, 35L, 28L, 45L, 39L, 38L, 36L, 32L, 34L, 6L, 14L,
    23L, 20L, 10L, 3L, 2L, 12L, 15L, 42L, 9L, 9L, 23L, 7L, 9L,
    9L, 24L, 4L, 22L, 23L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
    NA, NA, 32L, 37L, NA, NA, 30L, NA, 33L, 14L, 32L, 37L, 32L,
    NA, NA, NA, NA, 11L, NA, 16L, NA, 29L, 26L, 31L, 8L, 5L,
    1L, 43L, 18L, 11L, 6L, 21L, 9L, NA, NA, 27L), hof.mas = c(11L,
    NA, 16L, 33L, 20L, 19L, 9L, 27L, NA, NA, 26L, NA, 34L, NA,
    31L, 2L, 28L, 17L, 44L, 40L, 16L, 40L, 42L, 37L, 3L, 24L,
    43L, 36L, 37L, 16L, 39L, 30L, 23L, 7L, 36L, 41L, 25L, 36L,
    32L, 22L, 10L, 46L, 14L, 15L, 37L, 30L, 25L, 17L, 27L, NA,
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 25L, 38L, NA, NA,
    21L, NA, 6L, 15L, 4L, 45L, 8L, NA, NA, NA, NA, 17L, NA, 15L,
    NA, 31L, 1L, 12L, 15L, 5L, 18L, 35L, 13L, 31L, 32L, 38L,
    29L, NA, NA, 21L), hof.uai = c(43L, NA, 37L, 17L, 14L, 36L,
    3L, 27L, NA, NA, 14L, NA, 13L, NA, 4L, 18L, 42L, 37L, 35L,
    30L, 39L, 20L, 28L, 9L, 6L, 7L, 16L, 41L, 25L, 38L, 35L,
    37L, 31L, 37L, 33L, 31L, 10L, 12L, 15L, 32L, 24L, 40L, 36L,
    8L, 8L, 11L, 28L, 21L, 27L, NA, NA, NA, NA, NA, NA, NA, NA,
    NA, NA, NA, 28L, 9L, NA, NA, 44L, NA, 21L, 36L, 25L, 23L,
    22L, NA, NA, NA, NA, 40L, NA, 33L, NA, 29L, 17L, 2L, 42L,
    37L, 37L, 26L, 1L, 7L, 19L, 5L, 22L, NA, NA, 34L), hof.ltowvs = c(50L,
    43L, 29L, 8L, 38L, 27L, 14L, 9L, 37L, 22L, 21L, 2L, 12L,
    19L, 26L, 41L, 51L, 39L, 35L, 37L, 32L, 47L, 36L, 31L, 20L,
    33L, 20L, 22L, 52L, 11L, 10L, 7L, 25L, 16L, 2L, 5L, 24L,
    13L, 18L, 46L, 17L, 55L, 1L, 34L, 54L, 31L, 30L, 3L, 3L,
    12L, 7L, 13L, 23L, 2L, 6L, NA, 19L, 10L, 15L, 4L, 40L, 10L,
    14L, 37L, 28L, NA, 22L, 42L, 51L, 42L, 51L, 45L, 37L, 50L,
    53L, 32L, 48L, 35L, 44L, 44L, 49L, NA, 7L, NA, NA, NA, 12L,
    37L, 2L, NA, 28L, 5L, 21L, 22L), hof.ivr = c(10L, 25L, 29L,
    50L, 24L, 33L, 20L, 21L, 11L, 19L, 47L, 37L, 47L, 43L, 34L,
    47L, 40L, 32L, 18L, 17L, 10L, 45L, 43L, 48L, 49L, 53L, 38L,
    16L, 26L, 31L, 58L, 42L, 41L, 47L, 55L, 2L, 40L, 27L, 52L,
    31L, 30L, 27L, 16L, 22L, 12L, 14L, 1L, 26L, 13L, 19L, 28L,
    8L, 51L, 56L, 23L, 31L, 24L, 35L, 27L, 15L, 39L, 44L, 46L,
    5L, 45L, 49L, 40L, 6L, 6L, 3L, 6L, 9L, NA, 5L, 4L, 15L, 10L,
    20L, 29L, 16L, 15L, NA, 57L, NA, NA, NA, 36L, 7L, 54L, NA,
    10L, 28L, 35L, NA), gii.score = c(39.32, 28.91, 49.07, 55.22,
    29.79, 37.81, 46.61, 40.06, 30.1, 33.83, 55.73, 30.6, 60.1,
    37.45, 40.28, 61.58, 50.91, 53.59, 43, 46.4, 38.2, 68.3,
    54.07, 62.42, 57.7, 62.4, 53.8, 40.16, 57.05, 34.87, 38.03,
    34.3, 34.95, 41.2, 36.41, 22.77, 45.98, 31.05, 55.92, 59.36,
    38.1, 53.97, 56.26, 38.35, 47.47, 31.74, 23.07, 28.37, 33.19,
    24.38, 28.37, 28.68, 28.04, 23.72, 30.09, 24.17, 27, 27.65,
    24.64, 22.52, 59.02, 59.13, 57.02, 30.74, 50.48, 43.51, 59.97,
    42.16, 42.26, 45.51, 52.81, 40.53, 37.31, 38.23, 36.45, 36.47,
    41.23, 41.7, 32.31, 51.32, 42.99, 28.84, 29.31, 38.59, 36.8,
    26.87, 35.76, 57.23, 32.18, 29.95, 23.71, 33.78, 40.65, 53.54
    ), ctnt.dummy.asia = c(0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
    0, 0, 1, 1, 1, 1), ctnt.dummy.europe = c(1, 0, 1, 0, 0, 1,
    1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ctnt.dummy.noram = c(0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0), ctnt.dummy.africa = c(0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ctnt.dummy.oceania = c(0,
    0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ctnt.dummy.souam = c(0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0)), row.names = c(NA,
-94L), class = "data.frame")
```

答:
Inspecting the code of the sjPlot::plot_model function reveals that sjPlot:::plot_diag_linear method is used and yields the error.

```<code># sjPlot:::plot_diag_linear(regrs_2, geom.colors="red", dot.size=1, line.size=1)
# # Error in data.frame(x = fitted_, y = res_) :
# #   arguments imply differing number of rows: 61, 60
</code>```

Going a level deeper into the code we get to the plot list, where sjPlot:::diag_qq is failing.

```<code>sjPlot:::diag_vif(regrs_2)
</code>```

```<code># sjPlot:::diag_qq(regrs_2, dot.size=1, line.size=1)  ## FAILS!
# # Error in data.frame(x = fitted_, y = res_) :
# #   arguments imply differing number of rows: 61, 60
</code>```

```<code>sjPlot:::diag_norm(regrs_2, geom.colors="red")
# Warning message:
#   Removed 101 row(s) containing missing values (geom_path).
</code>```

```<code>sjPlot:::diag_ncv(regrs_2, dot.size=1, line.size=1)
# `geom_smooth()` using formula 'y ~ x'
</code>```

Also warnings are thrown. The issue might be due to statistical reasons, since the example on ?sjPlot::plot_model is working fine.

Only a partial answer, I know, hoping to help you somehow.

Body:
I was doing a regression analysis and made regression model with this code,

regrs_2 <- lm(gii.score ~ hof.pdi + hof.idv + hof.mas + hof.uai + hof.ltowvs +
                hof.ivr + ctnt.dummy.asia + ctnt.dummy.europe + ctnt.dummy.noram +
                ctnt.dummy.africa + ctnt.dummy.oceania, data = data)
library(sjPlot)
plot_model(regrs_2, type="diag")

and run this code:

sjPlot::plot_model(regrs_2,type="diag")

At this time, an error occurred, saying:

Error in data.frame(x = fitted_, y = res_) :
  arguments imply differing number of rows: 61, 60**

But when I changed the type= argument of plot_model from "diag" to "std" or "est" there is no error.

How can I resolve this problem?

This is my data:

structure(list(X = c(4L, 5L, 11L, 31L, 32L, 41L, 57L, 91L, 93L,
94L, 1L, 2L, 3L, 6L, 7L, 8L, 9L, 10L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L,
30L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 42L, 43L, 44L, 45L,
46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 58L, 59L,
60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L,
73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L,
86L, 87L, 88L, 89L, 90L, 92L), ctnt = structure(c(6L, 3L, 6L,
5L, 3L, 6L, 6L, 3L, 6L, 6L, 2L, 2L, 2L, 4L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 3L, 3L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 2L, 2L,
2L, 2L, 1L, 1L, 3L, 1L, 2L, 3L, 3L, 3L, 3L), .Label = c("남아메리카",
"북아메리카", "아시아", "아프리카", "오세아니아", "유럽"), class = "factor"),
    c_code = c(7L, 20L, 34L, 61L, 62L, 90L, 351L, 971L, 994L,
    995L, 1L, 1L, 1L, 27L, 30L, 31L, 32L, 33L, 36L, 39L, 40L,
    41L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 51L, 52L, 54L, 55L,
    56L, 57L, 58L, 60L, 63L, 64L, 65L, 66L, 81L, 82L, 84L, 86L,
    91L, 92L, 98L, 212L, 213L, 223L, 226L, 233L, 234L, 250L,
    251L, 255L, 256L, 260L, 263L, 352L, 353L, 354L, 355L, 356L,
    357L, 358L, 359L, 370L, 371L, 372L, 373L, 374L, 375L, 380L,
    381L, 382L, 385L, 387L, 420L, 421L, 502L, 503L, 506L, 507L,
    593L, 598L, 852L, 868L, 876L, 880L, 962L, 966L, 972L), country = structure(c(73L,
    27L, 80L, 6L, 43L, 86L, 71L, 3L, 8L, 33L, 16L, 25L, 87L,
    79L, 37L, 62L, 11L, 32L, 40L, 47L, 72L, 82L, 7L, 36L, 24L,
    81L, 65L, 70L, 34L, 68L, 58L, 4L, 13L, 17L, 19L, 91L, 55L,
    69L, 63L, 77L, 84L, 49L, 51L, 92L, 18L, 42L, 66L, 44L, 61L,
    2L, 56L, 15L, 35L, 64L, 74L, 30L, 83L, 88L, 93L, 94L, 54L,
    45L, 41L, 1L, 57L, 22L, 31L, 14L, 53L, 52L, 29L, 59L, 5L,
    10L, 89L, 76L, 60L, 21L, 12L, 23L, 78L, 38L, 28L, 20L, 67L,
    26L, 90L, 39L, 85L, 48L, 9L, 50L, 75L, 46L), .Label = c("Albania",
    "Algeria", "Arab countries", "Argentina", "Armenia", "Australia",
    "Austria", "Azerbaijan", "Bangladesh", "Belarus", "Belgium",
    "Bosnia", "Brazil", "Bulgaria", "Burkina Faso", "Canada",
    "Chile", "China", "Colombia", "Costa Rica", "Croatia", "Cyprus",
    "Czech Rep", "Denmark", "Dominican Rep", "Ecuador", "Egypt",
    "El Salvador", "Estonia", "Ethiopia", "Finland", "France",
    "Georgia", "Germany", "Ghana", "Great Britain", "Greece",
    "Guatemala", "Hong Kong", "Hungary", "Iceland", "India",
    "Indonesia", "Iran", "Ireland", "Israel", "Italy", "Jamaica",
    "Japan", "Jordan", "Korea South", "Latvia", "Lithuania",
    "Luxembourg", "Malaysia", "Mali", "Malta", "Mexico", "Moldova",
    "Montenegro", "Morocco", "Netherlands", "New Zealand", "Nigeria",
    "Norway", "Pakistan", "Panama", "Peru", "Philippines", "Poland",
    "Portugal", "Romania", "Russia", "Rwanda", "Saudi Arabia",
    "Serbia", "Singapore", "Slovak", "South Africa", "Spain",
    "Sweden", "Switzerland", "Tanzania", "Thailand", "Trinidad and Tobago",
    "Turkey", "U.S.A.", "Uganda", "Ukraine", "Uruguay", "Venezuela",
    "Vietnam", "Zambia", "Zimbabwe"), class = "factor"), hof.pdi = c(44L,
    NA, 24L, 11L, 39L, 31L, 28L, 40L, NA, NA, 12L, NA, 13L, NA,
    26L, 11L, 30L, 33L, 17L, 20L, 43L, 9L, 2L, 10L, 4L, 7L, 7L,
    33L, 10L, 29L, 41L, 19L, 34L, 28L, 32L, 41L, 1L, 45L, 5L,
    37L, 29L, 21L, 26L, 35L, 40L, 38L, 22L, 25L, 35L, NA, NA,
    NA, NA, NA, NA, NA, NA, NA, NA, NA, 13L, 6L, NA, NA, 23L,
    NA, 8L, 35L, 14L, 15L, 13L, NA, NA, NA, NA, 42L, NA, 36L,
    NA, 24L, 1L, 46L, 31L, 10L, 46L, 39L, 27L, 33L, 18L, 16L,
    40L, NA, NA, 3L), hof.idv = c(21L, NA, 25L, 46L, 4L, 19L,
    13L, 20L, NA, NA, 44L, NA, 47L, NA, 17L, 44L, 40L, 38L, 44L,
    41L, 14L, 35L, 28L, 45L, 39L, 38L, 36L, 32L, 34L, 6L, 14L,
    23L, 20L, 10L, 3L, 2L, 12L, 15L, 42L, 9L, 9L, 23L, 7L, 9L,
    9L, 24L, 4L, 22L, 23L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
    NA, NA, 32L, 37L, NA, NA, 30L, NA, 33L, 14L, 32L, 37L, 32L,
    NA, NA, NA, NA, 11L, NA, 16L, NA, 29L, 26L, 31L, 8L, 5L,
    1L, 43L, 18L, 11L, 6L, 21L, 9L, NA, NA, 27L), hof.mas = c(11L,
    NA, 16L, 33L, 20L, 19L, 9L, 27L, NA, NA, 26L, NA, 34L, NA,
    31L, 2L, 28L, 17L, 44L, 40L, 16L, 40L, 42L, 37L, 3L, 24L,
    43L, 36L, 37L, 16L, 39L, 30L, 23L, 7L, 36L, 41L, 25L, 36L,
    32L, 22L, 10L, 46L, 14L, 15L, 37L, 30L, 25L, 17L, 27L, NA,
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 25L, 38L, NA, NA,
    21L, NA, 6L, 15L, 4L, 45L, 8L, NA, NA, NA, NA, 17L, NA, 15L,
    NA, 31L, 1L, 12L, 15L, 5L, 18L, 35L, 13L, 31L, 32L, 38L,
    29L, NA, NA, 21L), hof.uai = c(43L, NA, 37L, 17L, 14L, 36L,
    3L, 27L, NA, NA, 14L, NA, 13L, NA, 4L, 18L, 42L, 37L, 35L,
    30L, 39L, 20L, 28L, 9L, 6L, 7L, 16L, 41L, 25L, 38L, 35L,
    37L, 31L, 37L, 33L, 31L, 10L, 12L, 15L, 32L, 24L, 40L, 36L,
    8L, 8L, 11L, 28L, 21L, 27L, NA, NA, NA, NA, NA, NA, NA, NA,
    NA, NA, NA, 28L, 9L, NA, NA, 44L, NA, 21L, 36L, 25L, 23L,
    22L, NA, NA, NA, NA, 40L, NA, 33L, NA, 29L, 17L, 2L, 42L,
    37L, 37L, 26L, 1L, 7L, 19L, 5L, 22L, NA, NA, 34L), hof.ltowvs = c(50L,
    43L, 29L, 8L, 38L, 27L, 14L, 9L, 37L, 22L, 21L, 2L, 12L,
    19L, 26L, 41L, 51L, 39L, 35L, 37L, 32L, 47L, 36L, 31L, 20L,
    33L, 20L, 22L, 52L, 11L, 10L, 7L, 25L, 16L, 2L, 5L, 24L,
    13L, 18L, 46L, 17L, 55L, 1L, 34L, 54L, 31L, 30L, 3L, 3L,
    12L, 7L, 13L, 23L, 2L, 6L, NA, 19L, 10L, 15L, 4L, 40L, 10L,
    14L, 37L, 28L, NA, 22L, 42L, 51L, 42L, 51L, 45L, 37L, 50L,
    53L, 32L, 48L, 35L, 44L, 44L, 49L, NA, 7L, NA, NA, NA, 12L,
    37L, 2L, NA, 28L, 5L, 21L, 22L), hof.ivr = c(10L, 25L, 29L,
    50L, 24L, 33L, 20L, 21L, 11L, 19L, 47L, 37L, 47L, 43L, 34L,
    47L, 40L, 32L, 18L, 17L, 10L, 45L, 43L, 48L, 49L, 53L, 38L,
    16L, 26L, 31L, 58L, 42L, 41L, 47L, 55L, 2L, 40L, 27L, 52L,
    31L, 30L, 27L, 16L, 22L, 12L, 14L, 1L, 26L, 13L, 19L, 28L,
    8L, 51L, 56L, 23L, 31L, 24L, 35L, 27L, 15L, 39L, 44L, 46L,
    5L, 45L, 49L, 40L, 6L, 6L, 3L, 6L, 9L, NA, 5L, 4L, 15L, 10L,
    20L, 29L, 16L, 15L, NA, 57L, NA, NA, NA, 36L, 7L, 54L, NA,
    10L, 28L, 35L, NA), gii.score = c(39.32, 28.91, 49.07, 55.22,
    29.79, 37.81, 46.61, 40.06, 30.1, 33.83, 55.73, 30.6, 60.1,
    37.45, 40.28, 61.58, 50.91, 53.59, 43, 46.4, 38.2, 68.3,
    54.07, 62.42, 57.7, 62.4, 53.8, 40.16, 57.05, 34.87, 38.03,
    34.3, 34.95, 41.2, 36.41, 22.77, 45.98, 31.05, 55.92, 59.36,
    38.1, 53.97, 56.26, 38.35, 47.47, 31.74, 23.07, 28.37, 33.19,
    24.38, 28.37, 28.68, 28.04, 23.72, 30.09, 24.17, 27, 27.65,
    24.64, 22.52, 59.02, 59.13, 57.02, 30.74, 50.48, 43.51, 59.97,
    42.16, 42.26, 45.51, 52.81, 40.53, 37.31, 38.23, 36.45, 36.47,
    41.23, 41.7, 32.31, 51.32, 42.99, 28.84, 29.31, 38.59, 36.8,
    26.87, 35.76, 57.23, 32.18, 29.95, 23.71, 33.78, 40.65, 53.54
    ), ctnt.dummy.asia = c(0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
    0, 0, 1, 1, 1, 1), ctnt.dummy.europe = c(1, 0, 1, 0, 0, 1,
    1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ctnt.dummy.noram = c(0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0), ctnt.dummy.africa = c(0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ctnt.dummy.oceania = c(0,
    0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ctnt.dummy.souam = c(0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0)), row.names = c(NA,
-94L), class = "data.frame")

Body:
Inspecting the code of the sjPlot::plot_model function reveals that sjPlot:::plot_diag_linear method is used and yields the error.

# sjPlot:::plot_diag_linear(regrs_2, geom.colors="red", dot.size=1, line.size=1)
# # Error in data.frame(x = fitted_, y = res_) :
# #   arguments imply differing number of rows: 61, 60

Going a level deeper into the code we get to the plot list, where sjPlot:::diag_qq is failing.

sjPlot:::diag_vif(regrs_2)

# sjPlot:::diag_qq(regrs_2, dot.size=1, line.size=1)  ## FAILS!
# # Error in data.frame(x = fitted_, y = res_) :
# #   arguments imply differing number of rows: 61, 60

sjPlot:::diag_norm(regrs_2, geom.colors="red")
# Warning message:
#   Removed 101 row(s) containing missing values (geom_path).

sjPlot:::diag_ncv(regrs_2, dot.size=1, line.size=1)
# `geom_smooth()` using formula 'y ~ x'

Also warnings are thrown. The issue might be due to statistical reasons, since the example on ?sjPlot::plot_model is working fine.

Only a partial answer, I know, hoping to help you somehow.


问:
Page not found: Running a php file on an Apache sever
I get page not found error when I try to run my php file running on the root folder of my apache. Other php files run fine(anyway this is a magento based site). Is it because i transferred the file through FTP?
Can a server be configured not to run some specific files? How can i get round this? has is got something to do with .htacess?</p>

答:
Does the fiel have the same extension as the other php files that work.

ie. myfile.php or myfile.php4

The default config for apache specifies that php files have the extension "php4" as php version 3.0 and before are not compatible with the current versions. Usually the plain "php" extension is re-enabled but maybe not in your case.


问:
GraphQL and ApolloProvider and store... its very nested
So, I am passing store thru ApolloProvider

```<code>  <ApolloProvider store={store} client={apolloClient}>
</code>```

Now, ApolloProvider is putting it, the store, in client. But its putting the store object, not the actual reducer object. So, I am getting the following, which seems odd to me..

```<code>client
   ---> store
  -----------> getState
  -----------> dispatch
</code>```

but no "state"? I mean, sure if I would call getState(), but that seems quite different from when I usually do redux without Apollo. I get my "state tree"... here, I am getting it...

What is the "normal" or "best practices" when using redux w/ graphql?

It seems excessive to access a state prop like so:

```<code>if (this.props.client.state.getState().whatever.foo)
</code>```

答:
Use queries to local state and React Hooks like:</p>

```<code>import gql from 'graphql-tag';
import { useQuery } from '@apollo/react-hooks';
//...
export default () => {
    const { data } = useQuery(gql('query GetTableFilter { selectedMall @client }'));
    // ... do something with data.selectedMall
</code>```

Body:
So, I am passing store thru ApolloProvider

  <ApolloProvider store={store} client={apolloClient}>

Now, ApolloProvider is putting it, the store, in client. But its putting the store object, not the actual reducer object. So, I am getting the following, which seems odd to me..

client
   ---> store
  -----------> getState
  -----------> dispatch

but no "state"? I mean, sure if I would call getState(), but that seems quite different from when I usually do redux without Apollo. I get my "state tree"... here, I am getting it...

What is the "normal" or "best practices" when using redux w/ graphql?

It seems excessive to access a state prop like so:

if (this.props.client.state.getState().whatever.foo)

Body:
Use queries to local state and React Hooks like:

import gql from 'graphql-tag';
import { useQuery } from '@apollo/react-hooks';
//...
export default () => {
    const { data } = useQuery(gql('query GetTableFilter { selectedMall @client }'));
    // ... do something with data.selectedMall


问:
How to calculate the order of an algorithm with recursive calls inside a loop
I have been doing some examples of calculating the cost recursive algorithms which are inside loops, and this one has me wondering how I could calculate it.

```<code>int example(int max) {
    int i  =  1;
    double x  =  0.0;

    while ( i <= max ) {
        x  =  calculate (x , i);
        i  = 2 ∗ i ;
    }
}
</code>```

We know that calculate (int x, int i) is of O(i), and that the order of example should be based on max.

An easier example of this would be the same code with a for(int i = 1;  i <= max; i++) loop, which would make an order on example of O(max^2), but in this case i is multiplied by two on each call. How could the cost be calculated in this case?

答:
while loop will run in log(max). Each iteration of the loop will run in O(i). Hence, the total time complexity is:

```<code>T(max) = O(1 + 2 + 2^2 + ... + 2^{log(max)}) = O(2^{log(max) + 1} - 1)
</code>```

As we know that 2^{log(max)} = max, T(max) = Theta(max).

Body:
I have been doing some examples of calculating the cost recursive algorithms which are inside loops, and this one has me wondering how I could calculate it.

int example(int max) {
    int i  =  1;
    double x  =  0.0;

    while ( i <= max ) {
        x  =  calculate (x , i);
        i  = 2 ∗ i ;
    }
}

We know that calculate (int x, int i) is of O(i), and that the order of example should be based on max.

An easier example of this would be the same code with a for(int i = 1;  i <= max; i++) loop, which would make an order on example of O(max^2), but in this case i is multiplied by two on each call. How could the cost be calculated in this case?

Body:
while loop will run in log(max). Each iteration of the loop will run in O(i). Hence, the total time complexity is:

T(max) = O(1 + 2 + 2^2 + ... + 2^{log(max)}) = O(2^{log(max) + 1} - 1)

As we know that 2^{log(max)} = max, T(max) = Theta(max).


问:
Regex string after one or two words
I try to get last string after one or two defined words. This is my actual Regex:

```<code> /(?i)(?:(ticket|number))\.?\s?\:?\s*?([^\s]+)
</code>```

And I want to get the ticket number from this list of possibilities:

```<code>ticket number A2-177653
ticket : A2-177653
number 454544
</code>```

Therefore the regex can have "ticket" or "number" or "ticket number"

Can anybody help me?

Thanks

答:
You may use

```<code>(?i)(?:ticket(?:\s+number)?|number)\.?\s?:?\s*(\S+)
</code>```

See the regex demo

Details

(?i) - case insensitive modifier

(?:ticket(?:\s+number)?|number) - ticket, number or ticket number

\.? - an optional .

\s?:?\s* - an optional whitespace, an optional : and then 0+ whitespaces

(\S+) - Group 1: any one or more non-whitespace chars.

Title: Regex string after one or two words

Body:
I try to get last string after one or two defined words. This is my actual Regex:

 /(?i)(?:(ticket|number))\.?\s?\:?\s*?([^\s]+)

And I want to get the ticket number from this list of possibilities:

ticket number A2-177653
ticket : A2-177653
number 454544

Therefore the regex can have "ticket" or "number" or "ticket number"

Can anybody help me?

Thanks

Body:
You may use

(?i)(?:ticket(?:\s+number)?|number)\.?\s?:?\s*(\S+)

See the regex demo

Details

(?i) - case insensitive modifier

(?:ticket(?:\s+number)?|number) - ticket, number or ticket number

\.? - an optional .

\s?:?\s* - an optional whitespace, an optional : and then 0+ whitespaces

(\S+) - Group 1: any one or more non-whitespace chars.


问:
How to find the size of a C string without using a while loop?
I was recently trying to find the size of an input C string buffer for using it in memcpy to copy the contents of the input buffers to the output buffer without overlapping.
The following is the code snippet.

```<code>char * func(char *buff1, char *buff2, char *outbuff)
{
    int size = 0;
    while(*buff1 != '\0')
     {
       size++;
       buff1++;
     }
   memcpy(outbuff, buff1, sizeof(char)*size);
   memcpy(outbuff + size, buff2, sizeof(char)*size);
   return outbuff;
}
</code>```

However, I found out that this is a very inefficient way of finding size. If you guys know about any other alternatives it would be very helpful to me.

Edit: I am not allowed to pass their sizes as separate parameters.

答:
C strings are null terminated arrays of characters. If your function handles legitimate C strings, then you should use the standard string library.
For example, strlen(src), strcpy(dst,src) etc. Since it is sometimes the case that strings violate the property of ending with 0, the standard string library offers functions like strncpy(dst,src,n) where copy is performed until the null terminating character, as long as the number of characters copied is at most n.

Body:
I was recently trying to find the size of an input C string buffer for using it in memcpy to copy the contents of the input buffers to the output buffer without overlapping.
The following is the code snippet.

char * func(char *buff1, char *buff2, char *outbuff)
{
    int size = 0;
    while(*buff1 != '\0')
     {
       size++;
       buff1++;
     }
   memcpy(outbuff, buff1, sizeof(char)*size);
   memcpy(outbuff + size, buff2, sizeof(char)*size);
   return outbuff;
}

However, I found out that this is a very inefficient way of finding size. If you guys know about any other alternatives it would be very helpful to me.

Edit: I am not allowed to pass their sizes as separate parameters.


问:
How to set high priority of push notification which is send to NotificationHub
I have successfully implemented Azure Function, which sends push notifications to NotificationHub for Android, iOS and UWP. During the testing I discovered that when Android device is in Doze mode push notification is not delivered on lock screen. It is only delivered when I unlock the phone.

I found out this stackoverflow post, which helped me to fix it with method SendFcmNativeNotificationAsync. I used this code:

```<code>string payload = @"{
                    ""data"":{
                        ""notificationtype"":""sap"",
                        ""title"":""value2"",
                    },
                        ""priority"":""high""
                    }";

await hub.SendFcmNativeNotificationAsync(payload);
</code>```

However my implementation using SendNotificationAsync method which works for all 3 platforms, but not in Doze mode. This is my code to send notification:

```<code>Dictionary<string, string> templateParameters = new Dictionary<string, string>();

templateParameters["alert"] = "Test";
templateParameters["title"] = "Whosap";

var notification = new TemplateNotification(templateParameters);
await hub.SendNotificationAsync(notification);
</code>```

I tried to set header of notification:

```<code>var headers = new Dictionary<string, string> { { "android", @"{""priority"": ""high""}" } };
notification.Headers = headers;
</code>```

But this didn't work. Does anybody know how to set priority in TemplateNotification object and send it with SendNotificationAsync method?

This is how I force/unforce device to doze mode:

```<code>adb shell dumpsys deviceidle force-idle
adb shell dumpsys deviceidle unforce
</code>```

答:
Based on your comment that you want to have "only informative push notifications", unfortunately, you cannot force the phone to show your notifications every time. This doesn't come as a limitation to either Xamarin, or even Azure Functions in that matter. Even some of Google's own applications behave the same.

Looking at Doze checklist:

If your users must see a notification right away, make sure to use an FCM high priority message

Even if we look at Using FCM to interact with your app while the device is idle:

FCM is optimized to work with Doze and App Standby idle modes by means of high-priority FCM messages. FCM high-priority messages let you reliably wake your app to access the network, even if the user’s device is in Doze or the app is in App Standby mode. In Doze or App Standby mode, the system delivers the message and gives the app temporary access to network services and partial wakelocks, then returns the device or app to the idle state.

So far it all looks like that if you decide to use High priority messages, everything should work fine. However, that's not the whole story. You are correct in setting the priority to high "priority":"high". Unfortunately, there are some caveats to this setting (from docs):

High priority messages generally should result in user interaction with your app or its notifications. If FCM detects a pattern in which they don't, your messages may be de-prioritized.

What this means is that if you are sending only an informative notification, it won't be enough to wake the device from Doze mode and show the notification. There checks/restrictions got even tighter from Android P. Read about app standby buckets here.

The good thing is that exiting Doze mode comes in a form of various events/interactions:

As soon as the user wakes the device by moving it, turning on the screen, or connecting a charger, the system exits Doze and all apps return to normal activity.

At least on the phones that I have tried, in a normal every-day scenario, the notifications are being suspended during either your night sleep, or when the device is sitting there without any interactions/movements, etc.

However, if you really need to deliver every notification and it is crucial to the UX, then you have 2 options:

If you want to have no user interaction - set the priority to high and simply hope that the system will occasionally show some of the notifications (during the maintenance window probably). Not the best way, but by default it may work from time to time.

If you want to guarantee that the notifications will pop-up, then have some screen describing the issue to the user and then navigate the user to Settings -> Apps & notifications --> Advanced --> Special app access --> Battery optimisation. Then he/she can select your app and manually set it to Don't optimise. Keep in mind that this is not considered a best practice and: a) the user shouldn't know about the consequences from this action and b) it is better to leave everything to the OS in order for it to work as intended.

To sum up, you don't have to set your notification's priority to high, because the OS will see that it a simple informative notification and it will now wake the phone. Keep in mind that, when the phone goes into "deep sleep" Doze mode, it shouldn't and mustn't wake for an informative notifications, so there's no point in trying - that's by design. Otherwise, every other developer can set its notification priority to high and the phone may never go to Doze mode, which will make the feature useless.

Body:
I have successfully implemented Azure Function, which sends push notifications to NotificationHub for Android, iOS and UWP. During the testing I discovered that when Android device is in Doze mode push notification is not delivered on lock screen. It is only delivered when I unlock the phone.

I found out this stackoverflow post, which helped me to fix it with method SendFcmNativeNotificationAsync. I used this code:

string payload = @"{
                    ""data"":{
                        ""notificationtype"":""sap"",
                        ""title"":""value2"",
                    },
                        ""priority"":""high""
                    }";

await hub.SendFcmNativeNotificationAsync(payload);

However my implementation using SendNotificationAsync method which works for all 3 platforms, but not in Doze mode. This is my code to send notification:

Dictionary<string, string> templateParameters = new Dictionary<string, string>();

templateParameters["alert"] = "Test";
templateParameters["title"] = "Whosap";

var notification = new TemplateNotification(templateParameters);
await hub.SendNotificationAsync(notification);

I tried to set header of notification:

var headers = new Dictionary<string, string> { { "android", @"{""priority"": ""high""}" } };
notification.Headers = headers;

But this didn't work. Does anybody know how to set priority in TemplateNotification object and send it with SendNotificationAsync method?

This is how I force/unforce device to doze mode:

adb shell dumpsys deviceidle force-idle
adb shell dumpsys deviceidle unforce


问:
Entity Framework 4 View Generation - Embedding files question and what about Source Control (TFS)
I am pre-generating views for a class project with an Entity Framework 4 edmx that is consumed by an asp.net application.

The resources I have used as reference are:

http://blog.willbeattie.net/2010/04/pre-generating-views-in-entity.html
and
http://msdn.microsoft.com/en-us/library/bb896240.aspx

The problem I am having relates to source control and also brings up another question about embedding the csdl/msl/ssdl files into the assembly. The articles above dictate the need to embed the aforementioned resources into the assembly by including them in the project and setting the files to be embedded.

But that leads me to wonder, since these files are being generated on build and copied over after, wouldn't the assembly always contain the last version of the csdl/msl/ssdl files? Because these files are generated on build and marked in the project to be embedded it would seem the files are embedded into the assembly are the ones previously generated on the previous build.

The heart of my issue concerns source control. If I include the csdl/msl/ssdl files in source control every time the project is taken down it won't build because these files will be marked as read only and Visual Studio will error when the post build process tries to copy the newly generated files over the files brought down from source control which are marked as read only. Due to the fact that these files are required for building the project but not generated until after the project is built I'm not currently seeing how I can successfully not check the csdl/msl/ssdl files into source control only keeping the reference to them in the project file there. This works for the Views.cs file which is generated on pre build but not the csdl/msl/ssdl files that are copied over on post build.

答:
I create my *.views.cs via a t4 template that I found on MSDN.

This negates all the pre/post build events and simplified the process. Also there is no problem with source control.
The tt file is totally generic and can be reused for any edmx by simply renaming it.

Hope it helps...

ContentLicense: CC BY-SA 2.5