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 / unzip-and-open.py
Last active April 17, 2024 15:31
unzip and open in intellij projcts generated from start.spring.io
#!/usr/bin/env python
import os
import subprocess
import sys
if __name__ == '__main__':
def run(c):
print('running: %s' % c)
@joshlong
joshlong / MvcRestApplicationInitializer.java
Last active October 11, 2023 20:07
This is a complete working Spring MVC REST application. The only thing unspecified are the imports and the Maven pom.xml. Deploy this class as a .war using Spring MVC 3.2.x (and, specifically, the spring-webmvc library) and you're done!
/**
* <p>This will be picked up in a Servlet 3 environment like Apache Tomcat 7.
*
* <p>This replaces <code>web.xml</code>.
*
*/
public class MvcRestApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override protected Class<?> [] getRootConfigClasses() {
@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();
}
}
@joshlong
joshlong / gist:6665633
Created September 23, 2013 01:52
Small change to make a Spring Boot & Java 1.8-compatible application
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>0.5.0.BUILD-SNAPSHOT</version>
</parent>
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 / Application.java
Last active October 26, 2022 16:28
Spring's `@Qualifier` is the best of both JSR 250's `@Resource` (which Spring also supports) and JSR 330's `@Inject` (which Spring also supports). You can think of it as a more flexible superset of the two. You can create type-local qualifer annotations as you would w/ JSR 330 or qualify things by bean ID. The Spring `@Qualifier` predates the JS…
package qualifiers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@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: