我已经使用npm安装了jasmine-node.我的项目的目录结构如下:
|-lib\
|-taxCalc.js
|-spec\
|-taxCalc.spec.coffee
|-taxCalc.spec.js
|-src\
|-taxCalc.coffee
Run Code Online (Sandbox Code Playgroud)
当我使用以下命令从for根文件夹运行jasmine-node时(对于CoffeeScript):
jasmine-node --coffee --verbose spec
Finished in 0.015 seconds
0 tests, 0 assertions, 0 failures
Run Code Online (Sandbox Code Playgroud)
如果我运行JavaScript版本也一样.
如果我明确指出spec文件测试运行正常:
jasmine-node --coffee --verbose spec/taxCalc.spec.coffee
Tax calculation
calculates tax
Finished in 0.009 seconds
1 test, 1 assertion, 0 failures
Run Code Online (Sandbox Code Playgroud)
文档说文件名应该以'spec.js'或'spec.coffee'结尾,所以一切都好看.
PS我在Windows 7上运行.
我已经创建了将窗口截屏保存到文件的过程.它适用于PNG和BMP,但不适用于JPG(和GIF).以下是捕获HBITMAP的代码:
HBITMAP Signature::getScreenHBITMAP() {
// get screen rectangle
RECT windowRect;
GetWindowRect(getMainWnd(), &windowRect);
// bitmap dimensions
int bitmap_dx = windowRect.right - windowRect.left;
int bitmap_dy = windowRect.bottom - windowRect.top;
// create bitmap info header
BITMAPINFOHEADER infoHeader;
infoHeader.biSize = sizeof(infoHeader);
infoHeader.biWidth = bitmap_dx;
infoHeader.biHeight = bitmap_dy;
infoHeader.biPlanes = 1;
infoHeader.biBitCount = 24;
infoHeader.biCompression = BI_RGB;
infoHeader.biSizeImage = 0;
infoHeader.biXPelsPerMeter = 0;
infoHeader.biYPelsPerMeter = 0;
infoHeader.biClrUsed = 0;
infoHeader.biClrImportant = 0;
// dibsection information
BITMAPINFO info;
info.bmiHeader = infoHeader;
HDC winDC = GetWindowDC(getMainWnd());
HDC …Run Code Online (Sandbox Code Playgroud) c++ windows-mobile visual-c++ windows-mobile-6 windows-mobile-6.5
我有相当大的数据库,有大约260万个文档,我有两个集合,每个集合120万,其余的是小集合(<1000个文档).当我为小集合创建新索引时,需要花费大量时间来完成索引(因此临时索引是无用的).似乎RavenDB索引进程读取DB中的每个文档并检查是否应将其添加到索引中.我认为仅索引索引使用的集合会更好.
此外,当使用Smuggler导出数据并且我只想导出一个小集合时,它会读取所有文档,导出可能需要花费很多时间.同时使用RavenDB Linq API和索引的自定义应用程序可以在几秒钟内导出数据.
为什么RavenDB会像这样?也许有一些配置设置可能会改变这种行为?
我正在为网站创建密码重置功能.必须实现密码重置的第一步:
我有服务类,它实现了公共方法 - RequestPasswordReset,这个方法非常具有程序性:
public void RequestPasswordReset(string email)
{
if(!IsValidEmail(email))
{
throw new ArgumentException("email");
}
var user = this.repository.FindByEmail(email);
if(user != null)
{
user.PasswordResetToken.Set(this.tokenGenerator.NewToken());
this.emailService.Send(this.from,
user.Email,
"Password reset",
"Your reset url: http://mysite.com/?t=" +
user.PasswordResetToken.Value);
}
else
{
this.emailService.Send(this.from,
user.Email,
"Requested password reset",
"Someone requested password reset at http://mysite.com");
}
}
Run Code Online (Sandbox Code Playgroud)
此方法违反单一责任原则 - 它检查用户是否存在,重置用户令牌,发送电子邮件.
这种解决方案的主要问题是,如果我需要添加额外的步骤,我必须为RequestPasswordReset方法和方法添加实现变得越来越复杂.例如,其他步骤可以是检查用户是否已在另一个相关系统中注册,我可以建议他在我的系统中创建新帐户或为他创建用户帐户.
我正在研究Command模式 - 将服务类重构为单独的命令可能是好的,而RequestPasswordReset可能是这些命令之一.但它并没有解决RequestPasswordReset方法中的步骤的主要问题.
我也在关注责任链模式 - 按顺序处理步骤会很好,但我不知道如何使用它来处理控制流程 - 应该实现的不同条件.此外,看起来每个处理程序应该执行类似的操作,并且不清楚整个控制流如何更改.
重构这样的程序代码的最佳方法是什么?
我正在尝试按子集合的属性创建查询.在SQL中很容易:
Select Table1.*
From Table1
Inner join Table2 on Table1.Id = Table2.Table1Id
OrderBy Table1.Column1, Table2.Column1
Run Code Online (Sandbox Code Playgroud)
这是我在NHibernate 2中的表现,它工作得很好:
var result = Session.Linq<Table1>()
.OrderBy(x => x.Column1)
.ThenBy(x => x.Table2.FirstOrDefault().Column1);
Run Code Online (Sandbox Code Playgroud)
迁移到NHibernate 3后,这不再起作用了.它抛出NHibernate.Hql.Ast.ANTLR.QuerySyntaxException:Antlr.Runtime.NoViableAltException.
我正在使用NHibernate 3.1.这种查询还有其他解决方案吗?
我有一个字段可以包含电子邮件或手机(在我的情况下,手机是8位数).我已经尝试了两种方法(两个示例都不起作用,因为'element'没有validate方法):
第一种方法:创建自定义方法并在那里进行两种验证,但后来我必须创建自己的电子邮件和移动验证 - 我找不到如何在新方法中重用jQuery验证规则的方法.这就是我想要的:
jQuery.validator.addMethod("mobileoremail", function(value, element) {
return this.optional(element) ||
element.validate({ rules: { digits: true, rangelength: [8, 8] } }) ||
element.validate({ rules: { email: true } });
}, "Invalid mobile or email");
Run Code Online (Sandbox Code Playgroud)
第二种方法:创建依赖规则.而且在这种情况下,我找不到如何重用jQuery验证规则的方法.
{ myRules: {
rules: {
user: {
required: true,
email: {
depends: function(element) {
return !element.validate({ rules: { mobile: true } });
}
},
mobile: {
depends: function (element) {
return !element.validate({ rules: { email: true } });
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) c# ×2
.net ×1
c++ ×1
coffeescript ×1
jasmine ×1
javascript ×1
jquery ×1
nhibernate ×1
node.js ×1
ravendb ×1
refactoring ×1
visual-c++ ×1