Skip to content

Instantly share code, notes, and snippets.

View abradley2's full-sized avatar
🌳
https://elm-lang.org/

Tony Bradley abradley2

🌳
https://elm-lang.org/
  • Washington, DC
View GitHub Profile
// utility function to run a series of functions
function series (funcs, idx) {
return funcs[idx || 0] && funcs[idx || 0](series.bind({}, funcs, (idx || 0) + 1))
}
const unique = list => list.reduce((a, c) => (a.indexOf(c) < 0 ? [c].concat(a) : a), []);
@abradley2
abradley2 / i_keep_forgetting_this_lol.sh
Created December 26, 2017 15:11
i_keep_forgetting_this_lol.sh
sudo docker run -d -p 6379:6379 redis
@abradley2
abradley2 / routing.js
Created May 28, 2018 13:20
Routing in vanilla.js
// first we need to intercept all clicks on our "spa-links" so they don't trigger a page reload.
// we can then use `history.pushState` so those link clicks still change the url appropriately.
// we will use the "spa-link" attribute to specify links in our application we want to intercept the clicks
// to, so we don't break links that go to external sites other than our spa.
// for example: <a href="/in-our-spa" spa-link>Link in our SPA!</a>
document.addEventListener('click', (e) => {
if (e.target.getAttribute('spa-link')) {
e.preventDefault()
history.pushState(null, document.title, e.target.getAttribute('href'))
@abradley2
abradley2 / example.js
Created January 5, 2019 18:14
Model-View-Intent
import xs from 'xstream'
import { run } from '@cycle/run'
import * as H from '@cycle/dom'
import create from 'immutability-helper'
const INPUT = 'INPUT'
function intent (DOM) {
const inputEvents = DOM.select('.field').events('input')
.map((e) => ({
@abradley2
abradley2 / Shpa.hs
Last active August 26, 2020 15:35
Being silly with Shpadoinkle
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Shpadoinkle as S
import Shpadoinkle.Backend.ParDiff
import Shpadoinkle.Html as H
import Data.Text
@abradley2
abradley2 / style.md
Last active October 8, 2020 15:29
style-guide

Suggested Style Guide

Prefer a newline+indent and then a newline for each parameter following a tag

avoid

div []
    []
@abradley2
abradley2 / app.tsx
Last active November 16, 2020 14:05
Reactive Programming with React and Most.js
import { startWith, map, constant, merge, combineArray, runEffects, tap } from '@most/core'
import { newDefaultScheduler } from '@most/scheduler'
const textVal$ = startWith(
'',
map(
(e) => (e.target as HTMLInputElement).value,
sources.fromDOMEvent('#text-input', 'input')
)
)
@abradley2
abradley2 / day-1.hs
Last active December 2, 2020 13:51
Advent of Code 2020 Day 1
{-# LANGUAGE OverloadedStrings #-}
import Data.Text (pack, splitOn, unpack)
findMatchPartTwo :: Int -> [Int] -> Maybe Int
findMatchPartTwo total (x : xs) =
case (* x) <$> findMatchPartOne (total - x) xs of
Just m -> Just m
Nothing -> findMatchPartTwo total xs
findMatchPartTwo _ [] = Nothing
@abradley2
abradley2 / day-2.hs
Created December 3, 2020 15:08
day-2.js
{-# LANGUAGE OverloadedStrings #-}
import Text.ParserCombinators.Parsec as P
data InputLine = InputLine
{ range :: (Int, Int),
charRequirement :: Char,
content :: String
}
deriving (Show)