使用 Jupyter Notebook,我可以创建一个动画图(基于此示例代码):
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def init():
line.set_ydata([np.nan] * len(x))
return line,
def animate(i):
line.set_ydata(np.sin(x + i / 100)) # update the data.
return line,
ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=2, blit=True, save_count=50)
plt.show()
Run Code Online (Sandbox Code Playgroud)
是否可以在 Visual Studio Code 的笔记本编辑器中执行此操作?我认为它涉及VS Code似乎不支持的魔术%matplotlib notebook
模式,但我不知道是否有替代方案。
我有一个很长的视频,我想把它加速成延时。在FFmpeg wiki 之后,我想出了这个咒语:
ffmpeg -i IMG_0238.MOV -r 60 -ss 00:04:41 -filter:v "setpts=PTS/60.0" -an output.mp4
Run Code Online (Sandbox Code Playgroud)
它应该剪掉最初的几分钟,然后以 60 倍的速度创建一个新的 60fps 视频文件。
虽然它将我所有的 CPU 核心旋转到 100%,但状态栏只是显示frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
并且永远不会进展。
问题似乎与-ss 00:04:41
指定开始时间的标志有关;我想删除源视频的前 4 分 41 秒。当我省略此选项时,视频转换成功。
完整日志如下。
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.30)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
libavutil …
Run Code Online (Sandbox Code Playgroud) 该docker buildx build
命令接受一个--cache-to type=registry,ref=my/repo:buildcache
将构建缓存推送到注册表的选项(一些文档)。
如何检查这个缓存?
docker buildx imagetools inspect my/repo:buildcache
由于空指针取消引用而崩溃。
docker manifest inspect my/repo:buildcache
触发 500 内部服务器错误。
Docker Hub 网站没有提供有关推送构建缓存标签的信息,只是它确实存在。
如果我使用对称--cache-from type=registry,ref=my/repo:buildcache
选项运行构建,它会打印importing cache manifest from my/repo:buildcache
,但我不知道它导入了什么。
我正在尝试获取钥匙串项的属性.此代码应查找所有可用属性,然后打印其标签和内容.
根据文档,我应该看到像'cdat'这样的标签,但它们只是看起来像一个索引(即,第一个标签是0,接下来是1).这使它变得毫无用处,因为我无法确定哪个属性是我正在寻找的属性.
SecItemClass itemClass;
SecKeychainItemCopyAttributesAndData(itemRef, NULL, &itemClass, NULL, NULL, NULL);
SecKeychainRef keychainRef;
SecKeychainItemCopyKeychain(itemRef, &keychainRef);
SecKeychainAttributeInfo *attrInfo;
SecKeychainAttributeInfoForItemID(keychainRef, itemClass, &attrInfo);
SecKeychainAttributeList *attributes;
SecKeychainItemCopyAttributesAndData(itemRef, attrInfo, NULL, &attributes, 0, NULL);
for (int i = 0; i < attributes->count; i ++)
{
SecKeychainAttribute attr = attributes->attr[i];
NSLog(@"%08x %@", attr.tag, [NSData dataWithBytes:attr.data length:attr.length]);
}
SecKeychainFreeAttributeInfo(attrInfo);
SecKeychainItemFreeAttributesAndData(attributes, NULL);
CFRelease(itemRef);
CFRelease(keychainRef);
Run Code Online (Sandbox Code Playgroud) Djangodjango.db.models.URLField
使用一个django.core.validators.URLValidator
:
class URLField(CharField):
default_validators = [validators.URLValidator()]
Run Code Online (Sandbox Code Playgroud)
因为它没有指定要接受的方案,所以 URLValidator 默认为这个集合:
schemes = ['http', 'https', 'ftp', 'ftps']
Run Code Online (Sandbox Code Playgroud)
我希望我的 URLField 接受ssh://
URL,所以我尝试了这个:
class SSHURLField(models.URLField):
'''URL field that accepts URLs that start with ssh:// only.'''
default_validators = [URLValidator(schemes=['ssh'])]
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用有效ssh://
URL保存新对象时,我被拒绝了。
如果我跳过从 URLField 继承并直接从 CharField 继承,也会发生这种情况:(编辑:实际上这在我重新创建数据库后确实有效。我不确定为什么前者不起作用。)
class SSHURLField(models.CharField):
'''URL field that accepts URLs that start with ssh:// only.'''
default_validators = [URLValidator(schemes=['ssh'])]
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 64
super(SSHURLField, self).__init__(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
当我在测试中直接使用 URLValidator 时,它可以工作:
def test_url(url):
try: …
Run Code Online (Sandbox Code Playgroud) 给定这个GeoJSON文件,我想渲染一个ASCII艺术世界地图。
我的基本方法是将GeoJSON加载到Shapely中,使用pyproj将点转换为Mercator,然后对ASCII艺术网格的每个字符的几何形状进行命中测试。
当将本初子午线居中时,它看起来(编辑:主要是)可以:
但以纽约市(lon_0=-74
)为中心,却突然陷入困境:
我相当确定我对这里的预测做错了。(将ASCII映射坐标转换为纬度/经度可能比转换整个几何图形更有效,但我不确定如何。)
import functools
import json
import shutil
import sys
import pyproj
import shapely.geometry
import shapely.ops
# Load the map
with open('world-countries.json') as f:
countries = []
for feature in json.load(f)['features']:
# buffer(0) is a trick for fixing polygons with overlapping coordinates
country = shapely.geometry.shape(feature['geometry']).buffer(0)
countries.append(country)
mapgeom = shapely.geometry.MultiPolygon(countries)
# Apply a projection
tform = functools.partial(
pyproj.transform,
pyproj.Proj(proj='longlat'), # input: WGS84
pyproj.Proj(proj='webmerc', lon_0=0), # output: Web Mercator …
Run Code Online (Sandbox Code Playgroud) 我希望这会返回一个Date
表示从现在开始一小时后的时间的对象:
Calendar.current.date(byAdding: DateComponents(hour: 1), to: Date())
Run Code Online (Sandbox Code Playgroud)
然而它又回来了nil
。这似乎是 API 的相当简单的使用,所以也许我对这个 API 应该如何工作有一些基本的误解?
这似乎只影响swift
Xcode 附带的命令行 REPL(macOS Catalina 10.15.3 上的版本 11.3.1)。
有趣的是,将上述代码包装在print()
调用中会强制它打印正确的结果。那么为什么会显示呢nil
?
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.3.0
Run Code Online (Sandbox Code Playgroud) 当我运行时singularity exec foo.simg whoami
,我从主机获取自己的用户名,这与在 Docker 中我获取root
或容器指定的用户不同。
如果我查看/etc/passwd
这个 Singularity 容器的内部,就会发现已为我的主机用户 ID 添加了一个条目/etc/passwd
。
如果我不知道程序运行时的用户 ID,如何制作便携式 Singularity 容器?
我已将 Docker 容器转换为 Singularity 映像,但它希望作为它定义的特定用户 ID 运行,并且已将多个目录chown
分配给该用户。当我在 Singularity 下运行它时,我的主机用户无权访问这些目录。
这将是一个黑客,但我可以修改所有这些目录的图像chmod 777
。有没有更好的方法让这个图像像任何用户一样在 Singularity 上工作?
(我正在运行 Singularity 2.5.2。)
我有Paramiko的包装纸SSHClient.exec_command()
.我想捕捉标准.这是我的函数的缩短版本:
def __execute(self, args, sudo=False, capture_stdout=True, plumb_stderr=True,
ignore_returncode=False):
argstr = ' '.join(pipes.quote(arg) for arg in args)
channel = ssh.get_transport().open_session()
channel.exec_command(argstr)
channel.shutdown_write()
# Handle stdout and stderr until the command terminates
captured = []
def do_capture():
while channel.recv_ready():
o = channel.recv(1024)
if capture_stdout:
captured.append(o)
else:
sys.stdout.write(o)
sys.stdout.flush()
while plumb_stderr and channel.recv_stderr_ready():
sys.stderr.write(channel.recv_stderr(1024))
sys.stderr.flush()
while not channel.exit_status_ready():
do_capture()
# We get data after the exit status is available, why?
for i in xrange(100):
do_capture()
rc = channel.recv_exit_status()
if not ignore_returncode …
Run Code Online (Sandbox Code Playgroud) 在我的 Django 应用程序中,我有一个 Attribute 模型,它与一个 MeasurementMethod 模型具有多对多关系。
我在 Attribute 的管理界面中为 MeasurementMethod 内联了一个内联,但我认为有一个单独的界面来管理 MeasurementMethods 根本没有用;没有理由用户会说,“哎呀,我想知道什么属性可以通过排水量来衡量。”
然而,在我找到Anton Belonovich 的帖子之前,这没有办法从内联编辑器创建新的 MeasurementMethods ,它说我需要admin.site.register(MeasurementMethod)
首先。我这样做了,果然出现了编辑和创建按钮。
但是现在在管理页面上,有一个应用程序列表和可以管理的模型,有一个我不想要的 MeasurementMethod 条目。
有没有办法摆脱它?或者有没有更好的方法来实现这一点?
我想要一个 shell 脚本来检查特定容器是否正在运行。
例如,如果容器尚未运行,我可能想要启动该容器,或者查询有关它的一些信息,例如公开了哪些端口。
AVCaptureMovieFileOutput
当我的应用程序启动时,我试图使用将设备摄像头录制到视频文件中。令我非常沮丧的是,我无法让它工作:
我可以AVCaptureVideoPreviewLayer
很好地查看视频源,所以我的会话连接正确。
它将输出到的文件尚不存在,并且位于可写目录中。
API 调用或AVCaptureSessionRuntimeError
通知未返回任何错误。
我的AVCaptureFileOutputRecordingDelegate
方法根本没有被调用。
我在示例代码之后尝试了示例代码,更令人抓狂的是其中一些似乎确实有效。
在 CMake 中,可以使用默认情况下add_subdirectory(foo EXCLUDE_FROM_ALL)
排除下面定义的目标,除非某些其他目标需要它们,如下所示:foo
add_subdirectory(foo EXCLUDE_FROM_ALL)
add_custom_target(wanted_foo_targets ALL DEPENDS
bar_tool # only build bar_tool from foo
)
Run Code Online (Sandbox Code Playgroud)
假设foo
定义了两个目标bar_tool
和foo_tool
,并对每个目标进行测试:
add_test(NAME test_foo_tool COMMAND foo_tool)
add_test(NAME test_bar_tool COMMAND bar_tool)
Run Code Online (Sandbox Code Playgroud)
当您构建整个项目时,foo_tool
不是构建,因为它不是任何东西的依赖项,而是bar_tool
构建,因为它是wanted_foo_targets
.
但 CTest 仍然注册该test_foo_tool
工具,但现在由于foo_tool
不存在而失败。
我可以删除/隐藏/跳过引用未构建的目标的测试吗?我知道我可以编写类似的测试命令,[ -f foo_tool ] && foo_tool
但这会错误地表明测试已通过。
如果我可以从父目录执行此操作,而不修改内部测试的设置方式,那就加分了foo
。就我而言,foo
这是一个由第三方提供的项目,我不想在他们编写新测试时维护他们的代码补丁。