Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile

Nix

Nix discourse

Is there much difference between using nix-shell and docker for local development?

You need to see a Docker image as a snapshot of a machine. It will stay like it is and thus anything you do with it will keep working. However, making changes to such an image is where nondeterminism seeps in. Docker images are built using shell commands, usually it contains commands like apt-get update, apt-get install ... or wget .... These fetch information from outside sources, but because the outside sources change over time will result in different files being fetched at different times. In addition, there are no checks that the files that are being fetched are actually the ones you intended to download for your Docker image. So, Docker images will stay the same, but building the Docker image will result in a different result

-- cabal v2-repl -b "transformers" -b "red-black-record" -b "sop-core" -b "managed" -b "profunctors" -b "aeson" -b "text"
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
@danidiaz
danidiaz / Ctors.hs
Last active March 2, 2019 14:38
adding and pruning ctors
{-# LANGUAGE DataKinds, TypeApplications #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
module Main where
import Data.RBR (FromList,Insert,Delete,Variant,I,injectSubset,widen,injectI,winnowI,prettyShowVariantI)
import GHC.TypeLits
-- would defining these as nullary type families improve things?
type Phase01 = FromList '[ '("ctor1",Int), '("ctor2",Bool), '("ctor3",Char) ]
@danidiaz
danidiaz / cpure_NP.hs
Last active January 19, 2019 16:45
cpure_NP example
{-# LANGUAGE DataKinds, TypeApplications #-}
-- http://hackage.haskell.org/package/sop-core
module Main where
import Data.SOP
import Data.SOP.NP (cpure_NP,cliftA_NP,collapse_NP)
import Data.Default
import Data.Proxy
-- NP is an n-ary product indexed by a type-level list. Each value is wrapped in an identity functor I.
@danidiaz
danidiaz / AKindClass.hs
Created January 18, 2019 18:49
kind class example
{-# LANGUAGE RankNTypes, DataKinds, TypeInType, PolyKinds, FlexibleInstances #-}
import Data.Proxy
import GHC.TypeLits
class Foo k
class Foo k => Bar (a :: k) where
baz :: Proxy a -> String
instance Foo k => Bar (a :: k) where
baz _ = "baz"
@danidiaz
danidiaz / WrappedFields.hs
Last active December 28, 2018 23:56
wrap all the fields of a record in a functor, and still allow indexing by field name
{-# LANGUAGE DataKinds,
TypeFamilies,
FlexibleInstances,
UndecidableInstances,
ScopedTypeVariables,
TypeApplications,
TypeOperators,
MultiParamTypeClasses,
FunctionalDependencies,
AllowAmbiguousTypes,
@danidiaz
danidiaz / TypeLevelSymbolSet.hs
Last active December 26, 2018 00:46
A type-level symbol set.
{-# LANGUAGE DataKinds,
PolyKinds,
TypeFamilies,
UndecidableInstances,
FlexibleContexts,
ScopedTypeVariables,
TypeApplications,
TypeOperators,
ExistentialQuantification,
DeriveFunctor,
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where

Vertical decomposition. Creating cohesive services

One of the biggest misconceptions about services is that a service is an independent deployable unit, i.e., service equals process. With this view, we are defining services according to how components are physically deployed. In our example, since it’s clear that the backend admin runs in its own process/container, we consider it to be a service.

But this definition of a service is wrong. Rather you need to define your services in terms of business capabilities. The deployment aspect of the system doesn’t have to be correlated to how the system has been divided into logical services. For example, a single service might run in different components/processes, and a single component might contain parts of multiple services. Once you start thinking of services in terms of business capabilities rather than deployment units, a whole world of options open.

What are the Admin UI

import Data.Foldable (toList)
import Streaming
import qualified Streaming.Prelude as S
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
main :: IO ()
main =
withFile "/tmp/source.txt" ReadMode $ \hSource ->
withFile "/tmp/target.txt" WriteMode $ \hTarget ->