Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ericgj
ericgj / 0-description.md
Last active April 5, 2020 22:50
Implementing a REST workflow using JSON Schema, an example

Implementing a REST workflow using JSON Schema, an example

The problem domain

You are designing a document-control system. Users create and edit documents for publication. Documents can be draft, in review, on hold, in process, or published. Users have specific roles which determine which documents they have access to, and what they are permitted to do to the documents, as the documents move through the workflow. Some users are writers, others are editors.

Expressed in plain language, the rules are:

  • Writers can view their own documents regardless of status.
  • Writers can create new documents.
  • Writers can save new documents as draft, or to in review if certain information is included.
@ericgj
ericgj / actor.py
Last active February 27, 2019 21:26
sequencing tasks in dramatiq
import dramatiq
@dramatiq.actor
def sequence(environ, sequence, environ_key=None, result_key=None):
""" could be anything, just used to kick off a sequence """
return {
u'environ': environ,
u'count': len(sequence)
}
@ericgj
ericgj / f.py
Last active June 18, 2018 09:41
simple tagged union type matching in python
"""
Derived from [fn.py](https://github.com/kachayev/fn.py) function 'curried'
Amended to fix wrapping error: cf. https://github.com/kachayev/fn.py/pull/75
Copyright 2013 Alexey Kachayev
Under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0
"""
#!/bin/env python
import sys
import re
from argparse import ArgumentParser
WORD_SPLIT = re.compile('[^a-zA-Z0-9]+')
FIRST_ALPHA = re.compile('^[a-zA-Z]')
def render(args,typename,values):
@ericgj
ericgj / Main.elm
Created March 6, 2018 04:39
session example
type Page
= Search Page.Search.Model
type alias Model =
{ page : Page
, session : Session
}
type Msg
@ericgj
ericgj / sequel_dot.rb
Created September 30, 2012 02:59
ER diagrams with Sequel and Graphviz
# Usage:
# ruby sequel_dot.rb [SEQUEL-DATABASE-URI] > output.dot
# Or pipe directly to Graphviz:
# ruby sequel_dot.rb [SEQUEL-DATABASE-URI] | dot -Tgif > output.gif
#
# Note adapted from Jeremy Evans' and Rohit Namjoshi's son's code at
# http://sequel.heroku.com/2010/05/29/fun-with-graphviz-and-associations/
#
# However, instead of basing graph on model associations, this uses foreign key constraints of the db tables
# Thus, this relies on the database adapter supporting #foreign_key_list.
@ericgj
ericgj / Main.elm
Last active January 9, 2017 20:14
messy page update chains
-- update triggered by browser URL change
updatePage : Pages.Page -> Model -> (Model, Cmd Msg)
updatePage page model =
let
(valueTypesStatus, valueTypesTask) =
if isLoadedValueTypes model then
( model.valueTypes
module Validation
exposing
( ValidationResult(..)
, map, mapMessage, andThen, andMap, succeed
, withDefault
, fromMaybeInitial, fromMaybe, toMaybe
, fromResultInitial, fromResult
, toString, message, isValid, isInvalid
, validate
)
@ericgj
ericgj / form.elm
Last active October 5, 2016 01:28
import Html exposing (Html, div, button, text)
import Html.Attributes as Attr
import Html.Events as Evt
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import Json.Decode as Json
import String
sample : Person
module AutocompleteIDList exposing (..)
{-
Adapted from https://github.com/thebritican/elm-autocomplete/blob/master/examples/src/AccessibleExample.elm
**Work in Progress**
Note that the underlying items must be `List (id,item)`
and `selectedItem` is `Maybe id` .