Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / .gitignore
Last active September 12, 2018 08:25
StateT Parser
dist
@bradparker
bradparker / Lens.hs
Last active August 23, 2018 05:23
Lenses
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Control.Applicative (Applicative(..))
import Data.Bool (Bool(False, True), not)
import Data.Char (toUpper)
import Data.Function (($), (&), (.), const, flip)
@bradparker
bradparker / recursive-foldable.hs
Last active May 10, 2018 05:05
Recurisive foldable... more or less
{-# LANGUAGE DeriveFoldable #-}
module Main where
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Foldable
data Object a
= Value a
module Main
( main
) where
import Control.Arrow ((&&&))
import Control.Monad.Trans.State (StateT(StateT), evalStateT)
import Data.List (uncons, unfoldr)
import Data.Maybe (fromMaybe, listToMaybe)
import System.Environment (getArgs)
@bradparker
bradparker / Scott.hs
Last active April 25, 2019 07:36
Wow
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
module Scott where
import qualified Prelude as Builtin
import qualified Data.Char as Builtin
import GHC.Num (Num(fromInteger, (-), (+)))
@bradparker
bradparker / weekdays-until.hs
Last active January 25, 2018 07:23
Weekdays Until
module Main where
import Data.Time
import Data.Time.Clock
import Data.Time.Format
import Data.Time.Calendar
import Data.Maybe
import System.Environment
import Text.ParserCombinators.ReadP
import Data.Char
@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
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 / 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
@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`