问:
How can I asynchronously capture output from a long-running Python subprocess
For a test I want to start a long-running Python 3 script on Linux, capture some of its output, check that it's as expected and kill it again.

I'm just trying to get the general framework working for now.

When I run the following code, I would expect the output to include line = "0" -- the python script just prints out an increasing sequence of integers, one per second. Instead, that for loop is skipped completely.

```<code>import subprocess
from tempfile import NamedTemporaryFile
import time
import unittest

import asynchronousfilereader

class TestProcessSpawning(unittest.TestCase):
    def test_spawning_counter(self):
        counter_code = \
"""
import time
i = 0
while True:
    print(i)
    i = i + 1
    time.sleep(1)
"""

        with NamedTemporaryFile(mode="w", suffix='.py', delete=False)\
                as temp_file:
            temp_file.write(counter_code)
            file_name = temp_file.name

            # proc = subprocess.Popen(['ping', 'localhost'],
            #                         stdout=subprocess.PIPE, close_fds=True)
            proc = subprocess.Popen(['python3', file_name],
                                    stdout=subprocess.PIPE, close_fds=True)

            time.sleep(3)

            assert proc.returncode is None  # None => still running

            reader = asynchronousfilereader.AsynchronousFileReader(proc.stdout)

            time.sleep(3)  # give it a chance?

            for line in reader.readlines():
                print('line = "{}"'.format(line))
                break  # just grab first one

            proc.kill()
</code>```

However, if I change ['python3', file_name] to ['ping', 'localhost'] I do get a line of output from ping (I'm running on Linux so ping keeps producing output until you stop it).

Any idea why this seems to work ok for other types of subprocess but not for python?

Notes:

this code uses the asynchronousfilereader available from pip

if I just run python3 <temp_file_name> in a shell, the script runs as expected, printing 0, 1, 2, ...

the process return code of None after a few seconds suggests the process gets run (i.e. doesn't just crash)

I have tried running it through unbuffer as suggested here: the output did not appear

I tried passing bufsize=1 to Popen: the output did not appear

if I include the -v flag I get lots of output, including this, which suggests python is trying to run interactively even though I've provided a file name:

Python 3.5.2 (default, Nov 23 2017, 16:37:01)

[GCC 5.4.0 20160609] on linux

Type "help", "copyright", "credits" or "license" for more information.

答:
You need to flush the file you write:

```<code>with NamedTemporaryFile(mode="w", suffix='.py', delete=False) as temp_file:
    temp_file.write(counter_code)
    temp_file.flush()
</code>```

Your program is too short to ever make it out of the buffer otherwise, and you are running an empty file.

I'd also make sure the program then flushes on every write; either run python3 -u for unbuffered stdout or use flush=True on every print. That way you don't have to add so many sleeps in your parent program.

With these changes, the unittest prints

```<code>line = "b'0\n'"
</code>```

and several warnings about the subprocess still running and the stdout buffer still being open before completing.

Body:
For a test I want to start a long-running Python 3 script on Linux, capture some of its output, check that it's as expected and kill it again.

I'm just trying to get the general framework working for now.

When I run the following code, I would expect the output to include line = "0" -- the python script just prints out an increasing sequence of integers, one per second. Instead, that for loop is skipped completely.

import subprocess
from tempfile import NamedTemporaryFile
import time
import unittest

import asynchronousfilereader

class TestProcessSpawning(unittest.TestCase):
    def test_spawning_counter(self):
        counter_code = \
"""
import time
i = 0
while True:
    print(i)
    i = i + 1
    time.sleep(1)
"""

        with NamedTemporaryFile(mode="w", suffix='.py', delete=False)\
                as temp_file:
            temp_file.write(counter_code)
            file_name = temp_file.name

            # proc = subprocess.Popen(['ping', 'localhost'],
            #                         stdout=subprocess.PIPE, close_fds=True)
            proc = subprocess.Popen(['python3', file_name],
                                    stdout=subprocess.PIPE, close_fds=True)

            time.sleep(3)

            assert proc.returncode is None  # None => still running

            reader = asynchronousfilereader.AsynchronousFileReader(proc.stdout)

            time.sleep(3)  # give it a chance?

            for line in reader.readlines():
                print('line = "{}"'.format(line))
                break  # just grab first one

            proc.kill()

However, if I change ['python3', file_name] to ['ping', 'localhost'] I do get a line of output from ping (I'm running on Linux so ping keeps producing output until you stop it).

Any idea why this seems to work ok for other types of subprocess but not for python?

Notes:

this code uses the asynchronousfilereader available from pip

if I just run python3 <temp_file_name> in a shell, the script runs as expected, printing 0, 1, 2, ...

the process return code of None after a few seconds suggests the process gets run (i.e. doesn't just crash)

I have tried running it through unbuffer as suggested here: the output did not appear

I tried passing bufsize=1 to Popen: the output did not appear

if I include the -v flag I get lots of output, including this, which suggests python is trying to run interactively even though I've provided a file name:

Python 3.5.2 (default, Nov 23 2017, 16:37:01)

[GCC 5.4.0 20160609] on linux

Type "help", "copyright", "credits" or "license" for more information.

Body:
You need to flush the file you write:

with NamedTemporaryFile(mode="w", suffix='.py', delete=False) as temp_file:
    temp_file.write(counter_code)
    temp_file.flush()

Your program is too short to ever make it out of the buffer otherwise, and you are running an empty file.

I'd also make sure the program then flushes on every write; either run python3 -u for unbuffered stdout or use flush=True on every print. That way you don't have to add so many sleeps in your parent program.

With these changes, the unittest prints

line = "b'0\n'"

and several warnings about the subprocess still running and the stdout buffer still being open before completing.


来源: stackexchange

问:
"printf" in microcontroller, what is it for?
I see "printf" instruction in sample codes of c language for microcontroller particularly in 8051. Since microcontrollers has no fixed output display what is the use of the "printf" instruction? </p>

答:
Some development tools allows you to use printf given an implementation of putchar or putch. In such tools, since you have this function sending characters to some device, printf will show messages on that device.

You just have to do the correct device initialization, implement putchar, putch or such (check your compiler/lib docs) and voilá! Your printf will behave the way you're expecting.

PS: Some compilers/libraries do not implement all printf format specifiers. Again, check your docs.

ContentLicense: CC BY-SA 2.5


问:
table keeps resizing not overflow
I'm trying to make my table overflow on the x axis instead of resizing once it gets past 900px browser width.

Here is my code:

```<code><div className='jobTableTop'>
<table className='jobsTable'>
  <tbody>
    <tr className='jobsTableHeader'>
      <td style={{"color": "lightgray"}}>BY</td>
      <td style={{"color": "lightgray"}}>JOB TITLE</td>
      <td style={{"color": "lightgray"}}>OPTION</td>
      <td style={{"color": "lightgray"}}>LOCATION</td>
      <td style={{"color": "lightgray"}}>WAGE</td>
      <td style={{"padding-top": "0px"}}></td>
    </tr>
    {this.props.dataToShow.map(function (item, index) {
      return (
        (index >= minItem && index <= maxItem) ?
          <tr key={item.id}>
            <td>{item.company}</td>
            <td>{item.title}</td>
            <td>{item.option}</td>
            <td>{item.location}</td>
            <td>{item.wage}</td>
            <td style={{"padding-top": "0px"}}>
              <a href={'/job-detail/' + item.id}>
                <Button className={classes.button} style={{"font-size": "20px"}} raised color="accent">
                  Apply
                </Button>
              </a>
            </td>
          </tr>
          :
          ''
        )})}
      </tbody>
    </table>
   </div>
</code>```

that is the jsx/html code

here is the css:

```<code>@media screen and (max-width: 900px){
    .jobsTable{
        overflow: hidden;
    }
}
.jobsTable tr {
border-bottom: 1px solid lightgray;
display: flex;
}
.jobsTable tr td {
    width: 16.6%;
    height: 40px;
    padding-top: 20px;
    font-size: 20px;
    vertical-align: middle;
    color: black;
}
</code>```

so when it goes under 900px i want it so that theres a scroll bar instead of the table going smaller no matter what i seem to do nothing makes it do this. Im trying to make it mobile compatible without making a separate version of the site.

edit changed:

all i changed was this.

```<code>.jobTableTop {
    width: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
}
</code>```

i have to make the webpage around 750px instead of 900px. how would i achieve said goal.

答:
All you need to need to do little change in your CSS code as below. Additionally, you can also define width: 100%; if you want to make the full available space used by the table. I have also added this code in CSS

```<code>@media screen and (max-width: 900px){
  .jobsTable{
    width: 100%;
    overflow-x: auto;
  }
}
</code>```

fixed code section not being all in grey -Andy

ContentLicense: CC BY-SA 3.0

Title: table keeps resizing not overflow

Body:
I'm trying to make my table overflow on the x axis instead of resizing once it gets past 900px browser width.

Here is my code:

      BY
      JOB TITLE
      OPTION
      LOCATION
      WAGE

    {this.props.dataToShow.map(function (item, index) {
      return (
        (index >= minItem && index <= maxItem) ?

            {item.company}
            {item.title}
            {item.option}
            {item.location}
            {item.wage}

                <Button className={classes.button} style={{"font-size": "20px"}} raised color="accent">
                  Apply
                </Button>

          :
          ''
        )})}

that is the jsx/html code

here is the css:

@media screen and (max-width: 900px){
    .jobsTable{
        overflow: hidden;
    }
}
.jobsTable tr {
border-bottom: 1px solid lightgray;
display: flex;
}
.jobsTable tr td {
    width: 16.6%;
    height: 40px;
    padding-top: 20px;
    font-size: 20px;
    vertical-align: middle;
    color: black;
}

so when it goes under 900px i want it so that theres a scroll bar instead of the table going smaller no matter what i seem to do nothing makes it do this. Im trying to make it mobile compatible without making a separate version of the site.

edit changed:

all i changed was this.

.jobTableTop {
    width: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
}

i have to make the webpage around 750px instead of 900px. how would i achieve said goal.

Body:
All you need to need to do little change in your CSS code as below. Additionally, you can also define width: 100%; if you want to make the full available space used by the table. I have also added this code in CSS

@media screen and (max-width: 900px){
  .jobsTable{
    width: 100%;
    overflow-x: auto;
  }
}

fixed code section not being all in grey -Andy


问:
Switch by class (instanceof) in PHP
It is possible to replace block of if( .. instanceof ...), elseif(... instanceof ...), ...  with switch?

For example:

```<code><?php
$class = ..... //some class

if($class instanceof SomeClass) {
    //do something
} elseif($class instanceof SomeAnotherClass) {
    //do something else
}
</code>```

答:
The following is more correct:

```<code>$class = get_class($objectToTest);

switch($class) {
    case TreeRequest::class:
        echo "tree request";
        break;
    case GroundRequest::class:
        echo "ground request";
        break;
}
</code>```

This way namespaces are properly compared (you don't have to type them out) and if anything changes such as the namespace or class name you'll get a decent IDE error informing you that your code is broken.

Title: Switch by class (instanceof) in PHP

Body:
It is possible to replace block of if( .. instanceof ...), elseif(... instanceof ...), ...  with switch?

For example:

<?php
$class = ..... //some class

if($class instanceof SomeClass) {
    //do something
} elseif($class instanceof SomeAnotherClass) {
    //do something else
}

Body:
The following is more correct:

$class = get_class($objectToTest);

switch($class) {
    case TreeRequest::class:
        echo "tree request";
        break;
    case GroundRequest::class:
        echo "ground request";
        break;
}

This way namespaces are properly compared (you don't have to type them out) and if anything changes such as the namespace or class name you'll get a decent IDE error informing you that your code is broken.


问:
R- current column minus sum of next x other columns till condition is met
I try to get the sum column done with R but it does not work.
Its actually simple to illustrate:
sum = points of current row - sum(bonus rows up till the first participation equals to 0) I would prefer a crisp and short code if it is possible.

```<code>Pupil   participation   bonus   points
  2           55          6       10
  2           33          3       10
  2           88          9       10
  2           44          8       10
  2           44          0       10
  2           66          7       10
  2            0          0       10
  1           22          11      10
  1           33          12      10
  1           33          13      10
  1            3          13      10
  1           44          1       10
  1            0          3       10
  1            0          0       10
</code>```

to

```<code>Pupil   participation   bonus   points   sum
  2           55          6       10      10-(6+3+9+8+0+7)
  2           33          3       10      10-(3+9+8+0+7)
  2           88          9       10      10-(9+8+0+7)
  2           44          8       10      10-(8+0+7)
  2           44          0       10      10-(0+7)
  2           66          7       10      10-(7)
  2            0          0       0        0
  1           22          11      10      10-(11+12+13+13+1)
  1           33          12      10      10-(12+13+13+1)
  1           33          13      10      10-(13+13+1)
  1            3          13      10      10-(13+1
  1           44          1       10      10-(1)
  1            0          3       10       0
  1            0          0       0        0
</code>```

Thanks

答:
We can use tidyverse

```<code>library(dplyr)
library(purrr)
df1 %>%
    group_by(Pupil) %>%
    mutate(points = replace(points, tail(which(participation == 0), 1), 0),
     bonus = bonus *(bonus != 0 & points != 0),
     Sum = (points - (accumulate_right(bonus*(participation != 0),
             `+`)))* (participation !=0))
# A tibble: 14 x 5
# Groups:   Pupil [2]
#   Pupil participation bonus points   Sum
#   <int>         <int> <int>  <dbl> <dbl>
# 1     2            55     6     10   -23
# 2     2            33     3     10   -17
# 3     2            88     9     10   -14
# 4     2            44     8     10    -5
# 5     2            44     0     10     3
# 6     2            66     7     10     3
# 7     2             0     0      0     0
# 8     1            22    11     10   -40
# 9     1            33    12     10   -29
#10     1            33    13     10   -17
#11     1             3    13     10    -4
#12     1            44     1     10     9
#13     1             0     3     10     0
#14     1             0     0      0     0
</code>```

Body:
I try to get the sum column done with R but it does not work.
Its actually simple to illustrate:
sum = points of current row - sum(bonus rows up till the first participation equals to 0) I would prefer a crisp and short code if it is possible.

Pupil   participation   bonus   points
  2           55          6       10
  2           33          3       10
  2           88          9       10
  2           44          8       10
  2           44          0       10
  2           66          7       10
  2            0          0       10
  1           22          11      10
  1           33          12      10
  1           33          13      10
  1            3          13      10
  1           44          1       10
  1            0          3       10
  1            0          0       10

to

Pupil   participation   bonus   points   sum
  2           55          6       10      10-(6+3+9+8+0+7)
  2           33          3       10      10-(3+9+8+0+7)
  2           88          9       10      10-(9+8+0+7)
  2           44          8       10      10-(8+0+7)
  2           44          0       10      10-(0+7)
  2           66          7       10      10-(7)
  2            0          0       0        0
  1           22          11      10      10-(11+12+13+13+1)
  1           33          12      10      10-(12+13+13+1)
  1           33          13      10      10-(13+13+1)
  1            3          13      10      10-(13+1
  1           44          1       10      10-(1)
  1            0          3       10       0
  1            0          0       0        0

Thanks

Body:
We can use tidyverse

library(dplyr)
library(purrr)
df1 %>%
    group_by(Pupil) %>%
    mutate(points = replace(points, tail(which(participation == 0), 1), 0),
     bonus = bonus *(bonus != 0 & points != 0),
     Sum = (points - (accumulate_right(bonus*(participation != 0),
             `+`)))* (participation !=0))
# A tibble: 14 x 5
# Groups:   Pupil [2]
#   Pupil participation bonus points   Sum
#   <int>         <int> <int>  <dbl> <dbl>
# 1     2            55     6     10   -23
# 2     2            33     3     10   -17
# 3     2            88     9     10   -14
# 4     2            44     8     10    -5
# 5     2            44     0     10     3
# 6     2            66     7     10     3
# 7     2             0     0      0     0
# 8     1            22    11     10   -40
# 9     1            33    12     10   -29
#10     1            33    13     10   -17
#11     1             3    13     10    -4
#12     1            44     1     10     9
#13     1             0     3     10     0
#14     1             0     0      0     0


问:
Multi-tenant authentication, IMustHaveTenant entity in ASP.NET Boilerplate Module Zero

Multi-Tenant Authentication

I have created a new tenant from the swagger UI as an admin and I can check in the data the tenant created successfully together with admin account.

Now how do I login as the admin of the newly created tenant?

Cos I tried Token-authenticating via Postman, specifying tenancyName in the request body and it only seems to authenticate the admin from default tenant - even when I put in rubbish in the tenancyName field, it won't detect any error or exception.

I check the configuration value in the CoreModule.cs and MultiTenancyEnabled has been set to true

Entity Relation with Tenant

Also I would like to relate one of my entity with the tenant entity. So I based the class on IMustHaveTenant interface along side FullAuditedEntity like this:

```<code>public class Rule: FullAuditedEntity, IMustHaveTenant
{
    public string columnA { get; set; }
    public string columnB { get; set; }
    public string columnC { get; set; }
    public int TenantId { get; set; }
}
</code>```

Is it enough or do I have to further put in any codes in the DbContext?

答:
Now how do I login as the admin of the newly created tenant?

For Token Based Authentication, send the tenant id in the Abp.TenantId header.

In Postman, click on Headers, add the Key as Abp.TenantId and the Value as your tenant id. If you just created a new tenant, that would be 2 as there is a Default tenant with id 1.

Also I would like to relate one of my entity with the tenant entity. [...] Is it enough or do I have to further put in any codes in the DbContext?

You have to add a DbSet in your DbContext:

public class MyDbContext : AbpDbContext
{
    public DbSet<Product> Products { get; set; }

    public MyDbContext(DbContextOptions<MyDbContext> options)
        : base(options)
    {
    }
}
```

Body:
Multi-Tenant Authentication

I have created a new tenant from the swagger UI as an admin and I can check in the data the tenant created successfully together with admin account.

Now how do I login as the admin of the newly created tenant?

Cos I tried Token-authenticating via Postman, specifying tenancyName in the request body and it only seems to authenticate the admin from default tenant - even when I put in rubbish in the tenancyName field, it won't detect any error or exception.

I check the configuration value in the CoreModule.cs and MultiTenancyEnabled has been set to true

Entity Relation with Tenant

Also I would like to relate one of my entity with the tenant entity. So I based the class on IMustHaveTenant interface along side FullAuditedEntity like this:

public class Rule: FullAuditedEntity, IMustHaveTenant
{
    public string columnA { get; set; }
    public string columnB { get; set; }
    public string columnC { get; set; }
    public int TenantId { get; set; }
}

Is it enough or do I have to further put in any codes in the DbContext?


问:
Second view of ViewSwitcher doesn't show up
I'm trying to add a simple ViewSwitcher with two ImageViews as children. But no matter what I try, the second child remains invisible. In the XML layout preview in Android Studio it looks like the second child has a size 0x0 pixels. The first child shows up just fine. What's the problem here?

```<code><ViewSwitcher
    android:id="@+id/viewSwitcher"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/view1"
        android:scaleType="fitXY"
        android:src="@drawable/view_1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ImageView
        android:id="@+id/view2"
        android:scaleType="fitXY"
        android:src="@drawable/view_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</ViewSwitcher>
</code>```

I'm switching beween the two views simply using gradientViewSwitcher.showNext().

答:
Try use a LinearLayout and wrap_conent
like this:

```<code> <!-- ViewSwitcher with two ImageView-->
 <ViewSwitcher
 android:id="@+id/viewSwitcher"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical">

       <ImageView
       android:id="@+id/view1"
       android:scaleType="fitXY"
       android:src="@drawable/view_1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"/>

       <ImageView
       android:id="@+id/view2"
       android:scaleType="fitXY"
       android:src="@drawable/view_2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"/>

    </LinearLayout>
     </ViewSwitcher>
</code>```

Body:
I'm trying to add a simple ViewSwitcher with two ImageViews as children. But no matter what I try, the second child remains invisible. In the XML layout preview in Android Studio it looks like the second child has a size 0x0 pixels. The first child shows up just fine. What's the problem here?

<ViewSwitcher
    android:id="@+id/viewSwitcher"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/view1"
        android:scaleType="fitXY"
        android:src="@drawable/view_1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ImageView
        android:id="@+id/view2"
        android:scaleType="fitXY"
        android:src="@drawable/view_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</ViewSwitcher>

I'm switching beween the two views simply using gradientViewSwitcher.showNext().

Body:
Try use a LinearLayout and wrap_conent
like this:

 <!-- ViewSwitcher with two ImageView-->
 <ViewSwitcher
 android:id="@+id/viewSwitcher"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical">

       <ImageView
       android:id="@+id/view1"
       android:scaleType="fitXY"
       android:src="@drawable/view_1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"/>

       <ImageView
       android:id="@+id/view2"
       android:scaleType="fitXY"
       android:src="@drawable/view_2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"/>

    </LinearLayout>
     </ViewSwitcher>


问:
How do I associate metadata with a DeepZoom SubImage?
I'm trying to sort through a collection of DeepZoom sub-images based on arbitrary data associated with each image. The sub-images get loaded automagically through an XML file generated by DeepZoom Composer. I don't see a clear way to associate arbitrary data with a DeepZoom sub-image.

The solutions that seem most obvious to me are brittle and don't scale well. Ideally, I'd like to put the relevant data in the generated XML file, but I'd lose that information on the next set of generated images.

Is there a well-established way of accomplishing this goal?

答: Metadata.xml has a Tag property that can be associated with each image. Hurray!</p>

OwnerDisplayName: Gabriel Isenberg


问:
Compiling MPIR with Visual C++ 2010
I'm trying to compile MPIR (the Windows-friendly fork of GMP) from the command line. My setup is pretty bog standard, Windows Vista 32-bit, Visual C++ 2010 express edition, and I'm just going for a completely vanilla 32-bit static library build, not trying to use the IDE. The information I could find with a Google search says:

Install the appropriate version of yasm.

Go into build.vc10

Configure.bat

Make.bat

I managed to get as far as step 3 seeming to work, and past the first obstacle in step 4, but now it's tripping up on this line in make.bat:

```<code>%MS_BUILD% gen-mpir\gen-mpir.vcxproj /p:Platform=Win32;Configuration=Release
</code>```

As far as the searches I've run can determine, there is no gen-mpir anywhere in the entire directory tree, nor any other reference to such. What am I missing?

答: Answer from the good folk on the mpir-devel mailing list: http://groups.google.com/group/mpir-devel/browse_thread/thread/488233bc8face88a</p>

Title: Compiling MPIR with Visual C++ 2010

Body:
I'm trying to compile MPIR (the Windows-friendly fork of GMP) from the command line. My setup is pretty bog standard, Windows Vista 32-bit, Visual C++ 2010 express edition, and I'm just going for a completely vanilla 32-bit static library build, not trying to use the IDE. The information I could find with a Google search says:

Install the appropriate version of yasm.

Go into build.vc10

Configure.bat

Make.bat

I managed to get as far as step 3 seeming to work, and past the first obstacle in step 4, but now it's tripping up on this line in make.bat:

%MS_BUILD% gen-mpir\gen-mpir.vcxproj /p:Platform=Win32;Configuration=Release

As far as the searches I've run can determine, there is no gen-mpir anywhere in the entire directory tree, nor any other reference to such. What am I missing?


问:
How to send model data from view to api controller using ajax
I am trying to send the value from my this view to given API controller.It is working when i hard-code the json data.I am unable to send the data of id and brandname when i press the button since it is in table. How do I make it work?Please help

```<code>  <table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Brand.BrandName)
        </th>
                <th>
            @Html.DisplayNameFor(model => model.ProductName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>

        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Brand.BrandName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ProductName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Price)
        </td>
      <td><input type="button" id="Save" /></td>

    </tr>
}

</table>
@section scripts {
<script>
    $(document).ready(function () {
        $("#Save").click(function () {

            var brand = { 'id':1, 'brandname': 'abc' }

            $.ajax({
                url: 'http://localhost:51429/api/brands',
                type: 'POST',
                dataType: 'json',
                data: brand,
                success: function (data, textStatus, xhr) {
                    console.log(data);
                },
                error: function (xhr, textStatus, errorThrown) {
                    console.log('Error in Operation');
                }
            });

        });
    });

   </script>
    }
</code>```

I have a brand API. And it post API controller is

```<code>    [HttpPost]
    public IHttpActionResult Post([FromBody]Brands brand)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        db.Brands.Add(brand);
        db.SaveChanges();

        return CreatedAtRoute("DefaultApi", new { id = brand.Id }, brand);

    }
</code>```

答:
There are many ways to go about this. One would be to select the cells and extract the data to send it later on:</p>

```<code>$("#Save").click(function () {
  var $button = $(this);
  var $cells = $button.closest("tr").find("td");

  var brand = {..., 'brandname': $cells.eq(0).html(), ...}

  ...
</code>```

Body:
I am trying to send the value from my this view to given API controller.It is working when i hard-code the json data.I am unable to send the data of id and brandname when i press the button since it is in table. How do I make it work?Please help

            @Html.DisplayNameFor(model => model.Brand.BrandName)

            @Html.DisplayNameFor(model => model.ProductName)

            @Html.DisplayNameFor(model => model.Price)

@foreach (var item in Model) {

            @Html.DisplayFor(modelItem => item.Brand.BrandName)

            @Html.DisplayFor(modelItem => item.ProductName)

            @Html.DisplayFor(modelItem => item.Price)

      <input type="button" id="Save" />

}

@section scripts {

    }

I have a brand API. And it post API controller is

    [HttpPost]
    public IHttpActionResult Post([FromBody]Brands brand)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        db.Brands.Add(brand);
        db.SaveChanges();

        return CreatedAtRoute("DefaultApi", new { id = brand.Id }, brand);

    }

Body:
There are many ways to go about this. One would be to select the cells and extract the data to send it later on:

$("#Save").click(function () {
  var $button = $(this);
  var $cells = $button.closest("tr").find("td");

  var brand = {..., 'brandname': $cells.eq(0).html(), ...}

  ...


问:
Angular 2 material autocomplete selected value
I have autocomplete input

```<code><div formArrayName="addresses">
  <div class="row"
       *ngFor="let itemrow of searchForm.controls.addresses.controls; let i=index"
       [formGroupName]="i">
    <mat-form-field>
      <input type="text"
             class="form-control" id="address"
             formControlName="address"
             matInput
             [matAutocomplete]="auto"
             (keyup)="getESRI($event.target.value)"
             (focusout)="bindLocation($event.target.value)">
      <mat-autocomplete #auto="matAutocomplete">
        <mat-option *ngFor="let option of testLocation"
                    [value]="option.text">
           {{ option.text }}
        </mat-option>
      </mat-autocomplete>
    </mat-form-field>
  </div>
</div>
</code>```

"testlocation":[{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true},{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true}]

When I'm trying add value [value]="option.magicKey it shows in the input option.magicKey when I select option. I need option.magicKey only as the value, and option.text as the input option. Otherwise how to add option.magicKey as parameter to bindLocation($event.target.value) function?

答:
Use [displayWith] attribute with auto complete field.

HTML FILE

```<code><input
  type="text"
  placeholder="Address"
  mdInput
  formControlName="address"
  [mdAutocomplete]="auto"
  (keyup)="onKeyUp()">
<md-autocomplete
  #auto="mdAutocomplete"
  [displayWith]="displayFn">
  <md-option *ngFor="let option of options"
    [value]="option">
    {{ option.text }}
  </md-option>
</md-autocomplete>
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have autocomplete input

    <mat-form-field>
      <input type="text"
             class="form-control" id="address"
             formControlName="address"
             matInput
             [matAutocomplete]="auto"
             (keyup)="getESRI($event.target.value)"
             (focusout)="bindLocation($event.target.value)">
      <mat-autocomplete #auto="matAutocomplete">
        <mat-option *ngFor="let option of testLocation"
                    [value]="option.text">
           {{ option.text }}
        </mat-option>
      </mat-autocomplete>
    </mat-form-field>

"testlocation":[{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true},{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true}]

When I'm trying add value [value]="option.magicKey it shows in the input option.magicKey when I select option. I need option.magicKey only as the value, and option.text as the input option. Otherwise how to add option.magicKey as parameter to bindLocation($event.target.value) function?

Body:
Use [displayWith] attribute with auto complete field.

HTML FILE

<input
  type="text"
  placeholder="Address"
  mdInput
  formControlName="address"
  [mdAutocomplete]="auto"
  (keyup)="onKeyUp()">
<md-autocomplete
  #auto="mdAutocomplete"
  [displayWith]="displayFn">
  <md-option *ngFor="let option of options"
    [value]="option">
    {{ option.text }}
  </md-option>
</md-autocomplete>


问:
Is there anything different between R.merge vs composing with rest operator?
Is there any advantage of use R.merge over composing with the rest operator?

```<code>const a = {name: 'john', job: 'developer'};
const b = {name: 'peter', commute: 'bike', address: {city: 'San Francisco'}};
const c = {...a, ...b};
console.log('rest', c);
const d = R.merge(a, b);
console.log('R.merge', d);
</code>```

c and d appear to be the same.

Are there any cases where the rest operator won't work while R.merge will?

答:
The current implementation of R.merge is effectively R.curry((l, r) => Object.assign({}, l, r)) (albeit polyfilled when necessary), so when fully applied it will behave the same as the rest operator in your example.

The main difference being that R.merge is curried, allowing for partial application. It can also be useful when operating in environments where the rest operator (or Object.assign) isn't available.

So if you don't require partial application and have the the rest operator natively available to you, then there is little benefit to use R.merge(a, b) over {...a, ...b}.

Body:
Is there any advantage of use R.merge over composing with the rest operator?

const a = {name: 'john', job: 'developer'};
const b = {name: 'peter', commute: 'bike', address: {city: 'San Francisco'}};
const c = {...a, ...b};
console.log('rest', c);
const d = R.merge(a, b);
console.log('R.merge', d);

c and d appear to be the same.

Are there any cases where the rest operator won't work while R.merge will?


问:
How to convert Python project into executable
I have a Python project that I want to convert into an executable. I have installed Pyinstaller. I only know how to convert one single script into .exe, but I have multiple packages with multiple python scripts.</p>

答:
The command line I used with success is:

```<code>pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py
</code>```

pyinstaller manages relatively well the multiple '.py' files that you import, no need to cite them. Under the 'add-data' option, you list the non-py files and in my example, the 'cprofiles_lmfit.py' file is the one containing the main.

But as indicated here need help to compile python with pyinstaller (and in few other posts), I am a beginner with pyinstaller. I was never able to use the 'theano' module and I did not optimize. I still have to test the suggestions in the answer.

Body:
The command line I used with success is:

pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py

pyinstaller manages relatively well the multiple '.py' files that you import, no need to cite them. Under the 'add-data' option, you list the non-py files and in my example, the 'cprofiles_lmfit.py' file is the one containing the main.

But as indicated here need help to compile python with pyinstaller (and in few other posts), I am a beginner with pyinstaller. I was never able to use the 'theano' module and I did not optimize. I still have to test the suggestions in the answer.


问:
How to optimize SQL query with two where clauses?
My query is something like this

```<code>SELECT * FROM tbl1
JOIN tbl2 ON something = something
WHERE 1 AND (tbl2.date = '$date' OR ('$date' BETWEEN tbl1.planA AND tbl1.planB ))
</code>```

When I run this query, it is considerably slower than for example this query

```<code>SELECT * FROM tbl1
JOIN tbl2 ON something = something
WHERE 1 AND ('$date' BETWEEN tbl1.planA AND tbl1.planB )
</code>```

or

```<code>SELECT * FROM tbl1
JOIN tbl2 ON something = something
WHERE 1 AND tbl2.date = '$date'
</code>```

In localhost, the first query takes about 0.7 second, the second query about 0.012 second and the third one 0.008 second.

My question is how do you optimize this? If currently I have 1000 rows in my tables and it takes 0.7 second to display the first query, it will take 7 seconds if I have 10.000 rows right? That's a massive slow down compared to second query (0.12 second) and third (0.08).

I've tried adding indexes, but the result is no different.

Thanks

Edit : This application will only work locally, so no need to worry about the speed over the web.

Sorry, I didn't include the EXPLAIN because my real query are much more complicated (about 5 joins). But the joins (I think) don't really matter, cos I've tried omitting them and still get approximately the same result as above.

The date belongs to tbl1, planA and planB belongs to tbl2. I've tried adding indexes to tbl1.date, tbl2.planA and tbl2.planB but the result is insignificant.

By schema do you mean MyISAM or InnoDB? It's MyISAM.

Okay, I'll just post my query straight away. Hopefully it's not that confusing.

```<code>SELECT *
FROM tb_joborder jo
LEFT JOIN tb_project p ON jo.project_id = p.project_id
LEFT JOIN tb_customer c ON p.customer_id = c.customer_id
LEFT JOIN tb_dispatch d ON jo.joborder_id = d.joborder_id
LEFT JOIN tb_joborderitem ji ON jo.joborder_id = ji.joborder_id
LEFT JOIN tb_mix m ON ji.mix_id = m.mix_id
WHERE dispatch_date = '2011-01-11'
OR '2011-01-11'
BETWEEN planA
AND planB
GROUP BY jo.joborder_id
ORDER BY customer_name ASC
</code>```

And the describe output

```<code>id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE  jo  ALL     NULL    NULL    NULL    NULL    453     Using temporary; Using filesort
1   SIMPLE  p   eq_ref  PRIMARY     PRIMARY     4   db_dexada.jo.project_id     1
1   SIMPLE  c   eq_ref  PRIMARY     PRIMARY     4   db_dexada.p.customer_id     1
1   SIMPLE  d   ALL     NULL    NULL    NULL    NULL    2048    Using where
1   SIMPLE  ji  ALL     NULL    NULL    NULL    NULL    455
1   SIMPLE  m   eq_ref  PRIMARY     PRIMARY     4   db_dexada.ji.mix_id     1
</code>```

答:
You can just use UNION to merge results of 2nd and 3d queries.

More about UNION.

Body:
My query is something like this

SELECT * FROM tbl1
JOIN tbl2 ON something = something
WHERE 1 AND (tbl2.date = '$date' OR ('$date' BETWEEN tbl1.planA AND tbl1.planB ))

When I run this query, it is considerably slower than for example this query

SELECT * FROM tbl1
JOIN tbl2 ON something = something
WHERE 1 AND ('$date' BETWEEN tbl1.planA AND tbl1.planB )

or

SELECT * FROM tbl1
JOIN tbl2 ON something = something
WHERE 1 AND tbl2.date = '$date'

In localhost, the first query takes about 0.7 second, the second query about 0.012 second and the third one 0.008 second.

My question is how do you optimize this? If currently I have 1000 rows in my tables and it takes 0.7 second to display the first query, it will take 7 seconds if I have 10.000 rows right? That's a massive slow down compared to second query (0.12 second) and third (0.08).

I've tried adding indexes, but the result is no different.

Thanks

Edit : This application will only work locally, so no need to worry about the speed over the web.

Sorry, I didn't include the EXPLAIN because my real query are much more complicated (about 5 joins). But the joins (I think) don't really matter, cos I've tried omitting them and still get approximately the same result as above.

The date belongs to tbl1, planA and planB belongs to tbl2. I've tried adding indexes to tbl1.date, tbl2.planA and tbl2.planB but the result is insignificant.

By schema do you mean MyISAM or InnoDB? It's MyISAM.

Okay, I'll just post my query straight away. Hopefully it's not that confusing.

SELECT *
FROM tb_joborder jo
LEFT JOIN tb_project p ON jo.project_id = p.project_id
LEFT JOIN tb_customer c ON p.customer_id = c.customer_id
LEFT JOIN tb_dispatch d ON jo.joborder_id = d.joborder_id
LEFT JOIN tb_joborderitem ji ON jo.joborder_id = ji.joborder_id
LEFT JOIN tb_mix m ON ji.mix_id = m.mix_id
WHERE dispatch_date = '2011-01-11'
OR '2011-01-11'
BETWEEN planA
AND planB
GROUP BY jo.joborder_id
ORDER BY customer_name ASC

And the describe output

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE  jo  ALL     NULL    NULL    NULL    NULL    453     Using temporary; Using filesort
1   SIMPLE  p   eq_ref  PRIMARY     PRIMARY     4   db_dexada.jo.project_id     1
1   SIMPLE  c   eq_ref  PRIMARY     PRIMARY     4   db_dexada.p.customer_id     1
1   SIMPLE  d   ALL     NULL    NULL    NULL    NULL    2048    Using where
1   SIMPLE  ji  ALL     NULL    NULL    NULL    NULL    455
1   SIMPLE  m   eq_ref  PRIMARY     PRIMARY     4   db_dexada.ji.mix_id     1


问:
Empty space on bottom of ScrollView
I'm trying to make an scrollable activity with a ConstraintLayout inside a ScrollView.

Supposed to be like this

But instead it shows an empty space at the bottom

Empty Space

On Android Studio Blueprint doesn't show anything there.

My XML is this:

```<code><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:layout_weight="1"
android:fillViewport="true">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.bonecadetrapo.imagensprincipal"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="25dp">

    <android.support.constraint.Guideline
        android:id="@+id/guideline10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="929dp" />

    <android.support.v7.widget.CardView
        android:id="@+id/cardview1"
        android:layout_width="164dp"
        android:layout_height="197dp"
        android:layout_marginBottom="300dp"
        android:layout_marginStart="17dp"
        android:layout_marginTop="8dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail"
                android:layout_width="164dp"
                android:layout_height="170dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="3dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="centerInside"
                app:srcCompat="@drawable/one" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="example 1" />

        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/cardview2"
        android:layout_width="164dp"
        android:layout_height="197dp"
        android:layout_marginBottom="300dp"
        android:layout_marginEnd="24dp"
        android:layout_marginStart="17dp"
        android:layout_marginTop="8dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.64"
        app:layout_constraintStart_toStartOf="@+id/guideline5"
        app:layout_constraintTop_toTopOf="@+id/guideline3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail2"
                android:layout_width="164dp"
                android:layout_height="170dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="3dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="centerInside"
                app:srcCompat="@drawable/two" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail2"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="example 2" />

        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/cardview5"
        android:layout_width="164dp"
        android:layout_height="160dp"
        android:layout_marginBottom="170dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.039"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/cardview3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail5"
                android:layout_width="164dp"
                android:layout_height="130dp"
                android:layout_marginLeft="6dp"
                android:layout_marginRight="6dp"
                android:layout_marginTop="6dp"
                android:adjustViewBounds="false"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:cropToPadding="false"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/exampletwo" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail5"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="Example 2" />

        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="384dp"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.Negocio">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.Negocio"
            app:title="Negocio">

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.constraint.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.06" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline5"
        android:layout_width="wrap_content"
        android:layout_height="929dp"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="204dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_end="17dp" />
</android.support.constraint.ConstraintLayout>
</code>```

I'm using Android Studio Beta 7 and Oreo.
I've tried every solution on google, none worked.

答:
I fixed it use this code</p>

```<code><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:layout_weight="1"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="com.bonecadetrapo.imagensprincipal"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="25dp">

        <android.support.constraint.Guideline
            android:id="@+id/guideline10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="929dp" />

        <android.support.v7.widget.CardView
            android:id="@+id/cardview1"
            android:layout_width="164dp"
            android:layout_height="197dp"
            android:layout_marginBottom="300dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline3"
            app:layout_constraintVertical_bias="0.0"
            android:layout_marginLeft="17dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail"
                    android:layout_width="164dp"
                    android:layout_height="170dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="3dp"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/one" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="example 1" />

            </RelativeLayout>

            <android.support.constraint.Guideline
                android:id="@+id/guideline6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_end="17dp" />
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/cardview2"
            android:layout_width="164dp"
            android:layout_height="197dp"
            android:layout_marginBottom="300dp"
            android:layout_marginEnd="24dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.64"
            app:layout_constraintStart_toStartOf="@+id/guideline5"
            app:layout_constraintTop_toTopOf="@+id/guideline3"
            app:layout_constraintVertical_bias="0.0"
            android:layout_marginRight="24dp"
            android:layout_marginLeft="17dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail2"
                    android:layout_width="164dp"
                    android:layout_height="170dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="3dp"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/two" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail2"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="example 2" />

            </RelativeLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/cardview5"
            android:layout_width="164dp"
            android:layout_height="160dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="24dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.039"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cardview2"
            app:layout_constraintVertical_bias="0.0">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail5"
                    android:layout_width="164dp"
                    android:layout_height="130dp"
                    android:layout_marginLeft="6dp"
                    android:layout_marginRight="6dp"
                    android:layout_marginTop="6dp"
                    android:adjustViewBounds="false"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:cropToPadding="false"
                    android:scaleType="fitXY"
                    app:srcCompat="@drawable/exampletwo" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail5"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="Example 2" />

            </RelativeLayout>
        </android.support.v7.widget.CardView>

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="384dp"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:title="Negocio">

            </android.support.v7.widget.Toolbar>

        </android.support.design.widget.AppBarLayout>

        <android.support.constraint.Guideline
            android:id="@+id/guideline3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.06" />

        <android.support.constraint.Guideline
            android:id="@+id/guideline5"
            android:layout_width="wrap_content"
            android:layout_height="929dp"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="204dp" />

    </android.support.constraint.ConstraintLayout>
</ScrollView>
</code>```

Title: Empty space on bottom of ScrollView

Body:
I'm trying to make an scrollable activity with a ConstraintLayout inside a ScrollView.

Supposed to be like this

But instead it shows an empty space at the bottom

Empty Space

On Android Studio Blueprint doesn't show anything there.

My XML is this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:layout_weight="1"
android:fillViewport="true">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.bonecadetrapo.imagensprincipal"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="25dp">

    <android.support.constraint.Guideline
        android:id="@+id/guideline10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="929dp" />

    <android.support.v7.widget.CardView
        android:id="@+id/cardview1"
        android:layout_width="164dp"
        android:layout_height="197dp"
        android:layout_marginBottom="300dp"
        android:layout_marginStart="17dp"
        android:layout_marginTop="8dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail"
                android:layout_width="164dp"
                android:layout_height="170dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="3dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="centerInside"
                app:srcCompat="@drawable/one" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="example 1" />

        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/cardview2"
        android:layout_width="164dp"
        android:layout_height="197dp"
        android:layout_marginBottom="300dp"
        android:layout_marginEnd="24dp"
        android:layout_marginStart="17dp"
        android:layout_marginTop="8dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.64"
        app:layout_constraintStart_toStartOf="@+id/guideline5"
        app:layout_constraintTop_toTopOf="@+id/guideline3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail2"
                android:layout_width="164dp"
                android:layout_height="170dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="3dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="centerInside"
                app:srcCompat="@drawable/two" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail2"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="example 2" />

        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/cardview5"
        android:layout_width="164dp"
        android:layout_height="160dp"
        android:layout_marginBottom="170dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.039"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/cardview3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail5"
                android:layout_width="164dp"
                android:layout_height="130dp"
                android:layout_marginLeft="6dp"
                android:layout_marginRight="6dp"
                android:layout_marginTop="6dp"
                android:adjustViewBounds="false"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:cropToPadding="false"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/exampletwo" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail5"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="Example 2" />

        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="384dp"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.Negocio">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.Negocio"
            app:title="Negocio">

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.constraint.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.06" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline5"
        android:layout_width="wrap_content"
        android:layout_height="929dp"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="204dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_end="17dp" />
</android.support.constraint.ConstraintLayout>

I'm using Android Studio Beta 7 and Oreo.
I've tried every solution on google, none worked.

Body:
I fixed it use this code

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:layout_weight="1"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="com.bonecadetrapo.imagensprincipal"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="25dp">

        <android.support.constraint.Guideline
            android:id="@+id/guideline10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="929dp" />

        <android.support.v7.widget.CardView
            android:id="@+id/cardview1"
            android:layout_width="164dp"
            android:layout_height="197dp"
            android:layout_marginBottom="300dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline3"
            app:layout_constraintVertical_bias="0.0"
            android:layout_marginLeft="17dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail"
                    android:layout_width="164dp"
                    android:layout_height="170dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="3dp"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/one" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="example 1" />

            </RelativeLayout>

            <android.support.constraint.Guideline
                android:id="@+id/guideline6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_end="17dp" />
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/cardview2"
            android:layout_width="164dp"
            android:layout_height="197dp"
            android:layout_marginBottom="300dp"
            android:layout_marginEnd="24dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.64"
            app:layout_constraintStart_toStartOf="@+id/guideline5"
            app:layout_constraintTop_toTopOf="@+id/guideline3"
            app:layout_constraintVertical_bias="0.0"
            android:layout_marginRight="24dp"
            android:layout_marginLeft="17dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail2"
                    android:layout_width="164dp"
                    android:layout_height="170dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="3dp"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/two" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail2"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="example 2" />

            </RelativeLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/cardview5"
            android:layout_width="164dp"
            android:layout_height="160dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="24dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.039"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cardview2"
            app:layout_constraintVertical_bias="0.0">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail5"
                    android:layout_width="164dp"
                    android:layout_height="130dp"
                    android:layout_marginLeft="6dp"
                    android:layout_marginRight="6dp"
                    android:layout_marginTop="6dp"
                    android:adjustViewBounds="false"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:cropToPadding="false"
                    android:scaleType="fitXY"
                    app:srcCompat="@drawable/exampletwo" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail5"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="Example 2" />

            </RelativeLayout>
        </android.support.v7.widget.CardView>

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="384dp"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:title="Negocio">

            </android.support.v7.widget.Toolbar>

        </android.support.design.widget.AppBarLayout>

        <android.support.constraint.Guideline
            android:id="@+id/guideline3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.06" />

        <android.support.constraint.Guideline
            android:id="@+id/guideline5"
            android:layout_width="wrap_content"
            android:layout_height="929dp"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="204dp" />

    </android.support.constraint.ConstraintLayout>
</ScrollView>


问:
Uploading a huge file to s3 (larger than my hard drive)
I'm trying to upload a file to an S3 bucket, but the problem is that the file I want to upload (and also create) is bigger than what my hard drive can hold (I want to store a 500TB file on the bucket)

Is there any way to do so?
The file is generated, so I thought about generating the file as I go while it uploads, but I can't quite figure out how to do it.

Any help is appreciated :)
Thanks in advace

答:
The Multipart Upload API allows you to upload a file in chunks, including on-the-fly content generation... but the maximum size of an object in S3 is 5 TiB.

Also, it costs a minimum of $11,500 to store 500 TiB in S3 for 1 month, not to mention the amount of time it takes to upload it... but if this is a justifiable use case, you might consider using some Snowball Edge devices, each of which has its own built-in 100 TiB of storage.


问:
How to get data and insert using id in php?
I make shopping site in php and I have one issue of product data.

```<code>First I make **product** datatabe below.

    CREATE TABLE IF NOT EXISTS `product` (
       `product_id` int(11) NOT NULL AUTO_INCREMENT,
       `product_sales_id` int(11) NOT NULL,
       `product_name` varchar(100) NOT NULL,
       `product_price` varchar(5000) NOT NULL,
       `image_name` varchar(300) NOT NULL,
       PRIMARY KEY (`product_id`)
    )

And Second table **product sales** below :

    CREATE TABLE IF NOT EXISTS `product_sales` (
       `product_sales_id` int(11) NOT NULL,
    )

Below page it admin site page when select product to insert in database and
show in product page.

Add_Product.php :

    <?php
        include_once('include/connection.php');
        include_once('include/function.php');
    ?>

    <?php
        if(isset($_POST['submit'])){
            $product_name = mysqli_real_escape_string($conn,$_POST['product_name']);
            $product_price = mysqli_real_escape_string($conn,$_POST['product_price']);
            $image_name = mysqli_real_escape_string($conn, basename( $_FILES["product_image"]["name"]));

            $target_dir = "upload/";
            $target_file = $target_dir . basename($_FILES["product_image"]["name"]);
            $uploadOk = 1;
            $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
            $filetype = $_FILES["product_image"]["type"];

            $image_upload = move_uploaded_file($_FILES["product_image"]["tmp_name"], $target_file);

            if($image_upload){
                mysqli_query($conn,"INSERT INTO product(product_name,product_price,image_name) VALUES ('".$product_name."','".$product_price."','".$image_name."')");
            }

        }
    ?>
</code>```

I make on more page product sell page but i do not know how to make this
    Above show I make table product_sales and his id store in product table
    how to add product_sales in database and show in page using id through.

答:
Change the product_sales_id in product_sales table into primary key and add product_id field as a foreign key in product_sales table.

Once the product is sold, you can store the product_id in the product_sales table.

And you can fetch the sold product details from product table using product_id which is present in the product_sales table using join query.

Body:
I make shopping site in php and I have one issue of product data.

First I make **product** datatabe below.

    CREATE TABLE IF NOT EXISTS `product` (
       `product_id` int(11) NOT NULL AUTO_INCREMENT,
       `product_sales_id` int(11) NOT NULL,
       `product_name` varchar(100) NOT NULL,
       `product_price` varchar(5000) NOT NULL,
       `image_name` varchar(300) NOT NULL,
       PRIMARY KEY (`product_id`)
    )

And Second table **product sales** below :

    CREATE TABLE IF NOT EXISTS `product_sales` (
       `product_sales_id` int(11) NOT NULL,
    )

Below page it admin site page when select product to insert in database and
show in product page.

Add_Product.php :

    <?php
        include_once('include/connection.php');
        include_once('include/function.php');
    ?>

    <?php
        if(isset($_POST['submit'])){
            $product_name = mysqli_real_escape_string($conn,$_POST['product_name']);
            $product_price = mysqli_real_escape_string($conn,$_POST['product_price']);
            $image_name = mysqli_real_escape_string($conn, basename( $_FILES["product_image"]["name"]));

            $target_dir = "upload/";
            $target_file = $target_dir . basename($_FILES["product_image"]["name"]);
            $uploadOk = 1;
            $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
            $filetype = $_FILES["product_image"]["type"];

            $image_upload = move_uploaded_file($_FILES["product_image"]["tmp_name"], $target_file);

            if($image_upload){
                mysqli_query($conn,"INSERT INTO product(product_name,product_price,image_name) VALUES ('".$product_name."','".$product_price."','".$image_name."')");
            }

        }
    ?>

I make on more page product sell page but i do not know how to make this
    Above show I make table product_sales and his id store in product table
    how to add product_sales in database and show in page using id through.


问:
Laravel 5 how to include config file?
I am using Laravel 5.5 and I have a config file in dir app\Json\Schemas\TestSchema.php which contains an array with configurations like this:

```<code>return [
  'value' => 'string'
];
</code>```

What is the best way to include file dynamically?

In my model

```<code>namespace App;

use App\Json\Traits\JsonModel;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    public function getJsonSchema($schema)
    {
        return  'App\\Json\\Schemas\\'.$schema;
    }
}
</code>```

答:
The best way would be to move your config file to the config folder. Lets assume you call it schema.php.

You can load the config file in your code using (where schema is the name of the config file without the .php):

```<code>config('schema');
</code>```

And if you want the value, you can use dot notation (where schema is the name of the config file, and value is a key in the config array):

```<code>$value = config('schema.value');
</code>```

Therefore the getJsonSchema function can be updated to (where $schema is the name of the config file):

```<code>public function getJsonSchema($schema)
{
    return  'App\\Json\\Schemas\\'.config($schema.'.value');
}
</code>```

Title: Laravel 5 how to include config file?

Body:
I am using Laravel 5.5 and I have a config file in dir app\Json\Schemas\TestSchema.php which contains an array with configurations like this:

return [
  'value' => 'string'
];

What is the best way to include file dynamically?

In my model

namespace App;

use App\Json\Traits\JsonModel;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    public function getJsonSchema($schema)
    {
        return  'App\\Json\\Schemas\\'.$schema;
    }
}

Body:
The best way would be to move your config file to the config folder. Lets assume you call it schema.php.

You can load the config file in your code using (where schema is the name of the config file without the .php):

config('schema');

And if you want the value, you can use dot notation (where schema is the name of the config file, and value is a key in the config array):

$value = config('schema.value');

Therefore the getJsonSchema function can be updated to (where $schema is the name of the config file):

public function getJsonSchema($schema)
{
    return  'App\\Json\\Schemas\\'.config($schema.'.value');
}