Skip to content

Instantly share code, notes, and snippets.

View linux-china's full-sized avatar

Libing Chen linux-china

View GitHub Profile
@linux-china
linux-china / viper_util.go
Last active April 10, 2024 05:13
Replace place holders in Golang Viper
// after viper read config, replace all placeholders with values
func ReplacePlaceHolders() {
r, _ := regexp.Compile("\\${[a-zA-Z0-9.: _]+}")
replacer := func(placeHolder []byte) []byte {
name := string(placeHolder)
name = name[2 : len(name)-1]
index := strings.Index(name, ":")
if index != -1 {
defaultValue := name[index+1:]
@linux-china
linux-china / JUnit5ExampleTest.java
Created January 5, 2024 01:39
Run JUnit 5 Tests with JBang
//usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 21
//DEPS org.junit.jupiter:junit-jupiter-engine:5.10.1
//DEPS org.junit.platform:junit-platform-console:1.9.3
//DEPS org.assertj:assertj-core:3.25.1
package com.example;
import org.junit.jupiter.api.Test;
import org.junit.platform.console.options.CommandLineOptions;
@linux-china
linux-china / multipass_completion.fish
Last active April 20, 2023 07:48
multipass shell completion for zsh & bash
complete -c multipass -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_use_subcommand" -f -a "delete" -d 'Delete instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "exec" -d 'Run a command on an instance'
complete -c multipass -n "__fish_use_subcommand" -f -a "find" -d 'Display available images to create instances from'
complete -c multipass -n "__fish_use_subcommand" -f -a "get" -d 'Get a configuration setting'
complete -c multipass -n "__fish_use_subcommand" -f -a "help" -d 'Display help about a command'
complete -c multipass -n "__fish_use_subcommand" -f -a "info" -d 'Display information about instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "launch" -d 'Create and start an Ubuntu instance'
complete -c multipass -n "__fish_use_subcommand" -f -a "list" -d 'List all available instances'
@linux-china
linux-china / graalvm.yml
Last active October 21, 2022 13:00
Github actions for GraalVM native image build on Windows, Mac and Linux. Please adjust 'demo-cli' to final name.
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: GraalVM Native Image build
on:
push:
branches: [ master ]
tags: [ '*' ]
@linux-china
linux-china / envoy-schema.json
Last active June 1, 2022 23:13
Envoy configuration json schema for Json and Yaml
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Envoy Proxy config schema",
"description": "JSON Schema for Envoy Proxy config",
"type": "object",
"properties": {
"admin": {
"type": "object",
"description": "Configuration for the local administration HTTP server",
"properties": {
@linux-china
linux-china / Dockerfile
Last active May 13, 2022 18:21
Build Docker image for JBang script with GraalVM native-image
FROM linuxchina/jbang-action:0.94.0-graal-java17-22.1.0 as builder
ARG mainClass="Hello2.java"
RUN mkdir -p /opt/app/out
WORKDIR /opt/app
COPY $mainClass /opt/app
RUN jbang export portable --native -O out/main $mainClass
@linux-china
linux-china / Dockerfle
Created May 13, 2022 17:56
Build Docker image for JBang script with Java 17
FROM linuxchina/jbang-action as builder
ARG mainClass="Hello2.java"
RUN mkdir -p /opt/app/out
WORKDIR /opt/app
COPY $mainClass /opt/app
RUN jbang export portable -O out/app.jar $mainClass
@linux-china
linux-china / JfrOverRSocketController.java
Created May 4, 2022 22:33
JfrOverRSocketController.java
import jdk.jfr.consumer.RecordingStream;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;
import reactor.core.publisher.Flux;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
@Controller
@linux-china
linux-china / KetamaConsistentHash.java
Last active February 22, 2022 11:31
Ketama Consistent Hash with Java language implementation
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class KetamaConsistentHash<T> {
@linux-china
linux-china / jbang-catalog-schema.json
Created December 15, 2021 20:00
JSON Schema file for JBang's jbang-catalog.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "JBang catalogs JSON Schema",
"description": "JSON Schema for jbang-catalog.json",
"type": "object",
"properties": {
"aliases": {
"description": "aliases",
"type": "object",
"additionalProperties": {