如果Heroku Postgres不允许使用blob,我应该使用什么来存储二进制数据?
2012-05-30T05:59:36+00:00 app[web.1]: [debug] c.j.b.StatementHandle - create table image_info (
2012-05-30T05:59:36+00:00 app[web.1]: id bigint not null,
2012-05-30T05:59:36+00:00 app[web.1]: image_id varchar(255),
2012-05-30T05:59:36+00:00 app[web.1]: subject_id varchar(255),
2012-05-30T05:59:36+00:00 app[web.1]: web_thumbnail blob,
2012-05-30T05:59:36+00:00 app[web.1]: created_date timestamp,
2012-05-30T05:59:36+00:00 app[web.1]: image blob,
2012-05-30T05:59:36+00:00 app[web.1]: thumbnail blob,
2012-05-30T05:59:36+00:00 app[web.1]: constraint pk_image_info primary key (id))
2012-05-30T05:59:36+00:00 app[web.1]: [debug] c.j.b.PreparedStatementHandle - update play_evolutions set last_problem = 'ERROR: type "blob" does not exist
2012-05-30T05:59:36+00:00 app[web.1]: Position: 176 [ERROR:0, SQLSTATE:42704]' where id = 1
Run Code Online (Sandbox Code Playgroud) 如果有警卫,我如何用于理解?
type Error = String
type Success = String
def csrfValidation(session:Session, body:JsValue):Either[Error,Success] = {
val csrfRet = for (csrfSession <- csrfStateSessionValidation(session).right;
csrfReq <- csrfStateReqBodyValidation(body).right if (csrfSession == csrfReq)) yield (csrfReq)
if (csrfRet.isRight)
Right(csrfRet)
else {
Logger.warn("request and session csrf is not the same")
Left("Oops,something went wrong, request and session csrf is not the same")
}
}
Run Code Online (Sandbox Code Playgroud)
使用它时出现此错误.
'withFilter' method does not yet exist on scala.util.Either.RightProjection[Error,Success], using `filter' method instead
Run Code Online (Sandbox Code Playgroud)
编辑: 我有另一个错误.我认为如果使用guard,它会返回一个选项结果.
[error] type mismatch;
[error] found : Option[scala.util.Either[Nothing,controllers.ProfileApiV1.Success]]
[error] required: …Run Code Online (Sandbox Code Playgroud) 我有这样的地图:
Map("first_key"->"first_value",
"second_key"->Map("second_first_key"->"second_first_value"))
Run Code Online (Sandbox Code Playgroud)
如何在scala中以递归方式将所有键转换为这样:
Map("firstKey"->"first_value",
"secondKey"->Map("secondFirstKey"->"second_first_value"))
Run Code Online (Sandbox Code Playgroud) 我想将json转换为Salat模型.我正在使用Play 2.X Scala Json.我找不到任何格式化可空的Seq的文档.根据https://github.com/novus/salat/wiki/SupportedTypes,我不能使用Option [Seq]或Option [List].
以下json是好的,但有时"位置"可能会丢失.
{
"id": 581407,
"locations": [
{
"id": 1692,
"tag_type": "LocationTag",
"name": "san francisco",
"display_name": "San Francisco"
}]
}
Run Code Online (Sandbox Code Playgroud)
这些是类:
case class User(
var id: Int,
var locations: Seq[Tag] = Seq.empty
)
case class Tag(
id: Int,
tag_type:String,
name:String,
display_name:String
)
Run Code Online (Sandbox Code Playgroud)
如何格式化可空的"位置"?
implicit val format: Format[User] = (
(__ \ 'id).format[Int] and
(__ \ 'locations).formatNullable(Seq[Tag])
)
Run Code Online (Sandbox Code Playgroud) 我想使用Scala正则表达式从以下输入中提取bell.com.我尝试了一些没有成功的变化.
"www.bell.com"
"bell.com"
"http://www.bell.com"
"https://www.bell.com"
"https://bell.com/about"
"https://www.bell.com?token=123"
Run Code Online (Sandbox Code Playgroud)
这是我的代码,但不起作用.
val pattern = """(?:([http|https]://)?)(?:(www\.)?)([A-Za-z0-9._%+-]+)[/]?(?:.*)""".r
url match {
case pattern(domain) =>
print(domain)
case _ => print("not found!")
}
Run Code Online (Sandbox Code Playgroud)
编辑:我的正则表达式错了.感谢@Tabo.这是正确的.
(?:https?://)?(?:www\.)?([A-Za-z0-9._%+-]+)/?.*
Run Code Online (Sandbox Code Playgroud) 我从内容脚本中插入了一个 iframe。它工作正常。但是如果我想在 iframe 上显示父级的 html 内容,我必须使用消息在 iframe 和内容脚本之间进行通信,但它不起作用。然后我尝试将消息从 iframe 发送到“事件页面”,然后发送到“内容脚本”。一旦内容脚本收到消息,它将查询 html 内容并回复。它也不起作用。我怎样才能让它工作?
内容脚本:
var iframe = document.createElement('iframe');
iframe.id = "popup";
iframe.src = chrome.runtime.getURL('frame.html');
document.body.appendChild(iframe);
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.from === 'event' && msg.method == 'ping') {
sendResponse({ data: 'pong' });
}
});
Run Code Online (Sandbox Code Playgroud)
活动页面:
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.from === 'popup' && msg.method === 'ping') {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
from: 'event',
method:'ping'}, function(response) {
sendResponse(response.data);
});
});
}
});
Run Code Online (Sandbox Code Playgroud)
框架.js
// This callback function …Run Code Online (Sandbox Code Playgroud) 我想继续使用我当前的RestKit,同时使用MagicRecord进行其余的提取和更新.我希望Restkit的MOC发送更新到MagicRecord的默认上下文.如果我理解正确,这就是我在做的事情.这个可以吗?
NSManagedObjectContext* context = [[RKObjectManager sharedManager].objectStore managedObjectContextForCurrentThread];
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:[XDBStore storeName]];
[context setParentContext:[NSManagedObjectContext MR_defaultContext]];
Run Code Online (Sandbox Code Playgroud)
也许是另一种方式,但仍然不确定.
NSPersistentStoreCoordinator *coordinator = [[[RKObjectManager sharedManager] objectStore] persistentStoreCoordinator];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];
Run Code Online (Sandbox Code Playgroud)
以前有人有同样的问题吗?
编辑1
我尝试了@ casademora的建议#1来设置默认上下文,但是出现了这个错误.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can only use -performBlockAndWait: on an NSManagedObjectContext that was created with a queue.'
Run Code Online (Sandbox Code Playgroud)
编辑2
我找到了一个黑客.首先,在magicalrecord中打开默认上下文的setter.接下来,更改RestKit存储的并发类型,以便可以在magicalrecord中使用其上下文.
的NSManagedObjectContext + MagicalRecord.h
+ (void) MR_setDefaultContext:(NSManagedObjectContext *)moc;
+ (void) MR_setRootSavingContext:(NSManagedObjectContext *)context;
Run Code Online (Sandbox Code Playgroud)
RKManagedObjectStore.m
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
Run Code Online (Sandbox Code Playgroud)
然后像这样设置MagicalRecord:
NSManagedObjectContext* context = [[RKObjectManager sharedManager].objectStore managedObjectContextForCurrentThread];
[NSManagedObjectContext MR_setRootSavingContext:context]; …Run Code Online (Sandbox Code Playgroud) 我尝试在Play 2.X上构建我的应用程序的监控工具.但是,我发现的大部分答案都指向了这个主题.
https://groups.google.com/forum/#!topic/play-framework/AE1INL1iqrs
另外一篇SO评论提到New Relic目前不支持Play 2.X.
New Relic文档仅提及Play 1.2.4.
https://newrelic.com/docs/java/new-relic-for-java
在Play 2.X上有新的Relic的解决方法吗?
我在s3 ios sdk上看到了一个用密钥上传文件的例子.但是,我找不到任何将文件上传到存储桶下的子文件夹的示例.如何指定我要上传到的子文件夹?
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = yourBucket;
uploadRequest.key = yourKey;
uploadRequest.body = yourDataURL;
uploadRequest.contentLength = [NSNumber numberWithUnsignedLongLong:fileSize];
[[transferManager upload:uploadRequest] continueWithBlock:^id(BFTask *task) {
// Do something with the response
return nil;
}];
Run Code Online (Sandbox Code Playgroud) 我有一个调用api并返回未来的Scala未来,如果结果不正确,那么另一个api调用将提交第一个future的结果并在将来返回.
这就是我到目前为止所拥有的.
val fut1 = Future(queryFirst)
val fut2 = fut1 map {
case y if y.isInstanceOf[NoResult] => Future(queryAgainWithFut1Result)
case x => x
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我访问fut2结果,它会给出这样的结果:
scala.concurrent.Await.result(fut2, 5 seconds)
warning: there was one feature warning; re-run with -feature for details
fut2: Any = scala.concurrent.impl.Promise$DefaultPromise@61ab71c2
Run Code Online (Sandbox Code Playgroud)
如果fut1结果不准确,有没有办法可以选择返回fut2?
编辑: 第二个未来必须使用第一个未来继续api调用.这就是我到目前为止所拥有的.
val fut1 = Future("queryFirst")
val fut2 = fut1 flatMap {
case y if y.isInstanceOf[Int] => Future("queryAgainWithResult(y)")
case x => Future(x)
}
Run Code Online (Sandbox Code Playgroud)