假设我在OSX上的端口8000上运行了一个服务器.我的Docker容器如何通过它访问它localhost:8000?我也无法更改主机名,因为容器中的应用程序不在我的控制范围内.
我已经阅读了之前关于使用--net="host"容器访问主机网络的讨论.但是,我在OSX和Docker在VM中运行,所以来自Docker容器的localhost--net="host"转到VM而不是我的真机.
然后我尝试了端口转发解决方法:VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port8000,tcp,,8000,,8000";无济于事.
任何建议将不胜感激.
从对另一个问题的评论中,有人说Clojure成语更喜欢返回nil而不是像Scheme中的空列表.这是为什么?
喜欢,
(when (seq lat) ...)
Run Code Online (Sandbox Code Playgroud)
代替
(if (empty? lat)
'() ...)
Run Code Online (Sandbox Code Playgroud) 这两个似乎在Clojure中做同样的事情.哪种语法是规范的?
(defn a ^int [] 4)
(defn b ^{:tag int} [] 4)
Run Code Online (Sandbox Code Playgroud)
我希望它是a因为它更短.
我有一堆路由并从 gin 开始gin.Default()(默认情况下为所有路由启用日志记录和恢复)。但是有一条路线(即/health)每 5 秒被 ping 一次。在不更改大部分代码的情况下禁用该路由的请求日志记录的直接方法是什么?
func main() {
// gin is initialized upstream in our internal framework
// so I can't change this line easily.
router := gin.Default()
router.GET("/someGet", getting)
router.POST("/somePost", posting)
router.PUT("/somePut", putting)
router.DELETE("/someDelete", deleting)
// ... and more
// Disable request logging for only this route.
// Note: I'm hoping that there's some parameter I can pass in here to do that
route.GET("/health", health)
router.Run()
}
Run Code Online (Sandbox Code Playgroud) 我正在学习Clojure使用教程并遇到像4clojure和99个lisp问题这样的问题.我解决问题很好,但我的代码似乎总是像下面的例子一样混乱.
对于像Clojure一样灵活的语言,初学者如何在不让其他人一直牵着的情况下学习惯用的方法?
我的烂摊子的一个例子:
(defn intersectall [lset]
(when-not (empty? (first lset))
(if (reduce #(and %1 %2) (map #(stars/member* (front lset) %) (rest lset)))
(cons (front lset) (intersectall (cons (rest (first lset)) (rest lset))))
(intersectall (cons (rest (first lset)) (rest lset))))))
Run Code Online (Sandbox Code Playgroud)
如果您想知道,该函数intersectall只返回所有输入子列表中的公共元素列表.
因此对于:
(def lset '((6 :pears :and)
(3 :peaches :and 6 :peppers)
(8 :pears :and 6 :plums)
(:and 6 :prunes :with some :apples)))
=> (intersectall lset)
(6 :and)
Run Code Online (Sandbox Code Playgroud)
这个问题来自The Little Schemer第117页.
我有一个 xts 对象,我用 to.period() 来“增加”周期以生成第二个 xts 对象。然后我将两个 xts 对象组合回了更快的时期。如何设置 cbind() 以便替换 NA(见下文)并填充最新值?
require(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)
x.wk <- to.weekly(x)
x2 <- cbind(x, x.wk[ , 4])
print(first(x2, "2 weeks"))
>head(x2)
Open High Low Close x.Close
2007-01-02 50.03978 50.11778 49.95041 50.11778 NA
2007-01-03 50.23050 50.42188 50.23050 50.39767 NA
2007-01-04 50.42096 50.42096 50.26414 50.33236 NA
2007-01-05 50.37347 50.37347 50.22103 50.33459 NA
2007-01-06 50.24433 50.24433 50.11121 50.18112 NA
2007-01-07 50.13211 50.21561 49.99185 49.99185 49.99185
2007-01-08 50.03555 50.10363 49.96971 49.98806 NA
2007-01-09 49.99489 49.99489 …Run Code Online (Sandbox Code Playgroud) 宏,transform!如下定义似乎适用=> (transform! ["foo" 1 2 3]).目的是获取一个列表,第一个元素是表示命名空间中的函数的字符串.然后包装到一切swap!.
问题是,在哪里transform!不起作用.我得到了这个神秘的例外:=> (transform! coll)(def coll ["foo" 1 2 3])
#<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: Symbol>
Run Code Online (Sandbox Code Playgroud)
功能:
(defmacro transform!
" Takes string input and update data with corresponding command function.
"
[[f & args]] ;; note double brackets
`(swap! *image* ~(ns-resolve *ns* (symbol f)) ~@args))
Run Code Online (Sandbox Code Playgroud)
我觉得很奇怪它适用于一个案例而不是另一个案例.