Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Lydell lydell

View GitHub Profile
View ElmMakeError.ts
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 Sep 17, 2021
Calculate the last digit of a Swedish personnummer – Note: don’t include `19` or `20` at the start!
View pnr_check_digit.js
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}
@lydell
lydell / .gitignore
Last active Aug 27, 2021
Trying to use ESLint’s RuleTester with Jest
View .gitignore
node_modules
@lydell
lydell / .gitignore
Last active Oct 19, 2021
Minify Elm code
View .gitignore
node_modules
@lydell
lydell / stable-sort.js
Last active Apr 25, 2020
A stableSort function that uses plain .sort if stable
View stable-sort.js
// 11 and 513 come from here: https://mathiasbynens.be/demo/sort-stability
function checkStable(length) {
return Array.apply(null, { length: length })
.map(function (_, i) {
return i;
})
.sort(function () {
return 0;
})
@lydell
lydell / .gitignore
Last active May 19, 2019
Experiments with import/export, React and Rollup
View .gitignore
bundle.js
node_modules
@lydell
lydell / draw-rect.js
Last active Oct 8, 2020
Visualize .getBoundingClientRect()
View draw-rect.js
function draw(rect) {
const div = document.createElement("div");
// Might be needed on crazy pages, but makes the console output for the div crazy large.
// div.style.all = "unset";
div.style.position = "absolute";
div.style.zIndex = "2147483647";
// At least _try_ to scroll along. Won’t work for inner scroll.
div.style.left = `${window.scrollX + rect.left}px`;
div.style.top = `${window.scrollY + rect.top}px`;
div.style.width = `${rect.width}px`;
View keybase.md

Keybase proof

I hereby claim:

  • I am lydell on github.
  • I am lydell (https://keybase.io/lydell) on keybase.
  • I have a public key whose fingerprint is C9F5 C6D9 0520 8814 3C8F 19AD DDEF 57C7 3914 C7EF

To claim this, I am signing this object:

@lydell
lydell / main.tex
Created Dec 28, 2017
LaTeX pagestyle confusion
View main.tex
\documentclass[twoside]{article}
\usepackage{fancyhdr}
\usepackage{extramarks}
\setlength{\headheight}{14pt}
\fancypagestyle{ttlpage}{
\fancyhf{}
\fancyhead[L]{First page head}
@lydell
lydell / _glyphicons.scss
Created May 29, 2017
Prettier SCSS, round 2
View _glyphicons.scss
@font-face {
src: url(if($bootstrap-sass-asset-helper, twbs-font-path('#{$icon-font-path}#{$icon-font-name}.eot'), '#{$icon-font-path}#{$icon-font-name}.eot'));
}
// Catchall baseclass
.glyphicon {}
// Individual icons
.glyphicon-asterisk {}