我使用的RabbitMQ并从一个简单的Python样品在这里 一起泊坞窗-撰写.我的问题是我需要等待rabbitmq完全启动.从我到目前为止搜索到的,我不知道如何等待容器x(在我的情况下是工人)直到y(rabbitmq)开始.
我找到了这个博文,他检查其他主机是否在线.我还发现了这个docker命令:
等待
用法:docker等CONTAINER [CONTAINER ...]
阻止,直到容器停止,然后打印其退出代码.
等待容器停止可能不是我想要的但如果是,是否可以在docker-compose.yml中使用该命令?到目前为止,我的解决方案是等待几秒钟并检查端口,但这是实现此目的的方法吗?如果我不等,我会收到错误.
泊坞窗,compose.yml
worker:
build: myapp/.
volumes:
- myapp/.:/usr/src/app:ro
links:
- rabbitmq
rabbitmq:
image: rabbitmq:3-management
Run Code Online (Sandbox Code Playgroud)
python hello sample(rabbit.py):
import pika
import time
import socket
pingcounter = 0
isreachable = False
while isreachable is False and pingcounter < 5:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('rabbitmq', 5672))
isreachable = True
except socket.error as e:
time.sleep(2)
pingcounter += 1
s.close()
if isreachable:
connection = pika.BlockingConnection(pika.ConnectionParameters(
host="rabbitmq"))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', …Run Code Online (Sandbox Code Playgroud) 我很困惑组件和反应类之间的区别是什么?
我何时在反应类中使用组件?看起来组件是一个类,createClass创建一个组件.
https://facebook.github.io/react/docs/top-level-api.html
React.Component
当使用ES6类定义React组件时,这是它的基类.有关如何将ES6类与React一起使用,请参阅可重用组件.有关基类实际提供的方法,请参阅组件API.
React.createClass
给定规范,创建组件类.组件实现一个返回一个子节点的render方法.那个孩子可能有一个任意深度的孩子结构.使组件与标准原型类不同的一点是,您不需要在它们上调用new.它们是为您构建后备实例(通过new)的便捷包装器.
yo angular在我的主目录中生成文件,我不知道为什么.
我做了以下事情:
节点的ppa
curl -sL https://deb.nodesource.com/setup | sudo bash -
Run Code Online (Sandbox Code Playgroud)
然后安装节点
sudo apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
创建符号链接
sudo ln -s "$(which nodejs)" /usr/bin/node
Run Code Online (Sandbox Code Playgroud)
安装自耕农
sudo npm install -g yo
sudo npm install -g generator-angular
Run Code Online (Sandbox Code Playgroud)
来自https://github.com/yeoman/generator-angular的说明的后续步骤
mkdir my-new-project && cd $_
Run Code Online (Sandbox Code Playgroud)
现在我跑了
yo angular test1
Run Code Online (Sandbox Code Playgroud)
现在所有文件都将在我的主目录中创建,而不是我当前所在的my-new-project目录.我错了什么?
node -v:v0.10.36
npm -v:2.5.1
Update1:新的npm版本
解:
yo angular在当前目录中查找.yo-rc.json文件,如果该文件不在那里它试图在home目录中找到它.要解决这个问题:
在主目录中查找隐藏的.yo-rc.json文件并将其删除.或者在要使用的目录中创建一个空的.yo-rc.json文件.
我正在使用Thymeleaf的Spring Boot 1.2.2.我的问题是我尝试在表单中发布一长串项目(一些标签,一个复选框),这些列表不能执行我的列表中的这么多项目.(我测试了小清单并且它有效.)
首先我使用了码头,但收到了错误,其中说:
java.lang.IllegalStateException: Form too many keys
at org.eclipse.jetty.util.UrlEncoded.decodeUtf8To(UrlEncoded.java:526)
Run Code Online (Sandbox Code Playgroud)
我搜索并看到了这篇文章.结果我补充说
applicationDefaultJvmArgs = ["-Dorg.eclipse.jetty.server.Request.maxFormKeys=8000"]
Run Code Online (Sandbox Code Playgroud)
到我的gradle.build,但它没有成功.结果我切换到Tomcat,它再次失败.错误消息是:
java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
Run Code Online (Sandbox Code Playgroud)
看起来它只能执行256个条目.我有大约500个条目.所以我认为增加maxhttpheadersize会有所帮助,并将此行添加到我的application.properties:
server.tomcat.max-http-header-size=-1
Run Code Online (Sandbox Code Playgroud)
(-1为无限制)我在我的Thymeleaf表格中设置method ="post".任何其他方式增加256限制?我不想分页我的结果.谢谢你的帮助.
我想在我的app.js服务器上传一个文件,该文件应该将该文件传输到像我的upload.js服务器这样的跨域服务器.
完整代码可在以下链接中找到
upload.js服务器正在运行.我的问题是app.js服务器.请求似乎能够传输文件(https://github.com/request/request#streaming).但是我不懂它.我总是得到:我的app.js中的[错误:协议无效]
最重要的是这条线:
fs.createReadStream(file.path).pipe(request.post('localhost:4000/upload'))
Run Code Online (Sandbox Code Playgroud)
我将post更改为put并在我的upload.js中post方法也放,但它会导致相同的错误.
我的目标是将文件从html页面上传到localhost:3000/upload,将文件管道传输到localhost:4000/upload(理想情况下具有相同的文件名).但我没有得到它的工作(这篇文章没有帮助我).
app.js:
var express = require('express')
, multiparty = require('multiparty')
, request = require('request')
, fs = require('fs')
, util = require('util')
, http = require('http');
var app = express();
app.use('/static', express.static('static'));
process.on('uncaughtException', function (err) {
console.log(err);
});
app.get('/', function (req, res) {
res.redirect('static/index.html');
});
app.post('/upload', function(req, res, next){
//https://github.com/request/request#streaming
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, …Run Code Online (Sandbox Code Playgroud) 我试图在文件的两次提交之间显示一个git diff.基本上,我这样做是为https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowChangedFilesBetweenCommits.java
您可以在https://github.com/svenhornberg/JGitDiff下查看我的完整代码
public class RepoDiff {
public void compare(byte[] fileContentOld, byte[] fileContentNew) {
try {
Repository repository = createNewRepository();
Git git = new Git(repository);
// create the file
commitFileContent(fileContentOld, repository, git, true);
commitFileContent(fileContentNew, repository, git, false);
// The {tree} will return the underlying tree-id instead of the commit-id itself!
ObjectId oldHead = repository.resolve("HEAD^^^^{tree}"); //here is my nullpointer
ObjectId head = repository.resolve("HEAD^{tree}");
System.out.println("Printing diff between tree: " + oldHead + " and " + head);
// prepare …Run Code Online (Sandbox Code Playgroud) 根据我对docker compose/fig的理解,如果您不想将端口暴露给其他人,则在两个服务/图像之间创建链接是一个主要原因.
像这里db不暴露任何端口,只链接:
web:
build: .
links:
- db
ports:
- "8000:8000"
db:
image: postgres
Run Code Online (Sandbox Code Playgroud)
Web是否认为db在其localhost上运行?我会从web中的脚本/程序连接到localhost:5432(postgresql的标准端口)来获取数据库连接吗?
如果这是正确的,如何在不暴露的情况下将端口5432更改为6432?我会在另一个端口上运行postgresql吗?
更新:
一些输入之后的有用链接:
是否可以使用与ReactRouter的反应,而不使用browserify或webpack.我正在关注http://rackt.github.io/react-router的文档,他们需要react和react-router(require('react-router');).如果我使用browerifly我生成的捆绑大约是1MB文件大小,这听起来很多.
那么是否可以通过包含来自像https://cdnjs.cloudflare.com/ajax/libs/react-router/0.13.3/ReactRouter.js这样的CDN的编译JS来实现反向传输,而不是自己捆绑所有需求?如果我尝试使其与CDN一起使用,我会收到一条未定义Route的错误.但它看起来像是在cdn文件中导出的.
我想编译我的JSX/ES6反应组件包括ReactRouter并从cdn反应JS文件,只将我的组件捆绑到一个新的js文件中.
这是可能的,还是浏览器和webpack正确设置项目的方法?(我看了几个github回购).我有些疑惑,因为http://rackt.github.io/react-router/上没有安装指南
喜欢这个伪html:
<head>
CND :include react, react-router
my code combinded.js
</head>
Run Code Online (Sandbox Code Playgroud) 我试图保护我的 Spring Boot 应用程序 (1.21) 的一些 urlpattern 看起来像我的 antMatchers("/report**")。hasRole("REPORT")被忽略。我改变了我的 antMatchers 的顺序,但这没有改变。
例如,如果我浏览到诸如 localhost:9000/report/books 之类的任何内容,我需要登录并且它仅适用于我的用户名密码组合,但我没有将 ROLE REPORT设置为我的用户“user”。所以我希望我不被允许访问报告站点,但会显示该页面。
我必须如何更改只有具有角色报告的用户才能访问该网址?
EDIT1更新源文件
应用程序.java
@SpringBootApplication
@EnableTransactionManagement
public class Application {
public static void main(String[] args) {
@SuppressWarnings("unused")
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
配置文件
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer(){
return new MyCustomizer();
}
private static class MyCustomizer implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer factory) { …Run Code Online (Sandbox Code Playgroud) 我想按节点获取一个子图(红色区域):子图由从输入节点可到达的所有节点组成。
像G.subgraph(3)从红色区域返回一个新的DiGraph。
例如,我创建一个DiGraph如下:
import networkx as nx
G = nx.DiGraph()
G.add_path([1,2,3,4])
G.add_path([3,'a','b'])
A = nx.to_agraph(G)
A.layout()
A.draw('graph.png')
Run Code Online (Sandbox Code Playgroud)
我查看了https://networkx.github.io/documentation/latest/reference/generation/networkx.Graph.subgraph.html并将其转换为单向。我测试了out_egdes,strong / weak_connected_component,但从未成功。我还查看了如何在有向图中查找子图而不转换为无向图?和Networkx:提取包含给定节点的有向组件(有向图)。
我知道Subgraph在DiGraph中不起作用。
有人可以告诉我该怎么做吗?如果结果图也是DiGraph会很好
python 3.5 的新功能之一是从该项目中获得启发的类型提示。
键入:PEP 484 –键入提示。
我想测试它,但是它没有按预期工作。
import typing
class BankAccount:
def __init__(self, initial_balance: int = 0) -> None:
self.balance = initial_balance
def deposit(self, amount: int) -> None:
self.balance += amount
def withdraw(self, amount: int) -> None:
self.balance -= amount
def overdrawn(self) -> bool:
return str(self.balance < 0)
my_account = BankAccount(15)
my_account.withdraw(5)
print(type(my_account.overdrawn()))
Run Code Online (Sandbox Code Playgroud)
结果是:
<class 'str'>
Run Code Online (Sandbox Code Playgroud)
我期待一个错误,因为我期望布尔作为回报。我在python:3.5(docker)和local上测试了它。我是否想念一些东西以使其起作用?这种键入是否在运行时不起作用(例如python app.py)?
java ×2
python ×2
reactjs ×2
spring-boot ×2
browserify ×1
docker ×1
fig ×1
file-upload ×1
jgit ×1
networkx ×1
node.js ×1
python-3.x ×1
react-router ×1
subgraph ×1
thymeleaf ×1
type-hinting ×1
ubuntu-14.04 ×1
webpack ×1
yeoman ×1