Skip to content

Instantly share code, notes, and snippets.

View seanhess's full-sized avatar

Sean Hess seanhess

View GitHub Profile
@seanhess
seanhess / Auth.hs
Last active August 29, 2015 14:24
error
type AuthLookup = JWTClaimsSet -> Bool
data AuthProtected
protected :: AuthLookup -> server -> (AuthLookup, server)
protected look server = (look, server)
--instance (Enter typ arg ret) => Enter (AuthLookup, rest) where
--enter (al, rest) = enter rest
@seanhess
seanhess / Test.hs
Created July 8, 2015 18:27
Haskell Servant ReaderT ExceptT newtype monad transformer stack
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Serials.Route.Test where
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Either
@seanhess
seanhess / Error
Last active February 18, 2017 00:41
Haskell Servant ReaderT Example
server/Serials/Route/Test.hs:43:15:
Couldn't match type ‘IO’ with ‘EitherT ServantErr IO’
Expected type: ServerT TestAPI (ReaderT Int IO)
Actual type: ReaderT Int (EitherT ServantErr IO) String
:<|> ReaderT Int (EitherT ServantErr IO) String
In the expression: test :<|> test
In an equation for ‘testServerT’:
testServerT
= test :<|> test
where
@seanhess
seanhess / Example.hs
Last active August 29, 2015 14:21
Servant Request Cookie
type AuthToken = Cookie "token" Text
type AuthAPI = "auth" :> AuthToken :> Get SecureUser
authServer :: Pool RethinkDBHandle -> Server AuthAPI
authServer h = current
where current mt = liftE $ checkAuth h mt
-- Auth code ------------------------------------------
-- some stuff is hidden, do you need more context?
@seanhess
seanhess / GetText.hs
Last active August 29, 2015 14:20
GetText
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Serials.Admin where
import Data.Text (Text)
import Control.Monad.Trans.Either
import Data.Aeson
import Data.Proxy
@seanhess
seanhess / chunks.hs
Created April 10, 2015 16:28
Take functions that work like span, and repeatedly apply them to consume a list
chunks :: ([a] -> ([a], [a])) -> [a] -> [[a]]
chunks f [] = []
chunks f xs = case c of
[] -> cs
ys -> ys : cs
where
(c, rest) = f xs
cs = chunks f rest
@seanhess
seanhess / example.hs
Last active August 29, 2015 14:18
Loop?
findIncrementing :: URL -> IO [Link]
findIncrementing base = do
find <- newChan
done <- newChan
forkIO $ worker find done
let next links n = do
ml <- readChan done
case ml of
@seanhess
seanhess / test.html
Created March 24, 2015 18:29
Jeff Demo code
<html>
<body>
<h1>Hello</h1>
<p>This is some text</p>
<p>This is <b>some</b> text</p>
<img style="width: 200px" src="http://deniseleeyohn.com/wp-content/uploads/2013/07/jeff-kelley.jpg" />
<p>Click <a href="http://google.com">here</a> to go to google</p>
<p><input type="text" id="message"> Message</p>
<p><button onclick="printMessage()">click me</button></p>
<p id="lastMessage">EMPTY</p>
@seanhess
seanhess / search.js
Created March 17, 2015 19:40
Optional Types, composed types
type Searchy = {
index: string;
// type?: string;
}
type ServerSearch = {
type: string;
search: Searchy;
}
@seanhess
seanhess / interfaces.ts
Created March 5, 2015 17:20
cursor interfaces
interface CourseCursor extends Cursor<Course> {
rules: RulesCursor;
}
interface RulesCursor extends Cursor<Rules> {
...
}