str "000123" --> int 123To trim a zero-padded decimal string and convert it to integer as shown above, simply use strconv.Atoi() function.
| #!/bin/bash | |
| # -------------------------------------------------------------------------------------------- | |
| # Installs Ruby 2.6.8 using rbenv/ruby-build on the Raspberry Pi OS | |
| # | |
| # Run from the web: | |
| # bash <(curl -sL https://gist.github.com/KEINOS/7101f542be23e5048198e2a27c3cfda8/raw/install_ruby_rpi.sh) | |
| # -------------------------------------------------------------------------------------------- | |
| # Welcome message |
| // To see how to use this gist: https://go.dev/play/p/3W-F9T113d_f @ Go Playground | |
| // Ref: https://qiita.com/mattn/items/6cad7b5dd73092b3d354 by @mattn @ Qiita | |
| package nurupo | |
| import ( | |
| "errors" | |
| "strings" | |
| ) | |
| // Nurupo returns an error if the message contains "ぬるぽ". |
| ssh_authorized_keys: | |
| - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCq44h2dipTqOlGog5RhqLXJE2ngfvdF2wRHF9aXxPGoh8VxdYAjXtGnuDXy/yhGGyzkSFjBZmseN/uFUkVA0Pa1mFtJUaFsYQo/AMrITQNai5DeKJoIga98xubAMpHgf6c9k0DyTo4R1VmLfrDAvcCU874n6j1coJxIpjCUSXA01SSSGoTqxTuZsB3imxraQE0nC1NvFdANAiA4HcmgYyMKfhvUev/letizKnWPVVUdG6uoUrSS4cZrTvfOAS0HQWo6cMKArn6FPnng2NPK9N6BNojpesfhVd4JiedW8jXHG93kjmaRnHkj/kjw2wl6Ud4fyDbA//mPEkHA3AhhktS9BkOf2Dpfa71phbFW4Yg/iwh6u9WpeLMgmSGA5jWg6puqNNdMr/PyNQwi34S6DX3c0eF3WMr8MHGyrSOQviu/YGaxuBFnFcn1w3QBQBxr7+MTf7bA4qeb53l2dFqx3i6YEjrXvPIBqQlk/iAVy1opkbmfRrWoJjgz84p5Om6muxN94xj2bywW03NUaafFJvRZYQ7zvKqzTq7NQqQAo1HLGy/vhZpRhYRqctBpzu3+bJlzFrqaSBmLjuLTDMTvHNPrORQoFPKzfa/SON3fHRmNjRaMpTLJDbaNAEaJXIHwnqpfLgelzrrKTJgH9BsABy2LTO9VX47UiPGatA4QIo/ZQ==" | |
| hostname: k3os-server-keinos01 | |
| write_files: | |
| - content: | | |
| nameserver 8.8.8.8 | |
| nameserver 8.8.4.4 | |
| owner: root:root | |
| path: /etc/resolv.conf | |
| permissions: '0644' |
「"golang" test "os.Stdin" "keinos"」でググってもヒットしなかったので、自分のググラビリティとして。
In the dependency injection point of view, it is a good practice to var OsStdin = os.Stdin and use OsStdin instead of os.Stdin. Then monkey patch (temporary replace) the variable during the test.
But if the external package doesn't support that OsStdin alias feature, and uses os.Stdin, we need to mock the os.Stdin some how.
Trimming/replacing repeated whitespaces such as space, tab, line-breaks, etc as one space.
Something like " foo\n\t\t bar\n buzz" to "foo bar buzz". But without using regex nor multiple strings.Replace().
Use
strings.Fiels()and join them.
| #!/bin/bash | |
| name_file_coverage='coverage.out' | |
| # getNameFilesUncovered echoes file names in comma-separated list which didn't | |
| # cover 100%. This will be used for “go-carpet` -file option. | |
| function getNameFilesUncovered() { | |
| list=$(go tool cover -func="$name_file_coverage" | grep -v '100.0%\|init\|total' | awk '{print $1}') | |
| echo "$list" | while IFS= read -r line; do | |
| basename "${line}" | sed -e 's/\.[^\.]*$/\.go/' |
| # docker-compose.yml for WordPress 5.5 + PHP 7.4.9, Apache 2.4.38 | |
| # | |
| # - Download URL: https://git.io/JJ5Vu | |
| # - How to run servers: | |
| # $ php -r 'copy("https://git.io/JJ5Vu", "./docker-compose.yml");' | |
| # $ docker-compose up -d | |
| # - How to access: | |
| # - Open browser: http://localhost:8989/ | |
| # - Ref: https://www.youtube.com/watch?v=pYhLEV-sRpY @ Youtube | |
| version: '3' |