Skip to content

Instantly share code, notes, and snippets.

View aloiscochard's full-sized avatar
🪄

Aloïs Cochard aloiscochard

🪄
View GitHub Profile
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 [email protected]
*
@aloiscochard
aloiscochard / rest-ws-client.scala
Created May 13, 2011 09:35
Scala REST WebService Client
// Sample usage of ...
// - Dispatch (http://dispatch.databinder.net)
// - SJSON (https://github.com/debasishg/sjson)
// ... to create a basic REST Web Service client for Twitter API
import dispatch._
import scala.reflect.BeanInfo
import sjson.json.Serializer.SJSON
// Model
@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 / JSONPrettyFormat.scala
Created October 11, 2011 18:35
Scala JSON Pretty Formatter
import scala.util.parsing.json._
val prettyFormatter: JSONFormat.ValueFormatter = {
def create(level: Int): JSONFormat.ValueFormatter = (x: Any) => {
x match {
case s: String => "\"" + JSONFormat.quoteString(s) + "\""
case jo: JSONObject =>
"{\n" +
"\t" * (level + 1) +
jo.obj.map({
@aloiscochard
aloiscochard / Stream.scala
Created November 2, 2011 16:06
Scala [In]finite Stream Constructor
import Stream._
/** A possibly finite stream that repeatedly applies a given function to a start value.
*
* @param start the start value of the stream
* @param f the function that's repeatedly applied
* @return the stream returning the possibly finite sequence of values `start, f(start), f(f(start)), ...`
*/
def iterate[A](f: A => A, a: A): Stream[A] = unfold((x: A) => Some((x, f(x))), a)
@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 / 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 / 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 / qsbt.sh
Last active March 5, 2018 21:34
QuickSBT - Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
#!/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 :