Skip to content

Instantly share code, notes, and snippets.

View seanparsons's full-sized avatar
💭
Setting A Status Message

Sean Parsons seanparsons

💭
Setting A Status Message
View GitHub Profile
scala> "[,]".parse
res0: Either[String,argonaut.Json] = Left(Unexpected content found: ,])
scala> "{,}".parse
res1: Either[String,argonaut.Json] = Left(Expected string bounds but found: ,})
# ldd -v /home/sean/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/bin/ghc
linux-vdso.so.1 => (0x00007ffc6ebe6000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f13fcb50000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f13fc948000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f13fc744000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f13fc540000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f13fc2c0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f13fbfb7000)
libHShaskeline-0.7.2.1-1dVCRhdIH7hAQWJrKwByYv-ghc7.10.2.so => /home/sean/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/bin/../haske_1dVCRhdIH7hAQWJrKwByYv/libHShaskeline-0.7.2.1-1dVCRhdIH7hAQWJrKwByYv-ghc7.10.2.so (0x00007f13fbc33000)
libHSterminfo-0.4.0.1-KvtqTNXWuWjKicEYaZ7qsx-ghc7.10.2.so => /home/sean/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/bin/../termi_KvtqTNXWuWjKicEYaZ7qsx/libHSterminfo-0.4.0.1-KvtqTNXWuWjKicEYaZ7qsx-
@seanparsons
seanparsons / argonaut.hs
Last active October 20, 2015 16:52
Thoughts about how to build Argonaut Haskell Edition.
data Json = JsonBool Bool
| JsonArray [Json]
| JsonNull
deriving (Eq, Show)
type JSONError = ()
type JSONReader a b = a -> Either JSONError (b, a)
boolReader :: (Bool -> b) -> JSONReader String b
@seanparsons
seanparsons / gist:83d37b13e60d1065eb22
Created September 18, 2015 16:28
Chef Goldfarb's Keto Chicken Pizza
Package of ground organic chicken, half bunch of kale, walnuts, 1 onion, 1 clove garlic, gorgonzola.
Mix w hands till well blended. add salt, pepper, red pepper flakes.
Spread out on either parchment or pie platepat flat, maybe 3/4 inch to 1/2 inch max.
Top pizza w Gorgonzola or other strong cheese (taleggio wd work) and other half onion, diced.
Preheat oven to 180 C, in it goes after, raise to 220c for 12 minutes..then lower to 180.
There will be a layer of fat and water from kale - remove pizza and pour off, then replace and bake 5 more min with crushed walnuts.
Remove from heat. let it cool. Consume.
Can even top w sour cream/creme fraiche/smetana.
@seanparsons
seanparsons / gist:4e4692ca01c65413cd88
Created September 4, 2015 14:26
Function definition example in Haskell.
doubleUs Int -> Int -> Int
doubleUs 0 0 = 0
doubleUs a 0 = a * 2
doubleUs 0 b = b * 2
doubleUs x y = x * 2 + y * 2
type AppRWS a = RWST ReaderEnv () () IO a
type SpockTApp a = SpockT (RWST ReaderEnv () () IO) a
@seanparsons
seanparsons / gist:51bc16518d933337cf5d
Created May 8, 2015 07:25
Baffling errors where GHC appears to be ignoring the types I've added to functions.
renderRoute :: HasRep as => S.Path as -> HVectElim as H.AttributeValue
renderRoute path =
let curryIt :: (HVect as -> H.AttributeValue) -> HVectElim as H.AttributeValue
curryIt = hVectCurry
uncurryIt :: HVectElim as Text -> HVect as -> Text
uncurryIt = hVectUncurry
renderIt :: S.Path as -> HVectElim as Text
renderIt = S.renderRoute
in curryIt $ fmap H.textValue $ uncurryIt $ renderIt path
@seanparsons
seanparsons / gist:32410870fd203bee4466
Created April 22, 2015 16:38
Trying to proxy some Thrift calls.
proxyCall :: (Typeable a) => String -> a -> Q Exp
proxyCall serviceName toProxy = do
let parameterCount n a' = case (typeRepArgs a') of
[x, xs] -> if tyConName $ typeRepTyCon x == "IO" then n else parameterCount (n + 1) xs
_ -> undefined
let noOfParameters = parameterCount 0 $ typeOf toProxy
fieldNames <- traverse (\n -> mkName ("a" ++ (show n))) [1..noOfParameters]
valueName <- fmap fromJust $ lookupValueName serviceName
return [p| $(valueName) resource $(fieldNames) = Pool.withResource pool (\(ThriftConnection _ client) -> $(toProxy) client $(fieldNames)) |]
import Control.Concurrent.Lifted
import Control.Monad.Base
import Data.IORef.Lifted
import Data.Traversable
import qualified Data.HashSet as S
import qualified Data.HashMap.Strict as M
import System.IO.Unsafe
import Debug.Trace
:set prompt "ghci> "
implicit val myEnumDecodeJson: DecodeJson[MyEnum] = DecodeJson{hCursor =>
hCursor.focus match {
case `myEnumValue1Json` => DecodeResult.ok(MyEnumValue1)
case `myEnumValue2Json` => DecodeResult.ok(MyEnumValue2)
case _ => DecodeResult.fail("Expected MyEnum.", hCursor.history)
}
}