Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,27 @@
import Data.List (unfoldr)
import Control.Monad (forM_)
import qualified Text.Blaze.Html5 as B
import Text.Blaze.Html.Renderer.Pretty (renderHtml)
import System.Random (RandomGen, getStdGen, randomRs, split)
makeTable
:: RandomGen g
=> [String] -> Int -> g -> B.Html
makeTable headings nRows gen =
B.table $
do B.thead $ B.tr $ forM_ (B.toHtml <$> headings) B.th
B.tbody $
forM_
(zip [1 .. nRows] $ unfoldr (Just . split) gen)
(\(x, g) ->
B.tr $
forM_
(take (length headings) (x : randomRs (1000, 9999) g))
(B.td . B.toHtml))
main :: IO ()
main = do
g <- getStdGen
putStrLn $ renderHtml $ makeTable ["", "X", "Y", "Z"] 3 g

View file

@ -0,0 +1,52 @@
{-# LANGUAGE QuasiQuotes #-}
import Data.List (elemIndex)
import Text.Hamlet (shamlet, Html)
import Text.Cassius (Css, renderCss, cassius)
import Text.Blaze.Html.Renderer.String (renderHtml)
import System.Random (getStdGen, randomRs)
styles :: p -> Css
styles = [cassius|
table, th, td
border: 1px solid black
border-collapse: collapse
th, td
padding: 15px
th, .rowLabel
background-color: #895
td
text-align: right
|]
renderTable :: [[Int]] -> Html
renderTable xs = [shamlet|
$doctype 5
<html>
<head>
<style>
#{renderCss $ styles undefined}
<body>
<table>
<tr>
<th>
$forall header <- headers
<th>#{header}
$forall row <- xs
<tr>
$maybe index <- elemIndex row xs
<td .rowLabel>#{index + 1}
$nothing
<td>?
$forall cell <- row
<td>#{cell}
|]
where
headers = ['X', 'Y', 'Z']
main :: IO ()
main = renderHtml . renderTable . rowsOf 3 . take 9 <$> randomValues >>= putStrLn
where
rowsOf _ [] = []
rowsOf n xs = take n xs : rowsOf n (drop n xs)
randomValues = randomRs (1, 9999) <$> getStdGen