Skip to content

Instantly share code, notes, and snippets.

View eborden's full-sized avatar
💙

Evan Rutledge Borden eborden

💙
View GitHub Profile
@eborden
eborden / Chans.hs
Created October 13, 2017 01:19
Immortal chans
#!/usr/bin/env stack
-- stack --resolver lts-9.8 script
module Main where
import Data.Functor (void)
import Data.Foldable (traverse_, for_)
import Data.Traversable (for)
import Control.Concurrent (forkIO, readChan, writeChan, newChan, getNumCapabilities)
import Control.Immortal (create, wait, Thread)
@eborden
eborden / Main.hs
Last active September 26, 2017 15:39
Benchmark various folding averages
module Main (main) where
import qualified Control.Foldl as Fold
import Criterion.Main
import qualified Data.List
import Data.Maybe
import Data.Semigroup
naiveAvg, foldMapAvg, foldlAvg, foldAvg :: [Float] -> Float
naiveAvg xs = Prelude.sum xs / fromIntegral (Prelude.length xs)
@eborden
eborden / CompactFail.hs
Created August 24, 2017 16:36
Compaction failing on an existential type carrying a type class dict
#!/usr/bin/env stack
-- stack --resolver nightly-2017-08-20 --install-ghc runghc --package compact
{-# LANGUAGE ExistentialQuantification #-}
module Main where
import Data.Compact
class SomeClass a where
someId :: a -> a
{
"adaptiveLowestDomain": "aengesha",
"adaptiveLevelsPassed": 0,
"domainDetails": [
{
"adaptiveStandardProgression": [
{
"changeDate": "2017-08-02T16:03:46.936525Z",
"standardId": "ohbeecei"
}
@eborden
eborden / TestWithMTL.hs
Last active June 7, 2017 02:37
An example of using MTL and "mock" interpretation.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main where
import Prelude hiding (readFile, writeFile)
import Control.Monad.Trans
import Control.Monad.State
import qualified System.IO as SIO
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
@eborden
eborden / javascript.vim
Created March 20, 2017 17:12
Enable Neomake eslint per buffer per project
" Enable eslint for given project buffer
" Store current cwd
let s:prev_cwd = getcwd()
" change path to project root for current buffer
let s:project_cwd = split(expand('%:p:h'), "js")[0]
lcd `=s:project_cwd`
" Assign proper eslint vars for this buffer
let s:eslint_path = system('PATH=$(npm bin):$PATH && which eslint')
@eborden
eborden / Eithers.hs
Last active March 8, 2017 16:44
Lazyness and the duality between Sums and Products
{-# LANGUAGE NoImplicitPrelude #-}
import Data.Foldable
import Control.Applicative
data Either a b = Left a | Right b
data Eithers t a b
= Eithers
{ lefts :: t a
, rights :: t b
@eborden
eborden / coupled.js
Last active January 16, 2017 06:45
Coupling code
function accountAdd (foo, x) {
return foo.account + x
}
// accountAdd exhibits stamp coupling and data coupling.
@eborden
eborden / csv.ex
Created October 7, 2016 21:39
Naive CSV parser in Elixir
defmodule CSV do
defp linesTransform(str, acc) do
case String.split(str, ~r/\n|\r\n/) do
[] -> {:halt, acc}
[head] -> {[], acc <> head}
[head | tail] ->
interspersedLines = Enum.take(tail, Enum.count(tail) - 1)
{[acc <> head] ++ interspersedLines, List.last tail}
end
@eborden
eborden / LossyHistogram.hs
Last active September 8, 2016 17:07
Lossy Histogram On Positive Reals
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module LossyHistogram
( Histogram
, histResolution
, histMagnitude
, histBuckets
, mkHistogram
, fromList
, keys