问:
Tkinter - Images is not display
I am  new on Tkinter. I was trying to display two images on my canvas but I couldn't. I tried to achieve this by creating two different files. One will contain all logic behind and the other one will handle the gui. Here is my code so far:

file1.py

```<code>from file2 import *

import tkinter as tk

import random

# global variables
w = 'initial'

class start_gui(tk.Frame):

    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self,parent, *args, **kwargs)
        # create canvas
        self.canvas = tk.Canvas(parent, width=800, height=800, background="green")
        self.canvas.pack()

        c = Display(self.canvas)
        c.current_play(w)

    if __name__ == "__main__":
      # create main window
      root = tk.Tk()
      root.geometry("800x800")
      start_gui(root)
      root.mainloop()
</code>```

file2.py

```<code>import tkinter as tk
from functools import partial
from PIL import ImageTk
from PIL import Image

class Display:

    def __init__(self, canv):
        self.canvas = canv

    def current_play(self, option):
        if (option == 'initial'):
            self.initial_display()
        elif (option == 'n' or option == 's'):
            self.ns_display()

    def initial_display(self):
        # display cat image
        self.im = Image.open("cat.gif")
        self.photo_image = ImageTk.PhotoImage(self.im)
        self.demo = self.canvas.create_image(400, 400, image=self.photo_image, anchor='center')

        self.canvas.create_rectangle(50, 25, 150, 75, fill="blue")

        self.temp_image = tk.PhotoImage(file="cat.gif")
        self.demo2 = self. canvas.create_image(600, 600, image =  self.temp_image, anchor='center')
</code>```

The problem here is that the two image items I created do not show up on the canvas but only the rectangle. Can someone help me with this?

PS: I am using python v 3.4

答:
The problem is one of garbage collection. Your Display object is stored in a local variable inside start_gui.__init__. Once start_gui is constructed, this object is thrown away. The image is an attribute of that object, so it gets garbage-collected. When an image object gets garbage-collected, tkinter is unable to display it.

The simple solution is to keep a permanent reference to Display:

```<code>self.display = Display(canvas)
self.display.current_play(w)
</code>```

Title: Tkinter - Images is not display

Body:
I am  new on Tkinter. I was trying to display two images on my canvas but I couldn't. I tried to achieve this by creating two different files. One will contain all logic behind and the other one will handle the gui. Here is my code so far:

file1.py

from file2 import *

import tkinter as tk

import random

# global variables
w = 'initial'

class start_gui(tk.Frame):

    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self,parent, *args, **kwargs)
        # create canvas
        self.canvas = tk.Canvas(parent, width=800, height=800, background="green")
        self.canvas.pack()

        c = Display(self.canvas)
        c.current_play(w)

    if __name__ == "__main__":
      # create main window
      root = tk.Tk()
      root.geometry("800x800")
      start_gui(root)
      root.mainloop()

file2.py

import tkinter as tk
from functools import partial
from PIL import ImageTk
from PIL import Image

class Display:

    def __init__(self, canv):
        self.canvas = canv

    def current_play(self, option):
        if (option == 'initial'):
            self.initial_display()
        elif (option == 'n' or option == 's'):
            self.ns_display()

    def initial_display(self):
        # display cat image
        self.im = Image.open("cat.gif")
        self.photo_image = ImageTk.PhotoImage(self.im)
        self.demo = self.canvas.create_image(400, 400, image=self.photo_image, anchor='center')

        self.canvas.create_rectangle(50, 25, 150, 75, fill="blue")

        self.temp_image = tk.PhotoImage(file="cat.gif")
        self.demo2 = self. canvas.create_image(600, 600, image =  self.temp_image, anchor='center')

The problem here is that the two image items I created do not show up on the canvas but only the rectangle. Can someone help me with this?

PS: I am using python v 3.4

Body:
The problem is one of garbage collection. Your Display object is stored in a local variable inside start_gui.__init__. Once start_gui is constructed, this object is thrown away. The image is an attribute of that object, so it gets garbage-collected. When an image object gets garbage-collected, tkinter is unable to display it.

The simple solution is to keep a permanent reference to Display:

self.display = Display(canvas)
self.display.current_play(w)


来源: stackexchange

问:
spring cron for running every hour at 35th minute
I have a job that is scheduled to run every hour and I am using spring cron (0 0/35 * * * ). I am expecting the job to run at the 35th minute every hour but I noticed that the job gets triggered at the 35th minute and also at top of the hour. I am not sure why, any suggestions?

Thanks,
Karthik

答: Your cron expression is incorrect, so change it to 0 */35 * * * which runs only for every 35 minutes

ContentLicense: CC BY-SA 3.0


答:
I think your fields are out of order. The Spring Cron documenation seems to say that Spring uses standard cron expressions. https://crontab.guru is a good tool for checking cron expressions.

https://crontab.guru/#0_0/35___* shows

“At minute 0 past every 35th hour from 0 through 23.”

Whereas https://crontab.guru/#35____ shows

“At minute 35.”

I think you need to use 35 * * * *

Title: spring cron for running every hour at 35th minute

Body:
I have a job that is scheduled to run every hour and I am using spring cron (0 0/35 * * * ). I am expecting the job to run at the 35th minute every hour but I noticed that the job gets triggered at the 35th minute and also at top of the hour. I am not sure why, any suggestions?

Thanks,
Karthik


答: According to the Spring CronSequenceGenerator docs, the /35 in 0 0/35 * * * effectively means "every minute that's a multiple of 35", which includes 0 - if you only want it to trigger at 35 minutes after each hour, just use 0 35 * * * * (which includes all 6 parameters it wants).


问:
Out of memory error when writing out spark dataframes to parquet format
I'm trying to query data from a database, do some transformations on it and save the new data in parquet format on hdfs.

Since the database query returns a large number of rows, I'm getting the data in batches and running the above process on every incoming batch.

UPDATE 2: The batch processing logic is:

```<code>import scala.collection.JavaConverters._

import org.apache.spark.SparkContext
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.Row
import org.apache.spark.sql.types.{StructType, StructField, StringType}

class Batch(rows: List[String],
            sqlContext: SQLContext) {

      // The actual schema has around 60 fields
      val schema = Array("name", "age", "address").map(field =>
                       StructField(field, StringType, true)
                   )

      val transformedRows = rows.map(rows => {

              // transformation logic (returns Array[Array[String]] type)

          }).map(row => Row.fromSeq(row.toSeq))

      val dataframe = sqlContext.createDataFrame(transformedRows.asJava, schema)

}

val sparkConf = new sparkConf().setAppName("Spark App")
val sparkContext = new SparkContext(sparkConf)
val sqlContext = new SQLContext(sparkContext)

// Code to query database
// queryResponse is essentially an iterator that fetches the next batch on calling queryResponse.next

var batch_num = 0

while (queryResponse.hasNext) {
    val batch = queryResponse.next

    val batchToSave = new Batch(
                          batch.toList.map(_.getDocument.toString),
                          sqlContext)

    batchToSave.dataframe.write.parquet(batch_num + "_Parquet")

    batch_num += 1

}
</code>```

My Spark version in 1.6.1 and the spark-submit is:

```<code>spark-submit target/scala-2.10/Spark\ Application-assembly-1.0.jar
</code>```

The problem is that after a certain number of batches, I get a java.lang.OutOfMemoryError error.

The entire stacktrace is:

```<code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOfRange(Arrays.java:2694)
    at java.lang.String.<init>(String.java:203)
    at java.lang.StringBuilder.toString(StringBuilder.java:405)
    at scala.StringContext.standardInterpolator(StringContext.scala:125)
    at scala.StringContext.s(StringContext.scala:90)
    at org.apache.spark.sql.execution.QueryExecution.toString(QueryExecution.scala:70)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:52)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation.run(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult$lzycompute(commands.scala:58)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult(commands.scala:56)
    at org.apache.spark.sql.execution.ExecutedCommand.doExecute(commands.scala:70)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:132)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:130)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
    at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:130)
    at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:256)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:148)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:139)
    at org.apache.spark.sql.DataFrameWriter.parquet(DataFrameWriter.scala:334)
    at app.Application$.main(App.scala:156)
    at app.Application.main(App.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
</code>```

I tried coalescing the data into a single partition but that didn't make any difference.

```<code>dataframe.coalesce(1).write.parquet(batch_num + "_Parquet")
</code>```

Any help would be appreciated.

UPDATE 1

Not doing a coalesce transform on the RDD still gives an error but the stacktrace is as follows. Seems to be an issue with Parquet.

```<code>Driver stacktrace:
    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1431)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1419)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1418)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1418)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:799)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:799)
    at scala.Option.foreach(Option.scala:236)
    at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:799)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1640)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1599)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1588)
    at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
    at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:620)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1855)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1868)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1945)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1.apply$mcV$sp(InsertIntoHadoopFsRelation.scala:150)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1.apply(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1.apply(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:56)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation.run(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult$lzycompute(commands.scala:58)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult(commands.scala:56)
    at org.apache.spark.sql.execution.ExecutedCommand.doExecute(commands.scala:70)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:132)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:130)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
    at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:130)
    at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:256)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:148)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:139)
    at org.apache.spark.sql.DataFrameWriter.parquet(DataFrameWriter.scala:334)
    at app.Application$.main(App.scala:156)
    at app.Application.main(App.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.OutOfMemoryError: Java heap space
    at org.apache.parquet.column.values.dictionary.IntList.initSlab(IntList.java:90)
    at org.apache.parquet.column.values.dictionary.IntList.<init>(IntList.java:86)
    at org.apache.parquet.column.values.dictionary.DictionaryValuesWriter.<init>(DictionaryValuesWriter.java:93)
    at org.apache.parquet.column.values.dictionary.DictionaryValuesWriter$PlainBinaryDictionaryValuesWriter.<init>(DictionaryValuesWriter.java:229)
    at org.apache.parquet.column.ParquetProperties.dictionaryWriter(ParquetProperties.java:131)
    at org.apache.parquet.column.ParquetProperties.dictWriterWithFallBack(ParquetProperties.java:178)
    at org.apache.parquet.column.ParquetProperties.getValuesWriter(ParquetProperties.java:203)
    at org.apache.parquet.column.impl.ColumnWriterV1.<init>(ColumnWriterV1.java:83)
    at org.apache.parquet.column.impl.ColumnWriteStoreV1.newMemColumn(ColumnWriteStoreV1.java:68)
    at org.apache.parquet.column.impl.ColumnWriteStoreV1.getColumnWriter(ColumnWriteStoreV1.java:56)
    at org.apache.parquet.io.MessageColumnIO$MessageColumnIORecordConsumer.<init>(MessageColumnIO.java:183)
    at org.apache.parquet.io.MessageColumnIO.getRecordWriter(MessageColumnIO.java:375)
    at org.apache.parquet.hadoop.InternalParquetRecordWriter.initStore(InternalParquetRecordWriter.java:109)
    at org.apache.parquet.hadoop.InternalParquetRecordWriter.<init>(InternalParquetRecordWriter.java:99)
    at org.apache.parquet.hadoop.ParquetRecordWriter.<init>(ParquetRecordWriter.java:100)
    at org.apache.parquet.hadoop.ParquetOutputFormat.getRecordWriter(ParquetOutputFormat.java:303)
    at org.apache.parquet.hadoop.ParquetOutputFormat.getRecordWriter(ParquetOutputFormat.java:262)
    at org.apache.spark.sql.execution.datasources.parquet.ParquetOutputWriter.<init>(ParquetRelation.scala:94)
    at org.apache.spark.sql.execution.datasources.parquet.ParquetRelation$$anon$3.newInstance(ParquetRelation.scala:286)
    at org.apache.spark.sql.execution.datasources.BaseWriterContainer.newOutputWriter(WriterContainer.scala:129)
    at org.apache.spark.sql.execution.datasources.DefaultWriterContainer.writeRows(WriterContainer.scala:255)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1$$anonfun$apply$mcV$sp$3.apply(InsertIntoHadoopFsRelation.scala:150)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1$$anonfun$apply$mcV$sp$3.apply(InsertIntoHadoopFsRelation.scala:150)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
    at org.apache.spark.scheduler.Task.run(Task.scala:89)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
</code>```

答:
Had the same problem today as well. Turned out my execution plan was rather complex and toString generated 150 MB of information which combined with String interpolation of Scala lead to the driver running out of memory.

You can try to increase the driver memory (I had to double it from 8 GB to 16 GB).

Body:
I'm trying to query data from a database, do some transformations on it and save the new data in parquet format on hdfs.

Since the database query returns a large number of rows, I'm getting the data in batches and running the above process on every incoming batch.

UPDATE 2: The batch processing logic is:

import scala.collection.JavaConverters._

import org.apache.spark.SparkContext
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.Row
import org.apache.spark.sql.types.{StructType, StructField, StringType}

class Batch(rows: List[String],
            sqlContext: SQLContext) {

      // The actual schema has around 60 fields
      val schema = Array("name", "age", "address").map(field =>
                       StructField(field, StringType, true)
                   )

      val transformedRows = rows.map(rows => {

              // transformation logic (returns Array[Array[String]] type)

          }).map(row => Row.fromSeq(row.toSeq))

      val dataframe = sqlContext.createDataFrame(transformedRows.asJava, schema)

}

val sparkConf = new sparkConf().setAppName("Spark App")
val sparkContext = new SparkContext(sparkConf)
val sqlContext = new SQLContext(sparkContext)

// Code to query database
// queryResponse is essentially an iterator that fetches the next batch on calling queryResponse.next

var batch_num = 0

while (queryResponse.hasNext) {
    val batch = queryResponse.next

    val batchToSave = new Batch(
                          batch.toList.map(_.getDocument.toString),
                          sqlContext)

    batchToSave.dataframe.write.parquet(batch_num + "_Parquet")

    batch_num += 1

}

My Spark version in 1.6.1 and the spark-submit is:

spark-submit target/scala-2.10/Spark\ Application-assembly-1.0.jar

The problem is that after a certain number of batches, I get a java.lang.OutOfMemoryError error.

The entire stacktrace is:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOfRange(Arrays.java:2694)
    at java.lang.String.<init>(String.java:203)
    at java.lang.StringBuilder.toString(StringBuilder.java:405)
    at scala.StringContext.standardInterpolator(StringContext.scala:125)
    at scala.StringContext.s(StringContext.scala:90)
    at org.apache.spark.sql.execution.QueryExecution.toString(QueryExecution.scala:70)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:52)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation.run(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult$lzycompute(commands.scala:58)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult(commands.scala:56)
    at org.apache.spark.sql.execution.ExecutedCommand.doExecute(commands.scala:70)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:132)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:130)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
    at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:130)
    at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:256)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:148)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:139)
    at org.apache.spark.sql.DataFrameWriter.parquet(DataFrameWriter.scala:334)
    at app.Application$.main(App.scala:156)
    at app.Application.main(App.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

I tried coalescing the data into a single partition but that didn't make any difference.

dataframe.coalesce(1).write.parquet(batch_num + "_Parquet")

Any help would be appreciated.

UPDATE 1

Not doing a coalesce transform on the RDD still gives an error but the stacktrace is as follows. Seems to be an issue with Parquet.

Driver stacktrace:
    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1431)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1419)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1418)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1418)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:799)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:799)
    at scala.Option.foreach(Option.scala:236)
    at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:799)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1640)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1599)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1588)
    at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
    at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:620)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1855)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1868)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1945)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1.apply$mcV$sp(InsertIntoHadoopFsRelation.scala:150)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1.apply(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1.apply(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:56)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation.run(InsertIntoHadoopFsRelation.scala:108)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult$lzycompute(commands.scala:58)
    at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult(commands.scala:56)
    at org.apache.spark.sql.execution.ExecutedCommand.doExecute(commands.scala:70)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:132)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:130)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
    at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:130)
    at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:55)
    at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:256)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:148)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:139)
    at org.apache.spark.sql.DataFrameWriter.parquet(DataFrameWriter.scala:334)
    at app.Application$.main(App.scala:156)
    at app.Application.main(App.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.OutOfMemoryError: Java heap space
    at org.apache.parquet.column.values.dictionary.IntList.initSlab(IntList.java:90)
    at org.apache.parquet.column.values.dictionary.IntList.<init>(IntList.java:86)
    at org.apache.parquet.column.values.dictionary.DictionaryValuesWriter.<init>(DictionaryValuesWriter.java:93)
    at org.apache.parquet.column.values.dictionary.DictionaryValuesWriter$PlainBinaryDictionaryValuesWriter.<init>(DictionaryValuesWriter.java:229)
    at org.apache.parquet.column.ParquetProperties.dictionaryWriter(ParquetProperties.java:131)
    at org.apache.parquet.column.ParquetProperties.dictWriterWithFallBack(ParquetProperties.java:178)
    at org.apache.parquet.column.ParquetProperties.getValuesWriter(ParquetProperties.java:203)
    at org.apache.parquet.column.impl.ColumnWriterV1.<init>(ColumnWriterV1.java:83)
    at org.apache.parquet.column.impl.ColumnWriteStoreV1.newMemColumn(ColumnWriteStoreV1.java:68)
    at org.apache.parquet.column.impl.ColumnWriteStoreV1.getColumnWriter(ColumnWriteStoreV1.java:56)
    at org.apache.parquet.io.MessageColumnIO$MessageColumnIORecordConsumer.<init>(MessageColumnIO.java:183)
    at org.apache.parquet.io.MessageColumnIO.getRecordWriter(MessageColumnIO.java:375)
    at org.apache.parquet.hadoop.InternalParquetRecordWriter.initStore(InternalParquetRecordWriter.java:109)
    at org.apache.parquet.hadoop.InternalParquetRecordWriter.<init>(InternalParquetRecordWriter.java:99)
    at org.apache.parquet.hadoop.ParquetRecordWriter.<init>(ParquetRecordWriter.java:100)
    at org.apache.parquet.hadoop.ParquetOutputFormat.getRecordWriter(ParquetOutputFormat.java:303)
    at org.apache.parquet.hadoop.ParquetOutputFormat.getRecordWriter(ParquetOutputFormat.java:262)
    at org.apache.spark.sql.execution.datasources.parquet.ParquetOutputWriter.<init>(ParquetRelation.scala:94)
    at org.apache.spark.sql.execution.datasources.parquet.ParquetRelation$$anon$3.newInstance(ParquetRelation.scala:286)
    at org.apache.spark.sql.execution.datasources.BaseWriterContainer.newOutputWriter(WriterContainer.scala:129)
    at org.apache.spark.sql.execution.datasources.DefaultWriterContainer.writeRows(WriterContainer.scala:255)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1$$anonfun$apply$mcV$sp$3.apply(InsertIntoHadoopFsRelation.scala:150)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelation$$anonfun$run$1$$anonfun$apply$mcV$sp$3.apply(InsertIntoHadoopFsRelation.scala:150)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
    at org.apache.spark.scheduler.Task.run(Task.scala:89)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)


问:
Getting Leaflet marker click event to work with Angular 2
When displaying leaflet on an Angular2 app the click bind to the marker does not get triggered on a mouse click.

```<code>  let el = this._elementRef.nativeElement.querySelector('.leaflet-maps');
  L.Icon.Default.imagePath = 'assets/img/theme/vendor/leaflet';

  this.map = new L.Map('map', {
    center: new L.LatLng(26.166314, -81.706957), zoom: 15});
  var osm=   L.tileLayer('http://ip/{z}/{x}/{y}.png',  { maxZoom: 18 }).addTo(this.map);
  var d= L.marker([26.166314, -81.706957], { icon: this.icons.online, clickable: true }).on('click',
    (data) => {
      alert("I have a click.")
    } ).addTo(this.map)
</code>```

I can add a click event on the map and it works fine but a click event on the marker does not seem to work.

答:
Make sure your code for instantiating your marker is correct, especially the icon this.icons.online.

Once the icon is removed, everything works as expected: https://plnkr.co/edit/NdKpe8BeoidYQCnxBsKS?p=preview

Body:
When displaying leaflet on an Angular2 app the click bind to the marker does not get triggered on a mouse click.

  let el = this._elementRef.nativeElement.querySelector('.leaflet-maps');
  L.Icon.Default.imagePath = 'assets/img/theme/vendor/leaflet';

  this.map = new L.Map('map', {
    center: new L.LatLng(26.166314, -81.706957), zoom: 15});
  var osm=   L.tileLayer('http://ip/{z}/{x}/{y}.png',  { maxZoom: 18 }).addTo(this.map);
  var d= L.marker([26.166314, -81.706957], { icon: this.icons.online, clickable: true }).on('click',
    (data) => {
      alert("I have a click.")
    } ).addTo(this.map)

I can add a click event on the map and it works fine but a click event on the marker does not seem to work.


问:
Problems adding, deleting and unchecking Categories Wordpress
I've come across a strange bug in my WordPress admin. The problem manifests itself as follows:

If I try to add a new category nothing happens when I press
"Add new category" button, but when I refresh the page the category
HAS been created. I can see the Ajax call being made (see below) but
there's no automatic page refresh.

There's a similar issue if I attempt to delete a category from this page, the category turns red, fades off but then just re-appears, however, if I refresh manually it HAS been deleted.

The third and final issue is the most problematic one. From within a post I am unable to "un-    check" a category. If I un-check a category and click "update post" the category is still checked, no manual refresh helps in this case. I can see the admin-ajax.php being called in the console but nothing happens.

I've been looking in the Console and can't see any errors, I can see the following call being made:

XHR finished loading: POST "https://mywebsite.com/wp-admin/admin-ajax.php".
VM8964 load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,underscore,backbone,utils&ver=4.1:4

I'm not 100% sure when this issue occurred but updated WP to 4.1 recently but can't say for sure that it occurred after the update.

I've tried switching off all plug-ins but this makes no difference and it's worth noting that I have the same issue when it comes to other custom types/taxonomies.

Also worth noting that I run WPML (multilingual) on the site.

From what I gather there seems to be something wrong with the Ajax/Jquery calls but I'm not particularly familiar with how the admin works so I'm not sure how to proceed from here.

Thanks,
Mikael

UPDATE:

Today I managed to get an error message out of the Chrome console, it seems to be related to jQuery:

FURTHER UPDATE:

I tried switching off my theme and it looks like that is the perpetrator that said, I can't for the love of god figure out what might be causing it the problem within my theme.

I assumed that the problem was within the functions.php file, however  after deleting every single line of code in the functions.php file the problem still persists. However, if I physically delete the function.php file off the server everything starts working again...I am confused like hell, anyone got any idea what's going on here?

Mikael

答:
Mikael!

I was solve this problem

Actually I have some spaces after ?> in my functions.php
Check your functions.php and remove spaces or something before <?php and after ?>.

It helps me. Hope it helps you.


问:
Removing Tab Indicator from ViewPager
I have a ViewPager that contains multiple tabs. There is a tab indicator at the top of the screen (the black strip in the following picture). How do I disable the tab indicator?

Here's the code if needed:

```<code>    // ViewPager
ViewPager pager;
TeamTabAdapter tabAdapter;

REvent event;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.Backup);
    setContentView(R.layout.activity_team_viewer);

    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getApplicationContext(), R.color.actionbar)));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    event = (REvent) getIntent().getSerializableExtra("event");
    RTeam team = (RTeam) getIntent().getSerializableExtra("team");
    RForm form = new Loader(getApplicationContext()).loadForm(event.getID());

    tabAdapter = new TeamTabAdapter(getSupportFragmentManager(), event, team, form);
    pager = (ViewPager) findViewById(R.id.pager);

    pager.addOnPageChangeListener(this);

    pager.setAdapter(tabAdapter);
    pager.setCurrentItem(1);
}
</code>```

答:
I am not quite sure . But try adding transparent color like below in your TabLayout tag in xml</p>

```<code>app:tabIndicatorColor="@android:color/transparent"
</code>```

Title: Removing Tab Indicator from ViewPager

Body:
I have a ViewPager that contains multiple tabs. There is a tab indicator at the top of the screen (the black strip in the following picture). How do I disable the tab indicator?

Here's the code if needed:

    // ViewPager
ViewPager pager;
TeamTabAdapter tabAdapter;

REvent event;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.Backup);
    setContentView(R.layout.activity_team_viewer);

    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getApplicationContext(), R.color.actionbar)));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    event = (REvent) getIntent().getSerializableExtra("event");
    RTeam team = (RTeam) getIntent().getSerializableExtra("team");
    RForm form = new Loader(getApplicationContext()).loadForm(event.getID());

    tabAdapter = new TeamTabAdapter(getSupportFragmentManager(), event, team, form);
    pager = (ViewPager) findViewById(R.id.pager);

    pager.addOnPageChangeListener(this);

    pager.setAdapter(tabAdapter);
    pager.setCurrentItem(1);
}

Body:
I am not quite sure . But try adding transparent color like below in your TabLayout tag in xml

app:tabIndicatorColor="@android:color/transparent"


问:
Efficiently handling python processes
So for my project I have to get a list of genes and clean it from synonyms ex. gene A might also be known as AA, so if in my original list there is AA and A I have to delete one of the two.

The list of genes is provided by the user, and I read the synonyms from a text file.

Both are stored in dictionaries.

The list is huuuuuge (Trump joke) and I will have to call this function, many times in my pipeline. So my question is: Can I multiprocess this to make it faster?

My initial approach was as follows:

```<code>for g in genes:
    process = multiprocessing.Process(target = fixReoccurences, args =  (g, genes, synonyms, replaced, ))
    my_processes.append(process)
    process.start()

# Wait for *ALL* the processes to finish.
for p in my_processes:
    p.join()
</code>```

But this approach quickly failed due to the fact that my script demanded 400 processes, that all of them are running a loop for ~40.000 iterations. It literally, froze my laptop.

So how can I tackle this issue by efficiently utilizing the multiple cores of my CPU to handle the processes?

答:
I generated some random data, and then just did a straight-line replace:

```<code>#!python3

import random
import string

from mark_time import mark

synonyms = { 'AA': 'A', 'BB': 'B'}

population = list(string.ascii_uppercase)
population[-1] = 'AA'   # replace 'Z' with AA
population[-2] = 'BB'   # replace Y with BB

mark('Building inputs')
inputs = [random.choice(population) for _ in range(40000 * 400)]
mark('... done')

print(' '.join(inputs[:100]))

mark('Building outputs')
outputs = [synonyms.get(ch, ch) for ch in inputs]
mark('... done')

print(' '.join(outputs[:100]))
</code>```

My output looks like this:

```<code>[1490996255.208] Building inputs
[1490996273.388] ... done
N A U W R W H D E BB V A S B B U W U V S W V E K N Q E R H R A H I V U X V E U G A R D M R S K F O R B B G R C U M C C Q T K G S S H W AA U BB K L W T L H V BB K H J D AA K P G W BB W C U G T P G M J L S J
[1490996273.388] Building outputs
[1490996276.12] ... done
N A U W R W H D E B V A S B B U W U V S W V E K N Q E R H R A H I V U X V E U G A R D M R S K F O R B B G R C U M C C Q T K G S S H W A U B K L W T L H V B K H J D A K P G W B W C U G T P G M J L S J
</code>```

It's taking 18 seconds to build the input data, and only 3 seconds to replace synonyms. That's for 400 * 40,000 items. I'm not sure if your input items are individual genes or some sort of SAM sequences or what. More information in the question would probably be good. ;-)

I don't think you need to multiprocess this. Just do a good job processing the data as you read the file.

Update

Sorry for dropping out last night. But, beer.

Anyway, here's some code that will read in a synonyms file, with each line having a pair of words, like "old new", and build a dictionary that maps each old -> new word. It then "flattens" the dictionary, so that there is no need to repeat a lookup - each key is stored with its eventual value. I figure you can use this to read the synonym files, etc.

```<code>def get_synonyms(synfile):
    """Read in a list of 'synonym' pairs, two words per line A -> B.
    Store the pairs in a dict. "Flatten" the dict, so that if A->B and
    B->C, the dict stores A->C and B->C directly. Return the dict.
    """

    syns = {}

    # Read entries from the file
    with open(synfile) if type(synfile) is str else synfile as sf:
        for line in sf:
            if not line.strip(): continue
            k,v = line.strip().split()
            syns[k] = v

    # "flatten" the synonyms. If A -> B and B -> C, then change A -> C
    for k,v in syns.items():
        nv = v
        while nv in syns:
            nv = syns[nv]
        syns[k] = nv

    return syns

import io

synonyms = """
A B
B C
C D
E B
F A
AA G
""".strip()

#with open('synonyms.txt') as synfile:
with io.StringIO(synonyms) as synfile:
    thesaurus = get_synonyms(synfile)

assert sorted(thesaurus.keys()) == "A AA B C E F".split()
assert thesaurus['A'] == 'D'
assert thesaurus['B'] == 'D'
assert thesaurus['C'] == 'D'
assert thesaurus['E'] == 'D'
assert thesaurus['F'] == 'D'
assert thesaurus['AA'] == 'G'
</code>```

Title: Efficiently handling python processes

Body:
So for my project I have to get a list of genes and clean it from synonyms ex. gene A might also be known as AA, so if in my original list there is AA and A I have to delete one of the two.

The list of genes is provided by the user, and I read the synonyms from a text file.

Both are stored in dictionaries.

The list is huuuuuge (Trump joke) and I will have to call this function, many times in my pipeline. So my question is: Can I multiprocess this to make it faster?

My initial approach was as follows:

for g in genes:
    process = multiprocessing.Process(target = fixReoccurences, args =  (g, genes, synonyms, replaced, ))
    my_processes.append(process)
    process.start()

# Wait for *ALL* the processes to finish.
for p in my_processes:
    p.join()

But this approach quickly failed due to the fact that my script demanded 400 processes, that all of them are running a loop for ~40.000 iterations. It literally, froze my laptop.

So how can I tackle this issue by efficiently utilizing the multiple cores of my CPU to handle the processes?

Body:
I generated some random data, and then just did a straight-line replace:

#!python3

import random
import string

from mark_time import mark

synonyms = { 'AA': 'A', 'BB': 'B'}

population = list(string.ascii_uppercase)
population[-1] = 'AA'   # replace 'Z' with AA
population[-2] = 'BB'   # replace Y with BB

mark('Building inputs')
inputs = [random.choice(population) for _ in range(40000 * 400)]
mark('... done')

print(' '.join(inputs[:100]))

mark('Building outputs')
outputs = [synonyms.get(ch, ch) for ch in inputs]
mark('... done')

print(' '.join(outputs[:100]))

My output looks like this:

[1490996255.208] Building inputs
[1490996273.388] ... done
N A U W R W H D E BB V A S B B U W U V S W V E K N Q E R H R A H I V U X V E U G A R D M R S K F O R B B G R C U M C C Q T K G S S H W AA U BB K L W T L H V BB K H J D AA K P G W BB W C U G T P G M J L S J
[1490996273.388] Building outputs
[1490996276.12] ... done
N A U W R W H D E B V A S B B U W U V S W V E K N Q E R H R A H I V U X V E U G A R D M R S K F O R B B G R C U M C C Q T K G S S H W A U B K L W T L H V B K H J D A K P G W B W C U G T P G M J L S J

It's taking 18 seconds to build the input data, and only 3 seconds to replace synonyms. That's for 400 * 40,000 items. I'm not sure if your input items are individual genes or some sort of SAM sequences or what. More information in the question would probably be good. ;-)

I don't think you need to multiprocess this. Just do a good job processing the data as you read the file.

Update

Sorry for dropping out last night. But, beer.

Anyway, here's some code that will read in a synonyms file, with each line having a pair of words, like "old new", and build a dictionary that maps each old -> new word. It then "flattens" the dictionary, so that there is no need to repeat a lookup - each key is stored with its eventual value. I figure you can use this to read the synonym files, etc.

def get_synonyms(synfile):
    """Read in a list of 'synonym' pairs, two words per line A -> B.
    Store the pairs in a dict. "Flatten" the dict, so that if A->B and
    B->C, the dict stores A->C and B->C directly. Return the dict.
    """

    syns = {}

    # Read entries from the file
    with open(synfile) if type(synfile) is str else synfile as sf:
        for line in sf:
            if not line.strip(): continue
            k,v = line.strip().split()
            syns[k] = v

    # "flatten" the synonyms. If A -> B and B -> C, then change A -> C
    for k,v in syns.items():
        nv = v
        while nv in syns:
            nv = syns[nv]
        syns[k] = nv

    return syns

import io

synonyms = """
A B
B C
C D
E B
F A
AA G
""".strip()

#with open('synonyms.txt') as synfile:
with io.StringIO(synonyms) as synfile:
    thesaurus = get_synonyms(synfile)

assert sorted(thesaurus.keys()) == "A AA B C E F".split()
assert thesaurus['A'] == 'D'
assert thesaurus['B'] == 'D'
assert thesaurus['C'] == 'D'
assert thesaurus['E'] == 'D'
assert thesaurus['F'] == 'D'
assert thesaurus['AA'] == 'G'


问:
Data is not updated accordint to related props value
I'm trying to use vuejs to have a modal window and hide it on putton pressed.
Here is some code:
index.html:

```<code><table class="table">
  <tr v-for = "dream in dreams">
  ...
  <th>
    <button id="show-modal" @click="showModal = true">New Post</button>
  </th>
  </tr>
</table>
...

<editdream v-bind:show.sync="showModal"></editdream>
</code>```

in editdream.vue file I have:

```<code><template>
  <div v-show="isShown" transition="modal">
  ...
  </div>
</template>

<script>
  export default {
  props: ['show'],
  methods: {

    close: function () {
        this.isShown = false;
    },

    savePost: function () {
        this.close();
    }
  },
  data: function () {
    return { isShown: this.show }
  }
}
</code>```

I supposed that when I press button then 'show' props will be updated for modal window and corresponding 'isShown' data will be udpdated as well. But I can only see that prop is becoming true, but isShown is still false when I press button. Could you please explain why?

答:
Inside of editdream.vue, you've defined isShown in under data.

data is set once prior to the creation of the component, so it doesn't update when you click your show-modal button in index.html. isShown stays at whatever your prop show was set to on creation, prior to the button being clicked (presumably false).

A simple fix would be make isShown a computed property:

```<code><template>
  <div v-show="isShown" transition="modal">
  ...
  </div>
</template>

<script>
export default {
  props: ['show'],
  methods: {
    close: function () {
        this.isShown = false;
    },
    savePost: function () {
        this.close();
    }
  },
  computed: {
    isShown: function() return {this.show};
  }
}
</code>```

computed properties actively watch the data on this, like your show prop, so it should update whenever show does.

Body:
I'm trying to use vuejs to have a modal window and hide it on putton pressed.
Here is some code:
index.html:

  ...

    <button id="show-modal" @click="showModal = true">New Post</button>

...

<editdream v-bind:show.sync="showModal"></editdream>

in editdream.vue file I have:

<template>

  ...

</template>

Body:
Inside of editdream.vue, you've defined isShown in under data.

data is set once prior to the creation of the component, so it doesn't update when you click your show-modal button in index.html. isShown stays at whatever your prop show was set to on creation, prior to the button being clicked (presumably false).

A simple fix would be make isShown a computed property:

<template>
  <div v-show="isShown" transition="modal">
  ...
  </div>
</template>

<script>
export default {
  props: ['show'],
  methods: {
    close: function () {
        this.isShown = false;
    },
    savePost: function () {
        this.close();
    }
  },
  computed: {
    isShown: function() return {this.show};
  }
}

computed properties actively watch the data on this, like your show prop, so it should update whenever show does.

ContentLicense: CC BY-SA 4.0


问:
Scripting a file move on an FTP Server
I'm attempting to move multiple files on an FTP server to a different directory on the same server. So far, I've written a bash script that will login and retrieve any new files in the remote directory but the ftp command doesn't support a 'mv' command. Essentially the script would download the new file(s) and then once downloaded move the file(s) to a different directory on the same server.  Please Note that the filenames will be different every time so the use of wildcards is important here.

Before you answer please note that this needs to be automated so using a GUI like Filezilla wouldn't help me as I would have to login to various ftp sites and move the files manually, also, keep in mind that I'm unable to ssh into any of the servers as they are managed by other company's and ftp access is all I'm able to get. Last thing, I won't know what the file names are so using a wildcard would be helpful.

Any help or guidance is truly appreciated.

Thank you!

答:
Perhaps the rename command in ftp could work for you?

```<code>rename [from [to]]
       Rename the file from on the remote machine, to the file to.
</code>```

I gave it a bash with an old file I had sitting on a server and it seemed to do what you want:

```<code>ftp> ls tmp/test*
229 Entering Extended Passive Mode (|||55572|)
150 Accepted data connection
-rw-r--r--    1 sinasohn   sinasohn           21 Mar 31 16:37 tmp/testfile01
226-Options: -a -l
226 1 matches total

ftp> ls tmp2/test*
229 Entering Extended Passive Mode (|||64715|)
150 Accepted data connection
226-Options: -a -l
226 0 matches total

ftp> rename tmp/testfile01 tmp2/testfile01
350 RNFR accepted - file exists, ready for destination
250 File successfully renamed or moved

ftp> ls tmp/test*
229 Entering Extended Passive Mode (|||56698|)
150 Accepted data connection
226-Options: -a -l
226 0 matches total

ftp> ls tmp2/test*
229 Entering Extended Passive Mode (|||50239|)
150 Accepted data connection
-rw-r--r--    1 sinasohn   sinasohn           21 Mar 31 16:37 tmp2/testfile01
226-Options: -a -l
226 1 matches total
ftp>
</code>```

I put blank lines in between commands here for clarity.

Hope this helps!

Title: Scripting a file move on an FTP Server

Body:
Perhaps the rename command in ftp could work for you?

rename [from [to]]
       Rename the file from on the remote machine, to the file to.

I gave it a bash with an old file I had sitting on a server and it seemed to do what you want:

ftp> ls tmp/test*
229 Entering Extended Passive Mode (|||55572|)
150 Accepted data connection
-rw-r--r--    1 sinasohn   sinasohn           21 Mar 31 16:37 tmp/testfile01
226-Options: -a -l
226 1 matches total

ftp> ls tmp2/test*
229 Entering Extended Passive Mode (|||64715|)
150 Accepted data connection
226-Options: -a -l
226 0 matches total

ftp> rename tmp/testfile01 tmp2/testfile01
350 RNFR accepted - file exists, ready for destination
250 File successfully renamed or moved

ftp> ls tmp/test*
229 Entering Extended Passive Mode (|||56698|)
150 Accepted data connection
226-Options: -a -l
226 0 matches total

ftp> ls tmp2/test*
229 Entering Extended Passive Mode (|||50239|)
150 Accepted data connection
-rw-r--r--    1 sinasohn   sinasohn           21 Mar 31 16:37 tmp2/testfile01
226-Options: -a -l
226 1 matches total
ftp>

I put blank lines in between commands here for clarity.

Hope this helps!


问:
Split String in Java based on open braces
```<code>Existing string:

stringToBeCleaned = author(A, UniqueVar1), author(B, UniqueVar1);

Expected String:

stringAfterCleaned = author(A, UniqueVar1)^author(B, UniqueVar1);
</code>```

The method I wanted to try was split the string and join it appending the exponential symbol. But I have problems in splitting.

```<code>split = stringToBeCleaned.split(", ");
</code>```

This does not give the required split.

```<code>split = stringToBeCleaned.split("), ");
</code>```

This split throws error for the invalid regex, because the braces are not closed Is there any way to achieve this. Any suggestions would be helpful.

答:
You just need to escape the parenthesis:

```<code>split = stringToBeCleaned.split("\\), ");
</code>```

Or you can just replace the comma without regex:

```<code>stringToBeCleaned = stringToBeCleaned.replace("), ", ")^");
</code>```

Body:
Existing string:

stringToBeCleaned = author(A, UniqueVar1), author(B, UniqueVar1);

Expected String:

stringAfterCleaned = author(A, UniqueVar1)^author(B, UniqueVar1);

The method I wanted to try was split the string and join it appending the exponential symbol. But I have problems in splitting.

split = stringToBeCleaned.split(", ");

This does not give the required split.

split = stringToBeCleaned.split("), ");

This split throws error for the invalid regex, because the braces are not closed Is there any way to achieve this. Any suggestions would be helpful.

Body:
You just need to escape the parenthesis:

split = stringToBeCleaned.split("\\), ");

Or you can just replace the comma without regex:

stringToBeCleaned = stringToBeCleaned.replace("), ", ")^");


问:
Remove Words Less Than 4 Characters from Pandas Series
I am trying to remove all words with less than 4 characters from each scalar value in a Pandas Series. What is the best way to do it? Here is my failed attempt:

```<code>df['text'] = df['text'].str.join(word for word in df['text'].str.split() if len(word)>3)
</code>```

I receive the following error message:

AttributeError: 'generator' object has no attribute 'join'

I based my attempt off of this post regarding the same in a string: Remove small words using Python

Side note: If its better to tokenize my words before removing with less than 4 characters please let me know.

EDIT: Each scalar value contains sentences so I want to remove for any words less than a length of 4 within the value.

答:
You can do something like this:

```<code>>>> df = pd.DataFrame({'text':["The quick brown fox", "jumped over the lazy dog"]})
>>> df
                       text
0       The quick brown fox
1  jumped over the lazy dog
>>> df['text'].str.split().map(lambda sl: " ".join(s for s in sl if len(s) > 3))
0         quick brown
1    jumped over lazy
Name: text, dtype: object
</code>```

But honestly, I usually stick to vanilla python for text-processing pipelines. pandas data structures don't play well with text. At the very least, you are losing the memory/speed advantages of numpy/pandas.

Body:
I am trying to remove all words with less than 4 characters from each scalar value in a Pandas Series. What is the best way to do it? Here is my failed attempt:

df['text'] = df['text'].str.join(word for word in df['text'].str.split() if len(word)>3)

I receive the following error message:

AttributeError: 'generator' object has no attribute 'join'

I based my attempt off of this post regarding the same in a string: Remove small words using Python

Side note: If its better to tokenize my words before removing with less than 4 characters please let me know.

EDIT: Each scalar value contains sentences so I want to remove for any words less than a length of 4 within the value.

Body:
You can do something like this:

>>> df = pd.DataFrame({'text':["The quick brown fox", "jumped over the lazy dog"]})
>>> df
                       text
0       The quick brown fox
1  jumped over the lazy dog
>>> df['text'].str.split().map(lambda sl: " ".join(s for s in sl if len(s) > 3))
0         quick brown
1    jumped over lazy
Name: text, dtype: object

But honestly, I usually stick to vanilla python for text-processing pipelines. pandas data structures don't play well with text. At the very least, you are losing the memory/speed advantages of numpy/pandas.


问:
Output string with leading spaces to log, keeping the spaces
How can I print leading spaces to the log?

When I do something like

```<code>data _null_;
  x = '  Hello, world!';
  put x;
run;
</code>```

The result is

```<code>2522  data _null_;
2523    x = '  Hello, world!';
2524    putlog x;
2525  run;

Hello, world!
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
</code>```

I looked through the PUT documentation, but nothing stood out to me.  It seems like using a format, such as $CHARw., might work.  However, that would require knowing the length of the string ahead of time.

I would like the log output to look like this:

```<code>  Hello, world!  (<--edited by hand to display leading spaces)
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
</code>```

答:
I used @Joe's answer and built from it.  It turns out that the + pointer control is dynamic.  That is, the pointer position can be controlled by a data set variable.  This is good for when you don't know how many spaces there will be.

```<code>211  data _null_;
212    string         = '       Hello, world!';
213    len_string     = length(string);
214    len_stripped   = length(strip(string));
215    leading_spaces = len_string - len_stripped;
216
217    put len_string= len_stripped= leading_spaces= ;
218    put;
219    put +leading_spaces string;
220  run;

len_string=20 len_stripped=13 leading_spaces=7

       Hello, world!
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
</code>```

Body:
How can I print leading spaces to the log?

When I do something like

data _null_;
  x = '  Hello, world!';
  put x;
run;

The result is

2522  data _null_;
2523    x = '  Hello, world!';
2524    putlog x;
2525  run;

Hello, world!
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

I looked through the PUT documentation, but nothing stood out to me.  It seems like using a format, such as $CHARw., might work.  However, that would require knowing the length of the string ahead of time.

I would like the log output to look like this:

  Hello, world!  (<--edited by hand to display leading spaces)
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

Body:
I used @Joe's answer and built from it.  It turns out that the + pointer control is dynamic.  That is, the pointer position can be controlled by a data set variable.  This is good for when you don't know how many spaces there will be.

211  data _null_;
212    string         = '       Hello, world!';
213    len_string     = length(string);
214    len_stripped   = length(strip(string));
215    leading_spaces = len_string - len_stripped;
216
217    put len_string= len_stripped= leading_spaces= ;
218    put;
219    put +leading_spaces string;
220  run;

len_string=20 len_stripped=13 leading_spaces=7

       Hello, world!
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


问:
Json data not converting to List
I have a json data which was not serialized properly.
I have attached the expected and bad one.

I need to handle the bad json, get in a right format

Expected

```<code>"channels": {
    "heart-rate": {
        "events": {
            "type": "Project.Model.ChannelEvents.HeartRateChannelEvent, Project, Version=1.2.7.0, Culture=neutral, PublicKeyToken=null",
            "structure": [
                "beatsPerMinute",
                "offset"
            ],
            "list": [
                [
                    40,
                    0
                ]
            ]
        }
    },
    "location": {
        "events": {
            "type": "Project.Model.ChannelEvents.LocationChannelEvent, Project, Version=1.2.7.0, Culture=neutral, PublicKeyToken=null",
            "structure": [
                "latitude",
                "longitude",
                "offset"
            ],
            "list": [
                [
                    0.0,
                    0.0,
                    0
                ]
            ]
        }

    }
}
</code>```

badjson
This is the bad json data which needs to be formatted, in a console application

```<code>"channels": {
    "heart-rate": {
        "events": {
            "$type": "System.Collections.Generic.List`1[[Project.Model.Activity+Channel+Event, Project]], mscorlib",
            "$values": [{
                    "$type": "Project.Model.ChannelEvents.HeartRateChannelEvent, Project",
                    "beatsPerMinute": 40,
                    "offset": 0
                }
            ]
        }
    },
    "location": {
        "events": {
            "$type": "System.Collections.Generic.List`1[[Project.Model.Activity+Channel+Event, Project]], mscorlib",
            "$values": [{
                    "$type": "Project.Model.ChannelEvents.LocationChannelEvent, Project",
                    "latitude": 0.0,
                    "longitude": 0.0,
                    "offset": 0
                }
            ]
        }
    }
}
</code>```

答:
Firstly, both your input and output JSON are syntactically invalid: they are missing outer braces { and }.  For the remainder of this answer, I'm going to assume this is a typo in the question.

Assuming you have not done so already, you could install json.net as shown here and then use LINQ to JSON to load and modify your JSON.  Using this approach avoids the need to define c# types that perfectly match your JSON.

Your input JSON has two problems:

The tokens "channels.heart-rate.events" and "channels.location.events" are arrays of objects for which Json.NET type information has been included.  (It is clear from the presence of the "$type" property that the JSON was originally generated using Json.NET)

What you want instead is for these arrays to be reformatted into a single object that contains the item type, an array of item property names, and an array of array of item property values.

The type information has been formatted using TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple.  You want to add assembly information, converting to FormatterAssemblyStyle.Full format.

Both of these can be corrected using LINQ-to-JSON.  Say you have two streams, Stream inputStream and Stream outputStream corresponding to a stream with the JSON to be fixed and a stream in which to store the fixed JSON.  Then, introduce the following utility methods:

```<code>public static class JsonExtensions
{
    const string JsonTypeName = @"$type";
    const string JsonValuesName = @"$values";

    public static void ReformatCollections(Stream inputStream, Stream outputStream, IEnumerable<string> paths, Func<string, string> typeNameMapper, Formatting formatting)
    {
        var root = JToken.Load(new JsonTextReader(new StreamReader(inputStream)) { DateParseHandling = DateParseHandling.None });
        root = ReformatCollections(root, paths, typeNameMapper);

        var writer = new StreamWriter(outputStream);
        var jsonWriter = new JsonTextWriter(writer) { Formatting = formatting };

        root.WriteTo(jsonWriter);
        jsonWriter.Flush();
        writer.Flush();
    }

    public static JToken ReformatCollections(JToken root, IEnumerable<string> paths, Func<string, string> typeNameMapper)
    {
        foreach (var path in paths)
        {
            var token = root.SelectToken(path);
            var newToken = token.ReformatCollection(typeNameMapper);
            if (root == token)
                root = newToken;
        }

        return root;
    }

    public static JToken ReformatCollection(this JToken value, Func<string, string> typeNameMapper)
    {
        if (value == null || value.Type == JTokenType.Null)
            return value;

        var array = value as JArray;
        if (array == null)
            array = value[JsonValuesName] as JArray;
        if (array == null)
            return value;

        // Extract the item $type and ordered set of properties.
        string type = null;
        var properties = new Dictionary<string, int>();
        foreach (var item in array)
        {
            if (item.Type == JTokenType.Null)
                continue;
            var obj = item as JObject;
            if (obj == null)
                throw new JsonSerializationException(string.Format("Item \"{0}\" was not a JObject", obj.ToString(Formatting.None)));
            var objType = (string)obj[JsonTypeName];
            if (objType != null && type == null)
                type = objType;
            else if (objType != null && type != null)
            {
                if (type != objType)
                    throw new JsonSerializationException("Too many item types.");
            }
            foreach (var property in obj.Properties().Where(p => p.Name != JsonTypeName))
            {
                if (!properties.ContainsKey(property.Name))
                    properties.Add(property.Name, properties.Count);
            }
        }
        var propertyList = properties.OrderBy(p => p.Value).Select(p => p.Key).ToArray();
        var newValue = new JObject();
        if (type != null)
            newValue["type"] = JToken.FromObject(typeNameMapper(type));
        newValue["structure"] = JToken.FromObject(propertyList);
        newValue["list"] = JToken.FromObject(array
            .Select(o => (o.Type == JTokenType.Null ? o : propertyList.Where(p => o[p] != null).Select(p => o[p]))));
        if (value.Parent != null)
            value.Replace(newValue);
        return newValue;
    }
}
</code>```

Then, at the top level of your console method, you can fix your JSON as follows:

```<code>    Func<string, string> typeNameMapper = (t) =>
        {
            if (!t.EndsWith(", Version=1.2.7.0, Culture=neutral, PublicKeyToken=null"))
                t = t + ", Version=1.2.7.0, Culture=neutral, PublicKeyToken=null";
            return t;
        };
    var paths = new[]
        {
            "channels.heart-rate.events",
            "channels.location.events"
        };
    JsonExtensions.ReformatCollections(inputStream, outputStream, paths, typeNameMapper, Formatting.Indented);
</code>```

Sample fiddle.

Title: Json data not converting to List

Body:
I have a json data which was not serialized properly.
I have attached the expected and bad one.

I need to handle the bad json, get in a right format

Expected

"channels": {
    "heart-rate": {
        "events": {
            "type": "Project.Model.ChannelEvents.HeartRateChannelEvent, Project, Version=1.2.7.0, Culture=neutral, PublicKeyToken=null",
            "structure": [
                "beatsPerMinute",
                "offset"
            ],
            "list": [
                [
                    40,
                    0
                ]
            ]
        }
    },
    "location": {
        "events": {
            "type": "Project.Model.ChannelEvents.LocationChannelEvent, Project, Version=1.2.7.0, Culture=neutral, PublicKeyToken=null",
            "structure": [
                "latitude",
                "longitude",
                "offset"
            ],
            "list": [
                [
                    0.0,
                    0.0,
                    0
                ]
            ]
        }

    }
}

badjson
This is the bad json data which needs to be formatted, in a console application

"channels": {
    "heart-rate": {
        "events": {
            "$type": "System.Collections.Generic.List`1[[Project.Model.Activity+Channel+Event, Project]], mscorlib",
            "$values": [{
                    "$type": "Project.Model.ChannelEvents.HeartRateChannelEvent, Project",
                    "beatsPerMinute": 40,
                    "offset": 0
                }
            ]
        }
    },
    "location": {
        "events": {
            "$type": "System.Collections.Generic.List`1[[Project.Model.Activity+Channel+Event, Project]], mscorlib",
            "$values": [{
                    "$type": "Project.Model.ChannelEvents.LocationChannelEvent, Project",
                    "latitude": 0.0,
                    "longitude": 0.0,
                    "offset": 0
                }
            ]
        }
    }
}

Body:
Firstly, both your input and output JSON are syntactically invalid: they are missing outer braces { and }.  For the remainder of this answer, I'm going to assume this is a typo in the question.

Assuming you have not done so already, you could install json.net as shown here and then use LINQ to JSON to load and modify your JSON.  Using this approach avoids the need to define c# types that perfectly match your JSON.

Your input JSON has two problems:

The tokens "channels.heart-rate.events" and "channels.location.events" are arrays of objects for which Json.NET type information has been included.  (It is clear from the presence of the "$type" property that the JSON was originally generated using Json.NET)

What you want instead is for these arrays to be reformatted into a single object that contains the item type, an array of item property names, and an array of array of item property values.

The type information has been formatted using TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple.  You want to add assembly information, converting to FormatterAssemblyStyle.Full format.

Both of these can be corrected using LINQ-to-JSON.  Say you have two streams, Stream inputStream and Stream outputStream corresponding to a stream with the JSON to be fixed and a stream in which to store the fixed JSON.  Then, introduce the following utility methods:

public static class JsonExtensions
{
    const string JsonTypeName = @"$type";
    const string JsonValuesName = @"$values";

    public static void ReformatCollections(Stream inputStream, Stream outputStream, IEnumerable<string> paths, Func<string, string> typeNameMapper, Formatting formatting)
    {
        var root = JToken.Load(new JsonTextReader(new StreamReader(inputStream)) { DateParseHandling = DateParseHandling.None });
        root = ReformatCollections(root, paths, typeNameMapper);

        var writer = new StreamWriter(outputStream);
        var jsonWriter = new JsonTextWriter(writer) { Formatting = formatting };

        root.WriteTo(jsonWriter);
        jsonWriter.Flush();
        writer.Flush();
    }

    public static JToken ReformatCollections(JToken root, IEnumerable<string> paths, Func<string, string> typeNameMapper)
    {
        foreach (var path in paths)
        {
            var token = root.SelectToken(path);
            var newToken = token.ReformatCollection(typeNameMapper);
            if (root == token)
                root = newToken;
        }

        return root;
    }

    public static JToken ReformatCollection(this JToken value, Func<string, string> typeNameMapper)
    {
        if (value == null || value.Type == JTokenType.Null)
            return value;

        var array = value as JArray;
        if (array == null)
            array = value[JsonValuesName] as JArray;
        if (array == null)
            return value;

        // Extract the item $type and ordered set of properties.
        string type = null;
        var properties = new Dictionary<string, int>();
        foreach (var item in array)
        {
            if (item.Type == JTokenType.Null)
                continue;
            var obj = item as JObject;
            if (obj == null)
                throw new JsonSerializationException(string.Format("Item \"{0}\" was not a JObject", obj.ToString(Formatting.None)));
            var objType = (string)obj[JsonTypeName];
            if (objType != null && type == null)
                type = objType;
            else if (objType != null && type != null)
            {
                if (type != objType)
                    throw new JsonSerializationException("Too many item types.");
            }
            foreach (var property in obj.Properties().Where(p => p.Name != JsonTypeName))
            {
                if (!properties.ContainsKey(property.Name))
                    properties.Add(property.Name, properties.Count);
            }
        }
        var propertyList = properties.OrderBy(p => p.Value).Select(p => p.Key).ToArray();
        var newValue = new JObject();
        if (type != null)
            newValue["type"] = JToken.FromObject(typeNameMapper(type));
        newValue["structure"] = JToken.FromObject(propertyList);
        newValue["list"] = JToken.FromObject(array
            .Select(o => (o.Type == JTokenType.Null ? o : propertyList.Where(p => o[p] != null).Select(p => o[p]))));
        if (value.Parent != null)
            value.Replace(newValue);
        return newValue;
    }
}

Then, at the top level of your console method, you can fix your JSON as follows:

    Func<string, string> typeNameMapper = (t) =>
        {
            if (!t.EndsWith(", Version=1.2.7.0, Culture=neutral, PublicKeyToken=null"))
                t = t + ", Version=1.2.7.0, Culture=neutral, PublicKeyToken=null";
            return t;
        };
    var paths = new[]
        {
            "channels.heart-rate.events",
            "channels.location.events"
        };
    JsonExtensions.ReformatCollections(inputStream, outputStream, paths, typeNameMapper, Formatting.Indented);

Sample fiddle.


问:
StringUtils.isBlank() vs String.isEmpty()
I ran into some code that has the following:

```<code>String foo = getvalue("foo");
if (StringUtils.isBlank(foo))
    doStuff();
else
    doOtherStuff();
</code>```

This appears to be functionally equivalent to the following:

```<code>String foo = getvalue("foo");
if (foo.isEmpty())
    doStuff();
else
    doOtherStuff();
</code>```

Is a difference between the two (org.apache.commons.lang3.StringUtils.isBlank and java.lang.String.isEmpty)?

答:
The accepted answer from @arshajii is totally correct. However just being more explicit by saying below,

StringUtils.isBlank()

```<code> StringUtils.isBlank(null)      = true
 StringUtils.isBlank("")        = true
 StringUtils.isBlank(" ")       = true
 StringUtils.isBlank("bob")     = false
 StringUtils.isBlank("  bob  ") = false
</code>```

StringUtils.isEmpty

```<code> StringUtils.isEmpty(null)      = true
 StringUtils.isEmpty("")        = true
 StringUtils.isEmpty(" ")       = false
 StringUtils.isEmpty("bob")     = false
 StringUtils.isEmpty("  bob  ") = false
</code>```

Body:
I ran into some code that has the following:

String foo = getvalue("foo");
if (StringUtils.isBlank(foo))
    doStuff();
else
    doOtherStuff();

This appears to be functionally equivalent to the following:

String foo = getvalue("foo");
if (foo.isEmpty())
    doStuff();
else
    doOtherStuff();

Is a difference between the two (org.apache.commons.lang3.StringUtils.isBlank and java.lang.String.isEmpty)?

Body:
The accepted answer from @arshajii is totally correct. However just being more explicit by saying below,

StringUtils.isBlank()

 StringUtils.isBlank(null)      = true
 StringUtils.isBlank("")        = true
 StringUtils.isBlank(" ")       = true
 StringUtils.isBlank("bob")     = false
 StringUtils.isBlank("  bob  ") = false

StringUtils.isEmpty

 StringUtils.isEmpty(null)      = true
 StringUtils.isEmpty("")        = true
 StringUtils.isEmpty(" ")       = false
 StringUtils.isEmpty("bob")     = false
 StringUtils.isEmpty("  bob  ") = false


问:
Lisp in the real world
I have experimented with Lisp (actually Scheme) and found it to be a very beautiful language that I am interested in learning more about.  However, it appears that Lisp is never used in serious projects, and I haven't seen it listed as a desired skill on any job posting.  I am interested in hearing from anyone who has used Lisp or seen it used in the "real world", or who knows whether it is considered a purely academic language.</p>

答: For the AutoCAD application AutoLISP/Visual LISP are used a lot for real projects and there is a large community of users.</p>

OwnerDisplayName: titaniumdecoy

Title: Lisp in the real world

LastEditorDisplayName: Ande Turner

OwnerDisplayName: Jimmy Bergmark - JTB World

ContentLicense: CC BY-SA 2.5


问:
multiple column with muptiple rows data to a single row & for the non duplicated data need concadination
Currently data is like below:-

```<code>SQL Query:-
declare @t table
(
    Id int,
    ReportedDate DATE,
    [Name] varchar(10)
)
insert into @t

select 1,'2016-01-01','ab' union all
select 2,'2016-01-01','a' union all
select 1,'2016-01-20','hha' union all
select 2,'2016-01-20','jnsjja' union all
select 1,'2016-01-01','jsjb' union all
select 2,'2016-01-01','sjjjwb' union all
select 1,'2016-01-20','bjd' union all
select 2,'2016-01-20','bwjw'

select * from @t order by id, ReportedDate
</code>```

Expected Result:-

It's working in case we have only 2 columns, one is Id & other one is anything. But for mutiple column I am unable

答:
There are countless examples for this, however, since you have a nicely structured question which is easy to copy and paste....

```<code>Select A.ID
      ,A.ReportedDate
      ,Name  = Stuff((Select Distinct ',' +Name From @t Where ID=A.ID and ReportedDate=A.ReportedDate For XML Path ('')),1,1,'')
 From (Select Distinct ID,ReportedDate From @t ) A
</code>```

Returns

```<code>ID  ReportedDate    Name
1   2016-01-01      ab,jsjb
1   2016-01-20      bjd,hha
2   2016-01-01      a,sjjjwb
2   2016-01-20      bwjw,jnsjja
</code>```

Body:
Currently data is like below:-

SQL Query:-
declare @t table
(
    Id int,
    ReportedDate DATE,
    [Name] varchar(10)
)
insert into @t

select 1,'2016-01-01','ab' union all
select 2,'2016-01-01','a' union all
select 1,'2016-01-20','hha' union all
select 2,'2016-01-20','jnsjja' union all
select 1,'2016-01-01','jsjb' union all
select 2,'2016-01-01','sjjjwb' union all
select 1,'2016-01-20','bjd' union all
select 2,'2016-01-20','bwjw'

select * from @t order by id, ReportedDate

Expected Result:-

It's working in case we have only 2 columns, one is Id & other one is anything. But for mutiple column I am unable

Body:
There are countless examples for this, however, since you have a nicely structured question which is easy to copy and paste....

Select A.ID
      ,A.ReportedDate
      ,Name  = Stuff((Select Distinct ',' +Name From @t Where ID=A.ID and ReportedDate=A.ReportedDate For XML Path ('')),1,1,'')
 From (Select Distinct ID,ReportedDate From @t ) A

Returns

ID  ReportedDate    Name
1   2016-01-01      ab,jsjb
1   2016-01-20      bjd,hha
2   2016-01-01      a,sjjjwb
2   2016-01-20      bwjw,jnsjja


问:
Storage Queue Connection String Environment variable
Is there an environment variable I can set in my azure app settings to have a function pick up my storage queue connection string? I've been looking over the source and I don't see anything.

But I do see this section (https://github.com/Azure/azure-content-nlnl/blob/master/articles/azure-functions/functions-run-local.md#to-run-locally) about running locally and being able to specify a connection string. I can't ship a connection string in my oss app.

答:
Yes, here are the steps for setting the App Setting for your Function App:

Visit your Function App through the Azure Functions Portal in the browser.

Click on the Function app settings button located on the bottom left.

Click on Configure app settings to load the app settings blade.

Scroll down to the App settings section, and add the key and value pair for your storage queue connection.

Click on the Save button.


问:
Rails method to return current "controller#action"?
Instead of checking if controller_name == 'foo' && action_name == 'bar', is there a Rails method to return the two in the same format that you'd define them in the routes.rb file (get '/buzz' => 'foo#bar')?

Is there something like get_current_route() that'll return "foo#bar"?

答:
I'm not aware of one.

But you can always write your own and stick it somewhere convenient:

e.g.:

```<code>module ApplicationHelper

  def get_current_route
    "#{params[:controller]}##{params[:action]}"
  end

end
</code>```

Body:
I'm not aware of one.

But you can always write your own and stick it somewhere convenient:

e.g.:

module ApplicationHelper

  def get_current_route
    "#{params[:controller]}##{params[:action]}"
  end

end


问:
How do I get a web job to use the azure portal storage connection string, not what's in the web job console app's deployed config file?
I've created a web job using the webjobs sdk that is linked to my web application.  Well it isn't anymore (I removed the webjobs-list.json file from the web app project), because when it was linked, it just copied the source code files into the websites' app-data folder, not the bin folder/binaries/exe.  But now that my web job is deployed from visual studio online to azure with my website, and tries to run, it's not reading the connection strings (AzureWebJobsStorage and AzureWebJobsDashboard) from the connection strings in my web application's settings in the azure portal.  It looks for them in the config file that is deployed with the exe that is generated from compiling the webjob. If I manually put those strings in that config and check in, and redploy it will use them from there, so it's not checking the portal at all (even though my web app is running fine using what is defined in the portal).  I thought that all web jobs were supposed to look for connection strings in the azure portal first?  That isn't happening at all for me.  Has anyone else experienced this?  Could it have something to do with how it's deployed by visual studio online?

Part of the error getting logged for the webjob process when trying to start:

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Functions.ProcessTestQueueMessage' ---> System.InvalidOperationException: Microsoft Azure WebJobs SDK 'Storage' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:
[04/01/2017 02:27:40 > ceef22: INFO] 1. Set the connection string named 'AzureWebJobsStorage' in the connectionStrings section of the .config file in the following format , or
[04/01/2017 02:27:40 > ceef22: INFO] 2. Set the environment variable named 'AzureWebJobsStorage', or
[04/01/2017 02:27:40 > ceef22: INFO] 3. Set corresponding property of JobHostConfiguration.
[04/01/2017 02:27:40 > ceef22: INFO]    at Microsoft.Azure.WebJobs.Host.Executors.StorageAccountParser.ParseAccount(String connectionString, String connectionStringName, IServiceProvider services)

Also, the only way I could get this to really deploy was to remove the webjobs-list.json file from the properties folder in the web project.  I know I'm not supposed to do that, that everything should just work and deploy with that in there, but when I left it in there, it wouldn't copy the binaries/bin/executable files into the App_Data\Jobs\continuous[webjob] folder on the website...it would literally copy all of the source code\files for the web job project into there (which of course wouldn't work/run, since it's just code, not an exe).  After removing that webjobs-list.json file, and then adding a second task to my release to find the [webjob].zip file from the build, then it would copy just the binaries and executable into the App_Data\Jobs\continuous[webjob] folder.  Maybe this is just an issue with trying to build and release from visual studio online, and it doesn't handle web job deployment well...not sure, I haven't been able to find a lot of information on setting that up to deploy a web job with a web app.

答:
Normally, this should just work. The flow is:

The WebJobs exe doesn't run in-place, but first gets copied to a temp folder

As part of that copying process, if any of the AppSettings & Conn Strings in the foo.exe.config file are set as Azure settings, they get replaced (only in the temp copy, not under App_Data).

Can you make sure that you are deploying both your foo.exe and foo.exe.config?

Update: as we found on chat, the problem was that you had a typo in the name of the connection string in Azure.


问:
CLIPS: to check path to the directory
CLIPS has function "(open)" used for opening files. If file can be opened this function returns "true". Is there a similar function for opening directories? I want to check that path to the directory (saved in the string variable) is correct. </p>

答:
There is not a similar function for opening directories. You would have to add one to the CLIPS source code using the user-defined function API described in the CLIPS Advanced Programming Guide. I couldn't find any references for a relevant library function in ANSI C, so you'd have to check for the appropriate function for whichever platform you're using:

How can I check if a directory exists?

C faster way to check if a directory exists

Title: CLIPS: to check path to the directory


问:
C++ text animation Error C2397
I writted this code from a youtube video (from Husam Haj):
https://www.youtube.com/watch?v=C2k-xiLmNSQ

This code is supposed to Animate Text (See the video) using C++, but the thing is that this code doesn't work since I got the following message from visual studio 2017:

"error C2397: conversion from 'int' to 'SHORT' requires a narrowing conversion"

I was researching in the internet and I found that someone already asked for help with this same code, but not solution:
http://www.dreamincode.net/forums/topic/358635-i-need-some-help/

I would appreciate any help

Below is the code:

```<code>#include "stdafx.h"
#include <string>
#include <string.h>
#include <windows.h>
#include <iostream>

using namespace std;

void Display(string[], const int);

int main()
{
const int arr_size = 12;
string myInfo[arr_size] = { " Animated text example",
  "     Brooklyn College",
  "  Pre-Engineering Program",
 };

 Display(myInfo, arr_size);

 return 0;
}

void Display(string arr_string[], int arr_size)
{
 HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);

COORD pos[18] = { { 0,6 },{ 0,7 },{ 0,9 },{ 0,11 },{ 0,13 },{ 0,15 },
 { 0,17 },{ 0,19 },{ 0,21 },{ 0,23 },{ 0,25 },{ 0,27 },
 { 0,29 },{ 0,31 },{ 0,33 },{ 0,35 },{ 0,37 },{ 0,39 } };

 for (int k = 0; k<arr_size; k++)
{
  for (int j = arr_string[k].size(); j >= 0; j--)
{
   for (int i = 0; i <= j; i = i++)
{
    SetConsoleCursorPosition(screen, pos[k]);
    cout << " " << endl;
    pos[k].X++;

    SetConsoleCursorPosition(screen, pos[k]);
    cout << arr_string[k][j] << endl;
    Sleep(1);
}
pos[k] = {0,k+1}; //HERE THE MISTAKE!
}
}
}
</code>```

答:
The complaint is you have a 32 bit number being stuffed into a 16 bit space and may suffer data loss. Would have expected that to be a warning, not a compiler error.

I don't know of a suffix for forcing an integer literal to a 16 bit integer, so a quick and cheesy solution is to cast

```<code>pos[k] = {(SHORT)0,(SHORT)(k+1)};
</code>```

You'll have a similar problem with

```<code>for (int j = arr_string[k].size(); j >= 0; j--)
</code>```

because you're assigning the unsigned integer from size() to a signed integer.

```<code>for (size_t j = arr_string[k].size(); j >= 0; j--)
</code>```

should solve that.  And while we are here, watch out for

```<code>for (int i = 0; i <= j; i = i++)
</code>```

because you don't know if you get the increment (i++) or the assignment (i=) first.

Title: C++ text animation Error C2397

Body:
I writted this code from a youtube video (from Husam Haj):
https://www.youtube.com/watch?v=C2k-xiLmNSQ

This code is supposed to Animate Text (See the video) using C++, but the thing is that this code doesn't work since I got the following message from visual studio 2017:

"error C2397: conversion from 'int' to 'SHORT' requires a narrowing conversion"

I was researching in the internet and I found that someone already asked for help with this same code, but not solution:
http://www.dreamincode.net/forums/topic/358635-i-need-some-help/

I would appreciate any help

Below is the code:

#include "stdafx.h"
#include <string>
#include <string.h>
#include <windows.h>
#include <iostream>

using namespace std;

void Display(string[], const int);

int main()
{
const int arr_size = 12;
string myInfo[arr_size] = { " Animated text example",
  "     Brooklyn College",
  "  Pre-Engineering Program",
 };

 Display(myInfo, arr_size);

 return 0;
}

void Display(string arr_string[], int arr_size)
{
 HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);

COORD pos[18] = { { 0,6 },{ 0,7 },{ 0,9 },{ 0,11 },{ 0,13 },{ 0,15 },
 { 0,17 },{ 0,19 },{ 0,21 },{ 0,23 },{ 0,25 },{ 0,27 },
 { 0,29 },{ 0,31 },{ 0,33 },{ 0,35 },{ 0,37 },{ 0,39 } };

 for (int k = 0; k<arr_size; k++)
{
  for (int j = arr_string[k].size(); j >= 0; j--)
{
   for (int i = 0; i <= j; i = i++)
{
    SetConsoleCursorPosition(screen, pos[k]);
    cout << " " << endl;
    pos[k].X++;

    SetConsoleCursorPosition(screen, pos[k]);
    cout << arr_string[k][j] << endl;
    Sleep(1);
}
pos[k] = {0,k+1}; //HERE THE MISTAKE!
}
}
}

Body:
The complaint is you have a 32 bit number being stuffed into a 16 bit space and may suffer data loss. Would have expected that to be a warning, not a compiler error.

I don't know of a suffix for forcing an integer literal to a 16 bit integer, so a quick and cheesy solution is to cast

pos[k] = {(SHORT)0,(SHORT)(k+1)};

You'll have a similar problem with

for (int j = arr_string[k].size(); j >= 0; j--)

because you're assigning the unsigned integer from size() to a signed integer.

for (size_t j = arr_string[k].size(); j >= 0; j--)

should solve that.  And while we are here, watch out for

for (int i = 0; i <= j; i = i++)

because you don't know if you get the increment (i++) or the assignment (i=) first.


问:
How to get next non child element
I honestly tried to do search before posting but couldn't find something specific.
So my task is to show hidden content in the blog, when user clicks on the link.
HTML looks like this:

```<code><div class="entry">
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is all the hidden content</p></div>
</div>
</code>```

Now jQuery I'm doing the following but it's not working:

```<code>$(".hidden_post").hide();
$(".a-toggle).click(function() {
$(this).next(".hidden_post").slideDown("slow"); });
</code>```

So to get next element I need to go to a parent element first and then proceed search from there.
Now it gets more complicated for me, because I'll actually going to have several hidden
contents in one "entry". Like this:

```<code><div class="entry">
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is hidden content #1</p></div>
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is hidden content #2</p></div>
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is hidden content #3</p></div>
</div>
</code>```

Now if I use $(this).parent().next(".hidden_post").slideDown("slow");
It will go up to "entry" div and then will find first "hidden_post" only. I guess
I still need another solution to go straight from class="a-toggle"> to
 that is next to it. Is there any solution?

答:
You could use the children method to get all direct children of the parent element.

```<code>$('div.entry').children('div.hidden_post');
</code>```

This will return all of the div children of the div with class of entry who have a class of hidden_post.

Title: How to get next non child element

Body:
I honestly tried to do search before posting but couldn't find something specific.
So my task is to show hidden content in the blog, when user clicks on the link.
HTML looks like this:

Here is a visible content  Read More...

Here is all the hidden content

Now jQuery I'm doing the following but it's not working:

$(".hidden_post").hide();
$(".a-toggle).click(function() {
$(this).next(".hidden_post").slideDown("slow"); });

So to get next element I need to go to a parent element first and then proceed search from there.
Now it gets more complicated for me, because I'll actually going to have several hidden
contents in one "entry". Like this:

Here is a visible content  Read More...

Here is hidden content #1

Here is a visible content  Read More...

Here is hidden content #2

Here is a visible content  Read More...

Here is hidden content #3

Now if I use $(this).parent().next(".hidden_post").slideDown("slow");
It will go up to "entry" div and then will find first "hidden_post" only. I guess
I still need another solution to go straight from  to
 that is next to it. Is there any solution?

Body:
You could use the children method to get all direct children of the parent element.

$('div.entry').children('div.hidden_post');

This will return all of the div children of the div with class of entry who have a class of hidden_post.


问:
impala throws invalid session id
I am using impala for querying data and my script throws this exception :

HiveServer2Error: Invalid session id

答: I'd recommend increasing your connection timeout parameter. Hiveserver2 does not distinguish between invalid session ids and timeouts.</p>

Title: impala throws invalid session id


问:
What is wrong with my Scheme using vector-set implementation?
I was wondering what I am doing wrong here with vector-set

```<code>(define foo0
  (lambda (vec)
    (let* ((newvec (vector vec))
           (l      (vector-length vec))
           (norm   (norm0 vec)))
      (do ((i 0(+ i 1)))
        ((= i l))
        (vector-set*! newvec  i (/(vector-ref vec i) norm))) newvec)))
</code>```

I am trying to set each element of the vector to be divided by norm (an integer from another predicate).

The error I keep getting is

```<code>  vector-set!: index is out of range
  index: 1
  valid range: [0, 0]
  vector: '#(3/4)
</code>```

So I am finding the first solution, however, the newvec gets reset to size 1, so the index goes out of range.

答: In the second line of your program, you write (vector vec). What does this evaluate to?

Body:
I was wondering what I am doing wrong here with vector-set

(define foo0
  (lambda (vec)
    (let* ((newvec (vector vec))
           (l      (vector-length vec))
           (norm   (norm0 vec)))
      (do ((i 0(+ i 1)))
        ((= i l))
        (vector-set*! newvec  i (/(vector-ref vec i) norm))) newvec)))

I am trying to set each element of the vector to be divided by norm (an integer from another predicate).

The error I keep getting is

  vector-set!: index is out of range
  index: 1
  valid range: [0, 0]
  vector: '#(3/4)

So I am finding the first solution, however, the newvec gets reset to size 1, so the index goes out of range.


问:
AWS CodePipeline adding artifacts to S3 in less useful format than running steps individually
I've set up a CodePipeline with the end goal of having a core service reside on S3 as a private maven repo for other pipelines to rely on. When the core service is updated and pushed to AWS CodeCommit, the pipeline should run, test it, build a jar using a maven docker image, then push the resulting jar to S3 where it can be accessed by other applications as needed.

Unfortunately, while the CodeBuild service works exactly how I want it to, uploading XYZCore.jar to /release on the bucket, the automated pipeline itself does not. Instead, it uploads to a "XYZCorePipeline" folder, which contains the input and output artifacts of the build. The output artifact itself is a zip file that's just a random string of characters. I checked the pipeline and it's using the service correctly, but pipeline specific builds always output there while standalone builds of the CodeBuild service output how I'd like them, allowing me to take advantage of things like versioning. What's the best way for me to fix the settings so the two builds match?

答:
Unfortunately CodePipeline does not support this use case.

As a workaround you could upload the artifact to S3 by invoking AWS CLI (aws s3 cp ...) from your buildspec.yml post_build.


问:
Tomcat 8 enable debug logging to list unneeded jars
When starting Tomcat 8 on Arch Linux ARM I get the following warning:

INFO: At least one JAR was scanned for TLDs yet contained no TLDs.
  Enable debug logging for this logger for a complete list of JARs that
  were scanned but no TLDs were found in them. Skipping unneeded JARs
  during scanning can improve startup time and JSP compilation time.`

I already modified ${catalina.home}/logging.properties like described here: How to fix JSP compiler warning: one JAR was scanned for TLDs yet contained no TLDs?

I changed some logging levels from INFO to FINE, uncommented "org.apache.jasper.compiler.TldLocationsCache.level = FINE" and added "org.apache.jasper.servlet.TldScanner.level = FINE". So the end of the file now looks the following:

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level =
  FINE
  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers
  = 2localhost.org.apache.juli.AsyncFileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level
  = FINE org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers
  = 3manager.org.apache.juli.AsyncFileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level
  = FINE org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers
  = 4host-manager.org.apache.juli.AsyncFileHandler

# For example, set the org.apache.catalina.util.LifecycleBase logger to log
  # each component that extends LifecycleBase changing state:
  #org.apache.catalina.util.LifecycleBase.level = FINE

# To see debug messages in TldLocationsCache, uncomment the following line: org.apache.jasper.compiler.TldLocationsCache.level = FINE
  org.apache.jasper.servlet.TldScanner.level = FINE

But I still get the warning at startup and not the unneeded JAR's paths. What's wrong?

答:
An easier way, in step 1 of the above post, instead of enabling debugging for everything, limit to org.apache.jasper:

Use this:

```<code>org.apache.jasper.level = FINEST
</code>```

Instead of this:

```<code>org.apache.catalina.level=FINEST
</code>```

Body:
An easier way, in step 1 of the above post, instead of enabling debugging for everything, limit to org.apache.jasper:

Use this:

org.apache.jasper.level = FINEST

Instead of this:

org.apache.catalina.level=FINEST