调用IPython.embed()时可以给它一个命令或魔法函数在嵌入发生后运行。
我想运行这样的东西
import IPython
IPython.embed(command='%pylab qt4')
Run Code Online (Sandbox Code Playgroud)
我目前的解决方法是将命令字符串复制到剪贴板,生成一个后台线程,该线程发送击键 %paste 然后输入到当前窗口。这在 linux 上工作正常,但它非常笨拙,我无法让它在 Windows 上也能正常工作。似乎应该可以指定这一点,但我从未掌握 IPython 配置的工作方式或要嵌入的参数的用途。
我的应用程序中有这部分代码
addComment (body: Object): Observable<Comment[]> {
//let bodyString = JSON.stringify(body); // Stringify payload
let bodyString = JSON.parse(JSON.stringify(body || null ))
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http.post(this.commentsUrl, bodyString, options) // ...using post request
.map((res:Response) => res.json()) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error.json().error || 'Server error')); //...errors if any
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在我的应用程序中添加评论时,它会引发如下错误: …
我正在使用 Spring Boot OAuth2Facebook 登录,但遇到错误:
JSON 解析错误:无法从 START_OBJECT 令牌反序列化 java.lang.String 的实例
相同的代码适用于 Google,登录按预期工作。我正在 Github 上关注此代码(https://github.com/callicoder/spring-boot-react-oauth2-social-login-demo)。
你能指导我解决这个问题吗?
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.csrf()
.disable()
.formLogin()
.disable()
.httpBasic()
.disable()
.exceptionHandling()
.authenticationEntryPoint(new RestAuthenticationEntryPoint())
.and()
.authorizeRequests()
.antMatchers("/","/public/**",
"/login",
"/register",
"/error",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/fonts/*.*",
"/webfonts/*.*",
"/**/*.css",
"/**/*.js")
.permitAll()
.antMatchers("/auth/**", "/oauth2/**")
.permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2Login()
.authorizationEndpoint()
.baseUri("/oauth2/authorize")
.authorizationRequestRepository
(cookieAuthorizationRequestRepository())
.and()
.redirectionEndpoint()
.baseUri("/oauth2/callback/*")
.and()
.userInfoEndpoint()
.userService(customOAuth2UserService)
.and() …Run Code Online (Sandbox Code Playgroud) 动态规划变化问题(有限硬币)。我正在尝试创建一个作为INPUT的程序:
int coinValues[]; //e.g [coin1,coin2,coin3]
int coinLimit[]; //e.g [2 coin1 available,1 coin2 available,...]
int amount; //the amount we want change for.
Run Code Online (Sandbox Code Playgroud)
输出:
int DynProg[]; //of size amount+1.
Run Code Online (Sandbox Code Playgroud)
并且输出应该是一个大小为amount+1的数组,其中每个单元格代表我们需要为单元格索引的数量提供更改的最佳硬币数量。
示例:假设我们在索引:5 处有 Array 的单元格,内容为 2。这意味着,为了改变 5(INDEX)的数量,您需要 2(单元格的内容)硬币(最佳解决方案) .
基本上我需要这个视频的第一个数组(C[p]) 的输出。这是完全相同的问题与大差异的有限公司硬币。 链接到视频。
注意:看视频理解,忽略视频的第二个数组,记住我不需要组合,而是DP数组,这样我就可以找到哪些硬币作为找零。
谢谢你。
我正在使用Spark 2.2,我正在尝试从Kafka读取JSON消息,将它们转换为DataFrame并将它们作为Row:
spark
.readStream()
.format("kafka")
.option("kafka.bootstrap.servers", "localhost:9092")
.option("subscribe", "topic")
.load()
.select(col("value").cast(StringType).as("col"))
.writeStream()
.format("console")
.start();
Run Code Online (Sandbox Code Playgroud)
有了这个,我可以实现:
+--------------------+
| col|
+--------------------+
|{"myField":"somet...|
+--------------------+
Run Code Online (Sandbox Code Playgroud)
我想要更像这样的东西:
+--------------------+
| myField|
+--------------------+
|"something" |
+--------------------+
Run Code Online (Sandbox Code Playgroud)
我尝试使用from_json函数struct:
DataTypes.createStructType(
new StructField[] {
DataTypes.createStructField("myField", DataTypes.StringType)
}
)
Run Code Online (Sandbox Code Playgroud)
但我只得到:
+--------------------+
| jsontostructs(col)|
+--------------------+
|[something] |
+--------------------+
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用,explode但我只有Exception说:
cannot resolve 'explode(`col`)' due to data type mismatch:
input to function explode should be array or map type, not
StructType(StructField(...
Run Code Online (Sandbox Code Playgroud)
知道如何使这项工作?
java apache-spark apache-spark-sql apache-spark-2.0 spark-structured-streaming
我的数据:
Q5 Q6 Q7
1 Not Agree Neutral Not Agree
2 Not Agree Neutral Neutral
3 Not Agree Agree Agree
4 Not Agree Agree Neutral
5 Neutral Not Agree Neutral
6 Not Agree Agree Neutral
7 Not Agree Neutral Neutral
8 Neutral Agree Neutral
9 Agree Neutral Not Agree
10 Neutral Agree Neutral
Run Code Online (Sandbox Code Playgroud)
Q567[1:3] <- lapply(Q567[1:3], factor, levels= c("Agree", "Neutral", "Not Agree"), ordered = TRUE)
likert(Q567) %>%
plot(type = "bar")
Run Code Online (Sandbox Code Playgroud)
我将它们转换为带有级别的因子,为什么我仍然收到错误
Error in likert(Q567) : All items (columns) must …Run Code Online (Sandbox Code Playgroud) 我正在使用 KorGE 库开始一个项目,我想使用 Retrofit 作为 XML 解析器。所以我尝试遵循这个指南,这看起来不错,但我只是在第一步中添加依赖项而陷入困境。
我已经包含了 KorGE 库(我从模板开始):
dependencies {
classpath("com.soywiz.korlibs.korge.plugins:korge-gradle-plugin:$korgePluginVersion")
classpath("com.soywiz.korlibs.klock:klock:1.6.1")
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试包含以下依赖项时,当我加载 gradle 更改时,一切都会变得糟糕(我想这是我应该声明它们的方式?):
classpath("com.squareup.retrofit:retrofit:2.4.0")
classpath("com.squareup.retrofit:converter-simplexml:2.4.0")
Run Code Online (Sandbox Code Playgroud)
在指南中,这个依赖项似乎是 API 的一部分,但我没有发现网上的声明有什么不同。如果我只是复制过去,它显然不起作用。
加载 gradle 更改后我得到的错误:
java.lang.IllegalArgumentException: org.gradle.api.internal.initialization.DefaultClassLoaderScope@a2e5ac5 must be locked before it can be used to compute a classpath!
java.lang.IllegalArgumentException: project.classLoaderScope must be locked before querying the project schema
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助,并为我的noobiness 感到抱歉。
拥有Dataset<Row>单列json字符串:
+--------------------+
| value|
+--------------------+
|{"Context":"00AA0...|
+--------------------+
Run Code Online (Sandbox Code Playgroud)
Json样本:
{"Context":"00AA00AA","MessageType":"1010","Module":"1200"}
Run Code Online (Sandbox Code Playgroud)
我怎样才能最有效地获得Dataset<Row>如下所示:
+--------+-----------+------+
| Context|MessageType|Module|
+--------+-----------+------+
|00AA00AA| 1010| 1200|
+--------+-----------+------+
Run Code Online (Sandbox Code Playgroud)
我正在流处理这些数据,我知道当我从文件中读取时,spark可以通过他自己做到这一点:
spark
.readStream()
.schema(MyPojo.getSchema())
.json("src/myinput")
Run Code Online (Sandbox Code Playgroud)
但现在我正在读取kafka的数据,它以另一种形式提供数据.我知道我可以使用像Gson这样的解析器,但我想让火花为我做.
我想转换Row的DataFrame成只使用火花API JSON字符串。
从输入 Row
+----------------+-----------+
| someThing| else|
+----------------+-----------+
| life| 42|
+----------------+-----------+
Run Code Online (Sandbox Code Playgroud)
和
myDataFrame
.select(struct("*").as("col"))
.select(to_json(col("col")))
.writeStream()
.foreach(new KafkaWriter())
.start()
Run Code Online (Sandbox Code Playgroud)
using KafkaWriter,即使用row.toString()我得到:
[{
"someThing":"life",
"else":42
}]
Run Code Online (Sandbox Code Playgroud)
当我想得到这个时:
{
"someThing":"life",
"else":42
}
Run Code Online (Sandbox Code Playgroud)
(没有[])
任何的想法?
package.json文件(依赖项、脚本){
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-router-dom": "^5.1.7",
"firebase": "^8.2.7",
"form-group": "^3.0.8",
"react": "^15.3.0",
"react-dom": "^17.0.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.2",
"react-tinder-card": "^1.3.1",
"reactstrap": "^8.8.1",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}
Run Code Online (Sandbox Code Playgroud) java ×4
apache-spark ×3
json ×3
typescript ×2
algorithm ×1
angular ×1
coin-change ×1
dependencies ×1
firebase ×1
http ×1
ipython ×1
korge ×1
kotlin ×1
likert ×1
observable ×1
python ×1
r ×1
reactjs ×1
scala ×1
spring-boot ×1
xml ×1