Skip to content

Instantly share code, notes, and snippets.

import java.util.*;
/**
* Nondeterministic finite automaton for recognising language of {aa, aab}*{b}
*
* @see http://www.dennis-grinch.co.uk/tutorial/nfa
* @author Dennis Grinch
*/
public class NFA {
/**
* Deterministic finite automata for recognising language of strings with
* following conditions:
*
* 1. It must contain only :, ), (, and _ characters.
* 2. :has to be followed by ) or (.
* 3. Has to have at least one smiley :) or sad :( face.
* 4. If string has more than one face, then all of them have to be separated by at least one _ character.
* 5. Each string can start and end with zero or more _ characters.
*
init : Maybe Token -> Location -> ( Model, Cmd Msg )
init token location =
let model =
{ initialModel
| token = Maybe.map RemoteData.succeed token |> Maybe.withDefault RemoteData.NotAsked
, route = parseLocation location
}
in
fetchPosts model
|> andThen fetchUser
landing : Model -> Html Msg
landing model =
case model.posts of
NotAsked ->
div [] []
Loading ->
withLoader (div [] [])
Success posts ->
RemoteData.map userHeader model.user
|> RemoteData.withDefault authHeader
graphcool: String
graphcool = "https://api.graph.cool/simple/v1/cjbm8w2980rge0186pld48aan"
fetchPosts: Cmd Msg
fetchPosts =
Http.post graphcool (jsonBody <| Encoders.postsQuery) decodePosts
|> RemoteData.sendRequest
|> Cmd.map Messages.OnFetchPosts
createRequest : Form -> String -> Http.Request Post
decodePosts : Decoder.Decoder (List Post)
decodePosts =
Decoder.list decodePost
|> Decoder.field "allPosts"
|> Decoder.field "data"
decodeGraphcoolToken : Decoder.Decoder String
decodeGraphcoolToken =
Decoder.string
|> Decoder.field "token"
postsQuery : Encoder.Value
postsQuery =
Encoder.object
[ ( "query", Encoder.string "query {allPosts(orderBy: createdAt_DESC){id title body}}" ) ]
authenticate : Token -> Encoder.Value
authenticate token =
let
query =
"mutation {authenticate (accessToken: \"" ++ token.accessToken ++ "\"){token}}"
{
"name": "elm-blog",
"version": "1.0.0",
"description": "An example of Elm blog.",
"devDependencies": {
"graphcool-lib": "^0.1.4",
"isomorphic-fetch": "^2.2.1",
"jsonwebtoken": "^8.1.0",
"jwks-rsa": "^1.2.1"
}
type AuthenticationPayload {
id: String!
token: String!
}
extend type Mutation {
authenticate(accessToken: String!) : AuthenticationPayload
}
types: ./types.graphql
functions:
authenticate:
type: resolver
schema: ./src/authentication.graphql
handler:
code:
src: ./src/resolvers/authenticate.js
environment:
AUTH0_DOMAIN: nookit.eu.auth0.com