Skip to content

Instantly share code, notes, and snippets.

@yujiorama
yujiorama / Dockerfile
Last active August 3, 2024 18:13
java dynaimc cds in container
FROM openjdk:12-jdk AS base
ENV SDKMAN_DIR=/usr/local/sdkman
WORKDIR /myapp
RUN set -x \
&& yum update -y \
&& yum install -y ca-certificates curl zip unzip sed binutils which \
&& curl -fsSL https://get.sdkman.io | bash \
@yujiorama
yujiorama / yjdfif
Created June 21, 2019 07:38
Flatten diff of yaml or json files
#!/bin/bash
set -euo pipefail
function info()
{
echo "[INFO] $@"
}
function warn()
@yujiorama
yujiorama / scoop-completion.bash
Created February 18, 2019 00:36
Poor completion script for scoop
__scoop_command_completion()
{
local candidates_
compword_="${COMP_WORDS[${COMP_CWORD}]}"
candidates_=$(scoop help | sed -r -e '/^$/d' -e '/.*(Usage|Some useful|to get help).*/d' | awk '{print $1}' | tr '\n' ' ')
COMPREPLY=($(compgen -W "${candidates_}" -- "${compword_}"))
}
complete -o default -o nospace -F __scoop_command_completion scoop
@yujiorama
yujiorama / update.sh
Created January 24, 2019 03:18
lombok.jar や plantuml.jar を更新する bash script
#!/bin/bash
#
# download_new_file__
# require date, stat, curl or http
#
download_new_file__()
{
local src=$1
local dst=$2
if [[ -e ${dst} ]]; then
@yujiorama
yujiorama / ssh-completion.bash
Created January 11, 2019 07:45
bash function for ssh command to hostname completion in ssh_config(5)
# ex: ts=4 sw=4 et filetype=sh
__hostname_completion()
{
local ssh_config_ compword_ hosts_
if [[ -e "${HOME}/.ssh/config" ]]; then
ssh_config_="${HOME}/.ssh/config"
elif [[ -e "/etc/ssh/ssh_config" ]]; then
ssh_config_="/etc/ssh/ssh_config"
else
@yujiorama
yujiorama / minikube.hyperv.ps1
Created December 18, 2018 05:10
startup script for minikube on Hyper-V VM on Windows 10 Pro
## Confirm EnableSMB2Protocol, for mount host folder
Set-SmbServerConfiguration -EnableSMB1Protocol $False -EnableSMB2Protocol $True
Get-SmbServerConfiguration | Select-Object -Property EnableSMB1Protocol,EnableSMB2Protocol
#
# EnableSMB1Protocol EnableSMB2Protocol
# ------------------ ------------------
# False True
#
@yujiorama
yujiorama / switch.ps1
Created November 9, 2018 08:48
Hyper-V の仮想スイッチを作るときのコード片
# 既存のネットワークアダプタとインターネット接続を共有して外部ネットワークに接続できる仮想スイッチ
New-VMSwitch -Name External -SwitchType External -NetAdapterName "Wi-Fi"
# NAT ネットワークを構成する仮想スイッチ
New-VMSwitch -Name NAT -SwitchType Internal
$ifIndex = (Get-NetAdapter -Name "vEthernet (Nat)").ifIndex
New-NetIPAddress -IPAddress 192.168.0.1 -PrefixLength 24 -InterfaceIndex $ifIndex
New-NetNat -Name NAT -InternalIPInterfaceAddressPrefix 192.168.0.0/24
# NAT ネットワークを削除
@yujiorama
yujiorama / docker-image-tag-list.sh
Created October 9, 2018 01:24
Dockerhub で公開されているイメージのタグ一覧
# usage
# add prefix "library" to public image
# ditl library/openjdk
#
# don't add prefix "library" to common image
# ditl adoptopenjdk/openjdk11
#
ditl() {
local name=$1
local next_url="https://registry.hub.docker.com/v2/repositories/${name}/tags/?page=1"
@yujiorama
yujiorama / Demo.java
Created September 16, 2018 07:08
constant-specific method implementations の実装例。会員の種類で割引率が違うとかそういう想定を enum に追い出してるので User は単純なまま。
import java.util.stream.Stream;
public class Demo {
public static void main(String[] args) {
User user = new User("Bob");
System.out.printf("user is %s\n", user.getName());
Stream.of(Role.values()).forEach(role -> {
user.setRole(role);
System.out.printf("\tas %s\n", role.name());
Stream.of(Item.values()).forEach(choise -> {
@yujiorama
yujiorama / Fruit.java
Created September 16, 2018 06:38
パッケージプライベートなら同じファイルに複数のクラスを定義できる(コンパイルエラーにならない)
// https://docs.oracle.com/javase/specs/jls/se8/html/jls-7.html#jls-7.6
public class Fruit {
public static void main(String[] args) {
System.out.println(Apple.values());
}
}
enum Apple {
FUJI,
PIPPIN,