Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / pipeline.js
Last active November 17, 2016 05:51
Promise pipeline with context object...
const { assign } = Object
const mergeResults = (pipeline, step) => (
pipeline.then((context) => (
step(context).then((result) => (
assign({}, context, result)
))
))
)
@bradparker
bradparker / flat-map.js
Created January 3, 2017 04:50
Flat Map
const flatMap = (array, func) => (
array.reduce((result, element) => (
result.concat(func(element))
), [])
)
@bradparker
bradparker / hank.hs
Last active January 26, 2017 23:18
hank
module Main where
import System.IO
import Control.Concurrent
import Control.Concurrent.STM
type Error = String
data Payload
= Increment
.envrc
const URL = require('url')
const QS = require('qs')
const { createElement } = require('react')
const { renderToString } = require('react-dom/server')
const { createServer } = require('http')
const logger = require('connect-logger')
const connect = require('connect')
const components = require('./components')
module Functor
( Functor
, lift
, apply
, map
, Monad
, join
, flatMap
, Maybe(..)
@bradparker
bradparker / create-db.sh
Created July 2, 2017 02:09
Create a DB from DATABASE_URL
#! /usr/bin/env sh
# {provider}://{user}:{password}@{host}:{port}/{dbname}
provider=`echo $DATABASE_URL | grep '://' | sed 's/^\(.*\):\/\/.*/\1/'`
url_without_provider=`echo $DATABASE_URL | sed s/"$provider:\/\/"//`
# extract the user and password (if any)
userpass=`echo $url_without_provider | grep @ | cut -d@ -f1`
pass=`echo $userpass | grep : | cut -d: -f2`
@bradparker
bradparker / one-req.js
Last active July 19, 2017 01:46
One update cycle on init / success / failure of a network request.
export const finishRegistration = ({ id, attributes }) => (dispatch) => {
dispatch({
type: 'FINISH_REGISTRATION',
payload: { id }
})
return finish({ id, attributes }).then(({
registration,
personalCampaign,
account
module Data.Tree where
import Data.Monoid
data KeyValue k v = KeyValue k v
instance (Show k, Show v) => Show (KeyValue k v) where
show (KeyValue k v) = "(" ++ show k ++ ", " ++ show v ++ ")"
instance (Eq k) => Eq (KeyValue k v) where
@bradparker
bradparker / biuld-error.log
Created January 13, 2018 01:23
GHJC build error log
cabal: Entering directory '/run/user/1000/cabal-tmp-20052/ghcjs-0.2.1'
[1 of 1] Compiling Main ( /run/user/1000/cabal-tmp-20052/ghcjs-0.2.1/dist/dist-sandbox-6a8a5e5a/setup/setup.hs, /run/user/1000/cabal-tmp-20052/ghcjs-0.2.1/dist/dist-sandbox-6a8a5e5a/setup/Main.o )
Linking /run/user/1000/cabal-tmp-20052/ghcjs-0.2.1/dist/dist-sandbox-6a8a5e5a/setup/setup ...
Configuring ghcjs-0.2.1...
Flags chosen: no-wrapper-install=False, network-uri=True, compiler-only=False
Dependency Cabal ==1.24.2.0: using Cabal-1.24.2.0
Dependency HTTP ==4000.3.9: using HTTP-4000.3.9
Dependency aeson ==0.11.3.0: using aeson-0.11.3.0
Dependency array ==0.5.1.1: using array-0.5.1.1
Dependency attoparsec ==0.13.2.0: using attoparsec-0.13.2.0