Skip to content

Instantly share code, notes, and snippets.

View lucamolteni's full-sized avatar
🏠
Working from home

Luca Molteni lucamolteni

🏠
Working from home
View GitHub Profile
@lucamolteni
lucamolteni / gist:4adc3b256d28fd0adf12
Created March 30, 2015 08:43
Request based dispatcher in com.squareup.okhttp.mockwebserver.MockWebServer
class AurumDispatcher extends QueueDispatcher {
val requestMap = new mutable.HashMap[String, BlockingQueue[MockResponse]]
override def dispatch(request: RecordedRequest): MockResponse = {
val key = requestMap.keySet.filter(k => request.getPath.startsWith(k))
val req: Set[Option[BlockingQueue[MockResponse]]] = key.map(requestMap.get)
val response: Set[Option[MockResponse]] = req.map(optQueue => optQueue.map(q => q.take()))
response.headOption.orNull.orNull.asInstanceOf[MockResponse]
}
module Main where
import Control.Monad
main :: IO ()
main = do putStrLn "Enter the amount of line to read"
s <- readLn :: IO Int
putStrLn ("Now enter " ++ show s ++ " lines ")
elements <- replicateM s getLine
let result = doSomething elements
While constructing the BuildPlan the following exceptions were encountered:
-- Failure when adding dependencies:
containers: needed (>=0.2 && <0.5), 0.5.6.2 found (latest is 0.5.6.3)
directory: needed (>=1 && <1.2), 1.2.2.0 found (latest is 1.2.4.0)
process: needed (>=1 && <1.2), 1.2.3.0 found (latest is 1.3.0.0)
needed for package: hsc2hs-0.67.20120610
Verifying that +volothamp is my blockchain ID. https://onename.com/volothamp
module Main where
import Data.WAVE
import Control.Monad
import Data.List
main :: IO ()
main = do
f <- getWAVEFile "example.wav"
let samples = waveSamples f
@lucamolteni
lucamolteni / gist:bf91e16a313ed7dcf919
Created November 6, 2015 10:48
What if Gen[T] were an instance of Applicative?
val myGen = for {
a <- arbitrary[String]
b <- arbitrary[String]
c <- arbitrary[String]
d <- arbitrary[String]
} yield MyClass(a, b, c, d)
============================= Much better
def str = arbitrary[String]
@lucamolteni
lucamolteni / gist:3a8f76af4c1200cdcd1b
Created March 6, 2016 09:36
Trying to mapM_ print a non existing expression
No instance for (Foldable ((->) a0)) arising from a use of ‘mapM_’
In a stmt of a 'do' block: mapM_ print log
In the expression:
do { newPlayer1 <- movePlayerLoop player1;
let log1 = initialState ++ ...;
mapM_ print log1;
newPlayer2 <- movePlayerLoop player2;
.... }
In an equation for ‘loop’:
loop initialState player1 player2
@lucamolteni
lucamolteni / gist:1c6aeff757984de5425d
Created March 9, 2016 10:12
OptionT vs traverseM
package com.bitgold.services
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Future, _}
import scalaz.OptionT._
import scalaz.Scalaz._
import scalaz.{OptionT, Scalaz}
class Comparison {
@lucamolteni
lucamolteni / gist:4bc246d1bf2f285af725
Created March 9, 2016 10:15
Idea not inferring type of traverseM correctly
package com.bitgold.services
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scalaz.Scalaz._
class Comparison {
def function1(inputParam: String): Future[Option[String]] = ???
module Main where
import Lib
import Data.Maybe
data Product = Product String
deriving (Show, Eq)
data ProductInfo = ProductInfo Product Int
deriving (Show, Eq)