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
let types = /private/tmp/dhall-kubernetes/types.dhall | |
let defaults = /private/tmp/dhall-kubernetes/defaults.dhall | |
let deployment: types.Deployment = | |
defaults.Deployment | |
//{ | |
metadata = defaults.ObjectMeta //{ name = "nginx" }, | |
spec = Some ( | |
defaults.DeploymentSpec | |
//{ |
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 Tree { | |
sealed trait Tree[A] | |
case class Leaf[A](a: A) extends Tree[A] | |
case class Node[A](left: Tree[A], right: Tree[A]) extends Tree[A] | |
def translate[A, B, C, F[_], E](t: Tree[A], check: (A, B) => Boolean, newState: B => B, endState: (A, B) => C, err: A => E)(implicit F: MonadError[F, E]): StateT[F, B, Tree[C]] = t match { | |
case Leaf(a) => StateT(s => if (check(a, s)) F.raiseError(err(a)) else F.pure((newState(s), Leaf(endState(a, s))))) | |
case Node(left, right) => | |
implicit val A = Apply[StateT[F, B, ?]] | |
(translate(left, check, newState, endState, err), translate(right, check, newState, endState, err)).mapN(Node.apply) |
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
def forLoop[A, C]( | |
from: A, | |
continue: A => Boolean, | |
next: A => A, | |
compute: (C, A) => C, | |
acc: C): C = { | |
@tailrec | |
def go(from: A, acc: C): C = { | |
if (continue(from)) | |
go(next(from), compute(acc, from)) |
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
// From haskell "Monoidal Parsing—Edward Kmett" | |
import cats.implicits._ | |
final case class Balance(l: Int, r: Int) | |
object Balance { | |
val EMPTY = Balance(0, 0) | |
val LEFT = Balance(0, 1) | |
val RIGHT = Balance(1, 0) | |
} |
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
trait Toto[F[_]] { | |
def hello[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
implicit val Fun = new Toto[List] { | |
override def hello[A, B](fa: List[A])(f: A => B): List[B] = fa.map(f) | |
} | |
implicit class FunImplicits[F[_], A](t: F[A]) { | |
def !!!![B](f: A => B)(implicit toto: Toto[F]): F[B] = toto.hello(t)(f) |
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
def value(i: List[Int]): Trampoline[List[Int]] = i match { | |
case Nil => Free.pure(Nil) | |
case head :: tail => Free.defer(value(tail)).flatMap { l => Free.pure(head + 1 :: l) } | |
} | |
import cats.implicits._ | |
println(value((1 to 10).toList).run) // List(2, 3, 4, 5, 6, 7, 8, 9, 10, 11) |
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
for i in 1 2 3 4 5; do nslookup -q=TXT "_cloud-netblocks$i.googleusercontent.com" 8.8.8.8 | tr ' ' '\n' | grep ip4 | cut -d':' -f2 ; done |
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
val builder = new KStreamBuilder | |
val textLines = builder.stream[String, String]("TextLinesTopic") | |
val pattern = Pattern.compile("\\W+") | |
val wordCounts: KTable[String, String] = textLines | |
.flatMapValues(line => pattern.split(line.toLowerCase).toIterable.asJava) | |
.groupBy { case (_, word: String) => word } | |
.count("Counts") | |
.mapValues(_.toString) | |
.to(Serdes.String, Serdes.String, "WordsWithCountsTopic") |
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
/** | |
* Handle records with a timestamp in their Avro value. | |
* Expects a LONG field named "timestamp". | |
* Any problem makes this extractor return the record's internal timestamp. | |
*/ | |
public class InValueTimestampExtractor implements TimestampExtractor { | |
@Override | |
public long extract(ConsumerRecord<Object, Object> record) { | |
if (record != null && record.value() != null) { |
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.reflect.macros.blackbox.Context | |
import scala.language.experimental.macros | |
class LoggerImpl(val c: Context) { | |
import c.universe._ | |
def getClassSymbol(s: Symbol): Symbol = if (s.isClass) s else getClassSymbol(s.owner) | |
def logImpl(msg: Expr[String]): Expr[Unit] = { | |
val cl = getClassSymbol(c.internal.enclosingOwner).toString | |
val time = c.Expr[String](q"new java.util.Date().toString") |
NewerOlder