Skip to content

Instantly share code, notes, and snippets.

View gclaramunt's full-sized avatar

Gabriel Claramunt gclaramunt

View GitHub Profile
@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
abstract class Blarhg[A] {
def add(x: A, y: A): A
}
abstract class Blejjj[A] extends Blarhg[A] {
def unit: A
}
object ImplicitTest extends App {
implicit object StringBlejjj extends Blejjj[String] {
def add(x: String, y: String): String = x concat y
def unit: String = ""
def sequence[A, B](l: Iterable[A])(fn: A ⇒ Future[B])(implicit ec: ExecutionContext): Future[List[B]] =
l.foldLeft(Future(List.empty[B])) {
(previousFuture, next) ⇒
for {
previousResults ← previousFuture
next ← fn(next)
} yield previousResults :+ next
@gclaramunt
gclaramunt / gist:74698bf8881899f42ad77916c2716946
Last active January 11, 2019 20:06
foldMap and secuence
object FutureUtils {
/**
* Serialises the futures so they execute one after another
* Future.sequence still runs all futures at the same time
*/
def sequence[A, B](l: Iterable[A])(fn: A ⇒ Future[B])(implicit ec: ExecutionContext): Future[Iterable[B]] =
foldM(l, ListBuffer.empty[B]) { (xs, x) => fn(x).map(xs :+ _) }
/**
package demo
import akka.serialization.SerializerWithStringManifest
import scalapb.{GeneratedMessage, GeneratedMessageCompanion}
import scala.reflect.runtime.{universe => ru}
/**
* Custom Serializer/Deserializer for scalapb protobuf generated classes
*/
@gclaramunt
gclaramunt / Playground.hs
Created March 1, 2021 14:10
Plutus Playground Smart Contract
-- A game with two players. Player 1 thinks of a secret word
-- and uses its hash, and the game validator script, to lock
-- some funds (the prize) in a pay-to-script transaction output.
-- Player 2 guesses the word by attempting to spend the transaction
-- output. If the guess is correct, the validator script releases the funds.
-- If it isn't, the funds stay locked.
import Control.Monad (void)
import qualified Data.ByteString.Char8 as C
import Language.Plutus.Contract
import qualified Language.PlutusTx as PlutusTx
@gclaramunt
gclaramunt / Playground.hs
Last active March 2, 2021 14:21
Plutus Playground Smart Contract
-- A game with two players. Player 1 thinks of a secret word
-- and uses its hash, and the game validator script, to lock
-- some funds (the prize) in a pay-to-script transaction output.
-- Player 2 guesses the word by attempting to spend the transaction
-- output. If the guess is correct, the validator script releases the funds.
-- If it isn't, the funds stay locked.
import Control.Monad (void)
import qualified Data.ByteString.Char8 as C
import qualified Data.Text as T
import Language.Plutus.Contract