我想在SBT中的"测试"和"它"配置之间分享一个帮助特征,但我还没弄明白如何.
这是一个最小的例子:
项目/ Build.scala
import sbt._
import Keys._
object MyBuild extends Build {
val scalaTest = "org.scalatest" %% "scalatest" % "2.0" % "test,it"
lazy val myProject =
Project(id = "my-project", base = file("."))
.configs(IntegrationTest)
.settings(Defaults.itSettings: _*)
.settings(
scalaVersion := "2.10.3",
libraryDependencies ++= Seq(
scalaTest
)
)
}
Run Code Online (Sandbox Code Playgroud)
的src /测试/阶/ Helpers.scala
trait Helper {
def help() { println("helping.") }
}
Run Code Online (Sandbox Code Playgroud)
的src /测试/阶/ TestSuite.scala
import org.scalatest._
class TestSuite extends FlatSpec with Matchers with Helper {
"My code" should "work" in {
help() …Run Code Online (Sandbox Code Playgroud) 编辑:tl; dr - 此问题似乎仅限于一小组 OS /编译器/库组合,现在由于@JonathanWakely而在GCC Bugzilla中作为Bug 68921进行跟踪.
我正在等待未来,我注意到top显示100%的CPU使用率并strace显示稳定的futex呼叫流:
...
[pid 15141] futex(0x9d19a24, FUTEX_WAIT, -2147483648, {4222429828, 3077922816}) = -1 EINVAL (Invalid argument)
...
Run Code Online (Sandbox Code Playgroud)
这是在Linux 4.2.0(32位i686)上,使用gcc 5.2.1版编译.
这是我最不可行的示例程序:
#include <future>
#include <iostream>
#include <thread>
#include <unistd.h>
int main() {
std::promise<void> p;
auto f = p.get_future();
std::thread t([&p](){
std::cout << "Biding my time in a thread.\n";
sleep(10);
p.set_value();
});
std::cout << "Waiting.\n";
f.wait();
std::cout << "Done.\n";
t.join(); …Run Code Online (Sandbox Code Playgroud) Mail multipart/alternative vs multipart/mixed的答案表明附件应该是multipart/alternative消息的对等,如:
我想发送带有一些内嵌图像和纯文本替代品的html部分的电子邮件.各个部分的首选MIME布局是什么?在示例代码和其他问题中出现了几个选项,但哪些选项在实践中效果最好?我倾向于这样:
这样,图像显然是为了渲染html部分.一个完整的例子是:
From: Rich Example <rich-example@example.org>
To: A Recipient <recipient@example.org>
Subject: An example of email with images and a plain alternative
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="outer-boundary"
This is a MIME-encoded message. If you are seeing this, your mail
reader is old.
--outer-boundary
Content-Type: text/plain; charset=us-ascii
This message might make you :) or it might make you :( …Run Code Online (Sandbox Code Playgroud) 也就是说,你能发送吗?
{
"registration_ids": ["whatever", ...],
"data": {
"foo": {
"bar": {
"baz": [42]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者是GCM请求的"数据"成员是否仅限于一个级别的键值对?我问b/c谷歌的文档[1]中的措辞暗示了限制,其中"数据"是:
一个JSON对象,其字段表示消息的有效负载数据的键值对.如果存在,有效载荷数据将作为应用程序数据包含在Intent中,其中键是额外的名称.例如,"data":{"score":"3x1"}会产生一个额外的意图得分,其值为字符串3x1对键/值对的数量没有限制,尽管有一个限制邮件的总大小.可选的.
[1] http://developer.android.com/guide/google/gcm/gcm.html#request
我有一个任务lazy val task = TaskKey[Unit],需要lazy val setting = SettingKey[String]输入.我也有三种不同的,独立的配置范围(config("dev"),config("stage"),config("prod"))和build.sbt指定的不同值的文件setting为每个配置的作用域(的setting in stage := "foo"...).
我期望task使用配置范围前缀进行调用会使任务使用来自相应配置范围的值(例如 >dev:task,将使任务使用setting来自的值dev,使用命令>stage:task将使任务使用setting来自stage... 的值).但是,这似乎不起作用.
如何强制task使用特定配置范围中的设置?
build.sbt:
setting := "default setting"
setting in stage := "stage setting"
setting in prod := "prod setting"
Run Code Online (Sandbox Code Playgroud)
Build.scala:
import sbt._
import Keys._
object TaskBuild extends Build {
val setting = SettingKey[String]("setting", "a …Run Code Online (Sandbox Code Playgroud) 我刚刚发现了std::shared_ptr"别名构造函数"并发现自己在问"为什么std :: unique_ptr没有相应的一个?
也就是说,如果你想分配一个Foo你可以把它的Bar成员传递给一个应该完全管理它的生命周期的函数Foo,那么能不能这样做吗?
#include <memory>
struct B {}
struct A {
B b;
}
void f(std::unique_ptr<B> b);
std::unique_ptr<A> a = std::make_unique<A>();
std::unique_ptr<B> b { std::move(a), &(a->b) }; // a now invalid.
f(std::move(b)); // f now responsible for deleting the A.
Run Code Online (Sandbox Code Playgroud)
这适用于std :: shared_ptr(http://ideone.com/pDK1bc)
#include <iostream>
#include <memory>
#include <string>
struct B {
std::string s;
};
struct A {
B b;
A(std::string s) : b{s} {};
~A() { std::cout << …Run Code Online (Sandbox Code Playgroud) 所以NGINX对我的rails应用程序非常有用 - 但是希望能帮助一个混合的静态/动态环境正确配置.这是一个API,所以基本上:
现在我知道我的位置/ try_files等正在挤压彼此,但我已经尝试了一堆排列,并且无法让它们全部工作.:)
upstream ss-api { server unix:/tmp/ss-api.socket fail_timeout=0; }
server {
listen 80 default deferred;
server_name localhost;
access_log /var/log/nginx/api_access.log;
location {
root /home/deployer/apps/api/current/public;
try_files $uri/index.html $uri.html $uri @ss-api;
}
location /doc/ {
root /home/deployer/apps/ss-api/current/doc;
}
location @ss-api {
proxy_pass http://ss-api;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 4G;
client_body_buffer_size 128k;
keepalive_timeout 5;
error_page 500 502 503 504 /500.html;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 …Run Code Online (Sandbox Code Playgroud) 我有兴趣构建未压缩的jar文件,以便在只有少数类更改时使我的rsync更快,到目前为止,我无法弄清楚如何告诉sbtassembly禁用压缩.
server > inspect assembly
[info] Task: java.io.File
[info] Description:
[info] Builds a single-file deployable jar.
[info] Provided by:
[info] {file:/.../}server/*:assembly
[info] Dependencies:
[info] server/*:assembly-merge-strategy(for assembly)
[info] server/*:assembly-output-path(for assembly)
[info] server/*:package-options(for assembly)
[info] server/*:assembly-assembled-mappings(for assembly)
[info] server/*:cache-directory
[info] server/*:test(for assembly)
[info] server/*:streams(for assembly)
[info] Delegates:
[info] server/*:assembly
[info] {.}/*:assembly
[info] */*:assembly
Run Code Online (Sandbox Code Playgroud)
...
server > inspect assembly-option(for assembly)
[info] Setting: sbtassembly.AssemblyOption = AssemblyOption(true,true,true,<function1>)
[info] Description:
[info]
[info] Provided by:
[info] {file:/.../}server/*:assembly-option(for assembly)
[info] Dependencies:
[info] server/*:assembly-assemble-artifact(for package-bin)
[info] server/*:assembly-assemble-artifact(for …Run Code Online (Sandbox Code Playgroud) 看起来有两个用于运行ProGuard的SBT插件.任何人都可以谈论他们的相对优势和劣势吗?我还没有在网上找到比较.
我假设xsbt-proguard-plugin通常更成熟,但为什么SBT的人会自己动手?
当我注意到下面的代码没有编译时,我正在玩Scala,为什么?
case class A(a:Int) {
def getA: ()=>Int = () => a
def getAA()=a
def getAAA=a
}
object Test extends App{
val a =A(3)
def printInt(f:()=>Int)=println(f())
printInt(a.getA) // fine, prints 3
printInt(a.getAA) // fine, prints 3
printInt(a.getAAA) // this does not compile, why ?
}
Run Code Online (Sandbox Code Playgroud)
a.getA,a.getAA和a.getAAA有什么区别?
我使用mobiledetect将移动用户重定向到特定页面.但是,当我写这篇文章时,我收到致命错误redirect().任何人都可以让我知道我错过了哪里和什么?
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();
if ($detect->isMobile())
redirect('iammobile.php');
else
echo '<h1>I am Desktop</h1>';
Run Code Online (Sandbox Code Playgroud)