This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def readerDistributive[I]: Distributive[({type R[X]=Reader[I, X]})#R] = new Distributive[({type R[X]=Reader[I, X]})#R] { | |
override def distributeImpl[G[_], A, B](fa: G[A])(f: (A) => Reader[I, B])(implicit gf: Functor[G]): Reader[I, G[B]] = | |
Reader { i => | |
fa.map(a => f(a)(i)) | |
} | |
override def map[A, B](fa: Reader[I, A])(f: (A) => B): Reader[I, B] = fa.map(f) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/bin/java -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.softwaremill.kmq; | |
import org.apache.kafka.common.serialization.Serdes; | |
import org.apache.kafka.streams.KafkaStreams; | |
import org.apache.kafka.streams.StreamsConfig; | |
import org.apache.kafka.streams.processor.Processor; | |
import org.apache.kafka.streams.processor.ProcessorContext; | |
import org.apache.kafka.streams.processor.StateStoreSupplier; | |
import org.apache.kafka.streams.processor.TopologyBuilder; | |
import org.apache.kafka.streams.state.Stores; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("user/{userId}") | |
public String getUser(@PathParam("userId") userId) { | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("/hello") | |
public class Hello { | |
@GET | |
@Produces(MediaType.TEXT_PLAIN) | |
public String helloWorld() { | |
return "Hello World"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hello.java | |
public class Hello { | |
public String helloWorld() { | |
return "Hello World"; | |
} | |
} | |
// HelloEndpoints.java | |
public class HelloEndpoints { | |
private Endpoint helloWorldEndpoint(Hello hello) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApplicationBootstrap { | |
public static void main(String[] args) { | |
// 1. create the object graph. Manually, by using "new". Like in the stone age. | |
Hello h = new Hello(); | |
// 2. create a list of all endpoints our application will expose | |
List<Endpoint> endpoints = new ArrayList<Endpoint>(); | |
endpoints.addAll(new HelloEndpoints().endpoints(h)); | |
endpoints.addAll(...); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.softwaremill.sttp._ | |
val sort: Option[String] = None | |
val query = "http language:scala" | |
// the `query` parameter is automatically url-encoded | |
// `sort` is removed, as the value is not defined | |
val request = sttp.get( | |
uri"https://api.github.com/search/repositories?q=$query&sort=$sort") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<K, V> void addToMultimap(ConcurrentHashMap<K, Set<V>> map, K key, V value) { | |
map.compute(key, (k, v) -> { | |
if (v == null) { | |
v = ConcurrentHashMap.newKeySet(); | |
} | |
v.add(value); | |
return v; | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val logDuration: Directive0 = extractRequestContext.flatMap { ctx => | |
val start = System.currentTimeMillis() | |
mapResponse { resp => | |
val took = System.currentTimeMillis() - start | |
logger.info(s"[${resp.status.intValue()}] ${ctx.request.method.name} " + | |
s"${ctx.request.uri} took: ${d}ms") | |
resp | |
} | |
} |