我已经制作了一个与CloudKit数据库交互的简单应用程序.基本上它只是一个日期选择器和两个按钮,第一个添加带有设置时间的新记录到数据库,第二个检索所有记录.除了所有操作都非常慢之外,这似乎工作正常.从saveRecord和performQuery获取响应大约需要10秒钟.我究竟做错了什么?以下是检索记录的代码.
@IBAction func retreiveButtonClick(sender: AnyObject) {
self.labelOutlet.text = "Waiting..."
func myHandler(results:[AnyObject]!, error:NSError!) {
if let err = error {
println("err: \(err.localizedDescription)")
} else {
self.labelOutlet.text = "Got \(results.count) results:"
for record in results {
let time = record.objectForKey("testTime") as NSDate
self.labelOutlet.text = self.labelOutlet.text + "\n\(time.description)"
}
}
}
var query = CKQuery(recordType:"TestTable", predicate:NSPredicate(value:true))
cloudDatabase.performQuery(query, inZoneWithID: nil, myHandler)
}
Run Code Online (Sandbox Code Playgroud)
我正在我的iPhone 5上测试它,它连接到本地WiFi.我注意到保存的记录在调用完成处理程序之前很久就出现在CloudKit Dashboard中(我有足够的时间来检查),所以我怀疑我在代码中做错了.
我在这里使用Unity.但可能我们只需指向一个正确的方向.
我们知道如何注入接口:
public class AccountController:ApiController
{
private readonly IAccountRepository _repository;
public AccountController(IAccountRepository repository)
{
_repository = repository;
}
}
Run Code Online (Sandbox Code Playgroud)
使用RegisterType
var container = new UnityContainer();
container.RegisterType<IAccountRepository, AccountRepository>(new HierarchicalLifetimeManager());
Run Code Online (Sandbox Code Playgroud)
但是在我的AccountRepository中,我们将一个类注入到构造函数中.
private readonly ApplicationUserManager _userManager;
public AccountRepository(ApplicationUserManager userManager)
{
_userManager = userManager;
}
Run Code Online (Sandbox Code Playgroud)
因此,在调用ApiController时,我仍然会收到此错误:
尝试创建"AccountController"类型的控制器时发生错误.确保控制器具有无参数的公共构造函数.
堆栈跟踪:
System.Web.Http.Detpatcher.DefaultHttpControllerActivator.GetInstanceOrActivator上的System.Web.Http.Internal.TypeActivator.Create [TBase](Type instanceType)中的System.Linq.Expressions.Expression.New(Type type)(HttpRequestMessage请求,类型System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage请求,HttpControllerDescriptor controllerDescriptor,类型controllerType)中的controllerType,Func`1和activator)
由于我已经创建了一些其他工作正常的ApiControllers,我想这一定是因为我们的ApplicationUserManager无法解析.
这里ApplicationUserManager继承自UserManager而不是接口.我不能用container.RegisterType<interface, derived_class>
.解决问题的正确方法是什么?
这是ApplicationUserManager:
public class ApplicationUserManager : UserManager<User>
{
public ApplicationUserManager(IdentityContext identityContext)
: base(new UserStore<User>(identityContext)) …
Run Code Online (Sandbox Code Playgroud) 这是一个非常直截了当的问题.Firebird有一个名为nbackup的备份工具,而您可以进行增量备份.
如果您没有按正确的顺序进行备份,该工具会抱怨(例如,您进行0级备份,然后进行2级备份).然后,我假设该工具在数据库中放置一个标志,指示上次备份的级别.
我该如何检索这些信息?
标题几乎描述了我的目标.这是代码[仅适用于WebKit]:
我们有两个div,elem1和elem2.还有一个名为logger的文本框来显示结果.elem1有一些带溢出的文本:滚动.
function eventHandler(e){
var myEvt = new e.constructor(e.type, e);
document.getElementById('elem1').dispatchEvent(myEvt);
}
function elem1MouseScroll(e){
document.getElementById('logger').value='mousescroll on ' + (e.target || e.srcElement).id + ' at (' + e.clientX + ', ' + e.clientY + ')';
}
document.getElementById('elem1').addEventListener('mousewheel', elem1MouseScroll, false);
document.getElementById('elem2').addEventListener('mousewheel', eventHandler, false);
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/s4hwt886/1
[蓝色div上的鼠标滚轮滚动应该转发到粉红色div.顶部的文本框显示结果.]
正如您所看到的,即使来自elem2的mousewheel事件在elem1上触发相同,遗憾的是elem1中的内容实际上并未实际滚动.
我很困惑.有人可以帮忙吗?您不必担心Gecko部分无法正常工作.构造函数技巧在Gecko中不起作用,因此代码会更大一些.这就是为什么我没有把它包括在小提琴中.
编辑:在Chrome中,这个小提琴就像我想要的那样.所以我更新了代码以支持Gecko.不幸的是,Firefox表现得像Safari一样.转发事件正在触发,我可以在日志文本框中看到它,但内容不滚动.这是更新的小提琴:http://jsfiddle.net/s4hwt886/2/
NB我想要一个非Jquery解决方案.我能找到的所有其他类似线程都与Jquery有关.
我试图在d3内重新调整窗口大小的SVG图表,但没有使用viewBox
和preserveAspectRatio
参数(我不喜欢他们如何处理文本).
我还试图在附加单个元素(不基于支持数据)时通过Bostock的建议坚持使用d3的数据绑定设计.
我有一些归结为这个(jsFiddle).但是,SVG元素的宽度/高度永远不会更新.
<div class="chart-container">
<button class="user-option">Some User Options</button>
<div class="svg-container"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
$(window).on("resize", function () {
draw();
});
function draw() {
var container = d3.select('.chart-container');
var drawWidth = Math.round(0.80 * container.node().clientWidth);
var drawHeight = Math.round(drawWidth * (3 / 4)); // Fixing a 4/3 aspect ratio
/*
* Use an inner g element as the SVG canvas in order to set and forget margins.
* See http://bl.ocks.org/mbostock/3019563
*/
var margin = …
Run Code Online (Sandbox Code Playgroud) 目前是否可以跨模块扫描/查询/迭代所有具有某些属性的函数(或类)?
例如:
source/packageA/something.d:
@sillyWalk(10)
void doSomething()
{
}
Run Code Online (Sandbox Code Playgroud)
source/packageB/anotherThing.d:
@sillyWalk(50)
void anotherThing()
{
}
Run Code Online (Sandbox Code Playgroud)
source/main.d:
void main()
{
for (func; /* All @sillWalk ... */) {
...
}
}
Run Code Online (Sandbox Code Playgroud) Grails 2.3.10
我已经创作了一个Grails插件,可以在我公司内部使用并安装在公司的Artifactory仓库中.如何设置另一个项目的BuildConfig,以便在安装插件时检查公司的私有神器仓库?
这是我尝试过的:
repositories {
...
grailsRepo "http://artifactory.mycompany.com/"
}
Run Code Online (Sandbox Code Playgroud)
并且...
repositories {
...
mavenRepo "http://artifactory.mycompany.com/"
}
Run Code Online (Sandbox Code Playgroud)
这些似乎都没有任何影响.更改或添加到grails插件仓库的正确配置是什么?
理想情况下,我希望检查自定义repo和grails central repo的插件.
编辑:
为了进一步澄清......我希望我的项目配置为下拉一个只存在于公司的神器服务器上的插件,而不是中心的Grails插件仓库.
我从grails编译得到以下输出:
Error |
Resolve error obtaining dependencies: Could not find artifact org.grails.plugins:cascade-validation:zip:0.1.0 in grailsCentral (http://repo.grails.org/grails/plugins) (Use --stacktrace to see the full trace)
Error |
Resolve error obtaining dependencies: Could not find artifact org.grails.plugins:cascade-validation:zip:0.1.0 in grailsCentral (http://repo.grails.org/grails/plugins) (Use --stacktrace to see the full trace)
Error |
Resolve error obtaining dependencies: Could not find artifact org.grails.plugins:cascade-validation:zip:0.1.0 in grailsCentral (http://repo.grails.org/grails/plugins) …
Run Code Online (Sandbox Code Playgroud) HEXTORAW 是多个 RDBMS 中的一个函数,例如Oracle和LUW 上的 DB2。它接受一个字符或整数输入,并基本上将其转换为十六进制值。
HEXTORAW(1234) = x'1234'
Run Code Online (Sandbox Code Playgroud)
这种类型转换的算法是什么?幕后代码发生了什么?
(这是因为想要在没有 HEXTORAW 函数的 RDBMS 中创建此函数。)
我正在尝试使用javascript进行移动重定向。这是我要完成的工作:
普通视图:https: //secure.example.com/checkout/Checkout.aspx?a = 1&b = 2&c = 3&d = 456789
重定向到
移动视图:https : //differentdomain.com/mobile/Checkout.aspx?a=1&b=2&c=3&d=456789
<script type="text/javascript">
function TN_mobileUrlOverride()
{
TN_mobile.DroidUrl = TN_mobile.IphoneUrl = TN_mobile.BlackBerryUrl = "https://example.com/mobile" + window.location;
}
</script>
<script src="http://s3.amazonaws.com/TNService/Js/mobile.js"></script>
Run Code Online (Sandbox Code Playgroud)
当我使用window.location时,它将添加整个域,从而导致:https : //example.com/mobile/https : //differentdomain.com/mobile/Checkout.aspx?a=1&b=2&c=3&d=456789
当我使用window.location.path时,它不携带变量,仅携带文件:https : //differentdomain.com/mobile/Checkout.aspx
替换域时如何保留文件和URL参数?
谢谢!
使用MongoDB v2.6,如果从大型结果集中对游标进行排序以获得溢出,则这种情况并不少见.
cursor = db.collection.find( { "key" : "value" } )
cursor.sort( { "rank" : 1 } ) // This can blow up
Run Code Online (Sandbox Code Playgroud)
该错误看起来很像:
运行器错误:溢出排序阶段缓冲数据使用量为33598393字节超过内部限制33554432字节
在这种情况下,解决方案是为排序标准提供索引,而不仅仅是密钥.
db.collection.ensureIndex( { "rank" : 1 } ) // ascending
Run Code Online (Sandbox Code Playgroud)
这很美妙.
我在另一个地方遇到了这个问题,一个文本索引. 按照MongoDB手册中有关文本索引创建的说明,我完成了以下操作:
db.collection.ensureIndex(
{ "$**": "text" },
{ name: "TextIndex" }
)
Run Code Online (Sandbox Code Playgroud)
并且,这已在集合中所有ExtendedJSON对象的所有字段上创建了一个文本索引.
搜索工作完美.
cursor = db.collection.find( { "$text" : { "$search" : "NEEDLE" } } )
cursor.count() // w00t! records …
Run Code Online (Sandbox Code Playgroud)