Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Janiczek Janiczek

View GitHub Profile
@Janiczek
Janiczek / README.md
Last active Jul 12, 2022
Elm ultisnips
View README.md
View elm-make-readable.mjs
import fs from 'fs/promises';
const rules = [
{
rule: /var ([^=]+)( = F\d\([^f]+function)[^(]\(/gmi,
replacement: `var $1$2 __$1( `,
},
{
rule: /(\sA\d\([\s]+)([^,]+)(,[\s]+)(function[^(]+)\(/gm,
replacement: `$1$2$3$4___$2(`,
},
@Janiczek
Janiczek / 01_Exploration of elm-random limits.md
Last active Apr 2, 2022
Exploration of elm/random limits
View 01_Exploration of elm-random limits.md

Exploration of elm/random limits

The goal of this exploration is to find out what happens in Random.int 0 <N> for various N, particularly along the top end.

The generator says:

Generate 32-bit integers in a given range.

This generator can produce values outside of the range [minInt, maxInt] but sufficient randomness is not guaranteed.

View ElmHelloWorld.elm
module ElmHelloWorld exposing (main)
import Html exposing (Html)
import Json.Decode as Decode exposing (Value)
import WebComponent
type alias Flags =
{ name : Maybe String }
@Janiczek
Janiczek / elm-build-cache.mjs
Last active Feb 4, 2022
Build ~/.elm cache manually without checking SHA1 hashes
View elm-build-cache.mjs
#!/usr/bin/env node
// the .mjs extension is important
// run this inside the directory containing the `elm.json` file
// (if it's not executable, run `chmod +x elm-build-cache.mjs`)
// with VERBOSE=1 env var it will show you results of the exec commands
import fs from 'fs/promises';
import {exec} from 'child_process';
View tapl
#!/usr/bin/env python
# Expects `apl` on the $PATH (GNU APL)
# Usage: echo '{(+/W)%NmW},N1+?5 5S2' | tapl
import sys
import subprocess
from itertools import groupby
replacements = {
View Grid.Zipper.elm
module Grid.Zipper exposing
( Zipper
, current
, currentFocus
, currentOrDefault
, doNTimes
, doUntil
, doWhile
, duplicate
, extend
View DevShell.elm
main : Program Decode.Value Model_ Msg
main =
Browser.application
{ init = init_
, update = update_
, view = view_
, subscriptions = subscriptions
, onUrlRequest = UrlRequested
, onUrlChange = UrlChanged
}
@Janiczek
Janiczek / ConfigChild.elm
Last active Nov 23, 2021
Two child-parent view patterns
View ConfigChild.elm
module ConfigChild exposing (Config, Msg, view)
import Html exposing (Html)
import Html.Events
type Msg
= LaunchTheNukes
type alias Config msg =
{ msg : Msg -> msg
View TaskProblem.elm
-- The answer is always traverse
-- https://impurepics.com/posts/2020-10-03-always-traverse.html
Task.maybe : (a -> Task x b) -> Maybe a -> Task x (Maybe b)
Task.maybe toTask maybe =
case maybe of
Nothing ->
Task.succeed Nothing
Just input ->
toTask input