Skip to content

Instantly share code, notes, and snippets.

Chris Done chrisdone

Block or report user

Report or block chrisdone

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chrisdone
chrisdone / 0README.md
Created Oct 22, 2019
Spinning up Duta mail server on DigitalOcean with docker-machine and docker-compose
View 0README.md

Change the mx.chrisdone.com mentions to your own domain.

Spin up a Droplet on DigitalOcean with docker-machine.

$ time docker-machine create \
  --driver digitalocean \
  --digitalocean-access-token $(cat ~/.do-token) \
  --digitalocean-monitoring \
  --digitalocean-region "lon1" \
  --digitalocean-size "s-1vcpu-1gb" \
@chrisdone
chrisdone / money-currency.hs
Last active Oct 22, 2019
money currency in haskell
View money-currency.hs
-- | A currency-less integral monetary value which cannot be further
-- subdivided. E.g. cent, penny, satoshi.
--
-- For lack of a better name:
-- <https://money.stackexchange.com/questions/85562/generic-name-for-the-smallest-unit-of-currency>
newtype IntegralMoney = IntegralMoney Int
deriving (Eq, Ord, Integral, Num, Enum, Real, Show)
instance PersistFieldSql IntegralMoney where
sqlType _ = SqlString
instance PersistField IntegralMoney where
View intero-file-embed.hs
{-# LANGUAGE CPP #-}
-- |
module Data.FileEmbed2
( makeRelativeToProject2
, module Data.FileEmbed
) where
import Data.FileEmbed
import Language.Haskell.TH
@chrisdone
chrisdone / Web.hs
Created Oct 3, 2019
Web yesod wrapper
View Web.hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE GADTs #-}
-- | A restricted web type.
module Web
( Web(..)
, runWebHandler
View various-foldls.hs
{-# LANGUAGE BangPatterns #-}
import Control.DeepSeq
import Data.List hiding (foldl)
import Prelude hiding (foldl)
foldl = \f accumulator list ->
case list of
[] -> accumulator
x:xs -> foldlS f (f accumulator x) xs
@chrisdone
chrisdone / foldl-vs-foldl-strict.md
Last active Sep 13, 2019
Strict fold vs regular fold
View foldl-vs-foldl-strict.md

Duet's folds example

Duet has this folding example:

data List a = Nil | Cons a (List a)
foldr = \f z l ->
  case l of
    Nil -> z
    Cons x xs -> f x (foldr f z xs)
View Execute.hs
-- | Execute the steps.
execute :: [SomeStep] -> RIO MainEnv ()
execute steps = do
resources <- newIORef mempty
mapRIO
(\MainEnv {logger} -> ExecuteEnv {logger = logger . ExecuteLog, resources})
(mapM_ executeSomeStep steps)
@chrisdone
chrisdone / file-embed-demo.hs
Created Aug 14, 2019
File embed expansion demo
View file-embed-demo.hs
> :set -XOverloadedStrings
> :set -XTemplateHaskell
> import Language.Haskell.TH
> $(bsToExp "Hello, World" >>= stringE . show)
"AppE (VarE GHC.IO.Unsafe.unsafePerformIO) (AppE (AppE (VarE Data.ByteString.Unsafe.unsafePackAddressLen) \
\(LitE (IntegerL 12))) (LitE (StringPrimL [72,101,108,108,111,44,32,87,111,114,108,100])))"
>
> :set -ddump-splices
@chrisdone
chrisdone / cleaner-forms.hs
Last active Aug 12, 2019
forms experimentation type family
View cleaner-forms.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Bifunctor
View ShuffleGraph.hs
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Graph.Shuffle where
-- | Shuffle a graph into a randomly sorted list, preserving
-- topological order.
{-
> quickCheckWith stdArgs {maxSuccess=10000} prop_identity
You can’t perform that action at this time.