Skip to content

Instantly share code, notes, and snippets.

View cmk's full-sized avatar

Chris McKinlay cmk

  • San Francisco
View GitHub Profile

deciban

The following table lists a number of rare events, arranged on a deciban scale. The deciban is a logarithmic unit — much like the decibel or the Richter scale — introduced by Alan Turing for expressing probabilities. It is a tenth of a ban, which is also known as the base-10 log-odds.

Please note that these are only rough estimates for the purpose of providing intuition for the relative likelihood of various rare events. Many are based on population averages, and do not apply to you personally. As always, keep the above comic in mind ;)

decibans event
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import Data.Bifunctor
import Data.Bifoldable
import Data.Bifunctor.Join
import Data.Biapplicative
import Data.Bitraversable
@cmk
cmk / Constraints.org
Created January 18, 2019 02:51 — forked from Icelandjack/Constraints.org
Type Classes and Constraints

Reddit discussion.

Disclaimer 1: Type classes are great but they are not the right tool for every job. Enjoy some balance and balance to your balance.

Disclaimer 2: I should tidy this up but probably won’t.

Disclaimer 3: Yeah called it, better to be realistic.

Type classes are a language of their own, this is an attempt to document features and give a name to them.

Verifying my Blockstack ID is secured with the address 1JafhKfXbBynoUfwCLJ1r9u4ymdyaC5N9c https://explorer.blockstack.org/address/1JafhKfXbBynoUfwCLJ1r9u4ymdyaC5N9c
-- | A 'Validator a b' is in particular a '(Applicative f, Choice p) => p a (f b)'.
type Validator a b = a -> Validation ValidationErrors b
-- | Lift a 'Getting (Maybe a) s (Maybe a)' into a 'Prism'. This should only be used if the
-- target domain type is a 'Maybe b'.
--
-- Note that error messages from 'Validator's consumed in this way are preserved.
--
-- @
-- 'validating' :: Getting (Maybe a) s (Maybe a) -> Validator a b -> Validator s (Maybe b)
#!/usr/bin/env stack
-- stack --resolver lts-11.10 script
import Control.Monad.Trans.Class
import Control.Monad.IO.Class
import Data.Functor.Identity
newtype ReaderT r m a = ReaderT { runReaderT :: r -> m a }
instance Functor m => Functor (ReaderT r m) where
fmap f (ReaderT rma) = ReaderT $ fmap f . rma
Verifying my Blockstack ID is secured with the address 1Ati9McJQVKAzatFb6JhKE957xvE2tiN6Q https://explorer.blockstack.org/address/1Ati9McJQVKAzatFb6JhKE957xvE2tiN6Q
{-# LANGUAGE RankNTypes, FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
module Free where
import Control.Monad.IO.Class
import Data.IORef
import Control.Applicative
import Control.Monad
import Data.Maybe (fromMaybe)
import qualified Control.Monad.Trans.State as ST
import qualified Data.Map as M
@cmk
cmk / free_monad_interpreter_pattern.md
Created January 2, 2017 22:30 — forked from CMCDragonkai/free_monad_interpreter_pattern.md
Haskell: Free Monad + Interpreter Pattern

Free Monad + Interpreter Pattern

It's like creating the front end and back end of a compiler inside Haskell without the need of Template Haskell!

Write your DSL AST as a Free Monad, and then interpret the monad any way you like.

The advantage is that you get to swap out your interpreter, and your main code

--Number of commits for libraries of interest during 2015–09–30 ~ 2016–09–30:
SELECT date, idname.repo_name AS repo_name, num_commits
FROM
(SELECT
DATE(created_at) AS date,
repo.id,
SUM(INTEGER(JSON_EXTRACT(payload, '$.size'))) AS num_commits
FROM
(TABLE_DATE_RANGE([githubarchive:day.],