Skip to content

Instantly share code, notes, and snippets.

module Main exposing (Flags, Model, Msg(..), init, main, subscriptions, update, view)
import Browser exposing (Document, UrlRequest)
import Browser.Navigation exposing (Key)
import Url exposing (Url)
type alias Flags =
{}
@manuscrypt
manuscrypt / FileUploadRequest.elm
Last active April 27, 2019 21:11
Elm: File Upload Request
doUploadFile : Maybe AuthToken -> String -> File -> (Result Http.Error UploadedFile -> msg) -> Cmd msg
doUploadFile mbToken name file msg =
Http.request
{ method = "PUT"
, headers = [Http.header "Authorization" <| "Bearer " ++ (tokenToString mbToken)]
, url = "api/upload"
, body =
Http.multipartBody
[ Http.stringPart "name" name
, Http.filePart "file" file
module Main exposing (..)
import Dict exposing (Dict)
import Html exposing (Html, div, text)
import Svg exposing (Svg, g)
import Svg.Attributes as SA
import Svg.Events as SE
type alias Idx =
module KellyColors exposing (..)
import Color exposing (..)
import Maybe exposing (..)
import List.Extra as List exposing (..)
type alias KellyDef =
{ isccNbsNr : Int, hexString : String, r : Int, g : Int, b : Int }
module Main exposing (..)
import Html exposing (div, button, ul, Html, li, text)
import Html.Attributes exposing (value, style)
import Html.Events exposing (onClick)
import Html.App as App
import Dict exposing (Dict)
import Random exposing (Seed)
cleanInput : List TileDef -> String -> String
cleanInput defs str =
let
validLetters =
List.map .letter defs
in
String.toUpper str
|> String.toList
|> List.filter (containsChar validLetters)
|> String.fromList
onKeyUp : Json.Decoder Msg
onKeyUp =
Json.oneOf
[ logged "keyDecoder" keyDecoder
-- , charCodeDecoder -- only on keypress
, logged "keyCodeDecoder" keyCodeDecoder
, logged "whichDecoder" whichDecoder
, logged "keyIdentifierDecoder" keyIdentifierDecoder
, logged "charDecoder" charDecoder
]
type alias Cell a =
{ pos: Vec2
, content: VirtualDom.Node a
}
type Cols a
= Cols (List (Cell a)) (Cell a) (List (Cell a))
type Rows a
@manuscrypt
manuscrypt / Task Basics
Created June 4, 2016 22:46
Shows how to perform a Task when the Success-Handler does not need any payload (empty tuple -> unit)
-- Check out: http://elm-community.github.io/elm-faq/#what-does--mean-1
module Main exposing (..)
import Html exposing (..)
import Html.App as App exposing (..)
import Task exposing (..)
type alias Model =