Skip to content

Instantly share code, notes, and snippets.

View KEINOS's full-sized avatar

KEINOS KEINOS

View GitHub Profile
@KEINOS
KEINOS / install_ruby_rpi.sh
Last active November 5, 2022 18:07 — forked from zzidante/install_ruby_rpi.sh
A Bash script to install Ruby 2.6.8 on the Raspberry Pi OS
#!/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
@KEINOS
KEINOS / nurupo.go
Last active April 16, 2022 06:08
[Golang] Gist is a git. Thus, it can be used in "import" of Go. See in action: https://go.dev/play/p/3W-F9T113d_f @ Go Playground
// 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 "ぬるぽ".
@KEINOS
KEINOS / convert-zero-padded-decimal-to-int.md
Last active April 18, 2022 03:04
[Golang] Zero padded decimal string to integer / Decimal string with leading zeros to integer

[Golang] How to convert a zero-padded decimal string to an integer?

Converting decimal string with leading zeros to integer

str "000123" --> int 123

To trim a zero-padded decimal string and convert it to integer as shown above, simply use strconv.Atoi() function.

@KEINOS
KEINOS / config.yaml
Last active February 26, 2022 12:13
K3OS config.yaml
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'
@KEINOS
KEINOS / how-to-get-verion-module.md
Created September 27, 2021 03:16
[Golang] How to get imported module/package version from main.go

[Golang] How to get the version of imported non-standard module from main

tl; dr

Use debug.ReadBuildInfo() of "runtime/debug" module.

ts; dr

This is an example to get the version of "golang.org/x/xerrors" package from the main source code.

@KEINOS
KEINOS / index.md
Last active October 20, 2024 00:58
【Golang】How to mock `os.Stdin` during the test in Go. 標準入力をモックする方法

GitHub Gist stars

「"golang" test "os.Stdin" "keinos"」でググってもヒットしなかったので、自分のググラビリティとして。

[Golang] How to mock/mimic os.Stdin during the test in Go

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.

@KEINOS
KEINOS / replace_whitespaces.md
Last active August 4, 2021 10:42
[Golang] How to replace all whitespaces into a single space without using regex.

[Golang] How To Replace All Whitespaces Into a Single Space in Go

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().

TL; DR

Use strings.Fiels() and join them.

@KEINOS
KEINOS / how-to-hide-info-msg-in-badger.md
Last active December 21, 2025 15:33
[Golang][BadgerDB] How to suppress/hide error messages

[Golang] How To Suppress/Hide Error/INFO Messages In Badger DB

TL; DR

Set Logger field of badger.Options object to nil

pathDirDB := GetMyPathDirDB()
optionsDB := badger.DefaultOptions(pathDirDB)
if !IsModeDebug {
@KEINOS
KEINOS / sample.sh
Last active August 12, 2021 01:45
[Golang][go-carpet] Bash sample of how to display / print only uncovered (not 100% of coverage) source files in "go-carpet" of Golang.
#!/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/'
@KEINOS
KEINOS / docker-compose.yml
Last active October 7, 2023 23:36
Docker-compose file for WordPress 5.5 + PHP 7.4.9, Apache 2.4.38 on the fly.
# 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'