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 / AuthServiceApplication.java
Last active December 10, 2017 00:54
An OAuth authorization service built using Java
// org.springframework.cloud:spring-cloud-starter-oauth2
// org.springframework.boot:spring-boot-starter-data-jpa
// com.h2database:h2
// redefine: spring-security.version == 4.1.0.RELEASE
package com.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@joshlong
joshlong / KotlinAuthenticationServiceApplication.kt
Last active May 30, 2019 11:00
An OAuth authorization service built using Kotlin
// org.springframework.cloud:spring-cloud-starter-oauth2
// org.springframework.boot:spring-boot-starter-data-jpa
// com.h2database:h2
// redefine: spring-security.version == 4.1.0.RELEASE
package com.example
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.SpringApplication
@joshlong
joshlong / hi.groovy
Last active August 29, 2015 14:22
a simple Spring Boot CLI program
// put the following in a script (hi.groovy)
@RestController
class GreetingRestController {
@RequestMapping("/hi/{n}")
def hi(@PathVariable String n){
[ greeting : "Hello, " + n +"!" ]
}
}
// then on the shell run the following
@joshlong
joshlong / deploy-bosh-lite-and-cf.sh
Last active August 29, 2015 14:22
This script will deploy BOSH Lite on the local VM and then layer Cloud Foundry on top of that
#! /bin/bash
set -e
WS=$HOME/workspace
O=my-org
S=dev
# make sure you have common buildchain tools like GCC (XCode!) installed
brew tap xoebus/homebrew-cloudfoundry
@joshlong
joshlong / cf-app-services.py
Last active August 29, 2015 14:22
This little script demonstrates using the Cloud Foundry API to look up all the services associated w/ a Cloud Foundry application. It requires an oauth taken as you can get from `cf oauth-token`
#!/usr/bin/env python
import os
import sys
import urllib2
import json
def cf_app_services(app_name, token):
app_name = app_name.strip()
@joshlong
joshlong / Application.java
Created May 28, 2015 20:13
A simple client that recursively scans a source code tree and invokes all `cf-deploy.sh`s it finds or, absent that, any present Cloud Foundry `manifest.yml`s by calling `cf push`. Ideally for continuous integration validation that code deploys and to do smoke tests like call the application's health codes and optionally stop a production deploy.
package deployment;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cloudfoundry.client.lib.CloudCredentials;
import org.cloudfoundry.client.lib.CloudFoundryClient;
import org.cloudfoundry.client.lib.domain.CloudApplication;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@joshlong
joshlong / DemoApplication.java
Last active March 5, 2018 21:22
Dynamic, optional collections of beans in Spring Java `@Configuration` classes
package demo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.util.ArrayList;
import java.util.List;
package demo;
import co.freeside.betamax.Betamax;
import co.freeside.betamax.Recorder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
@joshlong
joshlong / Spring.java
Last active August 29, 2015 14:08
This demonstrates using the `@Component` stereotype annotation on `@Qualifier` to omit it on types.
package spring;
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 / Spring.java
Last active August 29, 2015 14:08
This demonstrates using Spring-native annotations and Spring's `@Qualifier`
package spring;
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;