问:
Java XML library that preserves attribute order
I am writing a Java program that reads an XML file, makes some modifications, and writes back the XML.

Using the standard Java XML DOM API, the order of the attributes is not preserved.

That is, if I have an input file such as:

```<code><person first_name="john" last_name="lederrey"/>
</code>```

I might get an output file as:

```<code><person last_name="lederrey" first_name="john"/>
</code>```

That's correct, because the XML specification says that order attribute is not significant.

However, my program needs to preserve the order of the attributes, so that a person can easily compare the input and output document with a diff tool.

One solution for that is to process the document with SAX (instead of DOM):
Order of XML attributes after DOM processing

However, this does not work for my case,
because the transformation I need to do in one node might depend on a XPath expression on the whole document.

So, the simplest thing would be to have a XML library very similar to the standard Java DOM library, with the exception that it preserves the attribute order.

Is there such a library?

PS: Please, avoid discussing whether I should the preserve attribute order or not. This is a very interesting discussion, but it is not the point of this question.

答:
We had similar requirements per Dave's description. A solution that worked was based on Java reflection.

The idea is to set the propOrder for the attributes at runtime. In our case there's APP_DATA element containing three attributes: app, key, and value. The generated AppData class includes "content" in propOrder and none of the other attributes:

```<code>@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AppData", propOrder = {
    "content"
})
public class AppData {

    @XmlValue
    protected String content;
    @XmlAttribute(name = "Value", required = true)
    protected String value;
    @XmlAttribute(name = "Name", required = true)
    protected String name;
    @XmlAttribute(name = "App", required = true)
    protected String app;
    ...
}
</code>```

So Java reflection was used as follows to set the order at runtime:

```<code>final String[] propOrder = { "app", "name", "value" };
ReflectionUtil.changeAnnotationValue(
        AppData.class.getAnnotation(XmlType.class),
        "propOrder", propOrder);

final JAXBContext jaxbContext = JAXBContext
        .newInstance(ADI.class);
final Marshaller adimarshaller = jaxbContext.createMarshaller();
adimarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
        true);

adimarshaller.marshal(new JAXBElement<ADI>(new QName("ADI"),
                                           ADI.class, adi),
                      new StreamResult(fileOutputStream));
</code>```

The changeAnnotationValue() was borrowed from this post:
Modify a class definition's annotation string parameter at runtime

Here's the method for your convenience (credit goes to @assylias and @Balder):

```<code>/**
 * Changes the annotation value for the given key of the given annotation to newValue and returns
 * the previous value.
 */
@SuppressWarnings("unchecked")
public static Object changeAnnotationValue(Annotation annotation, String key, Object newValue) {
    Object handler = Proxy.getInvocationHandler(annotation);
    Field f;
    try {
        f = handler.getClass().getDeclaredField("memberValues");
    } catch (NoSuchFieldException | SecurityException e) {
        throw new IllegalStateException(e);
    }
    f.setAccessible(true);
    Map<String, Object> memberValues;
    try {
        memberValues = (Map<String, Object>) f.get(handler);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
    Object oldValue = memberValues.get(key);
    if (oldValue == null || oldValue.getClass() != newValue.getClass()) {
        throw new IllegalArgumentException();
    }
    memberValues.put(key, newValue);
    return oldValue;
}
</code>```

Body:
I am writing a Java program that reads an XML file, makes some modifications, and writes back the XML.

Using the standard Java XML DOM API, the order of the attributes is not preserved.

That is, if I have an input file such as:

<person first_name="john" last_name="lederrey"/>

I might get an output file as:

<person last_name="lederrey" first_name="john"/>

That's correct, because the XML specification says that order attribute is not significant.

However, my program needs to preserve the order of the attributes, so that a person can easily compare the input and output document with a diff tool.

One solution for that is to process the document with SAX (instead of DOM):
Order of XML attributes after DOM processing

However, this does not work for my case,
because the transformation I need to do in one node might depend on a XPath expression on the whole document.

So, the simplest thing would be to have a XML library very similar to the standard Java DOM library, with the exception that it preserves the attribute order.

Is there such a library?

PS: Please, avoid discussing whether I should the preserve attribute order or not. This is a very interesting discussion, but it is not the point of this question.

Body:
We had similar requirements per Dave's description. A solution that worked was based on Java reflection.

The idea is to set the propOrder for the attributes at runtime. In our case there's APP_DATA element containing three attributes: app, key, and value. The generated AppData class includes "content" in propOrder and none of the other attributes:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AppData", propOrder = {
    "content"
})
public class AppData {

    @XmlValue
    protected String content;
    @XmlAttribute(name = "Value", required = true)
    protected String value;
    @XmlAttribute(name = "Name", required = true)
    protected String name;
    @XmlAttribute(name = "App", required = true)
    protected String app;
    ...
}

So Java reflection was used as follows to set the order at runtime:

final String[] propOrder = { "app", "name", "value" };
ReflectionUtil.changeAnnotationValue(
        AppData.class.getAnnotation(XmlType.class),
        "propOrder", propOrder);

final JAXBContext jaxbContext = JAXBContext
        .newInstance(ADI.class);
final Marshaller adimarshaller = jaxbContext.createMarshaller();
adimarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
        true);

adimarshaller.marshal(new JAXBElement<ADI>(new QName("ADI"),
                                           ADI.class, adi),
                      new StreamResult(fileOutputStream));

The changeAnnotationValue() was borrowed from this post:
Modify a class definition's annotation string parameter at runtime

Here's the method for your convenience (credit goes to @assylias and @Balder):

/**
 * Changes the annotation value for the given key of the given annotation to newValue and returns
 * the previous value.
 */
@SuppressWarnings("unchecked")
public static Object changeAnnotationValue(Annotation annotation, String key, Object newValue) {
    Object handler = Proxy.getInvocationHandler(annotation);
    Field f;
    try {
        f = handler.getClass().getDeclaredField("memberValues");
    } catch (NoSuchFieldException | SecurityException e) {
        throw new IllegalStateException(e);
    }
    f.setAccessible(true);
    Map<String, Object> memberValues;
    try {
        memberValues = (Map<String, Object>) f.get(handler);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
    Object oldValue = memberValues.get(key);
    if (oldValue == null || oldValue.getClass() != newValue.getClass()) {
        throw new IllegalArgumentException();
    }
    memberValues.put(key, newValue);
    return oldValue;
}


来源: stackexchange

问:
Save Dataframe to csv directly to s3 Python
I have a pandas DataFrame that I want to upload to a new CSV file. The problem is that I don't want to save the file locally before transferring it to s3. Is there any method like to_csv for writing the dataframe to s3 directly? I am using boto3.

Here is what I have so far:

```<code>import boto3
s3 = boto3.client('s3', aws_access_key_id='key', aws_secret_access_key='secret_key')
read_file = s3.get_object(Bucket, Key)
df = pd.read_csv(read_file['Body'])

# Make alterations to DataFrame

# Then export DataFrame to CSV through direct transfer to s3
</code>```

答:
I read a csv with two columns from bucket s3, and the content of the file csv i put in pandas dataframe.

Example:

config.json

```<code>{
  "credential": {
    "access_key":"xxxxxx",
    "secret_key":"xxxxxx"
}
,
"s3":{
       "bucket":"mybucket",
       "key":"csv/user.csv"
   }
}
</code>```

cls_config.json

```<code>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import json

class cls_config(object):

    def __init__(self,filename):

        self.filename = filename

    def getConfig(self):

        fileName = os.path.join(os.path.dirname(__file__), self.filename)
        with open(fileName) as f:
        config = json.load(f)
        return config
</code>```

cls_pandas.py

```<code>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pandas as pd
import io

class cls_pandas(object):

    def __init__(self):
        pass

    def read(self,stream):

        df = pd.read_csv(io.StringIO(stream), sep = ",")
        return df
</code>```

cls_s3.py

```<code>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import boto3
import json

class cls_s3(object):

    def  __init__(self,access_key,secret_key):

        self.s3 = boto3.client('s3', aws_access_key_id=access_key, aws_secret_access_key=secret_key)

    def getObject(self,bucket,key):

        read_file = self.s3.get_object(Bucket=bucket, Key=key)
        body = read_file['Body'].read().decode('utf-8')
        return body
</code>```

test.py

```<code>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from cls_config import *
from cls_s3 import *
from cls_pandas import *

class test(object):

    def __init__(self):
        self.conf = cls_config('config.json')

    def process(self):

        conf = self.conf.getConfig()

        bucket = conf['s3']['bucket']
        key = conf['s3']['key']

        access_key = conf['credential']['access_key']
        secret_key = conf['credential']['secret_key']

        s3 = cls_s3(access_key,secret_key)
        ob = s3.getObject(bucket,key)

        pa = cls_pandas()
        df = pa.read(ob)

        print df

if __name__ == '__main__':
    test = test()
    test.process()
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have a pandas DataFrame that I want to upload to a new CSV file. The problem is that I don't want to save the file locally before transferring it to s3. Is there any method like to_csv for writing the dataframe to s3 directly? I am using boto3.

Here is what I have so far:

import boto3
s3 = boto3.client('s3', aws_access_key_id='key', aws_secret_access_key='secret_key')
read_file = s3.get_object(Bucket, Key)
df = pd.read_csv(read_file['Body'])

# Make alterations to DataFrame

# Then export DataFrame to CSV through direct transfer to s3

Body:
I read a csv with two columns from bucket s3, and the content of the file csv i put in pandas dataframe.

Example:

config.json

{
  "credential": {
    "access_key":"xxxxxx",
    "secret_key":"xxxxxx"
}
,
"s3":{
       "bucket":"mybucket",
       "key":"csv/user.csv"
   }
}

cls_config.json

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import json

class cls_config(object):

    def __init__(self,filename):

        self.filename = filename

    def getConfig(self):

        fileName = os.path.join(os.path.dirname(__file__), self.filename)
        with open(fileName) as f:
        config = json.load(f)
        return config

cls_pandas.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pandas as pd
import io

class cls_pandas(object):

    def __init__(self):
        pass

    def read(self,stream):

        df = pd.read_csv(io.StringIO(stream), sep = ",")
        return df

cls_s3.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import boto3
import json

class cls_s3(object):

    def  __init__(self,access_key,secret_key):

        self.s3 = boto3.client('s3', aws_access_key_id=access_key, aws_secret_access_key=secret_key)

    def getObject(self,bucket,key):

        read_file = self.s3.get_object(Bucket=bucket, Key=key)
        body = read_file['Body'].read().decode('utf-8')
        return body

test.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from cls_config import *
from cls_s3 import *
from cls_pandas import *

class test(object):

    def __init__(self):
        self.conf = cls_config('config.json')

    def process(self):

        conf = self.conf.getConfig()

        bucket = conf['s3']['bucket']
        key = conf['s3']['key']

        access_key = conf['credential']['access_key']
        secret_key = conf['credential']['secret_key']

        s3 = cls_s3(access_key,secret_key)
        ob = s3.getObject(bucket,key)

        pa = cls_pandas()
        df = pa.read(ob)

        print df

if __name__ == '__main__':
    test = test()
    test.process()

ContentLicense: CC BY-SA 3.0


问:
Can't access to Azure Storage folder using Lucene.Net
We decided to implement a search functionality in our API which is developed in ServiceStack, we decided to use Lucene.Net since we heard it was a great indexer to make searches.

We created a worker role whose job is to create the indexes in a Azure Storage folder, we guided ourselves using Leon Cullen's tutorial. We use the AzureDirectory library specified in that post, so we could use the latest Azure SDK.

Then in our API project we added the references for Lucene.Net and AzureDirectory too, our endpoint ended up looking like this:

```<code>    public object Post(SearchIndex request)
    {

        List<Product> products = new List<Product>();

        var pageSize = -1;
        var totalpages = -1;
        int.TryParse(ConfigurationManager.AppSettings["PageSize"], out pageSize);

        if (request.Page.Equals(0))
        {
            request.Page = 1;
        }

        // Get Azure settings
        AzureDirectory azureDirectory ;

        try
        {
            // This is the line where we get the Access denied exception thrown at us
            azureDirectory = new AzureDirectory(Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.AppSettings["ConnectionStringAzureSearch"]), "indexsearch");

            IndexSearcher searcher;
            using (new AutoStopWatch("Creating searcher"))
            {
                searcher = new IndexSearcher(azureDirectory);
            }

            using (new AutoStopWatch(string.Format("Search for {0}", request.SearchString)))
            {
                string[] searchfields = new string[] { "Id", "Name", "Description" };

                var hits = searcher.Search(QueryMaker(request.SearchString, searchfields), request.Page * pageSize);

                int count = hits.ScoreDocs.Count();
                float temp_totalpages = 0;
                temp_totalpages = (float)hits.ScoreDocs.Count() / (float)pageSize;

                if (temp_totalpages > (int)temp_totalpages)
                {
                    totalpages = (int)temp_totalpages + 1;
                }
                else
                {
                    totalpages = (int)temp_totalpages;
                }

                foreach (ScoreDoc match in hits.ScoreDocs)
                {
                    Document doc = searcher.Doc(match.Doc);

                    int producId = int.Parse(doc.Get("Id"));

                    Product product = Db.Select<Product>("Id={0}", producId).FirstOrDefault();

                    products.Add(product);
                }

            }

            return new SearchIndexResult { result = products.Skip((int)((request.Page - 1) * 10)).Take(pageSize).ToList(), PageSize = pageSize, TotalPages = totalpages };
        }
        catch (Exception e)
        {

            return new HttpResult(HttpStatusCode.NoContent, "azureDirectory. Parameter: " + request.SearchString + ". e: " + e.Message);
        }

    }
</code>```

If we run this locally it works as expected, returning us the results we were expecting. But when we published our API to Azure and tried to access to the search endpoint we received an 403 error message with the message 'Access to the path "D:/AzureDirectory" is denied".

We're confused as to why is trying to access to such folder at all, the name of the folder is wrong and I think it's trying to access a local route, we really don't know why does it work fine locally but once it's deployed to Azure it stops working.

The worker role runs without a problems, but it's the API side that cannot access to the folder in Azure Storage. Are we missing some important step in the configuration? The tutorial we followed wasn't very clear for beginners using Lucene.Net or Azure Storage so we fear we might have missed an important step. We've checked our connection strings and everything seems ok though.

答:
In addition to @brykneval answer, I tried his solution but last parameter bool compressBlob = false which he set to true made my local debug fail with 404 exception from AzureDirectory library and when I published to Azure web app, it had exception with message: System.IO.InvalidDataException: Block length does not match with its complement.

I removed last parameter from constructor and everything works like a charm. Hope this helps anyone.

Body:
We decided to implement a search functionality in our API which is developed in ServiceStack, we decided to use Lucene.Net since we heard it was a great indexer to make searches.

We created a worker role whose job is to create the indexes in a Azure Storage folder, we guided ourselves using Leon Cullen's tutorial. We use the AzureDirectory library specified in that post, so we could use the latest Azure SDK.

Then in our API project we added the references for Lucene.Net and AzureDirectory too, our endpoint ended up looking like this:

    public object Post(SearchIndex request)
    {

        List<Product> products = new List<Product>();

        var pageSize = -1;
        var totalpages = -1;
        int.TryParse(ConfigurationManager.AppSettings["PageSize"], out pageSize);

        if (request.Page.Equals(0))
        {
            request.Page = 1;
        }

        // Get Azure settings
        AzureDirectory azureDirectory ;

        try
        {
            // This is the line where we get the Access denied exception thrown at us
            azureDirectory = new AzureDirectory(Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.AppSettings["ConnectionStringAzureSearch"]), "indexsearch");

            IndexSearcher searcher;
            using (new AutoStopWatch("Creating searcher"))
            {
                searcher = new IndexSearcher(azureDirectory);
            }

            using (new AutoStopWatch(string.Format("Search for {0}", request.SearchString)))
            {
                string[] searchfields = new string[] { "Id", "Name", "Description" };

                var hits = searcher.Search(QueryMaker(request.SearchString, searchfields), request.Page * pageSize);

                int count = hits.ScoreDocs.Count();
                float temp_totalpages = 0;
                temp_totalpages = (float)hits.ScoreDocs.Count() / (float)pageSize;

                if (temp_totalpages > (int)temp_totalpages)
                {
                    totalpages = (int)temp_totalpages + 1;
                }
                else
                {
                    totalpages = (int)temp_totalpages;
                }

                foreach (ScoreDoc match in hits.ScoreDocs)
                {
                    Document doc = searcher.Doc(match.Doc);

                    int producId = int.Parse(doc.Get("Id"));

                    Product product = Db.Select<Product>("Id={0}", producId).FirstOrDefault();

                    products.Add(product);
                }

            }

            return new SearchIndexResult { result = products.Skip((int)((request.Page - 1) * 10)).Take(pageSize).ToList(), PageSize = pageSize, TotalPages = totalpages };
        }
        catch (Exception e)
        {

            return new HttpResult(HttpStatusCode.NoContent, "azureDirectory. Parameter: " + request.SearchString + ". e: " + e.Message);
        }

    }

If we run this locally it works as expected, returning us the results we were expecting. But when we published our API to Azure and tried to access to the search endpoint we received an 403 error message with the message 'Access to the path "D:/AzureDirectory" is denied".

We're confused as to why is trying to access to such folder at all, the name of the folder is wrong and I think it's trying to access a local route, we really don't know why does it work fine locally but once it's deployed to Azure it stops working.

The worker role runs without a problems, but it's the API side that cannot access to the folder in Azure Storage. Are we missing some important step in the configuration? The tutorial we followed wasn't very clear for beginners using Lucene.Net or Azure Storage so we fear we might have missed an important step. We've checked our connection strings and everything seems ok though.


问:
How to have a tooltip follow an element on a triggered event?
I have some problems with my code. Basically, I have a red ball and a div box for coordinates.

When I click on a document div.ball goes where I want to, but the box stays at its position. After 2nd click, ball goes where it should and the box moves to the previous position of the ball. The box goes where it should after double click on the same position.

I want the box be like a tooltip, appearing every time next to the ball.

Can you guys help me?

function menuRoll(){
    var hidden_collapse = document.getElementById("hidden_collapse");
    hidden_collapse.classList.toggle("myStyle");
}

function readPosition(ball){
    var rect = ball.getBoundingClientRect();
    var x = Math.round(rect.left) + "px";
    var y = Math.round(rect.top) + "px";
    coordinat.innerHTML = "Coordinates:"+ "
" + x + ", " + y;
    coordinat.style.top = Math.round(rect.top) - 30 + "px";
    coordinat.style.left = Math.round(rect.left) + 37 + "px";
}

window.onload = function(){
    var ball = document.getElementById('foo');
    var ball_space = document.getElementById('ball_space');
    var coordinat = document.getElementById("coordinat");
    document.addEventListener('click', function(e){

        ball.style.background = "#B40520";
        var ball_H = ball.offsetHeight;
        var ball_W = ball.offsetWidth;
        readPosition(ball);
        ball.style.transform = 'translateY('+(e.clientY-(0.5*ball_H))+'px)';
        ball.style.transform += 'translateX('+(e.clientX-(0.5*ball_W))+'px)';

    }, true);

};```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#coordinat {
  transition: all 1s;
  border-radius: 5px;
  position: absolute;
  text-align: center;
  right: 5px;
  top: 5px;
  width: 150px;
  height: 30px;
  padding: 5px 5px;
  background-color: black;
  color: white;
  font-size: 0.8em;
}

#foo{
  margin: 2px;
  border-radius: 50px;
  width: 30px;
  height: 30px;
  /*background: #B40520;*/
  background: white;
  position: absolute;
  top: 0px;
  left: 0px;
  -moz-transition: transform 1s, background 1s;
  -webkit-transition: transform 1s, background 1s;
  -ms-transition: transform 1s, background 1s;
  -o-transition: transform 1s, background 1s;
  transition: transform 1s, background 1s;

}</code>```

Coordinates you will see!

```

答:
You are reading previous position of tooltip, Instead Use ball position for tool-tip position, Have updated in your snippet

function menuRoll(){
      var hidden_collapse = document.getElementById("hidden_collapse");
      hidden_collapse.classList.toggle("myStyle");
      }
//readPosition();

      function readPosition(ball){
        //console.log(ball.clientY,ball.clientX);
        var clientX = parseInt(ball.clientX);
        var clientY = parseInt(ball.clientY);
        if((clientX+150) > window.innerWidth){
          clientX -= 210;
        }
        coordinat.style.top = (clientY-37) + "px";
        coordinat.style.left = (clientX+30) + "px";
        document.getElementById('coordinat').innerHTML = "Coordinates:"+ "
"+ clientX+" X "+clientY;
      }

window.onload = function(){
  var ball = document.getElementById('foo');
  var ball_space = document.getElementById('ball_space');
  var coordinat = document.getElementById("coordinat");
  document.addEventListener('click', function(e){
    ball.style.background = "#B40520";
    var ball_H = ball.offsetHeight;
    var ball_W = ball.offsetWidth;
    ball.style.transform = 'translateY('+(e.clientY-(0.5*ball_H))+'px)';
    ball.style.transform += 'translateX('+(e.clientX-(0.5*ball_W))+'px)';
    readPosition(e);
  }, true);

};```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#coordinat {
  transition:all 1s;
  border-radius: 5px;
  position: absolute;
  text-align: center;
  right: 5px;
  top: 5px;
  width: 150px;
  height: 30px;
  padding: 5px 5px;
  background-color: black;
  color: white;
  font-size: 0.8em;
}

#foo{
margin: 2px;
border-radius:50px;
width:30px;
height:30px;
/*background:#B40520;*/
background: white;
position:absolute;
top:0px;
left:0px;
-moz-transition: transform 1s, background 1s;
-webkit-transition: transform 1s, background 1s;
-ms-transition: transform 1s, background 1s;
-o-transition: transform 1s, background 1s;
transition: transform 1s, background 1s;

}</code>```

Coordinates you will see!

```
</div>
</div>
</p>

<p>Also added code to move tooltip at left if you click at extreme right, tooltip will automatically shift to left </p>

```if((clientX+150) > window.innerWidth){
    clientX -= 210;
}
```

Body:
I have some problems with my code. Basically, I have a red ball and a div box for coordinates.

When I click on a document div.ball goes where I want to, but the box stays at its position. After 2nd click, ball goes where it should and the box moves to the previous position of the ball. The box goes where it should after double click on the same position.

I want the box be like a tooltip, appearing every time next to the ball.

Can you guys help me?

function menuRoll(){
    var hidden_collapse = document.getElementById("hidden_collapse");
    hidden_collapse.classList.toggle("myStyle");
}

function readPosition(ball){
    var rect = ball.getBoundingClientRect();
    var x = Math.round(rect.left) + "px";
    var y = Math.round(rect.top) + "px";
    coordinat.innerHTML = "Coordinates:"+ "
" + x + ", " + y;
    coordinat.style.top = Math.round(rect.top) - 30 + "px";
    coordinat.style.left = Math.round(rect.left) + 37 + "px";
}

window.onload = function(){
    var ball = document.getElementById('foo');
    var ball_space = document.getElementById('ball_space');
    var coordinat = document.getElementById("coordinat");
    document.addEventListener('click', function(e){

        ball.style.background = "#B40520";
        var ball_H = ball.offsetHeight;
        var ball_W = ball.offsetWidth;
        readPosition(ball);
        ball.style.transform = 'translateY('+(e.clientY-(0.5*ball_H))+'px)';
        ball.style.transform += 'translateX('+(e.clientX-(0.5*ball_W))+'px)';

    }, true);

};

#coordinat {
  transition: all 1s;
  border-radius: 5px;
  position: absolute;
  text-align: center;
  right: 5px;
  top: 5px;
  width: 150px;
  height: 30px;
  padding: 5px 5px;
  background-color: black;
  color: white;
  font-size: 0.8em;
}

#foo{
  margin: 2px;
  border-radius: 50px;
  width: 30px;
  height: 30px;
  /*background: #B40520;*/
  background: white;
  position: absolute;
  top: 0px;
  left: 0px;
  -moz-transition: transform 1s, background 1s;
  -webkit-transition: transform 1s, background 1s;
  -ms-transition: transform 1s, background 1s;
  -o-transition: transform 1s, background 1s;
  transition: transform 1s, background 1s;

}

Coordinates you will see!

Body:
You are reading previous position of tooltip, Instead Use ball position for tool-tip position, Have updated in your snippet

function menuRoll(){
      var hidden_collapse = document.getElementById("hidden_collapse");
      hidden_collapse.classList.toggle("myStyle");
      }
//readPosition();

      function readPosition(ball){
        //console.log(ball.clientY,ball.clientX);
        var clientX = parseInt(ball.clientX);
        var clientY = parseInt(ball.clientY);
        if((clientX+150) > window.innerWidth){
          clientX -= 210;
        }
        coordinat.style.top = (clientY-37) + "px";
        coordinat.style.left = (clientX+30) + "px";
        document.getElementById('coordinat').innerHTML = "Coordinates:"+ "<br>"+ clientX+" X "+clientY;
      }

window.onload = function(){
  var ball = document.getElementById('foo');
  var ball_space = document.getElementById('ball_space');
  var coordinat = document.getElementById("coordinat");
  document.addEventListener('click', function(e){
    ball.style.background = "#B40520";
    var ball_H = ball.offsetHeight;
    var ball_W = ball.offsetWidth;
    ball.style.transform = 'translateY('+(e.clientY-(0.5*ball_H))+'px)';
    ball.style.transform += 'translateX('+(e.clientX-(0.5*ball_W))+'px)';
    readPosition(e);
  }, true);

};

#coordinat {
  transition:all 1s;
  border-radius: 5px;
  position: absolute;
  text-align: center;
  right: 5px;
  top: 5px;
  width: 150px;
  height: 30px;
  padding: 5px 5px;
  background-color: black;
  color: white;
  font-size: 0.8em;
}

#foo{
margin: 2px;
border-radius:50px;
width:30px;
height:30px;
/*background:#B40520;*/
background: white;
position:absolute;
top:0px;
left:0px;
-moz-transition: transform 1s, background 1s;
-webkit-transition: transform 1s, background 1s;
-ms-transition: transform 1s, background 1s;
-o-transition: transform 1s, background 1s;
transition: transform 1s, background 1s;

}

<div id="ball_space">
      <div id="coordinat">Coordinates you will see!</div>
     <div id="foo"></div>
    </div>

Also added code to move tooltip at left if you click at extreme right, tooltip will automatically shift to left

if((clientX+150) > window.innerWidth){
    clientX -= 210;
}


问:
In a multithreaded (Java or .Net) program, can I assume that copying a variable is atomic?
I was worrying about race conditions in an application I'm designing, when I was wondering about this question.

Let's say I have a large array or collection of some sort that is managed by one component of my program, let's call that component Monitor. Its job is to regularly check if the collection is "dirty", i. e. has changed recently, and if so, write a snapshot to disk (this is to checkpoint the application in case a crash occurs) and mark it as clean again.

Other components of the same program, running in a different thread, call the Monitor's methods to add data to or modify data in the array/collection. Those methods mark the collection as dirty.

Now, the altering methods run in the other components' threads, right? And if I'm not so lucky, they might be called while the snapshot is written to disk, change data that has already been written, set the dirty flag and the Monitor's thread unsets it just after that, without having saved the changes (it was already past the element when it changed). So I have a dirty collection that's marked as clean.

For a while, I thought that I could maybe solve the problem by making a temporary copy of the collection, mark it clean and then go and serialize the copy. But would the copying be atomic, i. e. can I be sure that the collection will not change while I'm copying it?

Meanwhile, I think I have found better solutions, like

setting a lock flag before beginning the write to disk and make the data altering methods wait until the flag is unset

have the data altering methods write to a "change queue" instead of directly to the collection and have the thread that does the disk writing process that queue

and I think the lock flag might be the best way to go. But I'm still curious: Is copying a variable atomic?

Follow-up: Maybe this should go in a question of its own, but actually it's very much the same. According to the answers below, my "lock flag" approach might also not work, right? Because the data altering method might check the lock flag while it is being set to the "locked" value and decide it's not locked. So I need a special construction like a mutex if I really want to do this right, correct?

Kudos to erickson for his very helpful answer on my follow-up. I really should have made this two questions so I could have accepted two answers. Please, vote him up, too.

答: Take a look at java.util.concurrent.atomic - there may be some good things in there you can use.</p>

OwnerDisplayName: Hanno

ContentLicense: CC BY-SA 2.5

LastEditorDisplayName: Hanno


问:
Best resource for Scraping multiple tables with unchanging URL using python
I want to scrape tables on web pages that have next links, but when you click these next buttons the URL won't change. What are the best/easiest resources to learn scraping with python (BeautifulSoup, Requests) to scrape these kinds of tables?

For example how do I scrape the tables on this page from Boone County Sheriff's Department.

答:
You will need to use Selenium instead of requests. That way you can have the power of interacting with javascript based actions.

Code:

```<code>import re
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chromeOptions = Options()
chromeOptions.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chromeOptions)
wait = WebDriverWait(driver, 30)
driver.get('https://report.boonecountymo.org/mrcjava/servlet/SH01_MP.I00290s')

soup = BeautifulSoup(driver.page_source, 'html.parser')
page_numbers = int(str(soup.find('a', string=re.compile('Page 1 of '), href='#').text).split('Page 1 of ')[1])
print(page_numbers)

tables = []

for page in range(1, page_numbers + 1):
    if page == 1:
        table = soup.find('tbody', id='mrc_main_table')
        #print(table)
        tables.append(table)
    else:
        wait.until(EC.visibility_of_element_located((By.XPATH, '//a[@class="page-button"][@data-pagetype="btn_next"]')))
        driver.find_element_by_xpath('//a[@class="page-button"][@data-pagetype="btn_next"]').click()
        soup = BeautifulSoup(driver.page_source, 'html.parser')
        table = soup.find('tbody', id='mrc_main_table')
        #print(table)
        tables.append(table)

print(tables)
</code>```

Output:

```5
[

AARON
KEVIN
PHILLIP
M
B
23
COLUMBIA
MO

 Details

ADAM
OMER
SIRAJ
M
B
29
COLUMBIA
MO

 Details

AKERS
BRANDEN
MICHAEL
M
W
32
MOKANE
MO

 Details

AKERS
SYDNEY
RAE
F
W
20
COLUMBIA
MO

 Details

ALLEN
WILLIAM
LAMAR
M
B
55
COLUMBIA
MO

 Details

ALVARADO
JACOVO

M
H
34
COLUMBIA
MO

 Details

ANDERSON
RICHARD
KENNETH
M
B
24
COLUMBIA
MO

 Details

AVALOS-AVALOS
JOSE

M
H
19
ST.ANN
MO

 Details

AVILES
LUCIANO
ESPINOZA
M
H
21
COLUMBIA
MO

 Details

BAILEY
JAMES
LEROY
M
W
50
COLUMBIA
MO

 Details

BARNEY
FELSON
DEVONE
M
B
40
COLUMBIA
MO

 Details

BARTON
JAMES
EDWARD
M
W
63
COLUMBIA
MO

 Details

BELL
COLIN
KEITH
M
W
35
HALLSVILLE
MO

 Details

BENEDETTI
FRANK
DOMINICK
M
W
29
COLUMBIA
MO

 Details

BENNETT
ROBERT
DAVID
M
B
39
COLUMBIA
MO

 Details

BERARDI
DEBORAH
EVA
F
W
56
COLUMBIA
MO

 Details

BLAIR
RYAN
WADE
M
W
26
MEXICO
MO

 Details

BOND
SOPHIA
LYNN
F
W
23
COLUMBIA
MO

 Details

BOONE
NIKKI
MARIE
F
W
33
COLUMBIALE
MO

 Details

BOSS
JAFARI
RASHIDI
M
B
34
COLUMBIA
MO

 Details

BOYDSTON
LAVERNE
KEHAULANI
F
A
59
MOBERLY
MO

 Details

BRILL
BRANDON
NICHOLAS
M
W
26
CLARK
MO

 Details

BROWN
THYRUS
MONTEZ
M
B
48
COLUMBIA
MO

 Details

BRYANT
CHESTER
LEROY
M
B
53
COLUMBIA
MO

 Details

................
ETC...
................

WILLIAMS
SYLVESTER
EARL
M
B
50
COLUMBIA
MO

 Details

WINTER
PAIGE
LYNN
F
W
20
COLUMBIA
MO

 Details

WISLEY
JORDAN
MONTEZ
M
B
27
COLUMBIA
MO

 Details

WOODS
DANIEL
SCOTT
M
W
33
COLUMBIA
MO

 Details

WOODWARD
ELAINIA
MARGURITE
F
B
19
TOPEKA
KS

 Details

WYATT
CHASE
ROY
M
W
31
CENTRALIA
MO

 Details

YEARWOOD
JAMES
CHRISTIAN
M
B
19
COLUMBIA
MO

 Details

ZARHOUNI
DRISS
BURCH
M
H
53
COLUMBIA
MO

 Details

ZWICKY
CARRIE
ANN
F
W
45
GALESBURG
IL

 Details

  Detainee Count: 235

Page 5 of 5

]
```

Body:
You will need to use Selenium instead of requests. That way you can have the power of interacting with javascript based actions.

Code:

import re
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chromeOptions = Options()
chromeOptions.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chromeOptions)
wait = WebDriverWait(driver, 30)
driver.get('https://report.boonecountymo.org/mrcjava/servlet/SH01_MP.I00290s')

soup = BeautifulSoup(driver.page_source, 'html.parser')
page_numbers = int(str(soup.find('a', string=re.compile('Page 1 of '), href='#').text).split('Page 1 of ')[1])
print(page_numbers)

tables = []

for page in range(1, page_numbers + 1):
    if page == 1:
        table = soup.find('tbody', id='mrc_main_table')
        #print(table)
        tables.append(table)
    else:
        wait.until(EC.visibility_of_element_located((By.XPATH, '//a[@class="page-button"][@data-pagetype="btn_next"]')))
        driver.find_element_by_xpath('//a[@class="page-button"][@data-pagetype="btn_next"]').click()
        soup = BeautifulSoup(driver.page_source, 'html.parser')
        table = soup.find('tbody', id='mrc_main_table')
        #print(table)
        tables.append(table)

print(tables)

Output:

5
[<tbody class="stripe" id="mrc_main_table">
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">AARON</td>
<td class="one td_left" data-th="First Name">KEVIN</td>
<td class="one td_left" data-th="Middle Name">PHILLIP</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">23</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=66343&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">ADAM</td>
<td class="two td_left" data-th="First Name">OMER</td>
<td class="two td_left" data-th="Middle Name">SIRAJ</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">B</td>
<td class="two td_right" data-th="Age">29</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=77695&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">AKERS</td>
<td class="one td_left" data-th="First Name">BRANDEN</td>
<td class="one td_left" data-th="Middle Name">MICHAEL</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">W</td>
<td class="one td_right" data-th="Age">32</td>
<td class="one td_left" data-th="City">MOKANE</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=51443&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">AKERS</td>
<td class="two td_left" data-th="First Name">SYDNEY</td>
<td class="two td_left" data-th="Middle Name">RAE</td>
<td class="two td_left" data-th="Sex">F</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">20</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=76028&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">ALLEN</td>
<td class="one td_left" data-th="First Name">WILLIAM</td>
<td class="one td_left" data-th="Middle Name">LAMAR</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">55</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=19022&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">ALVARADO</td>
<td class="two td_left" data-th="First Name">JACOVO</td>
<td class="two td_left" data-th="Middle Name"> </td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">H</td>
<td class="two td_right" data-th="Age">34</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=79782&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">ANDERSON</td>
<td class="one td_left" data-th="First Name">RICHARD</td>
<td class="one td_left" data-th="Middle Name">KENNETH</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">24</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=66544&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">AVALOS-AVALOS</td>
<td class="two td_left" data-th="First Name">JOSE</td>
<td class="two td_left" data-th="Middle Name"> </td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">H</td>
<td class="two td_right" data-th="Age">19</td>
<td class="two td_left" data-th="City">ST.ANN</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=78424&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">AVILES</td>
<td class="one td_left" data-th="First Name">LUCIANO</td>
<td class="one td_left" data-th="Middle Name">ESPINOZA</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">H</td>
<td class="one td_right" data-th="Age">21</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=79931&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BAILEY</td>
<td class="two td_left" data-th="First Name">JAMES</td>
<td class="two td_left" data-th="Middle Name">LEROY</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">50</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=18934&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">BARNEY</td>
<td class="one td_left" data-th="First Name">FELSON</td>
<td class="one td_left" data-th="Middle Name">DEVONE</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">40</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=4285&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BARTON</td>
<td class="two td_left" data-th="First Name">JAMES</td>
<td class="two td_left" data-th="Middle Name">EDWARD</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">63</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=76341&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">BELL</td>
<td class="one td_left" data-th="First Name">COLIN</td>
<td class="one td_left" data-th="Middle Name">KEITH</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">W</td>
<td class="one td_right" data-th="Age">35</td>
<td class="one td_left" data-th="City">HALLSVILLE</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=33000&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BENEDETTI</td>
<td class="two td_left" data-th="First Name">FRANK</td>
<td class="two td_left" data-th="Middle Name">DOMINICK</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">29</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=79913&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">BENNETT</td>
<td class="one td_left" data-th="First Name">ROBERT</td>
<td class="one td_left" data-th="Middle Name">DAVID</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">39</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=33666&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BERARDI</td>
<td class="two td_left" data-th="First Name">DEBORAH</td>
<td class="two td_left" data-th="Middle Name">EVA</td>
<td class="two td_left" data-th="Sex">F</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">56</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=78005&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">BLAIR</td>
<td class="one td_left" data-th="First Name">RYAN</td>
<td class="one td_left" data-th="Middle Name">WADE</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">W</td>
<td class="one td_right" data-th="Age">26</td>
<td class="one td_left" data-th="City">MEXICO</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=73590&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BOND</td>
<td class="two td_left" data-th="First Name">SOPHIA</td>
<td class="two td_left" data-th="Middle Name">LYNN</td>
<td class="two td_left" data-th="Sex">F</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">23</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=67252&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">BOONE</td>
<td class="one td_left" data-th="First Name">NIKKI</td>
<td class="one td_left" data-th="Middle Name">MARIE</td>
<td class="one td_left" data-th="Sex">F</td>
<td class="one td_left" data-th="Race">W</td>
<td class="one td_right" data-th="Age">33</td>
<td class="one td_left" data-th="City">COLUMBIALE</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=39306&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BOSS</td>
<td class="two td_left" data-th="First Name">JAFARI</td>
<td class="two td_left" data-th="Middle Name">RASHIDI</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">B</td>
<td class="two td_right" data-th="Age">34</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=60725&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">BOYDSTON</td>
<td class="one td_left" data-th="First Name">LAVERNE</td>
<td class="one td_left" data-th="Middle Name">KEHAULANI</td>
<td class="one td_left" data-th="Sex">F</td>
<td class="one td_left" data-th="Race">A</td>
<td class="one td_right" data-th="Age">59</td>
<td class="one td_left" data-th="City">MOBERLY</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=79939&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BRILL</td>
<td class="two td_left" data-th="First Name">BRANDON</td>
<td class="two td_left" data-th="Middle Name">NICHOLAS</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">26</td>
<td class="two td_left" data-th="City">CLARK</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=60089&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">BROWN</td>
<td class="one td_left" data-th="First Name">THYRUS</td>
<td class="one td_left" data-th="Middle Name">MONTEZ</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">48</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=45497&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">BRYANT</td>
<td class="two td_left" data-th="First Name">CHESTER</td>
<td class="two td_left" data-th="Middle Name">LEROY</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">B</td>
<td class="two td_right" data-th="Age">53</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=10513&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
................
ETC...
................

<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">WILLIAMS</td>
<td class="one td_left" data-th="First Name">SYLVESTER</td>
<td class="one td_left" data-th="Middle Name">EARL</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">50</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=8656&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">WINTER</td>
<td class="two td_left" data-th="First Name">PAIGE</td>
<td class="two td_left" data-th="Middle Name">LYNN</td>
<td class="two td_left" data-th="Sex">F</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">20</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=75775&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">WISLEY</td>
<td class="one td_left" data-th="First Name">JORDAN</td>
<td class="one td_left" data-th="Middle Name">MONTEZ</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">27</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=58487&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">WOODS</td>
<td class="two td_left" data-th="First Name">DANIEL</td>
<td class="two td_left" data-th="Middle Name">SCOTT</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">33</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=39227&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">WOODWARD</td>
<td class="one td_left" data-th="First Name">ELAINIA</td>
<td class="one td_left" data-th="Middle Name">MARGURITE</td>
<td class="one td_left" data-th="Sex">F</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">19</td>
<td class="one td_left" data-th="City">TOPEKA</td>
<td class="one td_left" data-th="State">KS</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=79008&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">WYATT</td>
<td class="two td_left" data-th="First Name">CHASE</td>
<td class="two td_left" data-th="Middle Name">ROY</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">W</td>
<td class="two td_right" data-th="Age">31</td>
<td class="two td_left" data-th="City">CENTRALIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=59360&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">YEARWOOD</td>
<td class="one td_left" data-th="First Name">JAMES</td>
<td class="one td_left" data-th="Middle Name">CHRISTIAN</td>
<td class="one td_left" data-th="Sex">M</td>
<td class="one td_left" data-th="Race">B</td>
<td class="one td_right" data-th="Age">19</td>
<td class="one td_left" data-th="City">COLUMBIA</td>
<td class="one td_left" data-th="State">MO</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=77805&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="even">
<td class="two td_left" data-th="Last Name">ZARHOUNI</td>
<td class="two td_left" data-th="First Name">DRISS</td>
<td class="two td_left" data-th="Middle Name">BURCH</td>
<td class="two td_left" data-th="Sex">M</td>
<td class="two td_left" data-th="Race">H</td>
<td class="two td_right" data-th="Age">53</td>
<td class="two td_left" data-th="City">COLUMBIA</td>
<td class="two td_left" data-th="State">MO</td>
<td class="two td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=33263&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="odd">
<td class="one td_left" data-th="Last Name">ZWICKY</td>
<td class="one td_left" data-th="First Name">CARRIE</td>
<td class="one td_left" data-th="Middle Name">ANN</td>
<td class="one td_left" data-th="Sex">F</td>
<td class="one td_left" data-th="Race">W</td>
<td class="one td_right" data-th="Age">45</td>
<td class="one td_left" data-th="City">GALESBURG</td>
<td class="one td_left" data-th="State">IL</td>
<td class="one td_left" data-th="">
<a class="_lookup btn btn-primary" height="600" href="SH01_MP.I00500s?PERKEP=79930&amp;hover_redir=&amp;height=600&amp;width=950" linkedtype="I" mrc="returndata" target="_lookup" width="860"><i class="fa fa-large fa-fw fa-list-alt"> </i>Details</a>
</td>
</tr>
<!-- -->
<tr class="tr-paging">
<th class="th_left paging_row bottomPaging" colspan="93">  Detainee Count: 235
                            <div class="pagination pagination-right fixed-pagination" style="margin-left: 2em;">
<ul>
<li>
<a class="page-button" data-pagetype="btn_top" href="javascript:void(0)"><i class="fa fa-angle-double-left fa-large"> </i></a>
</li>
<li>
<a class="page-button" data-pagetype="btn_prev" href="javascript:void(0)"><i class="fa fa-angle-left fa-large"> </i></a>
</li>
<li class="disabled">
<a href="#">Page 5 of 5</a>
</li>
<li>
<a class="" data-pagetype="btn_next" href="javascript:void(0)"><i class="fa fa-angle-right fa-large"> </i></a>
</li>
<li>
<a class="" data-pagetype="btn_btmm" href="javascript:void(0)"><i class="fa fa-angle-double-right fa-large"> </i></a>
</li>
</ul>
</div>
</th>
</tr>
</tbody>]


问:
Find largest sum of 3 numbers which is also divisable by 3
How to find largest sum of 3 numbers which is also divisable by 3?

Examples:

Input: [1, 15, 4, 7, 2]

Output: [15, 7, 2] (In that order)

Input: [1, 2, 4, 7]

Output: [1, 4, 7] (In that order)

I came up only with this:

```<code>function largestSum(arr) {
    let max = -1;
    let nums;

    for (let i = 0; i < arr.length; i++)
        for (let j = i + 1; j < arr.length; j++)
            for (let k = j + 1; k < arr.length; k++)
                if ((arr[i] + arr[j] + arr[k]) % 3 === 0 && arr[i] + arr[j] + arr[k] > max)
                    nums = [arr[i], arr[j], arr[k]], max = arr[i] + arr[j] + arr[k];

    return nums;
}
</code>```

But, isn't it better option here (with better efficiency)?

答: can't believe there is a way to do it without trying all the combinations of the array [what you've already done]</p>

Body:
How to find largest sum of 3 numbers which is also divisable by 3?

Examples:

Input: [1, 15, 4, 7, 2]

Output: [15, 7, 2] (In that order)

Input: [1, 2, 4, 7]

Output: [1, 4, 7] (In that order)

I came up only with this:

function largestSum(arr) {
    let max = -1;
    let nums;

    for (let i = 0; i < arr.length; i++)
        for (let j = i + 1; j < arr.length; j++)
            for (let k = j + 1; k < arr.length; k++)
                if ((arr[i] + arr[j] + arr[k]) % 3 === 0 && arr[i] + arr[j] + arr[k] > max)
                    nums = [arr[i], arr[j], arr[k]], max = arr[i] + arr[j] + arr[k];

    return nums;
}

But, isn't it better option here (with better efficiency)?


问:
creat a newtable with T-SQL using a concated name
I am trying to work out a script that will select into a new table from an existing table.   The catch is the table name needs to be a combination of the original table name and a string value representing the datetime.  This is what I have been trying and different variants.  However what I end up with is always a table named newtableName.  Or an error depending on whether I use SELECT * INTO dbo.@newtableName FROM dbo.ClientAppSetting or SELECT * INTO dbo.newtableName FROM dbo.ClientAppSetting.

any help or guidance would be greatly appreciated.

```<code>DECLARE @extension varchar(25)
DECLARE @tableName varchar(100)
DECLARE @newtableName varchar(100)
SET @tableName = 'ClientAppSetting'
SELECT convert(varchar(25), getdate(), 120) AS extension
SELECT CONCAT (@tableName,  @extension )AS newtableName

SELECT * INTO dbo.newtableName FROM dbo.ClientAppSetting
</code>```

答:
You need to use Dynamic SQL to achieve this. You can do something like this:</p>

```<code>DECLARE @extension varchar(25)
DECLARE @tableName varchar(100)
DECLARE @newtableName varchar(100)
DECLARE @sql varchar(1000)

SET @tableName = 'ClientAppSetting'

SELECT @extension = replace(replace(replace(replace(convert(varchar(25), getdate(), 120),'-',''),' ',''),':',''),'.','')

SELECT @newtableName = @tableName +'_' + @extension

set @sql = 'select * into ' + @newtableName +  ' from ' + @tableName

exec(@sql)
</code>```

Body:
I am trying to work out a script that will select into a new table from an existing table.   The catch is the table name needs to be a combination of the original table name and a string value representing the datetime.  This is what I have been trying and different variants.  However what I end up with is always a table named newtableName.  Or an error depending on whether I use SELECT * INTO dbo.@newtableName FROM dbo.ClientAppSetting or SELECT * INTO dbo.newtableName FROM dbo.ClientAppSetting.

any help or guidance would be greatly appreciated.

DECLARE @extension varchar(25)
DECLARE @tableName varchar(100)
DECLARE @newtableName varchar(100)
SET @tableName = 'ClientAppSetting'
SELECT convert(varchar(25), getdate(), 120) AS extension
SELECT CONCAT (@tableName,  @extension )AS newtableName

SELECT * INTO dbo.newtableName FROM dbo.ClientAppSetting

Body:
You need to use Dynamic SQL to achieve this. You can do something like this:

DECLARE @extension varchar(25)
DECLARE @tableName varchar(100)
DECLARE @newtableName varchar(100)
DECLARE @sql varchar(1000)

SET @tableName = 'ClientAppSetting'

SELECT @extension = replace(replace(replace(replace(convert(varchar(25), getdate(), 120),'-',''),' ',''),':',''),'.','')

SELECT @newtableName = @tableName +'_' + @extension

set @sql = 'select * into ' + @newtableName +  ' from ' + @tableName

exec(@sql)


问:
Move Solr data from v4 to v7
I have a solr cluster running solr v4.3 I want to export all the data and import it into a new solr v7.1 cluster.

What options do I have to export/import the data?

答:
options are:

if you have ALL your fields stored, you can try several things:

use DIH in Solr7 to index all data from a SolrEntityProcessor

write some scripts/code to export all data (in batches, using cursorMark if available in 4.3 or doing the cursor yourself with a fq on some field) in csv, and index it into Solr7

similarly, write some java/Solrj code that does the same thing

if you don't have all fields stored, then the only way is upgrading to Solr 6 first, then to 7 (by going through the upgrade process, but this does not reindex the data, which is highly recommended)

All this, assuming you don't have the original data to reindex, if you have it, it is a no brainer: reindex off it.

Title: Move Solr data from v4 to v7


问:
Python copy and concatenate linked lists, preserve order
I have a basic linked-list implementation in python. Each Cell has some data associated with it and a next object, used to include the rest of the linked list (and null if only the first param of data is given in the constructor).

I want to copy and concatenate two lists together, so that the final product preserves the order and is independent of the two original lists.

Here is what I have:
```<code>def list_concat_copy(A, B):
        C = Cell(A)
        while A.next != None:
                A = A.next
                C = Cell(A,C)
        C = Cell(B,C)
        while B.next != None:
                B = B.next
                C = Cell(B,C)
        return C```

The issue that I am having is that this reverses the order:
```<code>A = Cell(8,Cell(9,Cell(10)))
B = Cell(11,Cell(12,Cell(13)))
C = list_concat_copy(A,B)```

Now if I walk_and_print(C) I get 13 12 11 10 9 8

Any thoughts?

答:
The lists print out backwards because as you are packing the OUTER elements into the new list FIRST.  As you continue to unwrap A, you add a wrapping to C.

The cleanest way to duplicate these lists might be to do a deepcopy of A and B (we'll call them C and D), and then set the deepest element in C (found by traversing until C.next==None) to reference D.

Body:
I have a basic linked-list implementation in python. Each Cell has some data associated with it and a next object, used to include the rest of the linked list (and null if only the first param of data is given in the constructor).

I want to copy and concatenate two lists together, so that the final product preserves the order and is independent of the two original lists.

Here is what I have:

def list_concat_copy(A, B):
        C = Cell(A)
        while A.next != None:
                A = A.next
                C = Cell(A,C)
        C = Cell(B,C)
        while B.next != None:
                B = B.next
                C = Cell(B,C)
        return C

The issue that I am having is that this reverses the order:

A = Cell(8,Cell(9,Cell(10)))
B = Cell(11,Cell(12,Cell(13)))
C = list_concat_copy(A,B)

Now if I walk_and_print(C) I get 13 12 11 10 9 8

Any thoughts?


问:
Laravel Relationship not working on server
My project is working fine on local host, but on the server, getting error only on lesson page.

Subject Model is

```<code>    class Subjects extends Model
  {
    public function category()
    {
        return $this->belongsTo('Lea\Category');
    }
    public function lesson()
    {
        return $this->hasMany('Lea\Lessons');
    }
    public function chapter()
    {
        return $this->hasMany('Lea\Chapters');
    }
    public function users()
    {
        return $this->belongsToMany('Lea\User', 'subject_user', 'subject_id', 'user_id');
    }
  }
</code>```

And Lesson Model is

```<code>    class Lessons extends Model
{
    public function chapter()
    {
        return $this->belongsTo('Lea\Chapters');
    }
    public function subject()
    {
        return $this->belongsTo('Lea\Subjects', 'subject_id');
    }
    public function category()
    {
        return $this->belongsTo('Lea\Category');
    }

}
</code>```

My controller lessons has method index like below.

```<code>public function index()
    {

        $lessons = lessons::orderBy('id', 'asc')->paginate(5);
        return view('admin.lessons.index')->withLessons($lessons);
    }
</code>```

The way i am calling subject name is show below. first subject is relationship subject and 2nd subject is the field name where subject name saved in db. using foreach to get data like:

```<code>@foreach ($lessons as $lesson)
{{$lesson->subject->subject}}
@endforeach
</code>```

subjects table schema is

```<code>id
subject
admin_id
users_id
category_id
created_at
updated_at
</code>```

lessons table schema is

```<code>id
title
slug
category_id
subject_id
chapter_id
users_id
content
image
</code>```

答:
The reason you're getting the error in your server but not your local machine is that your server database is empty (or at least has fewer records).

{{$lesson->subject->subject}}

The lesson has no subject, so it's null. And your tryting to get a proprty subject of a null.

If you're using Laravel 5.5, you can wrap the subject in optional() method.

{{optional($lesson->subject)->subject}}

< Laravel 5.5
{{$lesson->subject ? $lesson->subject->subject : ''}}

Body:
My project is working fine on local host, but on the server, getting error only on lesson page.

Subject Model is

    class Subjects extends Model
  {
    public function category()
    {
        return $this->belongsTo('Lea\Category');
    }
    public function lesson()
    {
        return $this->hasMany('Lea\Lessons');
    }
    public function chapter()
    {
        return $this->hasMany('Lea\Chapters');
    }
    public function users()
    {
        return $this->belongsToMany('Lea\User', 'subject_user', 'subject_id', 'user_id');
    }
  }

And Lesson Model is

    class Lessons extends Model
{
    public function chapter()
    {
        return $this->belongsTo('Lea\Chapters');
    }
    public function subject()
    {
        return $this->belongsTo('Lea\Subjects', 'subject_id');
    }
    public function category()
    {
        return $this->belongsTo('Lea\Category');
    }

}

My controller lessons has method index like below.

public function index()
    {

        $lessons = lessons::orderBy('id', 'asc')->paginate(5);
        return view('admin.lessons.index')->withLessons($lessons);
    }

The way i am calling subject name is show below. first subject is relationship subject and 2nd subject is the field name where subject name saved in db. using foreach to get data like:

@foreach ($lessons as $lesson)
{{$lesson->subject->subject}}
@endforeach

subjects table schema is

id
subject
admin_id
users_id
category_id
created_at
updated_at

lessons table schema is

id
title
slug
category_id
subject_id
chapter_id
users_id
content
image


问:
Using sed to replace character
I am leaning how to use awk and sed this week. I know this question might have been asked before but I am not sure what is wrong with my script. I have three files and I am using grep to search for the pattern gge0001x gge0001y gge0001z. x is in file1, y is in file 2, and z is in file3.   If anyone wants to see L2E[1-3].iva they are here: https://gist.github.com/anonymous/1112988408874c730cd4f3d313226ba4

```<code>#!/bin/bash
echo "Performance Data"
sed -n '1,19p' L2E1.iva|cat > file1 #take lines 1-19 in L2E1 and take the
# output into file1. The next two commands do the same thing
sed -n '1,19p' L2E2.iva|cat > file2
sed -n '1,19p' L2E3.iva|cat > file3
curveName=`grep "F" file1|sed "s/F/ /"`
# This will search for F in file 1, and then substitute F with a space
curveName2=`grep "F" file2|sed "s/F/ /"`
curveName3=`grep "F" file3|sed "s/F/ /"`
echo "Curve Name" "$curveName $curveName2 $curveName3"
</code>```

I want my output to be Curve Name gge0001x gge0001y gge0001z. But the output is this instead:
Performance Data gge0006ze gge0006x

If I echo them out by themselves then it is fine, but once I echo all three on the same line the output gets skewed. Why does x show up last when it is first when I echo it and where did my y go to?

答:
A few tips at first:

```<code>sed -n '1,19p' L2E1.iva|cat > file1
</code>```

You can omit the cat an redirect the output of sed directly to the file:

```<code>sed -n '1,19p' L2E1.iva > file1
</code>```

```<code>curveName=`grep "F" file1|sed "s/F/ /"`
</code>```

Use $() instead of backticks for process substitution:

```<code>curveName=$(grep "F" file1 | sed "s/F/ /")
</code>```

But the output is this instead: Performance Data gge0006ze gge0006x

The reason for Performance Data in your output is, that you echo it at the beginning of your script.

Moreover you've got a typo in the last echo: $curvename2 -> $curveName2, this is why your y is missing.

Did you double check your files for the right contents? That's the only reason i can imagine, why your x comes last and the z first.

Title: Using sed to replace character

Body:
I am leaning how to use awk and sed this week. I know this question might have been asked before but I am not sure what is wrong with my script. I have three files and I am using grep to search for the pattern gge0001x gge0001y gge0001z. x is in file1, y is in file 2, and z is in file3.   If anyone wants to see L2E[1-3].iva they are here: https://gist.github.com/anonymous/1112988408874c730cd4f3d313226ba4

#!/bin/bash
echo "Performance Data"
sed -n '1,19p' L2E1.iva|cat > file1 #take lines 1-19 in L2E1 and take the
# output into file1. The next two commands do the same thing
sed -n '1,19p' L2E2.iva|cat > file2
sed -n '1,19p' L2E3.iva|cat > file3
curveName=`grep "F" file1|sed "s/F/ /"`
# This will search for F in file 1, and then substitute F with a space
curveName2=`grep "F" file2|sed "s/F/ /"`
curveName3=`grep "F" file3|sed "s/F/ /"`
echo "Curve Name" "$curveName $curveName2 $curveName3"

I want my output to be Curve Name gge0001x gge0001y gge0001z. But the output is this instead:
Performance Data gge0006ze gge0006x

If I echo them out by themselves then it is fine, but once I echo all three on the same line the output gets skewed. Why does x show up last when it is first when I echo it and where did my y go to?

Body:
A few tips at first:

sed -n '1,19p' L2E1.iva|cat > file1

You can omit the cat an redirect the output of sed directly to the file:

sed -n '1,19p' L2E1.iva > file1

curveName=`grep "F" file1|sed "s/F/ /"`

Use $() instead of backticks for process substitution:

curveName=$(grep "F" file1 | sed "s/F/ /")

But the output is this instead: Performance Data gge0006ze gge0006x

The reason for Performance Data in your output is, that you echo it at the beginning of your script.

Moreover you've got a typo in the last echo: $curvename2 -> $curveName2, this is why your y is missing.

Did you double check your files for the right contents? That's the only reason i can imagine, why your x comes last and the z first.


问:
AngularJS - how to get all elements by querySelector and disable links
I'm trying to make a simple step-by-step wizard.

HTML code for that (in index.html) looks like

```<code><div class="stepwizard col-md-offset-3">
    <div class="stepwizard-row setup-panel">
      <div class="stepwizard-step">
        <a href="/" type="button" class="btn btn-default btn-circle" id="step-1">1</a>
        <p>Start</p>
      </div>
      <div class="stepwizard-step">
        <a href="/registration" type="button" class="btn btn-default btn-circle" disabled="disabled" id="step-2">2</a>
        <p>Registration</p>
      </div>
      <div class="stepwizard-step">
        <a href="/tutorial" type="button" class="btn btn-default btn-circle" disabled="disabled" id="step-3">3</a>
        <p>Tutorial</p>
      </div>
      <div class="stepwizard-step">
        <a href="/thank-you" type="button" class="btn btn-default btn-circle" disabled="disabled" id="step-4">4</a>
        <p>Finish</p>
      </div>
    </div>
  </div>
</code>```

Code above work fine when was triggered by jQuery which looks like
      function stepnext(n){

```<code>function step(n){
    if(n != 0){
        $(".stepwizard-row a").removeClass('btn-primary');
        $(".stepwizard-row a").addClass('btn-default');
        $('.stepwizard-row #step-'+n+'').removeClass('btn-default');
        $('.stepwizard-row #step-'+n+'').addClass('btn-primary');
    }
}
</code>```

but I have moved it to each step controller and triggers it as

```<code>var stepReset = angular.element( document.querySelector( '.stepwizard-row a' ) );
stepReset.removeClass('btn-primary');
stepReset.addClass('btn-default');

var stepActive = angular.element( document.querySelector( '#step-1' ) );
stepActive.removeClass('btn-default');
stepActive.addClass('btn-primary');
</code>```

and so on for each #step-X

It works fine for selecting on each step for btn-primary but then when I follow to next step like from 2 to 3 is not reseting class from step 2 to btn-default just taking effect on first element from .stepwizard-row a which is step#1.

My question is how I can select all DOM elements for .stepwizard-row a?

Another question is related to have links "disabled" until landed or passed particular step. I have set them to disabled="disabled" but AngularJS let me click on them and skip steps.

答:
A similar and easier approach would be :

```<code><a href="/" type="button" class="btn btn-circle" ng-class="{'btn-default': step === 1, 'btn-primary': step !== 1 }" id="step-1">1</a>
</code>```

And in your Controller:

```<code>function currentStep (step) { $scope.step = step; }
</code>```

Body:
I'm trying to make a simple step-by-step wizard.

HTML code for that (in index.html) looks like

        1

Start

        2

Registration

        3

Tutorial

        4

Finish

Code above work fine when was triggered by jQuery which looks like
      function stepnext(n){

function step(n){
    if(n != 0){
        $(".stepwizard-row a").removeClass('btn-primary');
        $(".stepwizard-row a").addClass('btn-default');
        $('.stepwizard-row #step-'+n+'').removeClass('btn-default');
        $('.stepwizard-row #step-'+n+'').addClass('btn-primary');
    }
}

but I have moved it to each step controller and triggers it as

var stepReset = angular.element( document.querySelector( '.stepwizard-row a' ) );
stepReset.removeClass('btn-primary');
stepReset.addClass('btn-default');

var stepActive = angular.element( document.querySelector( '#step-1' ) );
stepActive.removeClass('btn-default');
stepActive.addClass('btn-primary');

and so on for each #step-X

It works fine for selecting on each step for btn-primary but then when I follow to next step like from 2 to 3 is not reseting class from step 2 to btn-default just taking effect on first element from .stepwizard-row a which is step#1.

My question is how I can select all DOM elements for .stepwizard-row a?

Another question is related to have links "disabled" until landed or passed particular step. I have set them to disabled="disabled" but AngularJS let me click on them and skip steps.

Body:
A similar and easier approach would be :

<a href="/" type="button" class="btn btn-circle" ng-class="{'btn-default': step === 1, 'btn-primary': step !== 1 }" id="step-1">1</a>

And in your Controller:

function currentStep (step) { $scope.step = step; }


问:
how to access elements inside of grid?
I have a lsitbox which contains a DataTemplate and inside that DataTemplate contains a Grid. I have attached MouseDown ClickListener to Grid. Now I want to get elements of that Grid whenever I click on it.

```<code><ListBox x:Name="listBox" HorizontalAlignment="Left" Height="222"
Margin="28,75,0,0" VerticalAlignment="Top" Width="244" ItemTemplate="
{DynamicResource DataTemplate1}" BorderThickness="5,1">
        <ListBox.Resources >
            <DataTemplate x:Key="DataTemplate1">
                <Grid Width="205" Height="84" MouseDown="ListClickListener">
                    <Label x:Name="nameLabel" Content="{Binding FullName}"
 HorizontalAlignment="Left" Margin="68,0,0,0" VerticalAlignment="Top"
 Width="127" Height="31"/>
                    <Label x:Name="numberLabel" Content="{Binding
 PhoneNumber}" HorizontalAlignment="Right" Margin="0,31,10,0"
 VerticalAlignment="Top" Width="127" Height="26"/>
                    <Ellipse x:Name="ellipse" HorizontalAlignment="Left"
 Height="60"  VerticalAlignment="Top" Width="60">
                        <Ellipse.Fill>
                            <ImageBrush ImageSource="{Binding Picture}"
 Stretch="UniformToFill"/>
                        </Ellipse.Fill>
                    </Ellipse>
                </Grid>
            </DataTemplate>
        </ListBox.Resources>
    </ListBox>
</code>```

and the method "ListClickListener" inside .cs is as follows:

```<code>private void ListClickListener(object sender, MouseButtonEventArgs e)
        {

        }
</code>```

答:
If all you want is the bound values from the controls, you don't need to touch the controls to do that. In fact, it's much better not to. You'd like to be able to change or rearrange the XAML in the DataTemplate without having to worry about fixing any other code.

You populated the ListBox with a collection of some class. That's the class you want to interact with, not any messy UI stuff. And that's easy in WPF.

For example, the Label's content is bound to the FullName property of the list box item's DataContext. Cast ((FrameworkElement)sender).DataContext to the type of the item displayed in the listbox. Let's say the item class is named MyListBoxItemClass:

```<code>private void ListClickListener(object sender, MouseButtonEventArgs e)
{
    var vm = (MyListBoxItemClass)((FrameworkElement)sender).DataContext;

    MessageBox.Show("FullName is " + vm.FullName);
}
</code>```

Title: how to access elements inside of grid?

Body:
I have a lsitbox which contains a DataTemplate and inside that DataTemplate contains a Grid. I have attached MouseDown ClickListener to Grid. Now I want to get elements of that Grid whenever I click on it.

<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="222"
Margin="28,75,0,0" VerticalAlignment="Top" Width="244" ItemTemplate="
{DynamicResource DataTemplate1}" BorderThickness="5,1">
        <ListBox.Resources >
            <DataTemplate x:Key="DataTemplate1">
                <Grid Width="205" Height="84" MouseDown="ListClickListener">

                    <Ellipse x:Name="ellipse" HorizontalAlignment="Left"
 Height="60"  VerticalAlignment="Top" Width="60">
                        <Ellipse.Fill>
                            <ImageBrush ImageSource="{Binding Picture}"
 Stretch="UniformToFill"/>
                        </Ellipse.Fill>
                    </Ellipse>
                </Grid>
            </DataTemplate>
        </ListBox.Resources>
    </ListBox>

and the method "ListClickListener" inside .cs is as follows:

private void ListClickListener(object sender, MouseButtonEventArgs e)
        {

        }

Body:
If all you want is the bound values from the controls, you don't need to touch the controls to do that. In fact, it's much better not to. You'd like to be able to change or rearrange the XAML in the DataTemplate without having to worry about fixing any other code.

You populated the ListBox with a collection of some class. That's the class you want to interact with, not any messy UI stuff. And that's easy in WPF.

For example, the Label's content is bound to the FullName property of the list box item's DataContext. Cast ((FrameworkElement)sender).DataContext to the type of the item displayed in the listbox. Let's say the item class is named MyListBoxItemClass:

private void ListClickListener(object sender, MouseButtonEventArgs e)
{
    var vm = (MyListBoxItemClass)((FrameworkElement)sender).DataContext;

    MessageBox.Show("FullName is " + vm.FullName);
}


问:
Change color of a word in html
I have a .html document that looks like this:

```<code><!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Change color</title>
  <style>
   .colortext {
     color: red;
   }
  </style>
 </head>
 <body>
  <p>bla bla lbla <span class="colortext">the</span>,
 the balfds of .</p>
 </body>
</html>
</code>```

In this document I give to the a red color. But how should I go in order to change color of every thein my huge text? Is there a way to change color in order not to write

for every word, I need?

答:
If you want use javascript to achieve this you can use regex like so.

HTML

```<code><p id="sentence">bla bla lbla the,
 the balfds of .</p>
</code>```

Javascript

```<code>var sentence = document.getElementById('sentence');
var text = sentence.textContent;

var replaceWord = text.replace(/\bthe\b/g,"<span class='colortext'>$&
</span>")

sentence.innerHTML = replaceWord;
</code>```

Title: Change color of a word in html

Body:
I have a .html document that looks like this:

<!DOCTYPE html>

  <meta charset="utf-8" />
  <title>Change color</title>

bla bla lbla the,
 the balfds of .

In this document I give to the a red color. But how should I go in order to change color of every thein my huge text? Is there a way to change color in order not to write

for every word, I need?

Body:
If you want use javascript to achieve this you can use regex like so.

HTML

<p id="sentence">bla bla lbla the,
 the balfds of .</p>

Javascript

var sentence = document.getElementById('sentence');
var text = sentence.textContent;

var replaceWord = text.replace(/\bthe\b/g,"<span class='colortext'>$&
</span>")

sentence.innerHTML = replaceWord;


问:
Match list of substrings and strings and return substring if it matches
I've seen may questions on this topic but most are the opposite of mine. I have a list of strings (column of a data frame) and a list of sub strings. I want to compare each string to the list of sub strings If it contains a sub string then return that sub-string else print 'no match'.

```<code>    subs = [cat, dog, mouse]

    df

      Name       Number     SubMatch
     dogfood      1           dog
     catfood      3           cat
     dogfood      2           dog
     mousehouse   1           mouse
     birdseed     1           no match
</code>```

my current output looks like this though:

```<code>     Name       Number     SubMatch
     dogfood      1           dog
     catfood      3           dog
     dogfood      2           dog
     mousehouse   1           dog
     birdseed     1           dog
</code>```

I suspect my code is just returning the first thing in the series, how do I change that to the correct thing in the series? Here is the Function:

```<code>    def matchy(col, subs):
        for name in col:
            for s in subs:
                if any(s in name for s in subs):
                    return s
                else:
                    return 'No Match'
</code>```

答:
I think you are over complicating things with a nested loop then the any test inside. Would this work better:

```<code>def matchy(col, subs):
        for name in col:
            for s in subs:
                if s in name:
                    return s
                else:
                    return 'No Match'
</code>```

Body:
I've seen may questions on this topic but most are the opposite of mine. I have a list of strings (column of a data frame) and a list of sub strings. I want to compare each string to the list of sub strings If it contains a sub string then return that sub-string else print 'no match'.

    subs = [cat, dog, mouse]

    df

      Name       Number     SubMatch
     dogfood      1           dog
     catfood      3           cat
     dogfood      2           dog
     mousehouse   1           mouse
     birdseed     1           no match

my current output looks like this though:

     Name       Number     SubMatch
     dogfood      1           dog
     catfood      3           dog
     dogfood      2           dog
     mousehouse   1           dog
     birdseed     1           dog

I suspect my code is just returning the first thing in the series, how do I change that to the correct thing in the series? Here is the Function:

    def matchy(col, subs):
        for name in col:
            for s in subs:
                if any(s in name for s in subs):
                    return s
                else:
                    return 'No Match'

Body:
I think you are over complicating things with a nested loop then the any test inside. Would this work better:

def matchy(col, subs):
        for name in col:
            for s in subs:
                if s in name:
                    return s
                else:
                    return 'No Match'


问:
Find role being used on server from AWS CLI
I'm on an EC2 instance that has an IAM role attached to it, and would like to be able to verify that I am indeed using this role from the AWS CLI.

I'm imagining being able to call something like this (but can't find anything like it in the CLI docs):

```<code>$ aws get-current-role-details
</code>```

Does this functionality exist?

答:
Unfortunately, there is not a simple way to get that information. You'll need to get there through the following path:

Step 1. Get the current EC2 instance ID from the instance metadata.

```<code>curl -s http://169.254.169.254/latest/meta-data/instance-id
</code>```

You may need the current region as well.

```<code>curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/\(.*\)[a-z]/\1/'
</code>```

Step 2. Get the ID of the IAM Instance Profile attached to your EC2 instance.

```<code>aws ec2 describe-instances \
    --region us-east-1 \
    --instance-id i-12345678 \
    --query 'Reservations[0].Instances[0].IamInstanceProfile.Id'
</code>```

Remember to substitute the EC2 instance ID and region as required.

Step 3. Get the IAM instance profile roles.

```<code>aws iam list-instance-profiles \
    --query "InstanceProfiles[?InstanceProfileId=='ABCDEFG'].Roles"
</code>```

Remember to substitute the IAM instance profile ID.

Notes:

An IAM instance profile may have more than one IAM role associated with it. Usually it will be only one, but it could have more.

Body:
I'm on an EC2 instance that has an IAM role attached to it, and would like to be able to verify that I am indeed using this role from the AWS CLI.

I'm imagining being able to call something like this (but can't find anything like it in the CLI docs):

$ aws get-current-role-details

Does this functionality exist?

Body:
Unfortunately, there is not a simple way to get that information. You'll need to get there through the following path:

Step 1. Get the current EC2 instance ID from the instance metadata.

curl -s http://169.254.169.254/latest/meta-data/instance-id

You may need the current region as well.

curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/\(.*\)[a-z]/\1/'

Step 2. Get the ID of the IAM Instance Profile attached to your EC2 instance.

aws ec2 describe-instances \
    --region us-east-1 \
    --instance-id i-12345678 \
    --query 'Reservations[0].Instances[0].IamInstanceProfile.Id'

Remember to substitute the EC2 instance ID and region as required.

Step 3. Get the IAM instance profile roles.

aws iam list-instance-profiles \
    --query "InstanceProfiles[?InstanceProfileId=='ABCDEFG'].Roles"

Remember to substitute the IAM instance profile ID.

Notes:

An IAM instance profile may have more than one IAM role associated with it. Usually it will be only one, but it could have more.


答:
I feel it's a bit difficult to answer this question without seeing the definition of Cell -- but I think I see the mistake. Think of the list as a set of layers. The loop is starting with the innermost value of C. Every time you call Cell in the loop, it "wraps" that value with another Cell with the next value. The outermost Cell has the last value.

In other words,

```<code>C = Cell(8)
D = Cell(9, C)
E = Cell(10, D)
</code>```

is equivalent to

```<code>E = Cell(10, Cell(9, Cell(8)))
</code>```

Is that clear?

EDIT:

For the sake of completeness, here's another way to do it:

```<code>class Cell(object):
    def __init__(self, data, n = None):
        self.data = data
        self.next = n

def list_concat_copy(A, B):
        head = Cell(A.data)
        C = head
        while A.next != None:
                A = A.next
                C.next = Cell(A.data)
                C = C.next
        C.next = Cell(B.data)
        C = C.next
        while B.next != None:
                B = B.next
                C.next = Cell(B.data)
                C = C.next
        return head

A = Cell(8, Cell(9, Cell(10)))
B = Cell(11, Cell(12, Cell(13)))
C = list_concat_copy(A, B)
</code>```

Title: Python copy and concatenate linked lists, preserve order

Body:
I feel it's a bit difficult to answer this question without seeing the definition of Cell -- but I think I see the mistake. Think of the list as a set of layers. The loop is starting with the innermost value of C. Every time you call Cell in the loop, it "wraps" that value with another Cell with the next value. The outermost Cell has the last value.

In other words,

C = Cell(8)
D = Cell(9, C)
E = Cell(10, D)

is equivalent to

E = Cell(10, Cell(9, Cell(8)))

Is that clear?

EDIT:

For the sake of completeness, here's another way to do it:

class Cell(object):
    def __init__(self, data, n = None):
        self.data = data
        self.next = n

def list_concat_copy(A, B):
        head = Cell(A.data)
        C = head
        while A.next != None:
                A = A.next
                C.next = Cell(A.data)
                C = C.next
        C.next = Cell(B.data)
        C = C.next
        while B.next != None:
                B = B.next
                C.next = Cell(B.data)
                C = C.next
        return head

A = Cell(8, Cell(9, Cell(10)))
B = Cell(11, Cell(12, Cell(13)))
C = list_concat_copy(A, B)


问:
DCount does not work. Pretty sure it has to do with the variable
My code stops running on the DCount line below.  In this RC is an Integer variable and previously set to 0.  RWPTitle is a string variable.  I think it has to do with how I have RWPTitle written.  Don't know if it is the quotation marks or what.  Not sure of syntax.

```<code>RC = DCount("PlanTitle", "rwpT", "PlanTile = " & RWPTitle)
</code>```

答:
Firstly, it is important to ensure you spell your field names correctly. ;)

Secondly, you usually will need to put quotation marks around string values.

```<code>RC = DCount("PlanTitle", "rwpT", "PlanTitle = '" & RWPTitle & "'")
</code>```

Body:
My code stops running on the DCount line below.  In this RC is an Integer variable and previously set to 0.  RWPTitle is a string variable.  I think it has to do with how I have RWPTitle written.  Don't know if it is the quotation marks or what.  Not sure of syntax.

RC = DCount("PlanTitle", "rwpT", "PlanTile = " & RWPTitle)

Body:
Firstly, it is important to ensure you spell your field names correctly. ;)

Secondly, you usually will need to put quotation marks around string values.

RC = DCount("PlanTitle", "rwpT", "PlanTitle = '" & RWPTitle & "'")


问:
Display message from properties file in Grails
I am very new to Grails and during my work I am stuck in one place. For the below mention submit button I would like to fetch the value from properties file. This is done with g:message when I am displaying value under td tag but for button what will e the syntax.</p>

```<code><g:submitToRemote class="submit"  value="<g:message code='Save' default='Save' />"/>
</code>```

答:
You may write your GSP as</p>

```<code><g:submitToRemote class="submit"  value="${g.message(code:'Save', default:'Save')}"/>
</code>```

Body:
I am very new to Grails and during my work I am stuck in one place. For the below mention submit button I would like to fetch the value from properties file. This is done with g:message when I am displaying value under td tag but for button what will e the syntax.

<g:submitToRemote class="submit"  value="<g:message code='Save' default='Save' />"/>

Body:
You may write your GSP as

<g:submitToRemote class="submit"  value="${g.message(code:'Save', default:'Save')}"/>