这很好用
val l = List(1,2,3)
l.flatMap(x => List(x))
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
l.flatMap(List)
Run Code Online (Sandbox Code Playgroud)
这也不起作用:
l.flatmap(List.apply _)
Run Code Online (Sandbox Code Playgroud)
有没有人有这个想法?谢谢!
在模块的源代码中Future
,我看到了这样的定义onComplete
:
/** When this future is completed, either through an exception, or a value,
* apply the provided function.
*
* If the future has already been completed,
* this will either be applied immediately or be scheduled asynchronously.
*
* $multipleCallbacks
* $callbackInContext
*/
def onComplete[U](@deprecatedName('func) f: Try[T] => U)(implicit executor: ExecutionContext): Unit
Run Code Online (Sandbox Code Playgroud)
这看起来很奇怪,因为它没有函数体(没有实现).那么为什么要这么做onComplete
呢?它是用Java实现的吗?我怎样才能找到真正的实现代码?
DOM 看起来像这样:
<body>
<div>A</div>
<div>B</div>
<div>C</div>
<div id="selected">D</div>
<div>E</div>
<div>F</div>
<div>G</div>
</body>
Run Code Online (Sandbox Code Playgroud)
现在我可以选择<div id="selected">D</div>
using $("div#selected")
,那么如何选择它之前的元素,即<div>C</div>
.
有没有人对此有想法?
这是一个例子:
p, span, div,img {
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<p>Para</p>
<span>Span</span>
<div>Div</div>
<img src="https://www.google.com/images/nav_logo195.png" />
<div><img src="https://www.google.com/images/nav_logo195.png" /></div>
Run Code Online (Sandbox Code Playgroud)
我发现适用text-align: center
于img
直接不起作用.
这是否意味着div
当需要居中图像时必须将其包裹在空?
有一个更好的方法吗?
这是我的代码(coffeescript):
toVoice = new Audio("myVoice.mp3")
toVoice.addEventListener("ended", ->console.log("ended"))
toVoice.addEventListener("error", ->console.log("error"))
toVoice.addEventListener("success", ->console.log("success"))
toVoice.addEventListener("ready", ->console.log("ready"))
Run Code Online (Sandbox Code Playgroud)
我想在以下情况下显示一条消息:
我发现ended
and error
eventListener 工作得很好,但是success
and ready
eventListener 不起作用。
我试图找到一份关于Audio
标签/对象的所有可用事件的 MDN 文档,但我没有找到。
有谁知道如何注册回调来检测音频是否有效且可播放?
我正在使用Nginx 1.9.2,以下是我的配置
upstream httpserver0{
server 127.0.0.1:35011 max_fails=3 fail_timeout=30s; #H_server0
}
server {
listen 443 ssl;
listen 80;
server_name 11.22.33.44; #my_server_name
etag on;
location ~* \.(ts|raw)$ {
set $server_id "0";
if ( $uri ~ ^/(.*cfs+)/(.*)$ ){
set $server_id $1;
}
if ( $server_id = "4cfs" ){
proxy_pass http://httpserver0$request_uri;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用上游模块和proxy_pass进行反向代理,我etag on
在服务器块内启用了etag功能.
但是,当我检查HTTP响应的标头时,我根本找不到该etag
字段.
有没有人有这个想法?谢谢!
以下是本机Javascript代码:
var first = Promise.resolve(1);
first.then((i)=>console.log(1))
Run Code Online (Sandbox Code Playgroud)
当我first
在Chrome的控制台中检查时,它显示其状态为"已解决"
> first
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: 1}
Run Code Online (Sandbox Code Playgroud)
但是,当我first.then((i)=>console.log(1))
在Chrome的控制台中检查时,它显示其状态为"待定"
> first.then((i)=>console.log(1))
1
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
Run Code Online (Sandbox Code Playgroud)
这看起来让我感到困惑,因为我期望它first.then((i)=>console.log(1))
具有状态,resolved
因为then
方法中的回调已经执行并完成.
有没有人有这个想法?
可能重复:
使用Python获取Wikipedia文章
>>> print urllib2.urlopen('http://zh.wikipedia.org/wiki/%E6%AF%9B%E6%B3%BD%E4%B8%9C').read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 400, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 438, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 521, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error …
Run Code Online (Sandbox Code Playgroud) 这是代码(也在这里):
#lang racket
(define poorY
((lambda length
(lambda (ls)
(cond
[(null? ls) 0]
[else (add1 ((length length) (cdr ls)))])))
(lambda length
(lambda (ls)
(cond
[(null? ls) 0]
[else (add1 ((length length) (cdr ls)))])))))
Run Code Online (Sandbox Code Playgroud)
当我运行它:
> (poorY '(9 7 8))
. . application: not a procedure;
expected a procedure that can be applied to arguments
given: '(#<procedure>)
arguments...:
'(#<procedure>)
Run Code Online (Sandbox Code Playgroud)
屏幕截图如下所示:
我正在使用DrRacket作为代表.代码有什么问题?
scheme functional-programming combinators y-combinator racket
在Pyramid中,通过GET发送请求可以通过创建URL来完成,如下所示:
@view_config(route_name="test")
def test(request):
return HTTPFound("http://test.com/redirect_to_another_test?a=1")
Run Code Online (Sandbox Code Playgroud)
但似乎HTTPFound
POST无法做到这一点,那我该怎么做呢?有没有人有这个想法?谢谢!
javascript ×3
css ×2
html ×2
python ×2
scala ×2
akka ×1
alignment ×1
asynchronous ×1
audio ×1
combinators ×1
concurrency ×1
css3 ×1
dom-events ×1
ecmascript-6 ×1
etag ×1
future ×1
http ×1
https ×1
jquery ×1
monads ×1
networking ×1
nginx ×1
promise ×1
pyramid ×1
racket ×1
scheme ×1
wikipedia ×1
y-combinator ×1