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
@abradley2
abradley2 / form.ts
Created August 8, 2023 12:15
Applicative Form Validation in TypeScript
type State<s, a> = (state: s) => [s, a]
function pureState<s, a> (a: a): State<s, a | null> {
return (s: s) => [s, a]
}
function mapState<s, a1, a2> (fn: (action: a1) => a2 | null, state: State<s, a1 | null>): State<s, a2 | null> {
return (s) => {
const [nextState, action] = state(s)
if (action !== null) return [nextState, fn(action)]
@abradley2
abradley2 / app.clj
Created April 8, 2023 12:36
Clojure Jetty Hello World
(ns app.main
(:import
[javax.servlet.http HttpServletResponse HttpServletRequest]
[org.eclipse.jetty.server Request ServerConnector Server]
[org.eclipse.jetty.server.handler AbstractHandler]
[org.eclipse.jetty.util.thread QueuedThreadPool])
(:gen-class))
(defn handler [^HttpServletRequest _ ^HttpServletResponse response]
(let [writer (.getWriter (doto response
@abradley2
abradley2 / ShipData.elm
Created February 12, 2023 20:24
ShipData
module ShipData exposing (..)
type Size
= Small
| Medium
| Large
| Huge
@abradley2
abradley2 / GenerateShipData.elm
Created February 12, 2023 20:23
GenerateShipData
module GenerateShipData exposing (..)
import Elm exposing (Expression)
import Gen.ShipData
import Json.Decode as Decode exposing (Decoder)
import ShipData
exposing
( Attack
, AttackProfile
, DefenseToken(..)
@abradley2
abradley2 / init.lua
Created July 11, 2022 12:09
nvim init.lua
vim.cmd [[packadd packer.nvim]]
vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc'
local o = vim.o
o.expandtab = true
o.smartindent = true
o.tabstop = 2
o.shiftwidth = 2
@abradley2
abradley2 / LinkCapture.purs
Created July 3, 2022 01:08
Intercept link clicks in PureScript
import Prelude
import Control.Monad.Maybe.Trans (MaybeT(..), runMaybeT)
import Control.Monad.Trans.Class (lift)
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe as Maybe
import Data.Newtype (wrap)
import Data.String as String
import Effect (Effect)
import Web.DOM.Node (Node)
import Web.DOM.Node as Node
@abradley2
abradley2 / Fluture.res
Created January 9, 2022 13:49
ReScript Fluture bindings
type t<'res, 'err> = Future('res, 'err)
type cancel = unit => unit
// Creation
@module("fluture")
external future: (('res => unit, 'err => unit) => cancel) => t<'res, 'err> = "Future"
let resolve = a =>
future((res, _rej) => {
@abradley2
abradley2 / build.sh
Created May 8, 2021 11:09
Super smol Elm bundles with Uglify-js@3
#!/bin/sh
set -e
js="bundle.js"
min="bundle.min.js"
elm make --optimize --output=$js src/Main.elm
./node_modules/.bin/uglifyjs $js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | ./node_modules/.bin/uglifyjs --mangle --output $min
@abradley2
abradley2 / day-10.hs
Created December 11, 2020 16:19
day-10 (not working edition)
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
module Main where
import qualified Text.ParserCombinators.Parsec as P
type Input = [Int]
data ProcessTree = ProcessTree
@abradley2
abradley2 / day-8.hs
Last active December 9, 2020 12:52
day-8.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
module Main where
import Text.ParserCombinators.Parsec as P
data Program = Program {total :: Int, visited :: [Int], lastToggle :: Int} deriving (Show)
type InputLine = (String, Int)