Skip to content

Instantly share code, notes, and snippets.

@chrisdone
chrisdone / 1-test-suite-requirements.txt
Last active May 22, 2019 12:58
Hasura python test suite
chris@precision:~/Work/hasura/graphql-engine$ docker run --rm -it --network host --name hasura-server -v`pwd`:`pwd` -w`pwd`/server/tests-py hasura/graphql-engine-server-builder:20190507-1 sh
# pip3 install -r requirements.txt
# pytest -vv --hge-url="http://localhost:8080" --pg-url="postgres://postgres:password@localhost:6432/postgres" test_events.py
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
-- | Lists that are of finite length.
module Data.List.Finite
@chrisdone
chrisdone / limitChunks.hs
Last active May 2, 2019 09:40
Limit chunks consumed in attoparsec
{-# LANGUAGE BangPatterns #-}
{-
Limit the number of chunks used to consume a given thing.
> feeder 5 (parse (limitChunksConsumed 1 jstring)) ("\"hello world\"")
Chunk [34,104,101,108,108]
Waiting for more ...
Chunk [111,32,119,111,114]
Waiting for more ...
@chrisdone
chrisdone / 0.md
Last active April 24, 2019 08:34
Prana demonstration

This is a simple demonstration of what Prana is currently capable of doing:

  1. The script generate.sh will compile
  • ghc-prim
  • integer-gmp
  • base
  1. The binary prana-ghc acts as a replacement for regular ghc, but it also "Recompiles" and outputs .prana files
  2. The resulting "object" .prana files contain STG for each library, and they go in the PRANA_DIR directory
  3. Along with an "index" file that maps numerical references of variables/nodes/data constructors to strings like package:Module.name.
  4. That whole process takes about 15 seconds.
@chrisdone
chrisdone / 0_fib-iter.hs
Last active April 23, 2019 13:33
Fibs in Prana
fib :: Int -> Int
fib n = go 0 1 0
where
go !acc0 !acc1 !i
| i == n = acc0
| otherwise = go acc1 (acc0 + acc1) (i + 1)
it :: Int
it = fib 50

Example use:

> import Network.HTTP.Simple
> import qualified Data.ByteString.Char8 as B8
> :set -XOverloadedStrings
> import Data.String
> withWebService (responseBs "Hello!") (\port -> httpBS (fromString ("http://localhost:" ++ show port)) >>= B8.putStrLn . getResponseBody)
Hello!
>
chris@precision:~/Work/chrisdone/sandbox$ ./servant1.hs
Hello, World!
CallStack (from HasCallStack):
error, called at /home/chris/Work/chrisdone/sandbox/servant1.hs:20:30 in main:Main
Something went wrong
// GET http://127.0.0.1:3001
@chrisdone
chrisdone / 0README.md
Last active April 14, 2019 11:45
Declarative REST API DSL experimenting

Inspectable, type-safe REST API without type-level programming or TH

This approach differs from

  • Yesod
  • Servant

Instead, the following approach is used:

  1. A request can be modelled as an Applicative (a la
@chrisdone
chrisdone / Main.hs
Created April 12, 2019 08:23
Servant docs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
@chrisdone
chrisdone / servant1.hs
Last active April 10, 2019 10:19
Servant examples
#!/usr/bin/env stack
-- stack --resolver lts-12.12 script
{-# LANGUAGE OverloadedStrings #-}
-- Just an API description, no service
import Servant.API
type MyAPI = EmptyAPI
main = pure ()