问:
Cannot compile with Proguard using Californium library: SHA-256 digest error for class
I'm using the Californium library. I have added the following dependencies to the build.gradle:

```<code>implementation 'org.eclipse.californium:californium-core:1.0.5'
implementation 'org.eclipse.californium:scandium:1.0.5'
</code>```

The app doesn't compile, but I was able to fix this by adding this to the build.gradle as well:

```<code>android {
    ...
    packagingOptions {
        exclude 'edl-v10.html'
        exclude 'epl-v10.html'
        exclude 'notice.html'
    }
}
</code>```

Now the app compiles without errors. However, when I enable proguard / code shrinking like this:

```<code>android {
    ...
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            ...
        }
    }
}
</code>```

Then the debug version of my app doesn't compile anymore! This is the error message:

```<code>Error:Execution failed for task ':app:transformClassesWithAndroidGradleClassShrinkerForDevDebug'.
> SHA-256 digest error for org/eclipse/californium/core/network/config/NetworkConfigObserverAdapter.class
</code>```

I noticed after trying this multiple times, the class above keeps changing to a different one. After adding the following to the proguard rules it still doesn't work:

```<code>-keep class org.eclipse.** { *; }
-keep interface org.eclipse.** { *; }
-keep enum org.eclipse.** { *; }
-dontwarn org.eclipse.**
</code>```

This is the full stacktrace in the gradle console:

```<code>org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithAndroidGradleClassShrinkerForDevDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:60)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:128)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:46)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$ExecuteTasks.run(DefaultGradleLauncher.java:311)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.initialization.DefaultGradleLauncher.runTasks(DefaultGradleLauncher.java:202)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:132)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:107)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:53)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:45)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:29)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:71)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:45)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:51)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:42)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:58)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:33)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.SecurityException: SHA-256 digest error for org/eclipse/californium/core/network/config/NetworkConfigObserverAdapter.class
    at com.google.common.io.ByteStreams.copy(ByteStreams.java:106)
    at com.google.common.io.ByteStreams.toByteArray(ByteStreams.java:166)
    at com.android.build.gradle.shrinker.FullRunShrinker.processJarFile(FullRunShrinker.java:477)
    at com.android.build.gradle.shrinker.FullRunShrinker.buildGraph(FullRunShrinker.java:169)
    at com.android.build.gradle.shrinker.FullRunShrinker.run(FullRunShrinker.java:108)
    at com.android.build.gradle.internal.transforms.BuiltInShrinkerTransform.fullRun(BuiltInShrinkerTransform.java:160)
    at com.android.build.gradle.internal.transforms.BuiltInShrinkerTransform.transform(BuiltInShrinkerTransform.java:130)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 102 more
</code>```

Any ideas why the app doesn't compile with proguard?

答:
The stacktrace points towards guava's ByteStreams.copy, but that's a false lead: the actual cause lies within the JarInputStream. Citing from the documentation:

SecurityException - if any of the jar file entries are incorrectly signed.

So the jar in question is either damaged or was incorrectly signed to begin with. The upstream "californium-core-1.0.5.jar", so it is either locally damaged or was incorrectly modified at some point (possibly by some kind of transformation).

Body:
I'm using the Californium library. I have added the following dependencies to the build.gradle:

implementation 'org.eclipse.californium:californium-core:1.0.5'
implementation 'org.eclipse.californium:scandium:1.0.5'

The app doesn't compile, but I was able to fix this by adding this to the build.gradle as well:

android {
    ...
    packagingOptions {
        exclude 'edl-v10.html'
        exclude 'epl-v10.html'
        exclude 'notice.html'
    }
}

Now the app compiles without errors. However, when I enable proguard / code shrinking like this:

android {
    ...
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            ...
        }
    }
}

Then the debug version of my app doesn't compile anymore! This is the error message:

Error:Execution failed for task ':app:transformClassesWithAndroidGradleClassShrinkerForDevDebug'.
> SHA-256 digest error for org/eclipse/californium/core/network/config/NetworkConfigObserverAdapter.class

I noticed after trying this multiple times, the class above keeps changing to a different one. After adding the following to the proguard rules it still doesn't work:

-keep class org.eclipse.** { *; }
-keep interface org.eclipse.** { *; }
-keep enum org.eclipse.** { *; }
-dontwarn org.eclipse.**

This is the full stacktrace in the gradle console:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithAndroidGradleClassShrinkerForDevDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:60)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:128)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:46)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$ExecuteTasks.run(DefaultGradleLauncher.java:311)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.initialization.DefaultGradleLauncher.runTasks(DefaultGradleLauncher.java:202)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:132)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:107)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:53)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:45)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:29)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:71)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:45)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:51)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:42)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:58)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:33)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.SecurityException: SHA-256 digest error for org/eclipse/californium/core/network/config/NetworkConfigObserverAdapter.class
    at com.google.common.io.ByteStreams.copy(ByteStreams.java:106)
    at com.google.common.io.ByteStreams.toByteArray(ByteStreams.java:166)
    at com.android.build.gradle.shrinker.FullRunShrinker.processJarFile(FullRunShrinker.java:477)
    at com.android.build.gradle.shrinker.FullRunShrinker.buildGraph(FullRunShrinker.java:169)
    at com.android.build.gradle.shrinker.FullRunShrinker.run(FullRunShrinker.java:108)
    at com.android.build.gradle.internal.transforms.BuiltInShrinkerTransform.fullRun(BuiltInShrinkerTransform.java:160)
    at com.android.build.gradle.internal.transforms.BuiltInShrinkerTransform.transform(BuiltInShrinkerTransform.java:130)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 102 more

Any ideas why the app doesn't compile with proguard?


来源: stackexchange

问:
@monthly cron job is not reliable
Our customer wants us to create a report every month.

In the past, we used a @monthly cron job for this task.

But this is not reliable:

The server could be down in this minute. Cron does not re-run those jobs

If the server is up, the database could be unreachable in this moment.

If the server is up and DB is up, there could be a third party system which is not reachable

There could be a software bug.

What can I do, to be sure that the report gets created monthly?

It is a Django based web application

答:
Use a decent scheduler

celery beat is a scheduler; It kicks off tasks at regular intervals, that are then executed by available worker nodes in the cluster.

You create a periodic task with the report function job. If the job fails celery will retry following the retry policy that you have set.

Celery doc - Periodic Tasks

ContentLicense: CC BY-SA 3.0

Title: @monthly cron job is not reliable


问:
Keras: weighted binary crossentropy
I tried to implement a weighted binary crossentropy with Keras, but I am not sure if the code is correct. The training output seems to be a bit confusing. After a few epochs I just get an accuracy of ~0.15. I think thats much too less (even for a random guess).

There are in general about 11% ones in the output and 89% zeros, therefore the weights are w_zero=0.89 and w_one=0.11.

My code:

def create_weighted_binary_crossentropy(zero_weight, one_weight):

    def weighted_binary_crossentropy(y_true, y_pred):

        # Original binary crossentropy (see losses.py):
        # K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1)

        # Calculate the binary crossentropy
        b_ce = K.binary_crossentropy(y_true, y_pred)

        # Apply the weights
        weight_vector = y_true * one_weight + (1. - y_true) * zero_weight
        weighted_b_ce = weight_vector * b_ce

        # Return the mean error
        return K.mean(weighted_b_ce)

    return weighted_binary_crossentropy
```

Maybe someone sees whats wrong?

Thank you

答:
I think using class weight in model.fit is not correct. {0：0.11， 1：0.89}, 0 here is the index, not the 0 class.
Keras Documentation: https://keras.io/models/sequential/
class_weight: Optional dictionary mapping class indices (integers) to a weight (float) value, used for weighting the loss function (during training only). This can be useful to tell the model to "pay more attention" to samples from an under-represented class.</p>

Title: Keras: weighted binary crossentropy

Body:
I tried to implement a weighted binary crossentropy with Keras, but I am not sure if the code is correct. The training output seems to be a bit confusing. After a few epochs I just get an accuracy of ~0.15. I think thats much too less (even for a random guess).

There are in general about 11% ones in the output and 89% zeros, therefore the weights are w_zero=0.89 and w_one=0.11.

My code:

def create_weighted_binary_crossentropy(zero_weight, one_weight):

    def weighted_binary_crossentropy(y_true, y_pred):

        # Original binary crossentropy (see losses.py):
        # K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1)

        # Calculate the binary crossentropy
        b_ce = K.binary_crossentropy(y_true, y_pred)

        # Apply the weights
        weight_vector = y_true * one_weight + (1. - y_true) * zero_weight
        weighted_b_ce = weight_vector * b_ce

        # Return the mean error
        return K.mean(weighted_b_ce)

    return weighted_binary_crossentropy

Maybe someone sees whats wrong?

Thank you


问:
TypeScript - test method against interface, ie T['methodName']
Given interface an interface:

```<code>class A {
   method(x:number) : string
}
</code>```

Given function

```<code>const b = (x: string) : number;
</code>```

The goal - test the function versus the interface

Realisation

```<code>type InterfaceKey = {
    method: any
};

function typecheck<T, K extends keyof InterfaceKey >(imp: () => T, d: T[K]) {
 //                                   K cannot be used to index type T ^
    imp();
    return d;
}

typecheck(someclass, 555); // <-- type check _is actually works_ here

// or

function typecheck <T>(imp: () => T, d: any) {
    imp();
    if(!d) {
        let mock: T;
        mock.default = d; // default does not exists on type T
        return mock;
    }
    return d;
}
</code>```

Look like the first approach is the only way, and it even performs a type check(in Webstorm, not in tsc), but does not compile.

Related: https://github.com/Microsoft/TypeScript/issues/15768

答:
Is this going in the right direction?</p>

```<code>class someclass {
  method(x: number): string { return null!; };
}

const b = (x: number): string => null!;

type InterfaceKey = {
  method: any
};

function typecheck<T extends InterfaceKey>() {
  return <K extends keyof InterfaceKey>(d: T[K]) => {};
}

// should fail if signature of someclass's `method` doesn't match that of `b`
typecheck<someclass>()(b);
</code>```

Body:
Given interface an interface:

class A {
   method(x:number) : string
}

Given function

const b = (x: string) : number;

The goal - test the function versus the interface

Realisation

type InterfaceKey = {
    method: any
};

function typecheck<T, K extends keyof InterfaceKey >(imp: () => T, d: T[K]) {
 //                                   K cannot be used to index type T ^
    imp();
    return d;
}

typecheck(someclass, 555); // <-- type check _is actually works_ here

// or

function typecheck <T>(imp: () => T, d: any) {
    imp();
    if(!d) {
        let mock: T;
        mock.default = d; // default does not exists on type T
        return mock;
    }
    return d;
}

Look like the first approach is the only way, and it even performs a type check(in Webstorm, not in tsc), but does not compile.

Related: https://github.com/Microsoft/TypeScript/issues/15768

Body:
Is this going in the right direction?

class someclass {
  method(x: number): string { return null!; };
}

const b = (x: number): string => null!;

type InterfaceKey = {
  method: any
};

function typecheck<T extends InterfaceKey>() {
  return <K extends keyof InterfaceKey>(d: T[K]) => {};
}

// should fail if signature of someclass's `method` doesn't match that of `b`
typecheck<someclass>()(b);


问:
Python Keras: An layer output exactly the same thing as input
I am using Keras to build a Network. During the process, I need a layer, which takes an LSTM input, doing nothing, just output exactly the same as input. i.e. if each input record of LSTM is like [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]], I am looking for a layer:

```<code>model.add(SomeIdentityLayer(x))
</code>```

SomeIdentityLayer(x) will take [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]] as input and output [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]]. Is such layer/structure available in Keras? Thanks!

答:
For a simpler operation like identity, you can just use a Lambda layer like:

model.add(Lambda(lambda x: x))

This will return an output exactly the same as your input.

Body:
I am using Keras to build a Network. During the process, I need a layer, which takes an LSTM input, doing nothing, just output exactly the same as input. i.e. if each input record of LSTM is like [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]], I am looking for a layer:

model.add(SomeIdentityLayer(x))

SomeIdentityLayer(x) will take [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]] as input and output [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]]. Is such layer/structure available in Keras? Thanks!


问:
Using PGP in golang
I'm trying to encrypt a string using the openPGP package in golang, but so far I haven't been successful.

Nothing that I've tried so far has worked, so I'm looking for any sort of suggestions or fixes.

The only requirements I have is that it should take the public/private key and the string to decrypt as a string, not files.

I tried to use the examples from this post: http://julianyap.com/2014/07/04/gnu-privacy-guard-gpg-examples-using-golang.html

Specifically this example: https://gist.github.com/jyap808/8324818

But when I run that out of the box it saids the following when trying to read the key

```<code>openpgp: invalid argument: no armored data found
</code>```

And I've found no other good example/working package.

I'm starting to run out of options, as I originally tried to do this in PHP, but failed horribly there too. Would be great if anyone could offer some suggestions!

Thanks in advance

答:
Here's a PGP package for Golang that abstracts away most of the complications and is pretty easy to use:

https://github.com/jchavannes/go-pgp

Checkout the test file for an example:

https://github.com/jchavannes/go-pgp/blob/master/pgp/encrypt_test.go

Title: Using PGP in golang

Body:
I'm trying to encrypt a string using the openPGP package in golang, but so far I haven't been successful.

Nothing that I've tried so far has worked, so I'm looking for any sort of suggestions or fixes.

The only requirements I have is that it should take the public/private key and the string to decrypt as a string, not files.

I tried to use the examples from this post: http://julianyap.com/2014/07/04/gnu-privacy-guard-gpg-examples-using-golang.html

Specifically this example: https://gist.github.com/jyap808/8324818

But when I run that out of the box it saids the following when trying to read the key

openpgp: invalid argument: no armored data found

And I've found no other good example/working package.

I'm starting to run out of options, as I originally tried to do this in PHP, but failed horribly there too. Would be great if anyone could offer some suggestions!

Thanks in advance


问:
swift UITapGestureRecognizer not working on view
I had to create a new thread bcoz it's driving me crazy and all the other answers online are exactly the same. I have done this countless of times but I cannot see what I am missing for the life of me. I am using a "test" view controller just to get the tap gesture working but it isn't working at all... I am fairly certain that I am setting this up correctly, as this is how I've always implemented it in the past: (yes, I have checked the box for isUserInteractionEnabled). I am even implementing this on a different viewcontroller this exact way and it is working...

```<code>class TestViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    view.addGestureRecognizer(tap)
  }

  let tap = UITapGestureRecognizer(target: self, action: #selector(wasTapped))

  @objc func wasTapped() {
    print("tapped")
  }
}
</code>```

I have also tried adding the parameters to wasTapped:

```<code>@objc func wasTapped(gestureRecognizer: UITapGestureRecognizer) {
  print("tapped")
}
</code>```

答:
Try something like this</p>

```<code>override func viewDidLoad() {
    super.viewDidLoad()

     let tap = UITapGestureRecognizer(target: self, action: #selector(wasTapped(sender:)))
     tap.numberOfTapsRequired = 1 // Default value
     view.isUserInteractionEnabled = true
     view.addGestureRecognizer(tap)

}

@objc func wasTapped(sender: UITapGestureRecognizer) {
    print("tapped")
}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I had to create a new thread bcoz it's driving me crazy and all the other answers online are exactly the same. I have done this countless of times but I cannot see what I am missing for the life of me. I am using a "test" view controller just to get the tap gesture working but it isn't working at all... I am fairly certain that I am setting this up correctly, as this is how I've always implemented it in the past: (yes, I have checked the box for isUserInteractionEnabled). I am even implementing this on a different viewcontroller this exact way and it is working...

class TestViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    view.addGestureRecognizer(tap)
  }

  let tap = UITapGestureRecognizer(target: self, action: #selector(wasTapped))

  @objc func wasTapped() {
    print("tapped")
  }
}

I have also tried adding the parameters to wasTapped:

@objc func wasTapped(gestureRecognizer: UITapGestureRecognizer) {
  print("tapped")
}

Body:
Try something like this

override func viewDidLoad() {
    super.viewDidLoad()

     let tap = UITapGestureRecognizer(target: self, action: #selector(wasTapped(sender:)))
     tap.numberOfTapsRequired = 1 // Default value
     view.isUserInteractionEnabled = true
     view.addGestureRecognizer(tap)

}

@objc func wasTapped(sender: UITapGestureRecognizer) {
    print("tapped")
}


答:
```<code>style = 'color: yellow; background: red; border: 3px solid green'
funct = lambda d: df_nan.isnull() * style
df_new.style.apply(funct, None)
</code>```

Title: How to color newly added values in a data frame with Pandas?

Body:
I'd like to highlight (or color) new values in a DataFrame that previously were NaNs.

I have 2 data frames with the same index.

One with NaNs

df_nan = pd.DataFrame(np.random.randint(10, size = (10, 10))).replace(8, np.nan)
df_nan

    0       1       2   3   4   5       6   7   8       9
0   NaN     NaN     7   0   0   0.0     0   6   2.0     4.0
1   6.0     3.0     7   1   0   5.0     3   5   NaN     7.0
2   5.0     6.0     0   1   0   NaN     2   4   4.0     7.0
3   NaN     2.0     6   3   1   4.0     9   0   5.0     3.0
4   9.0     0.0     5   2   2   5.0     6   0   9.0     1.0
5   9.0     4.0     0   2   3   9.0     2   9   3.0     4.0
6   4.0     4.0     9   6   7   1.0     7   9   5.0     NaN
7   0.0     NaN     9   2   0   5.0     7   6   3.0     NaN
8   9.0     9.0     0   0   4   6.0     3   3   1.0     7.0
9   3.0     6.0     3   2   7   1.0     6   5   2.0     9.0

Another one (an "updated" one) where NaNs have been replaced by new values (means of each column)

df_new = df_nan.replace(np.nan, np.mean(df_nan))
df_new

    0       1       2  3    4   5       6   7   8       9
0   5.62    4.25    7   0   0   0.0     0   6   2.00    4.00
1   6.00    3.00    7   1   0   5.0     3   5   3.77    7.00
2   5.00    6.00    0   1   0   4.0     2   4   4.00    7.00
3   5.62    2.00    6   3   1   4.0     9   0   5.00    3.00
4   9.00    0.00    5   2   2   5.0     6   0   9.00    1.00
5   9.00    4.00    0   2   3   9.0     2   9   3.00    4.00
6   4.00    4.00    9   6   7   1.0     7   9   5.00    5.25
7   0.00    4.25    9   2   0   5.0     7   6   3.00    5.25
8   9.00    9.00    0   0   4   6.0     3   3   1.00    7.00
9   3.00    6.00    3   2   7   1.0     6   5   2.00    9.00

How can i highlight or color the new values (means) using Pandas .style and .applymap() methods ?

Any help would be much appreciated !


问:
regex remove 3 characters before and after /
looking for a simple regular expression for this,

This is the input:

This is a sample text

```<code>eiwen34EDJ/VUFercsFIR/GRSnrr
</code>```

Output:

```<code>eiwen34 ercs nrr
</code>```

I want to remove 3 characters before and after '/'. i.e. In terms of my example, EDJ/VUF and FIR/GRS should be removed.

I was searched for many questions in here but didn't find the solution for it, please help me.

答:
You can also use the following regex replacement, where you don't need to put it in case insensitive. </p>

```<code>/[a-z]{3}\/[a-z]{3}/gi
</code>```

Body:
looking for a simple regular expression for this,

This is the input:

This is a sample text

eiwen34EDJ/VUFercsFIR/GRSnrr

Output:

eiwen34 ercs nrr

I want to remove 3 characters before and after '/'. i.e. In terms of my example, EDJ/VUF and FIR/GRS should be removed.

I was searched for many questions in here but didn't find the solution for it, please help me.

Body:
You can also use the following regex replacement, where you don't need to put it in case insensitive.

/[a-z]{3}\/[a-z]{3}/gi


问:
Trying to send a push notification when a user adds another user as a friend
I am trying to set up a cloud function to send a notification to the receiving user but when I look at my logs it shows undefined for friendRequest.sender. What is the proper way to access nested json values in firebase cloud functions ?

```<code>exports.sendFriendRequestNotification = functions.database.ref('/friend_request/{pushId}').onWrite(event => {
 var friendRequestMessage = "Sent you a friend request";

 const friendRequest = event.data.current.val();
 console.log(friendRequest);

 const senderUid = event.data.current.child("sender").child("userId").val();
 const receiverUid = event.data.current.child("receiver").child("userId").val();

 console.log(senderUid); //getting null in fb logs

 const promises = [];

 if (senderUid == receiverUid) {
    //if sender is receiver, don't send notification
    promises.push(event.data.current.ref.remove());
    return Promise.all(promises);
 }

 const getInstanceIdPromise = admin.database().ref('/friend_request/{pushId}').once('value');
 const getReceiverUidPromise = admin.auth().getUser(receiverUid);

 return Promise.all([getInstanceIdPromise, getReceiverUidPromise]).then(results => {
     const instanceId = results[0].val();
     const receiver = results[1];
     console.log('notifying ' + receiverUid + ' about ' + friendRequestMessage + ' from ' + senderUid);

     const payload = {
         notification: {
             title: receiver.displayName,
             body: friendRequestMessage,
             icon: receiver.photoURL
            }
    };

    admin.messaging().sendToDevice(instanceId, payload)
        .then(function (response) {
           console.log("Successfully sent message:", response);
        })
        .catch(function (error) {
           console.log("Error sending message:", error);
        });

});
</code>```

});

My Friend Request Object

```<code>           { '-KyYOqdAJAi5tKv3rMIY': { receiver:
  { soundCloudUserId: 0,
    userId: 'RvMaDClGqohUHrYDgKp9u5i03OI3  ',
    userName: 'fakefriend' },
 sender:
  { soundCloudUserId: 0,
    userId: 'VqDgYnDMNVUtByH3uyLDNskPPlj1 ',
    userName: 'doug4less' },
 status: 'Pending' } }
</code>```

Here is how the data looks in my Firebase DB

```<code>friend_request
      -> VqDgYnDMNVUtByH3uyLDNskPPlj1
          -> -KzPS5JjFE51hoqAP6_m
              -> receiver ...
                 sender   ...
                 status: "pending"
</code>```

Here is how I am creating a the friend request

```<code>    public void addFriendRequest() {
    BrainBeatsUser sender = new BrainBeatsUser("VqDgYnDMNVUtByH3uyLDNskPPlj1 ", "doug4less");
    BrainBeatsUser receiver = new BrainBeatsUser("RvMaDClGqohUHrYDgKp9u5i03OI3  ", "fakefriend");

    DatabaseReference friendRequest = mFirebaseDatabase.getReference("friend_request/" + mAddUser.getUserId());
    friendRequest
            .push()
            .setValue(new FriendRequest("Pending", sender, receiver))
            .addOnCompleteListener(task -> {
                if (task.isSuccessful()) {
                    friendUserDialog.dismiss();
                    Constants.buildInfoDialog(SocialActivity.this, "Request Sent", "Your friend request has been sent.");
                    sendFriendNotification();
                } else {
                    Constants.buildInfoDialog(SocialActivity.this, "Error", "There was an issue when sending that request.");
                }
            });
}
</code>```

答:
Try this:

```<code> const senderUid = event.data.current.child("sender").child("userId").val();
 const receiverUid = event.data.current.child("receiver").child("userId").val();
</code>```

event.data.current is a DeltaSnapshot object, you need to use syntax like this to get to its children.

Body:
I am trying to set up a cloud function to send a notification to the receiving user but when I look at my logs it shows undefined for friendRequest.sender. What is the proper way to access nested json values in firebase cloud functions ?

exports.sendFriendRequestNotification = functions.database.ref('/friend_request/{pushId}').onWrite(event => {
 var friendRequestMessage = "Sent you a friend request";

 const friendRequest = event.data.current.val();
 console.log(friendRequest);

 const senderUid = event.data.current.child("sender").child("userId").val();
 const receiverUid = event.data.current.child("receiver").child("userId").val();

 console.log(senderUid); //getting null in fb logs

 const promises = [];

 if (senderUid == receiverUid) {
    //if sender is receiver, don't send notification
    promises.push(event.data.current.ref.remove());
    return Promise.all(promises);
 }

 const getInstanceIdPromise = admin.database().ref('/friend_request/{pushId}').once('value');
 const getReceiverUidPromise = admin.auth().getUser(receiverUid);

 return Promise.all([getInstanceIdPromise, getReceiverUidPromise]).then(results => {
     const instanceId = results[0].val();
     const receiver = results[1];
     console.log('notifying ' + receiverUid + ' about ' + friendRequestMessage + ' from ' + senderUid);

     const payload = {
         notification: {
             title: receiver.displayName,
             body: friendRequestMessage,
             icon: receiver.photoURL
            }
    };

    admin.messaging().sendToDevice(instanceId, payload)
        .then(function (response) {
           console.log("Successfully sent message:", response);
        })
        .catch(function (error) {
           console.log("Error sending message:", error);
        });

});

});

My Friend Request Object

           { '-KyYOqdAJAi5tKv3rMIY': { receiver:
  { soundCloudUserId: 0,
    userId: 'RvMaDClGqohUHrYDgKp9u5i03OI3  ',
    userName: 'fakefriend' },
 sender:
  { soundCloudUserId: 0,
    userId: 'VqDgYnDMNVUtByH3uyLDNskPPlj1 ',
    userName: 'doug4less' },
 status: 'Pending' } }

Here is how the data looks in my Firebase DB

friend_request
      -> VqDgYnDMNVUtByH3uyLDNskPPlj1
          -> -KzPS5JjFE51hoqAP6_m
              -> receiver ...
                 sender   ...
                 status: "pending"

Here is how I am creating a the friend request

    public void addFriendRequest() {
    BrainBeatsUser sender = new BrainBeatsUser("VqDgYnDMNVUtByH3uyLDNskPPlj1 ", "doug4less");
    BrainBeatsUser receiver = new BrainBeatsUser("RvMaDClGqohUHrYDgKp9u5i03OI3  ", "fakefriend");

    DatabaseReference friendRequest = mFirebaseDatabase.getReference("friend_request/" + mAddUser.getUserId());
    friendRequest
            .push()
            .setValue(new FriendRequest("Pending", sender, receiver))
            .addOnCompleteListener(task -> {
                if (task.isSuccessful()) {
                    friendUserDialog.dismiss();
                    Constants.buildInfoDialog(SocialActivity.this, "Request Sent", "Your friend request has been sent.");
                    sendFriendNotification();
                } else {
                    Constants.buildInfoDialog(SocialActivity.this, "Error", "There was an issue when sending that request.");
                }
            });
}

Body:
Try this:

 const senderUid = event.data.current.child("sender").child("userId").val();
 const receiverUid = event.data.current.child("receiver").child("userId").val();

event.data.current is a DeltaSnapshot object, you need to use syntax like this to get to its children.


问:
I am sending GET method to server but receiving POST method
I am sending GET command to the server but in the Apache log I am  getting POST method.

```<code>URL url = new URL("http://192.168.0.111/shakil/shakil.php/?data=shakil,123,123,123");
JSONObject postDataParams = new JSONObject();
postDataParams.put("name", "nazmul");
postDataParams.put("email", "hossainnazmul93@gmail.com");
Log.e("params",postDataParams.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(3000 /* milliseconds */);
conn.setConnectTimeout(3000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
</code>```

Although the method is GET. Can Any one suggest me what is the problem?

答:
Comment this line:</p>

```<code>conn.setDoOutput(true);
</code>```

Body:
I am sending GET command to the server but in the Apache log I am  getting POST method.

URL url = new URL("http://192.168.0.111/shakil/shakil.php/?data=shakil,123,123,123");
JSONObject postDataParams = new JSONObject();
postDataParams.put("name", "nazmul");
postDataParams.put("email", "hossainnazmul93@gmail.com");
Log.e("params",postDataParams.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(3000 /* milliseconds */);
conn.setConnectTimeout(3000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();

Although the method is GET. Can Any one suggest me what is the problem?

Body:
Comment this line:

conn.setDoOutput(true);


问:
python regex sub repeat specific pattern
i have some string data that contains characters from color coding.. i am trying to remove them using re.sub , but i can't figure out how to repeat my pattern. i thought +? would as it states 1 or more repetitions non-greedy. but it is only removing the "[0m" in the string not also the "[32m"

```<code>test = 'test1 test2                       [32mOK[0m'
test = re.sub(r'(.\[[\d*]m)+?', '', test)
</code>```

how do make a regex that will remove any instance of the combination above leaving the text in between which in this instance is "OK" ??

my end goal here is to leave the OK text that is between [32 and [0m... OK could say FAILED or ERROR like this [32mFAILED[0m, [32mERROR[0m

答:
You can try using the following pattern:

```<code>test = re.sub(r'(?:\[\d+m)', '', test)
</code>```

This says to match [ followed by any number of digits, followed by m.  Note that this would leave intact any content after the m.

Demo

Body:
i have some string data that contains characters from color coding.. i am trying to remove them using re.sub , but i can't figure out how to repeat my pattern. i thought +? would as it states 1 or more repetitions non-greedy. but it is only removing the "[0m" in the string not also the "[32m"

test = 'test1 test2                       [32mOK[0m'
test = re.sub(r'(.\[[\d*]m)+?', '', test)

how do make a regex that will remove any instance of the combination above leaving the text in between which in this instance is "OK" ??

my end goal here is to leave the OK text that is between [32 and [0m... OK could say FAILED or ERROR like this [32mFAILED[0m, [32mERROR[0m

Body:
You can try using the following pattern:

test = re.sub(r'(?:\[\d+m)', '', test)

This says to match [ followed by any number of digits, followed by m.  Note that this would leave intact any content after the m.

Demo


答:
If you mean subset your data down to the elements that are less than or equal to 5, with the tidyverse you could do:

library(tidyverse)

foo %>%
    rownames_to_column('store1') %>%    # add rownames as variable
    gather(store2, distance, -store1) %>%    # reshape to long form
    filter(distance <=5,    # drop higher distances and same-store pairs
           distance != 0)
#>      store1    store2  distance
#> 1 Store 101 Store 114 0.9022046
#> 2 Store 200 Store 161 3.7240564
#> 3 Store 199 Store 164 4.0688591
#> 4 Store 208 Store 186 1.2764209
#> 5 Store 208 Store 197 3.8992589
#> 6 Store 208 Store 203 1.5594118
#> 7 Store 208 Store 207 2.6089659
#> 8 Store 200 Store 210 4.0643288
```

<p>or in base R:</p>

<pre class="lang-r prettyprint-override"><code>foo <- as.matrix(foo)    # `which` will coerce anyway, and matrix subsetting is more useful later
indices <- which(foo <= 5 & foo != 0, arr.ind = TRUE)

data.frame(
    store1 = rownames(foo)[indices[, 'row']],
    store2 = colnames(foo)[indices[, 'col']],
    distance = foo[which(foo <= 5 & foo != 0)],
    stringsAsFactors = FALSE
)
#>      store1    store2  distance
#> 1 Store 101 Store 114 0.9022046
#> 2 Store 200 Store 161 3.7240564
#> 3 Store 199 Store 164 4.0688591
#> 4 Store 208 Store 186 1.2764209
#> 5 Store 208 Store 197 3.8992589
#> 6 Store 208 Store 203 1.5594118
#> 7 Store 208 Store 207 2.6089659
#> 8 Store 200 Store 210 4.0643288
</code>```

Title: Cluster A Matrix of Distances

Body:
I have a dataframe of distances between stores, and I would like to produce an object, (list, dataframe, matrix) which shows only those stores which are less than five miles from each other.

foo <- structure(list(`Store 10` = c(97.182714060764, 0, 104.545505520858,120.848327689344, 21.4956940498461, 71.2102784197574, 9.17403190899889,232.086794775442, 43.8173227163331, 116.039010056627),
                      `Store 100` = c(74.2475604028815,23.3746751242071, 81.1712781831004, 144.120931315268, 23.4110542291118,94.4577722550024, 31.5739132041779, 209.492371721166, 66.6219804313243,92.7938789352653),
                      `Store 101` = c(19.0839143178718, 104.545505520858,0, 225.069522157464, 96.7190014732743, 175.476702723702, 112.459326421784,133.381899232519, 147.25396306609, 15.0815963235646),
                      `Store 11` = c(71.2541974994427,26.3632751561921, 78.1889204614728, 147.127665374137, 24.9756132579165,97.4001827503847, 34.5816273110414, 206.517729238781, 69.5004052925104,89.8749246302702),
                      `Store 113` = c(47.0881131319699, 50.6021433483968,54.2297393980493, 171.433305152348, 43.4877656302823, 121.27129019099,58.9080280322994, 182.467788036299, 93.0266775510096, 66.6478219738416),
                      `Store 114` = c(19.3082927142542, 103.863224882231, 0.902204635805178,224.353450878124, 96.1678237911265, 174.82195092457, 111.752223369642,134.253268603651, 146.61996769538, 15.2076513974641),
                      `Store 115` = c(46.1022549798483,139.935108222076, 35.5378432580255, 260.571940423921, 131.050291660978,210.672320747685, 147.943684720518, 100.604144112037, 182.304038294648,28.0600979672013),
                      `Store 116` = c(115.977910525396, 22.2743738090946,124.975555327727, 102.631253530033, 31.2636483056516, 50.7113682121305,18.9828219549928, 249.513008836821, 22.2791136562013, 137.099156498485),
                      `Store 121` = c(46.8649813497236, 138.05949112722, 33.6309330793517,258.355746842495, 130.216167069666, 209.073236612232, 145.841428480987,106.026865528358, 180.880981791045, 23.5225484914477),
                      `Store 122` = c(105.765734973956,9.17403190899889, 112.459326421784, 112.635113034315, 29.7123946609901,64.2530835558693, 0, 240.864256496468, 38.1560918075898, 123.514728759801),
                      `Store 123` = c(40.3098694204528, 133.529478517196, 29.0974945685631,254.144085030474, 124.817814759525, 204.30698545979, 141.519160181814,106.485062095671, 175.963360773997, 22.2402993792639),
                      `Store 124` = c(15.4826131889244,109.72589102537, 10.6559300294596, 230.562026431413, 100.032138241845,180.057734012961, 117.996983784268, 125.132767519462, 151.574939557027,20.7774566354144),
                      `Store 126` = c(80.4918388261617, 20.1645024607666,90.2108352624732, 137.940344444399, 8.19173113521019, 86.1818977331406,29.2603494697063, 214.189063275208, 57.5661773515707, 102.98401126524),
                      `Store 127` = c(50.5707899850002, 47.9998858006402, 56.5458773807153,168.658302706349, 42.7349808287988, 119.013256474241, 56.0276915534435,185.942422263827, 90.979153440465, 68.3777607965505),
                      `Store 128` = c(62.3985613534241,156.467009507205, 51.9662381582155, 277.034745305523, 147.628704344456,227.253259800475, 164.424437950093, 87.7741708055936, 198.897034347146,42.853904907684),
                      `Store 129` = c(44.4280683852888, 53.1076715622684,54.7594044775595, 173.567416520927, 42.09009359735, 122.269218220088,61.9327484138037, 178.979190967292, 93.684829649538, 68.3502152424742),
                      `Store 130` = c(29.6627438540889, 121.877375024469, 17.5379868044159,242.512526852249, 113.273456996737, 192.656341703268, 129.882659850672,116.636306650557, 164.32413853956, 14.5836446177209),
                      `Store 131` = c(42.5311323410154,137.779593313915, 34.1439587366749, 258.570280063638, 128.147397896773,208.229343539775, 145.950719450894, 99.9856701001915, 179.755056696375,29.1673894333183),
                      `Store 132` = c(155.558743492221, 60.771528260534,164.669885634013, 65.0176561457482, 69.959758550586, 11.3767524543355,54.3203426272865, 288.338559299794, 17.5083349593977, 176.63102062546),
                      `Store 133` = c(50.8336976425147, 144.449880156622, 39.9580651232559,265.02740840713, 135.720410143754, 215.24691301159, 152.412539463999,97.5389327984704, 186.904554971329, 31.5227184037659),
                      `Store 135` = c(63.3313266209041,157.175042409662, 52.6467805600477, 277.701522855422, 148.458750384611,228.000622471795, 165.103767022962, 87.8385721010536, 199.664633999748,43.2605181145178),
                      `Store 136` = c(61.8710249192055, 154.122020212753,49.6640907492411, 274.390910797956, 146.117217151602, 225.128094850195,161.895945075365, 93.5747028772301, 196.917181955845, 39.0757329765446),
                      `Store 137` = c(103.313457349294, 17.3461827402428, 113.229054795412,116.112422661667, 17.7120593551046, 63.5719949243665, 20.4028086903726,236.187273346596, 34.8714799448828, 125.874876880014),
                      `Store 139` = c(71.8160418260827,164.107026385352, 59.7067114286829, 284.279664826551, 156.194082461646,235.146144930092, 171.835462193164, 87.4721917453367, 206.95916222963,48.7051425613191),
                      `Store 14` = c(69.9026102953175, 27.6682921924945,76.8975949005597, 148.453900730172, 25.5703428825346, 98.6613132535166,35.9228707805444, 205.163394506493, 70.7179161568892, 88.638643540865),
                      `Store 141` = c(160.447782224841, 65.2717814365252, 169.388864785603,59.9444789236008, 74.9450028320972, 6.30907948029094, 58.5421265869609,293.360566048771, 22.4271238094327, 181.242078615482),
                      `Store 143` = c(94.4967558026401,16.3844028106868, 104.624495877666, 124.844515480636, 8.99230765291032,72.4097871621613, 22.9930146589562, 227.386414291682, 43.7102809488183,117.434599522384),
                      `Store 144` = c(30.6406755152047, 68.6112712822058,44.4695702684719, 188.558533806214, 55.6147674023494, 136.671637702601,77.5500247906599, 163.646263814946, 107.983907652985, 59.1750702503532),
                      `Store 145` = c(116.634237264487, 23.6359859109202, 125.843931060261,102.259873126813, 31.5514229455087, 50.039873981195, 20.6409773826946,249.951334197986, 21.4569059128841, 138.065135950694),
                      `Store 146` = c(49.0568193512663,54.311278216063, 51.5682497967442, 173.872187121451, 51.8366521189428,125.496883714123, 61.5757017052046, 183.451756458655, 97.9724963791237,61.9504010810814),
                      `Store 147` = c(0, 97.182714060764, 19.0839143178718,217.908876952855, 85.9859121607294, 166.67126390107, 105.765734973956,135.391012347645, 138.050987597536, 33.6823000691004),
                      `Store 148` = c(48.2299284841927,53.7142932078625, 51.5598052976402, 173.640099206422, 50.4421662885367,124.924567331259, 61.1836277867489, 182.958179140963, 97.2494257434835,62.3601665165924),
                      `Store 149` = c(49.9477288326237, 52.1431794480886,53.2674613906208, 171.968693905148, 49.3117412727633, 123.350162356965,59.5479342705133, 184.700460684605, 95.7315747878528, 63.9749611826139),
                      `Store 15` = c(82.5768888008737, 15.4683626243912, 89.2381403030532,135.920084787888, 21.9407747294326, 86.6764572064895, 23.3053648689151,217.826144766742, 59.181641916233, 100.588426031137),
                      `Store 150` = c(111.470597382221,14.5119998977806, 118.221849873196, 106.872183476945, 33.6852827380805,58.7080741940326, 5.76337578744118, 246.512942912896, 33.2309002398316,129.247939288897),
                      `Store 151` = c(85.5164627172282, 21.0650021470382,89.719717608509, 136.048733561359, 33.5514294236898, 89.3823249007233,25.3616871032807, 220.808335030956, 63.4667089762883, 99.7490148934809),
                      `Store 152` = c(65.7333609050899, 159.708693014139, 55.1846211658909,280.242160041282, 150.943739032955, 230.523732896797, 167.642654764196,85.7426951335072, 202.180426706117, 45.7642994377334),
                      `Store 153` = c(59.3579242287549,149.610092014953, 45.6143412842972, 269.559143541198, 142.330605461009,220.738288755992, 157.22437780625, 100.319798887199, 192.668333201516,33.8384127325631),
                      `Store 154` = c(14.6177046456285, 105.321597967839,5.80210070409739, 226.091584853407, 96.3550552882973, 175.921089463583,113.468746014001, 130.422441769589, 147.528879548255, 19.1326831571266),
                      `Store 155` = c(98.0521250589665, 14.9615837614282, 107.891590694071,121.044929404276, 12.842867538134, 68.7318498691966, 20.3433651716831,231.147101768248, 40.0455203560419, 120.545097753848),
                      `Store 158` = c(127.28518481773,30.2013867691535, 134.667667307237, 90.6598544948954, 45.3406347212269,42.0113596970615, 22.4099907573838, 261.906676938723, 18.6101002948444,145.890690285015),
                      `Store 159` = c(67.6749186168928, 158.91047585088,54.7277366056853, 278.919460342222, 151.389358118033, 230.013706144037,166.557956365005, 93.0065500154447, 201.902095297973, 43.2119219139315),
                      `Store 160` = c(110.120232119226, 20.8254695717587, 119.897083434758,109.392676953945, 24.4967523202215, 56.7555673594198, 20.9182993439403,242.976497116235, 28.0547337715745, 132.430245082595),
                      `Store 161` = c(138.113572784299,45.0931604978753, 147.748517674391, 82.7382855546652, 52.2879796050827,29.2315784133779, 40.03378203141, 270.539048139633, 3.72405642504832,160.050898616871),
                      `Store 162` = c(39.5318874970135, 58.2426177248329,46.7674666037364, 179.080302234251, 50.3530377561357, 128.818374320699,66.5595692995086, 174.922803603218, 100.509780214086, 59.5159959177498),
                      `Store 163` = c(113.898151873892, 21.8503465903741, 123.256785979153,105.115182928792, 28.6934110323499, 52.7968063588392, 19.914038455521,247.118360982377, 24.1551906075442, 135.568043716944),
                      `Store 164` = c(167.296800589537,72.5538864322338, 176.493531722362, 54.7266951318064, 81.5741222821151,4.06885914637227, 65.9373166073689, 299.806169163016, 29.2845708803529,188.451665473381),
                      `Store 165` = c(100.861353629287, 18.3110449793727,104.973470818329, 121.439421883486, 38.4023517429513, 76.6187217512178,16.1847822790123, 236.179406006191, 52.7160110816438, 114.687045845975),
                      `Store 166` = c(84.2309696787776, 26.0860582793184, 87.4029960514953,139.227141903611, 38.1811729600301, 93.434701169323, 29.8197291133567,219.249743646815, 67.9751869268833, 96.8901622223067),
                      `Store 167` = c(42.6659873965625,54.71184818961, 52.7896560771485, 175.274216597181, 44.0219182175731,124.078866519639, 63.4825184989626, 177.390013796269, 95.5146942756369,66.3595384524349),
                      `Store 168` = c(27.9588076795691, 69.7279066991086,40.3368579277696, 190.19369821024, 58.0608388931474, 138.737127622791,78.5070370487016, 162.366317609087, 110.102409513181, 54.8303582440215),
                      `Store 169` = c(69.3159383038625, 27.9806959835842, 76.7505745526877,148.828132946066, 24.427921667524, 98.7337533354309, 36.4499470061253,204.475568144805, 70.6516437376385, 88.7015577637252),
                      `Store 170` = c(21.5182328406625,81.0766121041097, 23.5040887504589, 201.7123753104, 73.5685355110635,151.972652223415, 89.0780912882125, 154.463389583329, 123.763124828067,36.3513987268101),
                      `Store 171` = c(44.113714476827, 141.170390840861,40.7099024063727, 261.969465961018, 129.923502112083, 210.767960750873,149.643621219947, 92.8741873982887, 182.130236923797, 39.1531976152106),
                      `Store 172` = c(19.7849976772945, 81.7327152729014, 23.0557408490977,202.456573054471, 73.7396811249913, 152.509772689368, 89.8263447104721,153.235986420409, 124.231532446728, 36.3930683039177),
                      `Store 173` = c(18.0896049763375,81.7180794297641, 23.7146422241885, 202.531152805935, 73.0324966127671,152.282200543921, 89.9452137081293, 152.432264250142, 123.912487479355,37.6141760528144),
                      `Store 174` = c(36.8897611134, 134.055684768267,35.3860918685918, 254.798580870764, 122.521779120797, 203.446863653305,142.593386316348, 99.2011320960102, 174.79194894808, 36.3508939538918),
                      `Store 175` = c(19.4055088776882, 116.574724359947, 23.3648681171702,237.25992572555, 104.929272535089, 185.845524690095, 125.170594980623,116.077864702495, 157.189185893232, 31.3550210113149),
                      `Store 176` = c(122.111235017339,31.0308415808054, 131.964915536305, 98.2014379071899, 36.2667125370514,45.0713484742342, 28.1298214696256, 254.596980227275, 16.5153465948402,144.457436271883),
                      `Store 177` = c(174.312564632948, 79.1922090280055,183.340294466275, 47.8073182354175, 88.6625262979693, 8.09591435748952,72.3206532781363, 306.943427288542, 36.2623491601668, 195.185377885561),
                      `Store 178` = c(124.61219657824, 29.2189874552703, 133.185169837572,93.7227786978209, 40.2544721298839, 42.2933454932431, 23.5771031889714,258.394559593159, 14.6785036558556, 145.039824993218),
                      `Store 179` = c(24.061240178573,73.6283030875174, 32.5698473716518, 194.474670260206, 64.2598509447223,143.868493927243, 82.0380354121153, 159.429322108816, 115.415891099251,46.4566844521991),
                      `Store 180` = c(44.9701847904077, 53.5741556808663,56.5028532974761, 173.52782156235, 41.0332449596439, 121.809685121786,62.5506909595459, 178.713172704501, 93.1490182636026, 70.441327010977),
                      `Store 181` = c(111.967567861059, 15.3395480941109, 118.456513677175,106.613028699201, 35.0444361312221, 58.9787865880595, 6.25161265482528,247.099102496894, 34.0064929129624, 129.338722956737),
                      `Store 182` = c(60.3456838723146,157.165746321455, 54.8712719155892, 278.007492402975, 146.264575168245,227.01038283941, 165.54630457556, 78.9129302783064, 198.39647719976,49.9351821713357),
                      `Store 183` = c(13.4908806737511, 106.989824235947,9.21244068502985, 227.822410878512, 97.4026538853887, 177.355731406986,115.251274704921, 127.837556171709, 148.88531616473, 21.2420515177377),
                      `Store 184` = c(111.033225406542, 19.2764979102658, 120.345826022698,107.824773824757, 26.0137323203271, 55.6456779424236, 18.2181155011756,244.358639647822, 27.0332546214697, 132.655884995622),
                      `Store 185` = c(121.308917445053,26.4252993976045, 130.039503153969, 97.124054050421, 36.8181137758406,45.4805165537354, 21.5036756085157, 255.000788916903, 17.4208150256445,141.995038580212),
                      `Store 186` = c(84.839269969394, 21.5242708074613,95.4923419326264, 134.770659233404, 1.2764208987712, 82.2799328459307,29.9352010285124, 217.469820029272, 53.5799208540953, 108.608440764191),
                      `Store 187` = c(70.762830554532, 26.7493232717837, 77.8264470408527,147.549192114017, 24.7936684973839, 97.7236536067102, 35.0395450196894,206.002392522627, 69.7738084636148, 89.5813570895854),
                      `Store 188` = c(73.4914682940968,166.142669957365, 61.6880533608055, 286.372456277449, 158.08397622017,237.153772934312, 173.900880020558, 85.3267010710687, 208.939606223087,50.8679871357349),
                      `Store 189` = c(30.6335264648226, 123.256891318455,18.9764035968927, 243.911262897971, 114.550626876199, 194.008128743653,131.27901530561, 115.178276808933, 165.660950927686, 15.68699143228),
                      `Store 19` = c(23.3642987684607, 78.6445238327238, 25.9240409323312,199.275549425542, 71.2620727787222, 149.554161877786, 86.6413245639711,156.793548788537, 121.358188826921, 38.6120813160024),
                      `Store 190` = c(24.8953566793903,117.245571156207, 13.3340327832417, 237.944432716928, 108.445877146219,187.947611720127, 125.309321393313, 120.152382559651, 159.583855382627,14.6647069749799),
                      `Store 191` = c(155.549777905836, 59.2045930103401,163.721983356225, 62.8685411134829, 70.9404199229136, 12.9854946588728,51.8374805070557, 289.315677754038, 19.3149032304898, 175.194340788389),
                      `Store 192` = c(91.4872714349676, 20.7420409870123, 102.303830906892,128.795763082887, 5.5849073536186, 75.9919896582289, 27.8657918252687,223.671926751966, 47.3273985563995, 115.43062460952),
                      `Store 193` = c(141.719380784307,44.7308064777817, 149.21549633528, 76.1901979874281, 58.6478661940372,28.2986343042698, 36.8888272114097, 276.148618719698, 14.5982071991189,160.401940554441),
                      `Store 194` = c(48.514585801489, 53.9192393293824,51.5507325193362, 173.721059423255, 50.9351331055158, 125.126181046054,61.3161015133771, 183.130645867563, 97.5039715964655, 62.2037250260579),
                      `Store 195` = c(164.817466984655, 68.4273774676872, 172.961113991137,53.7638946100393, 80.0923517591417, 6.92931132757607, 60.9386983862209,298.518399895709, 27.9982779422079, 184.375889358264),
                      `Store 196` = c(57.8791543420262,39.8731109468306, 64.7367364412644, 160.662187066822, 34.7483617119882,110.75845281183, 48.0982056977083, 193.235019566556, 82.6699385366847,76.7036279641455),
                      `Store 197` = c(82.3340701244326, 24.430876802672,93.3620542941436, 137.6952453344, 3.89925888328242, 85.0666101440906,32.9745290918747, 214.623799032827, 56.3779006738775, 106.651209674791),
                      `Store 198` = c(61.7331430932174, 41.6180605526713, 74.0615309657223,158.728662838499, 24.966286291908, 106.183761957946, 50.7830769428203,193.514274891317, 77.4948060082806, 88.0144312091132),
                      `Store 199` = c(166.67126390107,71.2102784197574, 175.476702723702, 53.7367961521279, 81.2330368742957,0, 64.2530835558693, 299.662194368447, 28.7008518753862, 187.234252564455),
                      `Store 2` = c(71.4306146651704, 26.1188858912486, 78.4436621201813,146.904747423482, 24.5812050041696, 97.1253757139686, 34.380881492236,206.676269143349, 69.2034635209456, 90.1621318945159),
                      `Store 200` = c(138.050987597536,43.8173227163331, 147.25396306609, 81.6884783765538, 52.5372484426156,28.7008518753862, 38.1560918075898, 270.994160457313, 0, 159.343872952503),
                      `Store 201` = c(167.299937831438, 71.0085926507406, 175.530197092849,51.5242300593162, 82.435859482383, 5.77433520197501, 63.5665101049999,300.893950302255, 30.1648913107489, 186.980778244732),
                      `Store 202` = c(75.8142152145889,168.978523628256, 64.4657604762506, 289.293568083503, 160.696477104858,239.941616470381, 176.782830387055, 82.1915792024463, 211.68656304804,53.9228716088697),
                      `Store 203` = c(84.4342251533454, 22.3413358736533,95.2178146219974, 135.345773392241, 1.55941180174149, 82.7893845620659,30.7454280782317, 216.929767592851, 54.0927852258926, 108.390557720654),
                      `Store 204` = c(22.1143205044024, 114.156359921168, 10.5669818888741,234.871499237087, 105.333331209187, 184.839958871956, 122.236961768806,122.814937270634, 156.471470077292, 14.94366299403),
                      `Store 205` = c(122.1867570939,35.6035124272749, 133.012362035619, 100.894788979297, 36.3496927542645,47.205327605463, 34.2399762735442, 253.324976689857, 20.2203608687206,145.950349598117),
                      `Store 206` = c(70.1191986671587, 167.111567817173,65.0342316301412, 287.93466221017, 155.89462732924, 236.774146245167,175.536143580105, 68.9290424392404, 208.133198902687, 59.7418624930726),
                      `Store 207` = c(88.5687945825953, 20.1658244721324, 99.2013792438283,131.220345824945, 2.60896587403033, 78.6245234271278, 28.0000435453275,221.084868654116, 49.929251874617, 112.276065981859),
                      `Store 208` = c(85.9859121607294,21.4956940498461, 96.7190014732743, 133.808566486628, 0, 81.2330368742957,29.7123946609901, 218.480538056125, 52.5372484426156, 109.857440510197),
                      `Store 209` = c(121.663640082533, 28.9006139146935, 131.070615054781,97.7229173210449, 36.1960660065879, 45.0888689432883, 25.2658849461922,254.676555811973, 16.3993052713823, 143.353549283483),
                      `Store 21` = c(36.0480404047006,61.9873611681417, 42.9777748186856, 182.813207902126, 54.0670953074946,132.604605615094, 70.2611511460531, 171.413791566702, 104.300827164642,55.7904226028449),
                      `Store 210` = c(141.172490571705, 47.590467181754,150.654610539172, 79.4675863369946, 55.4174448807273, 25.9907325466536,42.1310486296248, 273.73242009186, 4.06432884804506, 162.867201320882),
                      `Store 211` = c(195.549857773211, 99.0907594141363, 203.636015465996,24.5734528986502, 110.560998346534, 29.5859891297109, 91.3903210186264,329.041527102902, 58.0778758968437, 214.904399633133),
                      `Store 212` = c(19.8758322224963,79.5858453380513, 35.6533601753144, 199.72077031221, 66.8023296885385,147.875689075413, 88.4567582084607, 152.550832647225, 119.187833806082,50.6967832261861),
                      `Store 213` = c(208.422391774923, 111.355422226041,215.585707126769, 9.49312702759228, 124.417581698746, 44.7662840289739,103.146190321542, 342.670576447407, 72.4193928009537, 226.294313616523),
                      `Store 214` = c(57.4796622794928, 154.555666730667, 53.3509827699372,275.352996387969, 143.19987077126, 224.106641472437, 163.024900930719,80.036615273364, 195.458347761762, 49.6929091134769)),
                .Names = c("Store 10","Store 100", "Store 101", "Store 11", "Store 113", "Store 114","Store 115", "Store 116", "Store 121", "Store 122", "Store 123","Store 124", "Store 126", "Store 127", "Store 128", "Store 129","Store 130", "Store 131", "Store 132", "Store 133", "Store 135","Store 136", "Store 137", "Store 139", "Store 14", "Store 141","Store 143", "Store 144", "Store 145", "Store 146", "Store 147","Store 148", "Store 149", "Store 15", "Store 150", "Store 151","Store 152", "Store 153", "Store 154", "Store 155", "Store 158","Store 159", "Store 160", "Store 161", "Store 162", "Store 163","Store 164", "Store 165", "Store 166", "Store 167", "Store 168","Store 169", "Store 170", "Store 171", "Store 172", "Store 173","Store 174", "Store 175", "Store 176", "Store 177", "Store 178","Store 179", "Store 180", "Store 181", "Store 182", "Store 183","Store 184", "Store 185", "Store 186", "Store 187", "Store 188","Store 189", "Store 19", "Store 190", "Store 191", "Store 192","Store 193", "Store 194", "Store 195", "Store 196", "Store 197","Store 198", "Store 199", "Store 2", "Store 200", "Store 201","Store 202", "Store 203", "Store 204", "Store 205", "Store 206","Store 207", "Store 208", "Store 209", "Store 21", "Store 210","Store 211", "Store 212", "Store 213", "Store 214"),
                row.names = c("Store 147","Store 10", "Store 101", "Store 434", "Store 208", "Store 199","Store 122", "Store 593", "Store 200", "Store 502"),
                class = "data.frame")
==X==============================================================X==

Body:
If you mean subset your data down to the elements that are less than or equal to 5, with the tidyverse you could do:

library(tidyverse)

foo %>%
    rownames_to_column('store1') %>%    # add rownames as variable
    gather(store2, distance, -store1) %>%    # reshape to long form
    filter(distance <=5,    # drop higher distances and same-store pairs
           distance != 0)
#>      store1    store2  distance
#> 1 Store 101 Store 114 0.9022046
#> 2 Store 200 Store 161 3.7240564
#> 3 Store 199 Store 164 4.0688591
#> 4 Store 208 Store 186 1.2764209
#> 5 Store 208 Store 197 3.8992589
#> 6 Store 208 Store 203 1.5594118
#> 7 Store 208 Store 207 2.6089659
#> 8 Store 200 Store 210 4.0643288

or in base R:

foo <- as.matrix(foo)    # `which` will coerce anyway, and matrix subsetting is more useful later
indices <- which(foo <= 5 & foo != 0, arr.ind = TRUE)

data.frame(
    store1 = rownames(foo)[indices[, 'row']],
    store2 = colnames(foo)[indices[, 'col']],
    distance = foo[which(foo <= 5 & foo != 0)],
    stringsAsFactors = FALSE
)
#>      store1    store2  distance
#> 1 Store 101 Store 114 0.9022046
#> 2 Store 200 Store 161 3.7240564
#> 3 Store 199 Store 164 4.0688591
#> 4 Store 208 Store 186 1.2764209
#> 5 Store 208 Store 197 3.8992589
#> 6 Store 208 Store 203 1.5594118
#> 7 Store 208 Store 207 2.6089659
#> 8 Store 200 Store 210 4.0643288


问:
Issue when updating the password with wp_update_user()
I am creating a plugin that has a frontend profile update portion.

If I have this code...

```<code>$userdata = array(
    'user_login'    =>   $username,
    'user_email'    =>   $email,
    'user_url'      =>   $website,
    'first_name'    =>   $first_name,
    'last_name'     =>   $last_name,
    'nickname'      =>   $nickname,
    'description'   =>   $bio,
);

global $current_user; get_currentuserinfo();
$ID=$current_user->ID;
$ID_array = array('ID' => $ID);
$userdata = $ID_array + $userdata;

$user = wp_update_user( $userdata );
</code>```

...all is good; however, if I also update the password by adding 'user_pass' => $password thus changing the code to...

```<code>$userdata = array(
    'user_login'    =>   $username,
    'user_email'    =>   $email,
    'user_pass'     =>   $password,
    'user_url'      =>   $website,
    'first_name'    =>   $first_name,
    'last_name'     =>   $last_name,
    'nickname'      =>   $nickname,
    'description'   =>   $bio,
);

global $current_user; get_currentuserinfo();
$ID=$current_user->ID;
$ID_array = array('ID' => $ID);
$userdata = $ID_array + $userdata;

$user = wp_update_user( $userdata );
</code>```

... I get the following error on the frontend...

Warning: Cannot modify header information - headers already sent by (output started at /home/sdglandl/public_html/home/wp-content/themes/converio/header.php:2) in /home/sdglandl/public_html/home/wp-includes/pluggable.php on line 942

The same error occurs over and over and over for multiple lines

答:
When you update the current user's password the current user's cookies are cleared.  This is similar to an issue already discussed.  You'll need to run this code before any HTML is rendered to prevent the headers being already set issue.</p>

```<code>add_action( 'wp', 'set_current_users_password' );

function set_current_users_password() {
    // Get current logged-in user.
    $user = wp_get_current_user();

    // Change password.
    wp_set_password($new_password, wp_get_current_user()->ID);

    // Log-in again.
    wp_set_auth_cookie($user->ID);
    wp_set_current_user($user->ID);
    do_action('wp_login', $user->user_login, $user);
}
</code>```

Body:
I am creating a plugin that has a frontend profile update portion.

If I have this code...

$userdata = array(
    'user_login'    =>   $username,
    'user_email'    =>   $email,
    'user_url'      =>   $website,
    'first_name'    =>   $first_name,
    'last_name'     =>   $last_name,
    'nickname'      =>   $nickname,
    'description'   =>   $bio,
);

global $current_user; get_currentuserinfo();
$ID=$current_user->ID;
$ID_array = array('ID' => $ID);
$userdata = $ID_array + $userdata;

$user = wp_update_user( $userdata );

...all is good; however, if I also update the password by adding 'user_pass' => $password thus changing the code to...

$userdata = array(
    'user_login'    =>   $username,
    'user_email'    =>   $email,
    'user_pass'     =>   $password,
    'user_url'      =>   $website,
    'first_name'    =>   $first_name,
    'last_name'     =>   $last_name,
    'nickname'      =>   $nickname,
    'description'   =>   $bio,
);

global $current_user; get_currentuserinfo();
$ID=$current_user->ID;
$ID_array = array('ID' => $ID);
$userdata = $ID_array + $userdata;

$user = wp_update_user( $userdata );

... I get the following error on the frontend...

Warning: Cannot modify header information - headers already sent by (output started at /home/sdglandl/public_html/home/wp-content/themes/converio/header.php:2) in /home/sdglandl/public_html/home/wp-includes/pluggable.php on line 942

The same error occurs over and over and over for multiple lines

Body:
When you update the current user's password the current user's cookies are cleared.  This is similar to an issue already discussed.  You'll need to run this code before any HTML is rendered to prevent the headers being already set issue.

add_action( 'wp', 'set_current_users_password' );

function set_current_users_password() {
    // Get current logged-in user.
    $user = wp_get_current_user();

    // Change password.
    wp_set_password($new_password, wp_get_current_user()->ID);

    // Log-in again.
    wp_set_auth_cookie($user->ID);
    wp_set_current_user($user->ID);
    do_action('wp_login', $user->user_login, $user);
}