问:
Spark Worker Nodes starting but not showing in WebUI
I am trying to setup a small 3 node Spark cluster using some Raspberry Pi's and my main desktop but can't seem to get the Pi's to talk to my master node (the desktop). I have the network configured properly as I am also running Cassandra (Open source not DSE) on all three nodes. If I go to the web UI it only shows my main computer. I can put in the web ui address for each of the worker nodes and get their individual web ui page. They don't seem to know about my master node. I have each of the slave nodes in my slaves file. I feel like I am missing just one small thing to get this to work. Any suggestions would be much appreciated. Below are some logs and any other information I could think of that might be helpful , while trying to keep this fairly short and concise.

My spark-env.shon all the nodes is as follows (except Local IP is adjusted appropriately)

```<code>export SPARK_WORKER_CORES=6
export SPARK_MASTER_HOST=192.168.0.106

export SPARK_LOCAL_IP=192.168.0.201
</code>```

Log from a Worker Node:

```<code>Spark Command: /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java -cp /home/spark/spark/conf/:/home/spark/spark/jars/* -Xmx1g org.apache.spark.deploy.worker.Worker --webui-port 8081 spark://Palehorse:7077
========================================
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
17/07/05 03:22:40 INFO Worker: Started daemon with process name: 11065@PiCamp1
17/07/05 03:22:40 INFO SignalUtils: Registered signal handler for TERM
17/07/05 03:22:40 INFO SignalUtils: Registered signal handler for HUP
17/07/05 03:22:40 INFO SignalUtils: Registered signal handler for INT
17/07/05 03:22:41 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/07/05 03:22:42 INFO SecurityManager: Changing view acls to: spark
17/07/05 03:22:42 INFO SecurityManager: Changing modify acls to: spark
17/07/05 03:22:42 INFO SecurityManager: Changing view acls groups to:
17/07/05 03:22:42 INFO SecurityManager: Changing modify acls groups to:
17/07/05 03:22:42 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(spark); groups with view permissions: Set(); users  with modify permissions: Set(spark); groups with modify permissions: Set()
17/07/05 03:22:43 INFO Utils: Successfully started service 'sparkWorker' on port 35342.
17/07/05 03:22:44 INFO Worker: Starting Spark worker 192.168.0.201:35342 with 6 cores, 1024.0 MB RAM
17/07/05 03:22:44 INFO Worker: Running Spark version 2.1.1
17/07/05 03:22:44 INFO Worker: Spark home: /home/spark/spark
17/07/05 03:22:45 INFO Utils: Successfully started service 'WorkerUI' on port 8081.
17/07/05 03:22:45 INFO WorkerWebUI: Bound WorkerWebUI to 192.168.0.201, and started at http://192.168.0.201:8081
17/07/05 03:22:45 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:22:51 INFO Worker: Retrying connection to master (attempt # 1)
17/07/05 03:22:51 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:22:57 INFO Worker: Retrying connection to master (attempt # 2)
17/07/05 03:22:57 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:03 INFO Worker: Retrying connection to master (attempt # 3)
17/07/05 03:23:03 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:09 INFO Worker: Retrying connection to master (attempt # 4)
17/07/05 03:23:09 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:15 INFO Worker: Retrying connection to master (attempt # 5)
17/07/05 03:23:15 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:21 INFO Worker: Retrying connection to master (attempt # 6)
17/07/05 03:23:21 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:57 INFO Worker: Retrying connection to master (attempt # 7)
17/07/05 03:23:57 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:24:33 INFO Worker: Retrying connection to master (attempt # 8)
17/07/05 03:24:33 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:24:45 ERROR RpcOutboxMessage: Ask timeout before connecting successfully
17/07/05 03:24:45 WARN NettyRpcEnv: Ignored failure: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
17/07/05 03:24:45 WARN Worker: Failed to connect to master Palehorse:7077
org.apache.spark.SparkException: Exception thrown in awaitResult
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:77)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:75)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:83)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:100)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRef(RpcEnv.scala:108)
    at org.apache.spark.deploy.worker.Worker$$anonfun$org$apache$spark$deploy$worker$Worker$$tryRegisterAllMasters$1$$anon$1.run(Worker.scala:218)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:229)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:182)
    at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:197)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:194)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:190)
    ... 4 more
17/07/05 03:25:09 INFO Worker: Retrying connection to master (attempt # 9)
17/07/05 03:25:09 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:25:45 INFO Worker: Retrying connection to master (attempt # 10)
17/07/05 03:25:45 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:26:21 INFO Worker: Retrying connection to master (attempt # 11)
17/07/05 03:26:21 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:26:57 INFO Worker: Retrying connection to master (attempt # 12)
17/07/05 03:26:57 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:27:09 ERROR RpcOutboxMessage: Ask timeout before connecting successfully
17/07/05 03:27:09 WARN NettyRpcEnv: Ignored failure: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
17/07/05 03:27:09 WARN Worker: Failed to connect to master Palehorse:7077
org.apache.spark.SparkException: Exception thrown in awaitResult
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:77)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:75)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:83)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:100)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRef(RpcEnv.scala:108)
    at org.apache.spark.deploy.worker.Worker$$anonfun$org$apache$spark$deploy$worker$Worker$$tryRegisterAllMasters$1$$anon$1.run(Worker.scala:218)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:229)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:182)
    at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:197)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:194)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:190)
    ... 4 more
17/07/05 03:27:33 INFO Worker: Retrying connection to master (attempt # 13)
17/07/05 03:27:33 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:28:09 INFO Worker: Retrying connection to master (attempt # 14)
17/07/05 03:28:09 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:28:45 INFO Worker: Retrying connection to master (attempt # 15)
17/07/05 03:28:45 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:29:21 INFO Worker: Retrying connection to master (attempt # 16)
17/07/05 03:29:21 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:29:33 ERROR RpcOutboxMessage: Ask timeout before connecting successfully
17/07/05 03:29:33 WARN NettyRpcEnv: Ignored failure: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
17/07/05 03:29:33 WARN Worker: Failed to connect to master Palehorse:7077
org.apache.spark.SparkException: Exception thrown in awaitResult
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:77)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:75)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:83)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:100)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRef(RpcEnv.scala:108)
    at org.apache.spark.deploy.worker.Worker$$anonfun$org$apache$spark$deploy$worker$Worker$$tryRegisterAllMasters$1$$anon$1.run(Worker.scala:218)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:229)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:182)
    at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:197)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:194)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:190)
    ... 4 more
17/07/05 03:29:57 ERROR Worker: All masters are unresponsive! Giving up.
</code>```

答: I was able to get the slaves to talk to the master finally. Seemed to be a combination of things, one was a problem with my /etc/hosts file having the master name being set to the 127.0.1.1 address and the other problem did seem to be a problem with the start-all.sh solved by running the start-slave.sh spark://<master ip address>:7077

Body:
I am trying to setup a small 3 node Spark cluster using some Raspberry Pi's and my main desktop but can't seem to get the Pi's to talk to my master node (the desktop). I have the network configured properly as I am also running Cassandra (Open source not DSE) on all three nodes. If I go to the web UI it only shows my main computer. I can put in the web ui address for each of the worker nodes and get their individual web ui page. They don't seem to know about my master node. I have each of the slave nodes in my slaves file. I feel like I am missing just one small thing to get this to work. Any suggestions would be much appreciated. Below are some logs and any other information I could think of that might be helpful , while trying to keep this fairly short and concise.

My spark-env.shon all the nodes is as follows (except Local IP is adjusted appropriately)

export SPARK_WORKER_CORES=6
export SPARK_MASTER_HOST=192.168.0.106

export SPARK_LOCAL_IP=192.168.0.201

Log from a Worker Node:

Spark Command: /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java -cp /home/spark/spark/conf/:/home/spark/spark/jars/* -Xmx1g org.apache.spark.deploy.worker.Worker --webui-port 8081 spark://Palehorse:7077
========================================
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
17/07/05 03:22:40 INFO Worker: Started daemon with process name: 11065@PiCamp1
17/07/05 03:22:40 INFO SignalUtils: Registered signal handler for TERM
17/07/05 03:22:40 INFO SignalUtils: Registered signal handler for HUP
17/07/05 03:22:40 INFO SignalUtils: Registered signal handler for INT
17/07/05 03:22:41 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/07/05 03:22:42 INFO SecurityManager: Changing view acls to: spark
17/07/05 03:22:42 INFO SecurityManager: Changing modify acls to: spark
17/07/05 03:22:42 INFO SecurityManager: Changing view acls groups to:
17/07/05 03:22:42 INFO SecurityManager: Changing modify acls groups to:
17/07/05 03:22:42 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(spark); groups with view permissions: Set(); users  with modify permissions: Set(spark); groups with modify permissions: Set()
17/07/05 03:22:43 INFO Utils: Successfully started service 'sparkWorker' on port 35342.
17/07/05 03:22:44 INFO Worker: Starting Spark worker 192.168.0.201:35342 with 6 cores, 1024.0 MB RAM
17/07/05 03:22:44 INFO Worker: Running Spark version 2.1.1
17/07/05 03:22:44 INFO Worker: Spark home: /home/spark/spark
17/07/05 03:22:45 INFO Utils: Successfully started service 'WorkerUI' on port 8081.
17/07/05 03:22:45 INFO WorkerWebUI: Bound WorkerWebUI to 192.168.0.201, and started at http://192.168.0.201:8081
17/07/05 03:22:45 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:22:51 INFO Worker: Retrying connection to master (attempt # 1)
17/07/05 03:22:51 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:22:57 INFO Worker: Retrying connection to master (attempt # 2)
17/07/05 03:22:57 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:03 INFO Worker: Retrying connection to master (attempt # 3)
17/07/05 03:23:03 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:09 INFO Worker: Retrying connection to master (attempt # 4)
17/07/05 03:23:09 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:15 INFO Worker: Retrying connection to master (attempt # 5)
17/07/05 03:23:15 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:21 INFO Worker: Retrying connection to master (attempt # 6)
17/07/05 03:23:21 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:23:57 INFO Worker: Retrying connection to master (attempt # 7)
17/07/05 03:23:57 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:24:33 INFO Worker: Retrying connection to master (attempt # 8)
17/07/05 03:24:33 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:24:45 ERROR RpcOutboxMessage: Ask timeout before connecting successfully
17/07/05 03:24:45 WARN NettyRpcEnv: Ignored failure: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
17/07/05 03:24:45 WARN Worker: Failed to connect to master Palehorse:7077
org.apache.spark.SparkException: Exception thrown in awaitResult
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:77)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:75)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:83)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:100)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRef(RpcEnv.scala:108)
    at org.apache.spark.deploy.worker.Worker$$anonfun$org$apache$spark$deploy$worker$Worker$$tryRegisterAllMasters$1$$anon$1.run(Worker.scala:218)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:229)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:182)
    at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:197)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:194)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:190)
    ... 4 more
17/07/05 03:25:09 INFO Worker: Retrying connection to master (attempt # 9)
17/07/05 03:25:09 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:25:45 INFO Worker: Retrying connection to master (attempt # 10)
17/07/05 03:25:45 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:26:21 INFO Worker: Retrying connection to master (attempt # 11)
17/07/05 03:26:21 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:26:57 INFO Worker: Retrying connection to master (attempt # 12)
17/07/05 03:26:57 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:27:09 ERROR RpcOutboxMessage: Ask timeout before connecting successfully
17/07/05 03:27:09 WARN NettyRpcEnv: Ignored failure: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
17/07/05 03:27:09 WARN Worker: Failed to connect to master Palehorse:7077
org.apache.spark.SparkException: Exception thrown in awaitResult
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:77)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:75)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:83)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:100)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRef(RpcEnv.scala:108)
    at org.apache.spark.deploy.worker.Worker$$anonfun$org$apache$spark$deploy$worker$Worker$$tryRegisterAllMasters$1$$anon$1.run(Worker.scala:218)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:229)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:182)
    at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:197)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:194)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:190)
    ... 4 more
17/07/05 03:27:33 INFO Worker: Retrying connection to master (attempt # 13)
17/07/05 03:27:33 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:28:09 INFO Worker: Retrying connection to master (attempt # 14)
17/07/05 03:28:09 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:28:45 INFO Worker: Retrying connection to master (attempt # 15)
17/07/05 03:28:45 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:29:21 INFO Worker: Retrying connection to master (attempt # 16)
17/07/05 03:29:21 INFO Worker: Connecting to master Palehorse:7077...
17/07/05 03:29:33 ERROR RpcOutboxMessage: Ask timeout before connecting successfully
17/07/05 03:29:33 WARN NettyRpcEnv: Ignored failure: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
17/07/05 03:29:33 WARN Worker: Failed to connect to master Palehorse:7077
org.apache.spark.SparkException: Exception thrown in awaitResult
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:77)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse(RpcTimeout.scala:75)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:83)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:100)
    at org.apache.spark.rpc.RpcEnv.setupEndpointRef(RpcEnv.scala:108)
    at org.apache.spark.deploy.worker.Worker$$anonfun$org$apache$spark$deploy$worker$Worker$$tryRegisterAllMasters$1$$anon$1.run(Worker.scala:218)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Connecting to Palehorse/198.105.254.63:7077 timed out (120000 ms)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:229)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:182)
    at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:197)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:194)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:190)
    ... 4 more
17/07/05 03:29:57 ERROR Worker: All masters are unresponsive! Giving up.


来源: stackexchange

问:
Template MySQL zabbix
I am trying to monitor a database using this template https://share.zabbix.com/databases/mysql/template-mysql-800-items, the instructions do not indicate where I should place each file and modify each configuration, does anyone have experience with this?</p>

答: It's a bit of a large scale question, but in general, the XML file is imported in the Zabbix frontend, while the Perl script goes in /opt/mysql_check.pl (or wherever you point at in the userparameter entry in the agent daemon configuration file).</p>

ContentLicense: CC BY-SA 3.0

Title: Template MySQL zabbix


问:
Limit length of gridline (R plot)
How can I make the gridlines in an R plot using plot to not extend beyond the plot's boundaries? i.e. need to define gridlines' origin and end.

On the example given, I want the gridlines drawn by grid and the gridline at y=7.5 drawn by abline to extend from the y-axis to the right edge of the box.

```<code>plot(1:10,1:10,type = "n")
abline(h = 7.5, v = 0, col = "gray60", lty = 3)
grid(10,10)
</code>```

答:
You might have (unknowingly) set xpd = TRUE or xpd = NA. If you set your xpd = FALSE before your plot call, this will prevent your grid or abline (or ANY plot-additive object in Base R) from going beyond the plotting region.

So, do the following before your plot() call:

```<code>par(xpd = FALSE)
</code>```

For your future plotting cases remember that xpd = FALSE can be both locally used within a command, like abline(h = 2, xpd = FALSE) or it can be used globally, like how I used it for your case.

Further remember that xpd = NA IS NOT the same as xpd = FALSE. The former allows plotting to go well beyond the plotting region to par("oma") (outer margin area), while the latter keeps everything within the par("usr") (inner plotting) region. These features are helpful in various visualizations in R.

Title: Limit length of gridline (R plot)

Body:
How can I make the gridlines in an R plot using plot to not extend beyond the plot's boundaries? i.e. need to define gridlines' origin and end.

On the example given, I want the gridlines drawn by grid and the gridline at y=7.5 drawn by abline to extend from the y-axis to the right edge of the box.

plot(1:10,1:10,type = "n")
abline(h = 7.5, v = 0, col = "gray60", lty = 3)
grid(10,10)

Body:
You might have (unknowingly) set xpd = TRUE or xpd = NA. If you set your xpd = FALSE before your plot call, this will prevent your grid or abline (or ANY plot-additive object in Base R) from going beyond the plotting region.

So, do the following before your plot() call:

par(xpd = FALSE)

For your future plotting cases remember that xpd = FALSE can be both locally used within a command, like abline(h = 2, xpd = FALSE) or it can be used globally, like how I used it for your case.

Further remember that xpd = NA IS NOT the same as xpd = FALSE. The former allows plotting to go well beyond the plotting region to par("oma") (outer margin area), while the latter keeps everything within the par("usr") (inner plotting) region. These features are helpful in various visualizations in R.


问:
What does .div do in Pandas (Python)
I'm confused as to the highlighted line. What exactly is this line doing. What does .div do? I tried to look through the documentation which said

"Floating division of dataframe and other, element-wise (binary operator truediv)"

I'm not exactly sure what this means. Any help would be appreciated!

答:
You can divide one dataframe by another and pandas will automagically aligned the index and columns and subsequently divide the appropriate values. EG df1 / df2

If you divide a dataframe by series, pandas automatically aligns the series index with the columns of the dataframe.  It maybe that you want to align the index of the series with the index of the dataframe instead.  If this is the case, then you will have to use the div method.

So instead of:

```<code>df / s
</code>```

You use

```<code>df.div(s, axis=0)
</code>```

Which says to align the index of s with the index of df then perform the division while broadcasting over the other dimension, in this case columns.

Title: What does .div do in Pandas (Python)

Body:
You can divide one dataframe by another and pandas will automagically aligned the index and columns and subsequently divide the appropriate values. EG df1 / df2

If you divide a dataframe by series, pandas automatically aligns the series index with the columns of the dataframe.  It maybe that you want to align the index of the series with the index of the dataframe instead.  If this is the case, then you will have to use the div method.

So instead of:

df / s

You use

df.div(s, axis=0)

Which says to align the index of s with the index of df then perform the division while broadcasting over the other dimension, in this case columns.


问:
Django Wagtail/Haystack Search with Heroku
I uploaded my project to heroku and I have a Search engine which works on local development and I would like to make it work in production as well. I used Wagtails Search since it was super easy to install and configure but it seems not to be a proper solution for production. This was my configuration:

```<code>WAGTAILSEARCH_BACKENDS = {
'default': {
    'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch5',
    'URLS': [u'http://localhost:9200'],
    'INDEX': 'wagtail',
    'TIMEOUT': 5,
    'OPTIONS': {},
    'INDEX_SETTINGS': {},
    "ATOMIC_REBUILD":True
  }
}
</code>```

Heroku can't connect to Port 9200 and when I stated to read into the the configurations it seemed to be easier to use Haystack/Solr. This Heroku Article suggests to use the add-on "SearchBox Elasticsearch" but I cannot add any addons at the moment. So my Questions are:

Can I run the normal Haystack/Wagtail search without the Heroku add-on?

How do I make the 9200 Port accessible for Heroku?

Would it make sense to upgrade to Haystack? Is Wagtail scalable in production? anybody made any experience in production?

Im quite happy with Wagtail since everything works as it should and I don't want to change something that does the job. Hope somebody can enlighten me.

答: If you're using PostgreSQL as your database, a good option is to use Wagtail's PostgreSQL full-text search backend. It's fairly close in functionality to Elasticsearch, production-ready for large sites, and doesn't require running an external service.</p>

Body:
I uploaded my project to heroku and I have a Search engine which works on local development and I would like to make it work in production as well. I used Wagtails Search since it was super easy to install and configure but it seems not to be a proper solution for production. This was my configuration:

WAGTAILSEARCH_BACKENDS = {
'default': {
    'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch5',
    'URLS': [u'http://localhost:9200'],
    'INDEX': 'wagtail',
    'TIMEOUT': 5,
    'OPTIONS': {},
    'INDEX_SETTINGS': {},
    "ATOMIC_REBUILD":True
  }
}

Heroku can't connect to Port 9200 and when I stated to read into the the configurations it seemed to be easier to use Haystack/Solr. This Heroku Article suggests to use the add-on "SearchBox Elasticsearch" but I cannot add any addons at the moment. So my Questions are:

Can I run the normal Haystack/Wagtail search without the Heroku add-on?

How do I make the 9200 Port accessible for Heroku?

Would it make sense to upgrade to Haystack? Is Wagtail scalable in production? anybody made any experience in production?

Im quite happy with Wagtail since everything works as it should and I don't want to change something that does the job. Hope somebody can enlighten me.


问:
Qt WebSockets, how to send a message to client
I'm following this example http://doc.qt.io/qt-5/qtwebsockets-echoserver-example.html but I can't figure out how to send a message to client after the connection has been made.

This seems to work but only when it's inside a function from another class.

```<code>void EchoServer::processTextMessage(QString message)
{

    m_clients.at(0)->sendTextMessage("test");

}
</code>```

Where / How should I put the code to get it working?

e. g. How to send a message to client after a button has been pressed in MainWindow?

This is working

```<code>void EchoServer::processTextMessage(QString message)
{

      m_clients.at(0)->sendTextMessage("test");

}
</code>```

This isn't working

```<code>MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    m_clients.at(0)->sendTextMessage("test");

}
</code>```

Neither this

```<code>void MainWindow::myclicked()
{

 m_clients.at(0)->sendTextMessage("test");

}
</code>```

答:
I got it working. Here is the code:</p>

```<code>QWebSocket *messageSocket;

void EchoServer::onNewConnection()
{
    QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
    connect(pSocket, &QWebSocket::textMessageReceived, this, &EchoServer::processTextMessage);
    connect(pSocket, &QWebSocket::disconnected, this, &EchoServer::socketDisconnected);

    m_clients << pSocket;

    messageSocket=pSocket;
}

void MainWindow::myclicked()
{
    if (messageSocket)
        {

             messageSocket->sendTextMessage("test");
        }

}
</code>```

Body:
I'm following this example http://doc.qt.io/qt-5/qtwebsockets-echoserver-example.html but I can't figure out how to send a message to client after the connection has been made.

This seems to work but only when it's inside a function from another class.

void EchoServer::processTextMessage(QString message)
{

    m_clients.at(0)->sendTextMessage("test");

}

Where / How should I put the code to get it working?

e. g. How to send a message to client after a button has been pressed in MainWindow?

This is working

void EchoServer::processTextMessage(QString message)
{

      m_clients.at(0)->sendTextMessage("test");

}

This isn't working

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    m_clients.at(0)->sendTextMessage("test");

}

Neither this

void MainWindow::myclicked()
{

 m_clients.at(0)->sendTextMessage("test");

}

Body:
I got it working. Here is the code:

QWebSocket *messageSocket;

void EchoServer::onNewConnection()
{
    QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
    connect(pSocket, &QWebSocket::textMessageReceived, this, &EchoServer::processTextMessage);
    connect(pSocket, &QWebSocket::disconnected, this, &EchoServer::socketDisconnected);

    m_clients << pSocket;

    messageSocket=pSocket;
}

void MainWindow::myclicked()
{
    if (messageSocket)
        {

             messageSocket->sendTextMessage("test");
        }

}


问:
Stock of products during time
We need to create a query in which we will have the available stock of our products during next weeks.

We have 4 kind of orders-invoices.

a) Orders from suppliers which have an estimated delivery date

b) Invoices from suppliers which are being transformed from their orders and they also have a date

c) Orders for Clients with estimated execution date

d) Invoices for clients with a date

The a,b are going to add quantities to our table

The c,d are going to remove quantities from our table

For example:

We are currently on week 27 and we know that at 12 of July (week 28) we will receive 100 pcs of product A.

Then a client already pre-ordered 50 pcs with execution date 25 of July (week 30) , so we have an order which should reduce the quantity of product A at week 30.

If we are going to receive at 2 of August 100 pcs more, then on week 31 the table should show the estimated quantity by calculating:

```<code> Week27 - 0   pcs
 Week28 - 100 pcs (we will receive 100 pcs)
 Week29 - 100 pcs (nothing was sold)
 Week30 - 50  pcs (we will sell 50 pcs so the remaining quantity is 50)
 Week31 - 150 pcs (we will receive 100 pcs so the remaining quantity will be 150)
</code>```

答:
Found a solution which I think can work:

Firstly I created a View in our database named z_531 in which we collect all the nessecare rows with the product information and also Date etc.

Then I tried to make a cumulative sum in a query:

`SELECT    Date,Product,[Quantity A],[Date of Import export], [Week of import export], [Year of import export],Client,
                          (SELECT     SUM([Quantity A]) AS Expr1
                            FROM          dbo.z_531 AS b
                            WHERE      ([Wekk of Import Export] <= dbo.z_531.[Week of Import Export]) and ([Product] = dbo.z_531.[Product])) AS [Stock quantity]

FROM         dbo.z_531

ORDER BY [Product], [Date of Import Export]`

By adding in my sum Product = dbo.z_531.[Product] I have seperated sums per product and also by week.

Eventhough I think its not the quickest way to do it !

Title: Stock of products during time

Body:
We need to create a query in which we will have the available stock of our products during next weeks.

We have 4 kind of orders-invoices.

a) Orders from suppliers which have an estimated delivery date

b) Invoices from suppliers which are being transformed from their orders and they also have a date

c) Orders for Clients with estimated execution date

d) Invoices for clients with a date

The a,b are going to add quantities to our table

The c,d are going to remove quantities from our table

For example:

We are currently on week 27 and we know that at 12 of July (week 28) we will receive 100 pcs of product A.

Then a client already pre-ordered 50 pcs with execution date 25 of July (week 30) , so we have an order which should reduce the quantity of product A at week 30.

If we are going to receive at 2 of August 100 pcs more, then on week 31 the table should show the estimated quantity by calculating:

 Week27 - 0   pcs
 Week28 - 100 pcs (we will receive 100 pcs)
 Week29 - 100 pcs (nothing was sold)
 Week30 - 50  pcs (we will sell 50 pcs so the remaining quantity is 50)
 Week31 - 150 pcs (we will receive 100 pcs so the remaining quantity will be 150)


问:
Can a WCF Data Service be hosted by something other than IIS?
Is it possible to host a WCF Data Service with the ServiceHost class as you can with WCF services or Workflow Services? If not, what limits it from being hosted in that manner?</p>

答: Yes. You'll have the best luck with using the DataServiceHost as described in this MSDN reference page.

ContentLicense: CC BY-SA 2.5


问:
JDBC PreparedStatement default values on Insert (UCanAccess)
I was wondering how I can fetch the default values of newly inserted rows of MS Access via UCanAccess.

Table: my_tbl

```<code>Column   Type
-------+-----------------------
ID     | PrimaryKey, AutoNumber
Label  | Text
DT     | Date/Time, Default: Now()
</code>```

Code

```<code>PreparedStatement st = conn.prepareStatement("INSERT INTO my_tbl (Label) VALUES (?)", Statement.RETURN_GENERATED_KEYS);
st.setString(1, "my new label");

int insertResult = st.executeUpdate();
if(insertResult > 0) {
    ResultSet rs = st.getGeneratedKeys();
    rs.next();
    System.out.println("ID: " + rs.getInt(1));
}

//How do I get the generated value of DT
</code>```

Limitations

I cannot use the keyword DEFAULT because UCanAccess throws an SQLException (SO discussion about DEFAULT):

```<code>Caused by: org.hsqldb.HsqlException: DEFAULT keyword cannot be used as column has no DEFAULT
</code>```

Do you have another solution for me?

答:
How do I get the generated value of DT

You will need to use the value returned by rs.getInt(1) to execute another SELECT query of the form

SELECT DT FROM my_tbl WHERE ID = ?
```

and then retrieve the value from the ResultSet produced by calling executeQuery for that query.

Body:
I was wondering how I can fetch the default values of newly inserted rows of MS Access via UCanAccess.

Table: my_tbl

Column   Type
-------+-----------------------
ID     | PrimaryKey, AutoNumber
Label  | Text
DT     | Date/Time, Default: Now()

Code

PreparedStatement st = conn.prepareStatement("INSERT INTO my_tbl (Label) VALUES (?)", Statement.RETURN_GENERATED_KEYS);
st.setString(1, "my new label");

int insertResult = st.executeUpdate();
if(insertResult > 0) {
    ResultSet rs = st.getGeneratedKeys();
    rs.next();
    System.out.println("ID: " + rs.getInt(1));
}

//How do I get the generated value of DT

Limitations

I cannot use the keyword DEFAULT because UCanAccess throws an SQLException (SO discussion about DEFAULT):

Caused by: org.hsqldb.HsqlException: DEFAULT keyword cannot be used as column has no DEFAULT

Do you have another solution for me?

Body:
How do I get the generated value of DT

You will need to use the value returned by rs.getInt(1) to execute another SELECT query of the form

SELECT DT FROM my_tbl WHERE ID = ?

and then retrieve the value from the ResultSet produced by calling executeQuery for that query.


问:
I need my script to cycle through 3 corresponding arrays
Okay, this is going to need a little bit of explanation...

I'm making a reddit bot with praw, and I am storing topics, descriptions for the topic, and the user who submitted the top in a variable via an array.

Each week, the bot will post a new reddit thread which should contain 1 topic, and it's respective description and submitter.

What I need the script to do is cycle through the arrays without repeating any of the data, so that I don't get any repeat posts.

The bot will be on a scheduler that runs it every week, which is the part that is tripping me up, since normal methods won't permanently clear the options.

Optimally, I would want to store the code in another variable for each data type that I could use to put in the preset messages

Here's the variables:

```<code>#Question Databank
challengeTopicData = ('Command line', 'Choose your own theme', 'Memes', 'Glitch','No app drawer','Not minimal')
challengeDescriptionData = ('The best command-line/vintage computer theme','Choose a theme from given pool of choices and they will have to stick to it completely.','Make a theme from a meme. It\'s literally wide open - make the crappiest, low effort theme you can for 1 week only','Create a theme based around a glitch effect, whether it be the wallpaper, widget, or both','In this challenge you must create a homescreen with all of your icons on it, and show off your homescreen organization skills','Literally anything that can\'t be considered minimal')
challengeSubmitterData = ('-Tilde','thetinygoat','SuperScientistOfDoom','hallowaslosdu','inaforestgump','ssyynnxx')
</code>```

答:
Some thing along these lines, you can change your data to dicts or tuples however you like.</p>

```<code>def example():
    f1 = open("count.txt","r+")
    index = int(f1.read())
    data = [{'topic':'random topic 1', 'description':'random description 1', 'user': 'random user 1'}, {'topic':'random topic 2', 'description':'random description 2', 'user': 'random user 2'}]

    f1.seek(0,0)
    f1.write("%s" % index+1)
    f1.close()
    return data[index]
</code>```

Body:
Okay, this is going to need a little bit of explanation...

I'm making a reddit bot with praw, and I am storing topics, descriptions for the topic, and the user who submitted the top in a variable via an array.

Each week, the bot will post a new reddit thread which should contain 1 topic, and it's respective description and submitter.

What I need the script to do is cycle through the arrays without repeating any of the data, so that I don't get any repeat posts.

The bot will be on a scheduler that runs it every week, which is the part that is tripping me up, since normal methods won't permanently clear the options.

Optimally, I would want to store the code in another variable for each data type that I could use to put in the preset messages

Here's the variables:

#Question Databank
challengeTopicData = ('Command line', 'Choose your own theme', 'Memes', 'Glitch','No app drawer','Not minimal')
challengeDescriptionData = ('The best command-line/vintage computer theme','Choose a theme from given pool of choices and they will have to stick to it completely.','Make a theme from a meme. It\'s literally wide open - make the crappiest, low effort theme you can for 1 week only','Create a theme based around a glitch effect, whether it be the wallpaper, widget, or both','In this challenge you must create a homescreen with all of your icons on it, and show off your homescreen organization skills','Literally anything that can\'t be considered minimal')
challengeSubmitterData = ('-Tilde','thetinygoat','SuperScientistOfDoom','hallowaslosdu','inaforestgump','ssyynnxx')

Body:
Some thing along these lines, you can change your data to dicts or tuples however you like.

def example():
    f1 = open("count.txt","r+")
    index = int(f1.read())
    data = [{'topic':'random topic 1', 'description':'random description 1', 'user': 'random user 1'}, {'topic':'random topic 2', 'description':'random description 2', 'user': 'random user 2'}]

    f1.seek(0,0)
    f1.write("%s" % index+1)
    f1.close()
    return data[index]


问:
Is ANTLR available on QBasic?
I have just started studying about compiler design. And i have a little task to write a grammar on QBasic. But there are only few targeted languages on ANTLR. Is it possible on QBasic? Please anyone explain about this.</p>

答:
The biggest repository of ANTLR grammars I know of in one place is at this Github page.  And it doesn't look like QBasic is among them.

I've written a grammar/interpreter or three with BASIC-like syntax with domain-specific extensions (and no line numbers!) but it doesn't look like anyone has undertaken QBasic in ANTLR4, not publicly at least.

Title: Is ANTLR available on QBasic?


问:
SQL: exact row match given certain elements
this is my first time posting here. I don't seem to find the answer to my problem.

So... I'm arranging a DB for a school project, a cookbook that only shows recipes that can be made with existing elements from the "shelf".
These ingredients have to have an exact ingredients match.

user:

```<code>+---------------+------+----------+----------+
|     email     | name | lastname | password |
+---------------+------+----------+----------+
| pal@mail.com  | John | Potato   | password |
| they@mail.com | Mary | Carrot   | password |
+---------------+------+----------+----------+
</code>```

shelf:

```<code>+---------+------------+---------------+
| shelfID | ingredient |     user      |
+---------+------------+---------------+
|       1 |          1 | pal@mail.com  |
|       2 |          2 | pal@mail.com  |
|       3 |          3 | pal@mail.com  |
|       4 |          4 | pal@mail.com  |
|       5 |         10 | they@mail.com |
|       6 |         12 | they@mail.com |
+---------+------------+---------------+
</code>```

This is my recipe_ingredient relationship table

recipe_ingredient:

```<code>+--------+------------+
| recipe | ingredient |
+--------+------------+
|      1 |          1 |
|      1 |          2 |
|      1 |          4 |
|      1 |         10 |
|      2 |          1 |
|      2 |          2 |
|      2 |          3 |
|      2 |          4 |
|      3 |          2 |
|      3 |          3 |
|      3 |         15 |
+--------+------------+
</code>```

I've tried this query:

```<code>    SELECT
    rec_ing.recipe, shf.ingredient, shf.user
FROM
    recipes_ingredients AS rec_ing
        INNER JOIN
    shelf AS shf ON rec_ing.ingredient = shf.ingredient
        INNER JOIN
    users AS usr ON shf.user = usr.email
WHERE
    usr.email = 'pal@mail.com'
</code>```

that returns this table:

```<code>+--------+------------+--------------+
| recipe | ingredient |     user     |
+--------+------------+--------------+
|      1 |          1 | pal@mail.com |
|      1 |          2 | pal@mail.com |
|      1 |          4 | pal@mail.com |
|      2 |          1 | pal@mail.com |
|      2 |          2 | pal@mail.com |
|      2 |          3 | pal@mail.com |
|      2 |          4 | pal@mail.com |
|      3 |          2 | pal@mail.com |
|      3 |          3 | pal@mail.com |
+--------+------------+--------------+
</code>```

Although it's true that the Recipe 1 contains ingredients from my shelf, it's also missing Ingredient 10

```<code>+--------+------------+
| recipe | ingredient |
+--------+------------+
|      1 |          1 |
|      1 |          2 |
|      1 |          4 |
|      1 |         10 |
|    ... |        ... |
+--------+------------+
</code>```

I'm trying to only get this kind of result set.

```<code>+--------+------------+
| recipe | ingredient |
+--------+------------+
|      2 |          1 |
|      2 |          2 |
|      2 |          3 |
|      2 |          4 |
+--------+------------+
</code>```

Because Recipe 2 contains all elements from my shelf

I have been going around all day with this problem ... What could be missing?

答:
This is a bit tricky, because you need to aggregate your current query by recipe, but you also need the original query to get back the full records.  Sadly, MySQL does not support common table exprrssions or other features which could give us a less verbose query.

```<code>SELECT
    rec_ing.recipe,
    shf.ingredient,
    shf.user
FROM recipes_ingredients AS rec_ing
INNER JOIN shelf AS shf
    ON rec_ing.ingredient = shf.ingredient
INNER JOIN users AS usr
    ON shf.user = usr.email
INNER JOIN
(
    SELECT rec_ing.recipe
    FROM recipes_ingredients AS rec_ing
    INNER JOIN shelf AS shf
        ON rec_ing.ingredient = shf.ingredient
    LEFT JOIN users AS usr
        ON shf.user = usr.email
    WHERE
        usr.email = 'pal@mail.com'
    GROUP BY rec_ing.recipe
    HAVING COUNT(usr.email) = COUNT(*)
) t
    ON rec_ing.recipe = t.recipe
WHERE
    usr.email = 'pal@mail.com'
</code>```

The basic strategy here is to just do one additional join to a subquery which identifies all recipes where every ingredient belongs to a given user.  The critical part is the following:

```<code>HAVING COUNT(usr.email) = COUNT(*)
</code>```

This checks that the total number of rows for a given recipe matches the number of rows which have been assigned to a given user.

Body:
this is my first time posting here. I don't seem to find the answer to my problem.

So... I'm arranging a DB for a school project, a cookbook that only shows recipes that can be made with existing elements from the "shelf".
These ingredients have to have an exact ingredients match.

user:

+---------------+------+----------+----------+
|     email     | name | lastname | password |
+---------------+------+----------+----------+
| pal@mail.com  | John | Potato   | password |
| they@mail.com | Mary | Carrot   | password |
+---------------+------+----------+----------+

shelf:

+---------+------------+---------------+
| shelfID | ingredient |     user      |
+---------+------------+---------------+
|       1 |          1 | pal@mail.com  |
|       2 |          2 | pal@mail.com  |
|       3 |          3 | pal@mail.com  |
|       4 |          4 | pal@mail.com  |
|       5 |         10 | they@mail.com |
|       6 |         12 | they@mail.com |
+---------+------------+---------------+

This is my recipe_ingredient relationship table

recipe_ingredient:

+--------+------------+
| recipe | ingredient |
+--------+------------+
|      1 |          1 |
|      1 |          2 |
|      1 |          4 |
|      1 |         10 |
|      2 |          1 |
|      2 |          2 |
|      2 |          3 |
|      2 |          4 |
|      3 |          2 |
|      3 |          3 |
|      3 |         15 |
+--------+------------+

I've tried this query:

    SELECT
    rec_ing.recipe, shf.ingredient, shf.user
FROM
    recipes_ingredients AS rec_ing
        INNER JOIN
    shelf AS shf ON rec_ing.ingredient = shf.ingredient
        INNER JOIN
    users AS usr ON shf.user = usr.email
WHERE
    usr.email = 'pal@mail.com'

that returns this table:

+--------+------------+--------------+
| recipe | ingredient |     user     |
+--------+------------+--------------+
|      1 |          1 | pal@mail.com |
|      1 |          2 | pal@mail.com |
|      1 |          4 | pal@mail.com |
|      2 |          1 | pal@mail.com |
|      2 |          2 | pal@mail.com |
|      2 |          3 | pal@mail.com |
|      2 |          4 | pal@mail.com |
|      3 |          2 | pal@mail.com |
|      3 |          3 | pal@mail.com |
+--------+------------+--------------+

Although it's true that the Recipe 1 contains ingredients from my shelf, it's also missing Ingredient 10

+--------+------------+
| recipe | ingredient |
+--------+------------+
|      1 |          1 |
|      1 |          2 |
|      1 |          4 |
|      1 |         10 |
|    ... |        ... |
+--------+------------+

I'm trying to only get this kind of result set.

+--------+------------+
| recipe | ingredient |
+--------+------------+
|      2 |          1 |
|      2 |          2 |
|      2 |          3 |
|      2 |          4 |
+--------+------------+

Because Recipe 2 contains all elements from my shelf

I have been going around all day with this problem ... What could be missing?

Body:
This is a bit tricky, because you need to aggregate your current query by recipe, but you also need the original query to get back the full records.  Sadly, MySQL does not support common table exprrssions or other features which could give us a less verbose query.

SELECT
    rec_ing.recipe,
    shf.ingredient,
    shf.user
FROM recipes_ingredients AS rec_ing
INNER JOIN shelf AS shf
    ON rec_ing.ingredient = shf.ingredient
INNER JOIN users AS usr
    ON shf.user = usr.email
INNER JOIN
(
    SELECT rec_ing.recipe
    FROM recipes_ingredients AS rec_ing
    INNER JOIN shelf AS shf
        ON rec_ing.ingredient = shf.ingredient
    LEFT JOIN users AS usr
        ON shf.user = usr.email
    WHERE
        usr.email = 'pal@mail.com'
    GROUP BY rec_ing.recipe
    HAVING COUNT(usr.email) = COUNT(*)
) t
    ON rec_ing.recipe = t.recipe
WHERE
    usr.email = 'pal@mail.com'

The basic strategy here is to just do one additional join to a subquery which identifies all recipes where every ingredient belongs to a given user.  The critical part is the following:

HAVING COUNT(usr.email) = COUNT(*)

This checks that the total number of rows for a given recipe matches the number of rows which have been assigned to a given user.


问:
Using prototype in javascript
I have defined a couple of functions inside my javascript which work perfectly, but when I put it inside a prototype it just doesn't seem to work.

wall.html:

```<code><script type="text/javascript" src="Jquery/jquery-1.4.4.js"> </script>
<script type="text/javascript" src="src/CommentManager.js"> </script>
<script type="text/javascript" src="src/Reply.js"> </script>
<script type="text/javascript" src="src/Comment.js"> </script>
<script type="text/javascript">
    $(document).ready(function(){
        CommentManager();
        $("form#newMessage").submit(function(){
            var message = $("input#newMessageTxt").val();
            var newComment = new Comment(message);
        });
    });
</script>
</head>

<body>
    <div class="message">
        <form id="newMessage">>
            <input type="text" id="newMessageTxt" height="200px" value="Write a message" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
            <input type="submit" value="Submit" ></button>
        </form>
    </div>
</body>
</code>```

but the weird part is when I run the debugging tool in googlechrome, the $("form#newMessage").submit doesn't call at all. So Comment(message) is never created (which is where I have set up the prototype functions)

Comment.js:

```<code>function Comment(message){
    var self = this;
    var message = message;

    var comment = document.createElement("li");
    comment.id = "comment";
    comment.textContent = message;
    //empty reply field
    var replyField = document.createElement("ul");
    replyField.id = "replyField";
    //create the appropriate buttons
    createButtons(comment);
    //append the replyField
    comment.appendChild(replyField);
    //insert into wall
    addComment(comment);
    //effect after insertion
    Effect(comment);
    $(comment).mouseleave(function() {mouseOut(comment);});
    $(comment).mouseenter(function() {mouseOver(comment);});
    return comment;
}
Comment.prototype={
    deleteComment : function (comment){
        $(comment).fadeOut();
        setTimeout(function() {comment.parentNode.removeChild(comment);},500);
    },
//there are more methods here
}
</code>```

Commentmanager.js:

```<code>function CommentManager(){
    var owner = null;

    var wall = document.createElement("ul");
    wall.id = "wall";

    document.body.appendChild(wall);
    return wall;
}

function addComment(comment){
    var wall = document.getElementById("wall");
    wall.appendChild(comment);
}
</code>```

答:
Where is createButtons defined?  (in Comment.js)?

Also, you you titled that last file as Commentmanager.js, but wall.html has CommentManager.js (notice the capital M in wall.js). I'm assuming that's a typo here in the SO question, but make sure that your filenames on the server match the html script tags.

Title: Using prototype in javascript

Body:
I have defined a couple of functions inside my javascript which work perfectly, but when I put it inside a prototype it just doesn't seem to work.

wall.html:

        <form id="newMessage">>
            <input type="text" id="newMessageTxt" height="200px" value="Write a message" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
            <input type="submit" value="Submit" ></button>
        </form>

but the weird part is when I run the debugging tool in googlechrome, the $("form#newMessage").submit doesn't call at all. So Comment(message) is never created (which is where I have set up the prototype functions)

Comment.js:

function Comment(message){
    var self = this;
    var message = message;

    var comment = document.createElement("li");
    comment.id = "comment";
    comment.textContent = message;
    //empty reply field
    var replyField = document.createElement("ul");
    replyField.id = "replyField";
    //create the appropriate buttons
    createButtons(comment);
    //append the replyField
    comment.appendChild(replyField);
    //insert into wall
    addComment(comment);
    //effect after insertion
    Effect(comment);
    $(comment).mouseleave(function() {mouseOut(comment);});
    $(comment).mouseenter(function() {mouseOver(comment);});
    return comment;
}
Comment.prototype={
    deleteComment : function (comment){
        $(comment).fadeOut();
        setTimeout(function() {comment.parentNode.removeChild(comment);},500);
    },
//there are more methods here
}

Commentmanager.js:

function CommentManager(){
    var owner = null;

    var wall = document.createElement("ul");
    wall.id = "wall";

    document.body.appendChild(wall);
    return wall;
}

function addComment(comment){
    var wall = document.getElementById("wall");
    wall.appendChild(comment);
}


问:
Cannot 'GET' mLab Data b/c of CORS
I can't execute the 'GET' request with the getTasks() function.

```<code>$(document).ready(function(){
    getTasks();
});

const apiKey = 'xxxxxxx';

function getTasks(){
    $.ajax({
        type: 'GET',
        url: 'https://api.mlab.com/api/1/databases/taskmanager/collections/tasks?apiKey='+apiKey,
        contentType: 'application/json',
        xhrFields: {
            withCredentials: true
        },
        success: function(data){
            console.log(data);
        },
        error: function(){
            console.log('FAIL')
        }
    })
}
</code>```

The error that I get is:

api.mlab.com/api/1/databases/taskmanager/collections/tasks?apiKey=xxxxxxx
  Failed to load resource: the server responded with a status of 400
  (Bad Request)

Response to preflight request doesn't pass access control check: No
  'Access-Control-Allow-Origin' header is present on the requested
  resource. Origin 'null' is therefore not allowed access. The response
  had HTTP status code 400.

I understand that Google-Chrome on Windows is CORS enabled, and will not (by default) allow communication with a different domain.  I'm not sure what a preflight request is. Regardless, I tried to implement what I saw from Using CORS - HTML5 Rocks (from the CORS from jQuery section), but to no avail.

答:
At a guess, the remote API simply does not respond to pre-flight requests for GET calls (because it shouldn't have to).

Your code is triggering a pre-flight request because it is non-simple. This is due to your adding a Content-type: application/json header. A request Content-type header is used to indicate the request payload format. As it is a GET, there is no payload.

Try this instead...

```<code>$.getJSON('https://api.mlab.com/api/1/databases/taskmanager/collections/tasks', {
  apiKey: apiKey
}).done(function(data) {
  console.log(data)
}).fail(function() {
  console.log('FAIL')
})
</code>```

Title: Cannot 'GET' mLab Data b/c of CORS

Body:
I can't execute the 'GET' request with the getTasks() function.

$(document).ready(function(){
    getTasks();
});

const apiKey = 'xxxxxxx';

function getTasks(){
    $.ajax({
        type: 'GET',
        url: 'https://api.mlab.com/api/1/databases/taskmanager/collections/tasks?apiKey='+apiKey,
        contentType: 'application/json',
        xhrFields: {
            withCredentials: true
        },
        success: function(data){
            console.log(data);
        },
        error: function(){
            console.log('FAIL')
        }
    })
}

The error that I get is:

api.mlab.com/api/1/databases/taskmanager/collections/tasks?apiKey=xxxxxxx
  Failed to load resource: the server responded with a status of 400
  (Bad Request)

Response to preflight request doesn't pass access control check: No
  'Access-Control-Allow-Origin' header is present on the requested
  resource. Origin 'null' is therefore not allowed access. The response
  had HTTP status code 400.

I understand that Google-Chrome on Windows is CORS enabled, and will not (by default) allow communication with a different domain.  I'm not sure what a preflight request is. Regardless, I tried to implement what I saw from Using CORS - HTML5 Rocks (from the CORS from jQuery section), but to no avail.

Body:
At a guess, the remote API simply does not respond to pre-flight requests for GET calls (because it shouldn't have to).

Your code is triggering a pre-flight request because it is non-simple. This is due to your adding a Content-type: application/json header. A request Content-type header is used to indicate the request payload format. As it is a GET, there is no payload.

Try this instead...

$.getJSON('https://api.mlab.com/api/1/databases/taskmanager/collections/tasks', {
  apiKey: apiKey
}).done(function(data) {
  console.log(data)
}).fail(function() {
  console.log('FAIL')
})


问:
Windows Installer Project in Visual Studio 2017
I've been learning about deployment of various application types (eg. console applications, windows service applications, windows forms, wpf etc) built using Visual Studio 2017.

In particular I was looking at what I understand are referred to as Setup and Deployment Projects or Windows Installer Setup Projects: https://msdn.microsoft.com/en-au/library/wx3b589t(v=vs.100).aspx

I couldn't locate the Setup and Deployment Projects in Visual Studio 2017 at first. However I located an extension to Visual Studio from Microsoft called Microsoft Visual Studio 2017 Installer Projects
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2017InstallerProjects

After installing the extension for Visual Studio I could locate Visual Studio Installer under Other Project Types in the Add New Project window. I haven't been able to successfully build an installer however for a project however.

On different occasions and with different solutions using a standard default Windows Form project or a default console application, when I right click the Setup project in the Solution Explorer Window and select build the following happens:

A dialog window relating to SQL Management Studio appears with the following

Please wait while Windows configures SQL Server 2008 R2 SP2 Management Studio.

On top of that dialog window a further dialog window appears with:

0: Watson 1: 1304 2: STreamSupportFiles 3:streamBinaryToDisk 4:5
5:e:\sql10_main_t\sql\setup\darmwin\sqlcastub\streamca.cpp
6:238 7:sqlcastub.dll 8:sqlrun.msi

and an ok button.

If i pres the ok button on the dialog identified in 2 I end up with a further dialog with a title of SQL Server 2008 R2 SP2 Management Studio. The content of the window is:

Error writing to file: Access is denied.
Verify that you have access to that directory.
An OK button appears in the window.

I'm not sure what "that" directory actually refers to in this context as it wasn't expected.

If I click Ok on the dialog window then I see a Windows Installer dialog window with the message "Preparing to Install" and a cancel button.

After a prolonged period with nothing seemingly occurring, and the Visual Studio main window  now having (not responding) as part of its title I ultimately end up clicking the cancel button on the Windows installer dialog. This results in the installer freezing and ultimately either Visual Studio crashes or has become so unresponsive that I end up terminating it with the task manager.

I watched a video in which someone had built a Setup Project for a Windows Service and at no stage did i see the Windows relating to SQL Server or the Windows Installer Preparing to Install window. I didnt expect to receive any of the mentioned windows, nor Visual Studio to become unresponsive and essentially crash.

I went to Tools > Options > Projects and Solutions and changed the MS build output and log verbosity to Diagnostic, but didnt find anything related to SQL Server 2008.

Does anyone have any thoughts as to what may be causing this and how I could resolve?

Further, should I perhaps be looking at some other solution/tool to be used for deployment purposes instead of the Setup and Deployment projects? Given the nature of the question instead of leaving it at just this perhaps some other questions :
1. Are Setup and Deployment projects still a tool/solution actively used by other developers? If so, are they extensively used? Or how extensively are they used relatively to other technologies/tools/solutions for deployment?

答:
The problem was resolved on an x64 system by running:</p>
```<code>regsvr32.exe /u "C:\Program Files (x86)\Common Files\microsoft shared\MSI Tools\mergemod.dll"
regsvr32.exe "C:\Program Files (x86)\Common Files\microsoft shared\MSI Tools\mergemod.dll"
</code>```

Body:
The problem was resolved on an x64 system by running:

regsvr32.exe /u "C:\Program Files (x86)\Common Files\microsoft shared\MSI Tools\mergemod.dll"
regsvr32.exe "C:\Program Files (x86)\Common Files\microsoft shared\MSI Tools\mergemod.dll"

ContentLicense: CC BY-SA 4.0


问:
Javascript while loop waits for increment instead of becoming an infinite loop
Right now in my nodejs socket.io 'game' I would like to cycle through all users currently online*, each having their opportunity to be a leader and click a button that would sequentially make the next user the leader (to, again, click a button that makes the next user the leader. You get the idea). My issue is that when I make the while loop wait for the 'leader' socket to trigger the leaderSelection event to increment the while loop, the while loop instead creates an infinite loop, crashing my browser. Simply put, how can I make a while loop wait (a theoretically infinite amount of time) until it gets incremented, instead of running infinitely. Hopefully this was clear enough. Here's my code: </p>

```<code>while(i < ids.length) { //Go through all ids one by one
        //Select current id and make that person the leader
        socket.broadcast.to(ids[i]).emit('leader', { message: 'You are the leader for this round', options: 'THIS WOULD BE A SELECTION BUTTON FOR THE leaderSelection EVENT LISTENER'});
        //Loop through all the other people that are not the leader and say they are the users for this round
        for(var e = 0; e < ids.length; e++) {
            if(i == e) { //Skip current leader
                console.log('skipped ' + usernames[i]);
                continue;
            }
            socket.broadcast.to(ids[e]).emit('user', { message: 'You are a user for this round'});
        }
        //When the leader socket clicks the 'select' button, the while loop will go to the next person to be a leader
        socket.on('leaderSelection', function(data) {
            i++; //Here is the issue, the while loop crashes my browser trying to wait for the increment.
        });
    }
</code>```

答:
You can't do this in a while loop, Javascript just doesn't work that way.  A possible alternative approach:</p>

```<code>// Notify the current leader
function notifyLeader(leader) {
    socket.broadcast.to(leader).emit('leader', { message: 'You are the leader for this round', options: 'THIS WOULD BE A SELECTION BUTTON FOR THE leaderSelection EVENT LISTENER'});
}

// Notify all users except the leader
function notifyUsers(users, leader) {
    users
    .filter(user => user !== leader)
    .forEach(user => {
        socket.broadcast.to(user).emit('user', { message: 'You are a user for this round'});
    });
}

// In a round of play, notify the leaders and users
// When the leaderSelection event comes in, start a new round
// with the next leader
function startRound(ids, leaderIndex) {
    notifyLeader(ids[index]);
    notifyUsers(ids, leaderIndex);
    socket.once('leaderSelection', () => {
        startRound(ids, ++leaderIndex);
    });
}

// Start the first round with leader 0
startRound(ids, 0);
</code>```

Body:
Right now in my nodejs socket.io 'game' I would like to cycle through all users currently online*, each having their opportunity to be a leader and click a button that would sequentially make the next user the leader (to, again, click a button that makes the next user the leader. You get the idea). My issue is that when I make the while loop wait for the 'leader' socket to trigger the leaderSelection event to increment the while loop, the while loop instead creates an infinite loop, crashing my browser. Simply put, how can I make a while loop wait (a theoretically infinite amount of time) until it gets incremented, instead of running infinitely. Hopefully this was clear enough. Here's my code:

while(i < ids.length) { //Go through all ids one by one
        //Select current id and make that person the leader
        socket.broadcast.to(ids[i]).emit('leader', { message: 'You are the leader for this round', options: 'THIS WOULD BE A SELECTION BUTTON FOR THE leaderSelection EVENT LISTENER'});
        //Loop through all the other people that are not the leader and say they are the users for this round
        for(var e = 0; e < ids.length; e++) {
            if(i == e) { //Skip current leader
                console.log('skipped ' + usernames[i]);
                continue;
            }
            socket.broadcast.to(ids[e]).emit('user', { message: 'You are a user for this round'});
        }
        //When the leader socket clicks the 'select' button, the while loop will go to the next person to be a leader
        socket.on('leaderSelection', function(data) {
            i++; //Here is the issue, the while loop crashes my browser trying to wait for the increment.
        });
    }

Body:
You can't do this in a while loop, Javascript just doesn't work that way.  A possible alternative approach:

// Notify the current leader
function notifyLeader(leader) {
    socket.broadcast.to(leader).emit('leader', { message: 'You are the leader for this round', options: 'THIS WOULD BE A SELECTION BUTTON FOR THE leaderSelection EVENT LISTENER'});
}

// Notify all users except the leader
function notifyUsers(users, leader) {
    users
    .filter(user => user !== leader)
    .forEach(user => {
        socket.broadcast.to(user).emit('user', { message: 'You are a user for this round'});
    });
}

// In a round of play, notify the leaders and users
// When the leaderSelection event comes in, start a new round
// with the next leader
function startRound(ids, leaderIndex) {
    notifyLeader(ids[index]);
    notifyUsers(ids, leaderIndex);
    socket.once('leaderSelection', () => {
        startRound(ids, ++leaderIndex);
    });
}

// Start the first round with leader 0
startRound(ids, 0);


问:
Create Add-in for Acrobat Reader - PDF
Can i create an Add-in for Acrobat Reader? (something like Office Add-ins in visual studio)
for example, i open a pdf file with Acrobat Reader, i want to add my custom button in the Reader in order to perform a specific action.

Is it doable?

Is it Free?

Does it require third-party components?

Thanks.

答:
Download source code for a GNU-licensed PDF readerlike Evince or Okular and fork it to your heart's content.  With some massaging they can be compiled into Win32 binaries (probably requiring lots of libraries from their Linux counterparts, but still do-able).

Okular source code:

https://github.com/KDE/okular

Evince source code:

https://github.com/GNOME/evince

Title: Create Add-in for Acrobat Reader - PDF


问:
What JWT claims from Azure AD tokens can be safely used for user mappings?
We use OAuth 2.0 to obtain JWT tokens from an Azure AD. In our application, we have used the value of the 'upn' claim to identify an associated internal username.

The Azure AD Token Reference documents the upn claim as a "User Principal Name", which as far as I understand is a username following the addr-spec format (i.e. user@domain). This works well for users created within the Azure AD Tenant. To my surprise, however, the upn claim seems to be gone if the authenticated user is sync'ed from a different AD. This behavior does not seem to be documented anywhere.

Where can I find documentation on when the upn is guaranteed to be in a token?

What are reliable alternative claims that I can use instead? Preferably claims guaranteed to be of the form "user/domain", as that matches our model best. I have considered the following:

unique_name: I have only observed this to be equal to upn, but I am not sure where it comes from. Confusingly, the token reference says: This value is not guaranteed to be unique within a tenant and is designed to be used only for display purposes. (emphasis mine)

email: This too seems to be equal to upn, but again, where is it sourced from? In the management portal, I have tried putting a different value in every email related field associated with the user, but none of them seem to be propagated to this claim. It therefore appears that this field is not actually an email.

I want to be absolutely sure that our application will be able to handle all tokens issued by Azure AD, so I am hesitant to use any of the above claims unless I have some documentation that explains their actual semantics.

答: While it is fairly common for a User’s UPN and primary email address to be the same thing, that isn’t guaranteed (nor is the existence of UPN as you’ve noticed). So you should operate under the assumption that UPN != email address. If you need to know the email address, you should make a Graph call and search using the oid.</p>


问:
Faking a ASP.NET Page
I have a situation where my web application sits and waits for a request sent to a specific web page designated for that source. For example source1 makes a request to myapplication/source1.aspx and source 2 makes a request to myapplication/source2.aspx. I was wondering if it is possible to have it so that instead have having 10 different .aspx pages actually out sitting waiting for requests, if I could somehow configure my application to "fake" that those pages exist and actually have a single page to process the requests.

So basically source1 would post to the URL of myapplication/source1.aspx but my application interprets that and sends it on to the main processing page. The one catch is that the main page needs to also know which source it came from.

I cannot rely on the source being able to post to myapplication/processPage?Source=Source1 so that I could then figure out from the query string which source sent what.

I hope all of this made sense, please let me know if you need further clarification. Thank you for your help.

答:
One idea would be to create a custom handler, then map to the expected requests.  Here is a link for more information on handlers.

Pay special attention to the configuration that goes into your web.config for each handler.  The path that is defined does not have to be a path that exists.

One nice trick is to place your handler configuration within a  grouping within your web.config.  That way you can have various "virtual" paths within your application for handling different scenarios.

Title: Faking a ASP.NET Page


问:
Turning an array into a multidimensional array? Javascript
I am struggling to create a simple function that will taking an array such as

```<code>["chicken","10 lbs","hot sauce","4 cups","celery","1 stalk"]
</code>```

and turn it into a multidimensional array that looks like this

```<code>[["chicken","10 lbs"],["hot sauce","4 cups"],["celery","1 stalk"]]
</code>```

essentially index 0 and 1 merge into a new sub array then 2 and 3 merge and so on...

i am trying for loops where i increases +2 but i can't get it quite right, i thought this would be a simple solution but the loops i've made so far are almost crashing my browser...any help would be appreciated. thanks

EDIT:  WOW Thanks for all the rapid responses!  I looked at everything and learned a lot!

答:
Just another way to do this using .reduce():

var array = ["chicken","10 lbs","hot sauce","4 cups","celery","1 stalk"];

var array2d = array.reduce((array, element, index) => {
  if (index % 2 > 0) {
    array.push(array.pop().concat([element]));
  } else {
    array.push([element]);
  }

  return array;
}, []);

console.log(array2d);```
</div>
</div>
</p>

<p>A more generic method that could be used might look like the following:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function group(amount) {
  return (array) => array
    .reduce((array, element, index) => {
      if (index % amount > 0) {
        array.push(array.pop().concat([element]));
      } else {
        array.push([element]);
      }

      return array;
    }, []);
}

var a = ["chicken","10 lbs","hot sauce","4 cups","celery","1 stalk"];
var b = ["chicken","10","lbs","hot sauce","4","cups","celery","1","stalk"];
var group2 = group(2);
var group3 = group(3);
var a2d = group2(a);
var b2d = group3(b);

console.log(a2d);
console.log(b2d);</code>```

Body:
I am struggling to create a simple function that will taking an array such as

["chicken","10 lbs","hot sauce","4 cups","celery","1 stalk"]

and turn it into a multidimensional array that looks like this

[["chicken","10 lbs"],["hot sauce","4 cups"],["celery","1 stalk"]]

essentially index 0 and 1 merge into a new sub array then 2 and 3 merge and so on...

i am trying for loops where i increases +2 but i can't get it quite right, i thought this would be a simple solution but the loops i've made so far are almost crashing my browser...any help would be appreciated. thanks

EDIT:  WOW Thanks for all the rapid responses!  I looked at everything and learned a lot!

Body:
Just another way to do this using .reduce():

var array = ["chicken","10 lbs","hot sauce","4 cups","celery","1 stalk"];

var array2d = array.reduce((array, element, index) => {
  if (index % 2 > 0) {
    array.push(array.pop().concat([element]));
  } else {
    array.push([element]);
  }

  return array;
}, []);

console.log(array2d);

A more generic method that could be used might look like the following:

function group(amount) {
  return (array) => array
    .reduce((array, element, index) => {
      if (index % amount > 0) {
        array.push(array.pop().concat([element]));
      } else {
        array.push([element]);
      }

      return array;
    }, []);
}

var a = ["chicken","10 lbs","hot sauce","4 cups","celery","1 stalk"];
var b = ["chicken","10","lbs","hot sauce","4","cups","celery","1","stalk"];
var group2 = group(2);
var group3 = group(3);
var a2d = group2(a);
var b2d = group3(b);

console.log(a2d);
console.log(b2d);


问:
C# deserialize xml using linq
I have the following xml file

```<code><?xml version="1.0" encoding="utf-8"?>
<Launchpad>
  <Shortcuts>
    <Shortcut Id="1">
      <Type>Folder</Type>
       <FullPath>C:\bla\bla\bla</FullPath>
       <Name>Proximity</Name>
    </Shortcut>
    <Shortcut Id="2">
      <Type>Folder</Type>
      <FullPath>C:\bla</FullPath>
      <Name>Visual Studio 2017</Name>
    </Shortcut>
  </Shortcuts>
</Launchpad>
</code>```

I am trying to deserialize to an object like this: (Tried query syntax first, didn't work either)

```<code>XDocument xd = XDocument.Load(FullPath);

// query syntax
//var shortcuts = (from s in xd.Descendants("Shortcuts")
//                 select new Shortcut()
//                 {
//                   Id = Convert.ToInt32(s.Attribute("Id")),
//                   TypeOfLink = GetTypeFromString(s.Descendants("Type")
//                                .First()
//                                .Value),
//                   FullPathToTarget = s.Descendants("FullPath")
//                                         .First()
//                                         .Value,
//                   Name = s.Descendants("Name").First().Value,
//                 }).ToList();

// method syntax
List<Shortcut> shortcuts = xd.Descendants("Shortcuts")
                             .Select(s =>
               new Shortcut()
               {
                 //Id = Convert.ToInt32(s.Attribute("Id")),
                 TypeOfLink = GetTypeFromString(s.Descendants("Type")
                                                 .First().Value),
                 FullPathToTarget = s.Descendants("FullPath")
                                                 .First().Value,
                 Name = s.Descendants("Name")
                         .First().Value,
               }).ToList();
return shortcuts;
</code>```

For some reason I only get a single shortcut object in the list. Also, for some reason, the s.Attribute("Id") is null.

If anyone has any suggestions to improve the linq query or why the attribute is not working it would be a great help

答:
You have to read .Descendants("Shortcut") instead of .Descendants("Shortcuts").
Something like this:</p>

```<code>List<Shortcut> shortcuts = xd.Descendants("Shortcut").Select(s =>
                       new Shortcut()
                       {
                           Id = s.Attribute("Id").Value,
                           TypeOfLink = s.Descendants("Type").First().Value,
                           FullPathToTarget = s.Descendants("FullPath").First().Value,
                           Name = s.Descendants("Name").First().Value,
                       }).ToList();
</code>```

Title: C# deserialize xml using linq

Body:
I have the following xml file

<?xml version="1.0" encoding="utf-8"?>
<Launchpad>
  <Shortcuts>
    <Shortcut Id="1">
      <Type>Folder</Type>
       <FullPath>C:\bla\bla\bla</FullPath>
       <Name>Proximity</Name>
    </Shortcut>
    <Shortcut Id="2">
      <Type>Folder</Type>
      <FullPath>C:\bla</FullPath>
      <Name>Visual Studio 2017</Name>
    </Shortcut>
  </Shortcuts>
</Launchpad>

I am trying to deserialize to an object like this: (Tried query syntax first, didn't work either)

XDocument xd = XDocument.Load(FullPath);

// query syntax
//var shortcuts = (from s in xd.Descendants("Shortcuts")
//                 select new Shortcut()
//                 {
//                   Id = Convert.ToInt32(s.Attribute("Id")),
//                   TypeOfLink = GetTypeFromString(s.Descendants("Type")
//                                .First()
//                                .Value),
//                   FullPathToTarget = s.Descendants("FullPath")
//                                         .First()
//                                         .Value,
//                   Name = s.Descendants("Name").First().Value,
//                 }).ToList();

// method syntax
List<Shortcut> shortcuts = xd.Descendants("Shortcuts")
                             .Select(s =>
               new Shortcut()
               {
                 //Id = Convert.ToInt32(s.Attribute("Id")),
                 TypeOfLink = GetTypeFromString(s.Descendants("Type")
                                                 .First().Value),
                 FullPathToTarget = s.Descendants("FullPath")
                                                 .First().Value,
                 Name = s.Descendants("Name")
                         .First().Value,
               }).ToList();
return shortcuts;

For some reason I only get a single shortcut object in the list. Also, for some reason, the s.Attribute("Id") is null.

If anyone has any suggestions to improve the linq query or why the attribute is not working it would be a great help

Body:
You have to read .Descendants("Shortcut") instead of .Descendants("Shortcuts").
Something like this:

List<Shortcut> shortcuts = xd.Descendants("Shortcut").Select(s =>
                       new Shortcut()
                       {
                           Id = s.Attribute("Id").Value,
                           TypeOfLink = s.Descendants("Type").First().Value,
                           FullPathToTarget = s.Descendants("FullPath").First().Value,
                           Name = s.Descendants("Name").First().Value,
                       }).ToList();


问:
Google Calendar API Invalid value for start-min parameter
I am using the exact examples from the Google Calendar API in C#:
            string calendarURI = this.CalendarURI.Text;
            string userName =    this.UserName.Text;
            string passWord =    this.Password.Text;

```<code>        this.entryList = new ArrayList(50);
        ArrayList dates = new ArrayList(50);
        EventQuery query = new EventQuery();
        CalendarService service = new CalendarService("CalendarSampleApp");

        if (userName != null && userName.Length > 0)
        {
            service.setUserCredentials(userName, passWord);
        }

        // only get event's for today - 1 month until today + 1 year

        query.Uri = new Uri(calendarURI);

        query.StartTime = DateTime.Now.AddDays(-28);
        query.EndTime = DateTime.Now.AddMonths(6);

        EventFeed calFeed = service.Query(query) as EventFeed;
        Console.WriteLine(query.Uri);
</code>```

This is copied from the examples, but when I run it I get:

Execution of request failed: http://www.google.com/calendar/feeds/default/private/full?start-min=2010-11-19T23:58:20+01:00&start-max=2011-06-17T23:58:20+02:00

Which is the message

Invalid value for start-min parameter: 2010-11-19T23:58:20 01:00

What am I doing wrong?

答: I guess the problem solved itself, now I don't get that error anymore...</p>

Body:
I am using the exact examples from the Google Calendar API in C#:
            string calendarURI = this.CalendarURI.Text;
            string userName =    this.UserName.Text;
            string passWord =    this.Password.Text;

        this.entryList = new ArrayList(50);
        ArrayList dates = new ArrayList(50);
        EventQuery query = new EventQuery();
        CalendarService service = new CalendarService("CalendarSampleApp");

        if (userName != null && userName.Length > 0)
        {
            service.setUserCredentials(userName, passWord);
        }

        // only get event's for today - 1 month until today + 1 year

        query.Uri = new Uri(calendarURI);

        query.StartTime = DateTime.Now.AddDays(-28);
        query.EndTime = DateTime.Now.AddMonths(6);

        EventFeed calFeed = service.Query(query) as EventFeed;
        Console.WriteLine(query.Uri);

This is copied from the examples, but when I run it I get:

Execution of request failed: http://www.google.com/calendar/feeds/default/private/full?start-min=2010-11-19T23:58:20+01:00&start-max=2011-06-17T23:58:20+02:00

Which is the message

Invalid value for start-min parameter: 2010-11-19T23:58:20 01:00

What am I doing wrong?


问:
Angular 2 - init a session service before guard kicks in
So I have this guard to watch my protected routes on my app
Basically, my session service extracts its credentials from localStorage inside NgOnInit, and then the guard should ask the service if it has credentials so it will know if it should approve this route

```<code>import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import { SessionService } from './../session/session.service'

@Injectable()
export class AuthGuard implements CanActivate {

    constructor(
    private router: Router,
    private sessionService: SessionService
    ) { }

    canActivate() {
        //without this line this won't work
        //this.sessionService.loadUser();
        if (this.sessionService.isValidSession()) {
            // logged in so return true
            return true;
        }

        // not logged in so redirect to login page
        this.router.navigate(['/login']);
        return false;
    }
}
</code>```

this is my session service:

```<code>export class SessionService implements OnInit {
 .
 .
 .
constructor(
    private authService: AuthenticationService,
) {
    this.timeout = null;
}

ngOnInit() {
    this.loadUser();
}
</code>```

Now the problem is that ngOnInit on my session service doesn't get called automatically and I have to explicitly call loadUser() inside the guard, which is not what I want to do

Any idea how to make the ngOnInit of session service to get executed before canActive of guard?

Thanks a lot!!!

答: Do not user "OnInit" with services only with components. Instead, call the required loading logic in the service's constructor</p>

Body:
So I have this guard to watch my protected routes on my app
Basically, my session service extracts its credentials from localStorage inside NgOnInit, and then the guard should ask the service if it has credentials so it will know if it should approve this route

import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import { SessionService } from './../session/session.service'

@Injectable()
export class AuthGuard implements CanActivate {

    constructor(
    private router: Router,
    private sessionService: SessionService
    ) { }

    canActivate() {
        //without this line this won't work
        //this.sessionService.loadUser();
        if (this.sessionService.isValidSession()) {
            // logged in so return true
            return true;
        }

        // not logged in so redirect to login page
        this.router.navigate(['/login']);
        return false;
    }
}

this is my session service:

export class SessionService implements OnInit {
 .
 .
 .
constructor(
    private authService: AuthenticationService,
) {
    this.timeout = null;
}

ngOnInit() {
    this.loadUser();
}

Now the problem is that ngOnInit on my session service doesn't get called automatically and I have to explicitly call loadUser() inside the guard, which is not what I want to do

Any idea how to make the ngOnInit of session service to get executed before canActive of guard?

Thanks a lot!!!


问:
Prims and Bellman-Ford Algorithms in Directed Graphs
Please suggest resources to learn how to find a minimal spanning tree in a directed graph using Prim's algorithm, as well as Bellman-Ford algorithm to calculate the shortest path in a directed graph.</p>

答:
If you'd like some actual code for the algorithms, I recently coded both of these algorithms up.

Prim's algorithm

Bellman-Ford algorithm

The comments at the top of these files contains an analysis of the two algorithms both from a correctness and runtime perspective, and I hope they can shed some light on how they work.


问:
Google Drive API advanced file search
I'm trying to develop a PHP script which goes through my Google Drive to list my files
. I have the current structure :

```<code> -- logo1.png
|
|-- logo2.png
|
 -- myFolder
|     |
|      --logo3.png
|
|
 -- myPrivateFolder
      |
       --logo4.png
</code>```

I'm using the Google PHP library to make my queries. To list my files, I have this code :

```<code>$client = new Google_Client();
$client->setAuthConfig($oauth_credentials);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$service = new Google_Service_Drive($client);

$result = array();

try {
  $parameters = array(
      'q' => "mimeType contains 'image/'",
  );
  $files = $service->files->listFiles($parameters);

  $result = array_merge($result, $files->getFiles());
} catch (Exception $e) {
  print "Une erreur s'est produite : " . $e->getMessage();
}
return $result;
</code>```

$result is an array of 4 elements. Since I specified I only want MIME type 'image/', I only get my 4 images. Now, I'd like to know, how can I filter my results to exclude my private directory from the research ? I want to be able to specify in which folder not to look ?

I wasn't able to find in the documentation anything about that. Thanks in advance for any help !

答:
Firstly you'll need to get the ID of your private directory. You can do that with a query

```<code>name = 'my_private_directory'
</code>```

Once you have the ID, you can extend your existing query with

and not 'xxxxxx' in parents where xxxx is the File ID from step 1.

Title: Google Drive API advanced file search

Body:
I'm trying to develop a PHP script which goes through my Google Drive to list my files
. I have the current structure :

 -- logo1.png
|
|-- logo2.png
|
 -- myFolder
|     |
|      --logo3.png
|
|
 -- myPrivateFolder
      |
       --logo4.png

I'm using the Google PHP library to make my queries. To list my files, I have this code :

$client = new Google_Client();
$client->setAuthConfig($oauth_credentials);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$service = new Google_Service_Drive($client);

$result = array();

try {
  $parameters = array(
      'q' => "mimeType contains 'image/'",
  );
  $files = $service->files->listFiles($parameters);

  $result = array_merge($result, $files->getFiles());
} catch (Exception $e) {
  print "Une erreur s'est produite : " . $e->getMessage();
}
return $result;

$result is an array of 4 elements. Since I specified I only want MIME type 'image/', I only get my 4 images. Now, I'd like to know, how can I filter my results to exclude my private directory from the research ? I want to be able to specify in which folder not to look ?

I wasn't able to find in the documentation anything about that. Thanks in advance for any help !

Body:
Firstly you'll need to get the ID of your private directory. You can do that with a query

name = 'my_private_directory'

Once you have the ID, you can extend your existing query with

and not 'xxxxxx' in parents where xxxx is the File ID from step 1.


问:
Setting default value for TypeScript object passed as argument
```<code>function sayName(params: {firstName: string; lastName?: string}) {
    params.lastName = params.lastName || 'smith';  // <<-- any better alternative to this?
    var name = params.firstName + params.lastName
    alert(name);
}

sayName({firstName: 'bob'});
</code>```

I had imagined something like this might work:

```<code>function sayName(params: {firstName: string; lastName: string = 'smith'}) {
</code>```

Obviously if these were plain  arguments you could do it with:

```<code>function sayName(firstName: string, lastName = 'smith') {
    var name = firstName + lastName;
    alert(name);
}

sayName('bob');
</code>```

And in coffeescript you have access to the conditional existence operator so can do:

```<code>param.lastName ?= 'smith'
</code>```

Which compiles to the javascript:

```<code>if (param.lastName == null) {
    param.lastName = 'smith';
}
</code>```

答:
Typescript supports default parameters now:

https://www.typescriptlang.org/docs/handbook/functions.html

Also, adding a default value allows you to omit the type declaration, because it can be inferred from the default value:

```<code>function sayName(firstName: string, lastName = "Smith") {
  const name = firstName + ' ' + lastName;
  alert(name);
}

sayName('Bob');
</code>```

Body:
function sayName(params: {firstName: string; lastName?: string}) {
    params.lastName = params.lastName || 'smith';  // <<-- any better alternative to this?
    var name = params.firstName + params.lastName
    alert(name);
}

sayName({firstName: 'bob'});

I had imagined something like this might work:

function sayName(params: {firstName: string; lastName: string = 'smith'}) {

Obviously if these were plain  arguments you could do it with:

function sayName(firstName: string, lastName = 'smith') {
    var name = firstName + lastName;
    alert(name);
}

sayName('bob');

And in coffeescript you have access to the conditional existence operator so can do:

param.lastName ?= 'smith'

Which compiles to the javascript:

if (param.lastName == null) {
    param.lastName = 'smith';
}

Body:
Typescript supports default parameters now:

https://www.typescriptlang.org/docs/handbook/functions.html

Also, adding a default value allows you to omit the type declaration, because it can be inferred from the default value:

function sayName(firstName: string, lastName = "Smith") {
  const name = firstName + ' ' + lastName;
  alert(name);
}

sayName('Bob');