问:
Sheet copying moving blank or error

Microsoft Excel 2013 (15.0.4675.1000) 32bit

When trying to move or copy one of my sheet no matter in same workbook or other I get empty sheet which named as Sheet1 Sheet2 and etc.

When trying do the same thing programmatically with VBA like:

```<code>Sheets("Invoice").Select
Sheets("Invoice").Copy Before:=Sheets(1)
</code>```

I also get error Run time Error 1004: Method Copy of class Worksheet failed
This happens very often and every time on different sheets.

Maybe it because of many defined ranges on the sheet?

I tried save and close the workbook after copying but suck.
Workbook size is 100Kb only.

After empty sheet is created if I try to remove it Excel going to stop working and crashing.

Is this a Excel bug or what?

Here is attached file

Can you duplicate Invoice sheets?

答: I got your point, as the excel sheet are copying empty with Sheet-1 name is that the name of the sheet what you are trying to copy is 30 or 31 character, and Excel do not accept any sheet more than 31 character so this is why it can not be copied properly, please reduce the name of the sheet and try, I am sure you will be able to copy the sheet to an other location.</p>

Title: Sheet copying moving blank or error

Body:
Microsoft Excel 2013 (15.0.4675.1000) 32bit

When trying to move or copy one of my sheet no matter in same workbook or other I get empty sheet which named as Sheet1 Sheet2 and etc.

When trying do the same thing programmatically with VBA like:

Sheets("Invoice").Select
Sheets("Invoice").Copy Before:=Sheets(1)

I also get error Run time Error 1004: Method Copy of class Worksheet failed
This happens very often and every time on different sheets.

Maybe it because of many defined ranges on the sheet?

I tried save and close the workbook after copying but suck.
Workbook size is 100Kb only.

After empty sheet is created if I try to remove it Excel going to stop working and crashing.

Is this a Excel bug or what?

Here is attached file

Can you duplicate Invoice sheets?


来源: stackexchange

问:
How to filter array based on id in angularJS
i have multiple data for one id , i want filter my data like this

```<code>$scope.mpArray =[
{ Id: 1, Name: Madhu, Address: Upal },
{ Id: 1, Name: Chandu, Address: Upal },
{ Id: 2, Name: Srinu, Address: Kphb },
{ Id: 2, Name: Vijay, Address: kphb },
{ Id: 3, Name: Ajay, Address: Banglore },
{ Id: 3, Name: Narsi, Address: Banglore },
{ Id: 3, Name: Peter, Address: Banglore },
];
</code>```

i want to filter my array like this

```<code>var FilterArray = [
{ Id: 1,Madhu, Chandu},
{ Id: 2, Srinu, Vijay},
{ Id: 3, Ajay, Narsi, Peter},
];
</code>```

答:
```<code>$scope.mpArray =[
                    { Id: 1, Name: 'Madhu', Address: 'Upal' },
                    { Id: 1, Name: 'Chandu', Address: 'Upal' },
                    { Id: 2, Name: 'Srinu', Address: 'Kphb' },
                    { Id: 2, Name: 'Vijay', Address: 'kphb' },
                    { Id: 3, Name: 'Ajay', Address: 'Banglore' },
                    { Id: 3, Name: 'Narsi', Address: 'Banglore' },
                    { Id: 3, Name: 'Peter', Address: 'Banglore' },
                    ];
                    var FilterArray = [];
                    var FilteredArrayIds=[];
                    $scope.mpArray.forEach(
                                            function(detailObj) {
                                                if(FilteredArrayIds.indexOf(detailObj.Id)==-1)
                                                 return FilteredArrayIds.push(detailObj.Id);
                                        });
                    for(var i=0; i<FilteredArrayIds.length;i++)
                    {
                          var result = $scope.mpArray.filter(function( obj ) {
                              return obj.Id == FilteredArrayIds[i];
                          });
                          var rsltNames = result.map(function(obj){
                            return obj.Name;
                          })
                          var filteredObj ={
                            id:FilteredArrayIds[i]+',' +rsltNames.join()
                          }
                          FilterArray.push(filteredObj);
                    }
                    console.log(filteredObj)
</code>```

ContentLicense: CC BY-SA 3.0

Body:
i have multiple data for one id , i want filter my data like this

$scope.mpArray =[
{ Id: 1, Name: Madhu, Address: Upal },
{ Id: 1, Name: Chandu, Address: Upal },
{ Id: 2, Name: Srinu, Address: Kphb },
{ Id: 2, Name: Vijay, Address: kphb },
{ Id: 3, Name: Ajay, Address: Banglore },
{ Id: 3, Name: Narsi, Address: Banglore },
{ Id: 3, Name: Peter, Address: Banglore },
];

i want to filter my array like this

var FilterArray = [
{ Id: 1,Madhu, Chandu},
{ Id: 2, Srinu, Vijay},
{ Id: 3, Ajay, Narsi, Peter},
];


问:
ASP.NET Empty Web Site template
I'm trying to find ASP.NET Empty Web Site in Visual Studio 2016 template list, but I can't. It is still exist there or I'm able to use only ASP.NET Web Application?</p>

答:
To create an Empty web site, you need to do the following :

Open VS2015 > File > New Web Site > Visual C# > ASP.Net Empty Web Site

Title: ASP.NET Empty Web Site template


问:
Install ansible on HP UX
I'm new to ansible and I'm trying to figure out if there is a way to install ansible on HP-UX 11.31 machine.

I tried google it, but I was not able to find if / how it can be done.

I have Python installed on the machine.

Thanks,
Boaz.

答:
HP-UX can be managed by ansible just fine.
You just need to:

Install Python 2 (can be found in official HP-UX Internet Express bundle)

Copy rsa key (with ssh-copy-id or just upload it with some other tool)
That's, basically it.

If you want to setup control machine... just use Linux for that.

Title: Install ansible on HP UX


问:
No mapping between account names and security IDs was done - Install SQL Server MDS Workflow Integration Service
I try to create custom workflow by following article in https://learn.microsoft.com/en-us/sql/master-data-services/develop/create-a-custom-workflow-master-data-services.

I try to run InstallUtil Microsoft.MasterDataServices.Workflow.exe, but it failes. I wonder why.

I have specifed as servername\mds_workflow_service user when prompted during installation. I have just for case reset password to make sure that password is correct. The user have read and execute rights to the \bin folder. What could be wrong?

C:\Program Files\Microsoft SQL Server\130\Master Data Services\WebApplication\bin>InstallUtil Microsoft.MasterDataServices.Workflow.exe
Microsoft (R) .NET Framework Installation utility Version 4.7.2053.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\Program Files\Microsoft SQL Server\130\Master Data Services\WebApplication\bin\Microsoft.MasterDataServices.Workflow.exe assembly's progress.
The file is located at C:\Program Files\Microsoft SQL Server\130\Master Data Services\WebApplication\bin\Microsoft.MasterDataServices.Workflow.InstallLog.
Installing assembly 'C:\Program Files\Microsoft SQL Server\130\Master Data Services\WebApplication\bin\Microsoft.MasterDataServices.Workflow.exe'.
Affected parameters are:
   logtoconsole =
   assemblypath = C:\Program Files\Microsoft SQL Server\130\Master Data Services\WebApplication\bin\Microsoft.MasterDataServices.Workflow.exe
   logfile = C:\Program Files\Microsoft SQL Server\130\Master Data Services\WebApplication\bin\Microsoft.MasterDataServices.Workflow.InstallLog

An exception occurred during the Install phase.
System.ComponentModel.Win32Exception: No mapping between account names and security IDs was done

答: Solved by enterering service account in format in .\mds_workflow_service</p>


问:
Sed remove NULL but only when the NULL means empty or no value
Exporting a table from MySQL where fields that have no value will have the keyword NULL within.

```<code>| id | name | nickname | origin | date |
| 1  | Joe  | Mini-J   | BRAZIL | NULL |
</code>```

I have written a script to automatically remove all occurrences of NULL using a one-liner sed, which will remove the NULL in date column correctly:

```<code>sed -i 's/NULL//g'
</code>```

However, how do we handle IF we have the following?

```<code>| id | name | nickname | origin | date |
| 1  | Joe  | Mini-J   | BRAZIL | NULL |
| 2  | Dees | DJ Null Bee| US| 2017-04-01 |
| 3  | NULL AND VOID | NULLZIET | NULL| 2016-05-13 |
| 4  | Pablo | ALA PUHU MINULLE | GERMANY| 2017-02-14 |
</code>```

Apparently, the global search and replace all occurrences of NULL will be removed, where even "ALA PUHU MINULLE" will become "ALA PUHU MIE", which is incorrect.

I suppose the use of regex perhaps can be useful to apply the rule? But if so, will "DJ Null Bee" be affected or will it become "DJ Bee"? The desired outcome should really be:

```<code>| id | name | nickname | origin | date |
| 1  | Joe  | Mini-J   | BRAZIL |  |
| 2  | Dees | DJ Null Bee| US| 2017-04-01 |
| 3  | NULL AND VOID | DJ Null Bee| | 2016-05-13 |
| 4  | Pablo | ALA PUHU MINULLE | GERMANY| 2017-02-14 |
</code>```

Given that NULL is a special keyword for any databases, but there is no stopping anyone from calling themselves a DJ NULL, or have the word NULL because it means differently in another language.

Any ideas on how to resolve this? Any suggestions welcomed. Thank you!

答:
Use awk:

```<code>awk -F\| '{ for (i=2;i<=NF;i++) { if ( $i == " NULL " ) { printf "| " } else if ( $i == " NULL" ) { printf "| DJ Null Bee " } else { printf "|"$i } } printf "\n" }' filename
</code>```

Using pipe as the field separator, go through each field and then check if the field equates to " NULL " If it does, print nothing. Then check if the field equals " NULL" If it does print "DJ Null Bee" else print the field as is.

Body:
Exporting a table from MySQL where fields that have no value will have the keyword NULL within.

| id | name | nickname | origin | date |
| 1  | Joe  | Mini-J   | BRAZIL | NULL |

I have written a script to automatically remove all occurrences of NULL using a one-liner sed, which will remove the NULL in date column correctly:

sed -i 's/NULL//g'

However, how do we handle IF we have the following?

| id | name | nickname | origin | date |
| 1  | Joe  | Mini-J   | BRAZIL | NULL |
| 2  | Dees | DJ Null Bee| US| 2017-04-01 |
| 3  | NULL AND VOID | NULLZIET | NULL| 2016-05-13 |
| 4  | Pablo | ALA PUHU MINULLE | GERMANY| 2017-02-14 |

Apparently, the global search and replace all occurrences of NULL will be removed, where even "ALA PUHU MINULLE" will become "ALA PUHU MIE", which is incorrect.

I suppose the use of regex perhaps can be useful to apply the rule? But if so, will "DJ Null Bee" be affected or will it become "DJ Bee"? The desired outcome should really be:

| id | name | nickname | origin | date |
| 1  | Joe  | Mini-J   | BRAZIL |  |
| 2  | Dees | DJ Null Bee| US| 2017-04-01 |
| 3  | NULL AND VOID | DJ Null Bee| | 2016-05-13 |
| 4  | Pablo | ALA PUHU MINULLE | GERMANY| 2017-02-14 |

Given that NULL is a special keyword for any databases, but there is no stopping anyone from calling themselves a DJ NULL, or have the word NULL because it means differently in another language.

Any ideas on how to resolve this? Any suggestions welcomed. Thank you!

Body:
Use awk:

awk -F\| '{ for (i=2;i<=NF;i++) { if ( $i == " NULL " ) { printf "| " } else if ( $i == " NULL" ) { printf "| DJ Null Bee " } else { printf "|"$i } } printf "\n" }' filename

Using pipe as the field separator, go through each field and then check if the field equates to " NULL " If it does, print nothing. Then check if the field equals " NULL" If it does print "DJ Null Bee" else print the field as is.


问:
Display the output on the terminal and tail the last 10 lines to log file
I need to run a script and output the full contents to the terminal.
I then want to get the last 10 lines from the terminal output and put them in a log file.
I have tried using ./script.sh 2>&1 | tail -10 > log.log
but this stops the output to the terminal.

答:
Leverage process substitution of bash with tee:

```<code>./script.sh |& tee >(tail -10 >file.txt)
</code>```

|& is a shortcut for sending both STDOUT and STDERR over the pipe.

tee redirects it's STDIN to both STDOUT and to the file(s) given as argument(s) -- we have used process substitution to get a file descriptor and used tail -10 >file.txt inside process substitution to save the desired content.

Body:
Leverage process substitution of bash with tee:

./script.sh |& tee >(tail -10 >file.txt)

|& is a shortcut for sending both STDOUT and STDERR over the pipe.

tee redirects it's STDIN to both STDOUT and to the file(s) given as argument(s) -- we have used process substitution to get a file descriptor and used tail -10 >file.txt inside process substitution to save the desired content.


问:
PHP imagettftext always drawing black
Basically when I draw text it's ending up black like this: http://i.stack.imgur.com/z675F.png
Instead of the color I'm allocated in PHP and the function.
Code:

```<code>    $finalImage = imagecreatefrompng($imageFile);
    $logo = imagecreatefrompng($logoImage);
    imagecopy($finalImage, $logo, $logoPosition['x'], $logoPosition['y'], 0, 0, imagesx($logo), imagesy($logo));
    $font = "arial.ttf";
    $fontSize = 10;
    $yOffSet = 15;
    $white = imagecolorallocate($finalImage, 255, 255, 255);
    foreach($pixelArray as $key => $x) {
        foreach($valueArray[$key] as $valueText) {

            imagettftext($finalImage, $fontSize, 0, $x, $yOffSet, $white, $font, $valueText);
            $yOffSet += 15;
        }
        $yOffSet = 15;
    }
    if($miscText != null) {
        foreach($miscText as $key => $text) {
            imagettftext($finalImage, $fontSize, 0, $text['x'], $text['y'], $white, $font, $text['text']);
        }
    }
    imagepng($finalImage,$saveFileName.".png");
    imagedestroy($finalImage);
</code>```

It was working before, but then it just stopped and I have no clue why. It was after I changed the source image (Was generating fine) and I hadn't touched the code. I've tried all sorts of things with changing the colors, but I can't get it to display in anything other then black.

答:
Have you checked if the imagecolorallocate() function is returning boolean false, as it will if the allocation fails? If the $finalImage .png is 8bit, and your pure white color isn't in the source image's palette, this call will fail. You do say you changed the source image, so this is most likely why it's broken now.

```<code>$white = imagecolorallocate($finalImage, 255, 255, 255);
if ($white === FALSE) { // note the === -> strict type comparison
    die("Failed to allocate color 255/255/255")
}
</code>```

The function will also simply return a number representing the color triplets, in this case it would 0xFFFFFF. You can try passing that into the imagegetttftext() call directly, see if that helps.

ContentLicense: CC BY-SA 2.5

Title: PHP imagettftext always drawing black

Body:
Basically when I draw text it's ending up black like this: http://i.stack.imgur.com/z675F.png
Instead of the color I'm allocated in PHP and the function.
Code:

    $finalImage = imagecreatefrompng($imageFile);
    $logo = imagecreatefrompng($logoImage);
    imagecopy($finalImage, $logo, $logoPosition['x'], $logoPosition['y'], 0, 0, imagesx($logo), imagesy($logo));
    $font = "arial.ttf";
    $fontSize = 10;
    $yOffSet = 15;
    $white = imagecolorallocate($finalImage, 255, 255, 255);
    foreach($pixelArray as $key => $x) {
        foreach($valueArray[$key] as $valueText) {

            imagettftext($finalImage, $fontSize, 0, $x, $yOffSet, $white, $font, $valueText);
            $yOffSet += 15;
        }
        $yOffSet = 15;
    }
    if($miscText != null) {
        foreach($miscText as $key => $text) {
            imagettftext($finalImage, $fontSize, 0, $text['x'], $text['y'], $white, $font, $text['text']);
        }
    }
    imagepng($finalImage,$saveFileName.".png");
    imagedestroy($finalImage);

It was working before, but then it just stopped and I have no clue why. It was after I changed the source image (Was generating fine) and I hadn't touched the code. I've tried all sorts of things with changing the colors, but I can't get it to display in anything other then black.

Body:
Have you checked if the imagecolorallocate() function is returning boolean false, as it will if the allocation fails? If the $finalImage .png is 8bit, and your pure white color isn't in the source image's palette, this call will fail. You do say you changed the source image, so this is most likely why it's broken now.

$white = imagecolorallocate($finalImage, 255, 255, 255);
if ($white === FALSE) { // note the === -> strict type comparison
    die("Failed to allocate color 255/255/255")
}

The function will also simply return a number representing the color triplets, in this case it would 0xFFFFFF. You can try passing that into the imagegetttftext() call directly, see if that helps.


问:
How to use sql to select an element based on the result of another query
I have two tables, TABLE_1  and TABLE_2.

```<code>TABLE_1 : Line_id | Fail_id
              1        2
              2        3
TABLE_2 : Fail_id | Fail_reason
              1       "nrc"
              2       "lkc"
              3       "llc"
</code>```

How do I get Fail_resason for Line_id = 1 using a single query?I can do this using two queries but I have to use only 1 query.
Please help.

答:
You can join two tables like so:</p>

```<code> SELECT t2.Fail_reason
 FROM TABLE_1 as t1 JOIN TABLE_2 as t2 on t1.Fail_id = t2.Fail_id
 WHERE t1.Line_id = 1
</code>```

Body:
I have two tables, TABLE_1  and TABLE_2.

TABLE_1 : Line_id | Fail_id
              1        2
              2        3
TABLE_2 : Fail_id | Fail_reason
              1       "nrc"
              2       "lkc"
              3       "llc"

How do I get Fail_resason for Line_id = 1 using a single query?I can do this using two queries but I have to use only 1 query.
Please help.

Body:
You can join two tables like so:

 SELECT t2.Fail_reason
 FROM TABLE_1 as t1 JOIN TABLE_2 as t2 on t1.Fail_id = t2.Fail_id
 WHERE t1.Line_id = 1


问:
Avoid spam request to Azure functions
I'm using an Azure function app for my website to help send email. I use Azure Function authentication and pass the key as header from Ajax request and that works well. But my issue is that, having the function call in the JS of the website make it prone to my friends sending automated Http requests, such that the function is repeatedly executed
Is there a way to avoid this. May be using the request sender IP?</p>

答:
Azure Function keys are not supposed to be shipped to the end user devices (be it browser, mobile app, IoT device etc). You should hide function calls behind some authentication flow.

See these links for some options:

Authentication and authorization in Azure App Service

Working with identity in an Azure Function

A very similar question, but from Mobile app point of view:

How to safely call Azure Function with function level authorization in Xamarin mobile app?

Title: Avoid spam request to Azure functions


问:
Treat Userform as a Function
I have created a VBA UserForm which is essentially a glorified input box

Just like an input box can be employed like this

```<code>Dim returnVal As String
returnVal = InputBox("Write some string")
</code>```

I would like my userform to run like this

```<code>Dim returnVal As customClass
Set returnVal = MyUserForm([some arguments])
</code>```

ie. the MyUserForm() code passes some arguments to the userform, and when the userform is closed, it gets some arguments back (in the form of a custom class rather than a plain string)

What's the best way of structuring my userform to allow this functionality?

Currently, I'm just declaring some variables and the custom class publicly. I'm catching command button clicks and Query_close() events to hide the form, then I read the outputVal and close the form completely. I don't like this because I'd like my form to be totally self contained, and I think the capturing of events is messy.

In simplified code (read/return a string):

```<code>Function myUf(inVal As String) As String
Dim frm As New frmTest
frm.inputval = inVal
frm.Init 'sets caption. We cannot rely on userform initialize as this runs before inputval is set
         'We could pass a variable here to save writing to the public variable
frm.Show
myUf = frm.outputVal
Set frm = Nothing
End Function
</code>```

And in my Userform called frmTest with a textbox called tb1

```<code>Public inputval As String
Public outputVal As String

Public Sub Init()
Me.Caption = inputval 'setting caption, but could pass this anywhere
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = 1
outputVal = tb1 'reading value from textbox, but could return anything here
Me.Hide
End Sub
</code>```

答:
The basic idea is:

Create a Function in witch you combine your arguments to a string like:

```<code>strOpenArg = "param1:=value1;param2:=value2;"
</code>```

than open the form with the OpenArgs

```<code>DoCmd.OpenForm "UserForm", acNormal, , , , acDialog, strOpenArgs
</code>```

get your value and close the Form

```<code>Value= Form_UserForm.Value

DoCmd.Close acForm, "UserForm", acSaveNo
</code>```

in the UserForm set Form_open. Here you can get your parameters.you can devide this by string splitting.
Set also an OK Button, where you make the form just invisible and set the return value

```<code>Private Sub Form_Open(Cancel As Integer)
     Dim strParameter as String
     strParameter = Me.OpenArgs 'Here are your parmeters
End Sub

Private Sub ok_Click()
    m_Value = "Your ReturnValue"
    Me.Visible = False
End Sub

Private m_Value As String
Public Property Get Value() As String
    Value = m_msgBoxResult
End Property
</code>```

Title: Treat Userform as a Function

Body:
I have created a VBA UserForm which is essentially a glorified input box

Just like an input box can be employed like this

Dim returnVal As String
returnVal = InputBox("Write some string")

I would like my userform to run like this

Dim returnVal As customClass
Set returnVal = MyUserForm([some arguments])

ie. the MyUserForm() code passes some arguments to the userform, and when the userform is closed, it gets some arguments back (in the form of a custom class rather than a plain string)

What's the best way of structuring my userform to allow this functionality?

Currently, I'm just declaring some variables and the custom class publicly. I'm catching command button clicks and Query_close() events to hide the form, then I read the outputVal and close the form completely. I don't like this because I'd like my form to be totally self contained, and I think the capturing of events is messy.

In simplified code (read/return a string):

Function myUf(inVal As String) As String
Dim frm As New frmTest
frm.inputval = inVal
frm.Init 'sets caption. We cannot rely on userform initialize as this runs before inputval is set
         'We could pass a variable here to save writing to the public variable
frm.Show
myUf = frm.outputVal
Set frm = Nothing
End Function

And in my Userform called frmTest with a textbox called tb1

Public inputval As String
Public outputVal As String

Public Sub Init()
Me.Caption = inputval 'setting caption, but could pass this anywhere
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = 1
outputVal = tb1 'reading value from textbox, but could return anything here
Me.Hide
End Sub

Body:
The basic idea is:

Create a Function in witch you combine your arguments to a string like:

strOpenArg = "param1:=value1;param2:=value2;"

than open the form with the OpenArgs

DoCmd.OpenForm "UserForm", acNormal, , , , acDialog, strOpenArgs

get your value and close the Form

Value= Form_UserForm.Value

DoCmd.Close acForm, "UserForm", acSaveNo

in the UserForm set Form_open. Here you can get your parameters.you can devide this by string splitting.
Set also an OK Button, where you make the form just invisible and set the return value

Private Sub Form_Open(Cancel As Integer)
     Dim strParameter as String
     strParameter = Me.OpenArgs 'Here are your parmeters
End Sub

Private Sub ok_Click()
    m_Value = "Your ReturnValue"
    Me.Visible = False
End Sub

Private m_Value As String
Public Property Get Value() As String
    Value = m_msgBoxResult
End Property


问:
Spark java.io.InvalidClassException: org.apache.spark.unsafe.types.UTF8String; local class incompatible
I'm attempting to run my Spark applicaiton on a remote cluster and I'm getting serialization errors. The Scala and Spark version are the same. I'm stuck at this point.

spark-shell -version on the cluster:

```<code>root@a913008dd071:/usr/local/spark-2.1.1# ./bin/spark-submit --version
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 2.1.1
      /_/

Using Scala version 2.11.8, OpenJDK 64-Bit Server VM, 1.8.0_131
Branch
Compiled by user jenkins on 2017-04-25T23:51:10Z
Revision
Url
Type --help for more information.
</code>```

build.sbt

```<code>import sbt.ExclusionRule

name := "hxfa"
version := "1.0"
scalaVersion := "2.11.8"

val elasticVersion = "5.4.1"

resolvers += "Spark Packages" at "https://dl.bintray.com/spark-packages/maven/"
resolvers += "Additional spark packages" at "https://dl.bintray.com/sbcd90/org.apache.spark"
resolvers += "Apache HBase" at "https://repository.apache.org/content/repositories/releases"
resolvers += "Thrift" at "http://people.apache.org/~rawson/repo/"
resolvers += "Spring Plugins" at "http://repo.spring.io/plugins-release/"

/* Dependencies */
libraryDependencies ++= Seq(
  // Framework and configuration
  "org.springframework.boot" % "spring-boot-starter-web" % "1.5.4.RELEASE",
  "org.hibernate" % "hibernate-validator" % "5.2.4.Final",

  /* Serializations */
  "com.fasterxml.jackson.core" % "jackson-core" % "2.8.7",
  "com.fasterxml.jackson.core" % "jackson-databind" % "2.8.7",
  "com.fasterxml.jackson.module" % "jackson-module-scala_2.11" % "2.8.7",
  "com.esotericsoftware" % "kryo" % "4.0.0",

  // Spark and utilities
  "org.apache.spark" %% "spark-core" % "2.1.0",
  "org.apache.spark" %% "spark-sql" % "2.1.0" ,
  "org.apache.spark" %% "spark-mllib" % "2.1.0" ,
  "graphframes" % "graphframes" % "0.5.0-spark2.1-s_2.11",

  // Spark connectors
  "org.elasticsearch" % "elasticsearch-spark-20_2.11" % elasticVersion,
  "org.mongodb.spark" % "mongo-spark-connector_2.11" % "2.0.0",

  //JDBC
  "mysql" % "mysql-connector-java" % "5.1.35",

  // HBase
  "org.apache.hbase" % "hbase" % "1.2.4",
  "org.apache.hbase" % "hbase-client" % "1.2.4",
  "org.apache.hbase" % "hbase-common" % "1.2.4",

  // OrientDB
  "com.orientechnologies" % "orientdb-graphdb" % "2.2.20"

).map(_.excludeAll(ExclusionRule("org.slf4j", "slf4j-log4j12"), ExclusionRule("log4j", "log4j")))

libraryDependencies ++= Seq(
  "org.apache.hbase" % "hbase-server" % "1.2.4"
).map(_.excludeAll(
  ExclusionRule("com.sun.jersey", "jersey-server"),
  ExclusionRule("tomcat"),
  ExclusionRule("log4j", "log4j")
))

/* Assembly     */

mainClass in assembly := Some("com.x.x.hello.app.HX")
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false, includeDependency = false)

assemblyMergeStrategy in assembly := {
  case PathList("META-INF", xs@_*) => MergeStrategy.discard
  case x => MergeStrategy.first
}
</code>```

Stack trace:

java.io.InvalidClassException: org.apache.spark.unsafe.types.UTF8String; local class incompatible: stream classdesc serialVersionUID = -2992553500466442037, local class serialVersionUID = -5670082246090726217
      at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:616) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1843) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1713) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2000) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at scala.collection.immutable.List$SerializationProxy.readObject(List.scala:479) ~[scala-library-2.11.8.jar:1.0.0-M1]
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_45]
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at scala.collection.immutable.List$SerializationProxy.readObject(List.scala:479) ~[scala-library-2.11.8.jar:1.0.0-M1]
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_45]
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at scala.collection.immutable.List$SerializationProxy.readObject(List.scala:479) ~[scala-library-2.11.8.jar:1.0.0-M1]
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_45]
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at org.apache.spark.serializer.JavaDeserializationStream.readObject(JavaSerializer.scala:75) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.serializer.JavaSerializerInstance.deserialize(JavaSerializer.scala:114) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:80) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.scheduler.Task.run(Task.scala:99) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:322) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_45]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_45]
      at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_45]

答:
spark-submit --version displays the spark and scala version of its package and not of your system whereas your sbt is taking the scala version of your system. So

Please change

```<code>  "org.apache.spark" %% "spark-core" % "2.1.0",
  "org.apache.spark" %% "spark-sql" % "2.1.0" ,
  "org.apache.spark" %% "spark-mllib" % "2.1.0" ,
</code>```

to

```<code>  "org.apache.spark" % "spark-core_2.11" % "2.1.1",
  "org.apache.spark" % "spark-sql_2.11" % "2.1.1" ,
  "org.apache.spark" % "spark-mllib_2.11" % "2.1.1" ,
</code>```

And if it doesn't help, please update your question with your system scala version, how you are submitting the application and your remote machine's scala and spark version.

Body:
I'm attempting to run my Spark applicaiton on a remote cluster and I'm getting serialization errors. The Scala and Spark version are the same. I'm stuck at this point.

spark-shell -version on the cluster:

root@a913008dd071:/usr/local/spark-2.1.1# ./bin/spark-submit --version
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 2.1.1
      /_/

Using Scala version 2.11.8, OpenJDK 64-Bit Server VM, 1.8.0_131
Branch
Compiled by user jenkins on 2017-04-25T23:51:10Z
Revision
Url
Type --help for more information.

build.sbt

import sbt.ExclusionRule

name := "hxfa"
version := "1.0"
scalaVersion := "2.11.8"

val elasticVersion = "5.4.1"

resolvers += "Spark Packages" at "https://dl.bintray.com/spark-packages/maven/"
resolvers += "Additional spark packages" at "https://dl.bintray.com/sbcd90/org.apache.spark"
resolvers += "Apache HBase" at "https://repository.apache.org/content/repositories/releases"
resolvers += "Thrift" at "http://people.apache.org/~rawson/repo/"
resolvers += "Spring Plugins" at "http://repo.spring.io/plugins-release/"

/* Dependencies */
libraryDependencies ++= Seq(
  // Framework and configuration
  "org.springframework.boot" % "spring-boot-starter-web" % "1.5.4.RELEASE",
  "org.hibernate" % "hibernate-validator" % "5.2.4.Final",

  /* Serializations */
  "com.fasterxml.jackson.core" % "jackson-core" % "2.8.7",
  "com.fasterxml.jackson.core" % "jackson-databind" % "2.8.7",
  "com.fasterxml.jackson.module" % "jackson-module-scala_2.11" % "2.8.7",
  "com.esotericsoftware" % "kryo" % "4.0.0",

  // Spark and utilities
  "org.apache.spark" %% "spark-core" % "2.1.0",
  "org.apache.spark" %% "spark-sql" % "2.1.0" ,
  "org.apache.spark" %% "spark-mllib" % "2.1.0" ,
  "graphframes" % "graphframes" % "0.5.0-spark2.1-s_2.11",

  // Spark connectors
  "org.elasticsearch" % "elasticsearch-spark-20_2.11" % elasticVersion,
  "org.mongodb.spark" % "mongo-spark-connector_2.11" % "2.0.0",

  //JDBC
  "mysql" % "mysql-connector-java" % "5.1.35",

  // HBase
  "org.apache.hbase" % "hbase" % "1.2.4",
  "org.apache.hbase" % "hbase-client" % "1.2.4",
  "org.apache.hbase" % "hbase-common" % "1.2.4",

  // OrientDB
  "com.orientechnologies" % "orientdb-graphdb" % "2.2.20"

).map(_.excludeAll(ExclusionRule("org.slf4j", "slf4j-log4j12"), ExclusionRule("log4j", "log4j")))

libraryDependencies ++= Seq(
  "org.apache.hbase" % "hbase-server" % "1.2.4"
).map(_.excludeAll(
  ExclusionRule("com.sun.jersey", "jersey-server"),
  ExclusionRule("tomcat"),
  ExclusionRule("log4j", "log4j")
))

/* Assembly     */

mainClass in assembly := Some("com.x.x.hello.app.HX")
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false, includeDependency = false)

assemblyMergeStrategy in assembly := {
  case PathList("META-INF", xs@_*) => MergeStrategy.discard
  case x => MergeStrategy.first
}

Stack trace:

java.io.InvalidClassException: org.apache.spark.unsafe.types.UTF8String; local class incompatible: stream classdesc serialVersionUID = -2992553500466442037, local class serialVersionUID = -5670082246090726217
      at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:616) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1843) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1713) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2000) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at scala.collection.immutable.List$SerializationProxy.readObject(List.scala:479) ~[scala-library-2.11.8.jar:1.0.0-M1]
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_45]
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at scala.collection.immutable.List$SerializationProxy.readObject(List.scala:479) ~[scala-library-2.11.8.jar:1.0.0-M1]
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_45]
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at scala.collection.immutable.List$SerializationProxy.readObject(List.scala:479) ~[scala-library-2.11.8.jar:1.0.0-M1]
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_45]
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[na:1.8.0_45]
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[na:1.8.0_45]
      at org.apache.spark.serializer.JavaDeserializationStream.readObject(JavaSerializer.scala:75) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.serializer.JavaSerializerInstance.deserialize(JavaSerializer.scala:114) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:80) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.scheduler.Task.run(Task.scala:99) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:322) ~[spark-core_2.11-2.1.0.jar:2.1.0]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_45]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_45]
      at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_45]

Body:
spark-submit --version displays the spark and scala version of its package and not of your system whereas your sbt is taking the scala version of your system. So

Please change

  "org.apache.spark" %% "spark-core" % "2.1.0",
  "org.apache.spark" %% "spark-sql" % "2.1.0" ,
  "org.apache.spark" %% "spark-mllib" % "2.1.0" ,

to

  "org.apache.spark" % "spark-core_2.11" % "2.1.1",
  "org.apache.spark" % "spark-sql_2.11" % "2.1.1" ,
  "org.apache.spark" % "spark-mllib_2.11" % "2.1.1" ,

And if it doesn't help, please update your question with your system scala version, how you are submitting the application and your remote machine's scala and spark version.


问:
Yii2 - Bad Request (#400) - Missing required parameters: id
CommentController:

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

    $model = new Comment();

    var_dump(Yii::$app->request->post());

     if ($model->load(Yii::$app->request->post()))
     {
        $model->user_id = Yii::$app->user->getId();
        $model->created_at = time();
        $model->updated_at = time();
        $model->save();

        return $this->redirect(Url::to(['post/view', 'id'=>$model->post_id]));
     }

    return $this->redirect(Url::to(['/post/index']));
}
</code>```

If I pass as false to $model->save() the data gets stored in the database with no value in the foreign key field 'post_id' but still doesn't redirect me to the correct page.

New to yii and relatively new to software development, any help would be massively appreciated.

答:
It redirects you to post/view - means PostController - actionView($id), but without param $id, which is required in actionView($id). That's why you get 400 missing param error. You have to add this param - for now if you add false to save() method and it is saved without post_id - you can't redirect user to post/view because you didn't passed id of this object in GET

To avoid such things you should check if $model is really saved by if($model->save()) and if, redirect user to view.

Body:
CommentController:

public function actionCreate()
{

    $model = new Comment();

    var_dump(Yii::$app->request->post());

     if ($model->load(Yii::$app->request->post()))
     {
        $model->user_id = Yii::$app->user->getId();
        $model->created_at = time();
        $model->updated_at = time();
        $model->save();

        return $this->redirect(Url::to(['post/view', 'id'=>$model->post_id]));
     }

    return $this->redirect(Url::to(['/post/index']));
}

If I pass as false to $model->save() the data gets stored in the database with no value in the foreign key field 'post_id' but still doesn't redirect me to the correct page.

New to yii and relatively new to software development, any help would be massively appreciated.


问:
fputcsv inserting extra "
I realized that strings which contains spaces are inserted on the csv file with an extra " at the beginning and at the end

```<code>if (!file_exists("./csv/file.csv")) {
    $header = array("Arbol completo","Títol","Code","Parent Code","Servei","Urgència per defecte","Impacte","No es pot sol·licitar","Flux de Treball","SLA","Grup Resolutor-1","Grupo responsable catalogo","Informació","Documentació","Descripció","Llista autoritzats","Icona","Caracteristica", "Valor");
    $fp = fopen("./csv/catalogo_de _peticiones_de_servicio.csv", "w");
    fprintf($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF)));
    fputcsv($fp, $header,";");
    fclose($fp);
}
</code>```

it's somthing wrog ,it doens't have enconding problems I'm usen utf-8 charset

答:
Specify enclosure as blank which is the 4th optional parameter of fputcsv. Default enclosure is "

```<code>fputcsv($fp, $header,";", '');
</code>```

Reference Link

Title: fputcsv inserting extra "

Body:
I realized that strings which contains spaces are inserted on the csv file with an extra " at the beginning and at the end

if (!file_exists("./csv/file.csv")) {
    $header = array("Arbol completo","Títol","Code","Parent Code","Servei","Urgència per defecte","Impacte","No es pot sol·licitar","Flux de Treball","SLA","Grup Resolutor-1","Grupo responsable catalogo","Informació","Documentació","Descripció","Llista autoritzats","Icona","Caracteristica", "Valor");
    $fp = fopen("./csv/catalogo_de _peticiones_de_servicio.csv", "w");
    fprintf($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF)));
    fputcsv($fp, $header,";");
    fclose($fp);
}

it's somthing wrog ,it doens't have enconding problems I'm usen utf-8 charset

Body:
Specify enclosure as blank which is the 4th optional parameter of fputcsv. Default enclosure is "

fputcsv($fp, $header,";", '');

Reference Link


问:
How to Connect two qml files?
I am making a music player application. i have a DownRect which has a slider and a playSection which has a button. this button has a audio. when button is clicked audio is played and i want the slider to set it's value by the audio duration. (the button is add dynamically from ButtonD.qml file). what i want to do is to connect DownRect's slider to playSection's button.

```<code>//DownRect.qml
Rectangle{
    id: downRectangle
    width: parent.width
    height: parent.height
    x:0
    y:750
    color: "#c62828"
    smooth: true
Slider{

        id: sliderDownRect
        x: 300
        y: 25
        width: 650
        from: 0
        //        to: play.duration
        stepSize: 100
        value: 0
        Material.accent : Material.background
        Material.foreground: Material.background
        onValueChanged:{

        }

    }
}
</code>```

and here is the ButtonD.qml file which i'd like to connect to DownRect.qml

```<code>  //ButtonD.qml
Button{
    id: buttonD
    width:900
    height: 46
    flat: true
  Audio{
        id: playing
    }
}
</code>```

答:
You make sure that the duration (and other relevant properties of Audio) are exposed in ButtonD.qml, e.g. by adding aliases like such:

```<code>Button {
    id: buttonD
    property alias duration: playing.duration
    ...
}
</code>```

The same goes for the Slider's value.

```<code>Rectangle {
    id: downRectangle
    property alias duration: sliderDownRect.to
    ...
}
</code>```

In the file that instantiates both, you use Binding-objects to create a bidirectional binding between the both. Those Binding-objects excell at working with dynamically instantiated objects.

Basically, if you'd include the files into one file, this should look something like this:

main.qml

```<code>import QtQuick 2.7
import QtQuick.Controls 2.0
import QtMultimedia 5.5

ApplicationWindow {
    id: myWindow
    visible: true
    width: 600
    height: 600
    color: 'white'

    property Item dynamicallyCreatedItem

    Button {
        x: 102
        text: 'create'
        onClicked: {
            dynamicallyCreatedItem = Qt.createComponent('AudioButton.qml').createObject(myWindow.contentItem)
        }
    }

    DownRect {
        y: 50
        id: rect
    }

    Binding {
        target: rect
        property: 'maxValue'
        value: dynamicallyCreatedItem ? dynamicallyCreatedItem.duration : 0
        when: dynamicallyCreatedItem
    }

    Binding {
        target: rect
        property: 'value'
        value: dynamicallyCreatedItem ? dynamicallyCreatedItem.position : 0
        when: dynamicallyCreatedItem
    }
}
</code>```

AudioButton.qml

```<code>import QtQuick 2.0
import QtQuick.Controls 2.0
import QtMultimedia 5.5

Button {
    id: audioButton
    onClicked: audio.play()
    property alias duration: audio.duration
    property alias position: audio.position
    Audio {
        id: audio
        source: 'airhorn.wav'
    }
}
</code>```

DownRect.qml

```<code>import QtQuick 2.0
import QtQuick.Controls 2.0

Rectangle {
    id: rect
    width: parent.width
    height: 50
    property alias value: slider.value
    property alias maxValue: slider.to
    Slider {
        id: slider
        anchors.fill: parent
    }
}
</code>```

Title: How to Connect two qml files?

Body:
I am making a music player application. i have a DownRect which has a slider and a playSection which has a button. this button has a audio. when button is clicked audio is played and i want the slider to set it's value by the audio duration. (the button is add dynamically from ButtonD.qml file). what i want to do is to connect DownRect's slider to playSection's button.

//DownRect.qml
Rectangle{
    id: downRectangle
    width: parent.width
    height: parent.height
    x:0
    y:750
    color: "#c62828"
    smooth: true
Slider{

        id: sliderDownRect
        x: 300
        y: 25
        width: 650
        from: 0
        //        to: play.duration
        stepSize: 100
        value: 0
        Material.accent : Material.background
        Material.foreground: Material.background
        onValueChanged:{

        }

    }
}

and here is the ButtonD.qml file which i'd like to connect to DownRect.qml

  //ButtonD.qml
Button{
    id: buttonD
    width:900
    height: 46
    flat: true
  Audio{
        id: playing
    }
}

Body:
You make sure that the duration (and other relevant properties of Audio) are exposed in ButtonD.qml, e.g. by adding aliases like such:

Button {
    id: buttonD
    property alias duration: playing.duration
    ...
}

The same goes for the Slider's value.

Rectangle {
    id: downRectangle
    property alias duration: sliderDownRect.to
    ...
}

In the file that instantiates both, you use Binding-objects to create a bidirectional binding between the both. Those Binding-objects excell at working with dynamically instantiated objects.

Basically, if you'd include the files into one file, this should look something like this:

main.qml

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtMultimedia 5.5

ApplicationWindow {
    id: myWindow
    visible: true
    width: 600
    height: 600
    color: 'white'

    property Item dynamicallyCreatedItem

    Button {
        x: 102
        text: 'create'
        onClicked: {
            dynamicallyCreatedItem = Qt.createComponent('AudioButton.qml').createObject(myWindow.contentItem)
        }
    }

    DownRect {
        y: 50
        id: rect
    }

    Binding {
        target: rect
        property: 'maxValue'
        value: dynamicallyCreatedItem ? dynamicallyCreatedItem.duration : 0
        when: dynamicallyCreatedItem
    }

    Binding {
        target: rect
        property: 'value'
        value: dynamicallyCreatedItem ? dynamicallyCreatedItem.position : 0
        when: dynamicallyCreatedItem
    }
}

AudioButton.qml

import QtQuick 2.0
import QtQuick.Controls 2.0
import QtMultimedia 5.5

Button {
    id: audioButton
    onClicked: audio.play()
    property alias duration: audio.duration
    property alias position: audio.position
    Audio {
        id: audio
        source: 'airhorn.wav'
    }
}

DownRect.qml

import QtQuick 2.0
import QtQuick.Controls 2.0

Rectangle {
    id: rect
    width: parent.width
    height: 50
    property alias value: slider.value
    property alias maxValue: slider.to
    Slider {
        id: slider
        anchors.fill: parent
    }
}


问:
Javascript indexOf() finds the index of one character, but not that of another character, from a string. Why?
I am trying to use the Javascript indexOf() function to find the index position of two characters, viz. [ and ] in a string. But it shows strange behavior, i.e. It finds the index of opening-bracket [ but returns empty string as index of ].

There is no error in the Console tab of Google Chrome Inspector.

So this is the question. Why is this happening and how should I fix this?

var string = 'allPeoplesArray[0][peopleNameInput]';

var indexOfFirstOpeningBracket = string.indexOf('[');
alert('indexOfFirstOpeningBracket: ' + indexOfFirstOpeningBracket);//check

var indexOfFirstClosingBracket = string.indexOf(']');
alert('indexOfFirstClosingBracket') + indexOfFirstClosingBracket;//check```

答:
@Ebrahim Poursadeqi's answer is absolutely correct. I am just explaining a bit.

```<code>alert('indexOfFirstClosingBracket') + indexOfFirstClosingBracket;
</code>```

There is an mistake in this line. Notice there is a closing bracket after'indexOfFirstClosingBracket'. Remove it from there and place it an the end of the statement.

```<code>alert('indexOfFirstClosingBracket' + indexOfFirstClosingBracket);
</code>```

And the program will work as desired. Hope this works for you.

Body:
@Ebrahim Poursadeqi's answer is absolutely correct. I am just explaining a bit.

alert('indexOfFirstClosingBracket') + indexOfFirstClosingBracket;

There is an mistake in this line. Notice there is a closing bracket after'indexOfFirstClosingBracket'. Remove it from there and place it an the end of the statement.

alert('indexOfFirstClosingBracket' + indexOfFirstClosingBracket);

And the program will work as desired. Hope this works for you.


问:
Google Banner ads Failed to load ad: 0
I am unable to load Google banner ad in my activity. I have added all the permissions and tags described in developer.google.com and also have refereed others questions in StackOverflow.

```<code>AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("477359CAFFxxxxxxxxxxxxxxxxxxx").build();
 enter code hereadView.loadAd(adRequest);{}
</code>```

"My logcat output: and i  have added all permissions and meta tags"

```<code>04-12 10:07:18.753: W/ResourcesManager(17370): Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
        04-12 10:07:18.753: W/ResourcesManager(17370): Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
        04-12 10:07:18.846: I/WebViewFactory(17370): Loading com.google.android.webview version 40 (1832189-arm) (code 424501)
        04-12 10:07:18.869: I/LibraryLoader(17370): Time to load native libraries: 3 ms (timestamps 5621-5624)
        04-12 10:07:18.869: I/LibraryLoader(17370): Expected native library version number "",actual native library version number ""
        04-12 10:07:18.875: V/WebViewChromiumFactoryProvider(17370): Binding Chromium to main looper Looper (main, tid 1) {28944cc5}
        04-12 10:07:18.876: I/LibraryLoader(17370): Expected native library version number "",actual native library version number ""
        04-12 10:07:18.876: I/chromium(17370): [INFO:library_loader_hooks.cc(108)] Chromium logging enabled: level = 0, default verbosity = 0
        04-12 10:07:18.883: I/BrowserStartupController(17370): Initializing chromium process, singleProcess=true
        04-12 10:07:18.884: W/art(17370): Attempt to remove local handle scope entry from IRT, ignoring
        04-12 10:07:18.892: W/chromium(17370): [WARNING:resource_bundle.cc(304)] locale_file_path.empty()
        04-12 10:07:18.892: W/AudioManagerAndroid(17370): Requires BLUETOOTH permission
        04-12 10:07:18.893: I/chromium(17370): [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=36 off=49196 len=3229
        04-12 10:07:18.894: I/chromium(17370): [INFO:aw_browser_main_parts.cc(76)] Loading webviewchromium.pak from, fd:37 off:390788 len:1143511
        04-12 10:07:18.899: I/Adreno-EGL(17370): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/14/15, ab0075f, Id3510ff6dc
        04-12 10:07:18.951: I/Ads(17370): Starting ad request.
        04-12 10:07:18.952: I/Ads(17370): Use AdRequest.Builder.addTestDevice("F9D483C5C3943E9EFDC31D1B4C183CF8") to get test ads on this device.
        04-12 10:07:18.961: D/OpenGLRenderer(17370): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
        04-12 10:07:18.967: D/Atlas(17370): Validating map...
        04-12 10:07:19.000: I/OpenGLRenderer(17370): Initialized EGL, version 1.4
        04-12 10:07:19.003: D/OpenGLRenderer(17370): Enabling debug mode 0
        04-12 10:07:19.050: I/Ads(17370): CsiReporterFactory: CSI is not enabled. No CSI reporter created.
        04-12 10:07:21.086: W/Ads(17370): There was a problem getting an ad response. ErrorCode: 0
        04-12 10:07:21.110: W/chromium(17370): [WARNING:data_reduction_proxy_settings.cc(328)] SPDY proxy OFF at startup
        04-12 10:07:21.120: W/art(17370): Attempt to remove local handle scope entry from IRT, ignoring
        04-12 10:07:21.124: W/AwContents(17370): onDetachedFromWindow called when already detached. Ignoring`enter code here`
        04-12 10:07:21.140: W/Ads(17370): Failed to load ad: 0
</code>```

答: I had to same problem.  I was informed on my admob account that no ads were loaded yet because I had not created a payment account.  Ensure you have created a payment account on your admob page. </p>

Title: Google Banner ads Failed to load ad: 0

Body:
I am unable to load Google banner ad in my activity. I have added all the permissions and tags described in developer.google.com and also have refereed others questions in StackOverflow.

AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("477359CAFFxxxxxxxxxxxxxxxxxxx").build();
 enter code hereadView.loadAd(adRequest);{}

"My logcat output: and i  have added all permissions and meta tags"

04-12 10:07:18.753: W/ResourcesManager(17370): Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
        04-12 10:07:18.753: W/ResourcesManager(17370): Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
        04-12 10:07:18.846: I/WebViewFactory(17370): Loading com.google.android.webview version 40 (1832189-arm) (code 424501)
        04-12 10:07:18.869: I/LibraryLoader(17370): Time to load native libraries: 3 ms (timestamps 5621-5624)
        04-12 10:07:18.869: I/LibraryLoader(17370): Expected native library version number "",actual native library version number ""
        04-12 10:07:18.875: V/WebViewChromiumFactoryProvider(17370): Binding Chromium to main looper Looper (main, tid 1) {28944cc5}
        04-12 10:07:18.876: I/LibraryLoader(17370): Expected native library version number "",actual native library version number ""
        04-12 10:07:18.876: I/chromium(17370): [INFO:library_loader_hooks.cc(108)] Chromium logging enabled: level = 0, default verbosity = 0
        04-12 10:07:18.883: I/BrowserStartupController(17370): Initializing chromium process, singleProcess=true
        04-12 10:07:18.884: W/art(17370): Attempt to remove local handle scope entry from IRT, ignoring
        04-12 10:07:18.892: W/chromium(17370): [WARNING:resource_bundle.cc(304)] locale_file_path.empty()
        04-12 10:07:18.892: W/AudioManagerAndroid(17370): Requires BLUETOOTH permission
        04-12 10:07:18.893: I/chromium(17370): [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=36 off=49196 len=3229
        04-12 10:07:18.894: I/chromium(17370): [INFO:aw_browser_main_parts.cc(76)] Loading webviewchromium.pak from, fd:37 off:390788 len:1143511
        04-12 10:07:18.899: I/Adreno-EGL(17370): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/14/15, ab0075f, Id3510ff6dc
        04-12 10:07:18.951: I/Ads(17370): Starting ad request.
        04-12 10:07:18.952: I/Ads(17370): Use AdRequest.Builder.addTestDevice("F9D483C5C3943E9EFDC31D1B4C183CF8") to get test ads on this device.
        04-12 10:07:18.961: D/OpenGLRenderer(17370): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
        04-12 10:07:18.967: D/Atlas(17370): Validating map...
        04-12 10:07:19.000: I/OpenGLRenderer(17370): Initialized EGL, version 1.4
        04-12 10:07:19.003: D/OpenGLRenderer(17370): Enabling debug mode 0
        04-12 10:07:19.050: I/Ads(17370): CsiReporterFactory: CSI is not enabled. No CSI reporter created.
        04-12 10:07:21.086: W/Ads(17370): There was a problem getting an ad response. ErrorCode: 0
        04-12 10:07:21.110: W/chromium(17370): [WARNING:data_reduction_proxy_settings.cc(328)] SPDY proxy OFF at startup
        04-12 10:07:21.120: W/art(17370): Attempt to remove local handle scope entry from IRT, ignoring
        04-12 10:07:21.124: W/AwContents(17370): onDetachedFromWindow called when already detached. Ignoring`enter code here`
        04-12 10:07:21.140: W/Ads(17370): Failed to load ad: 0


问:
Returning a list from an iterated object in Python
I need help creating a list of iterated values. In this example, I want to get all odd numbers in the range of x. Then make a list from it:

```<code>def x_list(x):
    for i in range(x):
        if x%2==0:
            return i
</code>```

Since return stops the function after iterating through the first object, I'm unable to get the rest of the values and create a list from it.
Could you advice what I should use instead of "return"?
Thank you.

答:
Define ret as a list at the top of the function, fill it within the loop.

After the loop ends, return it.

```<code>def x_list(x):
    ret = []
    for i in range(x):
        if i%2==0:
            ret.append(i)
    return ret
</code>```

Body:
I need help creating a list of iterated values. In this example, I want to get all odd numbers in the range of x. Then make a list from it:

def x_list(x):
    for i in range(x):
        if x%2==0:
            return i

Since return stops the function after iterating through the first object, I'm unable to get the rest of the values and create a list from it.
Could you advice what I should use instead of "return"?
Thank you.

Body:
Define ret as a list at the top of the function, fill it within the loop.

After the loop ends, return it.

def x_list(x):
    ret = []
    for i in range(x):
        if i%2==0:
            ret.append(i)
    return ret


问:
Use of $ operator
my question is regarding the $ operator for accessing a particular part of my dataframe.

Here below is my data frame

```<code>structure(list(Treatment = structure(c(11L, 11L, 11L, 11L, 11L,
11L), .Label = c("Chlora", "Gen", "Lin", "Metro", "Metro+Pen",
"Metro+Rif", "Metro+Rif+Pen", "Pen", "Pen+Rif", "Rif", "Untreated"
), class = "factor"), CDW = c(0.833, 0.867, 0.833, 2.7, 3.3,
3.133), Chlorophyll = c(1.098, 1.376, 1.64, 34.714, 37.773, 40.54
), EPS = c(0.092, 0.067, 0.092, 0.571, 0.591, 0.597), Day = c(0L,
0L, 0L, 10L, 10L, 10L), TreatmentDay = structure(c(21L, 21L,
21L, 22L, 22L, 22L), .Label = c("Chlora0", "Chlora10", "Gen0",
"Gen10", "Lin0", "Lin10", "Metro+Pen0", "Metro+Pen10", "Metro+Rif+Pen0",
"Metro+Rif+Pen10", "Metro+Rif0", "Metro+Rif10", "Metro0", "Metro10",
"Pen+Rif0", "Pen+Rif10", "Pen0", "Pen10", "Rif0", "Rif10", "Untreated0",
"Untreated10"), class = "factor"), richness = c(36L, 37L, 39L,
31L, 31L, 24L), shannon = c(3.35867443756547, 3.37354007038303,
3.43640985397324, 3.16018680691703, 3.15718684762791, 2.85288614815093
)), .Names = c("Treatment", "CDW", "Chlorophyll", "EPS", "Day",
"TreatmentDay", "richness", "shannon"), row.names = c("Day0F1",
"Day0F2", "Day0F3", "Day10F1", "Day10F2", "Day10F3"), class = "data.frame")
</code>```

I can use

```<code>Unt$richness
[1] 36 37 39 31 31 24
</code>```

But if I want to do an anova test, I get an error message saying I cannot use $ with atomic vectors

```<code>Unt_Richness_anova <- aov(Unt$richness, TreatmentDay)
</code>```

So, I find it confusing I can use $ operator in atomic vector in one instance but not for the other.
Can someone help out?

答:
From looking at the source code of the aov() function, it is actually a call to another function called terms() that is causing this error.

Now if the terms() function is called when the data frame is not specified within the aov() function, it seems that the terms() function will only take a formulae styled argument which is passed from the aov() function.

Notice that the following code does not work (as you specified):

```<code>Unt_Richness_anova <- aov(Unt$richness, Unt$TreatmentDay)
</code>```

If you express the two variables as a formula then everything works as it should:

```<code>Unt_Richness_anova <- aov(Unt$richness ~ Unt$TreatmentDay)
</code>```

So the problem is not with the $ operator but in fact with the terms() function. It seems the terms() function can only deal with separate variables if they belong to the same dataframe AND the dataframe is specified within the aov() function.

Why this is the case I cannot answer but hopefully someone else can shed some light?

Title: Use of $ operator

Body:
my question is regarding the $ operator for accessing a particular part of my dataframe.

Here below is my data frame

structure(list(Treatment = structure(c(11L, 11L, 11L, 11L, 11L,
11L), .Label = c("Chlora", "Gen", "Lin", "Metro", "Metro+Pen",
"Metro+Rif", "Metro+Rif+Pen", "Pen", "Pen+Rif", "Rif", "Untreated"
), class = "factor"), CDW = c(0.833, 0.867, 0.833, 2.7, 3.3,
3.133), Chlorophyll = c(1.098, 1.376, 1.64, 34.714, 37.773, 40.54
), EPS = c(0.092, 0.067, 0.092, 0.571, 0.591, 0.597), Day = c(0L,
0L, 0L, 10L, 10L, 10L), TreatmentDay = structure(c(21L, 21L,
21L, 22L, 22L, 22L), .Label = c("Chlora0", "Chlora10", "Gen0",
"Gen10", "Lin0", "Lin10", "Metro+Pen0", "Metro+Pen10", "Metro+Rif+Pen0",
"Metro+Rif+Pen10", "Metro+Rif0", "Metro+Rif10", "Metro0", "Metro10",
"Pen+Rif0", "Pen+Rif10", "Pen0", "Pen10", "Rif0", "Rif10", "Untreated0",
"Untreated10"), class = "factor"), richness = c(36L, 37L, 39L,
31L, 31L, 24L), shannon = c(3.35867443756547, 3.37354007038303,
3.43640985397324, 3.16018680691703, 3.15718684762791, 2.85288614815093
)), .Names = c("Treatment", "CDW", "Chlorophyll", "EPS", "Day",
"TreatmentDay", "richness", "shannon"), row.names = c("Day0F1",
"Day0F2", "Day0F3", "Day10F1", "Day10F2", "Day10F3"), class = "data.frame")

I can use

Unt$richness
[1] 36 37 39 31 31 24

But if I want to do an anova test, I get an error message saying I cannot use $ with atomic vectors

Unt_Richness_anova <- aov(Unt$richness, TreatmentDay)

So, I find it confusing I can use $ operator in atomic vector in one instance but not for the other.
Can someone help out?

Body:
From looking at the source code of the aov() function, it is actually a call to another function called terms() that is causing this error.

Now if the terms() function is called when the data frame is not specified within the aov() function, it seems that the terms() function will only take a formulae styled argument which is passed from the aov() function.

Notice that the following code does not work (as you specified):

Unt_Richness_anova <- aov(Unt$richness, Unt$TreatmentDay)

If you express the two variables as a formula then everything works as it should:

Unt_Richness_anova <- aov(Unt$richness ~ Unt$TreatmentDay)

So the problem is not with the $ operator but in fact with the terms() function. It seems the terms() function can only deal with separate variables if they belong to the same dataframe AND the dataframe is specified within the aov() function.

Why this is the case I cannot answer but hopefully someone else can shed some light?


问:
Is this a right way to check if Postgres Committed a Transaction id
In Postgresql, If the transaction id is "123456", table name is "table1" then am I right to execute the following query? :

```<code>Select count (*) from table1 where xmin=123456 OR xmax=123456
</code>```

if count returns value > 1, then can I assume that the transaction id is committed?

_

Note:

Transaction id is sent from a different java program to another java
program via RMI (OR) TCP Sockets (OR) File (OR) some other mechanism

Transaction id is gathered from an after update,insert,delete
trigger

Vacuum or any other maintenance procedures are not performed during these operations

Don't worry about txid wraparound issue either

When using oracle, the v$transaction came to the rescue... but in Postgres, I couldn't find anything similar...
Though some googling led me to believe there are ways to find it using the "pg_log" file or the "pg_locks" view but I couldn't figure out how

Only dirty way I could think of is the xmin and xmax... I couldn't even tell whether it's a dirty method for that matter

are there any Postgresql Sensei who can lead me in the right direction?

Updates:

For postgresql 9.5 and later, "laurenz albe"'s answer is perfect...
For those who use Postgresql 9.0 to 9.3, you should use,

```<code>SELECT count(xmin) as SIZE FROM table1 WHERE xmin = 123456 AND xmax = 0
</code>```

Also When a Delete operation happens and you get a transaction id, we need to check it the different way...

```<code>SELECT count(xmin) as SIZE FROM table1 WHERE xmin = 123456 OR xmax = 123456
</code>```

then check the result. if it returns zero, then the delete operation is committed... if result is non-zero then the transaction is rolled back and you need not worry about the uncommitted transaction

Note:
This is to check if the transaction id received from a trigger and sent to another external program(java) has been committed and not rolled back and the database session is different...

答:
The test for xmax is wrong.

xmax gets set when a row version (a tuple in PostgreSQL) is marked as invalid by an UPDATE or DELETE. It means that no transaction with a later transaction ID can see this tuple, and it can be reclaimed as soon as nobody can see it any more.

If a transaction is rolled back, the value of xmax is not reset – the transaction status is stored in the commit log, and the tuple remains visible to others.

But xmax is also used to store row locks.

So if you can see a tuple where xmax = '123456', it means one of the following:

The tuple was deleted or updated and the transaction was committed, but your transaction snapshot is older, so you still see the old tuple.

The tuple was deleted or updated and the transaction was rolled back.

The tuple was locked by transaction 123456, e.g. with a SELECT ... FOR UPDATE.

On the other hand, if you see a tuple with xmin = '123456' and that is not your current transaction, you can be certain that this transaction is committed.

So your test should be

```<code>SELECT count(*) FROM table1 WHERE xmin='123456';
</code>```

But that is a terrible query. It forces a sequential scan over the whole table, and indexes on system columns are not allowed.

If you are using PostgreSQL 9.5 or newer, consider activating track_commit_timestamp and using the function pg_xact_commit_timestamp(xid). It will return NULL for transactions that are not committed.

Body:
In Postgresql, If the transaction id is "123456", table name is "table1" then am I right to execute the following query? :

Select count (*) from table1 where xmin=123456 OR xmax=123456

if count returns value > 1, then can I assume that the transaction id is committed?

_

Note:

Transaction id is sent from a different java program to another java
program via RMI (OR) TCP Sockets (OR) File (OR) some other mechanism

Transaction id is gathered from an after update,insert,delete
trigger

Vacuum or any other maintenance procedures are not performed during these operations

Don't worry about txid wraparound issue either

When using oracle, the v$transaction came to the rescue... but in Postgres, I couldn't find anything similar...
Though some googling led me to believe there are ways to find it using the "pg_log" file or the "pg_locks" view but I couldn't figure out how

Only dirty way I could think of is the xmin and xmax... I couldn't even tell whether it's a dirty method for that matter

are there any Postgresql Sensei who can lead me in the right direction?

Updates:

For postgresql 9.5 and later, "laurenz albe"'s answer is perfect...
For those who use Postgresql 9.0 to 9.3, you should use,

SELECT count(xmin) as SIZE FROM table1 WHERE xmin = 123456 AND xmax = 0

Also When a Delete operation happens and you get a transaction id, we need to check it the different way...

SELECT count(xmin) as SIZE FROM table1 WHERE xmin = 123456 OR xmax = 123456

then check the result. if it returns zero, then the delete operation is committed... if result is non-zero then the transaction is rolled back and you need not worry about the uncommitted transaction

Note:
This is to check if the transaction id received from a trigger and sent to another external program(java) has been committed and not rolled back and the database session is different...

Body:
The test for xmax is wrong.

xmax gets set when a row version (a tuple in PostgreSQL) is marked as invalid by an UPDATE or DELETE. It means that no transaction with a later transaction ID can see this tuple, and it can be reclaimed as soon as nobody can see it any more.

If a transaction is rolled back, the value of xmax is not reset – the transaction status is stored in the commit log, and the tuple remains visible to others.

But xmax is also used to store row locks.

So if you can see a tuple where xmax = '123456', it means one of the following:

The tuple was deleted or updated and the transaction was committed, but your transaction snapshot is older, so you still see the old tuple.

The tuple was deleted or updated and the transaction was rolled back.

The tuple was locked by transaction 123456, e.g. with a SELECT ... FOR UPDATE.

On the other hand, if you see a tuple with xmin = '123456' and that is not your current transaction, you can be certain that this transaction is committed.

So your test should be

SELECT count(*) FROM table1 WHERE xmin='123456';

But that is a terrible query. It forces a sequential scan over the whole table, and indexes on system columns are not allowed.

If you are using PostgreSQL 9.5 or newer, consider activating track_commit_timestamp and using the function pg_xact_commit_timestamp(xid). It will return NULL for transactions that are not committed.


问:
Make exception to smooth scrolling script
I'm using this script to make smooth scrolling on a page with a lot of anchors.
But when I'm adding Bootstrap's accordions, they don't work (they don't collapse/expand) due to this script.

How can I make some adjustments to the script, so that it doesn't collide with the accordions collapsing/expanding?

$('a[href*="#"]').click(function() {
  if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
    var target = $(this.hash);
    target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
    if (target.length) {
      $('html, body').animate({
        scrollTop: target.offset().top
      }, 500);
      return false;
    }
  }
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<div id="stats" role="tablist" aria-multiselectable="true">
  <div class="card stats">
    <h4 class="card-header" role="tab" id="statsHeading">
      Header</h4>
    <div id="collapseStats" class="collapse" role="tabpanel" aria-labelledby="statsHeading">
      <div class="card-block">
        Content...
      </div>
    </div>
  </div>
</div></code>```

Fiddle here.

答:
Update your html code with my code and problem will solve. please check and confirm. Here I just make changes in  tag if you check my code and I hope then you understand what is the issue :)   </p>

```<code>    <div id="stats" role="tablist" aria-multiselectable="true">
  <div class="card stats">
    <h4 class="card-header" role="tab" id="statsHeading">
      <a data-toggle="collapse" data-parent="#stats" href="javascript:void(0)" data-target="#collapseStats" aria-expanded="false">Header</a></h4>
    <div id="collapseStats" class="collapse" role="tabpanel" aria-labelledby="statsHeading">
      <div class="card-block">
        Content...
      </div>
    </div>
  </div>
</div>
</code>```

Body:
I'm using this script to make smooth scrolling on a page with a lot of anchors.
But when I'm adding Bootstrap's accordions, they don't work (they don't collapse/expand) due to this script.

How can I make some adjustments to the script, so that it doesn't collide with the accordions collapsing/expanding?

$('a[href*="#"]').click(function() {
  if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
    var target = $(this.hash);
    target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
    if (target.length) {
      $('html, body').animate({
        scrollTop: target.offset().top
      }, 500);
      return false;
    }
  }
});

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />

      Header

        Content...

Fiddle here.

Body:
Update your html code with my code and problem will solve. please check and confirm. Here I just make changes in  tag if you check my code and I hope then you understand what is the issue :)

    <div id="stats" role="tablist" aria-multiselectable="true">
  <div class="card stats">
    <h4 class="card-header" role="tab" id="statsHeading">
      <a data-toggle="collapse" data-parent="#stats" href="javascript:void(0)" data-target="#collapseStats" aria-expanded="false">Header</a></h4>
    <div id="collapseStats" class="collapse" role="tabpanel" aria-labelledby="statsHeading">
      <div class="card-block">
        Content...
      </div>
    </div>
  </div>
</div>


问:
Custom setter/willSet for Realm Object
Whenever I set a property of a Realm object I want to trigger the change of an other object that represents the object on my remote backend.

I was wondering if this is still the best practice recommended:

https://github.com/realm/realm-cocoa/issues/870#issuecomment-54543539

What I was trying to do, but doesn't work because it interferes with Realm:

```<code>dynamic var name: String = "" {
    willSet(newValue) {
        self.name = newValue
        self.widgetRemote?.name = newValue
    }
}
</code>```

答:
bdash's version in objc:

```<code>+(NSArray<NSString *> *)ignoredProperties
{
    return @[ @"name" ];
}
</code>```

see the answer bdash's swiftly provided to obtain more context on backing store exampt from persistence into realm store

Title: Custom setter/willSet for Realm Object

Body:
Whenever I set a property of a Realm object I want to trigger the change of an other object that represents the object on my remote backend.

I was wondering if this is still the best practice recommended:

https://github.com/realm/realm-cocoa/issues/870#issuecomment-54543539

What I was trying to do, but doesn't work because it interferes with Realm:

dynamic var name: String = "" {
    willSet(newValue) {
        self.name = newValue
        self.widgetRemote?.name = newValue
    }
}

Body:
bdash's version in objc:

+(NSArray<NSString *> *)ignoredProperties
{
    return @[ @"name" ];
}

see the answer bdash's swiftly provided to obtain more context on backing store exampt from persistence into realm store


问:
Split table into different level columns
I have got a requirement to split the data based on the level into 3 different columns. In the below table SU_DC_1 is the top level based on SETTLEUNIT column   I need to add the level.

Parent : TOPSETTLUNIT
Child  : SETTLEUNIT

Based on Child I need to create 3 additional columns

In the above hierarchy is mentioned as

Output:

I am finding it difficult to write the query for it. Could you please help .

答:
Something like:</p>

```<code>SELECT topsettlunit,
       settleunit,
       CONNECT_BY_ROOT( topsettlunit ) AS level1,
       CASE LEVEL
         WHEN 1 THEN settleunit
         WHEN 2 THEN topsettlunit
       END AS level2,
       CASE LEVEL
         WHEN 2 THEN settleunit
       END AS level3
FROM   your_table
START WITH topsettlunit NOT IN ( SELECT settleunit FROM your_table )
CONNECT BY PRIOR settleunit = topsettlunit;
</code>```

Body:
Something like:

SELECT topsettlunit,
       settleunit,
       CONNECT_BY_ROOT( topsettlunit ) AS level1,
       CASE LEVEL
         WHEN 1 THEN settleunit
         WHEN 2 THEN topsettlunit
       END AS level2,
       CASE LEVEL
         WHEN 2 THEN settleunit
       END AS level3
FROM   your_table
START WITH topsettlunit NOT IN ( SELECT settleunit FROM your_table )
CONNECT BY PRIOR settleunit = topsettlunit;


答:
If you use yield instead of return, then you should be able to iterate through the whole range. This example will print out the even numbers.

```<code>def x_list(x):
    for i in range(x):
        if i%2==1:
            yield i

for n in x_list(10):
    print(n)
</code>```

I also assume you want if i%2==1: not if x%2==0:, otherwise you'll get every number instead of just the odd ones.

Based on hop's suggestion, you could also do this:

```<code>evens = range(0, 10, 2)

for n in evens:
    print(n)
</code>```

Where the 3rd parameter in range is the step size

Title: Returning a list from an iterated object in Python

Body:
If you use yield instead of return, then you should be able to iterate through the whole range. This example will print out the even numbers.

def x_list(x):
    for i in range(x):
        if i%2==1:
            yield i

for n in x_list(10):
    print(n)

I also assume you want if i%2==1: not if x%2==0:, otherwise you'll get every number instead of just the odd ones.

Based on hop's suggestion, you could also do this:

evens = range(0, 10, 2)

for n in evens:
    print(n)

Where the 3rd parameter in range is the step size