Skip to content

Instantly share code, notes, and snippets.

View Janiczek's full-sized avatar

Martin Janiczek Janiczek

View GitHub Profile
@Janiczek
Janiczek / ElmHelloWorld.elm
Created February 24, 2022 22:32
Elm WebComponents
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 February 4, 2022 00:39
Build ~/.elm cache manually without checking SHA1 hashes
#!/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';
@Janiczek
Janiczek / tapl
Last active December 30, 2021 22:28
#!/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 = {
module Grid.Zipper exposing
( Zipper
, current
, currentFocus
, currentOrDefault
, doNTimes
, doUntil
, doWhile
, duplicate
, extend
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 November 23, 2021 16:14
Two child-parent view patterns
module ConfigChild exposing (Config, Msg, view)
import Html exposing (Html)
import Html.Events
type Msg
= LaunchTheNukes
type alias Config msg =
{ msg : Msg -> msg
-- 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
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 / Genetic.elm
Created October 4, 2021 19:00
Genetic Algorithm in Elm
module Genetic exposing (Config, Goal(..), run)
import List.Extra as List
import Random exposing (Generator)
import Random.Extra as Random
import Random.List
type alias Config solution =
{ newSolution : Generator solution
@Janiczek
Janiczek / elm-format-wrapper
Last active August 29, 2021 12:57 — forked from 4z3/elm-format-wrapper.nix
elm-format-wrapper that allows to ignore blocks of code
#!/usr/bin/env bash
# elm-format-wrapper 1.0.0
#
# Usage:
# elm-format-wrapper [--help] [--action=ACTION] PATH...
#
# Description:
# Format paths like elm-format, but allow ignoring blocks of code:
#