Skip to content

Instantly share code, notes, and snippets.

View TrustNoOne's full-sized avatar

Giovanni Caporaletti TrustNoOne

View GitHub Profile
import cats._
import Tree._
import scala.annotation.tailrec
sealed trait Tree[+A] {
def elem: A
def children: List[Tree[A]]
def flattenNodes = TreeFoldable.foldLeft(this, List.newBuilder[A])((b, x) ⇒ b += x).result
import java.time.ZoneOffset
import com.sksamuel.elastic4s.admin.CreateIndexTemplateDefinition
import com.sksamuel.elastic4s.mappings.{DynamicTemplateDefinition, TypedFieldDefinition}
import com.sksamuel.elastic4s.searches.QueryDefinition
import com.sksamuel.elastic4s.searches.aggs.{AggregationDefinition, FiltersAggregationDefinition, RangeAggregationDefinition}
import com.sksamuel.elastic4s.{ElasticDsl, IndexAndType, Indexable}
import org.elasticsearch.action.DocWriteResponse.Result
import org.elasticsearch.action.update.UpdateResponse
import org.elasticsearch.search.aggregations.bucket.histogram.{DateHistogramInterval, ExtendedBounds}
@TrustNoOne
TrustNoOne / higherkinds.scala
Created April 29, 2016 11:48
Higher Kinded type declarations in scala
trait Y
trait T[X]
trait TSub[X <: Y] extends T[X] // bounded
trait TCo[+X]
trait TCoSub[+X <: Y] extends TCo[X] // bounded
trait TContra[-X]
trait TContraSub[-X <: Y] extends TContra[X] // bounded
@TrustNoOne
TrustNoOne / EveryRandomObject.scala
Last active October 13, 2016 12:33
Shapeless Random case class/sealed trait family generator
import shapeless._
import shapeless.ops.coproduct.ToHList
import shapeless.ops.hlist.ToTraversable
@annotation.implicitNotFound(msg = "No EveryRandomObject found for ${A}. ${A} could not be a sealed hierarchy or one of its subtypes could not have a RandomObject instance available")
trait EveryRandomObject[A] {
def generate(): List[A]
}
object EveryRandomObject {
@TrustNoOne
TrustNoOne / PersistentViewSource.scala
Last active August 29, 2015 14:25
PersistentView exposed as a Source[T, _]
/*
* Copyright (c) 2015 ReaQta Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
@TrustNoOne
TrustNoOne / keybase.md
Created September 30, 2014 08:39
keybase.md

Keybase proof

I hereby claim:

  • I am TrustNoOne on github.
  • I am gcaporaletti (https://keybase.io/gcaporaletti) on keybase.
  • I have a public key whose fingerprint is 4260 5533 F0CB F8B4 0213 F8AE 6D20 9C95 563E 7516

To claim this, I am signing this object:

@TrustNoOne
TrustNoOne / EvilQuiz.java
Last active December 31, 2015 17:59
Evil quiz
public class EvilQuiz {
// Does this compile? Does it throw something? Does it print something? etc. etc.
public static void main(String[] args) throws Exception {
System.out.println(ohshieeeee());
}
private static long ohshieeeee() {
try {
throw null;
} finally {
@TrustNoOne
TrustNoOne / ClusterTestConfig.scala
Last active December 29, 2015 10:09
Akka cluster test
package clustertest
import akka.remote.testkit.MultiNodeConfig
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import com.typesafe.config.ConfigValueFactory._
import java.util.ArrayList
import scala.collection.mutable.ListBuffer
object ClusterTestConfig extends MultiNodeConfig {