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 java.lang.reflect.Field; | |
import java.util.Collection; | |
import java.util.stream.Stream; | |
import java.util.stream.Collectors; | |
public interface AutoCloseable2 extends AutoCloseable { | |
@Override | |
public default void close() throws Exception { | |
for (Field field : getClass().getDeclaredFields()) { |
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 ObjectMapper | |
enum Event { | |
case ringing | |
case incomingSound(instant: Int64, samples: Data) | |
case outgoingSound(instant: Int64, samples: Data) | |
case hangUp | |
} | |
extension Event : ImmutableMappable { |
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 jp.segfault.playground.aswj | |
import com.google.inject.Inject | |
import com.google.inject.Singleton | |
import javax.ws.rs.GET | |
import javax.ws.rs.Path | |
import javax.ws.rs.Produces | |
import javax.ws.rs.core.MediaType | |
import javax.ws.rs.core.Response |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<Response> | |
<Say voice="alice">Enjoy! Enjoy! Enjoy!</Say> | |
<Play>http://demo.twilio.com/docs/classic.mp3</Play> | |
</Response> |
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 shapeless.CNil | |
import shapeless.Coproduct | |
import shapeless.PolyDefns.Case1 | |
import shapeless.ops.coproduct.Basis | |
import shapeless.ops.coproduct.Remove | |
trait Unfold[F, A, C <: Coproduct] { | |
type Out = Option[C] | |
def apply(a: A): Out | |
} |
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
object Mutex { | |
def lock[T](path: String)(f: => T): T = { | |
val out = new java.io.FileOutputStream(path) | |
try { | |
val lock = out.getChannel().lock() | |
try f | |
finally lock.release() | |
} | |
finally out.close() | |
} |
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
object Main extends App { | |
val a = Seq("a", "b", "c") | |
// syntax #1 | |
{ | |
import MyCoproductSyntax1._ | |
for (username <- a; password <- a) { | |
UserService.authenticate(username, password).foldTo[Unit] | |
.caseOf[Authenticated] (_ => println("You just logged in!")) |
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 scala.concurrent.Future | |
import scala.concurrent.Promise | |
import scala.concurrent.ExecutionContext.Implicits.global | |
trait RecursiveFuture[+A] { lhs => | |
def get: Future[Option[(A, RecursiveFuture[A])]] | |
def flatMap[B](f: A => RecursiveFuture[B]): RecursiveFuture[B] = | |
new RecursiveFuture[B] { |
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.google.cloud.datastore.testing.LocalDatastoreHelper | |
commands += Command.command("datastoreRun") { state => | |
val helper = LocalDatastoreHelper.create(1.0) | |
helper.start() | |
atExit { | |
helper.stop() | |
} | |
addSystemPropertiesTo(state)(Seq( | |
"datastore.host" -> helper.getOptions.getHost |
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.google.cloud.datastore._ | |
import com.google.cloud.datastore.testing._ | |
object Main extends App { | |
def benchmark[A](title: String)(f: => A): A = { | |
val t0 = System.currentTimeMillis() | |
val o: A = f | |
val t1 = System.currentTimeMillis() | |
println(title) |