问:
autocomplete using jquery shows bullet points with no values in Laravel 5.4
I am using Laravel 5.4, Ajax and Jquery to auto-complete search field. I am unable to show search result. All I get to see is the list of bullet points with no search data in it. I am not sure how to check if data is really passed to the view? I did console.log (ui) but no result on console

Below is the screenshot showing search bar with bullet points results.

jquery search code

```<code> $("#searchfield").autocomplete({
  source    : '{{ url("/admin/users/autocomplete") }}',
  minlength :1,
  autofocus : true,
  select:function (e,ui){
    console.log(ui);
    alert(ui);
  }
});
</code>```

input field code

```<code><input type="text" class="form-control" style="width:70%; display:none;" name="searchfield" id="searchfield" placeholder="Enter username..." >
</code>```

display none property in input field changes to display:block when first name is selected from drop down. that is not the issue if that thought crosses ur mind.

Updated - output from the url /admin/users/autocomplete?term=...

```<code>[{"id":6,"name":"Lulu"},{"id":14,"name":"Luis"}]
</code>```

Now I am in much better state, all I need is data to be inserted into those empty results. below are the images with update html state and screenshot of inspect element screen if it helps find bug:

答:
I just split the action of collecting data and serving it to source of auto-complete. below is my code:</p>

```<code>  var searchdata = [];
  var select2 = $('#searchfield').val();
  $.ajax({
          type : 'GET',
          url  :  "{{url('/admin/users/autocomplete')}}",
          data :  {type : id, type_val : select2},
        }).done(function(data)
        {
          console.log(data);
          $.each(data, function( index, value )
          {
            searchdata.push(data[index].firstname);
          });
          $("#searchfield").autocomplete(
          {
            source    : searchdata,
            minlength :1,
            autofocus : true
          });
    });
});
</code>```

Body:
I am using Laravel 5.4, Ajax and Jquery to auto-complete search field. I am unable to show search result. All I get to see is the list of bullet points with no search data in it. I am not sure how to check if data is really passed to the view? I did console.log (ui) but no result on console

Below is the screenshot showing search bar with bullet points results.

jquery search code

 $("#searchfield").autocomplete({
  source    : '{{ url("/admin/users/autocomplete") }}',
  minlength :1,
  autofocus : true,
  select:function (e,ui){
    console.log(ui);
    alert(ui);
  }
});

input field code

<input type="text" class="form-control" style="width:70%; display:none;" name="searchfield" id="searchfield" placeholder="Enter username..." >

display none property in input field changes to display:block when first name is selected from drop down. that is not the issue if that thought crosses ur mind.

Updated - output from the url /admin/users/autocomplete?term=...

[{"id":6,"name":"Lulu"},{"id":14,"name":"Luis"}]

Now I am in much better state, all I need is data to be inserted into those empty results. below are the images with update html state and screenshot of inspect element screen if it helps find bug:

Body:
I just split the action of collecting data and serving it to source of auto-complete. below is my code:

  var searchdata = [];
  var select2 = $('#searchfield').val();
  $.ajax({
          type : 'GET',
          url  :  "{{url('/admin/users/autocomplete')}}",
          data :  {type : id, type_val : select2},
        }).done(function(data)
        {
          console.log(data);
          $.each(data, function( index, value )
          {
            searchdata.push(data[index].firstname);
          });
          $("#searchfield").autocomplete(
          {
            source    : searchdata,
            minlength :1,
            autofocus : true
          });
    });
});


来源: stackexchange

问:
Libgdx : Exported desktop jar file link to external path instead jar root
I'm trying to deploy my libgdx app into a jar desktop file. I use Intellij so i builded the desktop module, then executed  ./gradlew desktop:dist to produce the jar and everything gone well ! I use an Asset manager to load my assets. Now when i execute the jar, the asset manager try to get the assets in the directory of the jar and not directly in the jar file.

My asset manager :

```<code>package com.com8.game.Utils;

import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.SkinLoader;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

public class Assets {

public AssetManager manager = new AssetManager();

public static final AssetDescriptor<Texture> logo =
        new AssetDescriptor<Texture>("logo.png", Texture.class);

public static final AssetDescriptor<Texture> tableBack =
        new AssetDescriptor<Texture>("back.png", Texture.class);

public static final AssetDescriptor<Texture> frontBackground =
        new AssetDescriptor<Texture>("frontBackground.png", Texture.class);

public static final AssetDescriptor<Texture> backBackground =
        new AssetDescriptor<Texture>("backBackground.png", Texture.class);

public static final AssetDescriptor<TextureAtlas> uiAtlas =
        new AssetDescriptor<TextureAtlas>("UI/uiskin.atlas", TextureAtlas.class);

public static final AssetDescriptor<Skin> uiSkin =
        new AssetDescriptor<Skin>("UI/uiskin.json", Skin.class,
                new SkinLoader.SkinParameter("UI/uiskin.atlas"));

public static final AssetDescriptor<TextureAtlas> gameAtlas =
        new AssetDescriptor<TextureAtlas>("Atlas/gameImages.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> flamesAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/flamesAnimation.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> hitAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/hitAnimation.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> shipExplosionAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/shipExplosionAnimation.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> dustAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/dustAnimation.atlas", TextureAtlas.class);

public void load()
{
    manager.load(logo);
    manager.load(tableBack);
    manager.load(frontBackground);
    manager.load(backBackground);
    manager.load(uiAtlas);
    manager.load(uiSkin);
    manager.load(gameAtlas);
    manager.load(flamesAnimation);
    manager.load(hitAnimation);
    manager.load(shipExplosionAnimation);
    manager.load(dustAnimation);
}

public void dispose() {
    manager.dispose();
}
}
</code>```

My build.gradle of the desktopLauncher :
    apply plugin: "java"

```<code>sourceCompatibility = 1.6
sourceSets.main.java.srcDirs = [ "src/" ]

project.ext.mainClassName = "com.com8.game.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../core/assets");

task run(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
}

task debug(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
    debug = true
}

task dist(type: Jar) {
    from files(sourceSets.main.output.classesDir)
    from files(sourceSets.main.output.resourcesDir)
    from {configurations.compile.collect {zipTree(it)}}
    from files(project.assetsDir);

    manifest {
        attributes 'Main-Class': project.mainClassName
    }
}

dist.dependsOn classes

eclipse {
    project {
        name = appName + "-desktop"
        linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
    }
}

task afterEclipseImport(description: "Post processing after project
generation", group: "IDE") {
  doLast {
    def classpath = new XmlParser().parse(file(".classpath"))
    new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
    def writer = new FileWriter(file(".classpath"))
    def printer = new XmlNodePrinter(new PrintWriter(writer))
    printer.setPreserveWhitespace(true)
    printer.print(classpath)
  }
}
</code>```

Can someone please help me ? :) Thanks

EDIT :
I just added a "/" in front of each path name and it seems to be better !
now i have this, the file logo.png is in the root of the jar file.

And here is how i use Assets class :

```<code>// Assets
private AssetManager manager;
private Stage stage;
private Skin skin;

// UI
private TextField userIDRegistered;
private TextField userPwd;
private TextField userIDGuest;
private Label authentificationResponse;
private Label socketConnectedMessage;

// Socket
private Socket socket;

public ConnexionScreen(Com8 game) {
    this.game = game;
    this.socket = game.getSocket();
    this.manager = game.assets.manager;

    skin = game.skin;

    stage = game.stage;
    stage.clear();

    configSocketEvents();
}

@Override
public void show() {
    //Create Table
    Table mainTable = new Table();

    //Set table position properties
    mainTable.align(Align.center|Align.center);
    mainTable.setFillParent(true);

    //Create image
    Texture logoTexture = manager.get("/logo.png", Texture.class);
    Image logoImage = new Image(logoTexture);
</code>```

答:
Change

```<code>project.ext.assetsDir = new File("../core/assets");
</code>```

to

```<code>project.ext.assetsDir = new File("../android/assets");
</code>```

in build.gradle file of desktop module

then run ./gradlew desktop:dist

Hopefully, all of your resources are in assets folder of android module.

EDIT

I tested, It's working fine for me, find what you're doing wrong.

Code inside create() method

```<code>AssetDescriptor<Texture> assetDescriptor=new AssetDescriptor<Texture>("brick.png",Texture.class);

AssetManager assetManager=new AssetManager();
assetManager.load(assetDescriptor);   // load by assetDescriptor
assetManager.load("badlogic.jpg", Texture.class);   // manual loading

assetManager.finishLoading();

texture=assetManager.get("badlogic.jpg",Texture.class);  // fetch data manually
texture1=assetManager.get(assetDescriptor);              // fetch by descriptor
</code>```

I draw these two texture in render() method

Resources are inside core module in assets folder.

then I assign asset directory in build.gradle file of desktop module that is also using in dist task

project.ext.assetsDir = new File("../core/assets");

Run  ./gradlew dist command on terminal.

I find my desktop-1.0.jar inside build folder of desktop module. Copied and keep in some other folder and run by double click, It's working fine.

Both resources(badlogic.jpg & brick.png) are in my .jar at top root.

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to deploy my libgdx app into a jar desktop file. I use Intellij so i builded the desktop module, then executed  ./gradlew desktop:dist to produce the jar and everything gone well ! I use an Asset manager to load my assets. Now when i execute the jar, the asset manager try to get the assets in the directory of the jar and not directly in the jar file.

My asset manager :

package com.com8.game.Utils;

import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.SkinLoader;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

public class Assets {

public AssetManager manager = new AssetManager();

public static final AssetDescriptor<Texture> logo =
        new AssetDescriptor<Texture>("logo.png", Texture.class);

public static final AssetDescriptor<Texture> tableBack =
        new AssetDescriptor<Texture>("back.png", Texture.class);

public static final AssetDescriptor<Texture> frontBackground =
        new AssetDescriptor<Texture>("frontBackground.png", Texture.class);

public static final AssetDescriptor<Texture> backBackground =
        new AssetDescriptor<Texture>("backBackground.png", Texture.class);

public static final AssetDescriptor<TextureAtlas> uiAtlas =
        new AssetDescriptor<TextureAtlas>("UI/uiskin.atlas", TextureAtlas.class);

public static final AssetDescriptor<Skin> uiSkin =
        new AssetDescriptor<Skin>("UI/uiskin.json", Skin.class,
                new SkinLoader.SkinParameter("UI/uiskin.atlas"));

public static final AssetDescriptor<TextureAtlas> gameAtlas =
        new AssetDescriptor<TextureAtlas>("Atlas/gameImages.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> flamesAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/flamesAnimation.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> hitAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/hitAnimation.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> shipExplosionAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/shipExplosionAnimation.atlas", TextureAtlas.class);

public static final AssetDescriptor<TextureAtlas> dustAnimation =
        new AssetDescriptor<TextureAtlas>("Atlas/dustAnimation.atlas", TextureAtlas.class);

public void load()
{
    manager.load(logo);
    manager.load(tableBack);
    manager.load(frontBackground);
    manager.load(backBackground);
    manager.load(uiAtlas);
    manager.load(uiSkin);
    manager.load(gameAtlas);
    manager.load(flamesAnimation);
    manager.load(hitAnimation);
    manager.load(shipExplosionAnimation);
    manager.load(dustAnimation);
}

public void dispose() {
    manager.dispose();
}
}

My build.gradle of the desktopLauncher :
    apply plugin: "java"

sourceCompatibility = 1.6
sourceSets.main.java.srcDirs = [ "src/" ]

project.ext.mainClassName = "com.com8.game.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../core/assets");

task run(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
}

task debug(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
    debug = true
}

task dist(type: Jar) {
    from files(sourceSets.main.output.classesDir)
    from files(sourceSets.main.output.resourcesDir)
    from {configurations.compile.collect {zipTree(it)}}
    from files(project.assetsDir);

    manifest {
        attributes 'Main-Class': project.mainClassName
    }
}

dist.dependsOn classes

eclipse {
    project {
        name = appName + "-desktop"
        linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
    }
}

task afterEclipseImport(description: "Post processing after project
generation", group: "IDE") {
  doLast {
    def classpath = new XmlParser().parse(file(".classpath"))
    new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
    def writer = new FileWriter(file(".classpath"))
    def printer = new XmlNodePrinter(new PrintWriter(writer))
    printer.setPreserveWhitespace(true)
    printer.print(classpath)
  }
}

Can someone please help me ? :) Thanks

EDIT :
I just added a "/" in front of each path name and it seems to be better !
now i have this, the file logo.png is in the root of the jar file.

And here is how i use Assets class :

// Assets
private AssetManager manager;
private Stage stage;
private Skin skin;

// UI
private TextField userIDRegistered;
private TextField userPwd;
private TextField userIDGuest;
private Label authentificationResponse;
private Label socketConnectedMessage;

// Socket
private Socket socket;

public ConnexionScreen(Com8 game) {
    this.game = game;
    this.socket = game.getSocket();
    this.manager = game.assets.manager;

    skin = game.skin;

    stage = game.stage;
    stage.clear();

    configSocketEvents();
}

@Override
public void show() {
    //Create Table
    Table mainTable = new Table();

    //Set table position properties
    mainTable.align(Align.center|Align.center);
    mainTable.setFillParent(true);

    //Create image
    Texture logoTexture = manager.get("/logo.png", Texture.class);
    Image logoImage = new Image(logoTexture);

Body:
Change

project.ext.assetsDir = new File("../core/assets");

to

project.ext.assetsDir = new File("../android/assets");

in build.gradle file of desktop module

then run ./gradlew desktop:dist

Hopefully, all of your resources are in assets folder of android module.

EDIT

I tested, It's working fine for me, find what you're doing wrong.

Code inside create() method

AssetDescriptor<Texture> assetDescriptor=new AssetDescriptor<Texture>("brick.png",Texture.class);

AssetManager assetManager=new AssetManager();
assetManager.load(assetDescriptor);   // load by assetDescriptor
assetManager.load("badlogic.jpg", Texture.class);   // manual loading

assetManager.finishLoading();

texture=assetManager.get("badlogic.jpg",Texture.class);  // fetch data manually
texture1=assetManager.get(assetDescriptor);              // fetch by descriptor

I draw these two texture in render() method

Resources are inside core module in assets folder.

then I assign asset directory in build.gradle file of desktop module that is also using in dist task

project.ext.assetsDir = new File("../core/assets");

Run  ./gradlew dist command on terminal.

I find my desktop-1.0.jar inside build folder of desktop module. Copied and keep in some other folder and run by double click, It's working fine.

Both resources(badlogic.jpg & brick.png) are in my .jar at top root.


问:
why my django site in hosting (alwaysdata) cant show my page
I have deployed Django at alwaysdata.com,

this is my main page on http://zjm1126.alwaysdata.net/ :

i change the index.html to index1.html, this file is not my file ,

my project is like this :

```<code>example_project/
    __init__.py
    manage.py
    public/
        django.fcgi
        .htaccess
        media/
    settings.py
    urls.py
    myapp/
        views.py
        models.py
</code>```

what can i do to show my main page .

thanks

答: You have a misconfigured server. It doesn't know that pages in that directory should by default should be handled by Python. This was covered in Deploying Django at alwaysdata.com.</p>

ContentLicense: CC BY-SA 2.5

Body:
I have deployed Django at alwaysdata.com,

this is my main page on http://zjm1126.alwaysdata.net/ :

i change the index.html to index1.html, this file is not my file ,

my project is like this :

example_project/
    __init__.py
    manage.py
    public/
        django.fcgi
        .htaccess
        media/
    settings.py
    urls.py
    myapp/
        views.py
        models.py

what can i do to show my main page .

thanks


问:
Use text from URL after slash as parameter - htaccess
I need to rewrite this:

```<code>http://example.com/new/location/
</code>```

to:

```<code>http://example.com/new.php?p=location
</code>```

Btw it could be anything after new/ for example i need:

```<code>http://example.com/new/anything
</code>```

to actually be:

```<code>http://example.com/new.php?p=anything
</code>```

But i need to keep the URL structure with the slashes for SEO and security purposes

How could i achieve this using .htaccess?

currently in my htaccess ive got:

```<code>RewriteEngine on
RewriteBase /dir/
</code>```

Thanks

答:
Add the following directive into your .htaccess:

```<code>RewriteRule ^new/location$ new.php?p=location [L]
</code>```

or to work any values use:

```<code>RewriteRule ^new/(.*)$ new.php?p=$1 [L]
</code>```

Body:
I need to rewrite this:

http://example.com/new/location/

to:

http://example.com/new.php?p=location

Btw it could be anything after new/ for example i need:

http://example.com/new/anything

to actually be:

http://example.com/new.php?p=anything

But i need to keep the URL structure with the slashes for SEO and security purposes

How could i achieve this using .htaccess?

currently in my htaccess ive got:

RewriteEngine on
RewriteBase /dir/

Thanks

Body:
Add the following directive into your .htaccess:

RewriteRule ^new/location$ new.php?p=location [L]

or to work any values use:

RewriteRule ^new/(.*)$ new.php?p=$1 [L]


问:
html tables alignment using css
I am trying to get my alignment for tables and a map on an html page.
It looks like this at the moment:

1,2,3 are all tables, using CSS:

```<code>table {float:left;
    border-collapse: collapse;
    width: 20%; margin: 10px
}
</code>```

and 4 is a googlemap using:

```<code>#location{width: 30%;
    float: left;
    margin: 10px;
    margin-top: 30px;
}
</code>```

I would like 3 to go beneath 2, with 4 always on the right:

答:
The easiest way to do this is to wrap the two tables into a single div, then float that div.

.float-left {
  float: left;
  width: 20%;
  margin: 10px;
  border: 4px solid black;
}

.full-width {
  width: 100%;
  height: 150px;
}

.full-width caption {
  margin: 12px 0 2px 0;
  font-weight: bold;
}

.google-map {
  border: 2px solid black;
  width: 30%;
  margin: 10px;
  float: left;
  height: 300px;
  text-align: center;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="float-left">
  <table class="full-width">
    <caption>Table 1</caption>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </table>
</div>
<div class="float-left">
  <table class="full-width">
    <caption>Table 2</caption>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </table>
  <table class="full-width">
    <caption>Table 3</caption>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </table>
</div>
<div class="google-map">
  Google Map Here
</div></code>```

Title: html tables alignment using css

Body:
I am trying to get my alignment for tables and a map on an html page.
It looks like this at the moment:

1,2,3 are all tables, using CSS:

table {float:left;
    border-collapse: collapse;
    width: 20%; margin: 10px
}

and 4 is a googlemap using:

#location{width: 30%;
    float: left;
    margin: 10px;
    margin-top: 30px;
}

I would like 3 to go beneath 2, with 4 always on the right:

Body:
The easiest way to do this is to wrap the two tables into a single div, then float that div.

.float-left {
  float: left;
  width: 20%;
  margin: 10px;
  border: 4px solid black;
}

.full-width {
  width: 100%;
  height: 150px;
}

.full-width caption {
  margin: 12px 0 2px 0;
  font-weight: bold;
}

.google-map {
  border: 2px solid black;
  width: 30%;
  margin: 10px;
  float: left;
  height: 300px;
  text-align: center;
}

<div class="float-left">
  <table class="full-width">
    <caption>Table 1</caption>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </table>
</div>
<div class="float-left">
  <table class="full-width">
    <caption>Table 2</caption>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </table>
  <table class="full-width">
    <caption>Table 3</caption>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </table>
</div>
<div class="google-map">
  Google Map Here
</div>


问:
In this code, Why am I getting wrong output only for input value of 4.2 while it is working well for other values?
The following code converts dollars (floating values) into cents (integer values). Here 1 dollar == 100 cents. The code works flawlessly except for one value i.e 4.2. It gives output as 419 instead of 420 for 4.2 as input. Where is the bug?</p>

```<code>#include <stdio.h>
int main(void)
{
    float change;

    do
    {
        printf("O hai! Enter amount in dollars to convert in cents.\n");

        scanf("%f",&change);   //accepts input in dollars

    } while(change < 0.00);

    int i = change * 100;    //converts dollars into cents

    printf("The equivalent cents are %d\n",i);
}
</code>```

答:
Many floating point values do not have an exact representation in base 2.

You can try adding a very small value to push the value a little bit:

```<code>int i = (change + 0.0001) * 100;    //converts dollars into cents
</code>```

Body:
The following code converts dollars (floating values) into cents (integer values). Here 1 dollar == 100 cents. The code works flawlessly except for one value i.e 4.2. It gives output as 419 instead of 420 for 4.2 as input. Where is the bug?

#include <stdio.h>
int main(void)
{
    float change;

    do
    {
        printf("O hai! Enter amount in dollars to convert in cents.\n");

        scanf("%f",&change);   //accepts input in dollars

    } while(change < 0.00);

    int i = change * 100;    //converts dollars into cents

    printf("The equivalent cents are %d\n",i);
}

Body:
Many floating point values do not have an exact representation in base 2.

You can try adding a very small value to push the value a little bit:

int i = (change + 0.0001) * 100;    //converts dollars into cents


问:
Mapbox load only a country map
Can we create a map in mapbox, that is to be used ios, which loads only a particular country instead of the whole world? For instance I wish to load the map of UK, If I Zoom out completely i could see the whole UK but no other country.</p>

答:
I contacted the mapbox people and they kindly directed me towards the solution, I am sharing so it may be helpful for others

https://www.mapbox.com/help/style-single-country/

Title: Mapbox load only a country map


问:
How "perfect" does a database have to be?
I'm designing a website to track weight lifting and calories. I've never designed my own database before and I figured I should get is as spot on as possible before I start coding. Every time I think I'm done, I get antsy that it's not perfect. I've mostly fleshed it out in MySQL Workbench but I still have a few questions.

How important is it to make the
database "perfect" before hand? How
hard is it to re-factor a database
later?

What does the engine option do? Right
now all tables are defaulting to
InnoDB engine? Any issues with this?

Are dataypes changeable after data
entry? Maybe not going from VARCHAR
to INT, but what about VARCHAR(45) to
VARCHAR(255)?

What are basic database rules that HAVE to
be followed for a successful design?

I've also attached my ERM diagram. If anyone could point out any obvious irregularities it would be greatly appreciated.

答:
It looks pretty good ... except your exercise table.  The secondary1 to secondary10 fields smack of something that should probably be in a different table.  However, you've done well everywhere else, so maybe this makes sense?  Think about it and make sure.

Perfectness doesn't matter, things can (and will) change after you're done.  Try to normalize down as far as you can (you've done this mostly already).  Field sizes can be changed, don't worry about that.


问:
bootstrap input group select field,text field and search field
I want to build search bar similar to amazon site.

A select input field followed by input field followed by search button.

this is what I have got so far:

The issue is that the button1 dropdown is not a select input field if I do change to input field everything breaks.

examples in bootstrap site dont show group with input field select but dropdown menu.

my code

```<code> <div class="input-group input-group-lg">

        <input type="text" name="query" class="form-control" placeholder="Search this site" />
        <span class="input-group-btn">

          <button type="button" class="btn btn-primary dropdown-toggle custom" data-toggle="dropdown">Button 1 <span class="caret"></span></button>
          <ul class="dropdown-menu pull-right">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li class="divider"></li>
              <li><a href="#">Separated link</a></li>
          </ul>
        <button class="btn btn-primary" type="submit">
              <span class="glyphicon glyphicon-search"></span>
            </button>
    </span>

        </div>
</code>```

css - to remove curve radius for center input field or buttons

```<code>.custom{
    -webkit-border-radius: 0px !important;
    -moz-border-radius: 0px !important;
    border-radius: 0px !important;
}
</code>```

答:
I got it solved just amazon like search using this:</p>

```<code><div class="input-group my-group">

            <select id="filter_type" name="filter_type" class="selectpicker form-control" style="width:30%;">
                        <option value>Select Filter Type..</option>
                        <option value="all">All</option>
                        <option value="firstname">First Name</option>
                        <option value="lastname">Last Name</option>
                        <option value="email">Email</option>

                    </select>
            <select id="search" name="search" class="selectpicker form-control" disabled="disabled" style="width:70%;  display:block;">
                       <option value>select filter type first</option>
                       </select>

                    <input type="text" class="form-control" style="width:70%; display:none" name="searchfield" id="searchfield" placeholder="Enter username...">

             <span class="input-group-btn">
    <button id="submit" name="submit" class="btn btn-primary"  disabled="disabled" type="submit">Filter</button>
  </span>

        </div>
</code>```

Body:
I want to build search bar similar to amazon site.

A select input field followed by input field followed by search button.

this is what I have got so far:

The issue is that the button1 dropdown is not a select input field if I do change to input field everything breaks.

examples in bootstrap site dont show group with input field select but dropdown menu.

my code

        <input type="text" name="query" class="form-control" placeholder="Search this site" />

          <button type="button" class="btn btn-primary dropdown-toggle custom" data-toggle="dropdown">Button 1 </button>

Action

Another action

Something else here

Separated link

        <button class="btn btn-primary" type="submit">

            </button>

css - to remove curve radius for center input field or buttons

.custom{
    -webkit-border-radius: 0px !important;
    -moz-border-radius: 0px !important;
    border-radius: 0px !important;
}

Body:
I got it solved just amazon like search using this:

<div class="input-group my-group">

            <select id="filter_type" name="filter_type" class="selectpicker form-control" style="width:30%;">
                        <option value>Select Filter Type..</option>
                        <option value="all">All</option>
                        <option value="firstname">First Name</option>
                        <option value="lastname">Last Name</option>
                        <option value="email">Email</option>

                    </select>
            <select id="search" name="search" class="selectpicker form-control" disabled="disabled" style="width:70%;  display:block;">
                       <option value>select filter type first</option>
                       </select>

                    <input type="text" class="form-control" style="width:70%; display:none" name="searchfield" id="searchfield" placeholder="Enter username...">

             <span class="input-group-btn">
    <button id="submit" name="submit" class="btn btn-primary"  disabled="disabled" type="submit">Filter</button>
  </span>

        </div>


答: Use x[x > 0 & !is.na(x)]. This will only select entries where x is different from NA

Title: Select x>0 in x when NA in x

Body:
> x
 [1] -0.0006993769            NA  0.0605337483  0.0112900315  0.0166747653  0.0498045070 -0.0120633548  0.0034724936
 [9] -0.0107294362 -0.0021350540 -0.0092103916 -0.0369649485 -0.0136530145 -0.0127135534  0.0159644319 -0.0075359604
[17]  0.0138871055  0.0226605719 -0.0118107427  0.0168362283 -0.0175228517

> x>0
 [1] FALSE    NA  TRUE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE  TRUE
[21] FALSE

> x[x>0]
 [1]          NA 0.060533748 0.011290032 0.016674765 0.049804507 0.003472494 0.015964432 0.013887105 0.022660572 0.016836228

do not want to get NA in x[x>0], why NA were selected in this sequence


答:
You have this behavior because of the way a float is represented.

In IEEE 754, 4.2 is actually stored as 4.19999980926513671875 so that when you multiply it by 100 and cast it back to an int, you get 419 (i.e. the integer part of the result).

A solution would be to use

```<code>int i = (int) roundf(change * 100);
</code>```

or

```<code>int i = (int) lrintf(change * 100);
</code>```

with #include <math.h>.

Title: In this code, Why am I getting wrong output only for input value of 4.2 while it is working well for other values?

Body:
You have this behavior because of the way a float is represented.

In IEEE 754, 4.2 is actually stored as 4.19999980926513671875 so that when you multiply it by 100 and cast it back to an int, you get 419 (i.e. the integer part of the result).

A solution would be to use

int i = (int) roundf(change * 100);

or

int i = (int) lrintf(change * 100);

with #include <math.h>.


问:
FOREIGN KEY doesn't complete column after INSERT (PHP)
I have 2 tables. In the first i have id_user (that is primary key),username,name,password and in the second i have id_post(primary key),post,username,view,id(foreign key that references id_user).
After i use the query:

```<code>$query ="INSERT INTO posts (username,post,view) VALUES ('$username','$postare','$isprivate')";
</code>```

It completes my column id with NULL. I want in the column id to have the id_user of the user that make the query.Not NULL.

答:
You need to look up the value to get that in the data.  So, using your construct the query would look something like this:

```<code>insert into posts (userid, post, view)
    select u.userid, $postare, $isprivate
    from users u
    where u.username = '$username';
</code>```

Notes:

Do not store both userid and username in the posts table.  Only store the username in the users table and use userid to get the name when you need it.

Don't munge your query string by putting values directly in it.  Learn to use parameterized queries.

view is a really bad name for a column, because it is an SQL keyword.

Body:
I have 2 tables. In the first i have id_user (that is primary key),username,name,password and in the second i have id_post(primary key),post,username,view,id(foreign key that references id_user).
After i use the query:

$query ="INSERT INTO posts (username,post,view) VALUES ('$username','$postare','$isprivate')";

It completes my column id with NULL. I want in the column id to have the id_user of the user that make the query.Not NULL.

Body:
You need to look up the value to get that in the data.  So, using your construct the query would look something like this:

insert into posts (userid, post, view)
    select u.userid, $postare, $isprivate
    from users u
    where u.username = '$username';

Notes:

Do not store both userid and username in the posts table.  Only store the username in the users table and use userid to get the name when you need it.

Don't munge your query string by putting values directly in it.  Learn to use parameterized queries.

view is a really bad name for a column, because it is an SQL keyword.


问:
Angular 2 - Cannot read property of undefined error using Array.filter
folks, I am working on a project that needs to filter JSON but in developer tools of Chrome, it shows me an error of undefined property.

```<code> chart: JsonChart[] = [];
 charts: JsonCharts[] = [];

 getCharts() {
    this.iChartHttp.getCharts()
        .subscribe(
        charts => this.charts = charts, //return json object
        error => this.errorMessage = <any>error
        );
}

 if (this.chart_id != null) {
        this.getCharts();
         this.chart = this.charts.filter(charts => charts.id === this.chart_id)[0].series; // this like error occur.
    }
</code>```

Updated Question

It's not getting JSON Array from Service. but it works in another component

iChartHttpService:

```<code> getCharts(): Observable<JsonCharts[]> {
return this.http.get('assets/datas.json')
  .map((res: Response) => res.json())
  .do(data => console.log('server data:', data))  // debug
  .catch(this.handleError);
}

/**
* Handle HTTP error
*/
private handleError(error: any) {
// In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message
const errMsg = (error.message) ? error.message :
  error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
</code>```

}

答:
I think you need to send the series inside the javascript filter function. modify it like this </p>

```<code>if (this.chart_id != null) {
    this.getCharts();
    if (this.chart.length > 0) {
        this.chart = this.charts.filter(charts => {
            if (charts.id === this.chart_id) {
                charts[0].series;
            }
        })
    }
}
</code>```

Body:
folks, I am working on a project that needs to filter JSON but in developer tools of Chrome, it shows me an error of undefined property.

 chart: JsonChart[] = [];
 charts: JsonCharts[] = [];

 getCharts() {
    this.iChartHttp.getCharts()
        .subscribe(
        charts => this.charts = charts, //return json object
        error => this.errorMessage = <any>error
        );
}

 if (this.chart_id != null) {
        this.getCharts();
         this.chart = this.charts.filter(charts => charts.id === this.chart_id)[0].series; // this like error occur.
    }

Updated Question

It's not getting JSON Array from Service. but it works in another component

iChartHttpService:

 getCharts(): Observable<JsonCharts[]> {
return this.http.get('assets/datas.json')
  .map((res: Response) => res.json())
  .do(data => console.log('server data:', data))  // debug
  .catch(this.handleError);
}

/**
* Handle HTTP error
*/
private handleError(error: any) {
// In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message
const errMsg = (error.message) ? error.message :
  error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);

}

Body:
I think you need to send the series inside the javascript filter function. modify it like this

if (this.chart_id != null) {
    this.getCharts();
    if (this.chart.length > 0) {
        this.chart = this.charts.filter(charts => {
            if (charts.id === this.chart_id) {
                charts[0].series;
            }
        })
    }
}


问:
Laravel 5.4 - route model binding condition
I have implemented route model binding as follows:

Route:

```<code>Route::get('property/{property}', 'PropertyController@view');
</code>```

Controller:

```<code>public function view(Property $property)
{
    $data = compact([
        'property'
    ]);

    return view('property.view', $data);
}
</code>```

This works great. However I want to add a condition to the Property model to check that active = 1. How and where do I do this?

答:
You can register an explicit binding. Add the code below to RouteServiceProvider. This will be applied to the model binding when the segment is property.

```<code>Route::bind('property', function ($id) {
    return \App\Property::where('id', $id)
        ->where('active', 1)
        ->firstOrFail();
});
</code>```

If you need this condition to be applied globally for every result then you can add a global scope instead. https://laravel.com/docs/5.4/eloquent#global-scopes

Body:
I have implemented route model binding as follows:

Route:

Route::get('property/{property}', 'PropertyController@view');

Controller:

public function view(Property $property)
{
    $data = compact([
        'property'
    ]);

    return view('property.view', $data);
}

This works great. However I want to add a condition to the Property model to check that active = 1. How and where do I do this?

Body:
You can register an explicit binding. Add the code below to RouteServiceProvider. This will be applied to the model binding when the segment is property.

Route::bind('property', function ($id) {
    return \App\Property::where('id', $id)
        ->where('active', 1)
        ->firstOrFail();
});

If you need this condition to be applied globally for every result then you can add a global scope instead. https://laravel.com/docs/5.4/eloquent#global-scopes


问:
jquery- reverse nested icon's color just on click not for ever
I have a nested icon and I want it's color become reversed on click.Using jQuery I can change colors but it changes forever while I want it to changes just on click!
HTML:

```<code><div id="listSlider-right-icon">
            <i id="listSlider-right-arrow" class="fa fa-2x fa-square ">
                <i id="play-icon" class="fa fa-play"></i>
            </i>
</div>
</code>```

CSS:

```<code>#listSlider-right-icon{
    position: absolute;
    margin-top: 150px;
    cursor: pointer;
    color: green;
}
#listSlider-right-icon{
    right: 10%;
}

#listSlider-right-arrow i{
    font-size: 12px;
    position: absolute;
    left: 50%;
    top: 0.6em;
    margin-left: -7px;
    color: white;
}
</code>```

Jquery:

```<code>$('#listSlider-right-arrow').click(function () {
        $(this).css('color', '#fff');
        $('#play-icon').css('color', '#01a89e');
    });
</code>```

JSFiddle

In addition, I was wondering if it's possible using CSS?

答:
so its color changes just the time you click it ?

Have a look at the onMouseDown and onMouseUp events which are the start and the end of a click.

Body:
I have a nested icon and I want it's color become reversed on click.Using jQuery I can change colors but it changes forever while I want it to changes just on click!
HTML:

CSS:

#listSlider-right-icon{
    position: absolute;
    margin-top: 150px;
    cursor: pointer;
    color: green;
}
#listSlider-right-icon{
    right: 10%;
}

#listSlider-right-arrow i{
    font-size: 12px;
    position: absolute;
    left: 50%;
    top: 0.6em;
    margin-left: -7px;
    color: white;
}

Jquery:

$('#listSlider-right-arrow').click(function () {
        $(this).css('color', '#fff');
        $('#play-icon').css('color', '#01a89e');
    });

JSFiddle

In addition, I was wondering if it's possible using CSS?


问:
Golang/gin: How to disable the "Found." link on HTTP redirect
I'm using gin framework and I'm redirecting signin to home page when the user is already signed in. It shows this html element on the home page.

```<code><a href="/signin">Found</a> "."
</code>```

How to disable that element from the app?

This is my app code.

```<code>func GetSignIn(c *gin.Context) {
    // Get session from cookie. Check if email exists
    // redirect to Home page else show signin page.
    session := sessions.Default(c)
    if session.Get("email") != nil {
        fmt.Println(session.Get("email"))
        c.Redirect(302, "/")
    }
    c.HTML(200, "signin.html", "")
}
</code>```

It seems like, it's a Go thing
https://github.com/golang/go/blob/master/src/net/http/server.go#L2014

But I'm not sure, how to disable it. Would be great if someone guide me.

Thanks!

答:
Yeah, looks like it's a Go thing and you can't disable it.
I suggest you to write your own Redirect structure like render.Redirect from Gin (you can embed it in your new structure to avoid some copy pasting):

https://github.com/gin-gonic/gin/blob/master/render/redirect.go

Write your own Render method for new structure based on code from net/http and then use redirect like this:

https://github.com/gin-gonic/gin/blob/32cab500ecc71d2975f5699c8a65c6debb29cfbe/context.go#L476

I think it's the simplest way to bypass such net/http redirect behavior.

Body:
I'm using gin framework and I'm redirecting signin to home page when the user is already signed in. It shows this html element on the home page.

Found "."

How to disable that element from the app?

This is my app code.

func GetSignIn(c *gin.Context) {
    // Get session from cookie. Check if email exists
    // redirect to Home page else show signin page.
    session := sessions.Default(c)
    if session.Get("email") != nil {
        fmt.Println(session.Get("email"))
        c.Redirect(302, "/")
    }
    c.HTML(200, "signin.html", "")
}

It seems like, it's a Go thing
https://github.com/golang/go/blob/master/src/net/http/server.go#L2014

But I'm not sure, how to disable it. Would be great if someone guide me.

Thanks!


问:
Error in building mongodb source code using Visual C++
I followed make_vcxproj comment to create Visual C++ project. I also executed:

```<code>scons generated-sources
</code>```

for creating missed file. In master branch of mongo source code when I build the project I get following error:

Severity  Code    Description Project File    Line    Suppression State
  Error C2370   'kuint16max': redefinition; different storage class
  (compiling source file
  src\third_party\s2\base\strtoint.cc)  mongod  D:\Open
  Source\mongo\src\third_party\gperftools-2.5\src\base\basictypes.h 74

It seems there are two global definition of kuint16max one in integral_types.h and another in basictypes.h. Here is main part (related to error) in  basictypes.h file:

```<code>const uint16 kuint16max = (   (uint16) 0xFFFF);
const uint32 kuint32max = (   (uint32) 0xFFFFFFFF);
const uint64 kuint64max = ( (((uint64) kuint32max) << 32) | kuint32max );

const  int8  kint8max   = (   (  int8) 0x7F);
const  int16 kint16max  = (   ( int16) 0x7FFF);
const  int32 kint32max  = (   ( int32) 0x7FFFFFFF);
const  int64 kint64max =  ( ((( int64) kint32max) << 32) | kuint32max );

const  int8  kint8min   = (   (  int8) 0x80);
const  int16 kint16min  = (   ( int16) 0x8000);
const  int32 kint32min  = (   ( int32) 0x80000000);
const  int64 kint64min =  ( (((uint64) kint32min) << 32) | 0 );
</code>```

and in integral_types.h:

```<code>static const uint8  kuint8max  = (( uint8) 0xFF);
static const uint16 kuint16max = ((uint16) 0xFFFF);
static const uint32 kuint32max = ((uint32) 0xFFFFFFFF);
static const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF));
static const  int8  kint8min   = ((  int8) 0x80);
static const  int8  kint8max   = ((  int8) 0x7F);
static const  int16 kint16min  = (( int16) 0x8000);
static const  int16 kint16max  = (( int16) 0x7FFF);
static const  int32 kint32min  = (( int32) 0x80000000);
static const  int32 kint32max  = (( int32) 0x7FFFFFFF);
static const  int64 kint64min  = (( int64) GG_LONGLONG(0x8000000000000000));
static const  int64 kint64max  = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF));
</code>```

When I change git branch to stable branch, error still exist. So I think problem is in my build.

答:
Don't use the vcproj stuff to build MongoDB from source. It is intended for internal best-effort use by a few Windows developers. Instead, follow the build instructions in building.md and build with SCons on the command line. A good Windows build command line for the master branch might look like:

python ./buildscripts/scons.py --release -j12 --dynamic-windows --win-version-min=ws08r2 core

But do adjust the -j value as suitable for your local system. Note also that the building.md file is slightly out of date (a fix is currently in code review), and you will need VS2015 Update 3 along with two hotfixes.

Body:
I followed make_vcxproj comment to create Visual C++ project. I also executed:

scons generated-sources

for creating missed file. In master branch of mongo source code when I build the project I get following error:

Severity  Code    Description Project File    Line    Suppression State
  Error C2370   'kuint16max': redefinition; different storage class
  (compiling source file
  src\third_party\s2\base\strtoint.cc)  mongod  D:\Open
  Source\mongo\src\third_party\gperftools-2.5\src\base\basictypes.h 74

It seems there are two global definition of kuint16max one in integral_types.h and another in basictypes.h. Here is main part (related to error) in  basictypes.h file:

const uint16 kuint16max = (   (uint16) 0xFFFF);
const uint32 kuint32max = (   (uint32) 0xFFFFFFFF);
const uint64 kuint64max = ( (((uint64) kuint32max) << 32) | kuint32max );

const  int8  kint8max   = (   (  int8) 0x7F);
const  int16 kint16max  = (   ( int16) 0x7FFF);
const  int32 kint32max  = (   ( int32) 0x7FFFFFFF);
const  int64 kint64max =  ( ((( int64) kint32max) << 32) | kuint32max );

const  int8  kint8min   = (   (  int8) 0x80);
const  int16 kint16min  = (   ( int16) 0x8000);
const  int32 kint32min  = (   ( int32) 0x80000000);
const  int64 kint64min =  ( (((uint64) kint32min) << 32) | 0 );

and in integral_types.h:

static const uint8  kuint8max  = (( uint8) 0xFF);
static const uint16 kuint16max = ((uint16) 0xFFFF);
static const uint32 kuint32max = ((uint32) 0xFFFFFFFF);
static const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF));
static const  int8  kint8min   = ((  int8) 0x80);
static const  int8  kint8max   = ((  int8) 0x7F);
static const  int16 kint16min  = (( int16) 0x8000);
static const  int16 kint16max  = (( int16) 0x7FFF);
static const  int32 kint32min  = (( int32) 0x80000000);
static const  int32 kint32max  = (( int32) 0x7FFFFFFF);
static const  int64 kint64min  = (( int64) GG_LONGLONG(0x8000000000000000));
static const  int64 kint64max  = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF));

When I change git branch to stable branch, error still exist. So I think problem is in my build.


答:
As you can see here when you store a value in a float the actual number stored is not always what you expected. This is due to how floats are represented in binary (you can learn more on wiki).

Now, as shown in the 1st link, when you try to store 4.2 in change, you actually store 4.19.... Multiply it by 100, store it inside an int,and you get 419.

Changing your float into double will give you better (double) precision, and in your case, it will yield the expected result

```<code>double change; # float changed to double
do
{
    printf("O hai! Enter amount in dollars to convert in cents.\n");

    scanf("%lf",&change);   //accepts input in dollars # "%f" changed to "%lf"

} while(change < 0.00);

int i = change * 100;    //converts dollars into cents

printf("The equivalent cents are %d\n",i);

input: 4.2
output: 420
</code>```

on my machine.

Note that using double is not a fail-safe. It can also give misleading results, but it should behave better than float.

Body:
As you can see here when you store a value in a float the actual number stored is not always what you expected. This is due to how floats are represented in binary (you can learn more on wiki).

Now, as shown in the 1st link, when you try to store 4.2 in change, you actually store 4.19.... Multiply it by 100, store it inside an int,and you get 419.

Changing your float into double will give you better (double) precision, and in your case, it will yield the expected result

double change; # float changed to double
do
{
    printf("O hai! Enter amount in dollars to convert in cents.\n");

    scanf("%lf",&change);   //accepts input in dollars # "%f" changed to "%lf"

} while(change < 0.00);

int i = change * 100;    //converts dollars into cents

printf("The equivalent cents are %d\n",i);

input: 4.2
output: 420

on my machine.

Note that using double is not a fail-safe. It can also give misleading results, but it should behave better than float.


问:
Why is x^0 = x?
I have a very simple question.

Why is a number when XOR'ed with 0 gives the number itself.

Can someone please give the proof using an example.

Lets say I have the number 5

5^0==>

I think the answer should be just the last bit of 5 XOR'ed with 0, but the answer is still 5.

答:
0 is false, and 1 is true.

As per the definition, XOR operation A XOR B is "A or B, but not, A and B". So, since B is false, so the result will be A.

Also, XOR truth table shows that it outputs true whenever the inputs differ:

```<code>Input   Output

A   B   XOR Result
0   0   0
0   1   1
1   0   1
1   1   0
</code>```

As you can see, whatever be the value of A, if it is XORed with 0, the result is the bit itself.

So, as you say:

```<code> 5 = 101, 0 = 000
 When performing XOR operation on the individual bits:

 101
 000
----
 101  = 5.
</code>```

Hence, the result of X^0 is X itself.

Title: Why is x^0 = x?

Body:
0 is false, and 1 is true.

As per the definition, XOR operation A XOR B is "A or B, but not, A and B". So, since B is false, so the result will be A.

Also, XOR truth table shows that it outputs true whenever the inputs differ:

Input   Output

A   B   XOR Result
0   0   0
0   1   1
1   0   1
1   1   0

As you can see, whatever be the value of A, if it is XORed with 0, the result is the bit itself.

So, as you say:

 5 = 101, 0 = 000
 When performing XOR operation on the individual bits:

 101
 000
----
 101  = 5.

Hence, the result of X^0 is X itself.


问:
personal version control system to recommend
For personal use. Anyone can recommend the version control system for Windows</p>

答: Or CollabNet Subversion.  It's easy to set up and run as a Windows service.</p>


问:
How to send my notes to Output window in Visual Studio?
Have a look at the picture. No matter where i put console.writeline, nothing is showing in output. Where could be a mistake? Is something wrong with my output editor or what?

答:
Use Debug.WriteLine to write to the Output window as you want.

See also What's the difference between Console.WriteLine() vs Debug.WriteLine()?

ContentLicense: CC BY-SA 4.0


问:
HTML text does not appear white
I have html text that is colored white with css. I also have opacity set to 0.5, but that shouldn't change font color. It should stay white.

Is there any fix for this without removing opacity or background colors?

body {
  background: green;
}

.second-b {
  background-image: url(images/town.jpg);
  background-repeat: no-repeat;
  background-size: cover;
}

.color-box {
  width: 100%;
  height: 300px;
  background-color: red;
  opacity: 0.5;
  line-height: 300px;
  text-align: center;
}

.color-box-content {
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
  color: white;
  font-size: 22px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="second-b">
  <div class="color-box">
    <div class="color-box-content">Lorem ipsum</div>
  </div>
</div></code>```

答:
If you use opacity on an element it will affect all the items inside it,
you can use the opacity on the background-color only

```<code>background-color: rgba(255, 0, 0, 0.5);
</code>```

See code snippet:

body {
  background: green;
}

.second-b {
  background-image: url(images/town.jpg);
  background-repeat: no-repeat;
  background-size: cover;
}

.color-box {
  width: 100%;
  height: 300px;
  background-color: rgba(255, 0, 0, 0.5);
  line-height: 300px;
  text-align: center;
}

.color-box-content {
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
  color: white;
  font-size: 22px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="second-b">
  <div class="color-box">
    <div class="color-box-content">Lorem ipsum</div>
  </div>
</div></code>```

Title: HTML text does not appear white

Body:
I have html text that is colored white with css. I also have opacity set to 0.5, but that shouldn't change font color. It should stay white.

Is there any fix for this without removing opacity or background colors?

body {
  background: green;
}

.second-b {
  background-image: url(images/town.jpg);
  background-repeat: no-repeat;
  background-size: cover;
}

.color-box {
  width: 100%;
  height: 300px;
  background-color: red;
  opacity: 0.5;
  line-height: 300px;
  text-align: center;
}

.color-box-content {
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
  color: white;
  font-size: 22px;
}

Lorem ipsum

Body:
If you use opacity on an element it will affect all the items inside it,
you can use the opacity on the background-color only

background-color: rgba(255, 0, 0, 0.5);

See code snippet:

body {
  background: green;
}

.second-b {
  background-image: url(images/town.jpg);
  background-repeat: no-repeat;
  background-size: cover;
}

.color-box {
  width: 100%;
  height: 300px;
  background-color: rgba(255, 0, 0, 0.5);
  line-height: 300px;
  text-align: center;
}

.color-box-content {
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
  color: white;
  font-size: 22px;
}

<div class="second-b">
  <div class="color-box">
    <div class="color-box-content">Lorem ipsum</div>
  </div>
</div>


答:
Change your jQuery to this :

```<code>$('#listSlider-right-arrow').mousedown(function () {
  $(this).css('color', '#fff');
  $('#play-icon').css('color', '#01a89e');
});
$('#listSlider-right-arrow').mouseup(function () {
  $(this).css('color', 'green');
  $('#play-icon').css('color', 'white');
});
</code>```

.mousedown and .mouseup speak for themselves.

You also can add this to your CSS :

```<code>#listSlider-right-arrow:active {
  color: #fff;
}
#listSlider-right-arrow:active #play-icon {
  color: #01a89e;
}
</code>```

This works because #play-icon is in #listSlider-right-arrow

Title: jquery- reverse nested icon's color just on click not for ever

Body:
Change your jQuery to this :

$('#listSlider-right-arrow').mousedown(function () {
  $(this).css('color', '#fff');
  $('#play-icon').css('color', '#01a89e');
});
$('#listSlider-right-arrow').mouseup(function () {
  $(this).css('color', 'green');
  $('#play-icon').css('color', 'white');
});

.mousedown and .mouseup speak for themselves.

You also can add this to your CSS :

#listSlider-right-arrow:active {
  color: #fff;
}
#listSlider-right-arrow:active #play-icon {
  color: #01a89e;
}

This works because #play-icon is in #listSlider-right-arrow


问:
Trying to form a half triangle using a for loop, nothing is printing out
This is a practice exam question I was given to study for my java exam approaching...I was given the main method and cannot change the input, only alter the two other methods and their code. I need to print out

```<code>     &
    &&
   &&&
  &&&&
 &&&&&
&&&&&&
</code>```

I think I have written my for loop wrong to create the blank spaces, I cannot seem to get this write with the main method I have been give, any ideas?

```<code>public static void main(String[] args) {
    int size = 6;
    char c = '&';
    for (int i = 1; i < size + 1; i++) {
        drawBlanks(size, size - i);
        drawChars(size, size - i, c);
        System.out.println();
    }
    System.out.println();

}

public static void drawChars(int size, int i, char c) {

    for (int j = size; j < 1; j--) {
        System.out.print(c);
    }

}

public static void drawBlanks(int size, int i) {

    for (int k = 0; k <= i; k++) {
        System.out.print(" ");
    }
}
</code>```

答:
You have a problem in this loop :

```<code>for(int j = size; j < 1; j--)
</code>```

Instead change it to :

```<code>for (int j = size; j > i; j--) {
//-------------------^_^
</code>```

j should be > to i not j < to 1

Body:
This is a practice exam question I was given to study for my java exam approaching...I was given the main method and cannot change the input, only alter the two other methods and their code. I need to print out

     &
    &&
   &&&
  &&&&
 &&&&&
&&&&&&

I think I have written my for loop wrong to create the blank spaces, I cannot seem to get this write with the main method I have been give, any ideas?

public static void main(String[] args) {
    int size = 6;
    char c = '&';
    for (int i = 1; i < size + 1; i++) {
        drawBlanks(size, size - i);
        drawChars(size, size - i, c);
        System.out.println();
    }
    System.out.println();

}

public static void drawChars(int size, int i, char c) {

    for (int j = size; j < 1; j--) {
        System.out.print(c);
    }

}

public static void drawBlanks(int size, int i) {

    for (int k = 0; k <= i; k++) {
        System.out.print(" ");
    }
}

Body:
You have a problem in this loop :

for(int j = size; j < 1; j--)

Instead change it to :

for (int j = size; j > i; j--) {
//-------------------^_^

j should be > to i not j < to 1


问:
Distorted images from libWebP encoder
I had been using GDI+ & CxImage libraries for saving my images captured from the desktop and thought of moving to google's LibWebp as it is promising good quality images with better compression than JPEG or PNG.

I capture the desktop either using using directX or GDI on windows, encode and save them or transfer over the network and decode them on the other side. Every thing looks good except that the images captured with text are distorted but the same is not happening for web pages with heavy text content.

The texts are encoded properly whenever the background color changes(either being selected or highlighted). I do not understand what the problem is.

Here is a sample of an image of command prompt I encoded using libWebp, you can clearly see that the selected area is encoded properly and the rest are randomly distorted.

I do not find any resources or forums that discuss these kind of strange problems. Any help would be appreciated.

Thanks in advance.

答: The problem was with using the WebPPictureImportRGBA to import RGBA buffer, given 32bit RGBA as input,   using WebPPictureImportRGBX solved the problem.</p>

Title: Distorted images from libWebP encoder


问:
Can the Chef package resource accept a data bag?
I have a group of packages that would be nice to add to a data bag in order to install them all. Is it possible to use the package resource with a data bag?

EDIT: For instance - this is how I'm doing it with the chocolatey resource:

```<code>workstation_apps = data_bag_item('winapps','desktop_apps')

chocolatey_package workstation_apps['apps']
</code>```

This is the data bag structure:

```<code>{
  "id": "desktop_apps",
  "apps": [
   "slack",
   "putty",
   "jre8",
   "python2",
   "ruby",
   "chefdk",
   "vmwarevsphereclient",
   "vmwareworkstation",
   "vagrant",
   "terraform",
   "packer",
   "visualstudiocode",
   "pushbullet",
 ]
}
</code>```

This works with the "chocolatey" resource - but will it work with the standard package resource on linux (yum)?

答:
Yes, it is possible - it's all just code.

You can extract such information from a data bag and pass the list of package names as list to the package resource.

Body:
I have a group of packages that would be nice to add to a data bag in order to install them all. Is it possible to use the package resource with a data bag?

EDIT: For instance - this is how I'm doing it with the chocolatey resource:

workstation_apps = data_bag_item('winapps','desktop_apps')

chocolatey_package workstation_apps['apps']

This is the data bag structure:

{
  "id": "desktop_apps",
  "apps": [
   "slack",
   "putty",
   "jre8",
   "python2",
   "ruby",
   "chefdk",
   "vmwarevsphereclient",
   "vmwareworkstation",
   "vagrant",
   "terraform",
   "packer",
   "visualstudiocode",
   "pushbullet",
 ]
}

This works with the "chocolatey" resource - but will it work with the standard package resource on linux (yum)?


答:
What is there that you did not understand. Please read about XOR</p>

```<code>00000101 // = 5
00000000 // = 0
--------
00000101 // = 5
</code>```

Title: Why is x^0 = x?

Body:
I have a very simple question.

Why is a number when XOR'ed with 0 gives the number itself.

Can someone please give the proof using an example.

Lets say I have the number 5

5^0==>

I think the answer should be just the last bit of 5 XOR'ed with 0, but the answer is still 5.

Body:
What is there that you did not understand. Please read about XOR

00000101 // = 5
00000000 // = 0
--------
00000101 // = 5


答:
opacity Property affect on all his children.

you can use The following attributes :

1)background-color:hsla(0,100%,50%,0.5);

2)background-color:rgba(255,0,0,0.5);

body{
    background: green;
}

.second-b{
    background-image: url(images/town.jpg);
    background-repeat: no-repeat;
    background-size: cover;
}

.color-box{
    width:100%;
    height:300px;
    background-color:hsla(0,100%,50%,0.5);
    line-height: 300px;
    text-align: center;
}

.color-box-content{
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
  color:white;
  font-size:22px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="second-b">
    <div class="color-box">
         <div class="color-box-content">Lorem ipsum</div>
    </div>
</div></code>```

Title: HTML text does not appear white

Body:
opacity Property affect on all his children.

you can use The following attributes :

1)background-color:hsla(0,100%,50%,0.5);

2)background-color:rgba(255,0,0,0.5);

body{
    background: green;
}

.second-b{
    background-image: url(images/town.jpg);
    background-repeat: no-repeat;
    background-size: cover;
}

.color-box{
    width:100%;
    height:300px;
    background-color:hsla(0,100%,50%,0.5);
    line-height: 300px;
    text-align: center;
}

.color-box-content{
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
  color:white;
  font-size:22px;
}

<div class="second-b">
    <div class="color-box">
         <div class="color-box-content">Lorem ipsum</div>
    </div>
</div>


问:
When using java 8 map, filter and collect, does it create new objects or modify existing objects?
I have the code below where I am doing filtering using a filter and replace function inside my map and then I am doing a collect to replace my original array. My question is whether my original objects in inputArr are being discarded and new objects are created or are the same objects being modified when I am doing a collect?</p>

```<code>public static void test () {
    inputArr.stream().filter(s -> toRemove.contains(s)).
            forEach(u -> u.replaceAll("2","X"));
    inputArr = inputArr.stream().map(x -> filterReplace(x,toRemove)).collect(Collectors.toList());
    System.out.println(inputArr);
}

static String filterReplace(String input, Set<String> toRemove) {
    if (toRemove.contains(input)) {
        return "X";
    }
    else
        return input;
}
</code>```

答:
OK so if I understood correctly you want to find out if collect or forEach modifies the original source. You could have easily tested this yourself. Let's have a small class for test:

```<code>static class MyObject {
    private int value;

    public MyObject(int value) {
        super();
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return System.identityHashCode(this) + " " + value;
    }
}
</code>```

And a small usage, firs with forEach:

```<code>    MyObject first = new MyObject(1);
    MyObject second = new MyObject(2);
    List<MyObject> list = Arrays.asList(first, second);

    System.out.println(list);
    list.stream().forEach(x -> x.setValue(x.getValue() + 1));
    System.out.println(list);
</code>```

If you print these:

```<code>[1018081122 1, 242131142 2]
[1018081122 2, 242131142 3]
</code>```

Notice that its the same same hash - objects have not changed inside the list. The references are the same. What you have changed is the internals of an Object.

Same thing would happen for collect:

```<code>    System.out.println(list);
    List<MyObject> result = list.stream().filter(x -> x.getValue() > 0).collect(Collectors.toList());
    System.out.println(result);
</code>```

There are two main things to get here. Streams iterate over the existing source, if inside your stream you change some property (like in forEach example), you have changed the source.

You should not change the source of your stream as this is prohibited by the documentation. This is either called non-interference or side-effects.

Body:
I have the code below where I am doing filtering using a filter and replace function inside my map and then I am doing a collect to replace my original array. My question is whether my original objects in inputArr are being discarded and new objects are created or are the same objects being modified when I am doing a collect?

public static void test () {
    inputArr.stream().filter(s -> toRemove.contains(s)).
            forEach(u -> u.replaceAll("2","X"));
    inputArr = inputArr.stream().map(x -> filterReplace(x,toRemove)).collect(Collectors.toList());
    System.out.println(inputArr);
}

static String filterReplace(String input, Set<String> toRemove) {
    if (toRemove.contains(input)) {
        return "X";
    }
    else
        return input;
}

Body:
OK so if I understood correctly you want to find out if collect or forEach modifies the original source. You could have easily tested this yourself. Let's have a small class for test:

static class MyObject {
    private int value;

    public MyObject(int value) {
        super();
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return System.identityHashCode(this) + " " + value;
    }
}

And a small usage, firs with forEach:

    MyObject first = new MyObject(1);
    MyObject second = new MyObject(2);
    List<MyObject> list = Arrays.asList(first, second);

    System.out.println(list);
    list.stream().forEach(x -> x.setValue(x.getValue() + 1));
    System.out.println(list);

If you print these:

[1018081122 1, 242131142 2]
[1018081122 2, 242131142 3]

Notice that its the same same hash - objects have not changed inside the list. The references are the same. What you have changed is the internals of an Object.

Same thing would happen for collect:

    System.out.println(list);
    List<MyObject> result = list.stream().filter(x -> x.getValue() > 0).collect(Collectors.toList());
    System.out.println(result);

There are two main things to get here. Streams iterate over the existing source, if inside your stream you change some property (like in forEach example), you have changed the source.

You should not change the source of your stream as this is prohibited by the documentation. This is either called non-interference or side-effects.


问:
XSS am I doing it wrong? CI / php
I am working on an public facing interface that makes use of a database that is effectively untrusted due to multiple applications accessing it.

I would like a clean way of encoding all my output to UTF-8 with htmlentities to prevent XSS.

Codeigniter (CI) has nothing built in. The filter that is there is meant for input and does not actually filter all XSS attacks.

I would prefer a blanket fix but don’t think there is one.

What I’m really after in this discussion is what is the best way to filter my output? And is the following the best / most concise solution? (encode function is a wrapper on htmlentities with utf8 and ent_compat)

```<code><?php
    echo form_input(“start_date[”.encode($id).”]”, encode($action->start_date,true), class=“input input-date dateISO required” readonly=readonly title=“must set a date.”’);
?>
</code>```

As you can see the code starts looking pretty silly sprinkling this encode function everywhere. Encoding at controller level is just not a solution as CI doesn’t use strict templating. Encoding at model level leaves other possible avenues open. Encoding at time of output seems like the safest / catch all cases way of doing things, I just want someone to confirm I’m not missing something obvious and nicer to look at / maintain

答:
IMHO CodeIgniter were designed to filter from the input. It assumes that your data is already clean when the application were initialized, and you obtained input from form fields with the correct syntax :

```<code>$data["field"] = $this->input->post("field",true);
</code>```

The second parameter to post is to enable XSS filtering, see the declaration of post function  in system/libraries/CI_Input.php:

```<code>function post($index = '', $xss_clean = FALSE)
    {
        return $this->_fetch_from_array($_POST, $index, $xss_clean);
    }
</code>```

Title: XSS am I doing it wrong? CI / php

Body:
I am working on an public facing interface that makes use of a database that is effectively untrusted due to multiple applications accessing it.

I would like a clean way of encoding all my output to UTF-8 with htmlentities to prevent XSS.

Codeigniter (CI) has nothing built in. The filter that is there is meant for input and does not actually filter all XSS attacks.

I would prefer a blanket fix but don’t think there is one.

What I’m really after in this discussion is what is the best way to filter my output? And is the following the best / most concise solution? (encode function is a wrapper on htmlentities with utf8 and ent_compat)

<?php
    echo form_input(“start_date[”.encode($id).”]”, encode($action->start_date,true), class=“input input-date dateISO required” readonly=readonly title=“must set a date.”’);
?>

As you can see the code starts looking pretty silly sprinkling this encode function everywhere. Encoding at controller level is just not a solution as CI doesn’t use strict templating. Encoding at model level leaves other possible avenues open. Encoding at time of output seems like the safest / catch all cases way of doing things, I just want someone to confirm I’m not missing something obvious and nicer to look at / maintain

Body:
IMHO CodeIgniter were designed to filter from the input. It assumes that your data is already clean when the application were initialized, and you obtained input from form fields with the correct syntax :

$data["field"] = $this->input->post("field",true);

The second parameter to post is to enable XSS filtering, see the declaration of post function  in system/libraries/CI_Input.php:

function post($index = '', $xss_clean = FALSE)
    {
        return $this->_fetch_from_array($_POST, $index, $xss_clean);
    }


问:
"Error: Could not find or load main class jdk1.8.0_111"
I am new to java, i trying to run as java application in my eclipse. But i am getting Error: Could not find or load main class jdk1.8.0_111. I have jdk1.8.0_111 and jre1.8.0_111.

What does this mean, what causes it, and how should you fix it?

答: Can you describe your problem more clearly? You may be java is not installed successfully, if you sure the installation is successful, cmd input "java" will be prompted, please make sure you install java success.</p>


问:
ConstraintLayout: z-index issue
I am using ConstraintLayout for activity:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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="match_parent"
    tools:context="com.site.path.to.AuthenticationActivity">

    <EditText
        android:id="@+id/login"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="none"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <EditText
        android:id="@+id/password"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/login"/>

    <Button
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Log in"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/password"/>

    <FrameLayout
        android:visibility="gone"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/default_background"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

FrameLayout should hide all content of the page when visible. But it hides all content except button. Why the button doesn't hide? How to fix it?

答:
Editted:

Try to set android:stateListAnimator="@null" to the Button/AppCompatButton

In Lollipop (Android 5.0 (API 21)) and above, Buttons have a default elevation which causes them to always draw on top.

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent">

    <ImageView
        android:id="@+id/background_image"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="centerCrop"
        android:tint="#80000000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/logo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="24dp"
        android:src="@drawable/logo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/background_image"
        app:layout_constraintVertical_bias="0.049"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="7dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="7dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:fontFamily="sans-serif-light"
        android:text="There is More"
        android:textColor="@android:color/white"
        app:layout_constraintBottom_toTopOf="@+id/scrollView2"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="@+id/logo"
        app:layout_constraintTop_toTopOf="@+id/logo"
        app:layout_constraintVertical_bias="1.0"
        tools:ignore="HardcodedText" />

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/logo"
        app:layout_constraintVertical_bias="0.050000012">

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_first_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeEditTextLight">

                <EditText
                    android:id="@+id/input_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Name"
                    android:inputType="textPersonName"
                    android:theme="@style/ThemeEditTextLight" />

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeEditTextLight">

                <EditText
                    android:id="@+id/input_email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Email"
                    android:inputType="textEmailAddress"
                    android:theme="@style/ThemeEditTextLight" />

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeEditTextLight">

                <EditText
                    android:id="@+id/input_phone"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Phone"
                    android:inputType="phone"
                    android:theme="@style/ThemeEditTextLight" />

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/input_layout_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:theme="@style/ThemeEditTextLight">

                    <EditText
                        android:id="@+id/input_password"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Password"
                        android:inputType="textPassword"
                        android:theme="@style/ThemeEditTextLight" />

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

            </LinearLayout>

        </LinearLayout>
    </ScrollView>

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/sign_up_button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:backgroundTint="#2a98f0"
        android:stateListAnimator="@null"
        android:elevation="0dp"
        android:paddingBottom="16dp"
        android:paddingTop="16dp"
        android:text="Sign up"
        android:textColor="@android:color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/scrollView2"
        app:layout_constraintVertical_bias="0.100000024" />

    <TextView
        android:id="@+id/or_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:fontFamily="sans-serif-light"
        android:gravity="center"
        android:text="or\nSign up with social sites"
        android:textColor="@color/white"
        app:layout_constraintBottom_toTopOf="@+id/imageView6"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/or_tv"
        app:layout_constraintVertical_bias="0.8"
        app:srcCompat="@drawable/ic_google_plus" />

    <FrameLayout
        android:id="@+id/progressBar"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/red"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ProgressBar
            android:id="@+id/progressBarChild"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />
    </FrameLayout>

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

This worked for me.

Title: ConstraintLayout: z-index issue

Body:
I am using ConstraintLayout for activity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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="match_parent"
    tools:context="com.site.path.to.AuthenticationActivity">

    <EditText
        android:id="@+id/login"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="none"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <EditText
        android:id="@+id/password"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/login"/>

    <Button
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Log in"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/password"/>

    <FrameLayout
        android:visibility="gone"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/default_background"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

FrameLayout should hide all content of the page when visible. But it hides all content except button. Why the button doesn't hide? How to fix it?

Body:
Editted:

Try to set android:stateListAnimator="@null" to the Button/AppCompatButton

In Lollipop (Android 5.0 (API 21)) and above, Buttons have a default elevation which causes them to always draw on top.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent">

    <ImageView
        android:id="@+id/background_image"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="centerCrop"
        android:tint="#80000000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/logo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="24dp"
        android:src="@drawable/logo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/background_image"
        app:layout_constraintVertical_bias="0.049"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="7dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="7dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:fontFamily="sans-serif-light"
        android:text="There is More"
        android:textColor="@android:color/white"
        app:layout_constraintBottom_toTopOf="@+id/scrollView2"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="@+id/logo"
        app:layout_constraintTop_toTopOf="@+id/logo"
        app:layout_constraintVertical_bias="1.0"
        tools:ignore="HardcodedText" />

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/logo"
        app:layout_constraintVertical_bias="0.050000012">

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_first_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeEditTextLight">

                <EditText
                    android:id="@+id/input_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Name"
                    android:inputType="textPersonName"
                    android:theme="@style/ThemeEditTextLight" />

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeEditTextLight">

                <EditText
                    android:id="@+id/input_email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Email"
                    android:inputType="textEmailAddress"
                    android:theme="@style/ThemeEditTextLight" />

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeEditTextLight">

                <EditText
                    android:id="@+id/input_phone"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Phone"
                    android:inputType="phone"
                    android:theme="@style/ThemeEditTextLight" />

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/input_layout_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:theme="@style/ThemeEditTextLight">

                    <EditText
                        android:id="@+id/input_password"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Password"
                        android:inputType="textPassword"
                        android:theme="@style/ThemeEditTextLight" />

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

            </LinearLayout>

        </LinearLayout>
    </ScrollView>

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/sign_up_button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:backgroundTint="#2a98f0"
        android:stateListAnimator="@null"
        android:elevation="0dp"
        android:paddingBottom="16dp"
        android:paddingTop="16dp"
        android:text="Sign up"
        android:textColor="@android:color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/scrollView2"
        app:layout_constraintVertical_bias="0.100000024" />

    <TextView
        android:id="@+id/or_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:fontFamily="sans-serif-light"
        android:gravity="center"
        android:text="or\nSign up with social sites"
        android:textColor="@color/white"
        app:layout_constraintBottom_toTopOf="@+id/imageView6"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/or_tv"
        app:layout_constraintVertical_bias="0.8"
        app:srcCompat="@drawable/ic_google_plus" />

    <FrameLayout
        android:id="@+id/progressBar"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/red"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ProgressBar
            android:id="@+id/progressBarChild"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />
    </FrameLayout>

</android.support.constraint.ConstraintLayout>

This worked for me.