我最近偶然发现了Python的NotImplemented内置.经过一些阅读后,我确实得到了它的目的,但我不明白它为什么评估True为布尔值.下面的例子让我觉得这是一种残酷的玩笑:
>>> class A:
... def __eq__(self, other):
... return NotImplemented
...
>>>
>>> a = A()
>>> a == 1
False
>>> bool(a.__eq__(1))
True
Run Code Online (Sandbox Code Playgroud)
我的问题很简单:为什么要NotImplemented评价True?
假设我有以下类型:
interface Foo {
a?: string;
b: string;
}
Run Code Online (Sandbox Code Playgroud)
可以使用设置所有属性Required。
type Bar = Required<Foo>;
// Equivalent to
interface Bar {
a: string;
b: string;
}
Run Code Online (Sandbox Code Playgroud)
可以使用将所有属性设为可选Partial。
type Bar = Partial<Foo>;
// Equivalent to
interface Bar {
a?: string;
b?: string;
}
Run Code Online (Sandbox Code Playgroud)
我想做一个通用类型,而不是翻转所有属性的可选标志。
type Bar = Flip<Foo>;
// Equivalent to
interface Bar {
a: string;
b?: string;
}
Run Code Online (Sandbox Code Playgroud)
为实现Partial和Required相当简单明了,但这种Flip类型需要知道哪些属性Foo是可选的,这是必需的。是否可以使用泛型读取此修改内容?
一些背景:我相信这defaultProps在React 中将是有用的类型。
我有以下指令:
directive('myInput', function() {
return {
restrict: 'AE',
scope: {
id: '@',
label: '@',
type: '@',
value: '='
},
templateUrl: 'directives/dc-input.html',
link: function(scope, element, attrs) {
scope.disabled = attrs.hasOwnProperty('disabled');
scope.required = attrs.hasOwnProperty('required');
scope.pattern = attrs.pattern || '.*';
}
};
});
Run Code Online (Sandbox Code Playgroud)
使用以下模板:
<div class="form-group">
<label for="input-{{id}}" class="col-sm-2 control-label">{{label}}</label>
<div class="col-sm-10" ng-switch on="type">
<textarea ng-switch-when="textarea" ng-model="value" class="form-control" id="input-{{id}}" ng-disabled="disabled" ng-required="required"></textarea>
<input ng-switch-default type="{{type}}" ng-model="value" class="form-control" id="input-{{id}}" ng-disabled="disabled" ng-required="required" pattern="{{pattern}}"/>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
它由以下形式使用:
<form ng-controller="UserDetailsCtrl" role="form" class="form-horizontal">
<div ng-show="saved" class="alert alert-success">
The user …Run Code Online (Sandbox Code Playgroud) 我试图减少我的Android模拟器的荒谬的CPU使用率.
由于这个答案,我发现通过禁用音频可以大大降低CPU使用率.
我发现有三种方法可以在没有音频的情况下运行模拟器.
作为命令行标志:
$ emulator -avd <name> -noaudio
Run Code Online (Sandbox Code Playgroud)通过编辑~/.android/<name>.avd/config.ini和替换此行:
hw.audioInput=yes
Run Code Online (Sandbox Code Playgroud)
这两个:
hw.audioInput=no
hw.audioOutput=no
Run Code Online (Sandbox Code Playgroud)而不是使用图形AVD管理器,使用以下命令来创建模拟器:
$ android create avd -n <name> -t <target>
Run Code Online (Sandbox Code Playgroud)所有这些方法都有缺点.
-noaudio每次都需要传递旗帜.这意味着它无法从AVD管理器运行.config.ini 每次使用AVD管理器进行编辑时都会重置.我决定克隆现有设备并禁用那里的音频可能会有所帮助.
然而,这只是刚刚创建的~/.android/devices.xml,我无法解释如何默认禁用音频或任何ini包含硬件定义的文件.
是否可以创建默认情况下禁用声音的预定义硬件配置?如果是这样,怎么样?
我正在尝试创建一个吞吞吐吐的任务,该任务启动3个Browsersync实例,使用Protractor对它们运行端到端测试,然后很好地关闭Browsersync实例。
到目前为止,我已经提出了以下解决方案:
/**
* Run the end-to-end tests using Protractor.
*/
gulp.task('test:protractor', [
'serve:user',
'serve:bootstrap',
'serve:website'
], function(done) {
var protractor = spawn('protractor', [
path.resolve(__dirname, '..', 'protractor.conf.js'),
'--suite=bootstrap',
'--param.host.user', 'http://' + util.getDockerIp() + ':' + serve.userServer.getOption('port'),
'--param.host.bootstrap', 'http://' + util.getDockerIp() + ':' + serve.bootstrapServer.getOption('port'),
'--param.host.website', 'http://' + util.getDockerIp() + ':' + serve.websiteServer.getOption('port')
], {stdio: 'inherit'});
protractor.on('close', function(code) {
if (code) {
throw new Error(chalk.red('End-to-end tests failed'));
}
serve.userServer.exit();
serve.bootstrapServer.exit();
serve.websiteServer.exit();
done();
});
});
Run Code Online (Sandbox Code Playgroud)
这里的问题是xxxServer.exit()。此调用在process.exit()内部关闭整个NodeJS实例。这样,我无法很好地关闭每个服务器,而让gulp处理其余的服务器。
我找不到有关以其他任何方式关闭Browsersync的信息,因此我调查了该exit …
我正在尝试使用文件上传文件到Google云端存储gcloud-python并设置一些自定义元数据属性.为了尝试这个,我创建了一个简单的脚本.
import os
from gcloud import storage
client = storage.Client('super secret app id')
bucket = client.get_bucket('super secret bucket name')
blob = bucket.get_blob('kirby.png')
blob.metadata = blob.metadata or {}
blob.metadata['Color'] = 'Pink'
with open(os.path.expanduser('~/Pictures/kirby.png'), 'rb') as img_data:
blob.upload_from_file(img_data)
Run Code Online (Sandbox Code Playgroud)
我可以上传文件内容.上传文件后,我可以从开发者控制台手动设置元数据并检索它.
我无法弄清楚如何以编程方式上传元数据.
python google-cloud-storage gcloud-python google-cloud-python
我正在尝试拍照cordova-plugin-camera.我希望结果是一个File或一个Blob对象.
但是,destinationType必须是DATA_URL或之一FILE_URI.
文档说明:
DATAURL可能非常耗费内存,导致应用程序崩溃或内存不足错误.如果可能,请使用FILEURI或NATIVE_URI
但是,据我所知,将这样的文件uri转换为Blob需要执行以下步骤:
<img/Blob我发现很难相信这比使用效率更高DATAURL.所以我也可以使用DATAURL它并跳过步骤1-3.
有没有办法以Blob更有效的方式将照片作为对象拍摄?
我有一个 TypeScript mono 存储库,具有以下基本文件布局:
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 packages/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 workspace-a/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 workspace-b/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\nRun Code Online (Sandbox Code Playgroud)\n根tsconfig.json看起来像这样(删除了不相关的属性):
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 packages/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 workspace-a/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 workspace-b/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src/\n\xe2\x94\x82\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\nRun Code Online (Sandbox Code Playgroud)\ntsconfig.json每个包看起来像这样:
{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@scope/*": ["packages/*/src"]\n },\n "module": "es2020",\n "moduleResolution": "node"\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n所有包都使用@scope范围。此设置使以下代码可以workspace-a按预期工作:
{\n "extends": "../../tsconfig"\n}\nRun Code Online (Sandbox Code Playgroud)\n但是,以下代码也可以根据tscVSCode 中的自动导入首先工作并建议:
import …Run Code Online (Sandbox Code Playgroud) 我在nginx代理后面设置了一个pypiserver,它使用htpasswd进行身份验证.我目前能够上传sdists,但我无法弄清楚如何下载它们.我希望能够在运行时setup.py test以某种方式下载它们pip.这可能吗?
[distutils]
index-servers =
private
[private]
repository = https://example.com/pypi
username = remco
password = mypass
Run Code Online (Sandbox Code Playgroud)
为了使其更加困难,服务器当前正在使用未经验证的ssl连接.
我尝试了基于http://pythonhosted.org/setuptools/setuptools.html#setuptools-package-index的以下设置,但唯一的文档是'XXX'
#!/usr/bin/env python2.7
from setuptools import setup
setup(
name='asd',
version='0.0.1',
package_index='https://example.com/pypi/simple',
test_suite='test',
tests_require=['foo==0.0.1'])
Run Code Online (Sandbox Code Playgroud) 我目前skip_files在app.yaml中有以下内容:
skip_files:
- ^\..*
- ^.*\.(json|yaml)$
- ^Gruntfile\.js$
- ^bower_components
- ^node_modules
- ^src
- ^tests
- ^tmp
Run Code Online (Sandbox Code Playgroud)
这非常臃肿.实际上我只想添加一切到文件夹中的skip_files所有内容dist.
这可能吗?
我正在尝试用 AngularJS 编写一个 Markdown 编辑器。我正在使用 angular-markdown (AngularJS Showdown 包装器)来解析 markdown,我想使用highlightjs 突出显示代码块。我写了以下 Showdown 扩展:
/* global
hljs,
Showdown
*/
(function() {
'use strict';
Showdown.extensions.hljs = function(converter) {
return [
{
type: 'lang',
filter: function(text) {
return text;
var m = /([`]{3}[\S\s]*[`]{3})/gm.exec(text);
if(!m) {
return text;
}
for(var i in m) {
if(isNaN(i)) {
continue
}
var match = m[i];
var lang = match.replace(
/([`]{3})([\s\S]*)(\n){1}([\s\S]*)([`]{3})/gm,
'$2');
var code = match.replace(
/([`]{3})([\S\n]*)(\n){1}([\s\S]*)([`]{3})/gm,
'$4');
var hl;
try {
var hl = hljs.highlight(lang, code);
} …Run Code Online (Sandbox Code Playgroud) I\xe2\x80\x99m 尝试为 Python 包设置 GitHub 操作。我相信最明智的方法是我在 GitLab 中使用的 xe2x80x99m ;在 docker 镜像内运行一组命令。我想用一个矩阵来测试多个Python版本。
\n\n到目前为止,我已经定义了以下工作流程:
\n\nname: Pytest\n\non:\n - push\n - pull_request\n\njobs:\n pytest:\n runs-on: ubuntu-latest\n strategy:\n matrix:\n python-version:\n - 3.5\n - 3.6\n - 3.7\n - 3.8\n container: python:${{ python-version }}-alpine\n steps:\n - uses: actions/checkout@v2\n - name: Install\n run: |\n pip install poetry\n poetry install\n - name: PyTest\n run: poetry run pytest\nRun Code Online (Sandbox Code Playgroud)\n\n结果可以在这里看到: https: //github.com/remcohaszing/pywakeonlan/actions/runs/87630190
\n\n这显示以下错误:
\n\n\n\n\n工作流程无效。.github/workflows/pytest.yaml(行:17,列:16):无法识别的命名值:\'python-version\'。位于表达式中的位置 1:python-version
\n
我该如何修复这个工作流程?
\nI\xe2\x80\x99m 从 GitLab 管理的 Kubernetes 集群迁移到自我管理的集群。在这个自我管理的集群中需要安装 nginx-ingress 和 cert-manager。我已经设法对用于审查环境的集群执行相同的操作。我使用最新的 Helm3 RC 来管理这个,所以我不需要 Tiller。
\n\n到目前为止,我运行了这些命令:
\n\n# Add Helm repos locally\nhelm repo add stable https://kubernetes-charts.storage.googleapis.com\nhelm repo add jetstack https://charts.jetstack.io\n\n# Create namespaces\nkubectl create namespace managed\nkubectl create namespace production\n\n# Create cert-manager crds\nkubectl apply --validate=false -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.11/deploy/manifests/00-crds.yaml\n\n# Install Ingress\nhelm install ingress stable/nginx-ingress --namespace managed --version 0.26.1\n\n# Install cert-manager with a cluster issuer\nkubectl apply -f config/production/cluster-issuer.yaml\nhelm install cert-manager jetstack/cert-manager --namespace managed --version v0.11.0\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的cluster-issuer.yaml:
# Based on https://docs.cert-manager.io/en/latest/reference/issuers.html#issuers\napiVersion: cert-manager.io/v1alpha2\nkind: ClusterIssuer\nmetadata:\n …Run Code Online (Sandbox Code Playgroud) python ×3
javascript ×2
typescript ×2
android ×1
angularjs ×1
browser-sync ×1
cert-manager ×1
cordova ×1
gulp ×1
highlight ×1
kubernetes ×1
node.js ×1
pip ×1
pypi ×1
regex ×1
setuptools ×1
showdown ×1