Skip to content

Instantly share code, notes, and snippets.

View jfischoff's full-sized avatar
™️
Jonathaning

Jonathan Fischoff jfischoff

™️
Jonathaning
View GitHub Profile
waitForPort :: Int -> IO ()
waitForPort port = handle (\(_ :: IOException) -> threadDelay 10000 >> waitForDB port) $ do
let hints = defaultHints
{ addrFlags =
[ AI_NUMERICHOST
, AI_NUMERICSERV
]
, addrSocketType = Stream
}
addr:_ <- getAddrInfo (Just hints) (Just "127.0.0.1") (Just $ show port)
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE LambdaCase #-}
module Network.TCP where
import Data.Set (Set)
data PacketFlag = NS | CWR | ECE | URG | ACK | PSH | RST | SYN | FIN
deriving (Eq, Show, Ord)
type Packet = Set PacketFlag
data Edit a
= Insert a
| Delete a
| Same a
deriving (Show, Eq)
isSame :: Edit a -> Bool
isSame x = case x of
Insert {} -> False
Delete {} -> False
@jfischoff
jfischoff / gist:999abf4ac5e5dc516d3a
Created December 31, 2014 22:40
A mix of Vinyl style and SOP style
foldRRec :: forall f xs c a b p.
RecAll f xs c
=> p c
-> (forall x. c x => x -> a)
-> (a -> b -> b)
-> b
-> NP f xs
-> b
foldRRec p convert f z xs
= foldRRec' convert f z
@jfischoff
jfischoff / gist:b2f8c60883f2cfd0b187
Created December 13, 2014 23:51
Use case for reflection non law abiding Eqs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
module Approx where
import Data.Reflection
import Data.Proxy
import Foreign.Storable
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
@jfischoff
jfischoff / gist:df07e95ed8c3bd432a0f
Last active August 29, 2015 14:09
An iso between Sing xs and Rec Sing xs
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
@jfischoff
jfischoff / gist:912bf2243f40d158ffa8
Created November 15, 2014 07:04
Printing field names with the new-vinyl branch of Vinyl
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
@jfischoff
jfischoff / gist:4166914
Last active October 13, 2015 08:18
Fun with Polynomials
{-# LANGUAGE FlexibleContexts #-}
module Algebra.Monomial where
import Data.List
import Data.Function
import Text.Parsec hiding (parse)
import qualified Text.Parsec.Token as P
import qualified Text.Parsec.Language as P
import Control.Applicative ((<$>))
import Data.Functor.Identity
@jfischoff
jfischoff / gist:4034291
Created November 7, 2012 20:41
Type Level Associative Array
{-# LANGUAGE PolyKinds, DataKinds, TemplateHaskell, TypeFamilies,
GADTs, TypeOperators, RankNTypes, FlexibleContexts, UndecidableInstances,
FlexibleInstances, ScopedTypeVariables, MultiParamTypeClasses,
OverlappingInstances, TemplateHaskell #-}
module Oxymoron.Regions.TAssociativeArray where
import Data.Singletons
singletons [d| data AssocArray a b = AssocArray [(a, b)] |]
type instance ('AssocArray xs) :==: ('AssocArray ys) =