小编VK3*_*321的帖子

Nodejs在pub/sub中从客户端发布

我正在尝试在nodejs中构建一个小应用程序来发布和订阅.我被困在如何从客户端发布.这是我的代码.

这是我的服务器代码(server.js)

var express = require('express'),
app = express(),
http = require('http'),
server = http.createServer(app);
app.use(express.bodyParser());

app.get('/', function(req, res) {
  res.sendfile(__dirname + '/public/index.html');  
});

app.post('/publish/:channel/:event/', function(req, res) {
  console.log("**************************************");
  var params = req.params;
  console.log(req.params);
  console.log(req.body);
  var data = req.body;
  console.log("**************************************");
  var result = io.sockets.emit(params.channel,{event:params.event,data:data});
  //console.log(result);
  console.log("**************************************"); 
  res.sendfile(__dirname + '/public/index.html');  
});

//include static files
app.use(express.static(__dirname + '/public'));

server = server.listen(3000);
var io = require('socket.io').listen(server);

io.sockets.on('connection', function (s) {
  socket = s
  socket.emit('c1', { hello: 'world' });

  socket.on('test', function (data) {
    socket.emit('c1', …
Run Code Online (Sandbox Code Playgroud)

javascript redis node.js socket.io

7
推荐指数
1
解决办法
585
查看次数

Spring百里叶的页眉和页脚动态包括

我最近在春天开始使用百里香模板引擎.我想要实现的是 - 如果我的控制器就是这个

@RequestMapping(value="/", method=RequestMethod.GET)
public String index() {
    return "homePage";
}
Run Code Online (Sandbox Code Playgroud)

然后我想在homePage.html中编写HTML代码而没有像head,title,body等完整的HTML定义.

<div>This is home page content</div>
Run Code Online (Sandbox Code Playgroud)

不想在homePage.html这样写.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<head>
    <title>Spring MVC Example</title>
</head>
<body>
    <div th:include="fragments/header::head"></div>
    <div>This is home page content</div>
    <div th:include="fragments/footer::foot"></div>
</body>
Run Code Online (Sandbox Code Playgroud)

我更倾向于将头部分作为标题片段,来自控制器和页脚的内容来自页脚片段.

所以总的来说 - 我怎么能做到这一点:

/fragment/header.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<head>
    <title>Spring MVC Example</title>
</head>
<body>
Run Code Online (Sandbox Code Playgroud)

/home.html

<div>This is home page content</div>
Run Code Online (Sandbox Code Playgroud)

(这个投掷错误)

/fragment/footer.html

  </body>
 </html>
Run Code Online (Sandbox Code Playgroud)

注意:我已经看过这些例子了

java spring thymeleaf

7
推荐指数
2
解决办法
3万
查看次数

Swift 3动态添加删除子视图及其内容

我正在编写我的第一个Swift应用程序进行测验.每个问题都有随机的方式在屏幕上呈现如下截图.

在此输入图像描述

我是没有故事板的编程应用程序即.编程.我想在单个viewcontroller中为每个问题创建简单的分页流,而不使用Collocationview,Tableview或navigation.

到目前为止我做了什么?我有简单的viewcontroller与UIView()添加为子视图.我正在动态添加问题组件.现在,一旦用户点击继续,我想删除子视图并添加新的子视图和新问题.我能够删除子视图但子视图上的内容似乎仍然存在,因为我可以看到它被覆盖.

要获得更多说明,请查看我的代码.

import UIKit

class QuizController: UIViewController {

let subView = UIView()
var currentQuestion:Int = 1;


let questions = ["This is question 1", "Hello to question 2", "Question 3"]

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = .white
    setup_layout()
}

func setup_layout(){

    let closeBtn = UIButton(frame: CGRect(x: 5, y: 10, width: 200, height: 50))
    closeBtn.backgroundColor = UIColor.red
    closeBtn.setTitle("Close", for: .normal)
    closeBtn.addTarget(self, action: #selector(close), for: .touchUpInside)
    view.addSubview(closeBtn)
    //dynamic view
    create_subview()
}

func nextQuestion(){
    print("Show next")
    if let viewWithTag = self.view.viewWithTag(currentQuestion) …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview uiview ios swift

3
推荐指数
1
解决办法
7355
查看次数

react native [[DEFAULT]] firebaseapp 未初始化 react-native-firebase

我正在尝试将 react-native-firebase 模块与 react native 一起使用。

我得到的错误:

在此处输入图片说明

我遵循的步骤:

Step1:创建基本应用

react-native init myFirebaseApp
Run Code Online (Sandbox Code Playgroud)

转移到项目

cd myFirebaseApp
Run Code Online (Sandbox Code Playgroud)

安装模块

npm install --save react-native-firebase
Run Code Online (Sandbox Code Playgroud)

第 2 步:设置 Firebase SDK ( https://rnfirebase.io/docs/v4.2.x/installation/ios )

创建了 firebase 应用程序并下载了适用于 iOS 的 GoogleService-Info.plist

复制的

GoogleService-Info.plist

在项目中,然后

pod init
Run Code Online (Sandbox Code Playgroud)

将这些行添加到 pod 文件

  pod 'Firebase/Core'
  pod 'Firebase/Firestore'
Run Code Online (Sandbox Code Playgroud)

已安装的依赖项

pod install
Run Code Online (Sandbox Code Playgroud)

最后链接库

react-native link
Run Code Online (Sandbox Code Playgroud)

有人可以指导我我错过了什么或做错了什么?

ios firebase reactjs react-native react-redux

2
推荐指数
1
解决办法
4728
查看次数

Java SparkSql 2.4.0 ArrayIndexOutOfBoundsException错误

我是Spark的新手,正尝试使用Java Maven项目读取CSV文件,但遇到ArrayIndexOutOfBoundsException错误。

依存关系:

  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.12</artifactId>
        <version>2.4.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-sql_2.12</artifactId>
        <version>2.4.0</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

码:

SparkSession spark = SparkSession
            .builder()
            .appName("Java Spark SQL Example")
            .config("spark.master", "local")
            .getOrCreate();

    //Read file
    Dataset<Row> df = spark.read()
            .format("csv")
            .load("test.csv");
Run Code Online (Sandbox Code Playgroud)

CSV文件

name,code
A,1
B,3
C,5
Run Code Online (Sandbox Code Playgroud)

这是stacktrace

    Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
    18/11/12 11:16:25 INFO SparkContext: Running Spark version 2.4.0
    18/11/12 11:16:25 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    18/11/12 …
Run Code Online (Sandbox Code Playgroud)

java hive apache-spark apache-spark-sql

2
推荐指数
1
解决办法
927
查看次数