Skip to content

Instantly share code, notes, and snippets.

View jeffscottbrown's full-sized avatar

Jeff Scott Brown jeffscottbrown

View GitHub Profile
trait Foo<T> {
T getSomething() {
// how to return an instance of whatever T represents?...
}
}
class FooSomething implements Foo<Person> {
}
groovy:000>
groovy:000> aString = 'some string'
===> some string
groovy:000> aDoubleQuotedString = "some string"
===> some string
groovy:000> aGString = "Year: ${2070+42}"
===> Year: 2112
groovy:000>
groovy:000> aString.class
===> class java.lang.String
def query = Person.where {
pets.size() == 2
}
import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
import org.apache.catalina.Context
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer
import org.springframework.context.annotation.Bean
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
@Resource(uri='/people')
class Person {
String firstName
String lastName
}
privateaccess $ cat Widget.java
public class Widget {
private int size = 42;
}
privateaccess $
privateaccess $ cat Demo.groovy
class Demo {
static void main(args) {
~ $ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
~ $
~ $ cat Doit.java
public class Doit {
public static void main(String[] a) {
System.out.println("Hi");
}
groovy:000> initialMap = [name: 'Jeff', company: 'OCI']
===> [name:Jeff, company:OCI]
groovy:000>
groovy:000> secondMap = initialMap.collectEntries { k, v ->
groovy:001> ["-$k", v]
groovy:002> }
===> [-name:Jeff, -company:OCI]
groovy:000>
groovy:000> println "Initial Map: $initialMap"
Initial Map: [name:Jeff, company:OCI]
~ $ mn create-app --features swagger-java withswagger
| Generating Java project...
| Application created at /Users/jeffbrown/withswagger
~ $
~ $
~ $ mn create-app withoutswagger
| Generating Java project...
| Application created at /Users/jeffbrown/withoutswagger
~ $
~ $
private Function<String, Mono<? extends Orders>> keyToOrder(RedisReactiveCommands<String, String> commands) {
return { key ->
Flux<KeyValue<String, String>> values = commands.hmget(key, "price", "description")
Map map = [:]
return values.reduce(map, (all, keyValue)= {all.put(keyValue.getKey(), keyValue.getValue())
return all
}).map({entries -> ConvertibleValues.of(entries)})
.flatMap({entries ->
String description = entries.get("description", String.class).orElseThrow({ new IllegalStateException("No description")})
BigDecimal price = entries.get("price", BigDecimal.class).orElseThrow({new IllegalStateException("No price")})