我似乎无法使用mocha,supertest和should(和coffeescript)进行以下集成测试以传递快速项目.
考试
should = require('should')
request = require('supertest')
app = require('../../app')
describe 'authentication', ->
describe 'POST /sessions', ->
describe 'success', (done) ->
it 'displays a flash', (done) ->
request(app)
.post('/sessions')
.type('form')
.field('user', 'username')
.field('password', 'password')
.end (err, res) ->
res.text.should.include('logged in')
done()
Run Code Online (Sandbox Code Playgroud)
相关的应用程序代码
app.post '/sessions', (req, res) ->
req.flash 'info', "You are now logged in as #{req.body.user}"
res.redirect '/login'
Run Code Online (Sandbox Code Playgroud)
失败
1) authentication POST /sessions success displays a flash:
AssertionError: expected 'Moved Temporarily. Redirecting to …Run Code Online (Sandbox Code Playgroud) 我需要完成一个Android应用程序.为此我写了
@Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure You want to exit")
.setCancelable(false)
.setPositiveButton("YES"),
new DialogInterface.OnClickListener() {
// On
// clicking
// "Yes"
// button
public void onClick(DialogInterface dialog,int id) {
System.out.println(" onClick ");
closeApplication(); // Close Application method called
}
})
.setNegativeButton("NO"),
new DialogInterface.OnClickListener() {
// On
// clicking
// "No"
// button
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void closeApplication() {
System.out.println("closeApplication …Run Code Online (Sandbox Code Playgroud) 我刚刚用openCV2.3.1写了一个简单的视频阅读示例,但似乎无论如何我都无法打开avi视频:(
VideoCapture capture("guitarplaying.avi");
if(!capture.isOpened()){
std::cout<<"cannot read video!\n";
return -1;
}
Mat frame;
namedWindow("frame");
double rate = capture.get(CV_CAP_PROP_FPS);
int delay = 1000/rate;
while(true)
{
if(!capture.read(frame)){
break;
}
imshow("frame",frame);
if(waitKey(delay)>=0)
break;
}
capture.release();
Run Code Online (Sandbox Code Playgroud)
我做了一个断点std::cout<<"cannot read video!\n",发现它每次都停在这里.那么为什么avi视频无法打开?谢谢!
我正在编写一个应用程序,我使用express,Node.js和MongoDB(使用mongojs).我有一个模块db.js和一个server.js,下面有片段.
db.js
var getUsersByCity = function(city, callback) {
db.users.find({'city': city}).toArray(function(err, data) {
if (err) {
callback(err);
console.log(err);
} else {
console.log(data);
callback.json(data);
}
});
}
Run Code Online (Sandbox Code Playgroud)
server.js
app.post("/get_users_list", function(req, res) {
var body = req.body;
db.getUsersByCity(body.city, res);
});
Run Code Online (Sandbox Code Playgroud)
这是有效的,因为正如你所看到的callback.json(data),当我应该使用时,我(可能是错误地)使用了它callback(data).我认为db.js模块不应该负责发送响应,我应该res.json作为回调函数传递给我的函数.
问题是:当我按照我认为正确的方式做事时,我面临以下错误:
path_to_my_app/node_modules/mongojs/node_modules/mongodb/lib/mongodb/connection/base.js:245
throw message;
^
TypeError: Cannot call method 'get' of undefined
at res.json (path_to_my_app/node_modules/express/lib/response.js:189:22)
at path_to_my_app/db.js:36:13
at path_to_my_app/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:163:16
at commandHandler (path_to_my_app/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:706:16)
at path_to_my_app/node_modules/mongojs/node_modules/mongodb/lib/mongodb/db.js:1843:9
at Server.Base._callHandler (path_to_my_app/node_modules/mongojs/node_modules/mongodb/lib/mongodb/connection/base.js:445:41)
at path_to_my_app/node_modules/mongojs/node_modules/mongodb/lib/mongodb/connection/server.js:468:18
at …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,在其中我执行一些请求以获取对象ID.在每一个之后,我调用一个方法(get_actor_info())将此id作为参数传递(参见下面的代码).
ACTOR_CACHE_KEY_PREFIX = 'actor_'
def get_actor_info(actor_id):
cache_key = ACTOR_CACHE_KEY_PREFIX + str(actor_id)
Run Code Online (Sandbox Code Playgroud)
正如可以注意到,我在铸造actor_id到string与前缀相连来.但是,我知道我可以通过多种其他方式(.format()或者'%s%d',例如)来实现这一点,这导致了我的问题:'%s%d'在可读性,代码约定和效率方面,它会比字符串连接更好吗?
谢谢
我有一个视频(让我们称之为复合视频)由多个其他视频连接在一起使用某种模式.例如,请参阅下面视频的屏幕截图,分别由两个和四个其他视频组成:
但是,我需要以不同的方式显示它:一个主要的,更大的视频和N-1视频缩略图,其中N是视频总数.以下是与上述视频对应的其他显示:
要显示主要我正在使用HTML和CSS的组合来定位我想要在更大的div中的视频.无论复合视频中的视频数量如何,它都能顺利运行.
要显示缩略图,我正在使用<canvas>绘制我想要的部分:
video.addEventListener('play', function() {
(function loop() {
drawThumbnails();
setTimeout(loop, 1000 / 30); // drawing at 30fps
})();
}, false);
function drawThumbnails() {
for (var i = thumbs.length - 1; i >= 0; i--) {
drawThumbnail(thumbs[i]);
};
}
function drawThumbnail(thumb) {
var thumbNumber = Number(thumb.id.match(/\d+/g));
var canvasContext = thumb.getContext('2d');
var thumbCoordinates = getVideoCoordinates(thumbNumber);
var srcX = thumbCoordinates.column * videoWidth;
var srcY = thumbCoordinates.row * videoHeight;
canvasContext.drawImage(
video, srcX, srcY, videoWidth, videoHeight, // …Run Code Online (Sandbox Code Playgroud) 我需要在 debian 上安装 tkinter。经过一些研究[1] [2],我注意到 Tkinter 应该随 Python 自动安装。但是,当我尝试导入该模块时,我得到以下信息:
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tkinter
Run Code Online (Sandbox Code Playgroud)
当我尝试导入 Tkinter 时,错误发生变化:
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package
Run Code Online (Sandbox Code Playgroud)
所以我尝试通过 apt-get 安装 python-tk 包。又出现一个错误:
E: Failed …Run Code Online (Sandbox Code Playgroud) 我试图通过单击按钮来更改背景,但是我无法在Java代码中识别约束布局。
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
tools:context="frekzok.trafficlight.MainActivity">
//here are some button options
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java:
package frekzok.trafficlight;
import android.support.constraint.ConstraintLayout;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private ConstraintLayout mConstraintLayout;
private TextView mInfoTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mConstraintLayout =
(ConstraintLayout)findViewById(R.id.constraintLayout);
mInfoTextView = (TextView)findViewById(R.id.textView2);}
public void onRedButtonClick(View view) {
mInfoTextView.setText(R.string.red);
mConstraintLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.red));
}
public void onYellowButtonClick(View view) {
mInfoTextView.setText(R.string.yellow);
mConstraintLayout.setBackgroundColor(ContextCompat.getColor(this, …Run Code Online (Sandbox Code Playgroud) 我已经能够列出所有文件名和当前目录/文件夹,但我不知道如何为子目录创建 JSON 条目
这是我的代码
<?php
$dir = "office/";
if(is_dir($dir)){
if($dh = opendir($dir)){
while(($file = readdir($dh)) != false){
if($file != "." and $file != ".."){
$files_array[] = array('file' => $file); // Add the file to the array
}
}
}
$return_array =array('dir' => $files_array);
exit (json_encode($return_array));
}
?>
Run Code Online (Sandbox Code Playgroud)
和输出是
{
"dir": [
{
"file": "FreeWallpapersApp.zip"
},
{
"file": "20151211_ClipArtForTextView.7z"
},
{
"file": "QRite.7z"
},
{
"file": "CustomDialog_app_contacts.zip"
},
{
"file": "LockScreenBasicApp.apk"
},
{
"file": "ImgViewEffects.zip"
},
]
}
Run Code Online (Sandbox Code Playgroud)
如何使用 php 显示子文件夹中的文件以生成子目录中的文件名。