Skip to content

Instantly share code, notes, and snippets.

View jship's full-sized avatar

Jason Shipman jship

View GitHub Profile
@jship
jship / monad-logger-aeson-rio-shim.hs
Last active May 19, 2022 14:06
Demonstration of a possible shim to use monad-logger-aeson from rio's Utf8Builder-based logging facilities
-- | Description: This module demonstrates the foundations of a shim between
-- @monad-logger-aeson@ and the 'Utf8Builder'-based logging system in "RIO".
--
-- Note that this demonstration does not provide the same level of fanciness
-- "RIO"'s logging can provide when making 'LogFunc' values via 'LogOptions'
-- (e.g. sticky logging). The demonstration also digs into
-- @monad-logger-aeson@'s internals in a couple spots.
--
-- Output (when formatted with @jq@) looks like:
-- {
#!/usr/bin/env bash
set -o errexit
set -o pipefail
[[ "${DEBUG}" == 'true' ]] && set -o xtrace
declare -r package="$1"
if [ -z "$package" ]
then
echo "Must pass in package!"
@jship
jship / building-trees-from-pg-rows.md
Last active August 22, 2022 21:10
Efficient means of building a tree from node records pulled from DB

Sample tree:

a
|
+- b
|  |
|  +- d
|  |
|  `- e
@jship
jship / fresh-db.sh
Created April 22, 2022 13:52
Gross script to whack all pg data and make a fresh DB
#!/usr/bin/env bash
set -o errexit
set -o pipefail
[[ "${DEBUG}" == 'true' ]] && set -o xtrace
brew services stop postgresql@12
rm -rf /usr/local/var/postgresql\@12/
initdb -E utf8 -U postgres /usr/local/var/postgresql\@12/
@jship
jship / tangle.hs
Created April 5, 2022 13:34
Neat example of value recursion, courtesy of @tstat
-- | Maps each element of a list to a three-element tuple where the
-- first element is the previous element in the input list and the
-- final element is the next element of the input list.
--
-- > tangle [1..4]
-- [(4,1,2),(1,2,3),(2,3,4),(3,4,1)]
--
tangle :: forall a. [a] -> [(a, a, a)]
tangle = \input ->
case input of
import qualified System.Directory as Directory
import qualified System.Environment as Environment
import qualified System.FilePath as FilePath
listDirectoryDeep :: FilePath -> IO [FilePath]
listDirectoryDeep directory = do
entries <- listDirectoryShallow directory
foldMap listEntry entries
where
listEntry entry = do
@jship
jship / http-req.sh
Created February 15, 2022 17:11
bash function to perform an HTTP request and check status
#!/usr/bin/env bash
set -o errexit
set -o pipefail
[[ "$DEBUG" == 'true' ]] && set -o xtrace
# $1: expected http code
# $2: cookie file to use
function httpReq() {
local _expectedHTTPCode
@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"
@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
#!/usr/bin/env stack
{- stack
--resolver lts-17.10
--install-ghc
exec ghci
--package aeson
-- -ignore-dot-ghci -XDataKinds -XTypeApplications
-}
{-# LANGUAGE DataKinds #-}