Skip to content

Instantly share code, notes, and snippets.

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

Eric Torreborre etorreborre

🏠
Working from home
View GitHub Profile
@etorreborre
etorreborre / wishlist-answer.md
Created August 12, 2021 16:43
Response to "My specs(3?) wishlist"

Prescriptive Structural Syntax

I am sorry but I actually prefer the other style of specification! The main reason is that I think that encourages me to think about writing some text about what I am testing, and why I am testing it this way (that doesn't mean that I necessarily do it :-)).

Enforced Matcher Uniformity

I hear you and I indeed simplified all must expressions to be a must b, and then a must not(b).

@etorreborre
etorreborre / optics-witch.hs
Created July 14, 2021 07:22
Optics with the Witch library
{-# LANGUAGE TemplateHaskell #-}
import qualified Data.Text as T
import Optics as O
import Protolude hiding ((%), from)
import Witch
import Data.Coerce
-- 2 different temperature types
newtype Kelvin = Kelvin Double deriving (Eq, Show, Num)
@etorreborre
etorreborre / concurrent-map.hs
Created December 4, 2020 07:32 — forked from Gabriella439/concurrent-map.hs
Low-tech concurrent hashmap
module ConcurrentMap where
import Control.Concurrent.STM.TVar (TVar)
import Control.Concurrent.STM (STM)
import Data.Hashable (Hashable)
import Data.HashMap.Strict (HashMap)
import Data.Vector (Vector)
import qualified Control.Concurrent.STM.TVar as TVar
import qualified Data.Hashable as Hashable
@etorreborre
etorreborre / afterEachAsync.scala
Last active November 25, 2020 17:51
Add async steps in specs2
import org.specs2.specification.create._
import org.specs2.control.producer.Producer._
/** How to add an async action after each example */
trait AfterEachAsync extends org.specs2.mutable.Specification:
override def map(fs: =>Fragments): Fragments =
super.map(fs.flatMap { f =>
if Fragment.isExample(f) then
emitAsync(List(f, step(afterAsync)))
else
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE PostfixOperators #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeApplications #-}
@etorreborre
etorreborre / deactivate.scala
Created September 16, 2020 07:41
Deactivate implicits in traits scopes with Dotty
import scala.concurrent.ExecutionContext
// this type is used by the implicit search to succeed in finding Not[C]
// when C can not be found as an implicit value
import scala.implicits.Not
trait ImplicitExecutionContextFromExecutionEnv:
/**
@etorreborre
etorreborre / deps.hs
Created June 15, 2020 13:31
Dependencies with RecordWildCards
newService :: Monad m => Logger m -> Tracer m -> Service m
newService Logger {..} Tracer {..} = Service {..}
where
doIt :: Int -> Text -> m ()
doIt n t = do
info "doing it" t
traceIt (show n)
@etorreborre
etorreborre / README.md
Created April 16, 2020 21:41 — forked from dcsobral/README.md
Scala Configurable Warnings

Pull request #8373 implementing issue 333 (but please note differences).

Pull request description follows:

This PR adds a -Wconf compiler flag that allows filtering and configuring compiler warnings (silence them, or turn them into errors).

It also integrates the fantastic silencer compiler plugin by @ghik into the compiler, which allows suppressing warnings locally using the @nowarn annotation.

@etorreborre
etorreborre / fileNameMacro.scala
Created April 5, 2020 17:44
Bug with Dotty macros?
case class FileName private(name: String)
/**
val fileName1: FileName = ToFileName("fileName1")
-- Error: /Users/etorreborre/projects/specs2/specs2-five/common/shared/src/test/scala/org/specs2/io/DirectoryPathSpec.scala:13:38
[error] 13 | val fileName1: FileName = ToFileName("fileName1")
[error] | ^^^^^^^^^^^
[error] | fileName1 is not a valid file name! It must not contain a /
@etorreborre
etorreborre / ArgsSpec.scala
Created October 12, 2019 20:44
Specs2 command line arguments
import org.specs2.main.CommandLine
// run from sbt with
//
// sbt> testOnly *ArgsSpec*
// sbt> testOnly *ArgsSpec* -- isOk
// sbt> testOnly *ArgsSpec* -- !isOk
//
// and see the difference
class ArgsSpec(args: CommandLine) extends mutable.Specification {