Skip to content

Instantly share code, notes, and snippets.

View mossprescott's full-sized avatar

Moss Prescott mossprescott

View GitHub Profile
@mossprescott
mossprescott / ParseQueryParam.elm
Last active May 29, 2023 22:59
Parse a single query param
import Url
import Url.Parser
import URL.Parser.Query
parseQuizNumber : String -> Maybe Int
parseQuizNumber urlString =
let
dropPath : Url -> Url
dropPath url =
{ url | path = "" }
import PlaygroundSupport
import SwiftUI
struct Team: Comparable {
var name: String
var symbol: String
static func < (lhs: Team, rhs: Team) -> Bool {
return lhs.name < rhs.name
@mossprescott
mossprescott / clock.scad
Created March 26, 2022 18:34
OpenSCAD model of an interesting clock
/*
Crude copy of Fibonacci Clocks' "Hyperbola Clock" (https://www.youtube.com/watch?v=DgqTGXB9KNk).
Really needs an interesting shape for the face, but I'd rather come up with something
original than copy the original clock. Hmm...
*/
/* [Special] */
$fa = 1;
$fs = 0.2;
@mossprescott
mossprescott / pfds3.hs
Last active February 8, 2020 22:27
Binomial Heaps from Okasaki's Purely Functional Data Structures, Chapter 3
{-# LANGUAGE IncoherentInstances #-}
import ClassyPrelude hiding (link)
import GHC.TypeLits
--
-- Binomial Trees ala Okasaki's Purely Functional Data Structures, Chap. 3:
--
-- |List whose length is recorded in its type, and also in the type of each element, decreasing from
@mossprescott
mossprescott / stack_completion.sh
Created December 11, 2018 16:29
Dumb bash completion for stack
_stack()
{
local cur prev opts pkgs
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="build test --no-run-tests --test-arguments --ghc-options"
pkgs=$(find . -name package.yaml -and -not -path '*/.stack-work/*' | xargs -n 1 dirname | xargs -n 1 basename)
COMPREPLY=( $(compgen -W "$opts $pkgs" -- ${cur}) )
#! /usr/bin/env python3
"""Inspect stack.yaml in the current workspace. For each dependency referring to a git commit, check to see whether
the commit is 1) up-to-date with origin/master, 2) is ready to be merged, or 3) is behind.
Also check the stack.yaml of each referenced commit, and warn if any of _its_ dependency commits don't match.
Assumptions:
- the working directory is located somewhere within a git clone
- stack.yaml is present at the root of the clone
@mossprescott
mossprescott / unzipS3.sh
Created September 12, 2017 19:37
Download, gunzip, and concatenate a directory of (CSV) files from S3
#! /bin/bash
REMOTE_DIR=$1
LOCAL_FILE=$2
if [ -e $LOCAL_FILE ]; then
echo "File exists: $LOCAL_FILE"
exit -1
fi
@mossprescott
mossprescott / MapFuncAndEJson.md
Last active October 22, 2016 18:50
Notes on potential syntax for MapFunc with (mutually) embedded EJson

EJson

Starts with all of JSON, so needs ", {, [, number literals, true, false, null (and :, , in context).

Metadata looks like data @ metadata, and the "extended" types are all encoded with it. E.g. "<z85-encoded string>" @ { "ejson.type": "ejson.binary" }.

MapFunc

MapFunc is all functions of zero, one, two, or three arguments. So probably you can write it with parens as in:

@mossprescott
mossprescott / RenderTreeT.scala
Created October 13, 2016 18:29
Following ShowT
@typeclass trait RenderTreeT[T[_[_]]] {
def render[F[_]](tf: T[F])(implicit del: Delay[RenderTree, F]): RenderedTree
def renderTree[F[_]](delay: Delay[RenderTree, F]): RenderTree[T[F]] =
RenderTree.make(render(_)(delay))
}
object RenderTreeT {
implicit val fix: RenderTreeT[Fix] = new RenderTreeT[Fix] {
def render[F[_]](tf: Fix[F])(implicit del: Delay[RenderTree, F]): RenderedTree =
del(renderTree[F](del)).render(tf.unFix)
@mossprescott
mossprescott / mount.md
Created October 4, 2016 12:56
MOVE /mount notes
curl -i localhost:8080/metadata/fs/
curl -i -X PUT localhost:8080/mount/fs/foo/ -d '{ "mongodb": { "connectionUri": "mongodb://localhost" } }'
curl -i -X PUT localhost:8080/mount/fs/foo/bar -d '{ "view": { "connectionUri": "sql2://?q=select+*+from+baz" } }'
curl -i localhost:8080/metadata/fs/foo/
curl -i -X DELETE localhost:8080/mount/fs/foo/


curl -i -X MOVE -H "Destination: /foo2/" localhost:8080/mount/fs/foo/
curl -i -X MOVE -H "Destination: /foo2/" localhost:8080/data/fs/foo/