Skip to content

Instantly share code, notes, and snippets.

View lydell's full-sized avatar

Simon Lydell lydell

View GitHub Profile
@lydell
lydell / elm-watch-garbage-collection.html
Created July 21, 2024 18:03
Explains why elm-watch has been leaking memory when hot reloading, and how to fix it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>elm-watch garbage collection</title>
</head>
<body>
<script>
(function (scope) {
@lydell
lydell / copy-names.js
Created May 5, 2024 17:39
Elm functions that return Cmd
// https://elm.dmy.fr/?q=elm%2F
// https://elm.dmy.fr/?q=elm-explorations%2F
copy(Array.from(document.querySelectorAll(".pkg-summary-title a"), e => e.textContent).filter(s => s.startsWith("elm/") || s.startsWith("elm-explorations/")).join("\n"))
@lydell
lydell / elm-es5-vs-es3.md
Last active April 25, 2024 19:25
Elm output – ES5 or ES3? (It’s ES5)

For those interested in ES5 vs ES3 … it’s ES5. Trying to parse as ES3 chokes here:

var _String_filter = F2(function(isGood, str)
{
	var arr = [];
	var len = str.length;
	var i = 0;
	while (i < len)
	{
@lydell
lydell / Main.elm
Created January 6, 2024 10:34
React-looking Elm code
module Main exposing (main)
import React exposing (..)
import Zod
main = React.mount(render)
render(model) =
let
(getCount, setCount) = React.useState("count", Zod.int(), 0)
@lydell
lydell / doomsday.mjs
Created September 19, 2023 18:46
Doomsday method trainer
import * as readline from "readline";
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const lower = new Date(process.argv[2] || "0000-01-01");
const upper = new Date(process.argv[3] || "9999-12-31");
const diff = upper - lower;
function randomDate() {
return new Date(lower.getTime() + Math.random() * diff);
}
@lydell
lydell / README.md
Last active March 21, 2024 17:53
Find unused Elm record fields

Find unused Elm record fields

This script finds some unused record fields (but not all).

First run npm ci, and then:

git grep -l '^main =' | xargs elm make --output elm.js && node find-unused-record-fields.js < elm.js
@lydell
lydell / index.test.js
Created January 16, 2023 20:33
Jest 29 snapshot string escaping
test("js-tokens example", () => {
const token = {
type: "StringLiteral",
value: `""`,
};
expect(token).toMatchInlineSnapshot(`
{
"type": "StringLiteral",
"value": """",
}
@lydell
lydell / ab.fish
Created December 18, 2022 10:43
Advent of Code 2022 Day 18
begin
echo 'module Input'
echo 'let input ='
echo ' ['
cat | string replace -r ^ ' '
echo ' ]'
end >Input.fsx
dotnet fsi ab.fsx
@lydell
lydell / AB.elm
Created December 15, 2022 21:13
Advent of Code 2022 Day 15
module AB exposing (main)
import Browser
import Html exposing (Html)
import Html.Attributes
import Html.Events
import Input
import Process
import Set
import Svg exposing (Svg)
@lydell
lydell / AB.elm
Created December 14, 2022 23:08
Advent of Code 2022 Day 14 Part 1
module AB exposing (main)
import Browser
import Dict exposing (Dict)
import Html exposing (Html)
import Html.Attributes
import Html.Events
import Process
import Svg exposing (Svg)
import Svg.Attributes