Skip to content

Instantly share code, notes, and snippets.

View gregturn's full-sized avatar

Greg L. Turnquist gregturn

View GitHub Profile
@gregturn
gregturn / ScalaCompilationUnit.java
Created August 24, 2011 17:55
Embedding scala compiler in java
try {
Settings settings = new Settings();
settings.usejavacp().tryToSetFromPropertyValue("true");
settings.stopAfter().tryToSetColon(Nil.$colon$colon("dce")); // same as "dce" :: Nil in scala
settings.debug().tryToSetFromPropertyValue("true");
System.out.println("About to compile " + new String(sourceUnit.getContents()));
PrintWriter out = new PrintWriter("output.txt");
IMain main = new IMain(settings, out);

Hacking with Spring Boot 2.3: Reactive Edition

@gregturn
gregturn / git-lg
Created December 5, 2011 15:40
Pretty git "railroad track" log report
git log --graph --pretty=\"format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset'\" --abbrev-commit --date=relative
@gregturn
gregturn / gist:9e05e3dd9d1bfcb3d0e5ad7468f7e4c0
Created January 12, 2018 18:13
Collection+JSON data, the way I first coded it
"data" : {
"full-name": "M. Smith",
"email" : "msmith@example.com"
}
@gregturn
gregturn / gist:3cffdb21c242c42f5351d791c06a3be5
Created January 12, 2018 18:11
Collection+JSON data, done correctly
"data" : [
{"name" : "full-name", "value" : "M. Smith", "prompt" : "Full Name"},
{"name" : "email", "value" : "msmith@example.org", "prompt" : "Email"}
]
@Data
@Value
@Builder(builderMethodName = "collectionJson")
public class CollectionJson<T> {
private String version;
private String href;
private List<Link> links;
@Singular private List<Item<T>> items;
CollectionJson collectionJson = collectionJson()
.version("1.0")
.href(resource.getId().expand().getHref())
.links(value)
.items(Collections.EMPTY_LIST)
.build();
public abstract class AffordanceModelFactory implements Plugin<MediaType> {
abstract public MediaType getMediaType();
abstract public List<AffordanceModel> findAffordanceModels(Affordance affordance, Object invocationValue);
@Override
public boolean supports(MediaType delimiter) {
return delimiter != null && delimiter.equals(this.getMediaType());
}
public interface Affordance {
/**
* HTTP method this affordance covers. For multiple methods, add multiple {@link Affordance}s.
*
* @return
*/
String getHttpMethod();
/**
@GetMapping("/employees/{id}")
public Resource<Employee> findOne(@PathVariable String id) {
// Start the affordance with the "self" link, i.e. this method.
Link findOneLink =
linkTo(methodOn(EmployeeController.class).findOne(id)).withSelfRel();
// Define final link as means to find entire collection.
Link employeesLink = linkTo(methodOn(EmployeeController.class).all()).withRel("employees");