首先,我发布这个是因为当我在寻找下面问题的解决方案时,我在stackoverflow上找不到一个.所以,我希望在这里添加一点知识库.
我需要处理目录中的一些文件,并且需要以数字方式对文件进行排序.我lambda在wiki.python.org上找到了一些关于排序的例子 - 特别是使用模式 - 我把它放在一起:
#!env/python
import re
tiffFiles = """ayurveda_1.tif
ayurveda_11.tif
ayurveda_13.tif
ayurveda_2.tif
ayurveda_20.tif
ayurveda_22.tif""".split('\n')
numPattern = re.compile('_(\d{1,2})\.', re.IGNORECASE)
tiffFiles.sort(cmp, key=lambda tFile:
int(numPattern.search(tFile).group(1)))
print tiffFiles
Run Code Online (Sandbox Code Playgroud)
我仍然是Python的新手,并且想问社区是否可以对此进行任何改进:缩短代码(删除lambda),性能,样式/可读性?
谢谢Zachary
是否有emacs函数将驼峰式单词转换为下划线?就像是:
longVariableName
M-x to-underscore
long_variable_name
我对 VSCode 完全陌生,这是我的第一个设置。我知道这是一个非常常见的问题,但我找不到合适的解决方案。
这是我到目前为止的理解。如果我错了,请纠正我。
我想使用 ESLint 来查找 Javascript 代码中的错误,并使用 Prettier 来格式化所有语言。但似乎我们也可以使用 ESLint 格式化我们的 javascript 代码!我喜欢使用一些有用的规则,但 Prettier 似乎没有(括号中的空格)之类的规则。
所以我决定使用 ESLint 作为 Javascript 中的格式化程序。现在我看到网上有很多关于“如何将 ESLint 与 Prettier 集成”的教程。这个想法是使用插件扩展 Prettier 规则并向其中添加那些 ESLint 特定规则。合理的!
我最终得到了以下设置。请看下面我使用 ESLint 和 Prettier 的设置:
.eslintrc.js
module.exports = {
env: {
browser: true,
es6: true,
},
extends: ["prettier"],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
plugins: [
"prettier"
],
"rules": {
"space-in-parens": ["error", "always"],
"quotes": ["error", "single"],
"prettier/prettier": "error"
}
};
Run Code Online (Sandbox Code Playgroud)
VSCode 的 …
我使用import unittest创建了unitests.当我想运行一个特定的测试并且我放置一个断点然后转到控制台并尝试eval表达式没有返回值,好像stdout不再是控制台屏幕.
我从未安装过teamcity,但奇怪的是我在运行unittest时收到了消息.很奇怪.我想也许captureStandardOutput ='true'(在下面的最后一行强调)是问题的原因但我甚至无法找到更改参数的地方来测试它.
C:\Users\selas\AppData\Local\Continuum\Anaconda3\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59641 --file "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pycharm\_jb_unittest_runner.py" --target tests.test_model.FigurationDBTesting.test_printFigurationPerBoundary
pydev debugger: process 8932 is connecting
Connected to pydev debugger (build 171.3780.115)
teamcity[enteredTheMatrix timestamp='...']
Launching unittests with arguments python -m unittest tests.test_model.FigurationDBTesting.test_printFigurationPerBoundary
teamcity[testSuiteStarted timestamp='...' locationHint='python://tests' name='tests' nodeId='1' parentNodeId='0']
teamcity[testSuiteStarted timestamp='...' locationHint='python://tests.test_model' name='test_model' nodeId='2' parentNodeId='1']
teamcity[testSuiteStarted timestamp='...' locationHint='python://tests.test_model.FigurationDBTesting' name='FigurationDBTesting' nodeId='3' parentNodeId='2']
teamcity[testStarted timestamp='...' >!> captureStandardOutput='true' <!< locationHint='python://tests.test_model.FigurationDBTesting.test_printFigurationPerBoundary' name='test_printFigurationPerBoundary' nodeId='4' parentNodeId='3']
Run Code Online (Sandbox Code Playgroud) 我刚刚对我的应用程序进行了负载测试.我注意到两个相同请求的延迟有一些非常大的变化:3秒与30秒.当我挖掘痕迹时,我发现了以下内容:
| | Traced (ms) | Untraced (ms) |
|----------------------+-------------+---------------|
| High-latency Request | 193 | 29948 |
| Low-latency Request | 305 | 2934 |
Run Code Online (Sandbox Code Playgroud)
以下是跟踪的屏幕截图:
总体延迟低
总体延迟高
我无法理解运行时性能的10比1差异.
我只在负载下看到这些高延迟请求.我的代码中的某些内容可以解释这种可变性(假设两个请求都遵循相同的代码路径)吗?
编辑1
嗯,我接受tar尊重空文件的答案......但在我的系统上:
$ touch emptytar
$ tar -tf emptytar
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
Run Code Online (Sandbox Code Playgroud)
也许我有一个非规范版本?
$ tar --version
tar (GNU tar) 1.22
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by John Gilmore and Jay Fenlason. …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的.emacs文件配置为在Windows,Linux和Mac环境中工作 - 具体来说,我需要它为org-mode选择正确的字体和某个目录.
我尝试了下面加载正确的字体,但没有加载为org-mode指定的路径:
;; On Windows
(if (eq system-type 'windows-nt)
(set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
(setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
)
;; On Linux
(if (eq system-type 'gnu/linux)
(set-default-font "Inconsolata-11")
(setq load-path (cons "~/elisp/org-current/lisp" load-path))
)
我尝试了以下内容,在我的Windows机器上返回错误Font Inconsolata-11 is not defined,并在我的Linux机器上返回错误Font -outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1 is not defined.对于这两者,未加载指定的组织路径:
;; On Windows
(if (eq system-type 'windows-nt)
(setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
(set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
)
;; On Linux
(if (eq system-type 'gnu/linux)
(setq load-path (cons "~/elisp/org-current/lisp" load-path))
(set-default-font "Inconsolata-11")
)
我system-type在两个环境中评估了变量,并且它们都正确评估. …
任何人都可以告诉我在OS 10.7.3上使用svn和tcsh shell接受哪些日期格式?我试图做一个svn up -r {DATE},每次我得到这个:
svn: Syntax error in revision argument
Run Code Online (Sandbox Code Playgroud)
不接受此处描述的格式:http: //svnbook.red-bean.com/en/1.2/svn.tour.revs.html
我的最后一次尝试是尝试结帐:
svn checkout --revision {2012-02-17} svn+ssh://blah/blah blah
svn: Syntax error in revision argument '2012-02-17'
Run Code Online (Sandbox Code Playgroud)
谢谢
运行主项目后,每个下游项目都有测试结果,但"最新聚合测试结果"没有测试.如何配置Jenkins以使所有测试结果显示在聚合列表中?
我有一个非常简单的测试设置,使用cron和使用该logging模块的Python脚本,而cron在遇到日志记录事件时表现得很奇怪.
* * * * * ~/test.py >> ~/test.log
Run Code Online (Sandbox Code Playgroud)
#!/usr/bin/env python
import logging
logging.basicConfig(level=logging.DEBUG)
print 'Properly printed, to file'
logging.debug("Does not get printed, get's e-mailed as an error")
print 'Still running, though'
Run Code Online (Sandbox Code Playgroud)
运行cron之后,将使用以下两条消息填充日志:
Properly printed, to file
Still running, though
Run Code Online (Sandbox Code Playgroud)
在cron运行之后,我收到一条通知我有新邮件:
From tomcat6@local Thu May 23 16:35:01 2013
Date: Thu, 23 May 2013 16:35:01 -0700
From: root@local (Cron Daemon)
To: tomcat6@local
Subject: Cron <tomcat6@local> ~/test.py >> ~/test.log
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated …Run Code Online (Sandbox Code Playgroud) 我试图patch在stdout上捕获bash 的输出,但是我收到一个错误:
patch -o- some/file
patch: can't output patches to standard output
Run Code Online (Sandbox Code Playgroud)
我可以在stdout上获得补丁结果吗?
我开始疯狂地尝试让 Go 解码这个 json 请求正文。这是一个示例请求:
curl -X POST -d "{\"username\":\"foo\", \"password\":\"bar\"}" http://localhost:3000/users
Run Code Online (Sandbox Code Playgroud)
这是我的处理程序:
mux.HandleFunc("/users", func(rw http.ResponseWriter, req *http.Request) {
var body struct {
username string
password string
}
// buf := make([]byte, req.ContentLength)
// req.Body.Read(buf)
// fmt.Println(string(buf))
//
// The above commented out code will correctly print:
// {"username":"foo", "password":"bar"}
err := json.NewDecoder(req.Body).Decode(&body)
if err != nil {
rw.WriteHeader(http.StatusNotAcceptable)
return
}
fmt.Printf("%+v\n", body)
// prints -> {username: password:}
})
Run Code Online (Sandbox Code Playgroud)
就像评论所暗示的那样,我可以验证这req.Body确实是正确的 - 但无论出于何种原因,json.NewDecoder(req.Body).Decode(&body)永远不会填写 的字段body。
任何帮助将不胜感激!
我有一个名为“score”的 Int 属性的视图,我想用滑块调整它。
struct IntSlider: View {
@State var score:Int = 0
var body: some View {
VStack{
Text(score.description)
Slider(value: $score, in: 0.0...10.0, step: 1.0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是 SwiftUI 的 Slider 仅适用于双打/浮动。
我怎样才能让它与我的整数一起工作?