Skip to content

Instantly share code, notes, and snippets.

Brad bradparker

Block or report user

Report or block bradparker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bradparker
bradparker / iterate.js
Last active Nov 1, 2019
Flattening nested iterators ... for use with weird DynamoDB scan API
View iterate.js
const testItems = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const limit = 2;
const getBatch = (cursor = null) => {
const currentCursor = cursor || 0;
const nextPotentialCursor = currentCursor + limit;
const nextCursor = nextPotentialCursor > 10 ? null : nextPotentialCursor;
return new Promise(resolve =>
setTimeout(() => resolve({
@bradparker
bradparker / Ind.hs
Created Jul 28, 2019
Trying to figure out B. Milewski's slide from Lambda Jam 2019
View Ind.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall #-}
@bradparker
bradparker / Refined.ts
Last active Jul 25, 2019
Refinement type-y kinda things
View Refined.ts
interface Refinement<A> {
tag: string;
value: A;
}
interface Refined<A, R> {
value: A;
refinement: R;
}
View Bits.hs
import Control.Monad.State
import Data.Traversable
import Data.Tuple
toByteBits :: Integral n => n -> [n]
toByteBits =
evalState (for [1..8] (\_ -> state (\s -> swap (divMod s 2))))
main = do
print $ toByteBits 1
@bradparker
bradparker / Byte.hs
Last active Jul 6, 2019
Bytes and Folds / Traversals
View Byte.hs
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE RankNTypes #-}
module Byte where
import Data.Bool (bool)
import Data.Functor.Const (Const(Const, getConst))
import Data.Bits ((.&.), (.|.), xor)
import Prelude hiding (sum)
@bradparker
bradparker / concurrency.ts
Created Jul 1, 2019
JS concurrency _stuff_
View concurrency.ts
interface Person {
name: string;
age: number;
}
const people: Person[] = [{ name: "Bob", age: 100 }, { name: "Jane", age: 50 }];
const findPeople = (candidate: string): Promise<Person[]> => {
return new Promise(resolve => {
const timeout = Math.floor(Math.random() * 100);
@bradparker
bradparker / App.ts
Created Jun 16, 2019
Geneator function do notation experiment
View App.ts
import * as Either from "./Either";
type Action<I, E, A> = (input: I) => Promise<Either.Either<E, A>>;
export class App<I, E, A> {
public run: Action<I, E, A>;
public constructor(action: Action<I, E, A>) {
this.run = action;
}
@bradparker
bradparker / prepare-commit-message
Last active May 31, 2019
Git Hook to prepend a commit message with the Jira ticket id at the start of the current branch's name
View prepare-commit-message
#!/usr/bin/env bash
branchname=$(git branch | grep ^* | sed 's/\* //g')
regex="([A-Z]*-[0-9]*)"
if [[ $branchname =~ $regex ]]
then
ticket_id="${BASH_REMATCH[1]}"
message=`cat $1`
View Traversals.hs
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE FlexibleInstances #-}
module Traversals where
import Control.Applicative (Applicative(..))
import Data.Bool (Bool(True))
View LensesAndFunctionalReferences.hs
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
module LensesAndFunctionalReferences where
import Data.Char (chr, ord, toUpper)
import Data.Functor.Const (Const(Const, getConst))
import Data.Functor.Contravariant (Contravariant(contramap))
import Data.Functor.Identity (Identity(Identity, runIdentity))
You can’t perform that action at this time.