问:
md-datepicker shows error when date entered manually
I am using md-datepicker, when i put date manually it is showing invalid date but if i select date from this control then it is validated. for this i have used following code</p>

```<code>    <md-datepicker name="FromDate" ng-model="vm.user.FromDate" ng-required="true" id="FromDate" md-is-error="login.ToDate.$invalid && login..$submitted" md-placeholder="FromDate"></md-datepicker>
<div ng-messages="login.FromDate.$error" md-auto-hide="false" ng-show="login.FromDate.$touched ||login.FromDate.$submitted">
<div ng-message="required">Please enter FromDate.</div>                    </div>
</code>```

答:
i found the answer. in config section along with formatDate i added parseDate function and it is working fine no error while manual entry as well as selection from control</p>

```<code>  .config(function ($mdDateLocaleProvider) {
        $mdDateLocaleProvider.formatDate = function (date) {
            return date ? moment(date).format('DD-MM-YYYY') : '';
        };

        $mdDateLocaleProvider.parseDate = function (dateString) {
            var m = moment(dateString, 'DD-MM-YYYY', true);
            return m.isValid() ? m.toDate() : new Date(NaN);
        };
    });
</code>```

Body:
I am using md-datepicker, when i put date manually it is showing invalid date but if i select date from this control then it is validated. for this i have used following code

    <md-datepicker name="FromDate" ng-model="vm.user.FromDate" ng-required="true" id="FromDate" md-is-error="login.ToDate.$invalid && login..$submitted" md-placeholder="FromDate"></md-datepicker>

Please enter FromDate.

Body:
i found the answer. in config section along with formatDate i added parseDate function and it is working fine no error while manual entry as well as selection from control

  .config(function ($mdDateLocaleProvider) {
        $mdDateLocaleProvider.formatDate = function (date) {
            return date ? moment(date).format('DD-MM-YYYY') : '';
        };

        $mdDateLocaleProvider.parseDate = function (dateString) {
            var m = moment(dateString, 'DD-MM-YYYY', true);
            return m.isValid() ? m.toDate() : new Date(NaN);
        };
    });


来源: stackexchange

问:
How do I check if an <s:message /> has been set in JSF?
I have the following two files (JSF 1.2) to build a form:

```<code><!-- segment of form.xhtml -->
<s:decorate template="edit.xhtml">
    <h:inputText label="First Name" id="firstName" required="true" value="#{contactBean.firstName}">
        <f:validateLength minimum="1" maximum="25"/>
    </h:inputText>
</s:decorate>

<!-- segment of edit.xhtml -->
<s:validateAll>
    <ui:insert />
</s:validateAll>

<h:graphicImage value="/images/errorIcon.png" rendered="#{when we have a message for this input}" />
<s:message />
</code>```

In edit.xhtml, is there an expression I use in the <h:graphicImage> rendered attribute?

I tried rendered="#{invalid}", but the invalid remains true even after the <s:messages /> are cleared. This results in the errorIcon.png being displayed without an associated <s:message />.

Let me know if I'm taking entirely the wrong approach.

答:
I'm not sure about the Seam part, I'll only suggest the generic JSF approach. I see basically two ways to achieve this requirement:

Wrap FacesContext#getMessages(String clientId) in a bean property.

```<code>public boolean hasMessages(String clientId) {
    return FacesContext.getCurrentInstance().getMessages(clientId).hasNext();
}
</code>```

Use it as follows:

```<code><h:graphicImage rendered="#{bean.hasMessages('form:firstName')}" />
</code>```

(I assume that you're already using JBoss EL)

Set the image as CSS background image instead (my preferred approach):

```<code><s:message errorClass="message error" />
</code>```

with

```<code>.message.error {
    background: url('error.png') no-repeat left center;
    padding-left: 15px;
}
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I have the following two files (JSF 1.2) to build a form:

<s:decorate template="edit.xhtml">
    <h:inputText label="First Name" id="firstName" required="true" value="#{contactBean.firstName}">
        <f:validateLength minimum="1" maximum="25"/>
    </h:inputText>
</s:decorate>

<s:validateAll>
    <ui:insert />
</s:validateAll>

<h:graphicImage value="/images/errorIcon.png" rendered="#{when we have a message for this input}" />
<s:message />

In edit.xhtml, is there an expression I use in the <h:graphicImage> rendered attribute?

I tried rendered="#{invalid}", but the invalid remains true even after the <s:messages /> are cleared. This results in the errorIcon.png being displayed without an associated <s:message />.

Let me know if I'm taking entirely the wrong approach.

Body:
I'm not sure about the Seam part, I'll only suggest the generic JSF approach. I see basically two ways to achieve this requirement:

Wrap FacesContext#getMessages(String clientId) in a bean property.

public boolean hasMessages(String clientId) {
    return FacesContext.getCurrentInstance().getMessages(clientId).hasNext();
}

Use it as follows:

<h:graphicImage rendered="#{bean.hasMessages('form:firstName')}" />

(I assume that you're already using JBoss EL)

Set the image as CSS background image instead (my preferred approach):

<s:message errorClass="message error" />

with

.message.error {
    background: url('error.png') no-repeat left center;
    padding-left: 15px;
}


问:
Rename uploaded user image Google Cloud
I have the images uploading to google cloud, however I am not able to rename them to a random string before the image is uploaded.

I am wondering if anyone has a solution to this please.

Code:

```<code><?php
# Includes the autoloader for libraries installed with composer
require '../vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;

putenv('GOOGLE_APPLICATION_CREDENTIALS=/PATH TO JSON');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();

$client->setSubject($user_to_impersonate);

   $storage = new StorageClient([
      'projectId' => 'XXXXXXXXXX'
  ]);

   $bucket = $storage->bucket('abcd');

// Upload a file to the bucket.
$bucket->upload(
    fopen('./test.jpg', 'r') // I WANT TO RENAME THIS FILE BEING UPLOADED AND YES i UNDERSTAND IT WILL BE A $_FILE TYPE WHEN I FINISH THE CODE.
);

// Download and store an object from the bucket locally.
$object = $bucket->object('test.jpg');
$object->downloadToFile('/cache/test2.jpg');

?>
</code>```

答:
Ok the answer is really easy, first you need to read the file that you want to upload. second you will want to generate your new filename, for this i used two user properties (these will most likely stay the same or change very rarely). I also used the timestamp of the request. My theory is no two people should have the same personal information (IP address & user agent) [I will add the users UID once i have finished the prototype.

If anyone else would like the code please see below, and please improve it & share the changes you would make (be great to see what we all come up with.

THIS IS FREE TO USE AND NO NEED TO GIVE CREDIT

```<code>$new_file_name     =   md5(time().md5($_SERVER['REMOTE_ADDR']).md5($_SERVER['HTTP_USER_AGENT']));
    $path = "./test.jpg";
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $current = file_get_contents('./test.jpg');
    $rand = $new_file_name.".".$ext;
    echo $rand;
    file_put_contents("./cache/".$rand, $current);

// Upload a file to the bucket.
$bucket->upload(
    fopen('./cache/'.$rand, 'r')
);
</code>```

The only problem with it is that you are left with the new files in cache folder but you can add a delete function after the file has been uploaded.

Full code on github

OFFICIAL GITHUB REPO

ContentLicense: CC BY-SA 3.0

Title: Rename uploaded user image Google Cloud

Body:
I have the images uploading to google cloud, however I am not able to rename them to a random string before the image is uploaded.

I am wondering if anyone has a solution to this please.

Code:

<?php
# Includes the autoloader for libraries installed with composer
require '../vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;

putenv('GOOGLE_APPLICATION_CREDENTIALS=/PATH TO JSON');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();

$client->setSubject($user_to_impersonate);

   $storage = new StorageClient([
      'projectId' => 'XXXXXXXXXX'
  ]);

   $bucket = $storage->bucket('abcd');

// Upload a file to the bucket.
$bucket->upload(
    fopen('./test.jpg', 'r') // I WANT TO RENAME THIS FILE BEING UPLOADED AND YES i UNDERSTAND IT WILL BE A $_FILE TYPE WHEN I FINISH THE CODE.
);

// Download and store an object from the bucket locally.
$object = $bucket->object('test.jpg');
$object->downloadToFile('/cache/test2.jpg');

?>

Body:
Ok the answer is really easy, first you need to read the file that you want to upload. second you will want to generate your new filename, for this i used two user properties (these will most likely stay the same or change very rarely). I also used the timestamp of the request. My theory is no two people should have the same personal information (IP address & user agent) [I will add the users UID once i have finished the prototype.

If anyone else would like the code please see below, and please improve it & share the changes you would make (be great to see what we all come up with.

THIS IS FREE TO USE AND NO NEED TO GIVE CREDIT

$new_file_name     =   md5(time().md5($_SERVER['REMOTE_ADDR']).md5($_SERVER['HTTP_USER_AGENT']));
    $path = "./test.jpg";
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $current = file_get_contents('./test.jpg');
    $rand = $new_file_name.".".$ext;
    echo $rand;
    file_put_contents("./cache/".$rand, $current);

// Upload a file to the bucket.
$bucket->upload(
    fopen('./cache/'.$rand, 'r')
);

The only problem with it is that you are left with the new files in cache folder but you can add a delete function after the file has been uploaded.

Full code on github

OFFICIAL GITHUB REPO


问:
Create a person with alfresco RESTApi using xmlhttprequest
So I'm creating a custom share page for alfresco and I want to create a person using javascript thanks to the REST API (You will find all the doc about the api and why I shaped my var this way here) so I wrote this code which contains a xmlhttprequest to post the data :

```<code>var boby = "{ \"id\": \"bob\",\"firstName\": \"Bob\", \"lastName\": \"LeBricoleur\", \"email\": \"bob@lebricoleur.com\", \"telephone\": \"6666666666\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"bob\" }";
                        console.log(boby);
                        function loadDoc() {
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function() {
                            if (this.readyState == 4 && this.status == 200) {
                              document.getElementById("creatingperson").innerHTML = this.responseText;
                            }
                            };
                            xhttp.open("POST", 'http://localhost:8081/share/proxy/alfresco-api/-default-/public/alfresco/versions/1/people', true);
                            xhttp.setRequestHeader("Content-Type", "application/json");    //curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '[...]
                            xhttp.send(boby);
                        }
</code>```

Ok so this doesn't give me anything.. Not even an error message. At first I thought it was because of my whole code so I created the variable boby that I would send to the server to simplify the debug but I still don't know where the error comes from.

Is it a problem from my code ? From my way of using the api ? From alfresco share itself ? If you can help me thanks a lot !

P.S : I wrote a code to list people (instead of creating one) which works using the same url if that can help

[EDIT]

I've found another way to make my request and it works but I don't know why.. here is the code :

```<code>var createperson = "{ \"id\": \"" + document.getElementById('login').value + "\",\"firstName\": \"" + document.getElementById('firstName').value + "\", \"lastName\": \"" + document.getElementById('lastName').value + "\", \"email\": \"" + document.getElementById('mail').value + "\", \"telephone\": \"" + document.getElementById('telephone').value + "\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"" + document.getElementById('pwd2').value + "\" }";
                        console.log(createperson);
                            var url = "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people";
                            var method = "POST";
                            var async = true;
                            //var postData = "{ \"id\": \"bob\",\"firstName\": \"Bob\", \"lastName\": \"LeBricoleur\", \"email\": \"bob@lebricoleur.com\", \"telephone\": \"6666666666\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"bob\" }";

                            var request = new XMLHttpRequest();
                            request.onload = function () {
                               var status = request.status; // HTTP response status, e.g., 201 for "201 OK"
                               var data = request.responseText; // Returned data, e.g., an HTML document.
                                console.log("status :");
                                console.log(status);
                                console.log("data :");
                                console.log(data);
                            }

                            request.open(method, url, async);
                            request.setRequestHeader("Content-Type", "application/json");
                            request.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
                            request.send(createperson);
</code>```

Moreover when I try to use this type of request to list the people (just to use the method everywhere) it doesn't work.. here is a part of what I wrote to list people :

```<code>var url = "http://192.168.1.103:8080/alfresco/api/-default-/public/alfresco/versions/1/people";
         var method = "GET";
         var async = true;
         var request = new XMLHttpRequest();
         request.onload = function () {
               var status = request.status; // HTTP response status, e.g., 201 for "201 OK"
           objet = JSON.parse(request.responseText);
               console.log("status :");
               console.log(status);
               console.log("data :");
               console.log(objet);
         }

         request.open(method, url, async); //, "admin", "admin");
         request.setRequestHeader("Content-Type", "application/json");
         request.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
</code>```

So if anyone knows why it worked for creating someone and why it doesn't for listing thank you for your answer !

答:
Basically there can be 2 issues.

1.This api is only supported in alfresco version 5.2 and letter and your version should be below 5.2.
2.There was some CSRF token issue in xhr call.Can be solved by adding csrf token.For this function code is as below.

```<code>function loadDoc() {
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function(demo) {console.log(demo.error);
                            if (this.readyState == 4 && this.status == 200) {
                              console.log(this);
                            }
                            };
                            xhttp.open("POST", 'http://localhost:8081/share/proxy/alfresco-api/-default-/public/alfresco/versions/1/people', true);
                            xhttp.setRequestHeader("Content-Type", "application/json");
                            xhttp.setRequestHeader(Alfresco.util.CSRFPolicy.getHeader(), Alfresco.util.CSRFPolicy.getToken());//CSRF Token
                            xhttp.send(boby);
                        }
</code>```

Body:
So I'm creating a custom share page for alfresco and I want to create a person using javascript thanks to the REST API (You will find all the doc about the api and why I shaped my var this way here) so I wrote this code which contains a xmlhttprequest to post the data :

var boby = "{ \"id\": \"bob\",\"firstName\": \"Bob\", \"lastName\": \"LeBricoleur\", \"email\": \"bob@lebricoleur.com\", \"telephone\": \"6666666666\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"bob\" }";
                        console.log(boby);
                        function loadDoc() {
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function() {
                            if (this.readyState == 4 && this.status == 200) {
                              document.getElementById("creatingperson").innerHTML = this.responseText;
                            }
                            };
                            xhttp.open("POST", 'http://localhost:8081/share/proxy/alfresco-api/-default-/public/alfresco/versions/1/people', true);
                            xhttp.setRequestHeader("Content-Type", "application/json");    //curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '[...]
                            xhttp.send(boby);
                        }

Ok so this doesn't give me anything.. Not even an error message. At first I thought it was because of my whole code so I created the variable boby that I would send to the server to simplify the debug but I still don't know where the error comes from.

Is it a problem from my code ? From my way of using the api ? From alfresco share itself ? If you can help me thanks a lot !

P.S : I wrote a code to list people (instead of creating one) which works using the same url if that can help

[EDIT]

I've found another way to make my request and it works but I don't know why.. here is the code :

var createperson = "{ \"id\": \"" + document.getElementById('login').value + "\",\"firstName\": \"" + document.getElementById('firstName').value + "\", \"lastName\": \"" + document.getElementById('lastName').value + "\", \"email\": \"" + document.getElementById('mail').value + "\", \"telephone\": \"" + document.getElementById('telephone').value + "\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"" + document.getElementById('pwd2').value + "\" }";
                        console.log(createperson);
                            var url = "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people";
                            var method = "POST";
                            var async = true;
                            //var postData = "{ \"id\": \"bob\",\"firstName\": \"Bob\", \"lastName\": \"LeBricoleur\", \"email\": \"bob@lebricoleur.com\", \"telephone\": \"6666666666\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"bob\" }";

                            var request = new XMLHttpRequest();
                            request.onload = function () {
                               var status = request.status; // HTTP response status, e.g., 201 for "201 OK"
                               var data = request.responseText; // Returned data, e.g., an HTML document.
                                console.log("status :");
                                console.log(status);
                                console.log("data :");
                                console.log(data);
                            }

                            request.open(method, url, async);
                            request.setRequestHeader("Content-Type", "application/json");
                            request.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
                            request.send(createperson);

Moreover when I try to use this type of request to list the people (just to use the method everywhere) it doesn't work.. here is a part of what I wrote to list people :

var url = "http://192.168.1.103:8080/alfresco/api/-default-/public/alfresco/versions/1/people";
         var method = "GET";
         var async = true;
         var request = new XMLHttpRequest();
         request.onload = function () {
               var status = request.status; // HTTP response status, e.g., 201 for "201 OK"
           objet = JSON.parse(request.responseText);
               console.log("status :");
               console.log(status);
               console.log("data :");
               console.log(objet);
         }

         request.open(method, url, async); //, "admin", "admin");
         request.setRequestHeader("Content-Type", "application/json");
         request.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");

So if anyone knows why it worked for creating someone and why it doesn't for listing thank you for your answer !

Body:
Basically there can be 2 issues.

1.This api is only supported in alfresco version 5.2 and letter and your version should be below 5.2.
2.There was some CSRF token issue in xhr call.Can be solved by adding csrf token.For this function code is as below.

function loadDoc() {
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function(demo) {console.log(demo.error);
                            if (this.readyState == 4 && this.status == 200) {
                              console.log(this);
                            }
                            };
                            xhttp.open("POST", 'http://localhost:8081/share/proxy/alfresco-api/-default-/public/alfresco/versions/1/people', true);
                            xhttp.setRequestHeader("Content-Type", "application/json");
                            xhttp.setRequestHeader(Alfresco.util.CSRFPolicy.getHeader(), Alfresco.util.CSRFPolicy.getToken());//CSRF Token
                            xhttp.send(boby);
                        }


问:
Accessing Akka HTTP client certificate for the current connection
I am current Apache Tomcat user designing an Akka HTTP based replacement for a HTTPS web service that uses client certificates for authentication and authorization.  Using Tomcat I am accustomed to retrieving the client X509Certificate with a servlet request attribute

request.getAttribute("javax.servlet.request.X509Certificate")

I need the certificate for some additional authorization checks inside the handler for select routes.  How would retrieve the client certificate in this way with Akka HTTP 10.0.x?

答:
You need to enable decorating requests with TLS session info through the config settings for the server:

```<code>akka.http.server.parsing.tls-session-info-header = on
</code>```

And then extract the info for a specific request using the synthetic header akka.http.scaladsl.model.headers.Tls-Session-Info like so:

```<code>headerValueByType[`Tls-Session-Info`]() { sessionInfo =>
  val sslSession = sessionInfo.getSession()
  sslSession.getPeerCertificates
  ... etc ...
</code>```

Body:
You need to enable decorating requests with TLS session info through the config settings for the server:

akka.http.server.parsing.tls-session-info-header = on

And then extract the info for a specific request using the synthetic header akka.http.scaladsl.model.headers.Tls-Session-Info like so:

headerValueByType[`Tls-Session-Info`]() { sessionInfo =>
  val sslSession = sessionInfo.getSession()
  sslSession.getPeerCertificates
  ... etc ...


问:
Value 0 or null when send a json from angular to c#
I have a problem with my project on Angular&C#. I'm a begginer and i have this problem. When I send a json from angular to C # (POST), although json has value, c # doesn't get anything (value 0 for int and null for string). I don't know what i'm doing wrong. The Json has this structure :

```<code>[{"delegacion":11,"municipio":1,"ejercicio":2017,"ninterno":-1,"tipo":"T"}]
</code>```

My code

Angular

```<code>preparaTarea(){
this.data.push({'delegacion':this.delegacion,
                    'municipio':this.municipio,
                    'ejercicio':this.ejercicio,
                    'ninterno':this.ninterno,
                    'tipo':this.tipo_producto});

     this._DelegationService.sendPtipo(this.data)
        .subscribe(res=>{
                this.data = res;
              },
              (err) =>console.log(err));

    }

sendPtipo(data){
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });
        let urlPtipo ='http://localhost:50790/ApiProductoTipo/CalculaPTRecinto';

        let body = JSON.stringify(data);
        console.log(body);

    return this._http.post(urlPtipo , body , options)
                   .map(data => {alert('ok');})
                   .catch(this.handleError);
    }

    private handleError(error: Response) {
        console.error(error);
        return Observable.throw(error.json().error || 'Server error');
    }}
</code>```

c#

```<code>public class MyObj
        {
            public int delegacion { get; set; }
            public int municipio { get; set; }
            public int ejercicio { get; set; }
            public int ninterno { get; set; }
            public string tipo { get; set; }

        }
        [HttpPost]
        [Route("~/ApiProductoTipo/CalculaPTRecinto")]
        public HttpResponseMessage CalculaPTRecinto([FromBody]MyObj data)
        {
            var delegacion = data.delegacion;
            var municipio = data.municipio;
            var recinto = data.ninterno;
            var ejercicio = data.ejercicio;
            var tipo = data.tipo;

            if (this.productoTipoService.CalculaPTRecinto(delegacion, municipio, recinto, ejercicio, tipo) != 0)
            {
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
</code>```

When i debug, the values of delegacion, municipio etc has 0 value, and null for tipo. Any ideas? Thanks a lot!

答:
Finally I solved my problem doing this </p>

```<code>  preparaTarea() {
     //Changing array by this
    let datos = { "delegacion":this.delegacion,
                  "municipio":this.municipio,
                  "ejercicio":this.ejercicio,
                  "ninterno":this.ninterno,
                  "tipo":this.tipo_producto
                  };

    this._CalculoPTService.sendPtipo(datos)
      .subscribe(res => {
        datos = res;
      },
      (err) => console.log(err));
  }
</code>```

Body:
I have a problem with my project on Angular&C#. I'm a begginer and i have this problem. When I send a json from angular to C # (POST), although json has value, c # doesn't get anything (value 0 for int and null for string). I don't know what i'm doing wrong. The Json has this structure :

[{"delegacion":11,"municipio":1,"ejercicio":2017,"ninterno":-1,"tipo":"T"}]

My code

Angular

preparaTarea(){
this.data.push({'delegacion':this.delegacion,
                    'municipio':this.municipio,
                    'ejercicio':this.ejercicio,
                    'ninterno':this.ninterno,
                    'tipo':this.tipo_producto});

     this._DelegationService.sendPtipo(this.data)
        .subscribe(res=>{
                this.data = res;
              },
              (err) =>console.log(err));

    }

sendPtipo(data){
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });
        let urlPtipo ='http://localhost:50790/ApiProductoTipo/CalculaPTRecinto';

        let body = JSON.stringify(data);
        console.log(body);

    return this._http.post(urlPtipo , body , options)
                   .map(data => {alert('ok');})
                   .catch(this.handleError);
    }

    private handleError(error: Response) {
        console.error(error);
        return Observable.throw(error.json().error || 'Server error');
    }}

c#

public class MyObj
        {
            public int delegacion { get; set; }
            public int municipio { get; set; }
            public int ejercicio { get; set; }
            public int ninterno { get; set; }
            public string tipo { get; set; }

        }
        [HttpPost]
        [Route("~/ApiProductoTipo/CalculaPTRecinto")]
        public HttpResponseMessage CalculaPTRecinto([FromBody]MyObj data)
        {
            var delegacion = data.delegacion;
            var municipio = data.municipio;
            var recinto = data.ninterno;
            var ejercicio = data.ejercicio;
            var tipo = data.tipo;

            if (this.productoTipoService.CalculaPTRecinto(delegacion, municipio, recinto, ejercicio, tipo) != 0)
            {
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }

When i debug, the values of delegacion, municipio etc has 0 value, and null for tipo. Any ideas? Thanks a lot!

Body:
Finally I solved my problem doing this

  preparaTarea() {
     //Changing array by this
    let datos = { "delegacion":this.delegacion,
                  "municipio":this.municipio,
                  "ejercicio":this.ejercicio,
                  "ninterno":this.ninterno,
                  "tipo":this.tipo_producto
                  };

    this._CalculoPTService.sendPtipo(datos)
      .subscribe(res => {
        datos = res;
      },
      (err) => console.log(err));
  }


问:
Extracting a specific row of a table by DOMDocument
how can I extract information from a HTML file by using DOMDocument in PHP

my HTML page has a source with this part inside

this is my third table in the page that I need to work on:

```<code> <table>
 <tbody>
 <tr>
   <td>A</td>
   <td>B</td>
   <td>C</td>
   <td>D</td>
</tr>
<tr>
  <td>1</td>
  <td>2</td>
  <td>3</td>
  <td>4</td>
</tr>
</tbody>
</table>
</code>```

If my use ask me for showing row with B and D how should I extract the first row of this table and print it by using DOMDocument?

答:
This code is tested by me enjoy it</p>

```<code>$table = "<table>
 <tbody>
 <tr>
   <td>A</td>
   <td>B</td>
   <td>C</td>
   <td>D</td>
</tr>
<tr>
  <td>1</td>
  <td>2</td>
  <td>3</td>
  <td>4</td>
</tr>
</tbody>
</table>";
$doc = new DOMDocument();
$doc->loadHTML('<?xml encoding="utf-8"?>' . $table);
$rows =$doc->getElementsByTagName('tr');
$tds= $doc->getElementsByTagName('td');
$ths= $doc->getElementsByTagName('th');
foreach ($ths as $th) {
echo "<p> th  = ".$th." </p>";
}
foreach ($tds as $td) {
echo "<p> td  = ".$td." </p>";
}
</code>```

Body:
how can I extract information from a HTML file by using DOMDocument in PHP

my HTML page has a source with this part inside

this is my third table in the page that I need to work on:

   A
   B
   C
   D

  1
  2
  3
  4

If my use ask me for showing row with B and D how should I extract the first row of this table and print it by using DOMDocument?

Body:
This code is tested by me enjoy it

$table = "<table>
 <tbody>
 <tr>
   <td>A</td>
   <td>B</td>
   <td>C</td>
   <td>D</td>
</tr>
<tr>
  <td>1</td>
  <td>2</td>
  <td>3</td>
  <td>4</td>
</tr>
</tbody>
</table>";
$doc = new DOMDocument();
$doc->loadHTML('<?xml encoding="utf-8"?>' . $table);
$rows =$doc->getElementsByTagName('tr');
$tds= $doc->getElementsByTagName('td');
$ths= $doc->getElementsByTagName('th');
foreach ($ths as $th) {
echo "<p> th  = ".$th." </p>";
}
foreach ($tds as $td) {
echo "<p> td  = ".$td." </p>";
}

ContentLicense: CC BY-SA 4.0


问:
How can we make use of CoreML framework for handwriting detection in iOS 11
How can I use CoreML to convert handwritten image to text?

答: One way to achieve this is to use the Vision framework to detect text in your image, which gives you a list of rectangles. Then use a neural network that's trained to recognize text on each of these rectangles. You can use Vision to drive Core ML but you still need to provide it with a suitable neural network yourself. You can find pretrained networks for this on the web, but you'll need to convert them to Core ML using the tools supplied by Apple.</p>


问:
Help with Delphi 7, ADO, & MS Access SQL Statement
I have three tables (in a MS Access Database 2000 file *.mdb)

Knowledge

id

question

answer

Knowledge_Keywords

id

knowledgeid

keywordsid

Keywords

id

keyword

Need to get all the keywords for a knowledge

Select distinct keyword from keywords KW

Join knowledge_keywords KKW on KKW.keywordid = KW.id

Join Knowledge K on K.id = KKW.knowledgeid

Where k.id =  10

of course 10 is a example, i actually use a parameter there

Where k.id = :AKnowId';

and fill it in in code

qry.Parameters.ParamByName('AKnowId').Value:= AKnowledgeId;

anyway, i think the SQL is qrong, any help would be greatly appreciated

答:
Solved it!

Select distinct keyword

from (keywords KW

inner Join knowledge_keywords KKW on KKW.keywordid = KW.id)

inner Join Knowledge K on K.id = KKW.knowledgeid

Where k.id =  10


问:
Rails find all order, found 0 results expected 2
I'm having trouble sorting my table based on the votes column, votes is a multivalued attribute so I use count and try to sort it based on that. here is the code

```<code>@topics = Topic.find(:all,:order=>'@topic.votes.count DESC')
</code>```

Rails returns an error that says

```<code>ActiveRecord::RecordNotFound in TopicsController#index
Couldn't find all Topics with 'id': (all, {:order=>"@topic.votes.count DESC"}) (found 0 results, but was looking for 2)
</code>```

Just starting out with rails and still confused with some things, your help will be much appreciated.

答:
Instead of join include is best and faster option

```<code>Topic.include(:votes).group('topics.id').order('count(topics.id) DESC')
</code>```

Body:
I'm having trouble sorting my table based on the votes column, votes is a multivalued attribute so I use count and try to sort it based on that. here is the code

@topics = Topic.find(:all,:order=>'@topic.votes.count DESC')

Rails returns an error that says

ActiveRecord::RecordNotFound in TopicsController#index
Couldn't find all Topics with 'id': (all, {:order=>"@topic.votes.count DESC"}) (found 0 results, but was looking for 2)

Just starting out with rails and still confused with some things, your help will be much appreciated.

Body:
Instead of join include is best and faster option

Topic.include(:votes).group('topics.id').order('count(topics.id) DESC')


问:
What may be the reason for loss can not go further down when training multi-class nn using keras
I am training a multi-class neural network by using keras (backend is tensorflow). I will give my settings and some codes at final position.

The description is:
When I do 10 folders cross-validation, the training loss and validation loss goes down at first 10-15 epochs, but can not go further down after 15 epochs and staying on about (loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774).

I have tried several changes for my settings. For example, add hidden layers, add normalization.BatchNormalization(), change optimizer from adam to sgd or rmsprop, change loss function from categorical_crossentropy to others. But no effect.

I would like to discuss what are the probable reasons for this kind of things. I would be very happy if there is a summary document or presentation here.

My data has 10000 rows. And feature has 507 attributes of 0/1. Labels are multi-class with classes num = 7. The balance between classes is almost OK, because I selected the 10000 data from a more large dataset.

My model is as follows:

```<code>model = Sequential()
model.add(Dense(500, activation='relu', input_dim=self.feature_dim,
kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(100, activation='relu'))
model.add(Dense(self.label_dim, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
</code>```

Some logs as follows:

```<code>Running Fold 1/10
Train on 9534 samples, validate on 1060 samples
Epoch 1/100
1000/9534 [==>...........................] - ETA: 7s - loss: 6.9644 - acc: 0.1150
2000/9534 [=====>........................] - ETA: 3s - loss: 6.8357 - acc: 0.1715
3000/9534 [========>.....................] - ETA: 2s - loss: 6.7147 - acc: 0.2243
4000/9534 [===========>..................] - ETA: 1s - loss: 6.5922 - acc: 0.2683
5000/9534 [==============>...............] - ETA: 1s - loss: 6.4779 - acc: 0.2908
6000/9534 [=================>............] - ETA: 0s - loss: 6.3618 - acc: 0.3097
7000/9534 [=====================>........] - ETA: 0s - loss: 6.2513 - acc: 0.3244
8000/9534 [========================>.....] - ETA: 0s - loss: 6.1465 - acc: 0.3340
9000/9534 [===========================>..] - ETA: 0s - loss: 6.0439 - acc: 0.3411
9534/9534 [==============================] - 1s - loss: 5.9900 - acc: 0.3442 - val_loss: 4.8716 - val_acc: 0.4377
Epoch 2/100
1000/9534 [==>...........................] - ETA: 0s - loss: 4.8370 - acc: 0.4340
2000/9534 [=====>........................] - ETA: 0s - loss: 4.7593 - acc: 0.4415
3000/9534 [========>.....................] - ETA: 0s - loss: 4.6923 - acc: 0.4423
4000/9534 [===========>..................] - ETA: 0s - loss: 4.6176 - acc: 0.4557
5000/9534 [==============>...............] - ETA: 0s - loss: 4.5517 - acc: 0.4642
6000/9534 [=================>............] - ETA: 0s - loss: 4.4809 - acc: 0.4703
7000/9534 [=====================>........] - ETA: 0s - loss: 4.4036 - acc: 0.4804
8000/9534 [========================>.....] - ETA: 0s - loss: 4.3364 - acc: 0.4821
9000/9534 [===========================>..] - ETA: 0s - loss: 4.2652 - acc: 0.4901
9534/9534 [==============================] - 1s - loss: 4.2316 - acc: 0.4928 - val_loss: 3.5151 - val_acc: 0.5179
Epoch 3/100
1000/9534 [==>...........................] - ETA: 1s - loss: 3.4892 - acc: 0.5370
2000/9534 [=====>........................] - ETA: 1s - loss: 3.4573 - acc: 0.5395
3000/9534 [========>.....................] - ETA: 0s - loss: 3.4006 - acc: 0.5450
4000/9534 [===========>..................] - ETA: 0s - loss: 3.3430 - acc: 0.5435
5000/9534 [==============>...............] - ETA: 0s - loss: 3.2929 - acc: 0.5448
6000/9534 [=================>............] - ETA: 0s - loss: 3.2414 - acc: 0.5448
7000/9534 [=====================>........] - ETA: 0s - loss: 3.1959 - acc: 0.5446
8000/9534 [========================>.....] - ETA: 0s - loss: 3.1489 - acc: 0.5485
9000/9534 [===========================>..] - ETA: 0s - loss: 3.1021 - acc: 0.5501
9534/9534 [==============================] - 1s - loss: 3.0832 - acc: 0.5481 - val_loss: 2.6184 - val_acc: 0.5349
Epoch 4/100
1000/9534 [==>...........................] - ETA: 1s - loss: 2.5950 - acc: 0.5640
2000/9534 [=====>........................] - ETA: 1s - loss: 2.5570 - acc: 0.5705
3000/9534 [========>.....................] - ETA: 0s - loss: 2.5197 - acc: 0.5743
4000/9534 [===========>..................] - ETA: 0s - loss: 2.4929 - acc: 0.5650
5000/9534 [==============>...............] - ETA: 0s - loss: 2.4703 - acc: 0.5646
6000/9534 [=================>............] - ETA: 0s - loss: 2.4388 - acc: 0.5648
7000/9534 [=====================>........] - ETA: 0s - loss: 2.4054 - acc: 0.5680
8000/9534 [========================>.....] - ETA: 0s - loss: 2.3798 - acc: 0.5649
9000/9534 [===========================>..] - ETA: 0s - loss: 2.3522 - acc: 0.5662
9534/9534 [==============================] - 1s - loss: 2.3342 - acc: 0.5685 - val_loss: 2.0442 - val_acc: 0.5491
Epoch 5/100
1000/9534 [==>...........................] - ETA: 0s - loss: 2.0090 - acc: 0.5830
2000/9534 [=====>........................] - ETA: 0s - loss: 1.9990 - acc: 0.5865
3000/9534 [========>.....................] - ETA: 0s - loss: 1.9812 - acc: 0.5833
4000/9534 [===========>..................] - ETA: 0s - loss: 1.9558 - acc: 0.5835
5000/9534 [==============>...............] - ETA: 0s - loss: 1.9377 - acc: 0.5832
6000/9534 [=================>............] - ETA: 0s - loss: 1.9173 - acc: 0.5832
7000/9534 [=====================>........] - ETA: 0s - loss: 1.8968 - acc: 0.5850
8000/9534 [========================>.....] - ETA: 0s - loss: 1.8759 - acc: 0.5851
9000/9534 [===========================>..] - ETA: 0s - loss: 1.8582 - acc: 0.5846
9534/9534 [==============================] - 1s - loss: 1.8501 - acc: 0.5834 - val_loss: 1.6868 - val_acc: 0.5500
Epoch 6/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.6716 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.6387 - acc: 0.5910
3000/9534 [========>.....................] - ETA: 0s - loss: 1.6163 - acc: 0.5910
4000/9534 [===========>..................] - ETA: 0s - loss: 1.6130 - acc: 0.5882
5000/9534 [==============>...............] - ETA: 0s - loss: 1.5982 - acc: 0.5890
6000/9534 [=================>............] - ETA: 0s - loss: 1.5861 - acc: 0.5892
7000/9534 [=====================>........] - ETA: 0s - loss: 1.5724 - acc: 0.5914
8000/9534 [========================>.....] - ETA: 0s - loss: 1.5578 - acc: 0.5922
9000/9534 [===========================>..] - ETA: 0s - loss: 1.5492 - acc: 0.5904
9534/9534 [==============================] - 0s - loss: 1.5468 - acc: 0.5893 - val_loss: 1.4677 - val_acc: 0.5585
Epoch 7/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.4380 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.4332 - acc: 0.5900
3000/9534 [========>.....................] - ETA: 0s - loss: 1.4208 - acc: 0.5957
4000/9534 [===========>..................] - ETA: 0s - loss: 1.4073 - acc: 0.5985
5000/9534 [==============>...............] - ETA: 0s - loss: 1.4027 - acc: 0.5960
6000/9534 [=================>............] - ETA: 0s - loss: 1.3922 - acc: 0.5950
7000/9534 [=====================>........] - ETA: 0s - loss: 1.3842 - acc: 0.5951
8000/9534 [========================>.....] - ETA: 0s - loss: 1.3729 - acc: 0.5988
9000/9534 [===========================>..] - ETA: 0s - loss: 1.3611 - acc: 0.6012
9534/9534 [==============================] - 1s - loss: 1.3588 - acc: 0.6015 - val_loss: 1.3387 - val_acc: 0.5717
Epoch 8/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.3429 - acc: 0.5750
2000/9534 [=====>........................] - ETA: 0s - loss: 1.3071 - acc: 0.5980
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2915 - acc: 0.6007
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2834 - acc: 0.5977
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2791 - acc: 0.6008
6000/9534 [=================>............] - ETA: 0s - loss: 1.2636 - acc: 0.6043
7000/9534 [=====================>........] - ETA: 0s - loss: 1.2521 - acc: 0.6049
8000/9534 [========================>.....] - ETA: 0s - loss: 1.2495 - acc: 0.6041
9000/9534 [===========================>..] - ETA: 0s - loss: 1.2506 - acc: 0.6031
9534/9534 [==============================] - 1s - loss: 1.2491 - acc: 0.6022 - val_loss: 1.2617 - val_acc: 0.5698
Epoch 9/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1627 - acc: 0.6240
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1709 - acc: 0.6235
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2001 - acc: 0.6127
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2000 - acc: 0.6098
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2002 - acc: 0.6096
6000/9534 [=================>............] - ETA: 0s - loss: 1.1969 - acc: 0.6085
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1894 - acc: 0.6117
9534/9534 [==============================] - 1s - loss: 1.1793 - acc: 0.6094 - val_loss: 1.2151 - val_acc: 0.5679
Epoch 10/100
1000/9534 [==>...........................] - ETA: 1s - loss: 1.1436 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1369 - acc: 0.6260
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1366 - acc: 0.6207
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6210
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1276 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.1289 - acc: 0.6217
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1321 - acc: 0.6180
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1352 - acc: 0.6150
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1341 - acc: 0.6141
9534/9534 [==============================] - 0s - loss: 1.1349 - acc: 0.6129 - val_loss: 1.1946 - val_acc: 0.5632
Epoch 11/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1684 - acc: 0.5930
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1338 - acc: 0.6075
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1177 - acc: 0.6140
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6075
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1235 - acc: 0.6154
6000/9534 [=================>............] - ETA: 0s - loss: 1.1188 - acc: 0.6173
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1147 - acc: 0.6179
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1068 - acc: 0.6196
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1090 - acc: 0.6190
9534/9534 [==============================] - 0s - loss: 1.1092 - acc: 0.6177 - val_loss: 1.1788 - val_acc: 0.5689
Epoch 12/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0702 - acc: 0.6280
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0742 - acc: 0.6280
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0821 - acc: 0.6237
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0868 - acc: 0.6233
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0807 - acc: 0.6258
6000/9534 [=================>............] - ETA: 0s - loss: 1.0884 - acc: 0.6208
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0905 - acc: 0.6187
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0895 - acc: 0.6205
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0899 - acc: 0.6200
9534/9534 [==============================] - 1s - loss: 1.0900 - acc: 0.6205 - val_loss: 1.1598 - val_acc: 0.5830
Epoch 13/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0730 - acc: 0.6340
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0649 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0600 - acc: 0.6430
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0718 - acc: 0.6350
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0821 - acc: 0.6280
6000/9534 [=================>............] - ETA: 0s - loss: 1.0779 - acc: 0.6295
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0713 - acc: 0.6316
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0737 - acc: 0.6289
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0767 - acc: 0.6261
9534/9534 [==============================] - 1s - loss: 1.0752 - acc: 0.6259 - val_loss: 1.1589 - val_acc: 0.5642
Epoch 14/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0148 - acc: 0.6520
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0395 - acc: 0.6430
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0503 - acc: 0.6377
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0521 - acc: 0.6382
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0529 - acc: 0.6388
6000/9534 [=================>............] - ETA: 0s - loss: 1.0519 - acc: 0.6392
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0561 - acc: 0.6359
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0547 - acc: 0.6332
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0591 - acc: 0.6313
9534/9534 [==============================] - 0s - loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774
Epoch 15/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0513 - acc: 0.6410
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0635 - acc: 0.6245
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0500 - acc: 0.6280
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0530 - acc: 0.6257
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0585 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.0562 - acc: 0.6233
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0507 - acc: 0.6267
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0540 - acc: 0.6267
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0513 - acc: 0.6286
9534/9534 [==============================] - 0s - loss: 1.0492 - acc: 0.6290 - val_loss: 1.1608 - val_acc: 0.5802
Epoch 16/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0553 - acc: 0.6300
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0582 - acc: 0.6305
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0341 - acc: 0.6407
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0312 - acc: 0.6398
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0454 - acc: 0.6324
6000/9534 [=================>............] - ETA: 0s - loss: 1.0438 - acc: 0.6332
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0445 - acc: 0.6323
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0426 - acc: 0.6331
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0439 - acc: 0.6323
9534/9534 [==============================] - 0s - loss: 1.0427 - acc: 0.6323 - val_loss: 1.1544 - val_acc: 0.5764
Epoch 17/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0633 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0407 - acc: 0.6300
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0417 - acc: 0.6343
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0322 - acc: 0.6402
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0283 - acc: 0.6426
6000/9534 [=================>............] - ETA: 0s - loss: 1.0355 - acc: 0.6400
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0361 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0336 - acc: 0.6392
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0309 - acc: 0.6394
9534/9534 [==============================] - 0s - loss: 1.0342 - acc: 0.6382 - val_loss: 1.1575 - val_acc: 0.5755
Epoch 18/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0289 - acc: 0.6510
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0233 - acc: 0.6505
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0176 - acc: 0.6507
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0194 - acc: 0.6500
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0242 - acc: 0.6442
6000/9534 [=================>............] - ETA: 0s - loss: 1.0239 - acc: 0.6423
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0249 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0264 - acc: 0.6404
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0277 - acc: 0.6406
9534/9534 [==============================] - 0s - loss: 1.0299 - acc: 0.6389 - val_loss: 1.1597 - val_acc: 0.5708
Epoch 19/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0271 - acc: 0.6420
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0114 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0046 - acc: 0.6510
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0137 - acc: 0.6453
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0074 - acc: 0.6492
6000/9534 [=================>............] - ETA: 0s - loss: 1.0112 - acc: 0.6490
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0072 - acc: 0.6504
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0093 - acc: 0.6496
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0137 - acc: 0.6452
9534/9534 [==============================] - 0s - loss: 1.0159 - acc: 0.6451 - val_loss: 1.1603 - val_acc: 0.5651
</code>```

答:
How much accuracy you can achieve with any model obviously very much depends on your dataset and the accuracy of the labeling.

Do a prediction with your trained model and do a confusion matrix. Look at concrete examples of false-positive and false-negative predictions. Are these predictions actually false or does the model predict more accurate than the labels are? This happened to me several times in projects.

I suggest you first try to train your model until it overfits. From what I can see, your model is still learning or is at the verge of overfitting. Add more epochs until the validation loss and/or accuracy gets worse again. Than, for consequent tries, apply regularization if you need to. Start with a dropout of maybe .1 or .2 up to .5 max.

Setup Tensorboard so that you can track the difference between accuracy and validation accuracy.

With so many categorical variables: Have you made sure that you avoided the dummy variable trap? You need to make sure the # of dummy variables is one less than the # of your categories: http://www.algosome.com/articles/dummy-variable-trap-regression.html

Body:
I am training a multi-class neural network by using keras (backend is tensorflow). I will give my settings and some codes at final position.

The description is:
When I do 10 folders cross-validation, the training loss and validation loss goes down at first 10-15 epochs, but can not go further down after 15 epochs and staying on about (loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774).

I have tried several changes for my settings. For example, add hidden layers, add normalization.BatchNormalization(), change optimizer from adam to sgd or rmsprop, change loss function from categorical_crossentropy to others. But no effect.

I would like to discuss what are the probable reasons for this kind of things. I would be very happy if there is a summary document or presentation here.

My data has 10000 rows. And feature has 507 attributes of 0/1. Labels are multi-class with classes num = 7. The balance between classes is almost OK, because I selected the 10000 data from a more large dataset.

My model is as follows:

model = Sequential()
model.add(Dense(500, activation='relu', input_dim=self.feature_dim,
kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(100, activation='relu'))
model.add(Dense(self.label_dim, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

Some logs as follows:

Running Fold 1/10
Train on 9534 samples, validate on 1060 samples
Epoch 1/100
1000/9534 [==>...........................] - ETA: 7s - loss: 6.9644 - acc: 0.1150
2000/9534 [=====>........................] - ETA: 3s - loss: 6.8357 - acc: 0.1715
3000/9534 [========>.....................] - ETA: 2s - loss: 6.7147 - acc: 0.2243
4000/9534 [===========>..................] - ETA: 1s - loss: 6.5922 - acc: 0.2683
5000/9534 [==============>...............] - ETA: 1s - loss: 6.4779 - acc: 0.2908
6000/9534 [=================>............] - ETA: 0s - loss: 6.3618 - acc: 0.3097
7000/9534 [=====================>........] - ETA: 0s - loss: 6.2513 - acc: 0.3244
8000/9534 [========================>.....] - ETA: 0s - loss: 6.1465 - acc: 0.3340
9000/9534 [===========================>..] - ETA: 0s - loss: 6.0439 - acc: 0.3411
9534/9534 [==============================] - 1s - loss: 5.9900 - acc: 0.3442 - val_loss: 4.8716 - val_acc: 0.4377
Epoch 2/100
1000/9534 [==>...........................] - ETA: 0s - loss: 4.8370 - acc: 0.4340
2000/9534 [=====>........................] - ETA: 0s - loss: 4.7593 - acc: 0.4415
3000/9534 [========>.....................] - ETA: 0s - loss: 4.6923 - acc: 0.4423
4000/9534 [===========>..................] - ETA: 0s - loss: 4.6176 - acc: 0.4557
5000/9534 [==============>...............] - ETA: 0s - loss: 4.5517 - acc: 0.4642
6000/9534 [=================>............] - ETA: 0s - loss: 4.4809 - acc: 0.4703
7000/9534 [=====================>........] - ETA: 0s - loss: 4.4036 - acc: 0.4804
8000/9534 [========================>.....] - ETA: 0s - loss: 4.3364 - acc: 0.4821
9000/9534 [===========================>..] - ETA: 0s - loss: 4.2652 - acc: 0.4901
9534/9534 [==============================] - 1s - loss: 4.2316 - acc: 0.4928 - val_loss: 3.5151 - val_acc: 0.5179
Epoch 3/100
1000/9534 [==>...........................] - ETA: 1s - loss: 3.4892 - acc: 0.5370
2000/9534 [=====>........................] - ETA: 1s - loss: 3.4573 - acc: 0.5395
3000/9534 [========>.....................] - ETA: 0s - loss: 3.4006 - acc: 0.5450
4000/9534 [===========>..................] - ETA: 0s - loss: 3.3430 - acc: 0.5435
5000/9534 [==============>...............] - ETA: 0s - loss: 3.2929 - acc: 0.5448
6000/9534 [=================>............] - ETA: 0s - loss: 3.2414 - acc: 0.5448
7000/9534 [=====================>........] - ETA: 0s - loss: 3.1959 - acc: 0.5446
8000/9534 [========================>.....] - ETA: 0s - loss: 3.1489 - acc: 0.5485
9000/9534 [===========================>..] - ETA: 0s - loss: 3.1021 - acc: 0.5501
9534/9534 [==============================] - 1s - loss: 3.0832 - acc: 0.5481 - val_loss: 2.6184 - val_acc: 0.5349
Epoch 4/100
1000/9534 [==>...........................] - ETA: 1s - loss: 2.5950 - acc: 0.5640
2000/9534 [=====>........................] - ETA: 1s - loss: 2.5570 - acc: 0.5705
3000/9534 [========>.....................] - ETA: 0s - loss: 2.5197 - acc: 0.5743
4000/9534 [===========>..................] - ETA: 0s - loss: 2.4929 - acc: 0.5650
5000/9534 [==============>...............] - ETA: 0s - loss: 2.4703 - acc: 0.5646
6000/9534 [=================>............] - ETA: 0s - loss: 2.4388 - acc: 0.5648
7000/9534 [=====================>........] - ETA: 0s - loss: 2.4054 - acc: 0.5680
8000/9534 [========================>.....] - ETA: 0s - loss: 2.3798 - acc: 0.5649
9000/9534 [===========================>..] - ETA: 0s - loss: 2.3522 - acc: 0.5662
9534/9534 [==============================] - 1s - loss: 2.3342 - acc: 0.5685 - val_loss: 2.0442 - val_acc: 0.5491
Epoch 5/100
1000/9534 [==>...........................] - ETA: 0s - loss: 2.0090 - acc: 0.5830
2000/9534 [=====>........................] - ETA: 0s - loss: 1.9990 - acc: 0.5865
3000/9534 [========>.....................] - ETA: 0s - loss: 1.9812 - acc: 0.5833
4000/9534 [===========>..................] - ETA: 0s - loss: 1.9558 - acc: 0.5835
5000/9534 [==============>...............] - ETA: 0s - loss: 1.9377 - acc: 0.5832
6000/9534 [=================>............] - ETA: 0s - loss: 1.9173 - acc: 0.5832
7000/9534 [=====================>........] - ETA: 0s - loss: 1.8968 - acc: 0.5850
8000/9534 [========================>.....] - ETA: 0s - loss: 1.8759 - acc: 0.5851
9000/9534 [===========================>..] - ETA: 0s - loss: 1.8582 - acc: 0.5846
9534/9534 [==============================] - 1s - loss: 1.8501 - acc: 0.5834 - val_loss: 1.6868 - val_acc: 0.5500
Epoch 6/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.6716 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.6387 - acc: 0.5910
3000/9534 [========>.....................] - ETA: 0s - loss: 1.6163 - acc: 0.5910
4000/9534 [===========>..................] - ETA: 0s - loss: 1.6130 - acc: 0.5882
5000/9534 [==============>...............] - ETA: 0s - loss: 1.5982 - acc: 0.5890
6000/9534 [=================>............] - ETA: 0s - loss: 1.5861 - acc: 0.5892
7000/9534 [=====================>........] - ETA: 0s - loss: 1.5724 - acc: 0.5914
8000/9534 [========================>.....] - ETA: 0s - loss: 1.5578 - acc: 0.5922
9000/9534 [===========================>..] - ETA: 0s - loss: 1.5492 - acc: 0.5904
9534/9534 [==============================] - 0s - loss: 1.5468 - acc: 0.5893 - val_loss: 1.4677 - val_acc: 0.5585
Epoch 7/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.4380 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.4332 - acc: 0.5900
3000/9534 [========>.....................] - ETA: 0s - loss: 1.4208 - acc: 0.5957
4000/9534 [===========>..................] - ETA: 0s - loss: 1.4073 - acc: 0.5985
5000/9534 [==============>...............] - ETA: 0s - loss: 1.4027 - acc: 0.5960
6000/9534 [=================>............] - ETA: 0s - loss: 1.3922 - acc: 0.5950
7000/9534 [=====================>........] - ETA: 0s - loss: 1.3842 - acc: 0.5951
8000/9534 [========================>.....] - ETA: 0s - loss: 1.3729 - acc: 0.5988
9000/9534 [===========================>..] - ETA: 0s - loss: 1.3611 - acc: 0.6012
9534/9534 [==============================] - 1s - loss: 1.3588 - acc: 0.6015 - val_loss: 1.3387 - val_acc: 0.5717
Epoch 8/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.3429 - acc: 0.5750
2000/9534 [=====>........................] - ETA: 0s - loss: 1.3071 - acc: 0.5980
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2915 - acc: 0.6007
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2834 - acc: 0.5977
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2791 - acc: 0.6008
6000/9534 [=================>............] - ETA: 0s - loss: 1.2636 - acc: 0.6043
7000/9534 [=====================>........] - ETA: 0s - loss: 1.2521 - acc: 0.6049
8000/9534 [========================>.....] - ETA: 0s - loss: 1.2495 - acc: 0.6041
9000/9534 [===========================>..] - ETA: 0s - loss: 1.2506 - acc: 0.6031
9534/9534 [==============================] - 1s - loss: 1.2491 - acc: 0.6022 - val_loss: 1.2617 - val_acc: 0.5698
Epoch 9/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1627 - acc: 0.6240
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1709 - acc: 0.6235
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2001 - acc: 0.6127
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2000 - acc: 0.6098
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2002 - acc: 0.6096
6000/9534 [=================>............] - ETA: 0s - loss: 1.1969 - acc: 0.6085
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1894 - acc: 0.6117
9534/9534 [==============================] - 1s - loss: 1.1793 - acc: 0.6094 - val_loss: 1.2151 - val_acc: 0.5679
Epoch 10/100
1000/9534 [==>...........................] - ETA: 1s - loss: 1.1436 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1369 - acc: 0.6260
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1366 - acc: 0.6207
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6210
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1276 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.1289 - acc: 0.6217
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1321 - acc: 0.6180
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1352 - acc: 0.6150
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1341 - acc: 0.6141
9534/9534 [==============================] - 0s - loss: 1.1349 - acc: 0.6129 - val_loss: 1.1946 - val_acc: 0.5632
Epoch 11/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1684 - acc: 0.5930
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1338 - acc: 0.6075
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1177 - acc: 0.6140
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6075
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1235 - acc: 0.6154
6000/9534 [=================>............] - ETA: 0s - loss: 1.1188 - acc: 0.6173
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1147 - acc: 0.6179
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1068 - acc: 0.6196
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1090 - acc: 0.6190
9534/9534 [==============================] - 0s - loss: 1.1092 - acc: 0.6177 - val_loss: 1.1788 - val_acc: 0.5689
Epoch 12/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0702 - acc: 0.6280
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0742 - acc: 0.6280
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0821 - acc: 0.6237
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0868 - acc: 0.6233
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0807 - acc: 0.6258
6000/9534 [=================>............] - ETA: 0s - loss: 1.0884 - acc: 0.6208
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0905 - acc: 0.6187
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0895 - acc: 0.6205
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0899 - acc: 0.6200
9534/9534 [==============================] - 1s - loss: 1.0900 - acc: 0.6205 - val_loss: 1.1598 - val_acc: 0.5830
Epoch 13/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0730 - acc: 0.6340
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0649 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0600 - acc: 0.6430
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0718 - acc: 0.6350
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0821 - acc: 0.6280
6000/9534 [=================>............] - ETA: 0s - loss: 1.0779 - acc: 0.6295
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0713 - acc: 0.6316
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0737 - acc: 0.6289
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0767 - acc: 0.6261
9534/9534 [==============================] - 1s - loss: 1.0752 - acc: 0.6259 - val_loss: 1.1589 - val_acc: 0.5642
Epoch 14/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0148 - acc: 0.6520
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0395 - acc: 0.6430
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0503 - acc: 0.6377
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0521 - acc: 0.6382
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0529 - acc: 0.6388
6000/9534 [=================>............] - ETA: 0s - loss: 1.0519 - acc: 0.6392
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0561 - acc: 0.6359
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0547 - acc: 0.6332
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0591 - acc: 0.6313
9534/9534 [==============================] - 0s - loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774
Epoch 15/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0513 - acc: 0.6410
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0635 - acc: 0.6245
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0500 - acc: 0.6280
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0530 - acc: 0.6257
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0585 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.0562 - acc: 0.6233
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0507 - acc: 0.6267
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0540 - acc: 0.6267
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0513 - acc: 0.6286
9534/9534 [==============================] - 0s - loss: 1.0492 - acc: 0.6290 - val_loss: 1.1608 - val_acc: 0.5802
Epoch 16/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0553 - acc: 0.6300
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0582 - acc: 0.6305
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0341 - acc: 0.6407
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0312 - acc: 0.6398
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0454 - acc: 0.6324
6000/9534 [=================>............] - ETA: 0s - loss: 1.0438 - acc: 0.6332
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0445 - acc: 0.6323
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0426 - acc: 0.6331
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0439 - acc: 0.6323
9534/9534 [==============================] - 0s - loss: 1.0427 - acc: 0.6323 - val_loss: 1.1544 - val_acc: 0.5764
Epoch 17/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0633 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0407 - acc: 0.6300
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0417 - acc: 0.6343
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0322 - acc: 0.6402
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0283 - acc: 0.6426
6000/9534 [=================>............] - ETA: 0s - loss: 1.0355 - acc: 0.6400
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0361 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0336 - acc: 0.6392
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0309 - acc: 0.6394
9534/9534 [==============================] - 0s - loss: 1.0342 - acc: 0.6382 - val_loss: 1.1575 - val_acc: 0.5755
Epoch 18/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0289 - acc: 0.6510
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0233 - acc: 0.6505
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0176 - acc: 0.6507
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0194 - acc: 0.6500
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0242 - acc: 0.6442
6000/9534 [=================>............] - ETA: 0s - loss: 1.0239 - acc: 0.6423
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0249 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0264 - acc: 0.6404
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0277 - acc: 0.6406
9534/9534 [==============================] - 0s - loss: 1.0299 - acc: 0.6389 - val_loss: 1.1597 - val_acc: 0.5708
Epoch 19/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0271 - acc: 0.6420
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0114 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0046 - acc: 0.6510
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0137 - acc: 0.6453
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0074 - acc: 0.6492
6000/9534 [=================>............] - ETA: 0s - loss: 1.0112 - acc: 0.6490
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0072 - acc: 0.6504
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0093 - acc: 0.6496
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0137 - acc: 0.6452
9534/9534 [==============================] - 0s - loss: 1.0159 - acc: 0.6451 - val_loss: 1.1603 - val_acc: 0.5651


问:
Showing Hidden Row in Table
I am using some code based on the following JSFiddle. The intention is to show more information when the user clicks the "Show Extra" link.

The problem that I'm having is that when the link is clicked on all but the bottom row of the table the hidden element is shown briefly and then closes.

I am populating my table using template strings in javascript. Here is the code that I use to add rows to the table:

```<code>this.addRecordToTable = function(bet, index, id){
console.log(index);
console.log($.data(bet));
var butId = id.toString();

if (bet.bookies == null){
    bet.bookies = "";
}

if (bet.bet == null){
    bet.bet = "";
}

var newRow = `
<tr>
    <td>${bet.date}</td>
    <td>${bet.bookies}</td>
    <td>${bet.profit}</td>
    <td><button id=${butId}>Delete</button></td>
    <td><a href=\"#\" id=\"show_${index}\">Show Extra</a></td>
</tr>
<tr>
    <td colspan=\"5\">
        <div id=\"extra_${index}\" style=\"display: none;\">
            <br>hidden row
            <br>hidden row
            <br>hidden row
        </div>
    </td>
</tr>
`

console.log(newRow);
console.log("#"+butId);

$(newRow).appendTo($("#betTable"));
$("#"+butId).click(
    function()
    {
        if (window.confirm("Are you sure you want to delete this record?"))
        {
            var rec = new Records();
            rec.removeRecordAt(index);
            $("#betTable tbody").remove();
            var c = new Controller();
            c.init();
        }

    });

$("a[id^=show_]").click(function(event) {
    $("#extra_" + $(this).attr('id').substr(5)).slideToggle("slow");
    event.preventDefault();
});
</code>```

}

EDIT:

I had to change $("a[id^=show_]").click to $("a[id=show_"+index).click..., as the event handler was being added to each element every time I added a new element. Thanks to @freedomn-m.

答:
This code:

```<code>$("a[id^=show_]")
</code>```

adds a new event handler to every existing link as well as the new one as it's not ID/context specific so all the show a's match the selector.

You need to add the context (newRow) or use the existing variable(s) as part of the loop that are already defined, eg:

```<code>$("a[id^=show_]", newRow)
$("a#show_" + index)
</code>```

(or any other variation that works).

An alternative would be to use even delegation for the dynamically added elements, eg:

```<code>$(document).on("click", "a[id^=show_]", function...
</code>```

in which case you'd only need to define/call the event once and it would be fired for new elements (ie put that outside the new row loop).

Title: Showing Hidden Row in Table

Body:
I am using some code based on the following JSFiddle. The intention is to show more information when the user clicks the "Show Extra" link.

The problem that I'm having is that when the link is clicked on all but the bottom row of the table the hidden element is shown briefly and then closes.

I am populating my table using template strings in javascript. Here is the code that I use to add rows to the table:

this.addRecordToTable = function(bet, index, id){
console.log(index);
console.log($.data(bet));
var butId = id.toString();

if (bet.bookies == null){
    bet.bookies = "";
}

if (bet.bet == null){
    bet.bet = "";
}

var newRow = `

    ${bet.date}
    ${bet.bookies}
    ${bet.profit}
    <button id=${butId}>Delete</button>
    Show Extra

hidden row

hidden row

hidden row

`

console.log(newRow);
console.log("#"+butId);

$(newRow).appendTo($("#betTable"));
$("#"+butId).click(
    function()
    {
        if (window.confirm("Are you sure you want to delete this record?"))
        {
            var rec = new Records();
            rec.removeRecordAt(index);
            $("#betTable tbody").remove();
            var c = new Controller();
            c.init();
        }

    });

$("a[id^=show_]").click(function(event) {
    $("#extra_" + $(this).attr('id').substr(5)).slideToggle("slow");
    event.preventDefault();
});

}

EDIT:

I had to change $("a[id^=show_]").click to $("a[id=show_"+index).click..., as the event handler was being added to each element every time I added a new element. Thanks to @freedomn-m.

Body:
This code:

$("a[id^=show_]")

adds a new event handler to every existing link as well as the new one as it's not ID/context specific so all the show a's match the selector.

You need to add the context (newRow) or use the existing variable(s) as part of the loop that are already defined, eg:

$("a[id^=show_]", newRow)
$("a#show_" + index)

(or any other variation that works).

An alternative would be to use even delegation for the dynamically added elements, eg:

$(document).on("click", "a[id^=show_]", function...

in which case you'd only need to define/call the event once and it would be fired for new elements (ie put that outside the new row loop).


问:
java.util.concurrent.ConcurrentHashMap.get() throw StackOverflowError
In my Android app, I use a ConcurrentHashMap. Just a get operation，then stack over flow。

Device model: NX511J
Android OS: 5.1.1
Android SDK: 22

Here is the full stack trace：

```<code>java.lang.StackOverflowError: stack size 1036KB

(13000 same stack trace)

  at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1507)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:754)
    at com.tmall.wireless.minsk.internal.store.impl.ConfigStoreImpl.c(ConfigStoreImpl.java:526)
    at com.tmall.wireless.minsk.internal.store.impl.ConfigStoreImpl.a(ConfigStoreImpl.java:461)
    at mwo.a(MinskImpl.java:265)
    at jfd.a(TMConfigCenterManager.java:186)
    at ogf.c(TMRewriteEngine.java:177)
    at ogf$1.run(TMRewriteEngine.java:141)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)
</code>```

Source code (I think it is not using problem)：

```<code>private final ConcurrentMap<String, Module> immutableLocalCache = new ConcurrentHashMap<>();
    private Module getFromLocal(String moduleName) {
        Module module = immutableLocalCache.get(moduleName);// Stack over flow
        if (null != module) {
            return module;
        }
        //...
        try {
            Module ret = MinskDataConvertUtils.createMinskModule(data);
            immutableLocalCache.put(ret.name, ret);
            return ret;
        } catch (Exception e) {
            LogUtils.exception(e);
            return null;
        }
    }
</code>```

答:
The common cause for a stack overflow is a bad recursive call or condition you've passed in loop. Typically, this is caused when your recursive functions doesn't have the correct termination condition, so it ends up calling itself forever.

May be you're iterating or using recursion for getting operations. If you're using loop check the condition which you've given.
Still the error is persist then post your the code.

Body:
In my Android app, I use a ConcurrentHashMap. Just a get operation，then stack over flow。

Device model: NX511J
Android OS: 5.1.1
Android SDK: 22

Here is the full stack trace：

java.lang.StackOverflowError: stack size 1036KB

(13000 same stack trace)

  at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1507)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap$ForwardingNode.find(ConcurrentHashMap.java:1515)
    at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:754)
    at com.tmall.wireless.minsk.internal.store.impl.ConfigStoreImpl.c(ConfigStoreImpl.java:526)
    at com.tmall.wireless.minsk.internal.store.impl.ConfigStoreImpl.a(ConfigStoreImpl.java:461)
    at mwo.a(MinskImpl.java:265)
    at jfd.a(TMConfigCenterManager.java:186)
    at ogf.c(TMRewriteEngine.java:177)
    at ogf$1.run(TMRewriteEngine.java:141)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)

Source code (I think it is not using problem)：

private final ConcurrentMap<String, Module> immutableLocalCache = new ConcurrentHashMap<>();
    private Module getFromLocal(String moduleName) {
        Module module = immutableLocalCache.get(moduleName);// Stack over flow
        if (null != module) {
            return module;
        }
        //...
        try {
            Module ret = MinskDataConvertUtils.createMinskModule(data);
            immutableLocalCache.put(ret.name, ret);
            return ret;
        } catch (Exception e) {
            LogUtils.exception(e);
            return null;
        }
    }


答:
There are functions for that

https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html

```<code>Insert into table
(fixedval,hour,dayname,weeknumber,daynumber)
(Select 1, hour(inputdate), dayname(inputdate), weekofyear(inputdate), dayofyear(inputdate))
</code>```

Title: Divide timestamp in MySQL

Body:
I have a question regarding time in MySQL.
How do i get a time stamp like this:

2014-12-07 12:54:42.000000

To correctly insert itself in this table:
The timestamp has to divide to,Hour,Dayname,Weeknumber,Daynumber
I need a fixed value of 1 in every layar of the table

+-------------+----------+--------+-----+-----+-----------x
| fixedval    | Hour     | Dayname| Weeknumber| Daynumber |
+-------------+----------+--------+-----------+-----------+
| 1           |          |        |           |           |
| 1           |          |        |           |           |
| 1           |          |        |           |           |
| 1           |          |        |           |           |
| 1           |          |        |           |           |
+-------------+----------+--------+-----------+-----------+

Body:
There are functions for that

https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html

Insert into table
(fixedval,hour,dayname,weeknumber,daynumber)
(Select 1, hour(inputdate), dayname(inputdate), weekofyear(inputdate), dayofyear(inputdate))


问:
run vue with webpack
I'm trying to run vue using webpack but when i run webpack , index.htmlshows a blank page.whats wrong with my code?

index.html

```<code><html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Vue Example</title>
  </head>
  <body>
    <div id="app">{{ message }}</div>
    <script src="dist/build.js"></script>
  </body>
</html>
</code>```

.

```<code>//main.js
import Vue from 'vue'

var a = new Vue({
  el: '#app',
  data: {
    message: "i know you"
  }
})
</code>```

.

```<code>//webpack.config.js
module.exports = {
    // This is the "main" file which should include all other modules
    entry: './src/main.js',
    // Where should the compiled file go?
    output: {
        // To the `dist` folder
        path: './dist',
        // With the filename `build.js` so it's dist/build.js
        filename: 'build.js'
    },
    module: {
        // Special compilation rules

        loaders: [
            {
                // Ask webpack to check: If this file ends with .js, then apply some transforms
                test: /\.js$/,
                // Transform it with babel
                loader: 'babel',
                // don't transform node_modules folder (which don't need to be compiled)
                exclude: /node_modules/

            }
        ]
    }
}
</code>```

答:
When using VUE, the configuration of the WebPack itself is very user-friendly, but for beginners, it is easy to make mistakes. Cause the project to go wrong, just like you do not come out of the page.

In projects that use vue, individuals do not recommend configuring webpack and vue-loader separately. You can directly use vue official scaffolding, vue-cli. Do not have to consider these configurations, automatically configured.

vue-cli

If you just started learning Vue, here's an entry-level demo. Although it is only a small application, but it covers a lot of knowledge points (vue2.0 + vue-cli + vue-router + vuex + axios + mysql + express + pm2 + webpack), including front-end, back-end, database and other sites Some of the necessary elements, for me, learning great significance, would like to encourage each other!

Vue Demo

Title: run vue with webpack

Body:
I'm trying to run vue using webpack but when i run webpack , index.htmlshows a blank page.whats wrong with my code?

index.html

    <meta charset="utf-8">
    <title>Vue Example</title>

{{ message }}

.

//main.js
import Vue from 'vue'

var a = new Vue({
  el: '#app',
  data: {
    message: "i know you"
  }
})

.

//webpack.config.js
module.exports = {
    // This is the "main" file which should include all other modules
    entry: './src/main.js',
    // Where should the compiled file go?
    output: {
        // To the `dist` folder
        path: './dist',
        // With the filename `build.js` so it's dist/build.js
        filename: 'build.js'
    },
    module: {
        // Special compilation rules

        loaders: [
            {
                // Ask webpack to check: If this file ends with .js, then apply some transforms
                test: /\.js$/,
                // Transform it with babel
                loader: 'babel',
                // don't transform node_modules folder (which don't need to be compiled)
                exclude: /node_modules/

            }
        ]
    }
}


问:
PDF generation error with wkhtmltopdf
I'm having a strange issue when trying to copy text from a generated PDF. Following are the steps,

Generate the PDF using wicked_pdf gem

PDF generates correctly

When I do a select all on the PDF, the places it has letters fi, or ffi is not selecting

happens only in the server (linux), works fine
in local (mac)

I'm using

wicked_pdf gem

wkhtmltopdf ver 0.12

Fonts 'Noto Sans SC', 'Noto Sans'

ruby 2.2.3

rails 4.2.5.2

Below is what is happening when I do a select all.

答:
The reason might be due to having text-rendering set to optimizeLegibility in your css file.
Remove this line:

text-rendering: optimizeLegibility;

and you should be gold :)

Reference from Mozilla:

"One very visible effect is optimizeLegibility, which enables ligatures (ff, fi, fl etc.) in text smaller than 20px for some fonts (for example, Microsoft's Calibri, Candara, Constantia and Corbel or the DejaVu font family)."

Note that I had the same problem with the Noto font and optimizeLegibility definitely affects it.

Title: PDF generation error with wkhtmltopdf


问:
SQLite creates double column _id
I'm creating a very simple table inside my android app database. Something weird happened, but I can't find my error.

When I analize the database of my android app, inside my table there are 2 column _id, as you can see in the image

here you can see the class that "handle" the database.

```<code>public class ContactsDAO extends SQLiteOpenHelper {

    public ContactsDAO(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DB_NAME, factory, DB_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        try {
            String createQuery = "CREATE TABLE my_contact(_id integer primary key autoincrement, contact_uri text)";
            sqLiteDatabase.execSQL(createQuery);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1){}

  public void add(MyContact myContact){
        ContentValues contentValues = new ContentValues();
        contentValues.put(contact_uri, "uriiiiiiiii");
        SQLiteDatabase database = this.getWritableDatabase();
        database.insert(my_contact, null, contentValues);
        database.close();
    }
}

Thank in advance.
</code>```

SOLUTION

As the user CL. says, it's an error of the tool. If I check the tables using adb the table is correct, as you can see in this image

答:
It is not possible to have two columns with the same name.

The database is fine. The display in that "Developer Tools" window is wrong.

Title: SQLite creates double column _id

Body:
I'm creating a very simple table inside my android app database. Something weird happened, but I can't find my error.

When I analize the database of my android app, inside my table there are 2 column _id, as you can see in the image

here you can see the class that "handle" the database.

public class ContactsDAO extends SQLiteOpenHelper {

    public ContactsDAO(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DB_NAME, factory, DB_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        try {
            String createQuery = "CREATE TABLE my_contact(_id integer primary key autoincrement, contact_uri text)";
            sqLiteDatabase.execSQL(createQuery);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1){}

  public void add(MyContact myContact){
        ContentValues contentValues = new ContentValues();
        contentValues.put(contact_uri, "uriiiiiiiii");
        SQLiteDatabase database = this.getWritableDatabase();
        database.insert(my_contact, null, contentValues);
        database.close();
    }
}

Thank in advance.

SOLUTION

As the user CL. says, it's an error of the tool. If I check the tables using adb the table is correct, as you can see in this image


问:
iOS 11: How to create folder (directory) in Simulator
From iOS 11, Apple has provided a new feature (application) for File Management (Folder/Directory management option).

I'm trying to create a directory from simulator but all options are de-active in the simulator.

How can I enable them? Does simulator support File Manager?

Here are the steps I followed.

答:
The operations in the Files app seem to be very unstable at the moment. However if you want to add something there, for example you can:

Open the Photos app.

Select a photo.

Press the Open in button.

Select "Markup as PDF".

Done -> "Save File to".

Save there.

And the a file (and maybe a folder) will get created.

Result UI


问:
ansible playbook : changes not getting reflected
I have written ansible-playbook to configure hostname on VyOS server.
Playbook is not giving any errors, But changes are not getting reflected on VyOS

Here is the playbook:

```<code>---
 - hosts : server1
   vars:
    inventory_hostname : vyos_host
   name : setting host name
      vyos_config
        lines
          - set system host-name {{ inventory_hostname }}
</code>```

default host file i am using is :

/etc/ansible/project/hostfile

```<code>[server1]
192.168.1.82

[sever2]
192.168.1.88
</code>```

答:
Your playbook missing tasks block, proper spacing and colons, it should be written like

```<code>---
 - hosts : server1
   vars:
     inventory_hostname : vyos_host
   tasks:
     - name : setting host name
       vyos_config:
         lines:
           - set system host-name {{ inventory_hostname }}
</code>```

Plese check Intro to Playbooks and YAML syntax in official documentation

Body:
I have written ansible-playbook to configure hostname on VyOS server.
Playbook is not giving any errors, But changes are not getting reflected on VyOS

Here is the playbook:

---
 - hosts : server1
   vars:
    inventory_hostname : vyos_host
   name : setting host name
      vyos_config
        lines
          - set system host-name {{ inventory_hostname }}

default host file i am using is :

/etc/ansible/project/hostfile

[server1]
192.168.1.82

[sever2]
192.168.1.88

Body:
Your playbook missing tasks block, proper spacing and colons, it should be written like

---
 - hosts : server1
   vars:
     inventory_hostname : vyos_host
   tasks:
     - name : setting host name
       vyos_config:
         lines:
           - set system host-name {{ inventory_hostname }}

Plese check Intro to Playbooks and YAML syntax in official documentation


问:
Rails Authentication and Authorization without guarantee of browser sessions?
Right now, I am using the RESTful Authentication framework for authorizations with my rails application.  This is all well and good (though from my understanding, a little dated?), but now I need to authenticate a user who might not have an http session (such as from a application (not a browser) that is hitting my rails routes).

Specifically, I now have to support an iPhone application, that hits some of my restful routes to populate itself. However, this app needs to be authenticated, and just passing in a user name and password as parameters doesn't seem very secure. Not only is it not secure, it's not very clean (I would have to change all my calls referencing the current_user (stored in session) to manually setting the current user, as hits to my app without a browser doesn't seem to have session vars (or am I wrong about this?))

Any advice? Can RESTful Authentication do this? Is their an alternative framework (such as Authlogic, or OAuth or whatever) that can help me?

答:
CanCan is pretty much the de facto authorization tool for Rails apps. You shouldn't try to re-invent the wheel in this case.

It plays well with both AuthLogic and RESTful Authentication, I believe. I don't have much experience with the latter.


问:
Android Bitmap to Base64 String
How do I convert a large Bitmap (photo taken with the phone's camera) to a Base64 String?</p>

答:
Try this, first scale your image to required width and height, just pass your original bitmap, required width and required height to the following method and get scaled bitmap in return:

For example: Bitmap scaledBitmap = getScaledBitmap(originalBitmap, 250, 350);

```<code>private Bitmap getScaledBitmap(Bitmap b, int reqWidth, int reqHeight)
{
    int bWidth = b.getWidth();
    int bHeight = b.getHeight();

    int nWidth = bWidth;
    int nHeight = bHeight;

    if(nWidth > reqWidth)
    {
        int ratio = bWidth / reqWidth;
        if(ratio > 0)
        {
            nWidth = reqWidth;
            nHeight = bHeight / ratio;
        }
    }

    if(nHeight > reqHeight)
    {
        int ratio = bHeight / reqHeight;
        if(ratio > 0)
        {
            nHeight = reqHeight;
            nWidth = bWidth / ratio;
        }
    }

    return Bitmap.createScaledBitmap(b, nWidth, nHeight, true);
}
</code>```

Now just pass your scaled bitmap to the following method and get base64 string in return:

For example: String base64String = getBase64String(scaledBitmap);

```<code>private String getBase64String(Bitmap bitmap)
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);

    byte[] imageBytes = baos.toByteArray();

    String base64String = Base64.encodeToString(imageBytes, Base64.NO_WRAP);

    return base64String;
}
</code>```

To decode the base64 string back to bitmap image:

```<code>byte[] decodedByteArray = Base64.decode(base64String, Base64.NO_WRAP);
Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedByteArray, 0, decodedString.length);
</code>```

Title: Android Bitmap to Base64 String

Body:
Try this, first scale your image to required width and height, just pass your original bitmap, required width and required height to the following method and get scaled bitmap in return:

For example: Bitmap scaledBitmap = getScaledBitmap(originalBitmap, 250, 350);

private Bitmap getScaledBitmap(Bitmap b, int reqWidth, int reqHeight)
{
    int bWidth = b.getWidth();
    int bHeight = b.getHeight();

    int nWidth = bWidth;
    int nHeight = bHeight;

    if(nWidth > reqWidth)
    {
        int ratio = bWidth / reqWidth;
        if(ratio > 0)
        {
            nWidth = reqWidth;
            nHeight = bHeight / ratio;
        }
    }

    if(nHeight > reqHeight)
    {
        int ratio = bHeight / reqHeight;
        if(ratio > 0)
        {
            nHeight = reqHeight;
            nWidth = bWidth / ratio;
        }
    }

    return Bitmap.createScaledBitmap(b, nWidth, nHeight, true);
}

Now just pass your scaled bitmap to the following method and get base64 string in return:

For example: String base64String = getBase64String(scaledBitmap);

private String getBase64String(Bitmap bitmap)
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);

    byte[] imageBytes = baos.toByteArray();

    String base64String = Base64.encodeToString(imageBytes, Base64.NO_WRAP);

    return base64String;
}

To decode the base64 string back to bitmap image:

byte[] decodedByteArray = Base64.decode(base64String, Base64.NO_WRAP);
Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedByteArray, 0, decodedString.length);