如何使用Mongoid和Ruby查询日期范围(比如说从现在开始的最近30天)?
我需要最终得到如下所示的数组或哈希:
{
15 => 300,
14 => 23,
13 => 23
...
30 => 20 # Goes over into previous month
28 => 2
}
Run Code Online (Sandbox Code Playgroud)
我目前正在使用DateTime实例以及unix时间戳整数字段存储每个文档.
上述哈希中的键是天数,值是这些天的所有销售额的总和.
有任何想法吗?
如果这是一个noob问题,请原谅我:
我有一个应用程序,用户可以在他们的个人资料中设置自己的时区.
当有人添加阵容(特定于应用程序的术语)时,我会执行以下操作:
time = ActiveSupport::TimeZone.new(user.timezone).parse(
"Wednesday, 26 October, 2011 13:30:00"
)
# This outputs: 2011-10-26 13:30:00 +0200 - valid according to the user selected TZ
Run Code Online (Sandbox Code Playgroud)
然后我保存了阵容:
Lineup.create({
:date => time.gmtime,
:uid => user._id,
:pid => product._id
})
Run Code Online (Sandbox Code Playgroud)
这应该(理论上)将日期保存为gmtime,但在查看记录时我会得到以下信息:
{
"_id": ObjectId("4e9c6613e673454f93000002"),
"date": "Wed, 26 Oct 2011 13: 30: 00 +0200",
"uid": "4e9b81f6e673454c8a000001",
"pid": "4e9c6613e673454f93000001",
"created_at": "Mon, 17 Oct 2011 19: 29: 55 +0200"
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,日期字段错误 - 它仍然保持用户时区,它应该是GMT,而不是特定于时区.
如果我输出time.gmtime,我会得到正确的时间(应该保存):
2011-10-26 11:30:00 UTC (correct)
Run Code Online (Sandbox Code Playgroud)
有任何想法如何保存GMT日期,以便它实际保存GMT日期?
I have a large rails app converted successfully to use JRuby and it runs locally without any issues bundle exec rails s -b 0.0.0.0
.
I'm now trying to create a deployable WAR file using the following:
bundle exec warble executable war
This completes successfully without errors, but when running it with:
java -jar application.war
It boots up and then after a few seconds, it spits out this error:
2016-06-28 11:48:16.544:INFO::main: Logging initialized @228ms
2016-06-28 11:48:16.553:INFO:oejr.Runner:main: Runner
2016-06-28 11:48:16.698:INFO:oejs.Server:main: jetty-9.2.9.v20150224 …
Run Code Online (Sandbox Code Playgroud) 好吧,这让我疯了.
我正在尝试创建一个简单的AWS S3客户端,它允许与S3进行基本交互,但似乎我做错了什么并且无法弄清楚它是什么.它可能很明显,但我没有看到它.
我的密钥是正确的并且已经过测试 - 没有尾随空格等.
问题似乎与签名有关,它不断得到' 我们计算的请求签名与您提供的签名不匹配.从Amazon的REST API 检查您的密钥和签名方法错误.我创建了各种类别,添加了base64,HMAC SHA1生成功能,我还查看了各种在线示例,但到目前为止还没有成功.
不使用亚马逊提供的库的原因是因为它针对的是Cocoa Touch,我不想破解它以使其适用于Cocoa.
您可以在此处获取所有文件/代码的副本:https://www.dropbox.com/s/8ts9q71dz3uopxp/S3Lite.zip
然而,我关注亚马逊关于身份验证的文档,而且简单地说,一切都正确完成.
这是我如何生成签名:
-(NSString *)signRequest:(NSURLRequest *)request {
NSMutableString *sig = [[NSMutableString alloc] init];
// Request Method
[sig appendFormat:@"%@\n", [request HTTPMethod]];
// Content MD5
[sig appendFormat:@"%@\n", [[request HTTPBody] MD5String]];
// Content Type
[sig appendFormat:@"%@\n", [request valueForHTTPHeaderField:@"Content-Type"]];
// Date
[sig appendFormat:@"%@\n", [request valueForHTTPHeaderField:@"Date"]];
// Canonicalized Headers
[sig appendFormat:@"%@\n", @""]; // Empty for now
// Canonicalized Resource
[sig appendFormat:@"%@", [NSString stringWithFormat:@"/%@%@", _bucket, request.URL.path]];
NSString *encodedString …
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建NDK兼容代码(可以工作并且已经过测试),但是我在构建过程中遇到以下错误:
[armeabi-v7a] Compile thumb : cpufeatures <= cpu-features.c
/Users/sean/Library/Android/sdk/ndk-bundle/sources/android/cpufeatures/cpu-features.c: In function 'get_elf_hwcap_from_proc_self_auxv':
/Users/sean/Library/Android/sdk/ndk-bundle/sources/android/cpufeatures/cpu-features.c:534:5: warning: implicit declaration of function 'typeof' [-Wimplicit-function-declaration]
int fd = TEMP_FAILURE_RETRY(open(filepath, O_RDONLY));
^
In file included from /Users/sean/Library/Android/sdk/ndk-bundle/platforms/android-14/arch-arm/usr/include/fcntl.h:34:0,
from /Users/sean/Library/Android/sdk/ndk-bundle/sources/android/cpufeatures/cpu-features.c:75:
/Users/sean/Library/Android/sdk/ndk-bundle/platforms/android-14/arch-arm/usr/include/unistd.h:207:18: error: expected ';' before '_rc'
typeof (exp) _rc; \
^
/Users/sean/Library/Android/sdk/ndk-bundle/sources/android/cpufeatures/cpu-features.c:534:14: note: in expansion of macro 'TEMP_FAILURE_RETRY'
int fd = TEMP_FAILURE_RETRY(open(filepath, O_RDONLY));
^
/Users/sean/Library/Android/sdk/ndk-bundle/platforms/android-14/arch-arm/usr/include/unistd.h:209:9: error: '_rc' undeclared (first use in this function)
_rc = (exp); \
^
/Users/sean/Library/Android/sdk/ndk-bundle/sources/android/cpufeatures/cpu-features.c:534:14: note: in expansion of macro 'TEMP_FAILURE_RETRY'
int fd …
Run Code Online (Sandbox Code Playgroud) 我已经将Neo4j 3.0.1嵌入到Java 8应用程序中,但我一直遇到SPI问题.
从IntelliJ内部运行会产生预期的正确结果,但是一旦我将工件构建到JAR,运行它并尝试写入Neo4j,我得到以下异常:
Caused by: org.neo4j.kernel.impl.store.UnderlyingStorageException: java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'BlockTreeOrds' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classpath supports the following names: [Lucene50]
at org.neo4j.kernel.impl.transaction.command.LabelUpdateWork.apply(LabelUpdateWork.java:62)
at org.neo4j.kernel.impl.transaction.command.LabelUpdateWork.apply(LabelUpdateWork.java:33)
at org.neo4j.concurrent.WorkSync.doSynchronizedWork(WorkSync.java:121)
at org.neo4j.concurrent.WorkSync.apply(WorkSync.java:90)
at org.neo4j.kernel.impl.transaction.command.IndexBatchTransactionApplier.close(IndexBatchTransactionApplier.java:105)
at org.neo4j.kernel.impl.api.BatchTransactionApplierFacade.close(BatchTransactionApplierFacade.java:70)
at org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine.apply(RecordStorageEngine.java:336)
at org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess.applyToStore(TransactionRepresentationCommitProcess.java:78)
... 25 more
Run Code Online (Sandbox Code Playgroud)
似乎没有异常启动Neo4j所以我假设某些依赖关系没有通过Maven构建解决.
我的pom.xml
文件中有以下内容:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.0.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version> …
Run Code Online (Sandbox Code Playgroud)