text:
Q: Spark Java Error: Size exceeds Integer.MAX_VALUE I am trying to use spark for some simple machine learning task.
I used pyspark and spark 1.2.0 to do a simple logistic regression problem.
I have 1.2 million records for training, and I hashed the features of the records.
When I set the number of hashed features as 1024, the program works fine, but when I set the number of hashed features as 16384, the program fails several times with the following error:
Py4JJavaError: An error occurred while calling o84.trainLogisticRegressionModelWithSGD.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 4.0 failed 4 times, most recent failure: Lost task 1.3 in stage 4.0 (TID 9, workernode0.sparkexperience4a7.d5.internal.cloudapp.net): java.lang.RuntimeException: java.lang.IllegalArgumentException: Size exceeds Integer.MAX_VALUE
    at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:828)
    at org.apache.spark.storage.DiskStore.getBytes(DiskStore.scala:123)
    at org.apache.spark.storage.DiskStore.getBytes(DiskStore.scala:132)
    at org.apache.spark.storage.BlockManager.doGetLocal(BlockManager.scala:517)
    at org.apache.spark.storage.BlockManager.getBlockData(BlockManager.scala:307)
    at org.apache.spark.network.netty.NettyBlockRpcServer$$anonfun$2.apply(NettyBlockRpcServer.scala:57)
    at org.apache.spark.network.netty.NettyBlockRpcServer$$anonfun$2.apply(NettyBlockRpcServer.scala:57)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:108)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:108)
    at org.apache.spark.network.netty.NettyBlockRpcServer.receive(NettyBlockRpcServer.scala:57)
    at org.apache.spark.network.server.TransportRequestHandler.processRpcRequest(TransportRequestHandler.java:124)
    at org.apache.spark.network.server.TransportRequestHandler.handle(TransportRequestHandler.java:97)
    at org.apache.spark.network.server.TransportChannelHandler.channelRead0(TransportChannelHandler.java:91)
    at org.apache.spark.network.server.TransportChannelHandler.channelRead0(TransportChannelHandler.java:44)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:745)

    at org.apache.spark.network.client.TransportResponseHandler.handle(TransportResponseHandler.java:156)
    at org.apache.spark.network.server.TransportChannelHandler.channelRead0(TransportChannelHandler.java:93)
    at org.apache.spark.network.server.TransportChannelHandler.channelRead0(TransportChannelHandler.java:44)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:745)

Driver stacktrace:
    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1214)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1203)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1202)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1202)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:696)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:696)
    at scala.Option.foreach(Option.scala:236)
    at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:696)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessActor$$anonfun$receive$2.applyOrElse(DAGScheduler.scala:1420)
    at akka.actor.Actor$class.aroundReceive(Actor.scala:465)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessActor.aroundReceive(DAGScheduler.scala:1375)
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516)
    at akka.actor.ActorCell.invoke(ActorCell.scala:487)
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
    at akka.dispatch.Mailbox.run(Mailbox.scala:220)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

This error happens when I training the LogisticRegressionWithSGD after transferring the data into LabeledPoint.
Does anyone have a idea on this?
My code is as follows (I am using a IPython Notebook for this):
from pyspark.mllib.regression import LabeledPoint
from pyspark.mllib.classification import LogisticRegressionWithSGD
from numpy import array
from sklearn.feature_extraction import FeatureHasher
from pyspark import SparkContext
sf = SparkConf().setAppName("test").set("spark.executor.memory", "50g").set("spark.cores.max", 30)
sc = SparkContext(conf=sf)
training_file = sc.textFile("train_small.txt")
def hash_feature(line):
    values = [0, dict()]
    for index, x in enumerate(line.strip("\n").split('\t')):
        if index == 0:
            values[0] = float(x)
        else:
            values[1][str(index)+"_"+x] = 1
    return values
n_feature = 2**14
hasher = FeatureHasher(n_features=n_feature)
training_file_hashed = training_file.map(lambda line: [hash_feature(line)[0], hasher.transform([hash_feature(line)[1]])])
def build_lable_points(line):
    values = [0.0] * n_feature
    for index, value in zip(line[1].indices, line[1].data):
        values[index] = value
    return LabeledPoint(line[0], values)
parsed_training_data = training_file_hashed.map(lambda line: build_lable_points(line))
model = LogisticRegressionWithSGD.train(parsed_training_data)

The error happens when executing the last line.

A: The Integer.MAX_INT restriction is on the size of a file being stored. 1.2M rows is not a big thing, to I'm not sure your problem is "the limits of spark". More likely, some part of your work is creating something too big to be handled by any given executor.
I'm no Python coder, but when you "hashed the features of the records" you might be taking a very sparse set of records for a sample and creating an non-sparse array. This will mean a lot of memory for 16384 features. Particularly, when you do zip(line[1].indices, line[1].data). The only reason that doesn't get you out of memory right there is the shitload of it you seem to have configured (50G).
Another thing that might help is to increase the partitioning. So if you can't make your rows use less memory, at least you can try having fewer rows on any given task. Any temporary files being created are likely to depend on this, so you'll be more unlikely to hit file limits.

And, totally unrelated to the error but relevant for what you are trying to do:
16384 is indeed a big number of features, in the optimistic case where each one is just a boolean feature, you have a total of 2^16384 possible permutations to learn from, this is a huge number(try it here: https://defuse.ca/big-number-calculator.htm).
It is VERY, VERY likely that no algorithm will be able to learn a decision boundary with just 1.2M samples, you would probably need at least a few trillion trillion examples to make a dent on such a feature space. Machine Learning has its limitations, so don't be surprised if you don't get better-than-random accuracy.
I would definitely recommend trying some sort of dimensionality reduction first!!

A: At some point, it tries to store the features and 1.2M * 16384 is greater than Integer.MAX_INT so you are trying to store more than than maximum size of features supported by Spark.
You're probably running into the limits of Apache Spark.

A: Increasing the number of partitions may cause Active tasks is a negative number in Spark UI, which probably means that the number of partitions is too high.


text:
Q: column/row span for html table I want to put my controls in attached html structure.
Can anyone give me quick code for it?

A: In your image there are 2 rows and 4 columns in the table.

*

*First row has 3 cells, first with colspan 2 and other without any span

*Second row has 4 cells without any span.

You can get this Table structure by using this code.

    &nsp;
    &nsp;

    &nsp;
    &nsp;
    &nsp;
    &nsp;

A:

     column 1
     column 2
     column 3

     column 1
     column 2
     column 3
     column 4

redpajama_set_name: RedPajamaStackExchange


text:
Q: Android product flavors versionNameSuffix I'm using buildTypes and productFlavors. My app also uses an analytics tool and this tool used the versionName of my app.
How can I change the versionName per flavor? My test was
productFlavors {
    google {
        versionNameSuffix ".google"
    }
}

but it failed. Does anybody has an idea how to custom the versionName depending on the flavor?
Update
Apparently the 2.2.0 version of Gradle Android plugin now allows setting versionNameSuffix in productFlavors

A: This is still a work in progress for me, but seems to work:
productFlavors {
    development {
        versionName = android.defaultConfig.versionName + (System.getenv("BUILD_NUMBER") as Integer ? "-build" + System.getenv("BUILD_NUMBER") as Integer : "-developerBuild")
    }
}

So we can set the versionName in defaultConfig, on the build server it sets the environmental variable BUILD_NUMBER, so ends up being like: 1.2-build1234  The production build only uses the defaultConfig so is just 1.2, and when building on dev machines the environmental variable isn't set so its 1.2-developerBuild
Just came up with this plan tonight (so could be simplified i'm sure), so working on getting the latest source control revision added when on a dev machine, but i've seen other answers with how to do that.

A: You can set the entire version name through a flavor, like this:
productFlavors {
    flavor_a {
        versionName 'Version_A'
    }
    flavor_b {
        versionName 'Version_B'
    }
}
defaultConfig {
    versionName 'Default_version_name'
}

If a flavor doesn't specify a version name, it will pick it up from defaultConfig.


text:
Q: Calling count method of std::set of pointers with const key type reference I have a class like
struct S {

    bool foo(const AType& v) const {
        return values.count(&v); // compile error due to the constness of v
    }

    private:
        std::set<AType*> values;
};

This is a simplified version. In real code, foo does some complex things.
The code produces an error
invalid conversion from 'const AType*' to 'std::set<AType*>::key_type {aka AType*}'

I think foo should take 'const AType& v' because it does not mutate v.
The type of the member variable 'values' can not be std::set<const AType*> because some methods of the struct S call non-const methods of the elements contained in 'values'.
I can cast constness of 'v' away:
bool foo(const AType& v) const {
    return values.count((AType*) &v);
}

But I think this may not be a good solution in general.
What solution could I have?

A: The root of the problem is this:

The type of the member variable 'values' can not be std::set because some methods of the struct S call non-const methods of
  the elements contained in 'values'.

You are not supposed to mutate the set key in any way.
You should be using a map, where the actual key parts are in the key and are const, and the mutating parts are in the value and are non-const.
If this is impractical for your design, I understand. The const_cast workaround will solve the issue. It feels inelegant, but that's because your usage of set is inelegant.

A: This is just one of the many problems of the const correctness concept: it doesn't scale by composition.
The casting solution is just ok, if you feel it's "dirty" in some way probably you're overestimating cleanness of the const concept.
Consider that defining special types for const_iterator and const_reverse_iterator was needed or that sometimes const correctness requires actual code duplication (e.g. in many cases for operator[]) or that if you've an object containing a non-const pointer you can mutate the pointed-to object freely and even delete it in const members.
Your cast doesn't look that bad in comparison :-)

A: template<class T>
struct const_ptr_compare:std::less<T const*> {
  typedef void is_transparent;
};

std::set<AType*, const_ptr_compare<AType>> values;

and bob is your uncle.
I defined a comparator that can transparently handle T const* comparisons as well as T* comparisons.  I then told std::set that it is transparent.
The is_transparent technique is a C++14 enhancement to std::set.  Your compiler may already have support for it.

If you want to be able to pass in base-classes-of-T a bit more work needs to be done.  You need a function object that tests its two arguments (each pointers to const) to see which is a base class of the other, and does a std::less<base const*>{}(lhs, rhs) using that base class.  However, that is going further down the rabbit hole than we need to.

A C++11/03 approach could involve making the editable portions of AType mutable, and having a const AType* set.  Failing that, a const_cast<AType*> is reasonable.
Please don't use a C-style cast: they are almost never required, and they can be accidentally too powerful.


text:
Q: nhibernate retry how to manage the session in deadlocks I have been having deadlock issues. I've been on working some retry approaches. My retry code is currently just a 'for' statement that tries 5 times. I understand i need to use the 'Evit' nhibernate method to clear the session. I am using a session factory and use a transaction for each request.
In the below example if i experience a deadlock on the first retry will the orderNote property remain the same on the second retry?
private ActionResult OrderDetails(int id)
{
    var order = _orderRepository.Get(id);
    order.OrderNote = "will this text remain";

    Retry.Times(5).Do(() => _orderRepository.Update(order));

    return View();
}

Edit
1) Finding it hard to trace the cause. I'm getting about 10 locks a day all over my application.  Just set up a profiler. Are there any other useful methods for tracing
http://msdn.microsoft.com/en-us/library/ms190465.aspx
I think the main issue is that i'm using auto increament. I'm in the process of moving to hilo.
2) Using a different transation mode. I'm not defining any at the moment. What is recommended.
5) Long running operations. Yes i do. And i think because i'm using auto increament lazy loading is ignored. Does that sound correct?

A: In my opinion your code is trying to fix the symptoms instead of the cause.
You will be better off doing some of the following things:

*

*Find out why you are getting deadlocks and fix the core issue

*Use a different transaction mode to read past locks

*Look at delegating the update into a queue structure to be background processed

*Understand the update execution plan and perhaps add indexing to speed up queries

*Do you have any "long" running operations in your Controller action which is keeping the transaction open for longer than it should be?

*Even if the operation did deadlock, why don't you return an friendly error back to the calling page and let them manually retry.

Update:
1.) Useful methods for tracing
I have used this method for tracing deadlocks which should give you an idea of the resources which are in contention: Tracing Deadlocks
You can also look at the concurreny models available to you: NHibernate Concurrency
2.) Transaction Isolation Levels
Depending on your DB this Question has some useful information: Transaction Isolation Mode
3.) Long Running Operations
I have to use Identity Columns as my primary keys in NHibernate and I don't think these are going to be source of your problem in an update scenario as the Id/PK is already set by this point. Try to minimise the long running operations which will shorten the amount of time your transaction is held open.


text:
Q: PID: 30172 java.lang.NumberFormatException: Invalid int: "64" I don't understand the reason behind this exception
E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.khalid_al_mustadi.jockeystickers, PID: 30172
    java.lang.NumberFormatException: Invalid int: "64"

All I am doing is
if (Integer.parseInt(groupnameList.get(position).get("Value_C").trim().replace("%", "")) >= 70)

A: From the logs, it seems you  are trying to parse -
Integer.parseInt("\"64\""));

which means groupnameList.get(position).get("Value_C").trim().replace("%", "") gives you - "\"64\"" (a string "64" with the double quotes included)
And double quotes(") cannot be converted to integers which is why you get NumberFormatException.
Remove any double quotes prior to using Integer.parseInt() .


text:
Q: What is the ten minutes? In the first episode of Battlestar Galactica, 33, what is the ten minutes that Colonel Tigh and Commander Adama are rotating? Originally I thought it was ten minutes speaking to the President but have realized that ten minutes sleep might be more appropriate.

A: Based on the show's original script, the implication seems to be that Tigh and Adama are taking it in turns to have ten minutes downtime away from the bridge, time enough to SSS.
Note that Tigh has maneuvered the captain to his quarters in this earlier draft.

[They've arrived outside Adama's quarters. He glances at his watch.]
ADAMA: This my ten minutes or yours?
TIGH: Yours, I took ten last time.
ADAMA: See you two in Combat.


text:
Q: Spark on k8s - Error: Missing application resource I'm trying to run the SparkPi example using spark on k8s.
Working with

*

*kubectl

*minikube

*spark-2.4.4-bin-hadoop2.7

Running the following command:
spark-submit --master k8s://https://192.168.99.100:8443  --deploy-mode cluster  --name spark-pi  --class org.apache.spark.examples.SparkPi  --conf spark.executor.instances=1  --conf spark.kubernetes.container.image=sparkk8s:latest --conf spark.kubernetes.driver.pod.name=sparkpi  local:///opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar 10

throws the following exception in the pod logs:
+ env
+ sed 's/[^=]*=\(.*\)/\1/g'
+ sort -t_ -k4 -n
+ grep SPARK_JAVA_OPT_
+ readarray -t SPARK_EXECUTOR_JAVA_OPTS
+ '[' -n '' ']'
+ '[' -n '' ']'
+ PYSPARK_ARGS=
+ '[' -n '' ']'
+ R_ARGS=
+ '[' -n '' ']'
+ '[' '' == 2 ']'
+ '[' '' == 3 ']'
+ case "$SPARK_K8S_CMD" in
+ CMD=("$SPARK_HOME/bin/spark-submit" --conf
"spark.driver.bindAddress=$SPARK_DRIVER_BIND_ADDRESS" --deploy-mode client "$@")
+ exec /sbin/tini -s -- /opt/spark/bin/spark-submit --conf spark.driver.bindAddress=172.17.0.6 --deploy-mode client
Error: Missing application resource.
Usage: spark-submit [options] <app jar | python file | R file> [app arguments]
Usage: spark-submit --kill [submission ID] --master [spark://...]
Usage: spark-submit --status [submission ID] --master [spark://...]
Usage: spark-submit run-example [options] example-class [example args]

Initially I thought the parameters are not passing since the exec command doesn't show the driver class or path to jar executable. but kubectl describe shows the follows:
name:               sparkpi
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/10.0.2.15
Start Time:         Sun, 15 Sep 2019 13:14:37 +0300
Labels:             spark-app-selector=spark-7c0293be51924505b91e381df8de2b4f
                spark-role=driver
Annotations:        spark-app-name: spark-pi
Status:             Failed
IP:                 172.17.0.5
Containers:
spark-kubernetes-driver:
Container ID:  docker://db03f9a45df283848dc3e10c5d3171454b0d47ae25192e54f266e44f58eb7bc8
Image:         spark2:latest
Image ID:      docker://sha256:1d574a61cb26558ec38376d045bdf39fa18168d96486b2f921ea57d3d4fb2b48
Port:          <none>
Host Port:     <none>
Args:
  driver
State:          Terminated
  Reason:       Error
  Exit Code:    1
  Started:      Sun, 15 Sep 2019 13:14:37 +0300
  Finished:     Sun, 15 Sep 2019 13:14:38 +0300
Ready:          False
Restart Count:  0
Limits:
  memory:  1408Mi
Requests:
  cpu:     1
  memory:  1Gi
Environment:
  SPARK_DRIVER_MEMORY:        1g
  SPARK_DRIVER_CLASS:         org.apache.spark.examples.SparkPi
  SPARK_DRIVER_ARGS:          10
  SPARK_DRIVER_BIND_ADDRESS:   (v1:status.podIP)
  SPARK_MOUNTED_CLASSPATH:    /opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar:/opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar
  SPARK_JAVA_OPT_0:           -Dspark.app.name=spark-pi
  SPARK_JAVA_OPT_1:           -Dspark.app.id=spark-7c0293be51924505b91e381df8de2b4f
  SPARK_JAVA_OPT_2:           -Dspark.submit.deployMode=cluster
  SPARK_JAVA_OPT_3:           -Dspark.driver.blockManager.port=7079
  SPARK_JAVA_OPT_4:           -Dspark.driver.host=spark-pi-b8556ee3d1c33baf8d9feacc1cae7a9d-driver-svc.default.svc
  SPARK_JAVA_OPT_5:           -Dspark.kubernetes.container.image=spark2:latest
  SPARK_JAVA_OPT_6:           -Dspark.executor.instances=1
  SPARK_JAVA_OPT_7:           -Dspark.jars=/opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar,/opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar
  SPARK_JAVA_OPT_8:           -Dspark.kubernetes.executor.podNamePrefix=spark-pi-b8556ee3d1c33baf8d9feacc1cae7a9d
  SPARK_JAVA_OPT_9:           -Dspark.kubernetes.driver.pod.name=sparkpi
  SPARK_JAVA_OPT_10:          -Dspark.driver.port=7078
  SPARK_JAVA_OPT_11:          -Dspark.master=k8s://https://192.168.99.100:8443

I also tried to run the image using docker and check that the jar file is actually under the provided path - /opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar
Any suggestions?

A: I got back on this issue now, and the fix is somewhat annoying, the spark-submit is expected to run from the spark distribution folder so instead of using the spark-submit alias, run the spark-sumbit as bin/spark-submit ...
bin/spark-submit --master k8s://https://192.168.99.100:8443  --deploy-mode cluster  --name spark-pi  --class org.apache.spark.examples.SparkPi  --conf spark.executor.instances=1  --conf spark.kubernetes.container.image=sparkk8s:latest --conf spark.kubernetes.driver.pod.name=sparkpi  local:///opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar 10


text:
Q: Open file sleep then close infinite loop in batch? I have this batch file which opens 4 cmds and then goes to the corresponding
folder and executes some other bat files which then execute python scripts.
I basically want to have this batch file
:loop
start cmd.exe /k "cd C:\users\ivan\desktop\folder1 & call run.bat"
start cmd.exe /k "cd C:\users\ivan\desktop\folder2 & call run.bat"
start cmd.exe /k "cd C:\users\ivan\desktop\folder3 & call run.bat"
start cmd.exe /k "cd C:\users\ivan\desktop\folder4 & call run.bat"
goto loop

open these 4 cmds and then wait about 30 minutes and close and open them again, so it would look something like this
:loop
start cmd.exe /k "..."
sleep(1800000)
exit
goto loop

does anyone know if this is even possible?

A: start "RunBat" /d "C:\users\ivan\desktop\folder1" call run.bat

starts run.bat in a new window with the title RunBat with the working directory C:\users\ivan\desktop\folder1 (no need for a cd command)
timeout /t 1800 >nul

pauses the execution for (30min*60sec) 1800 seconds. (>nul: don't show the timer)
finally
taskkill /fi "WINDOWTITLE eq RunBat*"

kills all cmd windows where the windowtitle starts with RunBat (this way you don't need the PIDs). (Give all your "daughter processes" the same title, so you can kill all of them with a single taskkill command; or give them unique titles to be able to kill them separately)
Put a label and a goto around, and you're done.


text:
Q: Pyramid page loading animation I use pyramid for an application, and I want to show an hourglass when pyramid loads the new view. Before the view is updated, I have to do some work with a video file, and the page waits for a bunch of seconds before the response. I want to show an animation during that period.

A: try to use json response and while waiting for the response, you can display your animation
http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/narr/renderers.html


text:
Q: Im trying to make a write to text file in c# I have this code but doesn't seem to be doing anything so I am a bit stuck
const string sPath = "movieAdd.txt";
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
if (listBox1.SelectedItems.Count ==1)
{
     foreach (var item in listBox1.SelectedItems)
     {
          SaveFile.WriteLine(item);
     }
     SaveFile.Close();
}

A: It's not pointing anywhere ...
Try const string sPath = @"C:\movieAdd.txt";
or something like that.
Even better, use the Path methods to create it, or something like:
const string sPath = @"c:\movieAdd.txt";
    List<string> strings_to_write = new List<string>():
        if (listBox1.SelectedItems.Count ==1)
        {
            foreach (var item in listBox1.SelectedItems)
            {
                strings_to_write.Add(item);
            }

    System.IO.File.WriteAllLines(sPath, strings_to_write);

A: The code as it is writes lines only when exactly one entry in the list is selected. I'm unsure whether this is what you want, considering you're trying to write one line per selected item. You may want to rewrite your code to the following, which allows for more than one row to be selected. Also, the file is closed in any case in the following code.
const string sPath = "movieAdd.txt";
if (listBox1.SelectedItems.Count >= 1)
{
    using (System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath))
    {
        foreach (var item in listBox1.SelectedItems)
        {
            SaveFile.WriteLine(item);
        }
    }
}

Another issue may be you don't have an explicit path in your sPath variable. This may cause problems, depending on the current working directory, which may be different from the directory the executable resides in! It would be safer to add a directory explicitly, like this:
const string sPath = @"C:\temp\movieAdd.txt";
if (listBox1.SelectedItems.Count >= 1)
{
    using (System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath))
    {
        foreach (var item in listBox1.SelectedItems)
        {
            SaveFile.WriteLine(item);
        }
    }
}


text:
Q: How to express fmod() function or periodic functions in maths I have a periodic function with fmod() like this (in C):
float f(float x) {
    x = fmod(x, 1);
    if (x < 0.5f) return 1 - x;
    else return x
}

If I need a formal math formula for this function, what is the prettiest way?
Do people use fmod or mod functions in formulas like this? It looks strange.
$$
f(x) =
\left\{
             \begin{array}{**lr**}
             1-\mathrm{fmod} (x,1), & 0 \leq \mathrm{fmod} (x,1) < 0.5  \\
             \mathrm{fmod}(x,1), & 0.5 \leq \mathrm{fmod} (x,1) < 1
             \end{array}
\right.
$$


text:
Q: Query taking longer in C# than SQL I have a Stored Procedure that takes roughly a second to execute, however, using the same parameters when I deploy it on .NET C#, I reach the part where I use an SqlAdapter and use the Fill function, (using debug mode) I press F11 and then it stays there for like a minute until it finally returns a datatable, which only has one row by the way.
Is there something that I must consider when using C# for an SP instead of SQL?
The query in particular is the following:
ALTER PROCEDURE [dbo].[GAS_consumptions_spFullSearchA]
(
    @idClient INT,
    @beginDate DATETIME,
    @endDate DATETIME,
    @description VARCHAR(1000),
    @department VARCHAR(50),
    @area VARCHAR(50),
    @idCardType INT,
    @idProduct INT,
    @idStation INT,
    @cardCode VARCHAR(16),
    @idCostCenter INT,
    @idSection INT,
    @idDivision INT,
    @isManual INT,
    @idInvoice INT
)
AS

SET @description = ISNULL(@description, '')

SELECT DISTINCT
    con.idConsumption,
    cli.idClient,
    ISNULL(cli.tradename, cli.commercialName) AS tradeName,
    con.quantity,
    pro.[description],
    (con.price + con.iepsPerLiter + (con.price * con.tax) / 100) AS price,
    (con.subtotal + con.ieps) AS subtotal,
    con.createdDate AS dateCreated,
    ISNULL(sta.shortname, 'Corporativo') AS name,
    ISNULL(nip.idCard, nip2.[idCard]) AS idCard,
    ISNULL(clc.[name], 'CONSUMO ADMIN.') AS contact,
    '' AS operationType,
    con.gasPump,
    con.tax,
    con.total,
    sta.idStation,
    sta.[name] AS stationName,
    sta.rfc,
    con.stationSaleNumber,
    SUBSTRING (ISNULL(car.cardCode, car2.[cardCode]), 9, 16) AS cardCode,
    ISNULL (veh.economicNumber, veh2.economicNumber) AS economicNumber,
    ISNULL (veh.model, veh2.model) AS model,
    ISNULL (veh.licensePlates, veh2.licensePlates) AS licensePlates,
    sta.pemexKey,
    pro.idPemex,
    con.isManual,
    mcd.comments,
    rmc.reasonName,

    CASE
        WHEN car.cardCode IS NULL THEN 'Tarjeta'
        ELSE 'CHEQUE'
    END AS operation,

    con.TaxAmount,
    '1' AS RowType,
    con.CommissionsAmount,
    con.notes,
    con.CommissionsValue,
    con.CommissionsTaxAmount,
    cat.[description] AS [type],

    CASE ISNULL(ico.idInvoice, '-1')
        WHEN -1 THEN '-1'
        ELSE cor.series + ' ' + CAST(ico.idInvoice AS NVARCHAR)
    END AS idInvoice,

    con.mileage,
    con.stationSaleNumber AS saleNumber,
    con.workSchedule AS Turno,
    ISNULL(car.area, car2.area) AS Area,
    ISNULL(car.department, car2.department) AS department,

    CASE ISNULL(ico.idInvoice, '-1')
        WHEN -1 THEN '-1'
        ELSE inv.series + RIGHT('000000' + CAST(inv.number AS VARCHAR),6)
    END AS seriesNumber,

    CASE ISNULL(con.requestedAmount, '')
        WHEN '' THEN 0
        ELSE con.requestedAmount
    END AS RequestAmount,

    (
        SELECT cup.serial + CAST(cup.folio AS VARCHAR)+ '($' + CAST(cup.amount AS VARCHAR) + ')  '
        FROM CCARD_coupon AS cup
        WHERE cup.IdConsumption = con.idConsumption
        FOR XML PATH('')
    ) AS couponConsumtion,

    ISNULL(con.couponConsumption, 0) AS couponConsumption,
    ISNULL(coce.name, '') AS costCenter,
    ISNULL(sec.name, '') AS section,
    ISNULL(div.name, '') AS division,

    CASE ISNULL(con.isManual, 0)
        WHEN 1 THEN 'MANUAL'
        ELSE cat.[description]
    END AS [transaction],

    CASE con.isManual
        WHEN 1 THEN 'SI'
        ELSE ''
    END AS [Manual],

    CASE ISNULL(ico.idInvoice, '-1')
        WHEN -1 THEN ''
        ELSE CONVERT(VARCHAR, inv.createdDate, 120)
    END AS fechaFactura,

    cntCls.description AS clasificacion,
    cntSeg.description AS segmentacion,
    cntEco.description AS giro,

    CASE
        WHEN cct.idClientType IS NULL THEN 'NA'
        ELSE cct.description
    END AS tipoCliente,

    CONVERT(VARCHAR(10), cli.createdDate, 120) AS clienteCreacion,
    repBilling.name AS RepFacturacion,
    repSales.name AS RepVentas,
    repFinance.name AS RepCobranza,
    cor.idCorporative,
    con.picture,
    con.signature,

    CAST
    (
        CASE
            WHEN
            (
                LTRIM(RTRIM(ISNULL(con.picture, ''))) = ''
                AND LTRIM(RTRIM(ISNULL(con.signature, ''))) = ''
            ) THEN 0
            ELSE 1
        END AS BIT
    ) AS imagesAvailable,

    CAST
    (
        CASE LTRIM(RTRIM(ISNULL(con.picture, '')))
            WHEN '' THEN 0
            ELSE 1
        END AS BIT
    ) AS pictureAvailable,

    CAST
    (
        CASE LTRIM(RTRIM(ISNULL(con.signature, '')))
            WHEN '' THEN 0
            ELSE 1
        END AS BIT
    ) AS signatureAvailable
FROM
    GAS_consumptions con WITH(NOLOCK)
    INNER JOIN GAS_products pro WITH(NOLOCK) ON pro.IdProduct = con.IdProduct
    LEFT OUTER JOIN GAS_oneTimeNips otn WITH(NOLOCK) ON otn.idOneTimeNip = con.idOneTimeNip
    LEFT OUTER JOIN [GAS_cardNips] nip2 WITH(NOLOCK) ON nip2.[idNip] = otn.[idNip]
    LEFT OUTER JOIN GAS_CardNips nip WITH(NOLOCK) ON nip.idNip = con.idNip
    LEFT OUTER JOIN GAS_ClientContacts clc WITH(NOLOCK) ON clc.idClientContact = nip.idClientContact
    LEFT OUTER JOIN GAS_Cards car WITH(NOLOCK) ON car.idCard = nip.idCard
    LEFT OUTER JOIN [GAS_cards] car2 WITH(NOLOCK) ON car2.[idCard] = nip2.[idCard]
    LEFT OUTER JOIN [GAS_cardTypes] cat WITH(NOLOCK) ON cat.[idCardType] = car.[idCardType]
    LEFT OUTER JOIN CCARD_stations sta WITH(NOLOCK) ON sta.idStation = con.idStation
    LEFT OUTER JOIN GAS_Vehicles veh2 WITH(NOLOCK) ON veh2.idVehicle = car2.idVehicle
    LEFT OUTER JOIN GAS_Vehicles veh WITH(NOLOCK) ON veh.idVehicle = car.idVehicle
    LEFT OUTER JOIN CCARD_clients cli WITH(NOLOCK) ON cli.idClient = con.idClient
    LEFT OUTER JOIN CCARD_clientCreditTypes cct WITH(NOLOCK) ON cct.idClientType = dbo.GetClientType(cli.idAccountType, cli.remissionType, cli.isPayToCard, cli.isCoupon)
    INNER JOIN CCARD_corporatives cor WITH(NOLOCK) ON cor.idCorporative = cli.idCorporative
    LEFT OUTER  JOIN GAS_invoiceConsumptions ico WITH(NOLOCK) ON ico.idConsumption = con.idConsumption
    LEFT OUTER JOIN GAS_invoices inv WITH(NOLOCK) ON inv.idInvoice = ico.idInvoice
    LEFT OUTER JOIN GAS_manualConsumptionDetail mcd WITH(NOLOCK) ON mcd.idConsumption = con.idConsumption
    LEFT OUTER JOIN GAS_reasonsManualConsumption rmc WITH(NOLOCK) ON rmc.idReason = mcd.idReasonManualConsumption
    LEFT OUTER JOIN CCARD_divisions div WITH(NOLOCK) ON div.idDivision = con.idDivision
    LEFT OUTER JOIN CCARD_sections sec WITH(NOLOCK) ON sec.idSection = div.idSection
    LEFT OUTER JOIN CCARD_costCenters coce WITH(NOLOCK) ON coce.idCostCenter = sec.idCostCenter
    LEFT OUTER JOIN CCARD_ClientsClassifications cntCls WITH(NOLOCK) ON cntCls.idClientClassification = cli.idClientClassification
    LEFT OUTER JOIN CCARD_ClientsSegmentations cntSeg WITH(NOLOCK) ON cntSeg.idClientSegmentation = cli.idClientSegmentation
    LEFT OUTER JOIN CCARD_clientsEconomicActivities cntEco WITH(NOLOCK) ON cntEco.idEconomicActivity = cli.idEconomicActivity
    LEFT OUTER JOIN PORTA_employees repSales WITH(NOLOCK) ON repSales.idEmployee = cli.salesRepresentative
    LEFT OUTER JOIN PORTA_employees repBilling WITH(NOLOCK) ON repBilling.idEmployee = cli.billingRepresentative
    LEFT OUTER JOIN PORTA_employees repFinance WITH(NOLOCK) ON repFinance.idEmployee = cli.financeRepresentative
WHERE
    con.idClient = @idClient
    AND
    (
        (
            con.createdDate >= @beginDate
            AND con.createdDate < DATEADD(DAY, 1, @endDate)
            AND
            (
                @description IS NULL
                OR CAST(con.idConsumption AS VARCHAR(100)) LIKE '%' + @description + '%'
                OR pro.description LIKE '%' + @description + '%'
                OR sta.[name] LIKE '%' + @description + '%'
                OR veh.economicNumber LIKE '%' + @description + '%'
                OR veh.licensePlates LIKE '%' + @description + '%'
            )
            AND
            (
                @idCardType = -1
                OR cat.idCardType = @idCardType
            )
            AND
            (
                @idProduct = pro.idProduct
                OR @idProduct = -1
            )
            AND
            (
                sta.idStation = @idStation
                OR @idStation = -1
            )
            AND
            (
                @cardCode = '-1'
                OR
                (
                    car.cardCode LIKE @cardCode
                    OR car2.cardCode LIKE @cardCode
                )
            )
            AND
            (
                @department IS NULL
                OR @department = '-1'
                OR @department LIKE car.department
            )
            AND
            (
                @area IS NULL
                OR @area = '-1'
                OR @area LIKE car.area
            )
            AND
            (
                coce.idCostCenter = @idCostCenter
                OR @idCostCenter = -1
            )
            AND
            (
                sec.idSection = @idSection
                OR @idSection = -1
            )
            AND
            (
                div.idDivision = @idDivision
                OR @idDivision = -1
            )
            AND
            (
                con.isManual = @isManual
                OR @isManual = -1
            )
            AND @idInvoice = -1
        )
        OR inv.idInvoice = @idInvoice
    )
ORDER BY con.idConsumption


text:
Q: web application with local webserver on client machine I have simple web application built on html5 and RoR. It is simple application where user records his voice(html5 web audio) and then it is saved locally. Application won't be hosted on server instead it would be hosted on individual user machine. I need to develop some portable package like exe which will be run on Windows and Mac.
Is this possible? If yes, then what are the ways to achieve it?

A: You might find some useful info here
Here are some more recent tools


text:
Q: How to avoid Android application UI changes on low battery level? I'm developing an Android application according to provided UI. The UI is in bright colors and everything works well.
But when the battery level goes low the battery saver regime turns on and the UI in my application turns dark and some texts become unreadable
Is there any way to avoid it? I see that, for example, Facebook app is not changing its UI during battery saving process.
Thanks in advance.
Provided two screenshots in regular and saving mode:


text:
Q: Django template inline jQuery not working Trying to get inline jQuery in my template working so that I can use django url tags in AJAX calls later.
But I can't get the javascript to work. In my subpage I extend my index page which has all my javascript and jQuery libraries.
{% extends "subpage.django" %}

{% block content %}

    {% if graph %}

 {{ graph.name }}

       {% url 'graphImage' graph.id as the_graph %}

        Delete

Are you sure?

    {% endif %}
{# need to add object.id to dialog in javascript #}
{% endblock  %}

Made some edits. Put script in block content so it shows now when showing the source code. Still doesnt work however.
I now included the jQuery source using google apis. But the inline script still doesn't work. What is strange is that if I type it out in the console it works perfectly just not here! I know I am missing something!

A: Alright so I solved it!
My first problem was solved by user Paul Tomblin (sorry I don't know how to add you and I don't have enough rep to upvote your comment). I didn't realize that my subpage wouldn't include jQuery. For some reason I thought it would inherit that, but Django in this case doesn't work like that.
Secondly, I didn't add the $(document).ready(function(){}); So when the page loaded it wouldn't "run" or "intialize" the script.
The document ready function will run once the document is ready to run the JavaScript as stated here:
 http://learn.jquery.com/using-jquery-core/document-ready/
And here is my updated code:
{% extends "subpage.django" %}

{# once jQuery works, can do deleteGraph ajax requests #}

{% block content %}

    {% if graph %}

 {{ graph.name }}

       {% url 'graphImage' graph.id as the_graph %}

        Delete

Are you sure?

    {% endif %}
{# need to add object.id to dialog in javascript #}
{% endblock  %}

A:


text:
Q: Adding Three20 to my project on Xcode I've try to add the Three20 library to my project in manual mode how described in this link
enter link description here
Well at the point 4. I can't find the "Details" table for add the libThree20.a and libThree20Core.a
At the point 5 I can't find the "Targets" section of the sidebar.
Maybe the SDK XCODE 4.2.1 Framework is different.
How Can I add the Three20 library to a my project under XCODE 4.2.1???

A: You're right, these instructions are correct for the older Xcode 3. You can find a better guide at http://three20.info/article/2011-03-10-Xcode4-Support which explains on how to use the three20 python script installer


text:
Q: How to force floating blocks staying in the same row in css? So this is my demo: http://jsfiddle.net/3c40tafe/1/
How can I make the icon, file name and description in the same row? Meanwhile the width of the icon and title needs to be fixed, and the description paragraph takes the full of the rest width.
My code:

12 Kittens of Xmas

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

css:
.result_item_icon{
    display:block;
    float:left;
    width:50px;
    height:100%;
    text-align: center;
}
.result_item_icon img{
    max-width:50px;
    max-height:50px;
}

.result_item_name{
    display:block;
    height:50px;
    width:200px;
    font-weight:700;
    vertical-align: middle;
    float;left
}
.search_result_description{
    display:block;
    float:left
}

A: Don't use floating blocks if you don't want them to wrap. Sounds to me like you want table-like behavior:
.item_row {
    display:table;
}
.item_row > * {
    display:table-cell;
    vertical-align:top;
}
/* remove display:block; and float:left; from child elements */

http://jsfiddle.net/mblase75/3ambhr3a/

A: Check out: http://jsfiddle.net/3c40tafe/19/.
UI:

12 Kittens of Xmas

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

CSS:
    .result_item_icon {
    display: inline-block;
    width: 50px;
    height: 50px;
}

.result_item_icon img {
    width: 100%;
    height: 100%;
}

.result_item_name {
    display: inline-block;
    width: 200px;
    height: 50px;
}

.search_result_description {
}

A: .result_item_icon{
    display: inline-block;
    float:left;
    max-width: 50px;
    width: 10%;
    height:100%;
    text-align: center;
}
.result_item_icon img{
    width: 50px;
    display: inline-block;
}

.result_item_name{
    display: inline-block;
    height:50px;
    max-width: 200px;
    width: 25%;
    font-weight:700;
    vertical-align: middle;
    float: left;
}
.search_result_description{
    display: inline-block;
    float:left;
    width: 65%;
}

http://jsfiddle.net/3c40tafe/26/
Added max width to each one and gave the width a percentage based on its container (of 100%).
Also changed blocks to inline-blocks


text:
Q: Angular ng-messages: how to check password confirmation? THE SITUATION:
I am using ng-messages directive for instant validation in my angular app. Everything is working fine except one thing: i need to validate the field 'password confirmation' and don't know how to do.
THE CODE:
<form name="autentication_form" novalidate="" ng-submit="submit_register()">

        Email
        <input type="text" name="email" ng-model="registerData.email" required>

You did not enter the email

        Password
        <input type="password" name="password" ng-model="registerData.password" required>

Please enter the password

        Password confirmation
        <input type="password" name="password_confirmation" ng-model="registerData.password_confirmation" required>

Password confirmation required

</form>

THE QUESTION:
How can i check that the password confirmation match using ng-messages?

A: When developing, you can face the fact that you need to create your own checks, which will affect the validity of the form. If these checks are simple, such as a comparison of the two values, it is better to use a general guideline, than write your own checks for each situation. Look at use-form-error directive.
Live example on jsfiddle.

angular.module('ExampleApp', ['use', 'ngMessages'])
  .controller('ExampleController', function($scope) {

  });
.errors {
  color: maroon
}

    <form name="ExampleForm">
      Password
      <input ng-model="password" required />

      Confirm password
      <input ng-model="confirmPassword" name="confirmPassword" use-form-error="isNotSame" use-error-expression="password && confirmPassword && password!=confirmPassword" required />

Passwords Do Not Match!

          Passwords Do Not Match (from ng-message)!

    </form>

A: The easiest approach is to use a pattern. Works fine for me!
<input type="password" name="new_password1" ng-model="new_password1">

<input type="password" name="new_password2" ng-pattern="\b{{new_password1}}\b" ng-model="new_password2">

Not equal!!!

A: The best approach is to use a directive. The major point of problem here is that both password and password confirmation inputs need to be watched.
Here's the solution that could help

angular.module('app', ['ngMessages'])

.controller('ctrl', function($scope) {
  $scope.registerData = {};
})

.directive('confirmPwd', function($interpolate, $parse) {
  return {
    require: 'ngModel',
    link: function(scope, elem, attr, ngModelCtrl) {

      var pwdToMatch = $parse(attr.confirmPwd);
      var pwdFn = $interpolate(attr.confirmPwd)(scope);

      scope.$watch(pwdFn, function(newVal) {
          ngModelCtrl.$setValidity('password', ngModelCtrl.$viewValue == newVal);
      })

      ngModelCtrl.$validators.password = function(modelValue, viewValue) {
        var value = modelValue || viewValue;
        return value == pwdToMatch(scope);
      };

    }
  }
});

  <form name="autentication_form" novalidate="" ng-submit="submit_register()">

      Email
      <input type="text" name="email" ng-model="registerData.email" required="" />

        You did not enter the email

      Password
      <input type="password" name="password" ng-model="registerData.password" required />

        Please enter the password

      Password confirmation
      <input type="password" name="password_confirmation" ng-model="registerData.password_confirmation" required="" confirm-pwd="registerData.password" />

        Password confirmation required
        Password different

  </form>

A: Here's what I did (using ng-pattern):
<md-input-container class="md-block">
  New Password
  <input ng-model="user.password" name="password" type="password" required ng-pattern="'.{8,}'" />

Password required.

Password must be at least 8 characters.

</md-input-container>
<md-input-container class="md-block">
  Confirm Password
  <input ng-model="user.confirmPassword" name="confirmPassword" type="password" ng-pattern="user.password|escapeRegex" required />

Password confirmation required.

Passwords do not match.

</md-input-container>

And the following filter converts the ng-pattern regex to a literal:
module.filter('escapeRegex', function(){
  return function(str){
    return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  }
});

A: ngMessage works by adding $error.message_field_name to the DOM field name in the form object (within the scope of course). So if your DOM form name is autentication_form and the DOM field name is password_confirmation, you need to set $scope.autentication_form.password_confirmation.$error.nomatch (or whatever ngMessage name you want) to true to display the "Doesn't match" error.
Markup:
<input type="password" name="password_confirmation" ng-model="registerData.password_confirmation" required />

Please repeat your password.

Doesn't match.

Code, nothing special, just watching both passwords:
$scope.$watch("registerData.password + registerData.password_confirmation", function () {
            $scope.autentication_form.password_confirmation.$error.nomatch = $scope.registerData.password !== $scope.registerData.password_confirmation;
        });

A: i did using only ionic(html) validations.

    New Password

    New Password is required

Confirm Password
<input type="password" placeholder="Confirm Password" ng-model="passwordUpdateInfo.confirmPassword" name="confirmPassword" required>

Confirm Password is required

 0 && passwordUpdateInfo.confirmPassword != passwordUpdateInfo.newPassword">
    Password not match..(amar from india)

<button class="button button-positive button-block" ng-disabled="passwordUpdateInfo.confirmPassword.length > 0 && passwordUpdateInfo.confirmPassword != passwordUpdateInfo.newPassword">Update</button>


text:
Q: I tried to resize PersistentVolumeClaim with help of Kubectl patch pvc to increase storage from 10 Gi to 70 Gi but it's giving error: $ k patch pvc pv-volume -p '{"spec":{"resources":{"requests":{"storage":"70Mi"}}}}'
Error from server (Forbidden): persistentvolumeclaims "pv-volume" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize
Question: Create a pvc
name: pv-volume, class: csi-hostpath-sc, capacity:10Mi
Create a pod which mount the pvc as a volume.
name: web-server, image:nginx,mountpath: /usr/share/nginx/html
configure the new pod to have readWriteOnce
finally using kubectl edit ot kubectl patch pvc to a capacity of 70 Mi and record that change.
Please give me solution to patch pvc and record the change.
pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv
spec:
  capacity:
    storage: 70Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: csi-hostpath-sc
  hostPath:
    path: /usr/share/nginx/html

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-volume
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 10Mi
  storageClassName: csi-hostpath-sc

pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: web-server
spec:
  containers:
    - name: web-server
      image: nginx
      volumeMounts:
      - mountPath: "/usr/share/nginx/html"
        name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: pv-volume


text:
Q: is there any functions in google sheets to resolve the below problem? I want to filter the value in F (F>100) and group values in F according to Values in E, find the total for the group and multiply it with value in B as per the group (ie, A,B,C etc.,) and the final totals of the multiplied values for all groups
sum(A)*20+sum(B)*30+sum(C)*15 and so on
enter image description here

A: See if this works
=index(query({E:F, IFERROR(F:F*VLOOKUP(E:E, A:B, 2, 0))}, "Select Col1, sum(Col3) where Col2 > 100 group by Col1 label sum(Col3)''", 0))

A: If Col A will always have A,B,C,D,E in that order:
=arrayformula(if(A:A<>"",{A:A,QUERY({E:F},"select sum(Col2) where Col2 >100 group by Col1 label sum(Col2) '' ",0)*B:B},))

If not:
=arrayformula(if(A:A<>"",QUERY({E:F},"select sum(Col2) where Col2 >100 group by Col1 label sum(Col2) '' ",0)*query({A:B},"select Col2 where Col1 is not null order by Col1",0),))


text:
Q: Two line graph in R I have this data frame 'xy':
 mean_name mean_T_S mean_SIH
1      Action        3 3.272727
2  Reflection        5 4.727273
3 Flexibility        4 5.136364
4   Structure        3 2.636364

and want to have a line chart plotting two lines (one for mean_T_S and one for mean_SIH).
I tried changing the data frame 'xy' to this format
    mean_name      key    value
1      Action mean_SIH 3.272727
2  Reflection mean_SIH 4.727273
3 Flexibility mean_SIH 5.136364
4   Structure mean_SIH 2.636364
5      Action mean_T_S 3.000000
6  Reflection mean_T_S 5.000000
7 Flexibility mean_T_S 4.000000
8   Structure mean_T_S 3.000000

and then tried
xyplot <- ggplot(xy, aes(x=mean_name, y=xy$value, colour=xy$key)) + geom_line()

but it gives the following error:
Error: geom_line requires the following missing aesthetics: y

Appreciating any help!

A: Don't know how you're trying to plot a discreet x variable on a line (which needs a continuous variable), you may start like this
df <- read.table(text = ' mean_name mean_T_S mean_SIH
1      Action        3 3.272727
2  Reflection        5 4.727273
3 Flexibility        4 5.136364
4   Structure        3 2.636364', header = T)

library(tidyverse)

df %>% pivot_longer(!mean_name) %>%
  ggplot() +
  geom_col(aes(x = mean_name, y = value, color = name), position = 'dodge')

Created on 2021-05-14 by the reprex package (v2.0.0)


text:
Q: vector spaces - interpretation of a part of a text There is a part of a text that I don't understand - it is not homework, so I don't have to give any answer, it is just for understanding what I am reading.
The text, after introducing the definition of number field and its properties and the definition of a vector space and its properties, says: "Let M be any set, and let F(M,R) the set of all real-valued functions on M. (Think of an interval I ⊂ R for M.) Define addition and multiplication with scalars by (f + g)(m) = f(m) + g(m), (af)(m) = af(m). Then F(M,R) is a real vector space.
Check this! What is M in that case?".
I find what is written here a bit abstract and I don't get it...

A: Since the set of the real functions on $M$ is $F(M,\mathbb{R}):=\{f:M\rightarrow\mathbb{R}\mid f \text{ a function}\}$, $M$ can be any set over which the functions are defined. This doesn't give problems to the definition of a vector space, since sum and product by scalars work anyway: you can choose the neutral element as $f_0$ defined by $f_0(m)=0$, for every $m\in M$, and the negative of $f_1$ as $-f_1$ (defined, as always, by $-f_1(m)=(-1)f_1(m)$, for every $m\in M$; it can be done because $(\mathbb{R},+)$ is a group).

A: In order to understand what's going on, the first thing you need to understand is what a function is.

What a function is
Put simply, to have a function, you need two sets of things.  Call them $A$ and $B$.  Choose one of the sets as the set of inputs.  Let's choose $A$ as the set of our inputs.  Then a function is just something that "sends" each $a$ in $A$ to some $b$ in $B$.  If the function is named $f$ and the input $a$ is sent to $b$, then we write $f(a) = b$ as notation for that.  The important property of a function is that no input is sent to more than one output.  So we can't have one $a$ in $A$ being sent to more than one $b$ in $B$.
$A$, the set of inputs, is called the domain of the function.  The subset of $B$ that has things from $A$ being mapped to them is called the range of the function.
You can always come up with random/arbitrary functions given two sets.  Let $A = \{1,2,3\}$ and $B = \{4,5,6,7\}$.  You can write a random function by taking each element of $A$ and "sending" it to something in $B$.  I will send $1$ from $A$ to $6$ from $B$.  I will send $2$ from $A$ to $4$ from $B$.  I will send $3$ from $A$ to $6$ in $B$.  I can call this function $f$, so now I have $f(1) = 6$, $f(2) = 4$, and $f(3) = 6$.  Notice that every input has no more than one output, which is a requirement of functions.  But the output $6$ has two inputs ($1$ and $3$) being sent to it -- which is completely OK.  The domain of $f$ is $A$, and the range is $\{4,6\}$, since this is the subset of $B$ with things from $A$ being sent to them.

The next thing you need to understand is what a vector space is.
A vector space consists not of one set, but of two sets.  You specify one set which has elements that you call "vectors".  We can name this set $V$.  The other set has elements which you call "scalars".  We can name this set $S$.
So, to have a vector space, you need two sets.  Now, $S$ has to be a special type of set.  It has to be what's called a field, so it has to satisfy some properties listed in your textbook.  The main one it has to satisfy is that under the operation of multiplication (*), every non-zero element has a multiplicative inverse.  What this means is every non-zero element $a$ in $S$ has an element $b$ in $S$ with $ab = 1$.  We can write $\frac{1}{a}$ instead of $b$.  One obvious example of a field is $\Bbb R$, the set of real numbers.  $\pi$, for example, has $\frac{1}{\pi}$ as its multiplicative inverse, since $\pi * \frac{1}{\pi} = 1$.  Also, the number $1$ must be in the field $S$ (it's in every field).
Once you have the two sets $V$ and $S$, we think of the vector space as the set of elements of $V$ -- but you can multiply these elements of $V$ by elements of $S$.  For example, if $V$ is $\Bbb R^{2}$, and $S$ is $\Bbb R$, then of course we can multiply $\begin{bmatrix} a \\ b \end{bmatrix}$ in $\Bbb R^{2}$ by, for example, $2$ in $\Bbb R$.  The result is $2\begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} 2a \\ 2b \end{bmatrix}$.
Anyway, to be a vector space, this new set of stuff from $V$ multiplied with $S$ has to satisfy the vector space axioms written in your textbook.  If the new set does satisfy all of those, it is called a vector space.

Now that you hopefully understand all of the above, we can discuss what the book is saying.
The book says "Let $M$ be any set."  What we mean by that is exactly what it says.  Let $M$ be any set of things.  It can be a set of numbers, or even the set $\{\text{book}, \text{shoe}, \text{car}\}$.  Given any two sets, we can always define a function between them as we did above, so it doesn't matter what set $M$ is.  It is just a random set.  No need to specify which one for the theorem that they will state to hold.
Now, if $M$ is any set, we can think about all of the functions between the set $M$ and $\Bbb R$.  Think about all of the possible functions you can define between these two sets.  The set of all of these possible functions is denoted $F(M, \Bbb R)$, and it is a set of functions.
Now, for a vector space, something I did not mention above is that you need two operations on it.  You need to be able to add any two elements in it, and as we said above you need to be able to multiply things in $V$ with things in $S$ (called scalar multiplication).  In the definition you are asking about, they are specifying how the addition and scalar multiplication works.
If you have two functions in $F(M, \Bbb R)$ (which is our $V$ here), you can define the new function $f + g$ as the function that, for each input $m$ from $M$, $f + g$ sends $m$ to $f(m) + g(m)$ (the sum of where $m$ is sent to under $f$ and $g$).  It looks like the scalar set $S$ here is $\Bbb R$.  Since $V$ is $F(M, \Bbb R)$, we should be able to talk about multiplication between $V$ and $S$ here.  That's what they define next: if $a$ is a scalar (i.e., an element of $\Bbb R$) and $f$ is a vector (i.e., an element of $F(M, \Bbb R)$), then define $af$, the product, to be the function that sends each input $m$ to $a*f(m)$, the product of $a$ and the place where $f$ sends $m$ to.  $a$ and $f(m)$ are both just real numbers, so multiplication between them makes sense.
Now, armed with these definitions, the book claims that the sets $V = F(M, \Bbb R)$ and $S = \Bbb R$ form a vector space, which is something you should check.  It's actually really easy, even though it looks hard or intimidating at first.  Just check that each of the vector space axioms from the book holds in this case.


text:
Q: Change the behavior of the capslock key To be honest I'm not sure or what I want is possible but it would be very nice if this can be done.
I changed the behavior of the Capslock to act like a Ctrl key. Now it's just an Ctrl key only positioned at an easier to reach place, which is great, but…
It would even be nicer if I could press the Capslock key followed by a second key press. I mean for example: Capslock(ctrl) → V instead of the normal Capslock(ctrl) + V.
I guess what I'm looking for is a somewhat similar behavior as the G(go) combinations in Vim or Gmail. Does anyone have an idea how this can be accomplished?

A: Don't know how to arrange the second bit of behaviour. Doing the following should set you up for simply making Capslock act like the Ctrl key.

*

*In the dash, search for and launch "Keyboard Layout".

*Click on "Options" in the  lower right corner.

*Open "Caps Lock Key Behaviour"

*Select "Make Caps Lock an additional Control but keep the Caps_Lock keysym"

If  you would prefer to launch this from the terminal, you can do so by running the terminal command gnome-control-center. This should bring up a window titled "system settings". You should see several icons, one of which is "Keyboard Layout". Its under the "personal" heading. Once you select it, you can follow the above steps.


text:
Q: "Special" category is displayed in all categories or show parent category on sub category is there a way to have a "special" category in WordPress that will be displayed in all categories? Or is there any way to make parent category displayed on sub-categories?
For example, the categories in my website are:

*

*Asia

*

*South Asia

*

*India

*Bangladesh

*etc

*South-East Asia

*

*Indonesia

*Thailand

*etc

I want to put the post of Asia category to all sub categories, so when I visited www.mywebsite.com/thailand or bangladesh or others, I will also find post of Asia.
I don't know how to code (well, I know little bit), but tutorial always help me. Any help will be appreciated.
Regards.

A: With the categories you have presented I would expect the third level categories to have a URL like www.mywebsite.com/category/thailand. UNLESS you are using some plugin to remove the "category base".
The nature of hierarchical categories is that at each level you filter down to a more precise set of posts. It would be unexpected to see posts of all Asia when you are on a category archive page for Thailand.
You may be looking for a sidebar widget that lists all your categories and has a link list to the entire categories hierarchy, in which your categories will be lists as above. Users can click the link to see all posts in that category. This sidebar could exist on your post archive pages AND post single pages.


text:
Q: Get Markupextension expression in wpf via reflection I try to parse WPF Custom Control with LogicalTreeHelper. The LogicalTreeHelper gives me each control as DependancyObject. And I need to investigate which static resources be used with a control.
The Example of an xaml:
<Label Grid.Row="0" Grid.Column="0" Margin="{StaticResource MarginExtraSmall}"
       VerticalAlignment="Center" Content="{x:Static p:Resources.Type}" ></Label>

The problem is, when I try to get a value of the "Content" property of the Control "Label", I recieve a string, but I need a markupextension expression insteed, in this case "{x:Static p:Resources.Type}"
Code:
DumpElement(object elem)
{
    var dependencyProperties = elem.GetType().GetDependencyProperties();
    DependencyObject dependencyObject = elem as DependencyObject;

    foreach (var dependencyProperty in dependencyProperties)
    {
      var binding = BindingOperations.GetBinding(dependencyObject,
      dependencyProperty);
    }

    var publicProperties = elem.GetType().GetPublicProperies();

    foreach (var property in publicProperties)
    {
      var value = property.GetValue(elem);
    }
}

Have anybody an idea how to solve the problem?


text:
Q: Matlab HOF to apply a function to every row of a matrix I am trying to write a MATLAB function that applies a function to every row of a matrix. Is there a function that does this already? Stack overflow didn't seem to turn up anything. If not, here is the function I am trying to write:
function Z = rowMap(f,X)
[m n] = shape(Z);
Y = [];
for i = 1:m
  Y = [Y f(X(i,:))];
end
Z = Y;
end

Does MATLAB support higher order functions like this? I get an unexpected matlab operator error. Thanks in advance!

A: There are a few things wrong with the code you've provided.
1st your function returns Z, so you can not pass it at the beginning of the function to the shape function. Also, I'm not sure what the shape function is as it is not a built in MATLAB function. My guess is you want the size function.
You have complex indexing scheme going on. Unless the elements of X contain values that are indexes of the elements of f you are going to get an error. I've re-written your code applying MATLAB's mean function to each row.
mat = [1 2 14 6 5 48 96 175;...
   1 2 5 6 7 45 65 45];
[m, n] = size(mat);
Y=[];
for i =1 :m
   Y = [Y,mean(mat(i,:))];
end
Z = Y;

A: Yes, you can write higher-order functions in MATLAB. This requires function handles.
You create a function handle using the @ operator. For example, @mean is a handle to the function mean. You can also create anonymous functions (in other languages called lambdas), which can capture variables. For example,
data = rand(50,1);
func = @(ii)mean(data.^ii);

creates a function handle func that you can pass to a function and contains data.
Your rowMap function then can be written as
function Y = rowMap(f, X)
m = size(X, 1);
Y = zeros(m,1);
for i = 1:m
  Y(i) = f(X(i,:));
end

and be called with
X = randn(50, 50);
Y = rowMap(@mean, X);

or, using the function handle func we created above,
Y = rowMap(func, X);

(Do note that this is the same as calling Y = mean(X, 2), a lot of MATLAB functions work along one dimension only.)


text:
Q: Who closes an `InputStream` that is Returned from within a try with resources block? When doing a code review, I stumbled on some code that looks like this:
try (InputStream stream = new BufferedInputStream(resource)) {
    return stream;
}

where resource was defined elsewhere in the method. Note that this is sample code and that in real life, it's important that stream is closed so as not to leak resources.
My question is this: Will the try with resources block close stream on my behalf? Once stream has been returned to the caller, they might try to do something useful with it, or god forbid, hold a reference to it in a global variable that never gets cleaned up.
Will the try with resources block follow this reference around and dutifully clean it up? I can't find an answer to this in any of the tutorials or docs that I've read about this syntax.
My spidey sense is tingling and telling me that the better thing to do would be to copy the contents of the stream to some other object and then return that object to ensure that the stream is closed.

A: The Stream will be closed, if it is returned inside the try-with block.
This question was already asked, see here:
If it safe to return an InputStream from try-with-resource


text:
Q: Dropdown Menu not working on Index.html after adding java script I am Creating my personal website but I can not get the drop down to work on desktop then when it is on a mobile devise hide nav and click(using js) to show nav. But its not working only on the Index.html

GM

        Menu

Home

About

Portfolio

Music

Code

Contact

CSS:
/**Header**/
.nav {
    height: 61px;
    background: #381120;
}

.logo a{
    float: left;
    text-decoration: none;
    color: #7e7e7e;
    font-size: 43px;
    padding-top: 11px;
    padding-left: 30px;
}

.nav ul {
    margin: 0;
    padding: 0;
    float: right;
}

.nav ul li {
    list-style: none;
    float: left;
    display: block;
    padding: 19px;
}

.nav ul li a {
    color: #7e7e7e;
    text-decoration: none;
    font-size: 25px;
}

.nav ul ul.sub-nav {
    display: none;
    background: #381120;
    width: auto;
    position: absolute;
}

.nav ul li:hover > ul {
    display: block;
}

.nav ul ul li {
    float: none;
    padding-left: 24px;
}

.nav ul li a.active {
    color: #08a1c7;
}

.nav ul li a:hover {
    color: #efefef;
}

and:
.menu-trigger{
    padding-top: 16px;
    padding-right: 30px;
    font-size: 25px;
    text-align: center;
    display: none;
    float: right;
    color: #7e7e7e
}

.menu-trigger p{
    color: #7e7e7e
}

    /**480px**/

@media only screen and (max-width : 480px) {

    .menu-trigger{
        display: block;
    }

    .nav, .mobile-nav{
        display: none;
    }

    .nav-expanded{
        display: block;
    }

    .nav ul li{
        float: none;
        border-bottom: 1px solid #7e7e7e;
    }

    .nav ul li:last-child{
        border-bottom: none;
    }
}

Here is the JS sorry I forgot to put it on here:
jQuery(document).ready(function() {

    jQuery(".menu-trigger").click(function() {

        jQuery(".nav").slideToggle(400, function() {
            jQuery(this).toggleClass("nav-expanded").css('display', '');
        });

    });

});

A: You really should be able to animate all of this with just CSS. You don't even need jQuery for this, other than for the click action maybe.
Also, and this may not be the case, but in past I have had to write my click handlers like this to bypass some odd bugs. SlideToggle in jQuery can cause some glitchy effects and its not really a great way to do animated menu's. Try to avoid slideToggle().
$("[your-selector]").on("click",function(){
     /// do something...
});

A: I have created a jsfiddle with your code and its seems to work fine. Its rather unclear from what you ask, But what I guess is that your dropdown doesnt work on mobile screen. A problem could be importing jquery in your HTML file. That might solve your problem
jQuery(document).ready(function() {

    jQuery(".menu-trigger").click(function() {

        jQuery(".nav").slideToggle(400, function() {
            jQuery(this).toggleClass("nav-expanded").css('display', '');
        });

    });

});

A: Nevermind I fix it I added a

///content goes here

twice causing it to break Thank You for all your help still.


text:
Q: MATLAB : How to plot pdf I want to plot the following on the same piece of paper.
The pdf of exponential distribution with parameter 5
The pdf of t distribution with parameter 15
I don't know how to draw the pdf but know how to plot several figure on the same piece of paper by using command subplot()

A: Method 1: Use built-in functions  (requires Statistics toolbox)
Using exppdf() and tpdf() is easy but requires the Statistics Toolbox. If you don't have those functions then you can always directly code the PDF functions (Student's t and Exponential) as in Method 2 below.
Note that MATLAB parameterizes the Exponential distribution by the mean which is the inverse of the rate (lambda).
lambda = 5;
nu = 15;

Xrng = 0:.01:2;
Yrng = -5:.01:5;

figure
subplot(1,2,1)
plot(Xrng,exppdf(Xrng,1/lambda),'k-')
subplot(1,2,2)
plot(Yrng,tpdf(Yrng,nu),'b-')

Method 2: Hard-code PDF functions directly (no toolbox required)
You can always directly code the PDF functions (Student's t and Exponential).
fexph =@(x) lambda*exp(-lambda*x);
fth =@(x) (1/(sqrt(nu)*beta(0.5,0.5*nu)))*((1+((x.^2)./nu)).^(-0.5*(nu+1)));

figure
subplot(1,2,1)
plot(Xrng,fexph(Xrng),'k-')
subplot(1,2,2)
plot(Yrng,fth(Yrng),'b-')


text:
Q: Unable to convert output to list How to create a function that takes a list of non-negative integers and strings and return a new list without the strings?
Eg. filter_list([1, 2, "a", "b"]) ➞ [1, 2]
Issue: Not able to convert output to list
def filter_list(a):
    mylist=[]
    if type(a)==list:
        for i in a:
            if type(i)==int:
                output=print(i)
        mylist+=output
        return mylist

What am I doing wrong?

A: You could use a list comprehension which only includes list elements if they have the int type.
def filter_list(lis):
    return [i for i in lis if type(i) == int]

print(filter_list([1, 2, "a", "b"]))

Code Output:
[1, 2]

A: Can this help:
>>> def filter_list(lst):
    return [item for item in lst if type(item) is not str]

>>> filter_list([1, 2, 'a', 'b'])
[1, 2]
>>>

A: The mistake you made is that you are assigning the value returned by print() to output (which is None) and then you are adding a None type object to a list object which is an invalid operation. You can fix your code by doing something like this :
def filter_list(a):
    mylist=[]
    if type(a)==list:
        for i in a:
            if type(i)==int:
                print(i)
                mylist+=[i]
        return mylist

However this can be done in a much prettier way using List comprehensions!
List comprehension is a way to create a new list using a relatively much shorter syntax.
[elem for elem in _list if type(elem) is int]

A: Use isinstance and list comprehension:
def filter_list(lst):
    return [i for i in lst if isinstance(i, int)]

A: Use the filter function itself:
>>> list(filter(lambda x: isinstance(x, int), [1, 2, "a", "b"]))
[1, 2]

Issue with your code is that instead of printing and using += (which is used to concatenate two lists, not one list and one int) to add to your list, you should append the element like this:
for i in a:
    if type(i) == int:
        mylist.append(i)

A: You can use the filter method as follows:
def filter_list(a):
    return list(filter(lambda x: type(x) == int, a))

print(filter_list([1, 2, "a", "b"]))

Output:
[1, 2]

Your code fixed:
def filter_list(a):
    mylist=[]
    for i in a:
        if type(i)==int:
            mylist.append(i)
    return mylist

def filter_list1(a):
    return list(filter(lambda x: type(x) == int, a))

print(filter_list([1, 2, "a", "b"]), filter_list1([1, 2, "a", "b"]))

Output:
[1, 2] [1, 2]


text:
Q: PIG aggregate function - OutOfMemory: Java Heap Space The following fails:
data = FOREACH rawData GENERATE (int) col;
aggregate = FOREACH data GENERATE MIN(col);

Is there somehow I can get it the above to work?
I tried this:
data = FOREACH rawData GENERATE 1 dummy, (int) col;
grouped = GROUP data BY dummy;
aggregate = FOREACH grouped GENERATE MIN(data.col)

Now I get a: java.lang.Exception: java.lang.OutOfMemoryError: Java heap space
There are literally 11 rows of integers (1..11)...so not sure why I'm getting an outOfMemoryError?
I'm running the script from the command line pig -f myscript.pig
New to PIG so if I need to set something pls let me know...

A: Your intuition was correct in that you need to group the data first, before using MIN. You can use GROUP ALL for this purpose:
data = FOREACH rawData GENERATE (int) col;
grouped = GROUP data ALL;
aggregate = FOREACH grouped GENERATE MIN($1);

After a GROUP operation, $0 contains the group, $1 the first column, $2 the second column, and so on.


text:
Q: How to insert a column inbetween other columns (Perl Spreadsheet::WriteExcel) Lets say I have the following spreadsheet that I can parse in perl which looks like this:

I want to insert a column between Column1 and Column2. So end result looks like this:

It doesn't look like there is a set method for this in Spreadsheet-WriteExcel.
Does anyone know an easy way of doing this in Perl?
Many Thanks in advance!

A: The only(*) thing that Spreadsheet::WriteExcel can do is write spreadsheets. It doesn't have any facilities for reading an existing spreadsheet. Using it to modify an existing spreadsheet would involve first reading it with some other method (like Spreadsheet::ParseExcel) and then writing a brand new spreadsheet with the data the way you want it. Note that if you try this, you will lose macros, graphs, and any other feature that Spreadsheet::WriteExcel doesn't support.
The documentation for Spreadsheet::WriteExcel goes over a lot of the alternatives. See the WRITING EXCEL FILES and MODIFYING AND REWRITING EXCEL FILES sections. Win32::OLE for instance, gives you full access to Excel's internals with all the power and ease-of-use you'd expect from a Microsoft API. I'll leave it to you to judge whether any of these approaches qualify as "easy".
(*) - I don't mean that in a bad way. A Perl module that can write spreadsheets is pretty freaking cool.


text:
Q: Testing if there is any new knowledge in a third variable I am trying to predict the outcome $X$ of an event given a big set of input variables $A$, $B$, $C$, $D$, etc.
Both $X$ and $A$, $B$, $C$, etc. are categorical variables, some of them with a high number of categories.
We can think of $A$ as the main input because there is a hard correlation between $X$ and $A$. Also, most of the other variables $B$, $C$, $D$, etc. have a high correlation with $A$ too.
In order to reduce the size of my input vector I was thinking about some way to remove those variables that don't increase my knowledge about $X$ farther once I know $A$.
I am considering performing a $\chi^2$ test for every triplet $(X, A, anyOtherVar)$. My reasoning is that $p_{(A,B,X)} = p_A*p_{(B,X|A)}$ and if we assume that $B$ does not increase my knowledge about $X$ once I know $A$, then $p_{(A,B,X)} = p_A*p_{(B|A)}*p_{(X|A)}$ which becomes my null hypothesis.
And so, I can build the 3-dimensional contingency table using the probability from my null hypothesis $p_A*p_{(B|A)}*p_{(X|A)}$ instead of the usual $p_A*p_B*p_X$.
Does that procedure looks sound to you? Are there any other known and better approaches to attain my objective?
Update: Because of the hard correlations, I have a lot of zeros in the $p_{B|A}$ and $p_{X|A}$ matrices which result in divisions by zero in the $\chi^2$ addends. I can remove the cells with 0 predicted elements from the table, but then I am finding quite difficult to come with a method to calculate the degrees of freedom.

A: A reasonable approach for your problem is forward selection, a type of Stepwise Regression.
You could fit a regression with just the $A$ variables, and then compare this to the regression with the $A,B$, $A,C$, and $A,D$ variables via F-test where, for example
$$F_{A \; \text{vs.} \, A,B}=\frac{(SSE_A-SSE_{A,B})/(df_{A}-df_{A,B})}{SSE_{A,B}/df_{A,B}}.$$
Doing this for $A,B$, $A,C$, and $A,D$, you then add the variable to the model which had the highest value in the $F$ test (or if no variable was significant in the $F$ test you are done and can just stick with using $A$). You can then continue on in this manner to see if adding a third variable makes sense.
You can also try backward selection to see if it gives similar results.

A: The best method to achieve this would be a PCA or factor analysis on the variables before you do the regression. Think about it this way: If $A$ and $X$ are highly correlated, and $B$ and $X$ are also highly correlated, then very likely (but not necessarily) $A$ and $B$ are also correlated. So your variables $A,B,C,\ldots$ don't really capture independent information. This leads to problems in the analysis. So it is better to first remove this correlation and identify the underlying actual information in the variables. A PCA can achieve this.

A: It is not true that $\Pr(X|A, B) = \Pr(X|A)$ implies $\Pr(X|A, B, C) = \Pr(X|A, C)$: Given, $A$, a variable might predict $X$ together with another variable $C$ but not on it's own. And the same could hold for $C$.
Here's a stark example illustrating the point. Let $B$ be a coinflip. $C$ is another, independent, one. $X$ is a light. It turns on if $B$ and $C$ take the same value. $B$ is clearly useless for predicting $X$. As is $C$. But if you know both, you can perfectly predict $X$.
Considering one variable at a time in addition to $A$ would fail to uncover such interactions. It might be too aggressive and remove variables that would help.
But it might also be too conservative and fail to remove variables that are useless. If one variable is a copy of another, they'd both be kept even as only one of them is useful. From what you describe, this is likely in your case (the variables are highly correlated)
An alternative approach I'd suggest would be to estimate the additional predictive powers of large sets of variables in addition to $A$ jointly. Consider using a model with Lasso or Elastic Net penalty.

A: As @David Veich already mentioned a good way to proceed further would be feature selection methods like Forward selection,Backward elimination or Recursive feature elimination.
In place of these embedded Elimination methods you can also apply a Lasso Regression model.
You can also look into  discriminant correspondence analysis which is an extension of Linear Discriminant Analysis for Categorical Variables.
Do view this links for more information:
Lasso Regression for Categorical Variables
Discriminant Correspondence Analysis


text:
Q: How do I insert data into one table & get the primary key to insert in another table as a foreign key? I have 2 tables, users and syssla where syssla_id is a foreign key in users(syssla_id2).
create table syssla(
    syssla_id int auto_increment,
    Uppgift varchar (255),
    Information text,
    Tid varchar(100),
    primary key(syssla_id)
)engine=innodb;

create table users(
    user_id int ,
    username varchar (50),
    user_password varchar (50),
    Namn varchar(100),
    syssla_id2 int,
    primary key(user_id),
    foreign key(syssla_id2) references syssla(syssla_id)
)engine=innodb;

I want to do an insert with a form in php. But how can I do to get the foreign key to be inserted to a specific user in the other table(users) at the same time?

A: You should write a stored procedure that inserts first into syssla and then get the id using LAST_INSERT_ID() function to then insert new record into users

A: You do the following:
// you start a mysql transaction
$mysqli->begin_transaction();
// execute your first query
$mysqli->query(""); // Insert query here
$new_id = $mysqli->insert_id;

$mysqli->query(""); // second query here using the $new_id

$mysqli->commit();

$mysqli->close();

If for whatever reason the second query fails it will cancel the first query and it will be like nothing ever happened, also starting a transaction prevents other queries from overwriting you last inserted id. so you will never get the wrong id by some other query being executed by a different user.
ps. try and use prepared statements, they protect you better against sql injection than escaping variables manually


text:
Q: intersection of a closed-spline and a line given a closed piecewise polynomial spline and a line, what is the most efficient way to find the intersection(s) of the line and the spline?
each piece of the spline is given as:
$P_j(x)=\sum_{i=1}^k (x-b_j)^{k-i} c_{ji}$
where $k$ is the order for each polynomial, $j$ represents the number of pieces $j=1:L$, $b_j$ is the $j$th break, $c_{ji}$ is the coefficient.
I assume that the origin $[0,0]$ is inside the closed spline and the line always passes through the origin, hence $y=mx$.
As it can be seen in the following picture, the line passing through the origin intersects with the spline in 2 points that I am interested in. Is there a closed form solution for that?

A: Plug your spline equations into a line equation of the form $ax+by+c = 0$, and you will get a polynomial equation of degree $k-1$. The solutions of this equation are the parameter values on the spline where it intersects the line.
There is a closed-form solution only for the cases $k=2,3,4, 5$. But, even for the cases $k=4$ and $k=5$, the closed-form solutions are very complex and difficult to implement in floating-point arithmetic, so you might be better off with numerical methods.
None of this is related to the spline being closed -- the same approach works with splines that are either open or closed.
Tom Sederberg has written several papers comparing the reliability and efficiency of curve-curve intersection algorithms. You could start by looking up his paper on "Bezier clipping", or his notes here.


text:
Q: Zend Framework 2 - Annotation form - Bind doesn't work I'm using AnnotationForms and I altered my standard edit action from the tutorial to use Annotation and not standard forms.
Everything works except the $form->bind() doesn't fill in the values. The form fields stay empty.
I checked my variable which should be binded and it is set and looks good.
Here's my action:
    $id = (int)$this->getEvent()->getRouteMatch()->getParam('id');
    if (!$id) {
        return $this->redirect()->toRoute('album', array('action'=>'add'));
    }
    $album = $this->getEntityManager()->find('Album\Entity\Album', $id);

    $builder = new AnnotationBuilder();
    $form    = $builder->createForm(new \Album\Entity\Album());
    $form->add(new \MyVendor\Form\MyFieldset());
    $form->setBindOnValidate(false);
    $form->bind($album);

A: Alright, this was an easy one!
The trick is to transform your object to an array and use setData() instead of bind.
I found the solution hint here.
You still need bind() for saving the changes. If you leave it out, no error occurs but it won't save it either.
 $album = $this->getEntityManager()->find('Album\Entity\Album', $id);
 ...
 $form->bind($album);
 $form->setData($album->getArrayCopy());

A: The ClassMethods hydrator does actually work on bind, but the form element names need to match the lower-case-underscore Format (example: object property $moduleDisplayName, ClassMethods and ObjectProperty hydrator expect form element Name module_display_name.
The Zend\Form\Annotation by default produces a form element named moduleDisplayName. Therefore extracting the object to the form does not work.
Solution 1: Add the @Name Annotation to the property for ClassMethods to work.
Example:
/**
* @Form\Name("module_display_name")
protected $moduleDisplayName

Solution 2: Instantiate the ClassMethods hydrator with the optional Parameter underScoreSeperatedKeys set to false (Default is true) or use ClassMethods::setUnderScoreSeperatedKeys(false). Then ClassMethods will behave like any other hydrator.
The ObjectProperty hydrator works only on properties declared public. But naming is the same as with ArraySerializable (i.e. property $moduleDisplayName, form element Name moduleDisplayName).
The Reflection hydrator works on all properties. Naming is the same as with ArraySerializable.
Conclusion: ClassMethods is the one of four hydrators which expects a different form element naming scheme. Not too cool.


text:
Q: ruby - rackup problems I am trying to run rackup for running a ruby application. I am getting this error.
C:\Ali\Ruby\App>rackup -p  $PORT -o $IP
[2016-09-30 06:11:32] INFO  WEBrick 1.3.1
[2016-09-30 06:11:32] INFO  ruby 2.2.4 (2015-12-16) [i386-mingw32]
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/socket.rb:232:in `getaddrinfo': getad
drinfo: The specified class was not found.  (SocketError)
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/socket.rb:232:in `foreac
h'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/socket.rb:459:in `tcp_se
rver_sockets'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/utils.rb:70:in `
create_listeners'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/server.rb:133:in
 `listen'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/server.rb:114:in
 `initialize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:45
:in `initialize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib
/rack/handler/webrick.rb:31:in `new'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib
/rack/handler/webrick.rb:31:in `run'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib
/rack/server.rb:286:in `start'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib
/rack/server.rb:147:in `start'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rack-1.6.4/bin
/rackup:4:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.2.0/bin/rackup:23:in `load'
        from C:/RailsInstaller/Ruby2.2.0/bin/rackup:23:in `<main>'

What is wrong? Any help is appreciated.

A: Judging from your command-line path, you're using MS-DOS.  The variables $PATH and $IP are Unix-style variables.  Under MS-DOS, you would use %PATH% and %IP%.
Try:
C:\Ali\Ruby\App> echo %PATH%

and if that works (displays a long path), try making those changes.


text:
Q: Catched rejected promises via Promise.resolve arent recognized by Promise.all [UI5] given an promisesArray, if you were to add promises in this manner:
promisesArray.push(
    Promise.resolve(promise1)
        .catch((err) => {
           console.log("Hello World");
        })
);

If some of the promises were to be catched with Promise.resolve, the later Promise.all isn't going to recognize this promises as rejected
Promise.all(promisesArray)
 .then(()=> {
   //do something
  }, catch => {
   //error handling
  })

Hence going to the .then do something block
Question: What to do in this situation if you want Promise.all to do the catch block ?

A: You could try Promise.allSettled' instead of Promise.all to get an array of {status, value} objects which allows you to check which promises succeeded and which failed after the event. The push phase simplifies to
promisesArray.push( promise1) // etc

Afterwards you can check what happened:
Promise.allSettled(promisesArray).then( resultArray => {
    resultArray.forEach( (result, index) =>
       if( result.status == "fulfilled") {
           console.log( "promise %s was rejected with reason", index, result.reason);
       }
       else {
           console.log( "promise %s was fulfilled with value", index, result.value);
       }
   })
);


text:
Q: How to preserve values from multiple select objects on one form using Django HTMX Picture a todo list with multiple columns that include Priority, Status, AssignedTo, Due Date.  Now I have a form below this list that has a ChoiceBox (and in one case ModelChoiceBox) for each of these conditions.  So set Priority to 2, and the list refreshes to just 2's. Now select Status = 3 for example, and the two filters should be combined.  In my View however, they are not. The value of the most recent Select comes over, but he previous value is reset to None.  Here is a slimmed down example with just 2 Selects.

class FilterForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.attrs = {"novalidate": '', }

    priority = forms.ChoiceField(
        choices=PRIORITY_CHOICES,
        widget=forms.Select(attrs={
            'hx-get': reverse_lazy('change-priority'),
            'hx-target': '#tasklist',
            'hx-trigger': 'change'
        })
    )

    status = forms.ModelChoiceField(queryset=TaskStatus.objects.all(),
             widget=forms.Select(attrs={
              'hx-get': reverse_lazy('change-priority'),
              'hx-target': '#tasklist',
               'hx-trigger': 'change'
              })
          )

Here is a scaled down View:
def change_priority(request):
    filtform = FilterForm(request.POST)

    fpriority = filtform["priority"].value()

    fstatus = filtform["status"].value()
    tasklist = get_object_or_404(TaskList, owner=request.user)
    if tasklist:
        tasks = Task.objects.filter(priority=fpriority, status=fstatus)

        context = {
            "tasks": tasks,
            "filtform": filtform,

        }

        return render(request, "planner/partials/tasklist.html", context)
    return HttpResponse("Error - No Valid Task List")

So changing Priority sends the correct Selected value to View and Status is None. Then Select Status and hope to preserve Priority, but no. Now I get correct value for Status but Priority is None.
So you see I am trying to build a series of List filters that update the list dynamically and are cumulative.  Any idea how I can do this?

A: Since you are not submitting the whole form via HTMX, you need to explicitly include additional form elements in a HTMX request using hx-include attribute.
class FilterForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.attrs = {"novalidate": '', }

    priority = forms.ChoiceField(
        choices=PRIORITY_CHOICES,
        widget=forms.Select(attrs={
            'hx-get': reverse_lazy('change-priority'),
            'hx-include': '[name="status"]',
            'hx-target': '#tasklist',
            'hx-trigger': 'change'
        })
    )

    status = forms.ModelChoiceField(
        queryset=TaskStatus.objects.all(),
        widget=forms.Select(attrs={
           'hx-get': reverse_lazy('change-priority'),
           'hx-include': '[name="priority"]',
           'hx-target': '#tasklist',
           'hx-trigger': 'change'
        })
     )

You can also place it on common parent element, since it is inherited.


text:
Q: Make batch file interpret instructions line-by-line -WHAT I NEED
How can I create a batch file that interprets external instructions (not batch code) and puts them in a variable?

-WHAT I GOT
A sourceforge project called "Easy-Series" (For easier debunking, here is the download link for every dependency as well as main file; Ignore crashing when you put external commands, will fix that later, but if you can fix it, Please mention it in the comments.)

-SOLUTIONS THAT I HAVE RULED OUT
set
doesnt seem to work because I think it only grabs the first line of a file encoded in plain text format... Am I right? If not then you can theorize a solution...
-EXAMPLES EXPLAINED THOROUGHLY
Say I have a text file named commands.txt. I have a few EXTERNAL commands there to be INTERPRETED by an interpreter, of which I will code. I only need the "reading each line and put each line in separate variable" part. ONCE AGAIN, these commands are NOT batch commands, THESE ARE EXTERNAL COMMANDS which I need to be interpreted by an interpreter;
newfolder test
newfile test.txt
ping google.com

since I've already told you that this "Command Interpreter" called easycommandengine (Which aims for easier use of windows command line) interprets external instructions, I want each line to be put in a seperate variable
line 1 = ecl_ecmdengine_line%linecount%
line 2 = ecl_ecmdengine_line%linecount%
line 3 = ecl_ecmdengine_line%linecount%
line 4 = ecl_ecmdengine_line%linecount%
and so on and so forth

WHAT I MEAN BY THIS is THAT, say, LINE 1 of commands.txt which is newfolder test to be saved in variable "ecl_ecmdengine_line1"... 1 would be the %linecount% variable.
If you STILL don't understand (tl;dr?): I technically mean that I want a batch file to read .txt files with instructions the same way cmd reads batch files...
I'd also like the code to make %linecount% variable (which I suppose is already self-explanatory) work... I'm too newby to make for commands which just makes my mind blow up...

-NOTES
Once again, HERE are the files if you want to test my code out on your computer yourself...
If you think I have given too much or too few information, PM or Comment on this post, and I will try and fix it as soon as I can.

A: Test this - the last command will list the variables:
@echo off
setlocal enabledelayedexpansion
for /f "usebackq delims=" %%a in ("commands.txt") do (
set /a c+=1
set "command[!c!]=%%a"
)
set command[

A: @echo off

    setlocal enableextensions disabledelayedexpansion

    set "numLines=0"
    for /f "tokens=1,* delims=:" %%a in ('findstr /n "^" "commands.txt"') do (
        set "ecl_ecmdengine_line%%a=%%b"
        set /a "numLines+=1"
    )

    for /l %%a in (1 1 %numLines%) do (
        call echo line %%a is :%%ecl_ecmdengine_line%%a%%
    )

    setlocal enabledelayedexpansion
    for /l %%a in (1 1 %numLines%) do (
        echo line %%a is :!ecl_ecmdengine_line%%a!
    )
    endlocal

How to read lines from file (findstr is used to numerate the lines), and how to access its contents with or without delayed expansion enabled.

A: Previous answers from foxidrive and MC ND would solve your immediate problem, that is load lines from commands.txt into an array named ecl_ecmdengine_line. However, after that you need to process each one of the lines stored in the array, that is:
@echo off
setlocal EnableDelayedExpansion

rem Load lines from commands.txt into ecl_ecmdengine_line array:
set numLines=0
for /F "delims=" %%a in (commands.txt) do (
   set /A numLines+=1
   set "ecl_ecmdengine_line!numLines!=%%a"
)

rem Process the lines in ecl_ecmdengine_line array:
for /L %%i in (1,1,%numLines%) do echo process line %%i: !ecl_ecmdengine_line%%i!

However, previous method seems a waste to me. You may read the lines from commands.txt file and directly process them with no necessity to store they in any array. The Batch code below is an example of this method that also show how the commands could be processed:
@echo off

for /F "tokens=1*" %%a in (commands.txt) do call %%a %%b
goto :EOF

:newfolder
echo Creating newfolder for %*
exit /B

:newfile
echo Creating newfile for %*
exit /B

:ping
echo Executing ping with %*
exit /B