Skip to content

Instantly share code, notes, and snippets.

View ElmUrlQuirk.md
import Url
import Url.Parser exposing ((<?>))
import Url.Parser.Query

"http://example.com/?key=Prefix%3A+Some+text+%2B+Some+words+%3D+Words+%40+%3CLast+word%3E"
|> Url.fromString
|> Maybe.andThen (Url.Parser.parse (Url.Parser.top <?> Url.Parser.Query.string "key"))
--> Just (Just "Prefix: Some text + Some words = Words @ <Last word>")
@choonkeat
choonkeat / ICal.elm
Created Sep 12, 2022
very rudimentary iCalendar format support in elm
View ICal.elm
module ICal exposing
( VAlarmAction(..)
, VAlarmTrigger(..)
, VCalendar(..)
, VEvent(..)
, VEventProp(..)
, VEventStatusValue(..)
, eventPropString
, eventString
, string
@choonkeat
choonkeat / destructuring.md
Created May 20, 2022 — forked from yang-wei/destructuring.md
Elm Destructuring (or Pattern Matching) cheatsheet
View destructuring.md

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
@choonkeat
choonkeat / P.elm
Last active Apr 26, 2022
elm overhead
View P.elm
module P exposing (..)
main : Program () number msg
main =
Platform.worker
{ init = always ( 0, Cmd.none )
, update = \_ _ -> ( 0, Cmd.none )
, subscriptions = always Sub.none
}
View allVariants.elm
type TrafficLight
= Red
| Yellow
| Green
allTrafficLight : List TrafficLight
allTrafficLight =
let
helper list =
@choonkeat
choonkeat / Custom Type Naming Convention.md
Last active Oct 6, 2021
Custom Type Naming Convention (hope I can gist search this time; wrote it before)
View Custom Type Naming Convention.md

In a type specific module, we can name succinctly

module Channel

type Channel
    = Alpha
    | Beta
@choonkeat
choonkeat / external-aws-account.tf
Last active Aug 1, 2021
terraform declaration to "Another AWS account" with "external ID" for infrastructure scanning purpose, e.g. Cloudcraft
View external-aws-account.tf
resource "aws_iam_role" "foobar-role" {
name = "foobar"
path = "/"
assume_role_policy = data.aws_iam_policy_document.foobar-assume-role-policy-document.json
managed_policy_arns = [aws_iam_policy.foobar-policy.arn]
}
data "aws_iam_policy_document" "foobar-assume-role-policy-document" {
statement {
actions = ["sts:AssumeRole"]
View see.tailwind.grid.html
<div class="max-w-screen bg-gray-100 text-center">
<span class="text-red-400 sm:hidden">xs</span>
<span class="text-yellow-400 hidden sm:inline md:hidden">sm</span>
<span class="text-green-400 hidden md:inline lg:hidden">md</span>
<span class="text-blue-400 hidden lg:inline xl:hidden">lg</span>
<span class="text-purple-400 hidden xl:inline 2xl:hidden">xl</span>
<span class="text-pink-400 hidden 2xl:inline 3xl:hidden">2xl</span>
</div>
@choonkeat
choonkeat / elm-compile.sh
Created Apr 20, 2021
fix for atom-elmjutsu: configure elm and elm-test executable path to these 2 scripts instead
View elm-compile.sh
#!/bin/sh
if $(which elm) $*
then
echo '{"type":"compile-errors","errors":[]}' >&2
else
touch $0
fi
View defer.js
var waitall = {
defer: [],
final: null
}
// will make sure to call `waitall.final` when all `waitall.defer` has cleared
function defer (fn) {
waitall.defer.push(fn)
return function (...args) {
var result = fn(...args)