Skip to content

Instantly share code, notes, and snippets.

View eborden's full-sized avatar
💙

Evan Rutledge Borden eborden

💙
View GitHub Profile
@eborden
eborden / gist:e69054ec4c463bfd2f9a
Last active August 29, 2015 14:04
Node server to test whether chunked resources are loaded if the head element is partial. Should log: "title: " and "title: stuff"
const http = require('http');
http.createServer(function (req, res) {
if (req.url == '/script.js') {
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.end('console.log("title: " + document.title);'
+ 'setTimeout(function() {'
+ ' console.log("title:" + document.title);'
+ '}, 300);'
@eborden
eborden / Main.hs
Last active August 29, 2015 14:21
Rust's "Dining Philosophers" solution reimplemented in unidiomatic Haskell
module Main where
import Prelude hiding (sequence)
import Control.Concurrent
import Data.Foldable
import Data.Traversable
data Philosopher = Philosopher
{ name :: String
, left :: Int
@eborden
eborden / MontyHall.hs
Last active April 14, 2016 03:24
Various evaulation strategies for the Monty Hall problem with good and bad performance.
{-# LANGUAGE BangPatterns #-}
module Main (main) where
import Control.Concurrent.Async (mapConcurrently)
import Control.Monad.Writer (Writer, runWriter, execWriter, tell)
import Control.Parallel (pseq, par)
import Data.Foldable (foldl', fold)
import Data.Monoid ((<>))
import Data.Vector (Vector)
import Data.Vector.Generic ((!))
@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
@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 / 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 / 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 / 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 / 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
{
"adaptiveLowestDomain": "aengesha",
"adaptiveLevelsPassed": 0,
"domainDetails": [
{
"adaptiveStandardProgression": [
{
"changeDate": "2017-08-02T16:03:46.936525Z",
"standardId": "ohbeecei"
}