Skip to content

Instantly share code, notes, and snippets.

View jhrcek's full-sized avatar

Jan Hrcek jhrcek

View GitHub Profile
@jhrcek
jhrcek / timelines.hs
Last active August 14, 2020 10:12
This script prepends timestamps to lines streaming from stdin and prints them to stdout
#!/usr/bin/env stack
-- stack script --resolver lts-16.9 --package conduit,text,mtl
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall #-}
import Conduit (decodeUtf8C, encodeUtf8C, mapMC, runConduit, stdinC, stdoutC, (.|))
import Control.Monad.State.Strict (StateT, evalStateT, get, liftIO, put)
@jhrcek
jhrcek / Tree.elm
Created May 28, 2020 06:51
Draw datapoints tree as string
datapointItemToString : DatapointsItem -> String
datapointItemToString i =
case i of
DatapointsRoot ->
"Root"
CategoryItem category ->
"Cateogry: " ++ category.name
QuestionItem question ->
@jhrcek
jhrcek / thales-wip.hs
Created February 14, 2020 15:34
Work-in-progress animation video giving visual proof of Thales' theorem
#!/usr/bin/env stack
-- stack runghc --package reanimate --package linear --package reanimate-svg
{-# LANGUAGE OverloadedStrings #-}
module Main
( main,
)
where
@jhrcek
jhrcek / puml_like_example.dot
Created November 22, 2019 12:50
Example of PlantUML-like diagram in graphviz
digraph G {
// External system
node [style=filled fillcolor="#999999" shape=rectangle, fontcolor=white]
externalSystem [ label=<
<table border="0" cellborder="0" cellspacing="1">
<tr><td><b>External System</b></td></tr>
<tr><td>&lt;&lt;qualtrics&gt;&gt;</td></tr>
</table>
@jhrcek
jhrcek / Bench.elm
Last active August 1, 2019 08:51
Benchmark comparing getAll implementaions
module Bench exposing (main)
import Benchmark as B exposing (Benchmark, benchmark, compare, describe)
import Benchmark.Runner exposing (BenchmarkProgram, program)
import Dict exposing (Dict)
import RemoteData exposing (RemoteData(..), WebData)
main : BenchmarkProgram
main =
@jhrcek
jhrcek / PrototypeIndex.elm
Created July 18, 2019 11:54
Experimenting with mapping index to colors
type alias ColorCalculator =
Float -> Float
{-| Input: indexMin, indexMax, where 0 < indexMin < 100 < indexMax
Output: function `f : ColorCalculator` mapping index values "evenly" from interval `(indexMin, indexMax)` to `(0,1)` such that `f 100 = 0.5`
-}
createColorCalculatorForGivenInterval : Float -> Float -> ColorCalculator
module Main where
{-|
>>> getLine
Hello<Enter>
Hello
-}
main = undefined
@jhrcek
jhrcek / Main.elm
Last active May 24, 2019 13:51
Are requests sent, when `Cmd.map (always NoOp) requestCmd`?
module Main exposing (main)
import Browser
import Html exposing (Html)
import Http
type Msg
= GotText (Result Http.Error String)
| NoOp
@jhrcek
jhrcek / Main.hs
Created January 11, 2019 12:22
Servant + blaze-html example
#!/usr/bin/env stack
-- stack script --resolver lts-13.2 --package blaze-html,servant,servant-blaze,servant-server,wai,warp
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}
module Main (main) where
import Network.Wai (Application)
import qualified Network.Wai.Handler.Warp as Warp
@jhrcek
jhrcek / optparse-applicative-demo.hs
Last active April 5, 2019 05:42
optparse-applicative demo
import Options.Applicative (Parser, ParserInfo, command, execParser, fullDesc,
help, helper, info, progDesc, subparser, value)
main :: IO ()
main = execParser cliParser >>= print
demo :: Parser Int
demo = subparser
( command "a" (info (pure 1) (progDesc "A description"))
<> command "b" (info (pure 2) (progDesc "B description"))
)