Skip to content

Instantly share code, notes, and snippets.

Avatar
:bowtie:
Happily Hacking

Chris Penner ChrisPenner

:bowtie:
Happily Hacking
View GitHub Profile
@ChrisPenner
ChrisPenner / RequireTypeAp.hs
Created Nov 18, 2020
A hack to require type applications, even when not necessary
View RequireTypeAp.hs
{-# 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
View SemiRepresentable.hs
{-# 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
View BindAsync.hs
-- 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?"
View MapF.hs
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
module MyMap where
View OpticsForTreeTraversals.hs
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE RankNTypes #-}
module Recurser where
import Control.Lens
import Data.Monoid
import Data.Foldable
import Data.Functor.Contravariant
View haddock-up.sh
#!/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"
@ChrisPenner
ChrisPenner / TextOptics.hs
Created Apr 19, 2020
Optics for doing some text manipulation
View TextOptics.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE FlexibleContexts #-}
module Lib where
import Control.Lens
import Control.Applicative
import qualified Data.Text as T
@ChrisPenner
ChrisPenner / git-transplant
Created Apr 6, 2020
Transplant commits from one source to another
View git-transplant
#!/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:
@ChrisPenner
ChrisPenner / cap.sh
Created Apr 5, 2020
Capture can replay command line output
View cap.sh
#!/bin/bash
capdir=/tmp/cap
mkdir -p "$capdir"
record() {
tee "${capdir}/${1:-default}"
}
replay() {
View copy.sh
#!/bin/bash
# Use at your own risk :P
FOLDER="/tmp/copy-pasta"
if [ $# -lt 1 ]; then
cat << EOF
usage: copy <files>
EOF
exit 1
fi
You can’t perform that action at this time.