我正在使用React的componentDidUpdate
生命周期方法.
我试图确定两个数组是否相同.
我的prevState
数组看起来像这样:
prevState.players = [
{
name: 'Wayne Rooney',
age: 31
},
{
name: 'Lionel Messi',
age: 29
},
{
name: 'Robbie Fowler',
age: 42
}
];
Run Code Online (Sandbox Code Playgroud)
并且this.state
数组看起来像这样:
this.state.players = [
{
name: 'Wayne Rooney',
age: 31
},
{
name: 'Lionel Messi',
age: 29
},
{
name: 'Robbie Fowler',
age: 42
}
];
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,如果您展开下面的代码段,它们就不相同:
let playersOne = [{
name: 'Wayne Rooney',
age: 31
},
{
name: 'Lionel Messi',
age: 29
},
{
name: …
Run Code Online (Sandbox Code Playgroud)就像数据帧中的列和X1 $ value + X2 $值一样,我想在尽可能少的R代码的列表列表上执行它,而不是使用for-loop.谢谢.
输入:
n1 <- c(1,2,3)
n2 <- c(2,3,4)
df1 <- data.frame(n1,n2)
n1 <- c(3,2,1)
n2 <- c(5,5,6)
df2 <- data.frame(n1,n2)
mylist <- list(df1, df2)
n0 <- c(0,0,0) #init compute
compute <- data.frame(n0)
for(i in 1:length(mylist)){
compute[,1] <- mylist[[i]]$n1 + compute[,1]
}
Run Code Online (Sandbox Code Playgroud)
期望的输出:
>compute
n0
1 4
2 4
3 4
Run Code Online (Sandbox Code Playgroud) 以下代码
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import matplotlib.pyplot as plt
import numpy as np
class View(QGraphicsView):
def __init__(self):
super(View, self).__init__()
self.initScene(5)
def initScene(self,h):
self.scene = QGraphicsScene()
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.figure.subplots_adjust(left=0.03,right=1,bottom=.1,top=1,wspace=0, hspace=0)
ax = self.figure.add_subplot(111)
ax.set_xlim([0,1000])
data = np.random.rand(1000)
ax.plot(data, '-')
arr_img = plt.imread('sampleimage.jpg',format='jpg')
im = OffsetImage(arr_img,zoom=.9)
ab = AnnotationBbox(im, (.5, .5), xycoords='axes fraction') …
Run Code Online (Sandbox Code Playgroud) 我有通过以太网连接的Android PC 设备、手持设备。现在我能够获取设备的 IP 地址和 MAC 地址,但我还需要获取子网掩码、网关、pri-sec DNS 值。请任何人告诉我如何以编程方式找到这些值。
查找IP地址和MAC地址的代码是-
connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
networkInfo = connectivityManager.getActiveNetworkInfo();
networkType = networkInfo != null ? networkInfo.getTypeName() : "";
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ipAddress = inetAddress.getHostAddress().toString();
System.out.println("ipaddress=" + ipAddress + " formatter ip" + Formatter.formatIpAddress(inetAddress.hashCode()));
}
}
}
} catch (SocketException ex) {
} …
Run Code Online (Sandbox Code Playgroud) 我在 Angular-CLI 和 .NET Core 2.0 中使用 Angular 5.2.2(打字稿)。
我正在尝试向我的应用程序动态添加其他路由。
这个想法是我从服务器动态获取我的路由,该服务器检查哪些模块应该可供用户使用。但我似乎无法获得可用的路线。
我尝试使用添加它们,RouterModule.forRoot
但这不起作用。
我试过使用,Router.resetConfig
但我似乎无法让它工作。我尝试使用依赖注入在我创建的函数中获取它,但我最终得到了循环依赖:
Uncaught Error: Provider parse errors:
Cannot instantiate cyclic dependency! ApplicationRef ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
Run Code Online (Sandbox Code Playgroud)
这是我拥有的一些代码:
app-routing.module.ts
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { Routes, RouterModule, Router } from '@angular/router';
var routes: Routes = [{ path: '', loadChildren: "../app/modules/f2p-dashboard/f2p-dashboard.module#F2PDashboardModule" }];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: [
{
provide: APP_INITIALIZER,
useFactory: AppConfigServiceFactory,
deps: [F2PModuleService, Router ],
multi: true
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在perl中创建一个接受多个CLI args的CLI脚本.我正在使用该GetOptions
函数解析这些参数.我有两个选项--foo
,--bar
其中一个必须与传递给它的相应值一起出现.
有没有办法直接在GetOptions中处理这个?或者我是否必须手动为此检查?
我正在使用该Getopt::Long
模块.
编辑:当我说:
我有两个选项
--foo
,--bar
其中一个必须与传递给它的相应值一起出现.
我的意思是说这些应该是CLI参数,可以用作:
$ perl my-cli-script.pl --foo somevalue
$ #Or
$ perl my-cli-script.pl --bar someothervalue
Run Code Online (Sandbox Code Playgroud)
但不是
$ perl my-cli-script.pl --foo somevalue --bar someothervalue
$ #or
$ perl my-cli-script.pl
Run Code Online (Sandbox Code Playgroud) 我正在使用 React Native 设置一个新项目,如本教程:https : //facebook.github.io/react-native/docs/getting-started.html并构建 iOS 版本但它不起作用,空白屏幕LaunchScreen 运行后显示。
如果在Debug (react-native run-ios) 中构建,该应用程序可以工作,但在Release 中不起作用(由 Xcode 或终端构建发布)。
反应原生 v0.53.0
react-native-cli v2.0.1
节点 v8.10.0
Xcode 9.2
Xcode 中的日志显示:
2018-02-06 15:55:14.464233+0700 MyApp[306:35863] [辅助功能] ****************** 加载 GAX 客户端包 ******* ********* 2561-02-06 15:55:14.697 [error][tid:main][RCTCxxBridge.mm:423] 加载包失败(file:///var/containers/Bundle/应用程序/4FAF82CD-9EA4-4E73-800A-A2ABC9313405/MyApp.app/main.jsbundle)出现错误:(错误读取包/var/containers/Bundle/Application/4FAF82CD-9EA4-4E73-800A-A2ABC93134405/ main.jsbundle (null)) 2018-02-06 15:55:14.706782+0700 Shiip[306:35863] 加载包失败(file:///var/containers/Bundle/Application/4FAF82CD-9EA4-4E73-800A -A2ABC9313405/MyApp.app/main.jsbundle) 有错误:(错误读取包 /var/containers/Bundle/Application/4FAF82CD-9EA4-4E73-800A-A2ABC9313405/MyApp.app/main.jsbundle (null))
clang-format目前将所有pragma移动到第一列.clang格式之前的一个例子:
for (int i = 0; i < 4; ++i) {
#pragma UNROLL
// ...some code...
}
Run Code Online (Sandbox Code Playgroud)
clang格式后的相同代码:
for (int i = 0; i < 4; ++i) {
#pragma UNROLL
// ...some code...
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让clang-format完全忽略pragma行而不改变源代码(即不会混淆源代码// clang-format off
)?例如使用正则表达式?
这与此问题有关(我希望避免安装第三方工具),并希望通过此错误报告解决.
另外,虽然clang-format off
对于带有pragma的行是受到尊重的,但是注释行本身将缩进到pragma 将缩进到的内容(使用clang-format 6.0.0):
for (int i = 0; i < 4; ++i) {
// clang-format off
#pragma UNROLL
// clang-format on
// ...some code...
}
Run Code Online (Sandbox Code Playgroud) 在我的 Spark (2.2) DataFrame 中,每一行都是 JSON:
df.head()
//output
//[{"key":"111","event_name":"page-visited","timestamp":1517814315}]
df.show()
//output
//+--------------+
//| value|
//+--------------+
//|{"key":"111...|
//|{"key":"222...|
Run Code Online (Sandbox Code Playgroud)
我想将每个 JSON 行传递给列以获得这个result
:
key event_name timestamp
111 page-visited 1517814315
...
Run Code Online (Sandbox Code Playgroud)
我试过这种方法,但它没有给我预期的结果:
import org.apache.spark.sql.functions.from_json
import org.apache.spark.sql.types._
val schema = StructType(Seq(
StructField("key", StringType, true), StructField("event_name", StringType, true), StructField("timestamp", IntegerType, true)
))
val result = df.withColumn("value", from_json($"value", schema))
Run Code Online (Sandbox Code Playgroud)
和:
result.printSchema()
root
|-- value: struct (nullable = true)
| |-- key: string (nullable = true)
| |-- event_name: string (nullable = true)
| |-- timestamp: …
Run Code Online (Sandbox Code Playgroud) 我收到错误:'在角度web-app的编译时,在组件'中找不到名字'$'.当我使用const $ : any = '';
然后解决了错误但在浏览器控制台中得到另一个错误:'core.js:1440 ERROR TypeError:$不是函数'并且数据表在使用时也不起作用const $ : any = '';
.
下面是我的用户组件代码.此组件用于数据表的用户列表.
users.component.ts
import {DataService} from './../services/data.service';
import {Component, OnInit} from '@angular/core';
import {API_ENDPOINT} from '../app.module';
import {Response} from '@angular/http/src/static_response';
const $: any = '';
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.css']
})
export class UsersComponent implements OnInit {
private url = API_ENDPOINT + '/admin_api/users';
private users: any;
constructor(private dataService: DataService) {
}
ngOnInit() {
this.dataService.get(this.url)
.subscribe(responce => {
this.users = responce.data.users;
if (this.users) …
Run Code Online (Sandbox Code Playgroud) angular ×2
android ×1
angular5 ×1
apache-spark ×1
c++ ×1
clang-format ×1
dns ×1
ecmascript-6 ×1
ethernet ×1
gateway ×1
image ×1
ios ×1
javascript ×1
json ×1
matplotlib ×1
perl ×1
plot ×1
python ×1
r ×1
react-native ×1
reactjs ×1
resolution ×1
scala ×1
subnet ×1
typescript ×1
xcode9.2 ×1