Skip to content

Instantly share code, notes, and snippets.

View Akii's full-sized avatar
🚀
To the Moon

Akii

🚀
To the Moon
View GitHub Profile
chunkChan :: Int -> Int -> TChan a -> IO [a]
chunkChan numItems timeoutSeconds chan = do
maybeRead <- timeout (timeoutSeconds * 60 * 1000) . atomically $ replicateM numItems (readTChan chan)
case maybeRead of
Just as -> return as
Nothing -> do
as <- emptyChannel chan
if null as
then chunkChan numItems timeoutSeconds chan
else return as
instance (Ord a) => Ord [a] where
compare [] [] = EQ
compare [] (_:_) = LT
compare (_:_) [] = GT
compare (x:xs) (y:ys) = case compare x y of
EQ -> compare xs ys
other -> other
-- This is part of a pipeline that continously produces `ev`s
-- Essentially this is a fold or scan. I call `a` a "projection" of a series of `ev`s
projectionConsumer :: IORef a -> (ev -> a -> a) -> Consumer ev IO ()
projectionConsumer ref f = for cat $ modifyIORef' ref . f
-- projectionBConsumer :: IORef b -> (ev -> b -> b) ...
-- I now have this issue of composing multiple of these folds
-- What I resorted to is something like this
someOtherProjection :: IORef a -> IORef x -> IO ()
itemView : Item -> Html Msg
itemView item =
tr []
[ td [ class "item-id" ] [ text ("#" ++ item.id) ]
, td [ class "item-name" ] [ text item.name ]
]
@Akii
Akii / IQR.hs
Created November 20, 2018 17:54
module IQR
( Sample
, mkSample
, singletonSample
, insertSample
, insertSample'
, restrictSampleSize
, withoutDuplicates
, median
, lowerQuartile
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
type family All (c :: Type -> Constraint)
(ts :: [Type]) :: Constraint where
All c '[] = ()
All c (x ': xs) = (c x, All c xs)
@Akii
Akii / NT.hs
Created November 12, 2018 16:16
newtype NT = NT String
foo :: Maybe NT
foo = Just (NT "test")
bar :: Maybe NT -> Maybe String
bar = undefined -- ??? how to do this?
-- this would work but it verbose for multiple data constructors
bar (Just $ NT s) = Just s
title: Elescore;DB FaSta API;Compensation;Outage
author: Philipp Maier
summary: "
<p>Elescore (elevator + scoring), a platform that tracks elevator disruptions, integrates multiple external data sources.
One of these sources is the DB FaSta API: Elevator status for all stations operated by Deutsche&nbsp;Bahn.</p>
<p>
In the past, this API has had several major outages resulting in corruption of data.
Using event sourcing and statistics, I was able to detect outages and compensate them.</p>"
tags: Haskell, Statistics, 1.5 x IQR, Event-Sourcing, Stream Processing
Starting Elescore v3
2018-08-05T01:44:39 Residual detected: 351 -> 785.0
2018-08-05T12:48:12 Back to normal: 351 -> 397.0
2018-08-05T13:18:43 Residual detected: 361 -> 435.0
2018-08-05T13:24:29 Back to normal: 361 -> 367.0
2018-09-28T04:51:40 Residual detected: 466 -> 508.0
2018-09-28T08:15:36 Back to normal: 466 -> 439.0
2018-09-28T09:00:06 Residual detected: 458 -> 822.0
2018-09-28T10:51:00 Back to normal: 458 -> 476.0
2018-09-29T12:35:30 Residual detected: 165 -> 66.0