Skip to content

Instantly share code, notes, and snippets.

@evancz
evancz / Preferences.sublime-settings
Created August 22, 2019 16:21
my settings for Sublime Text
{
"color_scheme": "Monokai.sublime-color-scheme",
"ensure_newline_at_eof_on_save": true,
"fold_buttons": false,
"font_face": "Inconsolata",
"font_size": 16,
"ignored_packages":
[
"Vintage"
],
@evancz
evancz / Ports.js
Last active March 21, 2019 17:37
Example usage of Elm "ports" that uses signals, non-signals, records, and tuples. Build the Elm code with "elm --only-js Shanghai.elm" and include all of the JS in the HTML document.
// initialize the Shanghai component which keeps track of
// shipping data in and out of the Port of Shanghai.
var shanghai = Elm.worker(Elm.Shanghai, {
coordinates:[0,0],
incomingShip: { name:"", capacity:0 },
outgoingShip: ""
});
function logger(x) { console.log(x) }
@evancz
evancz / font-face.md
Last active March 14, 2019 09:07
It seems really complicated to use custom fonts well. This explores some ideas of how to make it easier.

Making it easier to load fonts

I have been doing a lot of work on making Elm assets really tiny. As part of some exploratory research I did ages ago, I read this document on font loading. It is a super helpful resource, but I was confused by all the different terms: FOIT, FOUT, FOFT, etc. It reminded me of the old "how do you center things?" blog posts from before flexbox. So my instinct was that probably lots of folks are confused about how to do it well, and maybe there is a better way!

So brainstormed some some ideas to:

  1. Save even more bits.
  2. Have an ideal visual experience.
  3. Be really easy to set up.

Project Idea

I think it would be really interesting to do some data visualizations with the Labor Force Participation Rate.

If you go to this Labor Fource Participation graph and change the range to 1948 to 2018. You will see:

  1. Millions of women joining the labor force starting in the 60s. (source)
  2. Of the 11 recessions that occurred in that time, only 2008 caused such a big downward swing. About 10 million people stopped working since then! Why? Did two-income households become single-income? And wait, isn't the unemployment rate really low right now?
  3. The unemployment rate only counts people who are looking for work (by some definition of looking) and different governments count that different! So what about discouraged workers? And what happens whe
@evancz
evancz / union-types.md
Last active March 12, 2018 13:14
Imagine conversations and questions for a time when people say "union type" instead of "algebraic data type". Think about how the responses might work if you said "ADT" instead.

Union Types

If Elm community is going to begin referring to "union types" instead of "algebraic data types" we should think about how that will work in practice. What discussions will we have? Will we find ourselves in awkward spots trying to explain things?

The following question/answer pairs simulate things I'd expect to see in a world of "union types". The pairs are grouped by what background I expect the questions to come from so we know the subtext. I have also added some meta comments in italic to explain my phrasing.

One thing to consider is that a lot of learners will not have a person to ask, so the path to arriving at these answers needs to be easy if you are just searching online.

General Questions

@evancz
evancz / Focus.md
Last active March 3, 2017 14:58
Potential outline of a simple and useful lens library for Elm

Focus

A Focus is a way to work with particular parts of a large chunk of data. On the most basic level, it lets you get and set fields of a record in a simple and composable way. This means you could avoid writing special record update syntax and use something that composes much more elegantly.

This API is inspired by the concept of Bidirectional Lenses as described by Nate Foster and seen in a modified form in Haskell as "lenses" and in ClojureScript as "cursors". My personal opinions and understanding comes from this talk by Simon Peyton Jones, discussions with @seliopou, and a basic understanding of Nate Foster's PhD thesis on bidirectional lenses. I chose the name "Focus" for this outline because it is sort of like a lens that only lets you see in one direction.

Here's the pseudocode that describes the basic API:

modul
import Dict exposing (Dict)
import Html exposing (..)
type Rank = King | Queen | Bishop | Knight | Rook | Pawn
type Color = Black | White
type alias Piece =
{ rank : Rank
import Dom
import Dom.Scroll
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Process
import Task
import WebSocket

Elm 0.17.1

Install

This is a patch release. Everything is the same, just slightly better!

The main changes are:

  • Default dependencies in elm-package.json are elm-lang/core and elm-lang/html.
  • Error messages for elm-package are improved (e.g. this and this)

Here is one of the changes I needed to make in package.elm-lang.org.

The issue was that the code was relying on linkQualified to always get a non-empty string as the token argument. While it is true that that will happen for the foreseeable future, I took this as an opportunity to do a more serious refactor so that the code was nicer and if it ever breaks in the future it will give me a very specific message.

Before

linkQualified : List String -> String -> Text.Text
linkQualified modules token =
  case List.reverse (String.split "." token) of