Skip to content

Instantly share code, notes, and snippets.

View bohde's full-sized avatar

Rowan Bohde bohde

View GitHub Profile
@bohde
bohde / add.js
Last active June 5, 2018 02:57
example webpack & mocha project
// a simple module
exports.add = function(a, b) {
return a + b;
};
@bohde
bohde / Order.hs
Last active March 11, 2018 19:13
Example of Haskell code I see under tested a lot
module Order where
-- DBM is some Monad Transformer stack that allows us to talk to our DB (also a form of DI!)
placeOrder :: User -> OrderDetails -> DBM ()
placeOrder user details = do
-- Some users will have discounts for
(discount :: Maybe Discount) <- findRelevantDiscount user details
-- Create the specific order for this user with any discount
@bohde
bohde / zip.hs
Created April 18, 2017 21:00
join for a hypothetical ziplist monad is the diagonal of the product
-- https://en.wikibooks.org/wiki/Haskell/Category_theory#The_second_law
join . fmap return = join . return = id
return = repeat
join . fmap repeat = join . repeat = id
-- let's try it on some arbitrary list
join [repeat a, repeat b, ...] = join (repeat [a, b, c, ...]) = [a, b, c, ...]
@bohde
bohde / test.sh
Created March 12, 2016 17:36
auto run hspec tests with stack using ghcid
ghcid -c 'stack ghci --test' --test 'Test.Hspec.hspec Main.spec'
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
module Data.HdrHistogram.Config.Test where
import GHC.TypeLits (Nat, type (<=))
-- Is there a way to add constraints to these kinds? For example, 1 <= sig <= 7, or lowest <= highest.
-- I found https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:-60--61--63-, but don't know how to use it.
irb(main):001:0> require 'riemann/dash'
=> true
irb(main):002:0> require 'riemann/dash/browser_config/s3'
Gem::LoadError: Unable to activate fog-json-1.0.2, because multi_json-1.3.6 conflicts with multi_json (~> 1.10)
@bohde
bohde / binary-results.txt
Created June 14, 2015 13:44
protobuf benchmarks
Running 1 benchmarks...
Benchmark bench: RUNNING...
benchmarking burst/encoding/1
time 520.7 ns (512.9 ns .. 529.5 ns)
0.997 R² (0.992 R² .. 0.999 R²)
mean 516.5 ns (509.9 ns .. 534.9 ns)
std dev 32.75 ns (12.46 ns .. 65.36 ns)
variance introduced by outliers: 77% (severely inflated)
benchmarking burst/encoding/10
module Fork where
newtype Fork' f a = Fork' { runFork :: forall r. (a -> r) ->
(f r -> r) ->
(forall b. Fork' f b -> r -> r) -> r } deriving Functor
instance Applicative (Fork' f) where
pure a = Fork' (\kh _ _ -> kh a)
Fork' f <*> Fork' g = Fork' (\kh ka kf -> f (\a -> g (\b -> kh (a b)) ka kf) ka kf)
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
module Fork where
import Control.Applicative (Applicative, pure, (<$>), (<*>))
data Fork f a = Halt a
@bohde
bohde / Main.lhs
Last active August 29, 2015 14:20
QueueDeadlocking
Here is a test runner that uses quickcheck to generate programs against
a concurrent queue api, to hopefully find the intentional bugs in
it's implementation.
> main :: IO ()
> main = hspec $ do
> describe "queue" $ do
> it "should not ever allow the client to block" $ property $ \program scheduler -> do
> res <- interpret scheduler $ new >>= runProgram program
> res `shouldSatisfy` (isRight)