Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
heiwa4126 / regenerate_ssh_host_keys.sh
Created November 24, 2020 01:59
Regenerate OpenSSH Host Keys on RHEL7
cd /etc/ssh
rm -f ssh_host_*key*
ssh-keygen -A
rm ssh_host_key ssh_host_key.pub -f
chmod 0640 ssh_host_*key
chown root:ssh_keys ssh_host_*key
chmod 0644 ssh_host_*key.pub
#
systemctl restart sshd
@heiwa4126
heiwa4126 / isFileDir.ps1
Created October 23, 2020 01:09
PowerShellでファイルかディレクトリか存在しないかを知る。 よくネットで見るのはPSIsContainerで識別する方法だけど、レジストリが来たら大惨事に (例: `HKCU:\`)。 知りたいのは **「ファイルシステム上のファイル(かディレクトリ)」** なのだ。
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# $ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
function isFileDir {
[OutputType([string])]
Param ([string]$file)
$i = Get-Item -LiteralPath $file -ErrorAction silent
if ($null -eq $i) {
@heiwa4126
heiwa4126 / hello_version.rs
Last active September 29, 2020 08:46
RustでCargo.tomlに書いた名前やバージョンを表示する方法
fn main() {
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
const PKGNAME: &'static str = env!("CARGO_PKG_NAME");
println!("{} v{}", PKGNAME, VERSION);
// println!("{} v{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
// でもOK
}
@heiwa4126
heiwa4126 / kernel_update.sh
Last active July 16, 2020 01:41
/etc/yum.confに`exclude=kernel-* kmod-* perf-* python-perf-* redhat-release-* initscripts` みたいなことのかいてあるRHELのホストに最新カーネルをインストールするコマンドを表示するスクリプト
#!/bin/bash
pkgs=(bpftool bpftool-debuginfo kernel kernel-abi-whitelists kernel-debug kernel-debug-debuginfo kernel-debug-devel kernel-debuginfo kernel-debuginfo-common-x86_64 kernel-devel kernel-doc kernel-headers kernel-tools kernel-tools-debuginfo kernel-tools-libs kernel-tools-libs-devel perf perf-debuginfo python-perf python-perf-debuginfo)
installed=()
for pkg in ${pkgs[@]}; do
rpm -q "$pkg" &> /dev/null
if [ $? -eq 0 ] ; then
installed+=("$pkg")
fi
done
@heiwa4126
heiwa4126 / interface_ex2.go
Created June 26, 2020 05:26
インタフェースが実体を受けるかポインタを受けるかはどうやら関数の実装できまるらしい。
package main
import (
"fmt"
)
type SS interface {
DoAnything()
}
@heiwa4126
heiwa4126 / interface_ex1.go
Created June 26, 2020 04:48
io.Writeインタフェースを持つ構造体Hogeの例
package main
import (
"fmt"
)
type Hoge struct {
label string
cnt int
}
@heiwa4126
heiwa4126 / tz2.go
Created June 18, 2020 06:40
Golangでローカル時間とUTC。あとstrptime()
package main
import (
"fmt"
"time"
)
func main() {
TF := `2006-01-02 15:04:05.999 -0700`
@heiwa4126
heiwa4126 / join2.yml
Last active March 6, 2020 13:07
Ansibleのサンプル。Jnija2には内包表記がない。リストを「引用符でくくって、コンマでつなぐ」例。win_shellとかでよく使う。
- name: jinja2 has not list comprehension.
hosts: localhost
become: no
gather_facts: false
vars:
data: [foo, bar, baz]
tasks:
-
debug:
msg: >
@heiwa4126
heiwa4126 / handler1.yml
Last active March 6, 2020 12:52
Ansibleで、handlersを使ってテンポラリフォルダを消すサンプル
- name: handler test
hosts: localhost
become: no
gather_facts: false
force_handlers: true
#-------------
tasks:
- name: Create working directory.
tempfile:
state: directory
@heiwa4126
heiwa4126 / join.yml
Last active March 6, 2020 12:47
Ansibleのjoinとsequenceのサンプル
- name: join and sequence example
hosts: localhost
become: no
gather_facts: False
vars:
data: [foo, bar, baz]
tasks:
-
name: join example
debug: msg="{{ data|join(', ') }}"