Skip to content

Instantly share code, notes, and snippets.

View Baccata's full-sized avatar

Olivier Mélois Baccata

View GitHub Profile
@Baccata
Baccata / Bool.scala
Created February 25, 2015 22:44
Implementation of typelevel booleans and integers using type projections
package baccata
/**
* Inspired from Grant Beaty's Scunits
*/
trait Bool {
type branch[B,T <: B, E <: B] <: B // typelevel if-then-else
type not <: Bool
type or[R <: Bool] <: Bool
type and[R <: Bool] <: Bool
module Main where
main = putStrLn (show (fforall (\x -> (x >= -1000)) (setInt)))
type Set a = a -> Bool
setInt :: Set Int
setInt = \x -> True
--filtering the range with the set function and checking if all elements from the set satisfy the predicate
fforall :: Restrict a => (a -> Bool) -> Set a -> Bool
import shapeless._
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// THE IMPLICIT CLASS THAT ALLOWS TO CALL #copy ON ANY SEALED TRAIT INSTANCE
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
object copySyntax {
implicit class CopySyntax[TypeToCopy](thingToCopy: TypeToCopy) {
@Baccata
Baccata / cloneAllBitbucket.sh
Last active July 1, 2016 12:40
Cloning all the repos under a user or team from bitbucket
#!/bin/bash
#Script to get all repositories under a user or team from bitbucket
#Usage: cloneAllBitbucket [username] [user_or_team]
curl -u ${1} https://api.bitbucket.org/1.0/users/${2} \
| jsawk 'return this.repositories.map(function(item){return item.name;})' \
| jsawk -n 'out(this)' \
| sed -e 's/^"//' -e 's/"$//' > repos
for repo_name in `cat repos`

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
import com.google.protobuf.Descriptors.{MethodDescriptor, ServiceDescriptor}
import com.trueaccord.scalapb.compiler.FunctionalPrinter.PrinterEndo
import com.trueaccord.scalapb.compiler._
import scala.collection.JavaConverters._
final class MonixGrpcPrinter(service: ServiceDescriptor,
override val params: GeneratorParams)
extends DescriptorPimps {
import cats.free.Free
import cats.{ Monad, ~> }
object KVStoreExample {
sealed trait KVStore[A]
case class Put[T](key: String, value: T) extends KVStore[Unit]
case class Get[T](key: String) extends KVStore[Option[T]]
object KVStore {
@Baccata
Baccata / ActorInterpreter.scala
Last active April 1, 2017 20:17
Transforming a pure stateful computation into an asynchronous effectful computation
import akka.actor.{ Actor, ActorSystem, Props }
import akka.util.Timeout
import cats._
import cats.data.State
class ActorInterpreter[G[_], StateData](
actorSystem: ActorSystem,
initialData: StateData,
stateInterpreter: G ~> Lambda[A => State[StateData, A]]
)(implicit t: Timeout, ec: ExecutionContext)
// *****************************************************************************
// Projects
// *****************************************************************************
lazy val `polykind-tests` =
project
.in(file("."))
.enablePlugins(AutomateHeaderPlugin, GitVersioning)
.settings(settings)
.settings(
@Baccata
Baccata / meeting.md
Created June 26, 2017 12:04 — forked from qingwei91/meeting.md
about meeting

Fantastic meetings and where to find them

Anecdotally most people in software industry hates meetings, because meeting is a soul-sucking dementor. Jokes aside, I think it's fair to say that people feel meeting is taking too much time, and the process is often painful.

In this post, I'll try to provide a few rules of thumb that I believe can make meeting less painful and more efficient.

Rule 1: Always reiterate your goal before start

How many times you attend a meeting without a goal in mind?