Skip to content

Instantly share code, notes, and snippets.

View mwotton's full-sized avatar

Mark Wotton mwotton

View GitHub Profile
mvarEnumerator :: (MonadIO m, ToJSON a1) => (Async a, MVar a1) -> Step Builder m b -> Iteratee Builder m b
mvarEnumerator (task,mvar) step = case step of
Yield a b -> Iteratee . return . Yield a $ b
Continue s -> do
r' <- liftIO $ race (wait task) (takeMVar mvar)
s $ case r' of
Left _ -> EOF
Right r -> Chunks [fromLazyByteString $ encode r]
Error s -> error (show s)
waiApp :: Parseable a => ([(Text, Query a)] -> IO (Async (), MVar (Text,Row))) -> Application
waiApp worker = \req -> do
-- could make this a Source, but we expect it to be relatively small.
body <- lazyRequestBody req
case decode body of
Nothing -> error "booo"
Just l -> do
let (badQ,goodQ) = partitionEithers $ map (\((name::Text),q) -> (name,) `fmap` parsePythia q) l
started <- worker goodQ
return (responseSource status200 [] $ do
streamFiles :: IO () -> [FilePath] -> Source IO (Flush Builder)
streamFiles ready filepaths = do
--liftIO $ ready
yield $ Chunk $ fromLazyByteString "{"
mapM_ (\x -> do
DCC.sourceFile x $= transducer
yield $ Chunk $ fromLazyByteString ",\n")
filepaths
yield $ Chunk $ fromLazyByteString "}"
module Completions where
import Control.Applicative ((<$>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Data.Trie
buildTrie :: FilePath -> IO (ByteString -> [ByteString])
buildTrie fp = do
data Decision = Kill | Continue | Fork
pipeRateLimiter :: MonadIO m => c -> (c -> Decision) -> (c -> a -> NominalDiffTime -> c) -> Producer a m () -> Pipe a b m ()
pipeRateLimiter = undefined
@mwotton
mwotton / RateBalancer.hs
Last active August 29, 2015 14:02
attempt at a rate balancer in pipes
{-# LANGUAGE ScopedTypeVariables #-}
module Net.LambdaSpider.RateBalancer where
import Data.IORef (atomicModifyIORef', newIORef)
import Data.IORef (IORef)
import Data.Time.Clock
import Pipes
import Pipes.Concurrent
data Decision = Kill | Continue | Fork
{-# LANGUAGE ScopedTypeVariables #-}
module Net.LambdaSpider.RateBalancer where
import Data.IORef (atomicModifyIORef', newIORef)
import Data.IORef (IORef)
import Data.Time.Clock
import Pipes
import Pipes.Concurrent
data Decision = Kill | Continue | Fork
module Net.LambdaSpider.RollingSum (RollingSum, new, current, add) where
import Data.Foldable (fold)
import Data.Monoid
import Data.Sequence
import Prelude hiding (length)
data RollingSum a b = RollingSum Int (Seq a) (a -> Int -> b)
instance Show a => Show (RollingSum a b) where
@mwotton
mwotton / gist:7beae21a6748dacaa2d9
Created June 27, 2014 03:17
breakdown of intelligent test runner

from a user perspective, we want something that can run in the context of a cabal project.

it should have some idea of a hierarchy of tests (could be from tasty or hspec, i wouldn't bother trying to make it general). when it starts up, it ought to try to run all the tests, noting which ones fail (and also which ones fail to compile: ideally, you would be able to achieve local progress even if there are compile errors in other parts of the program, though it's not essential.)

when a test is failing, it should scope down to that file, and keep running that test on file change until it works. when it succeeds, the whole test suite one layer up should run, and so on up to the root of the test tree.

When a test file changes, that's easy - we just run it. When another file changes, we need to trace back all the test files that are affected by it, and add them to the list of tests to be run.

expected pain points:

orb ➜ ~/projects/livingbook/data/dict git:(master) ✗ for i in el ell; do echo -n "$i "; grep $i\$ /usr/share/dict/words| while read x; do echo $x | wc -c; done | sort -n | uniq -c; done
el 4 4
16 5
67 6
96 7
56 8
23 9
16 10
3 11
2 13