#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
cout << "Hello World!";
}
Run Code Online (Sandbox Code Playgroud)
这不起作用.为什么?
所以我正在使用docker compose文件来部署我的Go web服务器.我的服务器使用mongo,所以我在docker compose中添加了一个数据卷容器和mongo服务.然后我写了一个Dockerfile来构建我的Go项目,最后运行它.
但是,还有另一个必须完成的步骤.编译完项目后,我必须运行以下命令:
./my-project -setup
这将向数据库添加一些必要的信息,并且只需添加一次信息.但是我不能在Dockerfile上添加这一步(在构建过程中),因为mongo必须已经启动.
那么,我怎样才能做到这一点?即使我重新启动服务器然后再次运行,docker-compose up我也不希望再次执行此命令.
我想我错过了一些Docker的理解,因为我实际上并不了解数据量容器的所有内容(他们只是停止了装载卷的容器吗?).另外,如果我重新启动服务器,然后运行docker-compose up,将运行哪些命令?它是否会启动与现在使用给定CMD停止的相同容器?
无论如何,这是我的docker-compose.yml:
version: '2'
services:
mongodata:
image: mongo:latest
volumes:
- /data/db
command: --break-mongo
mongo:
image: mongo:latest
volumes_from:
- mongodata
ports:
- "28001:27017"
command: --smallfiles --rest --auth
my_project:
build: .
ports:
- "6060:8080"
depends_on:
- mongo
- mongodata
links:
- mongo
Run Code Online (Sandbox Code Playgroud)
这是我的Dockerfile来构建我的项目图像:
FROM golang
ADD . /go/src/my_project
RUN cd /go/src/my_project && go get
RUN go install my_project
RUN my_project -setup
ENTRYPOINT /go/bin/my_project …Run Code Online (Sandbox Code Playgroud) 如何在代码中同时使用两个数据库?我的PHP应用程序使用SQLite数据库,但也连接到另一个使用MySQL数据库的应用程序.
目前我在我的codeception.yml文件中有这个:
modules:
config:
Db:
dsn: 'sqlite:db.sqlite'
dump: tests/_data/dump.sql
populate: true
cleanup: true
Run Code Online (Sandbox Code Playgroud)
这样,数据库每次都会填充测试数据,并在测试结束时自动清理.现在如何添加一个MySQL数据库呢?
此外,如果可能,在某些测试中我使用"seeInDatabase"函数.我如何指定它必须看哪个数据库?
以下函数声明中的(c App)是什么?
func (c App) SaveSettings(setting string) revel.Result {
--------------------------------------------------------------------------------------
func Keyword to define a function
(c App) ????
SaveSettings Function name
(setting string) Function arguments
revel.Result Return type
Run Code Online (Sandbox Code Playgroud) 我正在请求一个网站,其响应是这样的JSON:
{
"success": true,
"response": "<html>... html goes here ...</html>"
}
Run Code Online (Sandbox Code Playgroud)
我已经看到了废弃HTML或JSON的两种方法,但还没有找到如何在JSON中废弃HTML.是否可以使用scrapy来做到这一点?
看看这张图:

我知道p1,p2和中心,这是2d点.我也知道角度p1-center-p2和半径r.
如何使用画布'函数arc()绘制弧的填充部分?
编辑
我真正需要做的是,给定2个点和一个角度,在这两个点之间绘制一条曲线,使得p1-center-p2角度是给定角度.
我所做的是计算其中有2个点的圆周的中心和半径,现在我需要绘制连接p1和p2并具有给定角度的线.这是我计算环球中心的功能(工作正常)
function getCenter(v0x, v0y, v1x, v1y, curve) {
// result = p0
resx = parseFloat(v0x);
resy = parseFloat(v0y);
// tmpvec = (p1 - p0) * .5
tmpx = (v1x - v0x) / 2;
tmpy = (v1y - v0y) / 2;
// result += tmpvec
resx = resx + tmpx;
resy = resy + tmpy;
// rotate 90 tmpvec
tmptmpx = tmpx;
tmptmpy = tmpy;
tmpy = -tmptmpx;
tmpx = tmptmpy;
// tmpvec *= 1/tan(c/2)
tmpx …Run Code Online (Sandbox Code Playgroud) 正如您在下面的pprof输出中看到的,我有这些嵌套的for循环,它占用了我程序的大部分时间.源代码是golang,但代码解释如下:
8.55mins 1.18hrs 20: for k := range mapSource {
4.41mins 1.20hrs 21: if positions, found := mapTarget[k]; found {
. . 22: // save all matches
1.05mins 1.05mins 23: for _, targetPos := range positions {
2.25mins 2.33mins 24: for _, sourcePos := range mapSource[k] {
1.28s 15.78s 25: matches = append(matches, match{int32(targetPos), int32(sourcePos)})
. . 26: }
. . 27: }
. . 28: }
. . 29: }
Run Code Online (Sandbox Code Playgroud)
目前我正在使用的结构是2 map[int32][]int32,targetMap和sourceMap.
对于给定的键,这些映射包含一组int.现在我想在两个映射中找到匹配的键,并保存数组中元素的组合.
例如:
sourceMap[1] = [3,4]
sourceMap[5] …Run Code Online (Sandbox Code Playgroud) 我有两个函数来计算数n的阶乘.我不明白为什么'正常'函数需要更少的时间来计算数n的阶乘.这是正常的功能:
double factorial(int n) {
double s = 1;
while (n > 1) {
s *= n;
--n;
}
return s;
}
Run Code Online (Sandbox Code Playgroud)
这是递归函数:
double factorial(int n) {
if (n < 2) return 1;
return n * factorial(n-1);
}
Run Code Online (Sandbox Code Playgroud)
这应该不那么耗时,因为它不会创建一个新变量,并且它可以减少操作.虽然普通函数确实使用了更多的内存,但速度更快.
我应该使用哪一个?为什么?
PS:我正在使用双,因为我需要它来计算e ^ x的泰勒级数.
我在app.router之前使用了express.bodyParser(),并且标题似乎是正确的,但我仍然在req.body上未定义:
var app = express();
...
app.use(express.bodyParser());
...
app.use(app.router);
Run Code Online (Sandbox Code Playgroud)
req.headers的输出是这样的:
{ host: '127.0.0.1:3000',
connection: 'keep-alive',
'content-length': '0',
'cache-control': 'max-age=0',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
origin: 'http://127.0.0.1:3000',
'user-agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36',
'content-type': 'application/x-www-form-urlencoded',
referer: 'http://127.0.0.1:3000/register',
'accept-encoding': 'gzip,deflate,sdch',
'accept-language': 'es-ES,es;q=0.8' }
Run Code Online (Sandbox Code Playgroud)
帖子声明如下:
app.post('/register/do', function(req, res) {
...
console.log(req.headers);
console.log(req.body);
...
});
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在开发一个应用程序,我需要从服务器获取当前日期(它与机器的日期不同).我从服务器收到日期并使用简单的Split我创建一个新的DateTime:
globalVars.fec = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, int.Parse(infoHour[0]), int.Parse(infoHour[1]), int.Parse(infoHour[2]));
Run Code Online (Sandbox Code Playgroud)
globalVars是一个类,fec是一个公共静态变量,因此我可以在应用程序的任何地方访问它(我知道编码错误...).现在我需要有一个计时器来检查该日期是否等于我在List中存储的某些日期,如果它相等,我只需要调用一个函数.
List<DateTime> fechas = new List<DateTime>();
Run Code Online (Sandbox Code Playgroud)
在必须从我使用计算机日期的服务器获取日期之前,要检查日期是否匹配我使用的是:
private void timerDatesMatch_Tick(object sender, EventArgs e)
{
DateTime tick = DateTime.Now;
foreach (DateTime dt in fechas)
{
if (dt == tick)
{
//blahblah
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有来自服务器的日期,所以DateTime.Now不能在这里使用.取而代之的是我创建了一个Interval = 1000的新计时器,并且在tick上我使用以下内容向globalVars.fec添加1秒:
globalVars.fec = globalVars.fec.AddSeconds(1);
Run Code Online (Sandbox Code Playgroud)
但时钟不准确,每30分钟时钟损失约30秒.
有没有其他方法可以做我想做的事情?我曾考虑使用threading.timer,但我需要访问其他线程和非静态函数.
我有一个代码,在引导网格上显示产品.每个产品使用4列网格,因此每行显示3列.但是,由于它们的高度不同,它们无法正常显示.
<div class="container">
<div class="row">
<div class="col-md-4"><div class="well">Random height #1</div></div>
<div class="col-md-4"><div class="well">Random height #2 <br><br><br><br><br><br></div></div>
<div class="col-md-4"><div class="well">Random height #3 <br><br><br><br><br></div></div>
<div class="col-md-4"><div class="well">Random height #4 <br></div></div>
<div class="col-md-4"><div class="well">Random height #5 <br><br><br><br></div></div>
<div class="col-md-4"><div class="well">Random height #6 <br><br><br></div></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/a3w0hjx9/
<div class="container">
<div class="row">
<div class="col-md-4"><div class="well">Random height #1</div></div>
<div class="col-md-4"><div class="well">Random height #2 <br><br><br><br><br><br></div></div>
<div class="col-md-4"><div class="well">Random height #3 <br><br><br><br><br></div></div>
</div>
<div class="row">
<div class="col-md-4"><div class="well">Random height #4 <br></div></div>
<div class="col-md-4"><div class="well">Random height #5 …Run Code Online (Sandbox Code Playgroud) 我目前有一个这样的 for 循环:
async myFunc() {
for (l of myList) {
let res1 = await func1(l)
if (res1 == undefined) continue
let res2 = await func2(res1)
if (res2 == undefined) continue
if (res2 > 5) {
... and so on
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是 func1、func2 是返回承诺的网络调用,我不希望它们在等待它们时阻塞我的 for 循环。所以我不介意与 myList[0] 和 myList[1] 并行工作,也不关心列表项的处理顺序。
我怎样才能实现这个目标?
有这个结构
type Square struct {
Side int
}
Run Code Online (Sandbox Code Playgroud)
这些功能是否相同?
func (s *Square) SetSide(side int) {
s.Side = side
}
Run Code Online (Sandbox Code Playgroud)
VS
func SetSquareSide(s *Square, side int) {
s.Side = side
}
Run Code Online (Sandbox Code Playgroud)
我知道他们也这样做,但他们真的相同吗?我的意思是,有任何内部差异或什么?