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 / audio.sh
Created August 30, 2019 08:47
restore mac audio
# from https://www.makeuseof.com/tag/sound-advice-fixing-common-mac-audio-problems-os-x/
sudo killall coreaudiod
@etorreborre
etorreborre / fzf.ghci
Last active March 15, 2021 17:43
fzf
How to Use Fzf in GHCi
by Vanessa McHale | 2019-08-27 01:27
I use fzf when I'm on the command-line. To configure GHCi to use fzf instead of haskeline's built-in search:
Put the following in $HOME/.haskeline:
bind: ctrl-r : f z f return
and the following in $HOME/.ghci:
@etorreborre
etorreborre / sketch.hs
Created August 6, 2019 11:45
schemaz-registry?
import Data.Registry
data Company = Company [Department] deriving (Eq, Show)
data Departement = Department [PersonV0] deriving (Eq, Show)
data PersonV0 = PersonV0 Text deriving (Eq, Show)
data PersonV1 = PersonV1 Text Int deriving (Eq, Show)
-- A registry for a given "schema". That registry can be lifted to
-- any Applicative context: Encoder, Decoder, Gen, ...
-- a component
data FileSystem m = FileSystem {
exists :: Path -> m (Either Text Bool)
, readFile :: Path -> m (Either Text Text)
}
-- a constructor for a mock file system
newFileSystemWith :: (FileSystemValues -> FileSystemValues) -> FileSystem
newFileSystemWith f = FileSystem {
exists = \_ -> pure (_exists $ f fileSystemValues)
data Expr =
Var String
| Lam String Expr
| App Expr Expr
@etorreborre
etorreborre / cycle-constructors.hs
Created May 12, 2019 10:59
cycle-constructors
test_cycle_constructors =
prop "we can cycle deterministically across all the constructors of a data type" $ runS generators $ do
setGenS @Int (pure 1)
setCycleChooserS @EmployeeStatus
names <- replicateM 10 (forallS @EmployeeStatus)
names === take 10 (join $ repeat [Permanent, Temporary 1])
@etorreborre
etorreborre / propertyt-statet
Created May 12, 2019 10:36
propertyt-statet
test_with_better_department_name =
prop "a department must have a short capitalized name" $ runS generators $ do
setSmallCompany
setDepartmentName
company <- forallS @Company
let Just d = head $ departments company
(T.length (departmentName d) <= 5) === True
@etorreborre
etorreborre / setShortDepartmentNamesS.hs
Last active May 12, 2019 10:32
setShortDepartmentNamesS
setShortDepartmentNamesS :: MonadState (Registry _ _) m => m ()
setShortDepartmentNamesS = specializeGenS @Department genDepartmentName
@etorreborre
etorreborre / override-department-names
Last active May 12, 2019 10:26
override-department-names
-- short and upper cased names
genDepartmentName = T.take 5 . T.toUpper <$> genText
registry' =
specializeGen @Department genDepartmentName
registry
-- we get specific department names
λ> fmap departmentName <$> (replicateM 5 $ sampleIO (make @(GenIO Department) registry'))
["CE","UNZ","FG","V","HIB"]
registry' =
fun (list @Deparment (linear 10 1000))
<: registry