Skip to content

Instantly share code, notes, and snippets.

View jship's full-sized avatar

Jason Shipman jship

View GitHub Profile
#!/usr/bin/env stack
-- stack --resolver lts-15.6 --install-ghc exec ghci --package wai
{-# LANGUAGE ScopedTypeVariables, TypeApplications #-}
import Network.Wai (Middleware)
-- | This function doesn't look like much, but is pretty neat-o...
h :: (Functor f) => (b -> c) -> (a -> f b) -> a -> f c
h g f = fmap g . f
-- const has type:
-- const :: a -> b -> a
weirdConst :: b -> (forall a. a -> a) -> b
weirdConst b _f = b
blah :: Int
blah = weirdConst 42 id
-- blahBlah produces this compiler error:
--
#!/usr/bin/env stack
{- stack
--resolver lts-16.8
--install-ghc
exec ghci
-}
{-# LANGUAGE ScopedTypeVariables #-}
import Prelude hiding (foldl, foldr)
@jship
jship / TreePaths.hs
Created November 18, 2020 17:44
Get the paths for a Tree
import Data.Tree (Tree(Node, rootLabel, subForest))
paths :: Tree a -> [[a]]
paths = \case
Node { rootLabel, subForest } ->
[rootLabel] : concatMap (map (rootLabel :) . paths) subForest
@jship
jship / insecure-tls.hs
Created December 23, 2020 16:05
Haskell reference for building an insecure TLS HTTP manager
#!/usr/bin/env stack
{- stack
--resolver lts-16.8
--install-ghc
exec ghci
--package connection
--package http-client
--package http-client-tls
-}
#!/usr/bin/env stack
{- stack
--resolver lts-16.26
--install-ghc
exec ghci
--package http-client
-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
@jship
jship / share-the-load.hs
Last active February 8, 2021 23:31
Simple way of splitting up units of work across some max number of workers
#!/usr/bin/env stack
{- stack
--resolver lts-16.26
--install-ghc
exec ghci
--package hspec
-- -ignore-dot-ghci
-}
{-# LANGUAGE BlockArguments #-}
#!/usr/bin/env stack
{- stack
--resolver lts-17.10
--install-ghc
exec ghci
--package aeson
-- -ignore-dot-ghci -XDataKinds -XTypeApplications
-}
{-# LANGUAGE DataKinds #-}
@jship
jship / async-exception-synchrony.hs
Created August 18, 2021 15:56
Script that demonstrates the synchrony of 'throwTo'
#!/usr/bin/env stack
{- stack
--resolver lts-17.10
--install-ghc
script
--optimize
-}
-- This script demonstrates the synchrony of "Control.Exception.throwTo", in
-- that calling the function is only synchronous until the asynchronous
@jship
jship / webm-to-mov-with-transparency.sh
Created January 19, 2022 02:49
Convert .webm video to .mov and preserve transparency
ffmpeg -c:v libvpx -i "input.webm" -c:v prores_ks -pix_fmt yuva444p10le -metadata:s:v:0 alpha_mode="1" "output.mov"