Skip to content

Instantly share code, notes, and snippets.

@seanhess
seanhess / Microservice.hs
Created October 31, 2016 22:36
Scotty Microservice
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
import Control.Monad.IO.Class (liftIO)
import Data.Aeson (ToJSON, Value)
import Data.Time.Clock (UTCTime, getCurrentTime)
import Data.Text.Lazy (Text)
-- import Data.Monoid (mconcat)
@seanhess
seanhess / Tabs.elm
Last active September 9, 2016 06:37
module Reuse.TabsExercise exposing (..)
import Html exposing (Html, div, text, button, span, header, a)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import Html.App as Html
import Reuse.Functions as Order exposing (Msg3(..), update3, Model)
import Reuse.Examples.Button as Button
module Outside.AdvancedJson exposing (..)
import Json.Decode as Json exposing (decodeString, succeed, string, (:=), Decoder, maybe, oneOf, list, float, int)
import Json.Decode.Extra exposing ((|:))
import Json.Encode as Encode
import String
import Html exposing (div, h1, h2, text, button, ul, li, Html)
import Html.App exposing (program)
import Html.Events exposing (onClick)
import Http
fade : Bool -> Float -> Styles
fade isShown splashHeight =
[ transition "opacity 250ms, margin-top 250ms 250ms"
, opacity (float 0)
, marginTop (px -splashHeight)
]
++ if isShown then
fadeShown
else
[]
@seanhess
seanhess / Post.swift
Created August 10, 2016 19:49
Simple data objects.
//
// Post.swift
//
//
// Created by Greg Rosich on 7/14/16.
//
//
import Foundation
@seanhess
seanhess / project.clj
Created April 18, 2016 15:13
Clojure Project
(defproject sampling "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]
[reagent "0.5.1" :exclusions [cljsjs/react]]
[re-frame "0.6.0"]
[prismatic/schema "1.0.4"]]
2016-03-17 15:49:07.730 CrossProcess[22792:285165] RED
2016-03-17 15:49:07.730 CrossProcess[22792:285165] _numPoints = 17
2016-03-17 15:49:07.730 CrossProcess[22792:285165] point = {0, 0}
2016-03-17 15:49:07.731 CrossProcess[22792:285165] point = {-1, -1}
2016-03-17 15:49:07.731 CrossProcess[22792:285165] point = {-1, -1}
2016-03-17 15:49:07.731 CrossProcess[22792:285165] point = {-1, -1}
2016-03-17 15:49:07.731 CrossProcess[22792:285165] point = {-1, -1}
2016-03-17 15:49:07.731 CrossProcess[22792:285165] point = {-1, -1}
2016-03-17 15:49:07.732 CrossProcess[22792:285165] point = {-1, -1}
2016-03-17 15:49:07.732 CrossProcess[22792:285165] point = {-1, -1}
@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