Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Parsons parsonsmatt

View GitHub Profile
@parsonsmatt
parsonsmatt / props.py
Created Mar 15, 2016
mmm property checking
View props.py
def decode(data):
"""
Accepts a byte array and converts it into an Ack packet if possible. If the
decoding fails, then this method raises DecodeError. The following doc test
randomly samples legal values for the acknowledgment number and window size and
asserts that for all those values, Ack.decode(p.encode()) == p
>>> from random import *
>>> ack_nos = [randrange(int(1e6)) for i in range(1,10)]
>>> win_sizes = [randrange(int(1e3)) for i in range(1,10)]
View lensy-db.hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Lensy where
import Data.Functor.Identity
import Control.Lens
data Api f
@parsonsmatt
parsonsmatt / jobs.hs
Last active Nov 22, 2016
Multithreaded job system
View jobs.hs
module Jerbs where
import Control.Concurrent (forkIO, killThread)
import Control.Concurrent.STM (TQueue, atomically, newTQueueIO,
readTQueue, writeTQueue)
import Control.Exception (SomeException (..), try)
import Control.Monad (forever)
import Data.Foldable (for_)
import Data.Traversable (for)
@parsonsmatt
parsonsmatt / fails
Last active Nov 25, 2016
msgpack failing tests
View fails
Data.MsgPack
✗ that galois connection tho:
(Right Test.Main.TestVal {bar: 480996, baz: [0.5786002867755481], foo: "뎬�⸨�쭊"}) /= (Right Test.Main.TestVal {bar: 480996, baz: [0.5786002867755481], foo: "뎬�⸨�쭊"})
(Right Test.Main.TestVal {bar: -463187, baz: [0.8810286139515362, 0.7951747639082255], foo: "�"}) /= (Right Test.Main.TestVal {bar: -463187, baz: [0.8810286139515362, 0.7951747639082255], foo: "�"})
(Right Test.Main.TestVal {bar: 431163, baz: [], foo: "뒌閪�襪㎜"}) /= (Right Test.Main.TestVal {bar: 431163, baz: [], foo: "뒌閪�襪㎜"})
(Right Test.Main.TestVal {bar: 431939, baz: [0.3411815847927619, 0.7783211696792027, 0.019137335484445718], foo: "�"}) /= (Right Test.Main.TestVal {bar: 431939, baz: [0.3411815847927619, 0.7783211696792027, 0.019137335484445718], foo: "�"})
(Right Test.Main.TestVal {bar: -683034, baz: [0.09981450722544198, 0.28433427553825746, 0.6274012209043843, 0.41340820370866366, 0.8485718839096705, 0.6971856512581863], foo: "읤�"}) /= (Right Test.Main.TestVal {bar: -683034, baz
@parsonsmatt
parsonsmatt / tyfam.hs
Last active Dec 11, 2016
type families
View tyfam.hs
{-# language TypeFamilies, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, DataKinds, TypeOperators, GADTs #-}
module TyFam where
-- A type family is a function on types.
type family Element f
type instance Element [a] = a
instance MonoFunctor [a] where
View join.hs
type Join a b = Map (Key a) (Entity a, Collection b)
type Collection a = Map (Key a) (Entity a)
innerJoin
:: ( PersistEntity val1
, PersistEntity val2
, PersistField typ
, PersistEntityBackend val1 ~ SqlBackend
, PersistEntityBackend val2 ~ SqlBackend
@parsonsmatt
parsonsmatt / Beer.hs
Last active Mar 7, 2017
26 Bottles of Functional Programming
View Beer.hs
module Beer where
import Data.Char (toUpper)
main = putStrLn (song [100, 99 .. 0])
song = unlines . map verse
verse x = unlines [firstLine x, secondLine x]
View BookkeerperSchema.hs
instance ToSchema (Book' '[]) where
declareNamedSchema _ =
pure . NamedSchema Nothing $ mempty
& type_ .~ SwaggerObject
instance (KnownSymbol k, ToSchema v, ToSchema (Book' xs)) => ToSchema (Book' ( k :=> v ': xs )) where
declareNamedSchema _ = do
valRef <- declareSchemaRef (Proxy @v)
let key = Text.pack (symbolVal (Proxy @k))
rest = toNamedSchema (Proxy @(Book' xs))
@parsonsmatt
parsonsmatt / record-monoid.md
Last active May 7, 2017
Which default monoid instance would you want?
View record-monoid.md

I'm writing an extensible records library for fun and profit. I have two potential 'Monoid' instances I can give my 'HashRecord' type. Which would you prefer to see?

The record type is essentially HashRecord f xs, where xs is a type level list of (key :: Symbol) =: (value :: *) pairs, and f is a type constructor that each entry in the record is contained in.

Option 1

Delegate to the Monoid instance for the values.

You can’t perform that action at this time.