Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / interface_ex2.go
Created June 26, 2020 05:26
インタフェースが実体を受けるかポインタを受けるかはどうやら関数の実装できまるらしい。
package main
import (
"fmt"
)
type SS interface {
DoAnything()
}
@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 / 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 / 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 / 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 / r53register.sh
Created December 15, 2020 05:54
ElasticIPなしのEC2で外部IPをroute53でFQDNをふるスクリプト
#!/bin/bash
# see [Amazon Route 53: How to automatically update IP addresses without using Elastic IPs - DEV](https://dev.to/aws/amazon-route-53-how-to-automatically-update-ip-addresses-without-using-elastic-ips-h7o)
AWS=/usr/local/bin/aws
# Extract information about the Instance
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id/)
AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/)
MY_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4/)
# Extract tags associated with instance
@heiwa4126
heiwa4126 / index.jsp
Created December 16, 2020 08:24
Tomcatの動作チェックに日付とTomcat、JDKのバージョンがでるやつがほしいと言われたので作ったやつ。
<%@
page import="java.time.*"
contentType="text/html; charset=utf8"
%><!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
</head>
<title>Hello, Tomcat</title>
</head>
@heiwa4126
heiwa4126 / find_module_example1.yml
Created March 8, 2021 07:28
Ansibleのfindモジュールの例。/etc/*.confをコントロールマシンにコピーする。Jinja2のフィルタがめんどくさいがshell:つかうよりはいいんじゃないかと。
---
- name: fetch /etc/*.conf
hosts: linux
become: false
gather_facts: false
vars:
outpath: "{{ playbook_dir }}/var/etc_conf/{{ inventory_hostname }}"
tasks:
- name: get list