Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Bohde joshbohde

View GitHub Profile
@joshbohde
joshbohde / add.js
Last active Jun 5, 2018
example webpack & mocha project
View add.js
// a simple module
exports.add = function(a, b) {
return a + b;
};
@joshbohde
joshbohde / Order.hs
Last active Mar 11, 2018
Example of Haskell code I see under tested a lot
View Order.hs
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
@joshbohde
joshbohde / zip.hs
Created Apr 18, 2017
join for a hypothetical ziplist monad is the diagonal of the product
View zip.hs
-- 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, ...]
@joshbohde
joshbohde / test.sh
Created Mar 12, 2016
auto run hspec tests with stack using ghcid
View test.sh
ghcid -c 'stack ghci --test' --test 'Test.Hspec.hspec Main.spec'
View Test.hs
{-# 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.
View gist:24b1e02f2112d5faf29b
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)
View binary-results.txt
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
View ForkChurch.hs
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)
View Fork.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
module Fork where
import Control.Applicative (Applicative, pure, (<$>), (<*>))
data Fork f a = Halt a
@joshbohde
joshbohde / Main.lhs
Last active Aug 29, 2015
QueueDeadlocking
View Main.lhs
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)
You can’t perform that action at this time.