我在Scala中做了一些编程,我知道,例如,
xs map f
Run Code Online (Sandbox Code Playgroud)
是一样的
xs.map(f)
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将这种语法概括为像ScalaTest的语法,例如,
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[String]
evaluating { emptyStack.pop() } should produce [NoSuchElementException]
}
Run Code Online (Sandbox Code Playgroud)
我主要想知道看起来像多字构造的东西,即should produce.它很整洁.
http://managedruntime.org/关于tarball中究竟是什么以及用户想要它们的原因非常稀少.http://lwn.net/Articles/392307/有更多细节,但作者也不确定内存管理模块实际上做了什么.显然,高级目标是减少GC暂停,但我会对(指针)模块的功能以及为什么/如何改进这些功能感兴趣.尤其令人敬畏的是指向这些补丁有多大影响的指针(评估).
在ScalaQuery中,我可以使用"原始"结果行:
for (
x <- queryNA[(String,Int)]("select * from foo")(
GetResult(r => (r.<<[String], r.<<[Int]))
)
) {
println(x)
}
Run Code Online (Sandbox Code Playgroud)
但这完全是位置的(r是a PositionedResult).有没有办法使用列名来处理结果?(例如,row.getString("foo").)
我可以使用另一个支持它的数据库API,比如Querulous,但我已经在我的代码中使用ScalaQuery进行类型安全查询,并且如果可能的话,我想坚持使用一个库.
在另一个问题中,我建议with在通常使用<:或使用的地方使用<:<.因此,不是以下列两种方式之一定义函数:
scala> def f[A,C <: Seq[A]](xs: C) = 0
f: [A, C <: scala.collection.immutable.Seq[A]](xs: C)Int
scala> f(List(1))
<console>:54: error: inferred type arguments [Nothing,List[Int]] do not conform to method f's type parameter bounds [A,C <: scala.collection.immutable.Seq[A]]
f(List(1))
^
scala> implicit def f[A,C](xs: C)(implicit ev: C <:< Seq[A]) = new { def foo = 0 }
f: [A, C](xs: C)(implicit ev: <:<[C,scala.collection.immutable.Seq[A]])java.lang.Object{def foo: Int}
scala> List(0) foo
<console>:54: error: Cannot prove that List[Int] <:< …Run Code Online (Sandbox Code Playgroud) 更新:使用normalize.css 添加了简单的测试示例http://jsfiddle.net/7UhrW/1/.
Chrome/WebKit和Firefox具有不同的渲染引擎,这些渲染引擎以不同的方式呈现字体,特别是具有不同的尺寸.这并不令人惊讶,但令人惊讶的是一些差异的严重程度.
我可以随时调整页面上的各个元素以使其更相似,但至少可以说这很乏味.我一直在寻找更系统的解决方案,但许多资源(例如SO答案)只是说"使用重置包".虽然我确信它修复了一些其他的东西,比如填充和间距,但它似乎对字体尺寸没有任何影响.
例如,如果我从http://html5reset.org/获取重置包,我可以显示相当大的差异(请注意检查员中显示的布局尺寸).[下面的图片实际上比在此答案中显示/调整大小更高 - 例如在Chrome中,您可以右键单击并在新标签中打开图像.
<h1 style="font-size:64px; background-color: #eee;">Article Header</h1>
Run Code Online (Sandbox Code Playgroud)

使用Helvetica,Chrome的高度更低.
<h1 style="font-size:64px; background-color: #eee; font-family: Helvetica">Article Header</h1>
Run Code Online (Sandbox Code Playgroud)

使用不同的字体,Chrome再次呈现更高的字体,但另外字母间距变得混乱(可能是由于字体的粗体化):
<style>
@font-face {
font-family: "MyriadProRegular";
src: url("fonts/myriadpro-regular-webfont.eot");
src: local("?"), url("fonts/myriadpro-regular-webfont.woff") format("woff"), url("fonts/myriadpro-regular-webfont.ttf") format("truetype"), url("fonts/myriadpro-regular-webfont.svg#webfonteknRmz0m") format("svg");
font-weight: normal;
font-style: normal; }
@font-face {
font-family: "MyriadProLight";
src: url("fonts/myriadpro-light-webfont.eot");
src: local("?"), url("fonts/myriadpro-light-webfont.woff") format("woff"), url("fonts/myriadpro-light-webfont.ttf") format("truetype"), url("fonts/myriadpro-light-webfont.svg#webfont2SBUkD9p") format("svg");
font-weight: normal;
font-style: normal; }
@font-face {
font-family: "MyriadProSemibold";
src: url("fonts/myriadpro-semibold-webfont.eot");
src: local("?"), url("fonts/myriadpro-semibold-webfont.woff") format("woff"), url("fonts/myriadpro-semibold-webfont.ttf") format("truetype"), url("fonts/myriadpro-semibold-webfont.svg#webfontM3ufnW4Z") …Run Code Online (Sandbox Code Playgroud) 我的表lead有一个索引:
\d lead
...
Indexes:
"lead_pkey" PRIMARY KEY, btree (id)
"lead_account__c" btree (account__c)
...
"lead_email" btree (email)
"lead_id_prefix" btree (id text_pattern_ops)
Run Code Online (Sandbox Code Playgroud)
为什么PG(9.1)不使用索引进行这种直接的平等选择?电子邮件几乎都是独一无二的....
db=> explain select * from lead where email = 'blah';
QUERY PLAN
------------------------------------------------------------
Seq Scan on lead (cost=0.00..319599.38 rows=1 width=5108)
Filter: (email = 'blah'::text)
(2 rows)
Run Code Online (Sandbox Code Playgroud)
其他索引命中查询似乎没问题(虽然我不知道为什么这个不只是使用pkey索引):
db=> explain select * from lead where id = '';
QUERY PLAN
------------------------------------------------------------------------------
Index Scan using lead_id_prefix on lead (cost=0.00..8.57 rows=1 width=5108)
Index Cond: (id = ''::text)
(2 rows) …Run Code Online (Sandbox Code Playgroud) 当我刚刚运行middleman服务时,all.css编译得很好,只需要调用+box-shadow(none):
/* line 1, /home/yang/asdf/source/stylesheets/content.css.sass */
div {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none; }
Run Code Online (Sandbox Code Playgroud)
但是当我构建网站时,我得到了这个Sass/Compass错误:
$ middleman build
Slim::EmbeddedEngine is deprecated, it is called Slim::Embedded in Slim 2.0
Slim::EmbeddedEngine is deprecated, it is called Slim::Embedded in Slim 2.0
Slim::EmbeddedEngine is deprecated, it is called Slim::Embedded in Slim 2.0
/home/yang/asdf/source/stylesheets/content.css.sass:2:in `box-shadow': Undefined mixin 'box-shadow'. (Sass::SyntaxError)
(in /home/yang/asdf/source/stylesheets/content.css.sass:2)
from /home/yang/asdf/source/stylesheets/content.css.sass:2
from /var/lib/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:253:in `visit_mixin'
from /var/lib/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `visit'
from /var/lib/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:100:in `visit'
from /var/lib/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
from …Run Code Online (Sandbox Code Playgroud) 在编写头库(如Boost)时,可以定义自由浮动(非方法)函数,而不会(1)膨胀生成的二进制文件和(2)产生"未使用"的警告吗?
当我在多个源文件中包含的头文件中定义一个函数时,该头文件又被链接到同一个二进制文件中,链接器会抱怨重新定义.解决这个问题的一种方法是使函数保持静态,但这会在每个翻译单元中重现代码(顺便说一句,链接器可以安全地重复这些吗?).此外,这会触发有关未使用函数的编译器警告.
我试图在Boost中寻找一个自由浮动函数的例子,但我找不到一个.是否包含类(或模板)中的所有内容?
我正在尝试基于scalatra-sbt.g8的以下内容:
class FooWeb extends ScalatraServlet with ScalateSupport {
beforeAll { contentType = "text/html" }
get("/") {
templateEngine.layout("/WEB-INF/scalate/templates/hello-scalate.jade")
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到以下异常(即使文件存在) - 任何线索?
Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?
org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?
Run Code Online (Sandbox Code Playgroud)
FWIW,最重要的例外是来自org.mortbay.jetty.handler.ContextHandler.getResource1142行:_baseResource==null.
下面,第一个案例成功,第二个案例失败.为什么我需要一个明确的证据类型/为什么这个Scala类型绑定失败?什么是类型推理器在解决这个问题时的特殊限制A?
scala> implicit def view[A, C](xs: C)(implicit ev: C <:< Iterable[A]) = new { def bar = 0 }
view: [A, C](xs: C)(implicit ev: <:<[C,scala.collection.immutable.Iterable[A]])java.lang.Object{def bar: Int}
scala> view(List(1)) bar
res37: Int = 0
scala> implicit def view[A, C <: Seq[A]](xs: C) = new { def bar = 0 }
view: [A, C <: scala.collection.immutable.Seq[A]](xs: C)java.lang.Object{def bar: Int}
scala> view(List(1)) bar
<console>:149: error: inferred type arguments [Nothing,List[Int]] do not conform to method view's type parameter bounds [A,C <: …Run Code Online (Sandbox Code Playgroud)