Skip to content

Instantly share code, notes, and snippets.

View gbersac's full-sized avatar

Guillaume Bersac gbersac

  • 42
  • Paris
  • 16:37 (UTC -12:00)
View GitHub Profile
trait RNG {
def nextInt: (Int, RNG) // Should generate a random `Int`. We'll later define other functions in terms of `nextInt`.
}
object RNG {
// NB - this was called SimpleRNG in the book text
case class Simple(seed: Long) extends RNG {
def nextInt: (Int, RNG) = {
val newSeed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFFL // `&` is bitwise AND. We use the current seed to generate a new seed.
@gbersac
gbersac / fix_brew_42.sh
Created January 28, 2017 16:46
Shell to update brew sur mac 42
#!/bin/sh
#fix_brew.sh - mcartier
#you can keep ur brew if u need ur formulas
if [ "$1" = "--keep" ];
then
echo "actual brew not removed";
else
trait Functor[F[_]] {
def map[A,B](fa: F[A])(f: A => B): F[B]
def distribute[A,B](fab: F[(A, B)]): (F[A], F[B]) =
(map(fab)(_._1), map(fab)(_._2))
def codistribute[A,B](e: Either[F[A], F[B]]): F[Either[A, B]] = e match {
case Left(fa) => map(fa)(Left(_))
case Right(fb) => map(fb)(Right(_))
}
// This new data type will employ Scala’s type system to gain two static guarantees. We want our code to not compile if it violates these invariants:
// - If we hold a reference to a mutable object, then nothing can observe us mutat- ing it.
// - A mutable object can never be observed outside of the scope in which it was created.
/**
* For state thread, state transi- tion, state token, or state tag
* A local-effects monad.
*
* A: type of the mutable value.
* S: represents the ability to mutate state
trait Functor[F[_]] {
def map[A,B](fa: F[A])(f: A => B): F[B]
def distribute[A,B](fab: F[(A, B)]): (F[A], F[B]) =
(map(fab)(_._1), map(fab)(_._2))
def codistribute[A,B](e: Either[F[A], F[B]]): F[Either[A, B]] = e match {
case Left(fa) => map(fa)(Left(_))
case Right(fb) => map(fb)(Right(_))
}
@gbersac
gbersac / rinkebi_adress.txt
Created September 28, 2017 14:48
rinkebi adress
0x7adf277b6d4e4034fd1d230b9972824418a73566
@gbersac
gbersac / test_resources_extractor.scala
Created March 22, 2018 14:44
File from test resources folder #scala
import scala.io.Source
def fileToString(fileName: String, folder: String): String =
Source.fromURL(getClass.getClassLoader.getResource(folder + fileName)).mkString
@gbersac
gbersac / cats_either_list_sequence.scala
Created April 23, 2018 13:12
cats sequence on either list #scala #cats
/* for ammonite users
interp.load.ivy("org.typelevel" %% "cats-core" % "1.0.1")
interp.configureCompiler(_.settings.YpartialUnification.value = true)
@
*/
import cats.instances.list._
import cats.instances.either._
import cats.syntax.traverse._
@gbersac
gbersac / kafka_producer_listener.sh
Last active August 6, 2018 13:50
kafka producer / listener
#! /bin/sh
if [ $# -lt 2 ]; then
echo "$0 container topic"
exit 1
fi
# listener
CONTAINER="$1"
TOPIC="$2"
@gbersac
gbersac / alpakka_deserialization_error.scala
Last active August 7, 2018 09:22
#akka #kafka consumer deserialization error
/* for ammonite users
interp.load.ivy("com.typesafe.akka" %% "akka-stream-kafka" % "0.22")
interp.load.ivy("com.typesafe.play" %% "play-json" % "2.6.7")
@
*/
import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{ Failure, Success }