This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE PolyKinds #-} | |
module Data.Profunctor.Free where | |
import Data.Profunctor | |
import Control.Category (Category, (>>>)) | |
data IsCat = | |
HasCategory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -ne 2 ]]; then | |
cat >&2 <<EOF | |
Transplant a branch from one root to another. | |
Handy if you've done a squash-merge and need to rebase <from> the old branch <onto> the new master. | |
Usage: | |
git transplant <from> <to> | |
where: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE AllowAmbiguousTypes #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
-- Don't export this, it's just to make it so the type family *could* have a different |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
module SemiRepresentable where | |
import qualified Data.Map as M | |
import Numeric.Natural | |
import qualified Data.Set as S | |
import Data.These |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Bind an async to be cancelled when the current computation ends. | |
bindAsync :: IO a -> ContT r IO () | |
bindAsync m = do | |
ContT $ \cc -> do | |
withAsync m . const $ cc () | |
-- Use bindAsync to auto-cancel the thread when the containing computation finishes | |
testBoundAsync :: ContT r IO () | |
testBoundAsync = do | |
bindAsync . forever $ print "can you hear me now?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DerivingStrategies #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
module MyMap where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tail_recursion import tail_recursive, recurse | |
# Normal recursion depth maxes out at 980, this one works indefinitely | |
@tail_recursive | |
def factorial(n, accumulator=1): | |
if n == 0: | |
return accumulator | |
recurse(n-1, accumulator=accumulator*n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Adapted from script by Dimitri Sabadie <dimitri.sabadie@gmail.com> | |
dist=$(stack path --dist-dir --stack-yaml ./stack.yaml) | |
packagename=$(awk '/^name:\s*(.*)/{ print $2 }' ./*.cabal) | |
packageversion=$(awk '/^version:\s*(.*)/{ print $2 }' ./*.cabal) | |
echo -e "\033[1;36mGenerating documentation for $packagename-$packageversion\033[0m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
module Lib where | |
import Control.Lens | |
import Control.Applicative | |
import qualified Data.Text as T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
capdir=/tmp/cap | |
mkdir -p "$capdir" | |
record() { | |
tee "${capdir}/${1:-default}" | |
} | |
replay() { |