Skip to content

Instantly share code, notes, and snippets.

View lydell's full-sized avatar

Simon Lydell lydell

View GitHub Profile
@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
@lydell
lydell / Debug.log.original.js
Created October 30, 2022 13:05
Patch for Elm’s Debug.log that gives you an interactive value in the console
var _Debug_log = F2(function(tag, value)
{
console.log(tag + ': ' + _Debug_toString(value));
return value;
});
@lydell
lydell / bigrams-all.json
Created August 23, 2015 09:31
English bigram and character pair frequencies from Michael Dickens in JSON format
[
["e ",2357988],
[" t",2060528],
["th",1810335],
[" a",1554503],
["he",1523680],
["s ",1435225],
["in",1318298],
["t ",1268890],
["d ",1188359],
@lydell
lydell / doomsday.mjs
Created September 12, 2022 17:57
Doomsday algorithm
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 / .gitignore
Last active August 18, 2022 13:39
Trying to use ESLint’s RuleTester with Jest
node_modules
@lydell
lydell / zip.bash
Created March 18, 2022 21:52
GitHub source zipball reproduction attempt
#!/usr/bin/env bash
# Example:
#
# 1. git clone git@github.com:elm/core.git
# 2. cd core
# 3. ./zip.bash 1.0.5 out.zip elm/core
# 4. Compare outputs of:
# - `unzip -l out.zip` and `unzip -l github-zipball.zip`
# - `wc -c out.zip` and `wc -c github-zipball.zip`
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"module": "CommonJS",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
import * as Decode from "tiny-decoders";
import { ErrorTemplate, fancyError } from "./Errors";
import { join, RESET_COLOR } from "./Helpers";
import { NonEmptyArray } from "./NonEmptyArray";
import { AbsolutePath, ElmJsonPath, OutputPath } from "./Types";
// https://github.com/elm/compiler/blob/94715a520f499591ac6901c8c822bc87cd1af24f/compiler/src/Reporting/Doc.hs#L412-L431
// Lowercase means “dull” and uppercase means “vivid”:
// https://github.com/elm/compiler/blob/94715a520f499591ac6901c8c822bc87cd1af24f/compiler/src/Reporting/Doc.hs#L369-L391
@lydell
lydell / pnr_check_digit.js
Created September 17, 2021 19:00
Calculate the last digit of a Swedish personnummer – Note: don’t include `19` or `20` at the start!
check = s => { let v = s.split("").map((c, i) => { let d = Number(c); let m = i % 2 === 0 ? d * 2 : d; return m > 9 ? m - 9 : m }).reduce((a, b) => a + b, 0); return (10 - (v % 10)) % 10}