Skip to content

Instantly share code, notes, and snippets.

@aloiscochard
aloiscochard / fun-deps.scala
Last active Sep 11, 2016
Fun with fun-deps in scala.
View fun-deps.scala
/*
object Test0 {
import scalaz.meta.Foo._
val s: String = 1024.bar
val i: Int = "test".bar
println(s) // bar
println(i) // 42
}
*/
@aloiscochard
aloiscochard / scala-kinds.md
Created Jan 17, 2016
Scala - Identifying Kinds
View scala-kinds.md

Identification scheme for Scala kind annotations.

The number of parameters is followed by an optional list of of modifiers, starting with a letter to indicate the parameter rank and optionally swapping the case from the previous letter in case the type at this position is also higher kinded.

Examples:

  • [_]
    • 1
  • [_, _]
    • 2
@aloiscochard
aloiscochard / oplog.hs
Created Jan 18, 2015
Tailing MongoDB OpLog in Haskell
View oplog.hs
{-# LANGUAGE OverloadedStrings #-}
module Mongolito where
import Control.Exception
import Control.Monad.IO.Class (liftIO)
import Database.MongoDB
import System.Log.Logger
localDb :: Database
localDb = "local"
@aloiscochard
aloiscochard / 0-common.Module.scala
Last active Sep 11, 2016
Dependency Injection in Scala without Cake Pattern
View 0-common.Module.scala
package com.acme
import com.typesafe.config.Config
trait Module {
implicit def config: Config
}
View Transfigure.scala
package com.timeout
import scala.language.higherKinds
import scalaz._
trait Transfigure[A, B, T] {
def apply(x: A, f: B): T
}
View gist:10062325

"A designer knows he has achieved perfection not when there is nothing left to add,but when there is nothing left to take away." - Antoine de Saint-Exupéry

"One person's syntax is another person's semantics." -- Joseph Goguen

"Ugly programs are like ugly suspension bridges: they're much more liable to collapse than pretty ones, because the way humans (especially engineer-humans) perceive beauty is intimately related to our ability to process and understand complexity. A language that makes it hard to write elegant code makes it hard to write good code." - Eric S. Raymond

"It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures." - Alan J. Perlis

"Simple things should be simple and complex things should be possible." - Alan Kay

@aloiscochard
aloiscochard / Compute.scala
Created Dec 9, 2013
Compute: A very simple language for addition/substraction.
View Compute.scala
import scala.util.parsing.combinator._
import scala.util.matching._
object Compute {
sealed trait Expression
object Expression {
case class Literal(value: Int) extends Expression
case class Apply(operator: Operator, lhs: Expression, rhs: Expression) extends Expression
@aloiscochard
aloiscochard / Action.scala
Created Dec 1, 2013
Slick monadic Actions
View Action.scala
package slick
/**
* This is some code extracted from TimeOut codebase, demonstrating:
* - Use of tag typed to avoid mixing session of different DB
* - The use of the Reader Monad to compose Actions together and defer the choice of async/sync computation
*
* I remove the part where we can say if our operation are read only or not (to use different connection), in order to
* make things easier.
**/
@aloiscochard
aloiscochard / qsbt.sh
Last active Mar 5, 2018
QuickSBT - Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
View qsbt.sh
#!/usr/bin/env bash
############
# QuickSBT #
############
# Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
# http://github.com/aloiscochard / https://gist.github.com/4698501
# Error format for SBT, and shortcut to open SBT quickfix file :
@aloiscochard
aloiscochard / field.scala
Created Apr 13, 2012
Scala DSL design: Avoiding TupleX boilerplate using HList
View field.scala
package object field {
case class Field[T]()
val name = Field[String]()
val age = Field[Int]()
val admin = Field[Boolean]()
}
You can’t perform that action at this time.