Skip to content

Instantly share code, notes, and snippets.

@gigiigig
gigiigig / changereturntype.scala
Created June 29, 2017 10:16
Change Return type of a function
{
trait Aux[T] {
type R
def apply(t: T): R
}
implicit val sa = new Aux[String] {
type R = Boolean
def apply(s: String): Boolean = s.isEmpty
}
Finatra
No Payload
Running 30s test @ http://localhost:8888/hi
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 20.43ms 30.84ms 376.23ms 86.54%
Req/Sec 3.48k 750.12 14.54k 79.75%
1249354 requests in 30.04s, 86.98MB read
scala> sealed trait Op
defined trait Op
scala> case class Foo(s: String) extends Op
defined class Foo
scala> case class Ciao(i: Int) extends Op
defined class Ciao
scala> case class Bar(op: Op, b: Boolean)
@gigiigig
gigiigig / # neovim - 2016-03-31_12-27-10.txt
Created March 31, 2016 11:38
neovim (neovim/neovim/neovim) on OS X 10.11.4 - Homebrew build logs
Homebrew build logs for neovim/neovim/neovim on OS X 10.11.4
Build date: 2016-03-31 12:27:10
import scalaz._
import Scalaz._
/** I think there are two use cases where implicits are very useful:
* TypeClasses
* Pimp or Rich pattern
*
* Let's start with typeclasses, probably the more popular,
* e.g. Collection library in Scala is all TC based, look for CanBuildFrom
*/
@gigiigig
gigiigig / dumbcinfig.scala
Last active March 2, 2016 11:17
Simple config example
trait Config {
val timeout: Int = 1
val interval: Int = 2
def wantToChangeThis: Int
}
object DefaultConfig extends Config {
val wantToChangeThis: Int = 34
}
@gigiigig
gigiigig / caseclassequality.scala
Created February 19, 2016 10:49
Inheritance brake class eqaulity
trait Foo {
case class Bar(i: Int, s: String)
}
val fb1 = new Foo {}.Bar(3, "ciao")
val fb2 = new Foo {}.Bar(3, "ciao")
val equal = fb1 == fb2
println(s"equal: ${equal}") // equal: false
@gigiigig
gigiigig / simplecomputation.scala
Last active January 25, 2016 22:55
First simple type computation
object console extends App {
trait Nat {
type Plus[That <: Nat] <: Nat
}
trait _0 extends Nat {
type Plus[That <: Nat] = That
}
trait Succ[N <: Nat] extends Nat {
type Plus[That <: Nat] = Succ[N#Plus[That]]
import shapeless._
import shapeless.record._
import shapeless.ops.record._
import shapeless.ops.hlist._
object console extends App {
object sql {
@gigiigig
gigiigig / caseclasscontains.scala
Last active November 11, 2015 17:36
Check if a case class contain another.
import shapeless._
import shapeless.record._
import shapeless.ops.hlist.Selector
object console extends App {
trait HListContains[T <: HList, R <: HList]
object HListContains {