Skip to content

Instantly share code, notes, and snippets.

Happily Hacking

Chris Penner ChrisPenner

Happily Hacking
View GitHub Profile
# Adapted from script by Dimitri Sabadie <>
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 / 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 / git-transplant
Created Apr 6, 2020
Transplant commits from one source to another
View git-transplant
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.
git transplant <from> <to>
ChrisPenner /
Created Apr 5, 2020
Capture can replay command line output
mkdir -p "$capdir"
record() {
tee "${capdir}/${1:-default}"
replay() {
# Use at your own risk :P
if [ $# -lt 1 ]; then
cat << EOF
usage: copy <files>
exit 1
View TextSpan.hs
{-# LANGUAGE OverloadedStrings #-}
module TextSpan where
import Control.Lens
import qualified Data.Text as T
import Text.RawString.QQ (r)
import qualified Data.List as List
type Line = Int
type Col = Int
ChrisPenner / Folds.Filtering.hs
Created Jan 19, 2020
Deck of cards example for Optics By Example
View Folds.Filtering.hs
module Folds.Filtering where
import Control.Lens
data Card =
Card { _name :: String
, _aura :: Aura
, _holo :: Bool -- Is the card holographic
, _moves :: [Move]
} deriving (Show, Eq)
View Optics
View DynamicLens.hs
import Control.Lens
import Data.Typeable
import Data.Dynamic
dynamicLens :: Typeable a => (Lens' s a) -> Lens' s Dynamic
dynamicLens l = lens getter setter
getter s = toDyn $ view l s
setter s b =
case fromDynamic b of
View OpticsTraverse.hs
You can use *most* optics as though they're a custom `traverse`
>>> (each . _Right) print (Left 1, Right 2, Left 3)
-- We can ignore the new structure it returns
(Left 1,Right (),Left 3)
It works on other types of effects too!
Here we use lists as a non-determinism effect to get all possible combos!
You can’t perform that action at this time.