Skip to content

Instantly share code, notes, and snippets.

View jship's full-sized avatar

Jason Shipman jship

View GitHub Profile
@jship
jship / Debouncer.purs
Created August 12, 2023 22:29
Simple AVar-based Debouncer
module Debouncer
( Debouncer
, Task
, new
, defaultDelay
, run
) where
import Control.Applicative as Applicative
import Control.Bind (bind, discard, pure)
@jship
jship / reset-stg-author-commit-dates.sh
Created August 7, 2023 16:50
Set git author and commit dates for all stg patches
for p in $(stg series -P); do stg edit --authdate "$(date '+%Y-%m-%d %H:%M:%S %z')" --committer-date-is-author-date "$p"; done
@jship
jship / Foo.hs
Created June 4, 2023 13:32
Specifying constraints on existentials from the outside
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@jship
jship / constraintTrigger.sql
Last active February 11, 2023 16:38
PostgreSQL constraint trigger to do processing a single time at end of transaction in response to changes
-- This script sketches out a way of doing some processing in response to one or
-- more changes being made to tables throughout the transaction. The processing
-- is done just once before the transaction commits.
begin;
-- Create a table that stores a marker indicating whether or not a change has
-- happened in this transaction. We aren't concerned with what the change
-- specifically was, just that there was a change.
drop table if exists changed;
jq --sort-keys 'walk( if type == "array" then sort else . end )'
@jship
jship / pg-lateral-join.sql
Created December 16, 2022 15:08
Simple examples of left vs inner join lateral in PostgreSQL
-- i | i
-- ---+---
-- 1 |
-- 2 | 2
-- (2 rows)
select *
from (
values (1), (2)
) x(i)
left join lateral (

title: MTLiens author: Jason Shipman | jship patat: wrap: true margins: left: 10 right: 10 incrementalLists: true ...

@jship
jship / servant-generic-allLinks.hs
Created October 1, 2022 15:44
Example showing how to get links from a generic record-style servant API
@jship
jship / QuantifiedConstraintsExample.hs
Last active September 19, 2022 13:52
Small and reasonably grounded example of -XQuantifiedConstraints
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE QuantifiedConstraints #-}
module QuantifiedConstraintsExample
( Stuff(..)
, Things
, getThingsIO
, getThings
) where
@jship
jship / hspec-helpers.hs
Last active September 11, 2022 18:00
Some hspec helpers
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
import Control.Exception (PatternMatchFail(..), evaluate) -- @base@
import Control.Exception.Safe (catch) -- @safe-exceptions@
import Test.HUnit (assertFailure) -- @HUnit@
import Test.Hspec (HasCallStack) -- @hspec@
import qualified Test.Hspec as Hspec -- @hspec@
shouldReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m ()
shouldReturn action expected = action >>= \x -> x `shouldBe` expected