Skip to content

Instantly share code, notes, and snippets.

View seanhess's full-sized avatar

Sean Hess seanhess

View GitHub Profile
@seanhess
seanhess / Method.hs
Last active March 16, 2016 16:49
Servant Method combinator to match routes by method early
-- combinator that returns a mismatch if the method doesn't match
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Servant.Method where
type ModelAPI =
"models" :>
( ProjectKey :> Get '[JSON] [Model]
:<|> ProjectKey :> MultipartUpload :> Post '[JSON] Model
:<|> ProjectKey :> Capture "modelId" ID :> Get '[JSON] Model
:<|> ProjectKey :> Capture "modelId" ID :> "predictions" :> ReqBody '[JSON] PredictionInput :> Post '[JSON] Prediction
:<|> ProjectKey :> Capture "modelId" ID :> "predictions" :> Get '[JSON] [Prediction]
:<|> ProjectKey :> Capture "modelId" ID :> "predictions" :> Capture "predictionId" ID :> Get '[JSON] Prediction
)
@seanhess
seanhess / ApplicationSpecific.hs
Created February 2, 2016 21:22
Why Haskell helps with reusability
-- First, I made it application specific
attemptConnect :: Int -> TWInfo -> Manager -> APIRequest apiName responseType -> ResourceT IO (ResumableSource (ResourceT IO) StreamingAPI)
attemptConnect delay twInfo mgr = do
ms <- streamShowStatus twInfo mgr (statusesFilter accountName [accountID])
case ms of
Just s -> return s
Nothing -> do
liftIO $ putStrLn ("FAILED, delaying for " <> show delay <> "s")
liftIO $ threadDelay (delay * 1000 * 1000)
attemptConnect (delay*2) twInfo mgr
@seanhess
seanhess / StartExample.elm
Created October 20, 2015 21:06
Start-app working with initial value of inputs
module Main where
import Effects exposing (Effects, Never)
import Html exposing (Html)
import Signal exposing (Signal, Mailbox, Address)
import Signal.Extra exposing (foldp', combine, mapMany)
import Task
import StartApp exposing (Config, App)
import Debug
@seanhess
seanhess / Assignment.hs
Last active October 22, 2015 15:56
DataKinds / Proxy Assignment
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Proxy where
@seanhess
seanhess / Main.elm
Created September 16, 2015 15:28
Drag example
import Html exposing (div, button, text, Html, p, h1, span, pre)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import StartApp.Simple as StartApp
import Signal exposing (Address)
import Tangle
type alias Model =
{ tangle : Tangle.Model
@seanhess
seanhess / example.js
Created September 14, 2015 15:50
Stateless React Components
class ParentView extends React.Component {
constructor() {
this.state = {
// parent state becomes child props
items: ["one", "two", "three"]
}
}
// item is a complete domain object with enough info to do things with
onDeleteItem(item) {
@seanhess
seanhess / Form.elm
Created September 14, 2015 01:52
Form.elm
type Action
= Update String
| Enter
type alias Model = { text : String }
update : Action -> Model -> Model
update action model
case action of
Update txt -> { model | text <- txt }
@seanhess
seanhess / BetterThanChess.hs
Created September 12, 2015 18:08
BetterThanChess.hs
module Main where
import Prelude hiding (lookup)
import System.IO
import Data.Char
import Data.List as List hiding (lookup)
import qualified Data.List.Split as List
import Debug.Trace
import Control.Monad
import Data.Maybe
@seanhess
seanhess / findtype.hs
Last active August 29, 2015 14:25
Typed holes and inline typing.
main = do
foo <- getLine
return ()
-- the type of `getLine` is IO String, but how can we figure that out?
-- let's put the wrong type inline and let GHC yell at us
-- "Couldn't match expected type ‘()’ with actual type ‘IO String’"
main2 = do
-- we're checking the type of getLine here