问:
How to investigate failing dataproc worker processes?
I'm running a PySpark job and Im having trouble determining the cause of failure on worker processes.

While my job is running I started noticing stack traces in the job output such as:

```<code>16/04/10 03:24:21 WARN org.apache.spark.scheduler.cluster.YarnSchedulerBackend$YarnSchedulerEndpoint: Container marked as failed: container_1460240417530_0021_01_000003 on host: cluster-2-w-0.c.my-project.internal. Exit status: -100. Diagnostics: Container released on a *lost* node
[Stage 0:=================================>                      (19 + 13) / 32]16/04/10 03:26:21 WARN org.apache.spark.rpc.netty.NettyRpcEndpointRef: Error sending message [message = RemoveExecutor(2,Container marked as failed: container_1460240417530_0021_01_000003 on host: cluster-2-w-0.c.my-project.internal. Exit status: -100. Diagnostics: Container released on a *lost* node)] in 1 attempts
org.apache.spark.rpc.RpcTimeoutException: Futures timed out after [120 seconds]. This timeout is controlled by spark.rpc.askTimeout
    at org.apache.spark.rpc.RpcTimeout.org$apache$spark$rpc$RpcTimeout$$createRpcTimeoutException(RpcTimeout.scala:48)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:63)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:76)
    at org.apache.spark.rpc.RpcEndpointRef.askWithRetry(RpcEndpointRef.scala:101)
    at org.apache.spark.rpc.RpcEndpointRef.askWithRetry(RpcEndpointRef.scala:77)
    at org.apache.spark.scheduler.cluster.CoarseGrainedSchedulerBackend.removeExecutor(CoarseGrainedSchedulerBackend.scala:359)
    at org.apache.spark.scheduler.cluster.YarnSchedulerBackend$YarnSchedulerEndpoint$$anonfun$receive$1.applyOrElse(YarnSchedulerBackend.scala:176)
    at org.apache.spark.rpc.netty.Inbox$$anonfun$process$1.apply$mcV$sp(Inbox.scala:116)
    at org.apache.spark.rpc.netty.Inbox.safelyCall(Inbox.scala:204)
    at org.apache.spark.rpc.netty.Inbox.process(Inbox.scala:100)
    at org.apache.spark.rpc.netty.Dispatcher$MessageLoop.run(Dispatcher.scala:215)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException: Futures timed out after [120 seconds]
    at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219)
    at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223)
    at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:107)
    at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
    at scala.concurrent.Await$.result(package.scala:107)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:75)
    ... 11 more
16/04/10 03:26:40 WARN org.apache.spark.rpc.netty.NettyRpcEndpointRef: Error sending message [message = RequestExecutors(23,0,Map())] in 1 attempts
org.apache.spark.rpc.RpcTimeoutException: Cannot receive any reply in 120 seconds. This timeout is controlled by spark.rpc.askTimeout
    at org.apache.spark.rpc.RpcTimeout.org$apache$spark$rpc$RpcTimeout$$createRpcTimeoutException(RpcTimeout.scala:48)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:63)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33)
    at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:185)
    at scala.util.Try$.apply(Try.scala:161)
    at scala.util.Failure.recover(Try.scala:185)
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324)
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at org.spark-project.guava.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:293)
    at scala.concurrent.impl.ExecutionContextImpl$$anon$1.execute(ExecutionContextImpl.scala:133)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248)
    at scala.concurrent.Promise$class.complete(Promise.scala:55)
    at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.processBatch$1(Future.scala:643)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.apply$mcV$sp(Future.scala:658)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.apply(Future.scala:635)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.apply(Future.scala:635)
    at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch.run(Future.scala:634)
    at scala.concurrent.Future$InternalCallbackExecutor$.scala$concurrent$Future$InternalCallbackExecutor$$unbatchedExecute(Future.scala:694)
    at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:685)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248)
    at scala.concurrent.Promise$class.tryFailure(Promise.scala:112)
    at scala.concurrent.impl.Promise$DefaultPromise.tryFailure(Promise.scala:153)
    at org.apache.spark.rpc.netty.NettyRpcEnv$$anon$1.run(NettyRpcEnv.scala:241)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException: Cannot receive any reply in 120 seconds
    at org.apache.spark.rpc.netty.NettyRpcEnv$$anon$1.run(NettyRpcEnv.scala:242)
    ... 7 more
[Stage 0:=================================>                      (19 + 13) / 32]
</code>```

Ill also notice the overall CPU usage of the cluster slowly drop as worker nodes fail. These nodes seem to permanently fail and do not re-join the cluster:

I'm using preemtible machines but when I check the status of these machines they are still running and have not been preempted. So I'm guessing its something wrong on the worker:

答:
It could be because of the heavy workload in the workers. Try to increase spark.network.timeout (default 120) to a bigger number.

If that is not resolving the error, most likely causes are garbage collection. Try to run a memory profile with the following options.
-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/ -XX:+CMSClassUnloadingEnabled

Body:
I'm running a PySpark job and Im having trouble determining the cause of failure on worker processes.

While my job is running I started noticing stack traces in the job output such as:

16/04/10 03:24:21 WARN org.apache.spark.scheduler.cluster.YarnSchedulerBackend$YarnSchedulerEndpoint: Container marked as failed: container_1460240417530_0021_01_000003 on host: cluster-2-w-0.c.my-project.internal. Exit status: -100. Diagnostics: Container released on a *lost* node
[Stage 0:=================================>                      (19 + 13) / 32]16/04/10 03:26:21 WARN org.apache.spark.rpc.netty.NettyRpcEndpointRef: Error sending message [message = RemoveExecutor(2,Container marked as failed: container_1460240417530_0021_01_000003 on host: cluster-2-w-0.c.my-project.internal. Exit status: -100. Diagnostics: Container released on a *lost* node)] in 1 attempts
org.apache.spark.rpc.RpcTimeoutException: Futures timed out after [120 seconds]. This timeout is controlled by spark.rpc.askTimeout
    at org.apache.spark.rpc.RpcTimeout.org$apache$spark$rpc$RpcTimeout$$createRpcTimeoutException(RpcTimeout.scala:48)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:63)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:76)
    at org.apache.spark.rpc.RpcEndpointRef.askWithRetry(RpcEndpointRef.scala:101)
    at org.apache.spark.rpc.RpcEndpointRef.askWithRetry(RpcEndpointRef.scala:77)
    at org.apache.spark.scheduler.cluster.CoarseGrainedSchedulerBackend.removeExecutor(CoarseGrainedSchedulerBackend.scala:359)
    at org.apache.spark.scheduler.cluster.YarnSchedulerBackend$YarnSchedulerEndpoint$$anonfun$receive$1.applyOrElse(YarnSchedulerBackend.scala:176)
    at org.apache.spark.rpc.netty.Inbox$$anonfun$process$1.apply$mcV$sp(Inbox.scala:116)
    at org.apache.spark.rpc.netty.Inbox.safelyCall(Inbox.scala:204)
    at org.apache.spark.rpc.netty.Inbox.process(Inbox.scala:100)
    at org.apache.spark.rpc.netty.Dispatcher$MessageLoop.run(Dispatcher.scala:215)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException: Futures timed out after [120 seconds]
    at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219)
    at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223)
    at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:107)
    at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
    at scala.concurrent.Await$.result(package.scala:107)
    at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:75)
    ... 11 more
16/04/10 03:26:40 WARN org.apache.spark.rpc.netty.NettyRpcEndpointRef: Error sending message [message = RequestExecutors(23,0,Map())] in 1 attempts
org.apache.spark.rpc.RpcTimeoutException: Cannot receive any reply in 120 seconds. This timeout is controlled by spark.rpc.askTimeout
    at org.apache.spark.rpc.RpcTimeout.org$apache$spark$rpc$RpcTimeout$$createRpcTimeoutException(RpcTimeout.scala:48)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:63)
    at org.apache.spark.rpc.RpcTimeout$$anonfun$addMessageIfTimeout$1.applyOrElse(RpcTimeout.scala:59)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33)
    at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:185)
    at scala.util.Try$.apply(Try.scala:161)
    at scala.util.Failure.recover(Try.scala:185)
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324)
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at org.spark-project.guava.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:293)
    at scala.concurrent.impl.ExecutionContextImpl$$anon$1.execute(ExecutionContextImpl.scala:133)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248)
    at scala.concurrent.Promise$class.complete(Promise.scala:55)
    at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.processBatch$1(Future.scala:643)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.apply$mcV$sp(Future.scala:658)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.apply(Future.scala:635)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch$$anonfun$run$1.apply(Future.scala:635)
    at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
    at scala.concurrent.Future$InternalCallbackExecutor$Batch.run(Future.scala:634)
    at scala.concurrent.Future$InternalCallbackExecutor$.scala$concurrent$Future$InternalCallbackExecutor$$unbatchedExecute(Future.scala:694)
    at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:685)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248)
    at scala.concurrent.Promise$class.tryFailure(Promise.scala:112)
    at scala.concurrent.impl.Promise$DefaultPromise.tryFailure(Promise.scala:153)
    at org.apache.spark.rpc.netty.NettyRpcEnv$$anon$1.run(NettyRpcEnv.scala:241)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException: Cannot receive any reply in 120 seconds
    at org.apache.spark.rpc.netty.NettyRpcEnv$$anon$1.run(NettyRpcEnv.scala:242)
    ... 7 more
[Stage 0:=================================>                      (19 + 13) / 32]

Ill also notice the overall CPU usage of the cluster slowly drop as worker nodes fail. These nodes seem to permanently fail and do not re-join the cluster:

I'm using preemtible machines but when I check the status of these machines they are still running and have not been preempted. So I'm guessing its something wrong on the worker:


来源: stackexchange

问:
jQuery UI dialog form, not sending correct variable
I'm loading a customer info page using jQuery. There's a list of customers with a link next to it:

```<code><a href="#" onclick="load_customer(<?php echo $c->id; ?>);return false;">View</a>
</code>```

That triggers this function:

```<code>function load_customer(id) {
  $("#dashboard").load('get_info/' + id);
}
</code>```

That works perfectly. On the page I'm loading, I have a jQuery UI modal dialog form for adding new information.

```<code><div id="addinfo">
  <form><input type="hidden" name="customer_id" value="<?php echo $c->id; ?>" /></form>
</div>
</code>```

My javascript:

```<code>  $("#addinfobutton").click(function(){
            $("#addinfo").dialog("open");
            return false;
   });
   $("#addinfo").dialog({
            autoOpen:false,
            width:400,
            height:550,
            modal: true
   });
</code>```

When you select a customer the first time, it populates the hidden field correctly, but then it stays the same even after selecting other customers.

I thought that by loading a new customer page, the form would reset as well... but apparently it's being stored/cached somewhere. If I echo the ID anywhere else in the page, it shows correctly... just not in the "addinfo" div.

Any help/suggestions would be appreciated! Thanks!

答:
JQuery dialog's dont reload the content for you when you open them. I tend to have an AJAX call replacing the content of the div that the dialog is on (or tweakng some values in it) when the dialog is opened.

If you want a hidden field, then I wouldn't put it within the dialog, you should be able to retrieve the value from outside the dialog.

ContentLicense: CC BY-SA 2.5

Body:
I'm loading a customer info page using jQuery. There's a list of customers with a link next to it:

<a href="#" onclick="load_customer(<?php echo $c->id; ?>);return false;">View

That triggers this function:

function load_customer(id) {
  $("#dashboard").load('get_info/' + id);
}

That works perfectly. On the page I'm loading, I have a jQuery UI modal dialog form for adding new information.

  <form><input type="hidden" name="customer_id" value="<?php echo $c->id; ?>" /></form>

My javascript:

  $("#addinfobutton").click(function(){
            $("#addinfo").dialog("open");
            return false;
   });
   $("#addinfo").dialog({
            autoOpen:false,
            width:400,
            height:550,
            modal: true
   });

When you select a customer the first time, it populates the hidden field correctly, but then it stays the same even after selecting other customers.

I thought that by loading a new customer page, the form would reset as well... but apparently it's being stored/cached somewhere. If I echo the ID anywhere else in the page, it shows correctly... just not in the "addinfo" div.

Any help/suggestions would be appreciated! Thanks!


问:
iOS/Android finger print - authentication server side
I'm trying to wrap my head around how to implement iOS/Android finger print to authenticate a user.

From what I understand, triggering the finger print dialog is just an additional security?

So a typical on boarding process would be something like this:

User downloads the app.

User registers/signs in, and get a token back from the server.

On certain actions where we need additional security, trigger finger print dialog.

If fingerprint is OK - do actual REST call with token from step 2.

Am I missing something?

答:
Please read one of these blogs (there's many others):

http://www.techotopia.com/index.php/An_Android_Fingerprint_Authentication_Tutorial

https://www.survivingwithandroid.com/2016/12/android-fingerprint-authentication-tutorial.html

Process have to be:

User must have already register fingerprint and choose unlock device with fingerprint in Android Settings app.

User downloads the app.

User registers/signs in with fingerprint check

App generate a local token and store in secure (secure element) keystore on device

this local app token is sent to server

On certain actions where we need additional security, trigger finger print dialog.

If fingerprint is OK, app ahs access to secure key store to get token. App can use this token to do REST call from step 4.

ContentLicense: CC BY-SA 3.0


问:
Can we integrate Paypal Payment Gateway with IONIC 1 or 2 app if yes then how...?
I have developed a mobile application for Android & iOS using IONIC framework. Now I want to integrate Payment Gateway with the same app.

I have gone through multiple links, but didn't get a final answer it is it possible to integrate Paypal with IONIC or not.

答:
This is created by me and successfully work in ionic 1 you can try this:

https://github.com/hitarthiCreole/ionic-paypal-sdk-demo

for a other reference you can also go through this:

http://ionicandroidlearning.blogspot.in/2015/11/ionic-paypal-integration.html

https://github.com/paypal/PayPal-Cordova-Plugin#your-app-integration


问:
store value into an array JS
I would like to store some values into an array in HTML. The values are from a random number generator in Python as {{player.a1s1}}. This has been taken care of. basically, when on each click on button "mm1a" , the player will see one more button in the form. the number of clicks will be recorded. and I would like to have the random number {{player.a1s1}} shown on the button to be stored in JS as an array. My code could not store the value into array.

HTML

```<code><div class="container1">
<p>
    {{ player.text1a }} # this will get the text from a python variable.
</p>

<form id="frm1">
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
</form>
</div>

<div><button class="mm1a" type="button">{{ player.optiona1 }}</button>
# this will get the innerhtml from another python variable.

</div>

<p>
  samplemma1<input id="id_samplemma1" name="samplemma1" value="0"></input>
</p>
</code>```

in javascript

```<code>$('.mm1a').on('click',function(){
$('.toAdd:eq('+count+')').show();
count++;
hello();
getarraya();
});

var clicks = 0; # to count how many clickes the players did
function hello() {
    clicks += 1;
    document.getElementById("id_clicksmma1").innerHTML = clicks;
    document.getElementById("id_clicksmma1").value = clicks;
};

# below part does not work
var myarraya = [];
var c = 0;
function getarraya() {
    c += 1;
    myarraya.push(document.forms["frm1"].elements[c].innerHTML);
    document.getElementById("id_clicksmma1").innerHTML = myarraya;
    document.getElementById("id_clicksmma1").value = myarraya;
};
</code>```

答:
jquery "on" must be inside document.ready and variable myarraya
and  c  move it to top.</p>

Title: store value into an array JS

Body:
I would like to store some values into an array in HTML. The values are from a random number generator in Python as {{player.a1s1}}. This has been taken care of. basically, when on each click on button "mm1a" , the player will see one more button in the form. the number of clicks will be recorded. and I would like to have the random number {{player.a1s1}} shown on the button to be stored in JS as an array. My code could not store the value into array.

HTML

    {{ player.text1a }} # this will get the text from a python variable.

<form id="frm1">
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
<button  class="toAdd">{{player.a1s1}}</button>
</form>

<button class="mm1a" type="button">{{ player.optiona1 }}</button>
# this will get the innerhtml from another python variable.

  samplemma1<input id="id_samplemma1" name="samplemma1" value="0"></input>

in javascript

$('.mm1a').on('click',function(){
$('.toAdd:eq('+count+')').show();
count++;
hello();
getarraya();
});

var clicks = 0; # to count how many clickes the players did
function hello() {
    clicks += 1;
    document.getElementById("id_clicksmma1").innerHTML = clicks;
    document.getElementById("id_clicksmma1").value = clicks;
};

# below part does not work
var myarraya = [];
var c = 0;
function getarraya() {
    c += 1;
    myarraya.push(document.forms["frm1"].elements[c].innerHTML);
    document.getElementById("id_clicksmma1").innerHTML = myarraya;
    document.getElementById("id_clicksmma1").value = myarraya;
};


问:
How to know other music player app is playing in android programmatically in android
I am playing music player from assets in my application. When other music player app is playing my app(music player) has stopped. If my app(music player is resumed) the other music player is still continuing playing song. How to know other music player app is stopped from service or other callbacks?</p>

```<code>import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.IBinder;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.util.Log;

import com.myapp.music.MusicMediaController;

public class MyMusicService extends Service implements      AudioManager.OnAudioFocusChangeListener {

private AudioManager mAudioManager;

@Override
public void onCreate() {
    super.onCreate();

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onAudioFocusChange(int focusChange) {

    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            MusicMediaController.getInstance().resumeAudio();
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            MusicMediaController.getInstance().pauseAudio();
            mAudioManager.abandonAudioFocus(this);
            break;
    }
}
}
</code>```

答:
AudioManager has a method to know if the music is active:</p>

```<code>val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
  if (audioManager.isMusicActive && isEnabled) {
   ...
  }
</code>```

Body:
I am playing music player from assets in my application. When other music player app is playing my app(music player) has stopped. If my app(music player is resumed) the other music player is still continuing playing song. How to know other music player app is stopped from service or other callbacks?

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.IBinder;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.util.Log;

import com.myapp.music.MusicMediaController;

public class MyMusicService extends Service implements      AudioManager.OnAudioFocusChangeListener {

private AudioManager mAudioManager;

@Override
public void onCreate() {
    super.onCreate();

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onAudioFocusChange(int focusChange) {

    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            MusicMediaController.getInstance().resumeAudio();
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            MusicMediaController.getInstance().pauseAudio();
            mAudioManager.abandonAudioFocus(this);
            break;
    }
}
}

Body:
AudioManager has a method to know if the music is active:

val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
  if (audioManager.isMusicActive && isEnabled) {
   ...
  }


问:
Ruby query need to update
Relationship:

account has_many users

user has_one sima

primary_partner_id is "account_id" which is passing as params.

```<code>User.where(primary_partner_id: 2).map{|a| a.sima}.reject{ |e| e.to_s.empty?}
</code>```

Results as below:

```<code> [
    #<Sima id: 93, user_id: 7, interviewer_account_user_id: 1945, interviewer_completion_date: "2017-06-09", transcriber_account_user_id: nil, transcriber_completion_date: nil, biographer_account_user_id: nil, biographer_completion_date: nil, reviewer_account_user_id: nil, reviewer_completion_date: nil, status: "accepted", autobiographical_form: "27381", autobiographical_form_completion_date: nil, sima_level_id: "1", created_at: "2017-06-06 20:17:57", updated_at: "2017-06-09 10:04:33", autobiographical_form_comments: nil, on_hold: nil, comments: [{:comment=>"easylims.xlsx", :user_name=>"Mike Burns", :created_at=>2017-06-06 20:17:57 UTC}, {:comment=>"ok", :user_name=>"SIMA Admin", :created_at=>2017-06-06 20:19:33 UTC}], interviewer_id: nil, interviewer_start_date: nil, transcriber_start_date: nil, biographer_start_date: nil, reviewer_start_date: nil>,
    #<Sima id: 92, user_id: 1, interviewer_account_user_id: nil, interviewer_completion_date: nil, transcriber_account_user_id: nil, transcriber_completion_date: nil, biographer_account_user_id: nil, biographer_completion_date: nil, reviewer_account_user_id: nil, reviewer_completion_date: nil, status: "accepted", autobiographical_form: "27437", autobiographical_form_completion_date: nil, sima_level_id: "1", created_at: "2017-06-06 20:01:50", updated_at: "2017-06-06 20:22:50", autobiographical_form_comments: nil, on_hold: nil, comments: [{:comment=>"original_msg (1).txt", :user_name=>"bild_cloud@bild.org", :created_at=>2017-06-06 20:01:50 UTC}, {:comment=>"ok", :user_name=>"SIMA Admin", :created_at=>2017-06-06 20:22:05 UTC}], interviewer_id: nil, interviewer_start_date: nil, transcriber_start_date: nil, biographer_start_date: nil, reviewer_start_date: nil>
 ]
</code>```

Sima has field like status and I have three statuses as "pending, accepted, declined"

Question:

Now I want to show the result as per status which will pass by the user as params. So the result should be as per status from Sima. If params is status=" accepted" then Sima list will have only which has status "accepted"

答:
If you add to Sima Model
belongs_to :user You can get an list of Sima by
Sima.joins(:users).where(users: { primary_partner_id: 2 }).where(status: 'accepted')

Title: Ruby query need to update

Body:
Relationship:

account has_many users

user has_one sima

primary_partner_id is "account_id" which is passing as params.

User.where(primary_partner_id: 2).map{|a| a.sima}.reject{ |e| e.to_s.empty?}

Results as below:

 [
    #<Sima id: 93, user_id: 7, interviewer_account_user_id: 1945, interviewer_completion_date: "2017-06-09", transcriber_account_user_id: nil, transcriber_completion_date: nil, biographer_account_user_id: nil, biographer_completion_date: nil, reviewer_account_user_id: nil, reviewer_completion_date: nil, status: "accepted", autobiographical_form: "27381", autobiographical_form_completion_date: nil, sima_level_id: "1", created_at: "2017-06-06 20:17:57", updated_at: "2017-06-09 10:04:33", autobiographical_form_comments: nil, on_hold: nil, comments: [{:comment=>"easylims.xlsx", :user_name=>"Mike Burns", :created_at=>2017-06-06 20:17:57 UTC}, {:comment=>"ok", :user_name=>"SIMA Admin", :created_at=>2017-06-06 20:19:33 UTC}], interviewer_id: nil, interviewer_start_date: nil, transcriber_start_date: nil, biographer_start_date: nil, reviewer_start_date: nil>,
    #<Sima id: 92, user_id: 1, interviewer_account_user_id: nil, interviewer_completion_date: nil, transcriber_account_user_id: nil, transcriber_completion_date: nil, biographer_account_user_id: nil, biographer_completion_date: nil, reviewer_account_user_id: nil, reviewer_completion_date: nil, status: "accepted", autobiographical_form: "27437", autobiographical_form_completion_date: nil, sima_level_id: "1", created_at: "2017-06-06 20:01:50", updated_at: "2017-06-06 20:22:50", autobiographical_form_comments: nil, on_hold: nil, comments: [{:comment=>"original_msg (1).txt", :user_name=>"bild_cloud@bild.org", :created_at=>2017-06-06 20:01:50 UTC}, {:comment=>"ok", :user_name=>"SIMA Admin", :created_at=>2017-06-06 20:22:05 UTC}], interviewer_id: nil, interviewer_start_date: nil, transcriber_start_date: nil, biographer_start_date: nil, reviewer_start_date: nil>
 ]

Sima has field like status and I have three statuses as "pending, accepted, declined"

Question:

Now I want to show the result as per status which will pass by the user as params. So the result should be as per status from Sima. If params is status=" accepted" then Sima list will have only which has status "accepted"


问:
Why is YouTube Media Player not stopping?
Refering to Workaround for Youtube API? code which I made it work as expected(check my answer to the question) with only one problem: When I go back, the Youtube Player is still playing.

I tried Overriding onPause() function from Fragment class but is not working..
Also within another class, I have myOnBackPressed() function which handle the adapter and fragments..

```<code>public void myOnBackPressed() {
    FragmentManager fragmentManager = getFragmentManager();

    if (eventDetailsFragment == null || fragmentManager == null)
        return;
    fragmentManager.beginTransaction().detach(eventDetailsFragment).remove(eventDetailsFragment).commit();
    fragmentManager.popBackStack();

    getChildFragmentManager().popBackStackImmediate(R.id.event_list_frame, FragmentManager.POP_BACK_STACK_INCLUSIVE);

    ((EventListActivity) getActivity()).menuRestoreClickListener();
    ((EventListActivity) getActivity()).menuDefaulClickListener();
    if (titleBefore != null && !titleBefore.isEmpty())
        toolbar.setTitle(titleBefore);
    toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_menu));

}
</code>```

What I am actually trying, is to make the player stops from within this function

Any idea would be appreciated, thanks !

答:
As I thought, the problem was with the backstack

I just had to pop the fragment containing Youtube Player from the stack

```<code>android.support.v4.app.FragmentManager supportFragmentManager = ((FragmentActivity) getActivity()).getSupportFragmentManager();
supportFragmentManager.popBackStack();
</code>```

Body:
Refering to Workaround for Youtube API? code which I made it work as expected(check my answer to the question) with only one problem: When I go back, the Youtube Player is still playing.

I tried Overriding onPause() function from Fragment class but is not working..
Also within another class, I have myOnBackPressed() function which handle the adapter and fragments..

public void myOnBackPressed() {
    FragmentManager fragmentManager = getFragmentManager();

    if (eventDetailsFragment == null || fragmentManager == null)
        return;
    fragmentManager.beginTransaction().detach(eventDetailsFragment).remove(eventDetailsFragment).commit();
    fragmentManager.popBackStack();

    getChildFragmentManager().popBackStackImmediate(R.id.event_list_frame, FragmentManager.POP_BACK_STACK_INCLUSIVE);

    ((EventListActivity) getActivity()).menuRestoreClickListener();
    ((EventListActivity) getActivity()).menuDefaulClickListener();
    if (titleBefore != null && !titleBefore.isEmpty())
        toolbar.setTitle(titleBefore);
    toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_menu));

}

What I am actually trying, is to make the player stops from within this function

Any idea would be appreciated, thanks !

Body:
As I thought, the problem was with the backstack

I just had to pop the fragment containing Youtube Player from the stack

android.support.v4.app.FragmentManager supportFragmentManager = ((FragmentActivity) getActivity()).getSupportFragmentManager();
supportFragmentManager.popBackStack();


问:
how can i stop a ajax request in ajaxSend?
```<code>$('#speichern').live('click' , function () {

    var data_save = $('#form_rechn').serialize()+ '&' + 'action=save' + '&' + 'total=' + Number($('#grandTotal').text().replace(/EUR/g, ""));

 $.ajax({
    type    : "POST",
    cache   : false,
    url     : 'invoice_new_action.php',
    data    : data_save,

    ajaxSend : $.post("invoice_new_action.php",{"action":"before","rn":   $('#rn').val()},function(huhn){
                var totest = Number(huhn)
                if ( totest == "") {
                    } else {
                $('#rn').val(totest);
                $.fancybox('nr. existiert. ');
                return false; // Why don't stop here?
                };}),

     error:function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
     },
    success : function(data) {
        $.fancybox(data);
            }
    });
</code>```

Can I do it another way? Why is the ajax not stopped via return false?

答:
Why doesn't it stop? Because the function you are defining is the callback function for $.post, which will always be called when you get a response from post. Because $.post is asynchronous by default, you can't post and wait for a response to find out if you should keep going with your original ajax call.

You could either use synchronous ajax post (eww! bad!) or you could explain the end result you are trying to accomplish. With the community's help, perhaps you can rethink your implementation to something that doesn't require one ajax post to decide if you need to post another. In general, I think what you want is this:

```<code>$('#speichern').live('click' , function () {
  // Immediately post to test if you should keep going
  $.post('...',function(huhn){
    // ...
    if (totest){
      // Oh, OK, now we can call the real ajax.
      $.post(...,data_save,function(data){
        $.fancybox(data);
      });
    }
  }
});
</code>```

Body:
$('#speichern').live('click' , function () {

    var data_save = $('#form_rechn').serialize()+ '&' + 'action=save' + '&' + 'total=' + Number($('#grandTotal').text().replace(/EUR/g, ""));

 $.ajax({
    type    : "POST",
    cache   : false,
    url     : 'invoice_new_action.php',
    data    : data_save,

    ajaxSend : $.post("invoice_new_action.php",{"action":"before","rn":   $('#rn').val()},function(huhn){
                var totest = Number(huhn)
                if ( totest == "") {
                    } else {
                $('#rn').val(totest);
                $.fancybox('nr. existiert. ');
                return false; // Why don't stop here?
                };}),

     error:function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
     },
    success : function(data) {
        $.fancybox(data);
            }
    });

Can I do it another way? Why is the ajax not stopped via return false?

Body:
Why doesn't it stop? Because the function you are defining is the callback function for $.post, which will always be called when you get a response from post. Because $.post is asynchronous by default, you can't post and wait for a response to find out if you should keep going with your original ajax call.

You could either use synchronous ajax post (eww! bad!) or you could explain the end result you are trying to accomplish. With the community's help, perhaps you can rethink your implementation to something that doesn't require one ajax post to decide if you need to post another. In general, I think what you want is this:

$('#speichern').live('click' , function () {
  // Immediately post to test if you should keep going
  $.post('...',function(huhn){
    // ...
    if (totest){
      // Oh, OK, now we can call the real ajax.
      $.post(...,data_save,function(data){
        $.fancybox(data);
      });
    }
  }
});


问:
faster alternative to memcpy?
I have a function that is doing memcpy, but it's taking up an enormous amount of cycles. Is there a faster alternative/approach than using memcpy to move a piece of memory?</p>

答:
This is an answer for x86_64 with AVX2 instruction set present. Though something similar may apply for ARM/AArch64 with SIMD.

On Ryzen 1800X with single memory channel filled completely (2 slots, 16 GB DDR4 in each), the following code is 1.56 times faster than memcpy() on MSVC++2017 compiler. If you fill both memory channels with 2 DDR4 modules, i.e. you have all 4 DDR4 slots busy, you may get further 2 times faster memory copying. For triple-(quad-)channel memory systems, you can get further 1.5(2.0) times faster memory copying if the code is extended to analogous AVX512 code. With AVX2-only triple/quad channel systems with all slots busy are not expected to be faster because to load them fully you need to load/store more than 32 bytes at once (48 bytes for triple- and 64-bytes for quad-channel systems), while AVX2 can load/store no more than 32 bytes at once. Though multithreading on some systems can alleviate this without AVX512 or even AVX2.

So here is the copy code that assumes you are copying a large block of memory whose size is a multiple of 32 and the block is 32-byte aligned.

For non-multiple size and non-aligned blocks, prologue/epilogue code can be written reducing the width to 16 (SSE4.1), 8, 4, 2 and finally 1 byte at once for the block head and tail. Also in the middle a local array of 2-3 __m256i values can be used as a proxy between aligned reads from the source and aligned writes to the destination.

```<code>#include <immintrin.h>
#include <cstdint>
/* ... */
void fastMemcpy(void *pvDest, void *pvSrc, size_t nBytes) {
  assert(nBytes % 32 == 0);
  assert((intptr_t(pvDest) & 31) == 0);
  assert((intptr_t(pvSrc) & 31) == 0);
  const __m256i *pSrc = reinterpret_cast<const __m256i*>(pvSrc);
  __m256i *pDest = reinterpret_cast<__m256i*>(pvDest);
  int64_t nVects = nBytes / sizeof(*pSrc);
  for (; nVects > 0; nVects--, pSrc++, pDest++) {
    const __m256i loaded = _mm256_stream_load_si256(pSrc);
    _mm256_stream_si256(pDest, loaded);
  }
  _mm_sfence();
}
</code>```

A key feature of this code is that it skips CPU cache when copying: when CPU cache is involved (i.e. AVX instructions without _stream_ are used), the copy speed drops several times on my system.

My DDR4 memory is 2.6GHz CL13 . So when copying 8GB of data from one array to another I got the following speeds:

```<code>memcpy(): 17,208,004,271 bytes/sec.
Stream copy: 26,842,874,528 bytes/sec.
</code>```

Note that in these measurements the total size of both input and output buffers is divided by the number of seconds elapsed. Because for each byte of the array there are 2 memory accesses: one to read the byte from the input array, another to write the byte to the output array. In the other words, when copying 8GB from one array to another, you do 16GB worth of memory access operations.

Moderate multithreading can further improve performance about 1.44 times, so total increase over memcpy() reaches 2.55 times on my machine.
Here's how stream copy performance depends on the number of threads used on my machine:

```<code>Stream copy 1 threads: 27114820909.821 bytes/sec
Stream copy 2 threads: 37093291383.193 bytes/sec
Stream copy 3 threads: 39133652655.437 bytes/sec
Stream copy 4 threads: 39087442742.603 bytes/sec
Stream copy 5 threads: 39184708231.360 bytes/sec
Stream copy 6 threads: 38294071248.022 bytes/sec
Stream copy 7 threads: 38015877356.925 bytes/sec
Stream copy 8 threads: 38049387471.070 bytes/sec
Stream copy 9 threads: 38044753158.979 bytes/sec
Stream copy 10 threads: 37261031309.915 bytes/sec
Stream copy 11 threads: 35868511432.914 bytes/sec
Stream copy 12 threads: 36124795895.452 bytes/sec
Stream copy 13 threads: 36321153287.851 bytes/sec
Stream copy 14 threads: 36211294266.431 bytes/sec
Stream copy 15 threads: 35032645421.251 bytes/sec
Stream copy 16 threads: 33590712593.876 bytes/sec
</code>```

The code is:

```<code>void AsyncStreamCopy(__m256i *pDest, const __m256i *pSrc, int64_t nVects) {
  for (; nVects > 0; nVects--, pSrc++, pDest++) {
    const __m256i loaded = _mm256_stream_load_si256(pSrc);
    _mm256_stream_si256(pDest, loaded);
  }
}

void BenchmarkMultithreadStreamCopy(double *gpdOutput, const double *gpdInput, const int64_t cnDoubles) {
  assert((cnDoubles * sizeof(double)) % sizeof(__m256i) == 0);
  const uint32_t maxThreads = std::thread::hardware_concurrency();
  std::vector<std::thread> thrs;
  thrs.reserve(maxThreads + 1);

  const __m256i *pSrc = reinterpret_cast<const __m256i*>(gpdInput);
  __m256i *pDest = reinterpret_cast<__m256i*>(gpdOutput);
  const int64_t nVects = cnDoubles * sizeof(*gpdInput) / sizeof(*pSrc);

  for (uint32_t nThreads = 1; nThreads <= maxThreads; nThreads++) {
    auto start = std::chrono::high_resolution_clock::now();
    lldiv_t perWorker = div((long long)nVects, (long long)nThreads);
    int64_t nextStart = 0;
    for (uint32_t i = 0; i < nThreads; i++) {
      const int64_t curStart = nextStart;
      nextStart += perWorker.quot;
      if ((long long)i < perWorker.rem) {
        nextStart++;
      }
      thrs.emplace_back(AsyncStreamCopy, pDest + curStart, pSrc+curStart, nextStart-curStart);
    }
    for (uint32_t i = 0; i < nThreads; i++) {
      thrs[i].join();
    }
    _mm_sfence();
    auto elapsed = std::chrono::high_resolution_clock::now() - start;
    double nSec = 1e-6 * std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
    printf("Stream copy %d threads: %.3lf bytes/sec\n", (int)nThreads, cnDoubles * 2 * sizeof(double) / nSec);

    thrs.clear();
  }
}
</code>```

UPDATE 2023-01-18:
I don't have that system anymore, but the 2666MHz DDR4 is marked PC4-21300U, meaning 22334668800 bytes/second from one RAM slot. As I had 2 RAM slots, the max bandwidth was 44669337600 bytes/second. And the approach with SIMD and multithreading achieved 87.72% of the theoretical bandwidth when using 5 threads.

Title: faster alternative to memcpy?

Body:
This is an answer for x86_64 with AVX2 instruction set present. Though something similar may apply for ARM/AArch64 with SIMD.

On Ryzen 1800X with single memory channel filled completely (2 slots, 16 GB DDR4 in each), the following code is 1.56 times faster than memcpy() on MSVC++2017 compiler. If you fill both memory channels with 2 DDR4 modules, i.e. you have all 4 DDR4 slots busy, you may get further 2 times faster memory copying. For triple-(quad-)channel memory systems, you can get further 1.5(2.0) times faster memory copying if the code is extended to analogous AVX512 code. With AVX2-only triple/quad channel systems with all slots busy are not expected to be faster because to load them fully you need to load/store more than 32 bytes at once (48 bytes for triple- and 64-bytes for quad-channel systems), while AVX2 can load/store no more than 32 bytes at once. Though multithreading on some systems can alleviate this without AVX512 or even AVX2.

So here is the copy code that assumes you are copying a large block of memory whose size is a multiple of 32 and the block is 32-byte aligned.

For non-multiple size and non-aligned blocks, prologue/epilogue code can be written reducing the width to 16 (SSE4.1), 8, 4, 2 and finally 1 byte at once for the block head and tail. Also in the middle a local array of 2-3 __m256i values can be used as a proxy between aligned reads from the source and aligned writes to the destination.

#include <immintrin.h>
#include <cstdint>
/* ... */
void fastMemcpy(void *pvDest, void *pvSrc, size_t nBytes) {
  assert(nBytes % 32 == 0);
  assert((intptr_t(pvDest) & 31) == 0);
  assert((intptr_t(pvSrc) & 31) == 0);
  const __m256i *pSrc = reinterpret_cast<const __m256i*>(pvSrc);
  __m256i *pDest = reinterpret_cast<__m256i*>(pvDest);
  int64_t nVects = nBytes / sizeof(*pSrc);
  for (; nVects > 0; nVects--, pSrc++, pDest++) {
    const __m256i loaded = _mm256_stream_load_si256(pSrc);
    _mm256_stream_si256(pDest, loaded);
  }
  _mm_sfence();
}

A key feature of this code is that it skips CPU cache when copying: when CPU cache is involved (i.e. AVX instructions without _stream_ are used), the copy speed drops several times on my system.

My DDR4 memory is 2.6GHz CL13 . So when copying 8GB of data from one array to another I got the following speeds:

memcpy(): 17,208,004,271 bytes/sec.
Stream copy: 26,842,874,528 bytes/sec.

Note that in these measurements the total size of both input and output buffers is divided by the number of seconds elapsed. Because for each byte of the array there are 2 memory accesses: one to read the byte from the input array, another to write the byte to the output array. In the other words, when copying 8GB from one array to another, you do 16GB worth of memory access operations.

Moderate multithreading can further improve performance about 1.44 times, so total increase over memcpy() reaches 2.55 times on my machine.
Here's how stream copy performance depends on the number of threads used on my machine:

Stream copy 1 threads: 27114820909.821 bytes/sec
Stream copy 2 threads: 37093291383.193 bytes/sec
Stream copy 3 threads: 39133652655.437 bytes/sec
Stream copy 4 threads: 39087442742.603 bytes/sec
Stream copy 5 threads: 39184708231.360 bytes/sec
Stream copy 6 threads: 38294071248.022 bytes/sec
Stream copy 7 threads: 38015877356.925 bytes/sec
Stream copy 8 threads: 38049387471.070 bytes/sec
Stream copy 9 threads: 38044753158.979 bytes/sec
Stream copy 10 threads: 37261031309.915 bytes/sec
Stream copy 11 threads: 35868511432.914 bytes/sec
Stream copy 12 threads: 36124795895.452 bytes/sec
Stream copy 13 threads: 36321153287.851 bytes/sec
Stream copy 14 threads: 36211294266.431 bytes/sec
Stream copy 15 threads: 35032645421.251 bytes/sec
Stream copy 16 threads: 33590712593.876 bytes/sec

The code is:

void AsyncStreamCopy(__m256i *pDest, const __m256i *pSrc, int64_t nVects) {
  for (; nVects > 0; nVects--, pSrc++, pDest++) {
    const __m256i loaded = _mm256_stream_load_si256(pSrc);
    _mm256_stream_si256(pDest, loaded);
  }
}

void BenchmarkMultithreadStreamCopy(double *gpdOutput, const double *gpdInput, const int64_t cnDoubles) {
  assert((cnDoubles * sizeof(double)) % sizeof(__m256i) == 0);
  const uint32_t maxThreads = std::thread::hardware_concurrency();
  std::vector<std::thread> thrs;
  thrs.reserve(maxThreads + 1);

  const __m256i *pSrc = reinterpret_cast<const __m256i*>(gpdInput);
  __m256i *pDest = reinterpret_cast<__m256i*>(gpdOutput);
  const int64_t nVects = cnDoubles * sizeof(*gpdInput) / sizeof(*pSrc);

  for (uint32_t nThreads = 1; nThreads <= maxThreads; nThreads++) {
    auto start = std::chrono::high_resolution_clock::now();
    lldiv_t perWorker = div((long long)nVects, (long long)nThreads);
    int64_t nextStart = 0;
    for (uint32_t i = 0; i < nThreads; i++) {
      const int64_t curStart = nextStart;
      nextStart += perWorker.quot;
      if ((long long)i < perWorker.rem) {
        nextStart++;
      }
      thrs.emplace_back(AsyncStreamCopy, pDest + curStart, pSrc+curStart, nextStart-curStart);
    }
    for (uint32_t i = 0; i < nThreads; i++) {
      thrs[i].join();
    }
    _mm_sfence();
    auto elapsed = std::chrono::high_resolution_clock::now() - start;
    double nSec = 1e-6 * std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
    printf("Stream copy %d threads: %.3lf bytes/sec\n", (int)nThreads, cnDoubles * 2 * sizeof(double) / nSec);

    thrs.clear();
  }
}

UPDATE 2023-01-18:
I don't have that system anymore, but the 2666MHz DDR4 is marked PC4-21300U, meaning 22334668800 bytes/second from one RAM slot. As I had 2 RAM slots, the max bandwidth was 44669337600 bytes/second. And the approach with SIMD and multithreading achieved 87.72% of the theoretical bandwidth when using 5 threads.

ContentLicense: CC BY-SA 4.0


问:
Get text from multiple classes in scrapy
I want to crawl data from a website. I use this code

```<code>import scrapy

class KamusSetSpider(scrapy.Spider):
    name = "kamusset_spider"
    start_urls = ['http://kbbi.web.id/abadi']

    def parse(self, response):
        SET_SELECTOR = '.tur highlight'
        for brickset in response.css(SET_SELECTOR):
            yield {
                'name': brickset.css(SET_SELECTOR).extract_first(),
            }
</code>```

and this is the inspect element:

I want to get every text in the red oval, like mengabadi, mengabadikan, etc. There are multiple class in the 'b' tag => tur highlight. But, I have not get any result.

What's the problem? How to solve it?
I have change my code become this:

```<code>def parse(self, response):
        for kamusset in response.css("div#d1"):
            text = kamusset.css("div.sub_17 b.tur.highlight::text").extract()
            print(dict(text=text))
</code>```

but still not working. It return null.

答:
Selector .tur highlight means - select elements highlight inside all elements with class tur.

To select elements with multiple classes use selector without whitespaces :

```<code>SET_SELECTOR = '.tur.highlight'
</code>```

Body:
I want to crawl data from a website. I use this code

import scrapy

class KamusSetSpider(scrapy.Spider):
    name = "kamusset_spider"
    start_urls = ['http://kbbi.web.id/abadi']

    def parse(self, response):
        SET_SELECTOR = '.tur highlight'
        for brickset in response.css(SET_SELECTOR):
            yield {
                'name': brickset.css(SET_SELECTOR).extract_first(),
            }

and this is the inspect element:

I want to get every text in the red oval, like mengabadi, mengabadikan, etc. There are multiple class in the 'b' tag => tur highlight. But, I have not get any result.

What's the problem? How to solve it?
I have change my code become this:

def parse(self, response):
        for kamusset in response.css("div#d1"):
            text = kamusset.css("div.sub_17 b.tur.highlight::text").extract()
            print(dict(text=text))

but still not working. It return null.

Body:
Selector .tur highlight means - select elements highlight inside all elements with class tur.

To select elements with multiple classes use selector without whitespaces :

SET_SELECTOR = '.tur.highlight'


问:
How to automate the crawling without hardcoding any number to it?
I've written a script using python with selenium to scrape names of restaurants from a webpage. It is working great if I hardcode the number of amount I want to parse. The page has got lazy-loading process and it displays 40 names in each scroll. However, my script can handle it. The only thing I would like to improve in my script is that I do not wish to hardcode the number; rather, I want it to detect itself how many are there and parse it successfully. Hope there is someone to help. Here is the code:</p>

```<code>from selenium import webdriver
import time

driver = webdriver.Chrome()

driver.get('https://www.yellowpages.ca/search/si/1/pizza/Toronto')

while True:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(3)

    links = [posts.text for posts in driver.find_elements_by_xpath("//div[@itemprop='itemListElement']//h3[@itemprop='name']/a")]

    if (len(links) == 240):
            break

for link in links:
    print(link)

driver.quit()
</code>```

答:
You can check if the number of links has changed in the last iteration</p>

```<code>num_Of_links = -1
num = 0
while num != num_Of_links:
    num_Of_links = num
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(3)

    links = [posts.text for posts in driver.find_elements_by_xpath("//div[@itemprop='itemListElement']//h3[@itemprop='name']/a")]
    num = len(links)
</code>```

Body:
I've written a script using python with selenium to scrape names of restaurants from a webpage. It is working great if I hardcode the number of amount I want to parse. The page has got lazy-loading process and it displays 40 names in each scroll. However, my script can handle it. The only thing I would like to improve in my script is that I do not wish to hardcode the number; rather, I want it to detect itself how many are there and parse it successfully. Hope there is someone to help. Here is the code:

from selenium import webdriver
import time

driver = webdriver.Chrome()

driver.get('https://www.yellowpages.ca/search/si/1/pizza/Toronto')

while True:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(3)

    links = [posts.text for posts in driver.find_elements_by_xpath("//div[@itemprop='itemListElement']//h3[@itemprop='name']/a")]

    if (len(links) == 240):
            break

for link in links:
    print(link)

driver.quit()

Body:
You can check if the number of links has changed in the last iteration

num_Of_links = -1
num = 0
while num != num_Of_links:
    num_Of_links = num
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(3)

    links = [posts.text for posts in driver.find_elements_by_xpath("//div[@itemprop='itemListElement']//h3[@itemprop='name']/a")]
    num = len(links)


问:
How to open another submit form after submitting one on html or javascript?
I am trying to open another form to get inputs after submitting one. In my code, I want to edit a node in my array and by getting the first input I make the program find my node to edit. If the input is valid -the input is one of the nodes in my array-, I want it to open another  on the same place as the first one. How can I do that?</p>

```<code><p>
  <a href="#" style="font-size: 20px" onclick="toggle_visibility('editNodeForm');">EDIT AN EXISTING NODE</a>
</p>
<form action="#" style="display: none;" id="editNodeForm">ID or Name:
  <input type="text" id="toEdit" size="20" style="width: 50%; height: 2em;">
  <br />
  <br />
  <button type="button" class="myButton" form="editNodeForm" style="width: 50%;" onclick="editExistingNode();">Submit</button>
  <br />
  <br />
</form>
</code>```

答:
Try to replace the the line

```<code>nextDiv = parent.next('div');
</code>```

with:

```<code>nextDiv = $(this).parent().next('div');
</code>```

in the code of the comment above, if it's not working

Body:
I am trying to open another form to get inputs after submitting one. In my code, I want to edit a node in my array and by getting the first input I make the program find my node to edit. If the input is valid -the input is one of the nodes in my array-, I want it to open another  on the same place as the first one. How can I do that?

  EDIT AN EXISTING NODE

<form action="#" style="display: none;" id="editNodeForm">ID or Name:
  <input type="text" id="toEdit" size="20" style="width: 50%; height: 2em;">

  <button type="button" class="myButton" form="editNodeForm" style="width: 50%;" onclick="editExistingNode();">Submit</button>

</form>

Body:
Try to replace the the line

nextDiv = parent.next('div');

with:

nextDiv = $(this).parent().next('div');

in the code of the comment above, if it's not working


问:
Detecting near-by phone numbers
Trying to figure out some sort of method in which it would be possible to detect nearby phone numbers e.g. within a private premises.

My only lead so far is to build a mini mobile base station that would let phones connect to it - even then my theory for this has many holes and blanks.

The above may be completely off or possibly I may be on to something, either way if someone could give me a rough idea of what direction to take it in that would be much appreciated - I do not require any kind of code as I would much rather figure it out myself via a finger pointed in the right direction.

Even if you do not have any solid answers but some tips that could possibly help me piece this together, that'd be great.

答:
This link might be useful. It feature some code and instructions for a personal cell tower.
https://julianoliver.com/output/stealth-cell-tower</p>

Title: Detecting near-by phone numbers


问:
numpy: pass by reference does not work on itself
I tried the following:

```<code>p=np.array([[1,1,1],[2,2,2],[3,3,3]])
p[0,:] = p[1,:]
y = p[1,:]
print(p)
p[1,1] = 4
print(p)
print(y)
</code>```

As you can see the output is:

```<code>[[2 2 2]
 [2 2 2]
 [3 3 3]]
[[2 2 2]
 [2 4 2]
 [3 3 3]]
[2 4 2]
</code>```

So when I assigned the second row of p to y it was passed by reference. When I assigned the second row of p to the first row of p it was passed by copy. Why is that the case?

The output I expected is:

```<code>[[2 2 2]
 [2 2 2]
 [3 3 3]]
[[2 4 2]
 [2 4 2]
 [3 3 3]]
[2 4 2]
</code>```

答:
In short, the difference:

accessing a slice of an array (... = p[]) creates a new view into the data if possible.

assigning to a slice of an array (p[] = ...) copies elemets into the array.

The long story:

After p = np.array([[1,1,1],[2,2,2],[3,3,3]]) p holds the original data.

y = p[1,:] gives you a view into the data held by p (You can verify this by looking at y.base, which is p). This is not an assignment into an array, but y is a completely new object that shares data with p. Think of it like this:

```<code>Data: [1, 1, 1, 2, 2, 2, 3, 3, 3]
       ^        ^
       p        y
</code>```

The data is just a block of memory. p points to the beginning of this memory and y points somewhere in the middle. (They don't merely "point" but also contain additional information about dimensions and who owns the data, but this is not important here.)

It is important to recognize that an array points only to the beginning of its associated data. Then it simply uses dimensions and step sizes (strides) to interpret the data as vectors, matrices, etc. Remember: one array - one pointer.

p[0,:] = p[1,:] here we assign a part of p to another part of the array. To get the expected behavior different parts of p would need to point to the same block of data. This is not possible (but something similar can be achieved in a limited way by cleverly manipulating strides). Instead, the data is copied.

Body:
I tried the following:

p=np.array([[1,1,1],[2,2,2],[3,3,3]])
p[0,:] = p[1,:]
y = p[1,:]
print(p)
p[1,1] = 4
print(p)
print(y)

As you can see the output is:

[[2 2 2]
 [2 2 2]
 [3 3 3]]
[[2 2 2]
 [2 4 2]
 [3 3 3]]
[2 4 2]

So when I assigned the second row of p to y it was passed by reference. When I assigned the second row of p to the first row of p it was passed by copy. Why is that the case?

The output I expected is:

[[2 2 2]
 [2 2 2]
 [3 3 3]]
[[2 4 2]
 [2 4 2]
 [3 3 3]]
[2 4 2]

Body:
In short, the difference:

accessing a slice of an array (... = p[]) creates a new view into the data if possible.

assigning to a slice of an array (p[] = ...) copies elemets into the array.

The long story:

After p = np.array([[1,1,1],[2,2,2],[3,3,3]]) p holds the original data.

y = p[1,:] gives you a view into the data held by p (You can verify this by looking at y.base, which is p). This is not an assignment into an array, but y is a completely new object that shares data with p. Think of it like this:

Data: [1, 1, 1, 2, 2, 2, 3, 3, 3]
       ^        ^
       p        y

The data is just a block of memory. p points to the beginning of this memory and y points somewhere in the middle. (They don't merely "point" but also contain additional information about dimensions and who owns the data, but this is not important here.)

It is important to recognize that an array points only to the beginning of its associated data. Then it simply uses dimensions and step sizes (strides) to interpret the data as vectors, matrices, etc. Remember: one array - one pointer.

p[0,:] = p[1,:] here we assign a part of p to another part of the array. To get the expected behavior different parts of p would need to point to the same block of data. This is not possible (but something similar can be achieved in a limited way by cleverly manipulating strides). Instead, the data is copied.


问:
Errors when compiling wxWidgets
I'm following this tutorial to begin with Code::Blocks using wxWidgets.

Following the tutorial, my first step was:

```<code>cd C:\wxWidgets-3.0.3\build\msw
</code>```

Since I have the mingw32-make.exe installed in the directory C:\Program Files\CodeBlocks\MinGW\bin, next I do the following (again based on the tutorial):

```<code>C:\wxWidgets-3.0.3\build\msw>"C:\Program Files\CodeBlocks\MinGW\bin\mingw32-make" -f makefile.gcc BUILD=release SHARED=0 MONOLITHIC=1 UNICODE=1 CXXFLAGS=-fno-keep-inline-dllexport
</code>```

The output I get is:

```<code>gcc -c -o gcc_mswu\wxregex_regcomp.o  -O2 -mthreads  -DHAVE_W32API_H -DNDEBUG -I
..\..\include -I..\..\lib\gcc_lib\mswu -D__WXMSW__  -D_UNICODE   -MTgcc_mswu\wxr
egex_regcomp.o -MFgcc_mswu\wxregex_regcomp.o.d -MD -MP ../../src/regex/regcomp.c

gcc: error: CreateProcess: No such file or directory
makefile.gcc:5702: recipe for target 'gcc_mswu\wxregex_regcomp.o' failed
mingw32-make: *** [gcc_mswu\wxregex_regcomp.o] Error 1
</code>```

I think that gcc is not found, so I need to edit the makefile.gcc

Am I right?

I'm not used to makefiles, so, I apologize but I need some help.

答:
Open a command box and cd C:\wxWidgets-3.0.3\build\msw

Type and press enter:

PATH=%PATH%;C:\Program Files\CodeBlocks\MinGW\bin

This will add the mingw needed files (they execute chained) to your PATH, only for the command box. If you want it permanent, modify PATHenviroment var in you Windows settings.

Now run the command to compile wxWidgets:

mingw32-make" -f makefile.gcc BUILD=release SHARED=0 MONOLITHIC=1 UNICODE=1 CXXFLAGS="-std=gnu++11" The std=gnu+11 flag is default (not needed) if your mingw version uses gcc >=5.2. Use it anyhow, it's harmless.

Adding RUNTIME_LIBS=static may avoid to have a couple of mingw libs visible (on the path). This way you can run your app without providing those libs.

Probably you'll get zillions of warnings (not errors) about "deprecating" with BestSize. That's a gcc <5.3 bug, not wx one.

You can get rid of those messages modifying a few lines at include/wx/window.h But better don't use the old version that ships with CB and download the newest one from http://www.mingw.org/

Title: Errors when compiling wxWidgets

Body:
I'm following this tutorial to begin with Code::Blocks using wxWidgets.

Following the tutorial, my first step was:

cd C:\wxWidgets-3.0.3\build\msw

Since I have the mingw32-make.exe installed in the directory C:\Program Files\CodeBlocks\MinGW\bin, next I do the following (again based on the tutorial):

C:\wxWidgets-3.0.3\build\msw>"C:\Program Files\CodeBlocks\MinGW\bin\mingw32-make" -f makefile.gcc BUILD=release SHARED=0 MONOLITHIC=1 UNICODE=1 CXXFLAGS=-fno-keep-inline-dllexport

The output I get is:

gcc -c -o gcc_mswu\wxregex_regcomp.o  -O2 -mthreads  -DHAVE_W32API_H -DNDEBUG -I
..\..\include -I..\..\lib\gcc_lib\mswu -D__WXMSW__  -D_UNICODE   -MTgcc_mswu\wxr
egex_regcomp.o -MFgcc_mswu\wxregex_regcomp.o.d -MD -MP ../../src/regex/regcomp.c

gcc: error: CreateProcess: No such file or directory
makefile.gcc:5702: recipe for target 'gcc_mswu\wxregex_regcomp.o' failed
mingw32-make: *** [gcc_mswu\wxregex_regcomp.o] Error 1

I think that gcc is not found, so I need to edit the makefile.gcc

Am I right?

I'm not used to makefiles, so, I apologize but I need some help.


问:
Fast drawing lots of rectangles one at a time in WPF
My application is fed data from an external device. After each data point, there is a short electronic
dead time (of about 10µs) in which no other data point can arrive, which my application should use to process and display
the data on screen in a scatter plot. My most important goal is to not exceed this electronic dead time.
How would one approach this problem in a WPF based application, and what would be a way to benchmark different methods?

Things I've tried are:

Creating a Rectangle in a Canvas for every arriving data point. This is too slow by a factor of 10.

The same approach, but drawing DrawingVisuals in a custom control. Better, but still a little too slow. Adding visual/logical children to the tree may have too much overhead.

A UserControl where all data points are stored in an array and displayed in the OnRender method. Here I have to draw every point again on each call to OnRender. This method therefore slows down over time, which is undesireable. Is there a way to tell OnRender not to clear the screen on each pass, so that I could paint incrementally?

Displaying each point as a pixel in a WriteableBitmap. This seems to work, but I 've not found a way to determine, if invalidating part of the Bitmap does not add a few very long  wait times ocassionally (when the Image is actually refreshed on screen). Any Ideas for measuring this?

Edit:

In the comments, the point of buffering data and displaying it at a slower rate has been raised.
The problem with that approach is, that at some point I have to process the buffer.
Doing that during the measurement introduces a long time during which my system is busy and new events would be discarded.
Therefore dealing with every point individually, but for good, would be more desireable. Using 10 µs to trigger the display for every event is much better than storing it into a buffer in no time and use 100µs every 50  ms or so to process the accumulated events.

I the olden (i.e. non-WPF) days, you could e.g. put the neccesary data into the graphics memory, and have the graphics card deal with it at its convenience. Of cource, it would not actually be displayed at a rate faster than 60Hz, but you did not have to touch this data again.

答:
If I get it right you have a scenario where you want to get data from your sensor for a few seconds - and show it. You have a realtime requirement - or do you store the data from your special "camera" as an image and the realtime plotting is just for shows?

If so you could wait the few seconds and then show the result?

It sounds like WritableBitmap could be a way to solve your problem.
I would assume that there is an overhead each time you have a lock/unlock block since it has to do with theading - so I don't think it is a good idea for each point.
To get timing on it you could use a profiler on a test project / test data - dotTrace from jetbrains is ok - I think they have a trial version.  You could also use a performance counter - that might be usefull for other stuff as well.

I would make it multithreaded and have a high priority thread to process the incomming points - or do you recive interrups from your device? As i understand it is more important to get all point than to draw all points rightaway.

You write that WritableBitmap is barely fast enough - so with your current solution I would try saving calls to AddDirtyRect so it is only at every n points/millisec - transfer to the frontbuffer should be fast even if it is a large block.
You should be able to get it just as fast with wpf as with forms - its just nicer.

With some code and more info on your system it would be easier to answer :)


问:
Removing specific parts of a string c#

ANS680401571E0001(FreeEntry-ControlledExit)01930F0003(InService)019423Gate Interface Controller 173(0XAD)019545G.I.C(1014028) EntryValidator(01.00.14028) ExitValidator(01.00.14028)53

Everything before the first "(" needs to be removed. There is no rule as to how long this part can be(it differs). Then after ")" everything needs to be removed EXCEPT for the last 4 characters before the next "(" ,in this case 0003 needs to stay. Also note that the 01930F can change and the length will also change. Next every between after the "(InService)" and "Gate" has to be removed. and last everything after "ExitValidator(01.00.14028)" has to be removed.

This is basically what it needs to look like once done.

(FreeEntry-ControlledExit)
0003(InService)
Gate Interface Controller 173(0XAD)
G.I.C(1014028)
EntryValidator(01.00.14028)
ExitValidator(01.00.14028)

答:
There's no easy solution for that but I would start with making some method to substring your whole input string like such :

```<code>string p(string input, string openSign, string closeSign, ref int sPos, int lOffset = 0, int rOffset = 0)
{
    int idxL = input.IndexOf(openSign, sPos);
    int idxR = input.IndexOf(closeSign, idxL);
    sPos = idxL + 1;
    if(idxL != -1 && idxR != -1)
    {
        int s = idxL - lOffset;
        int e = idxR + 1 + rOffset;
        return input.Substring(s, e - s);
    }
    return string.Empty;
}
</code>```

Then you can make use it like such :

```<code>string input = "ANS680401571E0001(FreeEntry-ControlledExit)01930F0003(InService)019423Gate Interface Controller 173(0XAD)019545G.I.C(1014028) EntryValidator(01.00.14028) ExitValidator(01.00.14028)53";
string build = "";

build = "";

int i = 0;
build += p(input, "(", ")", ref i, 0, 0);
build += p(input, "(", ")", ref i, 4, 0);
build += p(input, "Gate", ")", ref i, 0, 0);
build += p(input, "G.I.C", ")", ref i, 0, 0);
build += p(input, "Entry", ")", ref i, 0, 0);
build += p(input, "Exit", ")", ref i, 0, 0);
</code>```

Which will result with build being >> "(FreeEntry-ControlledExit)0003(InService)Gate Interface Controller 173(0XAD)G.I.C(1014028)EntryValidator(01.00.14028)ExitValidator(01.00.14028)"

Online example

This should be possible with regular expressions but I don't have time now to think about that. Maybe I'll update my answer later on when there will be no sufficient answer.

Title: Removing specific parts of a string c#

Body:
There's no easy solution for that but I would start with making some method to substring your whole input string like such :

string p(string input, string openSign, string closeSign, ref int sPos, int lOffset = 0, int rOffset = 0)
{
    int idxL = input.IndexOf(openSign, sPos);
    int idxR = input.IndexOf(closeSign, idxL);
    sPos = idxL + 1;
    if(idxL != -1 && idxR != -1)
    {
        int s = idxL - lOffset;
        int e = idxR + 1 + rOffset;
        return input.Substring(s, e - s);
    }
    return string.Empty;
}

Then you can make use it like such :

string input = "ANS680401571E0001(FreeEntry-ControlledExit)01930F0003(InService)019423Gate Interface Controller 173(0XAD)019545G.I.C(1014028) EntryValidator(01.00.14028) ExitValidator(01.00.14028)53";
string build = "";

build = "";

int i = 0;
build += p(input, "(", ")", ref i, 0, 0);
build += p(input, "(", ")", ref i, 4, 0);
build += p(input, "Gate", ")", ref i, 0, 0);
build += p(input, "G.I.C", ")", ref i, 0, 0);
build += p(input, "Entry", ")", ref i, 0, 0);
build += p(input, "Exit", ")", ref i, 0, 0);

Which will result with build being >> "(FreeEntry-ControlledExit)0003(InService)Gate Interface Controller 173(0XAD)G.I.C(1014028)EntryValidator(01.00.14028)ExitValidator(01.00.14028)"

Online example

This should be possible with regular expressions but I don't have time now to think about that. Maybe I'll update my answer later on when there will be no sufficient answer.


问:
Compressed representation of polygons
I have a lot of (millions) of polygons from openstreetmap-data with mostly (more than 99%) exactly four coordinates representing houses.

Example

I currently save the four coordinates for each house explicitly as Tuple of floats (Latitude and Longitude), hence taking 32 bytes of memory.

Is there a way to store this information in a compressed way (fewer than 32 byte) since the four coordinates only differ very few in the last decimals?

答:
You are giving no information on the resolution you want to keep.

Assuming 1 m accuracy is enough, 24 bits can cover up to 16000 km. Then 8 bits should also be enough to represent the size information (up to 256 m).

This would make 8 bytes per house.

More aggressive compression for instance with Huffman coding will probably not work on the locations (relatively uniform distribution); a little better on the sizes, but the benefit is marginal.

Title: Compressed representation of polygons