我在用
trap 'echo -e "\e[92m$ $BASH_COMMAND\e[0m"' DEBUG
Run Code Online (Sandbox Code Playgroud)
在Bash脚本中打印每个执行的命令.
这工作正常,只是当我将它们一起管道时它会打印两个命令:
bzip2 -dc < dump.sql.bz2 | mysql test
Run Code Online (Sandbox Code Playgroud)
打印:
Run Code Online (Sandbox Code Playgroud)$ bzip2 -dc < dump.sql.bz2 $ mysql test
我可以trap
对管道或管道进行任何更改,以便将该行打印为一行吗?
我正在使用 SpringBoot 开发 Web 应用程序,这是我的application.properties
文件,用于指定访问数据库的凭据:
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/Salamander
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行 SpringBoot 应用程序时,它给了我这个错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'salamander.user' doesn't exist
at sun.reflect.GeneratedConstructorAccessor72.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_40]
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_40]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1962) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
... 69 common frames omitted
Run Code Online (Sandbox Code Playgroud)
当然,我有一个名为 user 的实体,但数据库是空的。但
spring.jpa.hibernate.ddl-auto=create-drop
Run Code Online (Sandbox Code Playgroud)
应该说休眠以在数据库中再次创建表,对吗?所以有什么问题?
如果我使用远程数据库执行相同操作,即使远程数据库为空,它也可以工作。
我目前正在处理需要使用uint8_t的项目.我发现了一个问题,有人可以向我解释为什么会这样吗?
//using DIGIT_T = std::uint8_t;
using DIGIT_T = std::uint32_t;
std::uint8_t bits = 1;
DIGIT_T test1 = ~(DIGIT_T)0;
std::cout << std::hex << (std::uint64_t)test1 << std::endl;
DIGIT_T test2 = ((~(DIGIT_T)0) >> bits);
std::cout << std::hex << (std::uint64_t)test2 << std::endl;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,输出是预期的
ffffffff
7fffffff
Run Code Online (Sandbox Code Playgroud)
但是当我取消注释第一行并使用uint8_t时输出为
ff
ff
Run Code Online (Sandbox Code Playgroud)
这种行为给我带来了麻烦.
谢谢您的帮助.
马雷克
所以我使用的是React-Redux,在我的reducer中我想从我的状态中删除一个主机名.所以从环顾四周我发现state.filter是实现这一目标的好方法.但是,这不起作用,我在控制台中不断收到错误.
index.js
import "babel-polyfill";
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger'
import { HostnameAppContainer } from './components/HostnameApp';
import {createStore, applyMiddleware} from 'redux';
import hostnameApp from './reducer'
import {fetchHostnames} from './action_creators'
const loggerMiddleware = createLogger()
const store = createStore(
hostnameApp,
applyMiddleware(
thunkMiddleware, // lets us dispatch() functions
loggerMiddleware // neat middleware that logs actions
)
)
store.dispatch(fetchHostnames())
ReactDOM.render(
<Provider store={store}>
<HostnameAppContainer />
</Provider>,
document.getElementById('app')
)
;
Run Code Online (Sandbox Code Playgroud)
reducer.js
export …
Run Code Online (Sandbox Code Playgroud) 我正在弹性beanstalk上运行一个scala应用程序,服务器过量使用未旋转的容器日志.beanstalk的默认方案将docker日志旋转到/var/log/eb-docker/containers/eb-current-app/*
文件夹中,但是其他日志正在累积/var/lib/docker/containers/<container-id>/*
,因为它们没有旋转,磁盘会很快变满.
我已经尝试通过/etc/logrotate.elasticbeanstalk.hourly/logrotate.elasticbeanstalk.applogs.conf
手动添加另一个logrotation claues来处理这个问题,这解决了这个问题.
但是,当我尝试使用.ebextension配置文件在每个实例beanstalk启动时实现更改时,更改的日志轮换文件不会出现在服务器上.
这是我的.config文件 -
files:
"/etc/logrotate.elasticbeanstalk.hourly/logrotate.elasticbeanstalk.applogs.conf":
mode: "000644"
content: |
/var/log/eb-docker/containers/eb-current-app/* {
size 10M
rotate 5
missingok
compress
notifempty
copytruncate
dateext
dateformat %s
olddir /var/log/eb-docker/containers/eb-current-app/rotated
}
/var/lib/docker/containers/*/*.log {
size 10M
rotate 5
missingok
compress
notifempty
copytruncate
dateext
dateformat %s
olddir /var/log/eb-docker/containers/eb-current-app/rotated
}
Run Code Online (Sandbox Code Playgroud)
我也尝试使用我在这篇reddit帖子中找到的最简单的配置文件形式 - https://www.reddit.com/r/aws/comments/2u3afj/elastic_beanstalk_issues_with_ebextensions/,但它也没有任何配置文件对我发起的实例的影响.
关于为什么我的配置不会影响环境的任何建议将不胜感激.
这是一个非常愚蠢的问题,但是我无法maven-gpg-plugin
在 POM 上配置以正常工作。基本上,我希望它仅在我运行时才对工件进行签名mvn deploy
,以免在运行clean install
. clean install
即使没有我的私钥,任何在 github 上下载我的项目的人都应该能够运行,这似乎是合理的。
好的,所以我想这样做:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为 OSS Sonatype 会抱怨工件未签名。如果我用deploy
阶段替换(应该可以正常工作)阶段ìnstall
,那么它会在我运行时为 OSS Sonatype 正确签名mvn deploy
,但是即使在我运行时它也会运行mvn install
(我不希望)。我错过了什么?
我真的很困惑,发现下面的代码只是拒绝崩溃与典型的" 意外发现的nil,同时解开一个可选值 "异常,你期望从力展开bar
.
struct Foo {
var bar: Bar?
}
struct Bar {}
var foo = Foo()
debugPrint(foo.bar) // nil
debugPrint(foo.bar!.dynamicType) // _dynamicType.Bar
Run Code Online (Sandbox Code Playgroud)
这似乎dynamicType
是在某种程度上能够回退到定义类型的bar
-没有崩溃.
请注意,这仅在Bar
定义为值类型(如@dfri所说)时出现,Foo
是a struct
或final class
(由@MartinR指出)foo
并且是可变的.
我最初认为它可能只是一个编译器优化,因为bar
在编译时已知类型,因此力展开可能已被优化掉 - 但它也Bar
被定义为a 时崩溃final class
.此外,如果我将"优化级别"设置为-Onone
,它仍然有效.
我倾向于认为这是一个奇怪的错误,但想要一些确认.
这是一个错误或功能dynamicType
,或者我只是在这里遗漏了一些东西?
(使用Xcode 7.3 w/Swift 2.2)
在Swift 4.0.3中,这仍然是可重现的(有一个更简单的例子):
var foo: String?
print(type(of: foo!)) …
Run Code Online (Sandbox Code Playgroud) 我想用呈现 GenericForeignKey 字段的模型来概括我的工作流程。
所以我创建了父类 GFKModel:
class GFKModel(models.Model):
target_content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
target_id = models.PositiveIntegerField()
target = GenericForeignKey('target_content_type', 'target_id')
Run Code Online (Sandbox Code Playgroud)
然后我继承它:
class Question(GFKModel):
author = models.ForeignKey(User)
text = models.TextField()
class Meta:
unique_together = ('author', 'target_content_type', 'target_id')
Run Code Online (Sandbox Code Playgroud)
我需要在 'author'、'target_content_type' 和 'target_id' 上添加 unique_together 约束,但由于迁移错误我不能这样做:
qna.Question: (models.E016) 'unique_together' refers to field 'target_content_type' which is not local to model 'Question'.
HINT: This issue may be caused by multi-table inheritance.
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我需要等待几个AFNetworking请求完成,我尝试使用调度组,但我似乎无法做到正确.
这是我的代码:
dispatch_group_t group = dispatch_group_create();
for (int k = 0; k < 10 ; k++) {
dispatch_group_enter(group);
[[AFHTTPSessionManager manager] GET:@"http://google.com/" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"success");
dispatch_group_leave(group);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"failure");
dispatch_group_leave(group);
}];
}
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
NSLog(@"DONE");
Run Code Online (Sandbox Code Playgroud)
问题是它被卡在dispatch_group_wait上,因为既没有调用成功块,也没有调用失败块.
我该如何解决?
我有通过快递设置cookie的问题.我正在使用Este.js dev stack
,我尝试在API身份验证/login
路由中设置cookie .这是我在/api/v1/auth/login
路线中使用的代码
res.cookie('token', jwt.token, {expires: new Date(Date.now() + 9999999)});
res.status(200).send({user, token: jwt.token});
Run Code Online (Sandbox Code Playgroud)
在src/server/main.js
我已经注册cookie-parser
为第一个中间件
app.use(cookieParser());
Run Code Online (Sandbox Code Playgroud)
/api/v1/auth/login
路由的响应头包含
Set-Cookie:token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ..
Run Code Online (Sandbox Code Playgroud)
但cookie没有保存在浏览器中(document.cookie
是空的,Resources - Cookies
在develepoers工具中的选项卡也是空的):(
编辑:
我发现当我打电话给这个/api/v1/auth/login
(没有电话res.send
或res.json
)
res.cookie('token', jwt.token, {expires: new Date(Date.now() + 9999999), httpOnly: false});
next();
然后设置cookie并且响应头已设置X-Powered-By:Este.js
...这esteMiddleware
在expres前端渲染部分中设置.
我用的时候 res.send
res.cookie('token', jwt.token, {expires: new Date(Date.now() + 9999999), httpOnly: false}).send({user, token: jwt.token});`
next();
Run Code Online (Sandbox Code Playgroud)
然后我得到错误Can't set …
afnetworking ×1
bash ×1
c++ ×1
cookies ×1
django ×1
docker ×1
express ×1
hibernate ×1
inheritance ×1
java ×1
javascript ×1
maven ×1
mysql ×1
node.js ×1
objective-c ×1
react-redux ×1
reactjs ×1
redux ×1
repository ×1
spring ×1
swift ×1
yaml ×1