Skip to content

Instantly share code, notes, and snippets.

View joshlong's full-sized avatar
🍃
i'm on Twitter @starbuxman

Josh Long joshlong

🍃
i'm on Twitter @starbuxman
View GitHub Profile
@joshlong
joshlong / ReversingServiceApplication.java
Last active September 7, 2023 09:46
this is a simple network service that reverses strings. I'm using it to test out Project Loom
package com.example.demo;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
@joshlong
joshlong / VcConfiguration.java
Created July 22, 2023 14:02
AOT for Spring ViewComponents with Thomas
@Configuration
class VcConfiguration {
@Bean
static ViewComponentResourceAotProcessor viewComponentResourceAotProcessor() {
return new ViewComponentResourceAotProcessor();
}
}
package hollywood.framework;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.FileCopyUtils;
#!/usr/bin/env bash
PID=${1}
RSS=`ps -o rss ${PID} | tail -n1`
RSS=`bc <<< "scale=1; ${RSS}/1024"`
echo "${PID}: ${RSS}M"
@joshlong
joshlong / DatesApplication.java
Last active November 6, 2022 10:30
calculates when the version of Java converges with its age. Assumes Java Beta came out January 1995.
// run with
// java DatesApplication.java
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Map;
public class DatesApplication {
@joshlong
joshlong / DemoApplication.java
Created September 20, 2022 09:32
This is a trivial Spring Boot 3 AOT application doing all sorts of stuff
/*
add schema.sql
create table customer
(
id serial primary key,
name varchar(255) not null
);
add spring boot starters as usual, then add:
@joshlong
joshlong / MongoTestContainersEnvironmentPostProcessor.java
Created January 14, 2022 22:07
MongoTestContainersEnvironmentPostProcessor.java
package autoservices;
import com.mongodb.reactivestreams.client.MongoClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.lifecycle.Startables;
@joshlong
joshlong / FunctionalReactiveHttpApplication.kt
Last active December 5, 2021 19:50
FunctionalReactiveHttpApplication.kt
package com.example.reactive
import org.reactivestreams.Publisher
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.builder.SpringApplicationBuilder
import org.springframework.cloud.gateway.handler.predicate.RoutePredicates.path
import org.springframework.cloud.gateway.route.gateway
import org.springframework.context.support.beans
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.mapping.Document
#!/bin/bash
START_DIR=`pwd`
export OS=$( uname | tr '[:upper:]' '[:lower:]' )
export SCRIPT_DIR=$HOME/my-env
export SCRIPT_DIR_BIN=$SCRIPT_DIR/bin
export SCRIPT_OS_DIR=${SCRIPT_DIR}/${OS}
export APP_INSTALL_LOGS=${SCRIPT_OS_DIR}/logs
///usr/bin/env curl -LSs https://sh.jbang.dev | bash -s - "$0" "$@"; exit $?
//DEPS org.springframework.boot:spring-boot-starter-web:2.3.4.RELEASE
import org.springframework.web.bind.annotation.*;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.context.*;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.context.annotation.*;