This file contains 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
/** | |
* I wrote this while trying to figure out what a monad was and how you would write one. No guarantees that this is | |
* actually a monad or good code at all. | |
* | |
* I wanted this monad to encapsulate side effects and apply them lazily. One interesting observation that I found | |
* from all the println statements was that in order for the bind (flatMap) to not evaluate the side effect was to use | |
* by-name parameters. Not sure if this is really a unit function anymore... | |
*/ | |
object StringOpsMonad extends App { | |
println("-----") |
This file contains 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.io.File | |
import akka.http.javadsl.model.headers.ContentDisposition | |
import akka.http.scaladsl.Http | |
import akka.http.scaladsl.client.RequestBuilding | |
import akka.http.scaladsl.model.{HttpResponse, Uri} | |
import akka.stream.scaladsl._ | |
import akka.stream.{Graph, Materializer, SinkShape} | |
import akka.util.ByteString |
This file contains 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.language.experimental.macros | |
import scala.reflect.macros.blackbox | |
/** | |
* Macro bundle for case class macros. | |
*/ | |
class CaseClassMacrosImpl(val c: blackbox.Context) { | |
import c.universe._ |
This file contains 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 akka.NotUsed | |
import akka.stream.{Attributes, Inlet, SinkShape} | |
import akka.stream.scaladsl.{Sink, Source} | |
import akka.stream.stage._ | |
class OneToOneOnDemandSink[T, +M](sink: T => Sink[T, M]) extends GraphStage[SinkShape[T]] { | |
val in: Inlet[T] = Inlet("OneToOneOnDemandSink.in") | |
override val shape = SinkShape(in) |
This file contains 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
private object LoggerOutputStream { | |
def info(logger: Logger, charset: Charset = StandardCharsets.UTF_8, maxMessageSize: Int = 8192): OutputStream = | |
apply(logger, Level.Info, charset, maxMessageSize) | |
def error(logger: Logger, charset: Charset = StandardCharsets.UTF_8, maxMessageSize: Int = 8192): OutputStream = | |
apply(logger, Level.Error, charset, maxMessageSize) | |
def apply(logger: Logger, level: Level.Value, charset: Charset = StandardCharsets.UTF_8, maxMessageSize: Int = 8192): OutputStream = | |
new LoggerOutputStream(logger, level, charset, maxMessageSize) |
This file contains 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.example | |
class Test { | |
// This works | |
(_: Int).fooImplicit | |
} |
This file contains 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 FixingVarianceErrors { | |
trait InvariantThing[T] | |
trait CovariantThing[+T] { | |
// Fails to compile with error: | |
// Error:(12, 9) covariant type T occurs in invariant position in | |
// type => FixingVarianceErrors.InvariantThing[T] of method thing1 | |
def thing1: InvariantThing[T] |
This file contains 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
git log --shortstat --format="%an" | sed '/^$/d' | awk ' | |
BEGIN { FS = ", " } | |
{ | |
if (match($1, /^ [0-9]+ files? changed/)) { | |
split($2, a, " ") | |
inserts = (a[1] == "")? 0 : a[1] | |
split($3, b, " ") | |
deletes = (b[1] == "")? 0 : b[1] | |
total = (inserts - deletes) | |
print name " " inserts " " deletes " " total |
This file contains 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
case class Inner(a: String, b: Int) | |
case class Outer(a: String, i: Inner) |
This file contains 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.geneious.nucleus.service.util.play.json | |
import play.api.libs.json._ | |
import shapeless._ | |
trait CoproductFormats { | |
implicit val cNilReads: Reads[CNil] = Reads(_ => JsError()) | |
implicit val cNilWrites: Writes[CNil] = Writes(_ => JsNull) |
OlderNewer