Skip to content

Instantly share code, notes, and snippets.

View gclaramunt's full-sized avatar

Gabriel Claramunt gclaramunt

View GitHub Profile
@gclaramunt
gclaramunt / Trick.scala
Last active August 29, 2015 13:56
Evil trick using implicits to customize error messages in a validation
abstract class MyTry[T] {
def get: T
def flatMap[U](f: T => MyTry[U]): MyTry[U]
def map[U](f: T => U): MyTry[U]
def filter(p: T => Boolean)(implicit msg:Msg[T]): MyTry[T]
}
object MyTry {
def apply[T](r: => T): MyTry[T] =
@gclaramunt
gclaramunt / all.scm
Created April 22, 2014 01:35
Lot of exercises from "The Little Schemer"
#lang scheme
(define atom? (let ((f1 pair?) (f2 not)) (lambda (x) (f2 (f1 x)))))
(define lat?
(lambda (lat)
(cond
((null? lat) #t)
((atom? (car lat)) (lat? (cdr lat)))
(else #f)
)))
@gclaramunt
gclaramunt / Factory.scala
Created June 10, 2014 16:29
Attempt to a typesafe factory patter in scala
/**
* Created by claramun on 6/9/14.
*/
trait A
trait B { val value:String }
trait X1A extends A
trait X1B extends B
@gclaramunt
gclaramunt / unboxed.hs
Created July 11, 2014 16:38
Dangeours haskell
{-# LANGUAGE MagicHash #-}
-- | Main entry point to the application.
module Main where
import GHC.Exts
-- | The main entry point.
main :: IO ()
main = do
putStrLn $ showUnboxedInt 1#
@gclaramunt
gclaramunt / middle.hs
Created July 11, 2014 21:59
Middle of a list with the hare and tortoise method
-- | Main entry point to the application.
module Main where
-- | The main entry point.
main :: IO ()
main = do
putStrLn "Welcome to FP Haskell Center!"
putStrLn "Have a good day!"
putStrLn $ show $ middle [1]
putStrLn $ show $ middle [1,2]
@gclaramunt
gclaramunt / HList.hs
Created February 10, 2015 18:17
Heterogeneous list in Haskell
{-# LANGUAGE GADTs #-}
module HLists where
data Hlist where
HNil :: Hlist
HCons :: a-> Hlist -> Hlist
HConsShw :: Show a => a-> Hlist -> Hlist -- show here is horrible
instance Show Hlist
where show HNil = ""
show (HCons a l) = "?" ++ ","++ show l
def fun(k:Int)={
val x = f(k)
val y = g(x)
val z = h(y)
x+y+z
}
// If f,g,h return Option
def fun1(k:Int)=for {
combinations:: String -> [String]
combinations [] = []
combinations (x:xs) = [x] : combs ++ fmap (x :) combs
where combs = combinations xs
@gclaramunt
gclaramunt / git-dmz-flow.md
Last active August 29, 2015 14:27 — forked from djspiewak/git-dmz-flow.md
Git DMZ Flow

Git DMZ Flow

I've been asked a few times over the last few months to put together a full write-up of the Git workflow we use at RichRelevance (and at Precog before), since I have referenced it in passing quite a few times in tweets and in person. The workflow is appreciably different from GitFlow and its derivatives, and thus it brings with it a different set of tradeoffs and optimizations. To that end, it would probably be helpful to go over exactly what workflow benefits I find to be beneficial or even necessary.

  • Two developers working on independent features must never be blocked by each other
    • No code freeze! Ever! For any reason!
  • A developer must be able to base derivative work on another developer's work, without waiting for any third party
  • Two developers working on inter-dependent features (or even the same feature) must be able to do so without interference from (or interfering with) any other parties
  • Developers must be able to work on multiple features simultaneously, or at lea
@gclaramunt
gclaramunt / Graph.scala
Created December 19, 2008 02:20
Dijkstra shortest path - my first Scala program
package dfs2;
abstract class Graph {
type Edge
type Node <: NodeIntf
abstract class NodeIntf {
def connectWith(node: Node): Edge
}
def nodes: Set[Node]
def edges: Set[Edge]