所以,基本上我试着计算每个单词出现在Chef食谱文件中的次数.
7-zip
ant
ant
ant
apache2
apache2
apache2
apache2
api-example-v1
api-products-v3
apt
apt
apt
ark
ark
ark
artifactory
artifactory
artifactory-wrapper
atp-cache-clear
Run Code Online (Sandbox Code Playgroud)
所以它应该像"uniq -c myfile.txt"一样简单(文件已经排序),但我遇到的问题是当我这样做时我得到这个输出:
1 7-zip
2 ant
1 ant
3 apache2
1 apache2
1 api-example-v1
1 api-products-v3
2 apt
1 apt
2 ark
1 ark
1 artifactory
1 artifactory
1 artifactory-wrapper
1 atp-cache-clear
1 atp-cache-clear
2 atpc-deployer
1 atpc-deployer
2 atpc-wrapper
1 atpc-wrapper
Run Code Online (Sandbox Code Playgroud)
如您所见,输出不正确.例如,"ark"只应出现一次,计数为3.依此类推所有项目.
我已经这样做了,没有其他文件的问题,输出是正确的.
作为一个注释,我已经尝试了"cat -T myfile.txt"来查看不可打印的字符,看看有什么东西在那里我看不到但没有显示出来.
我还从文件的每一行中删除了尾部和前导空格.
我还能错过什么?
这与问题有关:
尽管一切都在现在的工作很好,我没能做到的唯一事情是tolower的,因为我得到一个错误的用户输入:
bool lookupTerm(const std::string& term, const std::vector<std::string>& possible_names) {
transform(term.begin(), term.end(), term.begin(), ::tolower);
for (const std::string &possible_name : possible_names)
{
if (possible_name.compare(term) == 0)
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
const std::vector<std::string> possible_asterisk = { "star" ,
"asterisk" ,
"tilde"};
string term = "SoMeWorD";
Run Code Online (Sandbox Code Playgroud)
In file included from /usr/include/c++/7.2.0/algorithm:62:0,
from jdoodle.cpp:5:
/usr/include/c++/7.2.0/bits/stl_algo.h: In instantiation of '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) [with _IIter = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >; _OIter = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >; …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试来自gjson库的值是否是最快和最简单的方式的字符串.我不想使用开关类型断言.
if reflect.TypeOf(gjson.Get(input, "name").Value()) != "string" {
return "Not a string!"
}
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?
我正在尝试学习使用 Go 的分析功能。考虑到这一点,我创建了这个简单的应用程序:https : //github.com/Matias-Barrios/countWords ,它只是计算给定txt文件的单词出现次数。
问题是,一旦创建了.cpu.prof文件,我就看不到任何东西。一旦我打开文件,我就会收到此错误:
(0) matias #> go tool pprof .cpu.prof
File: main
Type: cpu
Time: Oct 9, 2019 at 12:38am (-03)
Duration: 201.31ms, Total samples = 0
No samples were found with the default sample value type.
Try "sample_index" command to analyze different sample values.
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 0, 0% of 0 total
flat flat% sum% cum cum% …Run Code Online (Sandbox Code Playgroud) 所以根据苹果的文档:https : //developer.apple.com/documentation/webkit/wkwebviewconfiguration/1614793-allowsinlinemediaplayback
我应该能够使用 Swift 4 轻松地在线播放视频,但无论我做什么,它总是会在本机视频播放器中打开视频。
这是我的代码:
convenience init(style: UITableViewCell.CellStyle, reuseIdentifier: String?, url: String = "", title: String) {
self.init(style: style, reuseIdentifier: reuseIdentifier)
self.videoTitleLabel.text = title
self.urlToVideo = url
setUpUI()
setUpLayout()
webView.backgroundColor = .smalt
webView.translatesAutoresizingMaskIntoConstraints = false
webView.configuration.allowsInlineMediaPlayback = true
webView.configuration.preferences.javaScriptEnabled = true
webView.load(URLRequest(url: URL(string: self.urlToVideo + "?playsinline")! ))
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我在尝试完全清除Maria DB 并重新安装时遇到问题。
这就是我删除它的方法:
2073 sudo apt-get remove --purge maria*
2074 rm -f /var/log/mariadb
2075 rm -f /var/log/mariadb/mariadb.log
2076 rm -rf /var/lib/mysql
2077 rm -rf /usr/lib64/mysql
2078 rm -rf /usr/share/mysql
Run Code Online (Sandbox Code Playgroud)
然后我尝试重新安装为:
sudo apt install mariadb-server
mysql_secure_installation
Run Code Online (Sandbox Code Playgroud)
但问题是一旦我这样做了,我就会被提示输入 root 密码,不应该设置它,因为我应该已经清除了所有内容。
[~]@Ubuntu1804 #> mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
package main
import (
"fmt"
"time"
)
type Response struct {
Data string
Status int
}
func main() {
var rc [10]chan Response
for i := 0; i < 10; i++ {
rc[i] = make(chan Response)
}
var responses []Response
for i := 0; i < 10; i++ {
go func(c chan<- Response, n int) {
c <- GetData(n)
close(c)
}(rc[i], i)
}
for _, resp := range rc {
responses = append(responses, <-resp)
}
for _, item := …Run Code Online (Sandbox Code Playgroud) 我的 Kotlin 应用程序中有一个如下所示的方法:
coroutineScope{
val aFetcher = async { a.fetch()}
val bFetcher = async { b.fetch()}
val cFetcher = async { c.fetch()}
val dFetcher = async { d.fetch()}
Merged(a.await(),b.await(),c.await(),d.await())
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我找不到一种方法使一个请求依赖于另一个请求。就我而言,我需要 cFetcher 等到 bFetcher 结束工作后再开始。
在 Kotlin 中执行此操作的正确方法是什么?
我想要一堆goroutines来从很多服务器上获取一些信息.我正在简化下面的代码,因此它更具可读性.它看起来工作得很好,但是在完成所有任务之后就会感到恐慌,因为我从不关闭频道.问题是我不确定在哪里关闭它.
我需要你的帮助:
func main() {
ch := make(chan string)
for i:= 0; i < 10 ; i++ {
go func(c chan <- string,t int){
time.Sleep( time.Duration(rand.Intn(3000)) * time.Millisecond )
c <- strconv.Itoa(t) + " : Done " + strconv.Itoa(rand.Intn(3000))
}(ch,i)
}
for val := range ch {
fmt.Println(val)
}
}
Run Code Online (Sandbox Code Playgroud)
$ go run test_channels.go
0 : Done 1694
6 : Done 511
3 : Done 162
2 : Done 89
8 : …Run Code Online (Sandbox Code Playgroud)