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 / WebSocketConfig.java
Created January 17, 2020 19:05
WebSocketConfig for WebFlux
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter;
import java.util.HashMap;
import java.util.Map;
@linux-china
linux-china / Makefile
Created October 12, 2019 23:24
Makefile for Emscripten
WASM_MODULE = cpp17
CC = em++
CXXFLAGS = --bind -O3 -x c++ -std=c++17 -s ALLOW_MEMORY_GROWTH=1 -s 'MALLOC="emmalloc"'
.PHONY : all clean
all: $(WASM_MODULE).wasm ## Build all Wasm
$(WASM_MODULE).wasm: $(WASM_MODULE).cpp ## Compile cpp17.wasm
$(CC) $(CXXFLAGS) -o $(WASM_MODULE).js $(WASM_MODULE).cpp
@linux-china
linux-china / object-relations.puml
Created August 5, 2019 17:30
Composite, Aggregate and Relation
@startuml
class Building {
- apartments
}
Building --* Apartment: contains >
class Car {
- wheels
}
https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d
@linux-china
linux-china / kotlin2native.sh
Created August 16, 2018 22:58
Kotlin script to native image
kotlinc -include-runtime hello.kt -d hello.jar
native-image -jar hello.jar
@linux-china
linux-china / FoodOrder.kt
Created August 14, 2018 17:09
Kotlin Builder Pattern Demo
package org.mvnsearch.builder
class FoodOrder private constructor(builder: FoodOrder.Builder) {
val bread: String?
val meat: String?
init {
this.bread = builder.bread
this.meat = builder.meat
@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 / FilenameComparator.java
Created February 26, 2018 05:58
Order Versioned File Names Semantically in Java
public final class FilenameComparator implements Comparator<String> {
private static final Pattern NUMBERS =
Pattern.compile("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
private static final Pattern FILE_ENDING =
Pattern.compile("(?<=.*)(?=\\..*)");
@Override
public final int compare(String o1, String o2) {
if (o1 == null || o2 == null)
@linux-china
linux-china / TcpIpPropertySourceConfig.java
Created January 6, 2018 10:54
Spring Boot to set server.address
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Arrays;
import java.util.Collections;
@linux-china
linux-china / auto_load_bashrc.sh
Created August 30, 2017 06:36
Use .bashrc.d directory instead of bloated .bashrc
for file in ~/.bashrc.d/*.bashrc;
do
source “$file”
done