当我们处理本地文件时,我试图做的事情相当简单,但当我试图用远程URL这样做时,问题就来了。

基本上,我试图从一个URL提取的文件创建一个PIL图像对象。当然,我总是可以只获取URL并将其存储在临时文件中,然后将其打开到一个图像对象中,但这感觉非常低效。

以下是我所拥有的:

Image.open(urlopen(url))

它抱怨seek()不可用,所以我尝试了这个:

Image.open(urlopen(url).read())

但这也不管用。是否有更好的方法来做到这一点,或者写入临时文件是做这类事情的公认方法?

这是运行wget最简单的例子:

wget http://www.example.com/images/misc/pic.png

但是如何使wget跳过下载if pic。已经有Pngis了?

PIL在我的系统中支持JPEG。

每当我做一个上传,我的代码失败:

File "PIL/Image.py", line 375, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available

我该如何解决这个问题?

我只有分支主和我得到这个错误,每次我尝试“git拉”:

error: Couldn't set refs/remotes/origin/master
From /var/lib/git/xxx/project
 ! a0f80ea..49177a3  master     -> origin/master  (unable to update local ref)

当我执行“git pull origin master”时,我得到:

error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.

我一直在寻找,却找不到原因

最近我读了很多关于函数式编程的东西,大部分我都能理解,但有一件事我就是搞不懂,那就是无状态编码。在我看来,通过删除可变状态来简化编程就像通过删除仪表盘来“简化”一辆汽车:最终产品可能更简单,但希望它能与最终用户交互。

几乎我能想到的每个用户应用程序都将状态作为核心概念。如果你写了一个文档(或一个SO post),状态会随着每一个新的输入而改变。或者如果你玩电子游戏,会有大量的状态变量,从所有角色的位置开始,这些角色往往会不断移动。如果不跟踪不断变化的值,您怎么可能做任何有用的事情呢?

每次我发现一些讨论这个问题的东西,它都是用真正的技术函数语言写的,假设我没有浓厚的FP背景。有谁知道如何向那些对命令式编码有很好的、扎实的理解,但在函数方面完全是n00b的人解释这一点吗?

编辑:到目前为止,一堆回复似乎试图让我相信不可变值的优点。我懂你的意思。这很有道理。我不明白的是,在没有可变变量的情况下,如何跟踪必须不断变化的值。

EDIT (2/19/21): A lot of time has elapsed since I asked this original question years ago and I've seen a flurry of activity since then. I re-selected an answer which I think is consistent with the most localized and safe option for solving this issue (which is typically associated with docker-compose). While docker did introduce the prune command, it is generally a dangerous operation and I would be cautious about using it as you may unintentionally impact other applications or setups you have on your machine


我在使用Docker 1.9.1删除Docker卷时遇到了一些问题。

我已经删除了所有停止的容器,因此docker ps -a返回空。

当我使用docker卷ls时,我得到了一大堆docker容器:

docker volume ls
DRIVER              VOLUME NAME
local               a94211ea91d66142886d72ec476ece477bb5d2e7e52a5d73b2f2f98f6efa6e66
local               4f673316d690ca2d41abbdc9bf980c7a3f8d67242d76562bbd44079f5f438317
local               eb6ab93effc4b90a2162e6fab6eeeb65bd0e4bd8a9290e1bad503d2a47aa8a78
local               91acb0f7644aec16d23a70f63f70027899017a884dab1f33ac8c4cf0dabe5f2c
local               4932e2fbad8f7e6246af96208d45a266eae11329f1adf176955f80ca2e874f69
local               68fd38fc78a8f02364a94934e9dd3b5d10e51de5b2546e7497eb21d6a1e7b750
local               7043a9642614dd6e9ca013cdf662451d2b3df6b1dddff97211a65ccf9f4c6d47
#etc x 50

由于这些卷都不包含任何重要的内容,我尝试使用docker卷rm $(docker卷ls -q)清除所有卷。

在这个过程中,大部分都被删除了,但我得到了:

Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use

他们中的很大一部分人。如果我一开始就没有任何容器存在,那么如何使用这些卷呢?

在使用Java 8可选类时,有两种方法可以将值包装在可选类中。

String foobar = <value or null>;
Optional.of(foobar);         // May throw NullPointerException
Optional.ofNullable(foobar); // Safe from NullPointerException

我明白可选的。ofNullable是唯一安全的使用Optional的方式,但是为什么Optional。存在吗?为什么不直接使用Optional呢?nullable和在任何时候都是安全的?

我发现在Windows的命令行中工作令人沮丧,主要是因为与linux和OS X上的“rxvt”、“xterm”或“terminal”等终端应用程序相比,控制台窗口使用起来很糟糕。主要的投诉:

No standard copy/paste. You have to turn on "mark" mode and it's only available from a multi-level popup triggered by the (small) left hand corner button. Then copy and paste need to be invoked from the same menu You can't arbitrarily resize the window by dragging, you need to set a preference (back to the multi-level popup) each time you want to resize a window You can only make the window so big before horizontal scroll bars enter the picture. Horizontal scroll bars suck. With the cmd.exe shell, you can't navigate to folders with \\netpath notation (UNC?), you need to map a network drive. This sucks when working on multiple machines that are going to have different drives mapped

是否有任何技巧或应用程序(付费或其他)可以解决这些问题?

我今天开始使用vimdiff,并想做一些我在基于Windows的差异编辑器上认为理所当然的事情(比如展开/折叠一个差异部分,有完整的文件展开/只有差异,上面或下面有三个上下文行,等等)。我目前只知道以下命令:

键盘快捷键:

do -获取从其他窗口到当前窗口的更改。 dp -将当前窗口的更改放入另一个窗口。 c -跳转到下一个更改。 [c -跳转到之前的更改。 Ctrl+W, W -切换到另一个分割窗口(Ctrl +W, Ctrl+W做同样的事情,以防你稍后放开Ctrl键)

有人能给我指出正确的方向吗?这样我就可以复制类似的功能了。

例如,如果我能围绕差分展开/折叠直线,那就太好了。

当使用grep时,它将突出显示一行中与正则表达式匹配的任何文本。

如果我想要这种行为,但有grep打印出所有行以及?在快速浏览了grep手册页后,我一无所获。