Skip to content

Instantly share code, notes, and snippets.

View aloiscochard's full-sized avatar
🪄

Aloïs Cochard aloiscochard

🪄
View GitHub Profile
package com.timeout
import scala.language.higherKinds
import scalaz._
trait Transfigure[A, B, T] {
def apply(x: A, f: B): T
}
package org.opensource.aloiscochard;
import java.util.Map;
import java.util.TreeMap;
/**
* This class handle simple translation of index (coordonate).<br>
* <i>N.B. can be used when translating index during string manipulation.</i>
* @author alois.cochard@gmail.com
*
@aloiscochard
aloiscochard / gist:982914
Created May 20, 2011 13:45
Simple Dependency Injector
/////////////////////////
// Dependency Injector //
/////////////////////////
import scala.collection.immutable.HashMap
object Injector {
private var registry = new HashMap[java.lang.Class[_], Any]
def inject[T : Manifest] : T = {
@aloiscochard
aloiscochard / ParallelPluginComponent.scala
Created August 24, 2011 18:37
Scala Parallel Compiler Plugin
import java.util.concurrent.ScheduledThreadPoolExecutor
import java.util.concurrent.TimeUnit
import scala.actors.scheduler.ExecutorScheduler
import scala.tools.nsc
import nsc.Phase
import nsc.plugins.PluginComponent
abstract class ParallelPluginComponent extends PluginComponent {
import global._
@aloiscochard
aloiscochard / scalax-ahlist.scala
Created January 3, 2012 12:00
Scala Association Heterogeneous List (map with heterogeneous values)
// Association Heterogeneous List
object AHListTest {
object AHList {
def apply[K]() = new AHNil[K]()
}
sealed trait AHList[K] {
def get[V : Manifest](k: K): Option[V] = None
def get[V : Manifest](k: K, default: V): V = get[V](k).getOrElse(default)
@aloiscochard
aloiscochard / field.scala
Created April 13, 2012 17:45
Scala DSL design: Avoiding TupleX boilerplate using HList
package object field {
case class Field[T]()
val name = Field[String]()
val age = Field[Int]()
val admin = Field[Boolean]()
}
@aloiscochard
aloiscochard / Application.scala
Created February 22, 2012 12:17
Service mocking example using Sindi
package application
import sindi._
import service.a._
import service.x.module._
object AppContext extends Context {
override lazy val modules = new ServiceXModule :: Nil
@aloiscochard
aloiscochard / Compute.scala
Created December 9, 2013 11:35
Compute: A very simple language for addition/substraction.
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 / scala-kinds.md
Created January 17, 2016 11:06
Scala - Identifying Kinds

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 January 18, 2015 11:35
Tailing MongoDB OpLog in Haskell
{-# 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"