所以我正在学习Scala,我遇到了这个挑剔的问题......
如果我们有一个String并希望将其转换成一个Int,我在网上找到的所有例子都说:"这很简单!只需使用String.toInt!"
好的:
var x = readLine().toInt
Run Code Online (Sandbox Code Playgroud)
很简单.我假设toInt是一个功能String.但如果是这样的话,我应该可以toInt用括号打电话,对吧?来自Java,这对我来说更自然:
var x = readLine().toInt()
Run Code Online (Sandbox Code Playgroud)
可惜!Scala给了我以下错误:
[错误] /home/myhome/code/whatever/hello.scala:13:Int不带参数
[error] var x = readLine().toInt()
好奇.这个错误是什么意思?是toInt不是一个功能String?同样,为什么我可以两个都做:
var x = readLine().toLowerCase()
var y = readLine().toLowerCase
Run Code Online (Sandbox Code Playgroud)
没有任何问题?
编辑:重复的问题不解决toLowerCasevs toInt问题.
在Golang中,我们可以使用内置make()函数创建具有给定初始长度和容量的切片.
考虑以下几行,切片的长度设置为1,其容量为3:
func main() {
var slice = make([]int, 1, 3)
slice[0] = 1
slice = append(slice, 6, 0, 2, 4, 3, 1)
fmt.Println(slice)
}
Run Code Online (Sandbox Code Playgroud)
我惊讶地看到这个程序打印出来:
[1 6 0 2 4 3 1]
这让我想知道 - 如果append()可以简单地超越它,最初定义切片容量的重点是什么?设置足够大的容量是否有性能提升?
我有一个简单的CMakeLists.txt,如下所示:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(calculator)
FIND_PACKAGE(Qt5Core)
FIND_PACKAGE(Qt5Gui)
FIND_PACKAGE(Qt5Widgets)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
SET(calculator_SOURCES main.cpp mainwindow.cpp)
SET(calculator_HEADERS mainwindow.h)
SET(calculator_FORMS mainwindow.ui)
QT5_WRAP_CPP(calculator_HEADERS_MOC ${calculator_HEADERS})
QT5_WRAP_UI(calculator_FORMS_HEADERS ${calculator_FORMS})
ADD_LIBRARY(calculator_CONFIG ${calculator_HEADERS_MOC} ${calculator_FORMS_HEADERS})
QT5_USE_MODULES(calculator_CONFIG Widgets)
ADD_EXECUTABLE(calculator ${calculator_SOURCES} ${calculator_CONFIG})
QT5_USE_MODULES(calculator Core Gui Widgets)
Run Code Online (Sandbox Code Playgroud)
当我尝试使用cmake -G "Unix Makefiles"和随后构建项目时make,控制台说ui_mainwindow.h没有找到.问题是什么?这是我的cmake文件吗?
完整错误输出:
[ 22%] Building CXX object CMakeFiles/calculator.dir/mainwindow.cpp.o
/home/centurion/Code/cpp/calculator/mainwindow.cpp:2:27: fatal error: ui_mainwindow.h: No such file or directory
#include "ui_mainwindow.h"
^
compilation terminated.
make[2]: *** [CMakeFiles/calculator.dir/mainwindow.cpp.o] Error 1
make[1]: *** [CMakeFiles/calculator.dir/all] Error 2
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud) 所以我运行maven package将我的依赖项构建到一个 jar 中。但是,我需要 Maven 忽略任何编译错误并无论如何打包 jar。
这将如何实现?我pom.xml的如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- Project specific stuff would be here... -->
<build>
<sourceDirectory>wherever</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- etc... -->
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Run Code Online (Sandbox Code Playgroud)
搜索 SO 只向我展示了如何忽略单元测试中的编译错误。我只是希望我的包被编译,尽管代码中有任何错误。
编辑:人们似乎在抨击我。我已经做 Java 5 年了。我知道你不应该编译出错。我知道这意味着什么。
我的老板和我一起编程。他特意说,“我在Eclipse中可以编译出错,所以在Maven中编译出错。” 这不是因为我无知,也不是因为我拒绝接受自己的错误。因为那是我被特别命令去做的事情。我没有问这个问题,因为我不称职,正如你们许多人想的那样。
恨我所有你想要的,只要知道你这样做是不公平的。
我正在研究Rust手册的第二版,并决定尝试制作经典的Celsius-to-Fahrenheit转换器:
fn c_to_f(c: f32) -> f32 {
return ( c * ( 9/5 ) ) + 32;
}
Run Code Online (Sandbox Code Playgroud)
编译cargo build它将产生编译时错误:
error[E0277]: the trait bound `f32: std::ops::Mul<{integer}>` is not satisfied
--> src/main.rs:2:12
|
2 | return (c * (9 / 5)) + 32;
| ^^^^^^^^^^^^^ the trait `std::ops::Mul<{integer}>` is not implemented for `f32`
|
= note: no implementation for `f32 * {integer}`
Run Code Online (Sandbox Code Playgroud)
作为一个新的Rust程序员,我的解释是我不能将float和integer类型相乘.我通过使所有常量浮点数解决了这个问题:
fn c_to_f(c: f32) -> f32 {
return ( c * ( 9.0/5.0 ) ) + 32.0; …Run Code Online (Sandbox Code Playgroud) 我看了几个教程,使用卷积神经网络深入学习Keras.在教程中(以及Keras的官方文档中),MNIST数据集的加载方式如下:
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
Run Code Online (Sandbox Code Playgroud)
但是,没有解释为什么我们有两个元组的数据.我的问题是:什么是x_train和y_train以及他们如何从他们的不同x_test和y_test同行?
我正在使用react-router v3.0.0和react v15.1.0.我有以下路线设置:
ReactDom.render(<Provider store={store}>
<Router history={BrowserHistory}>
<Route path='shop' component={App}>
<IndexRoute component={Shop} />
<Route path='/product' component={ProductView} />
</Route>
</Router>
</Provider>, document.getElementById('app'));
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我Route的应用程序基础有一条路径'shop'.就用户而言,这应该导致2条不同的路线,http://example.com/shop并且http://example.com/shop/product.然而,这种情况并非如此.
当我部署上述代码时,http://example.com/shop正确呈现,但不http://example.com/shop/product呈现任何内容.事实上,我收到一个控制台错误:
Warning: [react-router] Location "/shop/product" did not match any routes
Run Code Online (Sandbox Code Playgroud)
所以,我改变了我的设置:
ReactDom.render(<Provider store={store}>
<Router history={BrowserHistory}>
<Route path='shop/' component={App}>
<IndexRoute component={Shop} />
<Route path='product' component={ProductView} />
</Route>
</Router>
</Provider>, document.getElementById('app'));
Run Code Online (Sandbox Code Playgroud)
这将允许我渲染http://example.com/shop/(注意尾随正斜杠)http://example.com/shop/product,但不是http://example.com/shop.
是可以渲染http://example.com/shop,http://example.com/shop/,http://example.com/shop/product在同一应用程序内?
很简单 我在/user/login路线中这样设置了一个cookie :
if (rememberMe) {
console.log('Login will remembered.');
res.cookie('user', userObj, { signed: true, httpOnly: true, path: '/' });
}
else {
console.log('Login will NOT be remembered.');
}
Run Code Online (Sandbox Code Playgroud)
我已经为cookie解析器设置了秘密:
app.use(cookieParser('shhh!'));
Run Code Online (Sandbox Code Playgroud)
很基本的东西。只要我能够检索存储在cookie中的任何内容,一切都工作得很好:
app.use(function (req, res, next) {
if (req.signedCookies.user) {
console.log('Cookie exists!');
req.session.user = req.signedCookies.user;
}
else {
console.log('No cookie found.');
}
next();
});
Run Code Online (Sandbox Code Playgroud)
在调用此中间件之前,请先声明“ Cookie存在!”。如果Cookie有效,则始终在控制台中登录。
问题是当我尝试删除Cookie时。我尝试了res.clearCookie('user'),,res.cookie('user', '', { expires: new Date() })并且尝试传递相同的标志(我传递给res.cookie()in /user/login)。我尝试使用这些方法的组合,但是没有任何效果。
当前,我能够清除Cookie(并且不会收到“ Cookie存在!”日志消息)的唯一方法是清除浏览器历史记录。我的登出路线如下所示:
route.get('/user/logout', function (req, res, next) { …Run Code Online (Sandbox Code Playgroud) GitHub的一个有用功能是用户可以通过提交消息关闭他们的"拉取请求"(PR).例如,如果Closes #1写入提交消息并且该提交随后落在master分支上,GitHub将自动关闭PR.
GitLab具有类似的设置,但拉取请求被称为"合并请求"(MR).虽然我在GitHub中找到了对自动PR关闭功能的支持,但似乎GitLab完全没有这个有用的功能.关闭合并请求(我发现)的唯一方法是手动点击GitLab本身的"接受"或"关闭"按钮.
是的,我知道你可以解决问题,如下所述:http://docs.gitlab.com/ee/customization/issue_closing.html
但正如那页所说:
当提交或合并请求解决一个或多个问题时,当提交或合并请求落在项目的默认分支中时,可能会自动关闭这些问题.
因此,如果MR或提交登陆,则只会关闭问题master,但如果提交登陆,则不会关闭MR master.
我搜索了GitLab-CE回购的问题并空手而归.这只是一个记录不完整的功能,还是GitLab CE根本不支持这个?
标题说明了一切.我正在尝试使用adb和我的平板电脑,但我似乎永远无法得到它.我按照本教程,但我得到的是:

我不明白.我尝试了原生的LG驱动程序,遵循上述教程,甚至只使用设备香草.没有什么工作,我不知道为什么.adb_usb.ini如果有人好奇,我手动将我的供应商ID添加到了.(LG的VID是1004).