Skip to content

Instantly share code, notes, and snippets.

View jhrcek's full-sized avatar

Jan Hrcek jhrcek

View GitHub Profile
@jhrcek
jhrcek / sse.hs
Last active September 24, 2022 08:51
Server-Sent Events - is it possible to detect SSE client disconnecting?
#!/usr/bin/env stack
{- stack script
--resolver lts-18.28
--package bytestring,containers,servant,servant-server,servant-rawm-server,stm,wai,wai-extra,warp
-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
@jhrcek
jhrcek / pi-backend.hs
Last active August 10, 2022 09:39
Set of scripts to startup all components of PI locally
#!/usr/bin/env stack
-- stack script --resolver lts-19.18 --package ansi-terminal,turtle
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
import Data.Bool (bool)
import System.Console.ANSI (setTitle)
import Turtle
@jhrcek
jhrcek / index-date-condition-query.sql
Created June 10, 2022 13:01
Index Date query with diagnosis condition
WITH person_date AS (
SELECT
person_id,
MIN(condition_start_date) AS index_date
FROM
? schema.condition_occurrence
WHERE (condition_concept_id IN (1, 2, 3))
GROUP BY
person_id
HAVING
{- stack script
--resolver lts-18.26
--package containers
--package random
-}
{-# LANGUAGE NamedFieldPuns #-}
{-# OPTIONS_GHC -Wall #-}
import Control.Monad.State.Strict (State)
@jhrcek
jhrcek / amazonka-library-dependencies.svg
Created November 29, 2021 07:26
amazonka 2.0 library dependencies
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhrcek
jhrcek / locks.hs
Last active November 9, 2021 07:49
Run at most one async job per user
#!/usr/bin/env stack
{- stack script
--resolver lts-18.14
--package async,containers,say,stm
-}
import Control.Concurrent
import Control.Concurrent.Async
import Control.Concurrent.STM (TVar, atomically, modifyTVar, newTVarIO, readTVar)
import qualified Data.IntSet as Set
@jhrcek
jhrcek / case-split-in-do.hs
Last active March 3, 2021 15:42
How to case split in monadic do block
data Thing = A | B | C
getThing :: IO Thing
getThing = pure A
f :: Int -> IO ()
f i = do
thing <- getThing
-- TODO what can I do here to make the tactics plugin offer "case split" code action?
case thing of
@jhrcek
jhrcek / Demo.hs
Last active November 13, 2020 09:37
Pattern matching servant client functions out of generic record
module PI.Demo where
import Servant (Handler, Put)
import Servant.API.Generic (AsApi, ToServant, fromServant)
import Servant.Client (ClientM)
import Servant.Client.Generic (AsClientT, genericClient)
import Servant.Server.Generic (AsServer, genericServer)
data Parent mode = Parent
{ parent1 :: mode :- Capture "x" Int :> Get '[JSON] String
@jhrcek
jhrcek / dependent-bullshit.hs
Created October 7, 2020 16:22
Playing with dependent types in Haskell
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
@jhrcek
jhrcek / build error
Created September 10, 2020 14:05
aws-lambda-haskell-runtime - build error in testing project
~/Tmp/aws-lambda-play> stack build
Building all executables for `aws-lambda-play' once. After a successful build of all of them, only specified executables will be rebuilt.
aws-lambda-play> configure (lib + exe)
Configuring aws-lambda-play-0.1.0.0...
aws-lambda-play> build (lib + exe)
Preprocessing library for aws-lambda-play-0.1.0.0..
Building library for aws-lambda-play-0.1.0.0..
Preprocessing executable 'bootstrap' for aws-lambda-play-0.1.0.0..
Building executable 'bootstrap' for aws-lambda-play-0.1.0.0..
Linking .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/bootstrap/bootstrap ...