Skip to content

Instantly share code, notes, and snippets.

@evancz
evancz / cs51.md
Last active April 21, 2022 21:12
Notes for CS51 guest lecture.
@evancz
evancz / ocaml.elm
Last active December 13, 2023 16:06
Syntax Hints (OCaml -> Elm)
module Hints exposing (..)
import List
import Html exposing (..)
import Html.Attributes as A
{-----------------------------------------------------------
SYNTAX HINTS (OCaml -> Elm)
@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"
],

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 / 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.
@evancz
evancz / cron.md
Last active December 25, 2020 13:18
Cron job to remind myself to stretch

Type crontab -l to see your cron jobs. Type crontab -e to edit them. You have to use Vim apparently.

Add a line like this:

0,30	*	*	*	*	/Users/YOURNAME/Documents/scripts/stretch.sh

That is on every 0th and 30th minute of the hour. Make sure all the separators in there are tabs!

@evancz
evancz / data-interchange.md
Last active October 31, 2024 12:01
Why do I have to write JSON decoders in Elm?

A vision for data interchange in Elm

How do you send information between clients and servers? What format should that information be in? What happens when the server changes the format, but the client has not been updated yet? What happens when the server changes the format, but the database cannot be updated?

These are difficult questions. It is not just about picking a format, but rather picking a format that can evolve as your application evolves.

Literature Review

By now there are many approaches to communicating between client and server. These approaches tend to be known within specific companies and language communities, but the techniques do not cross borders. I will outline JSON, ProtoBuf, and GraphQL here so we can learn from them all.

@evancz
evancz / recursive-values.md
Last active April 2, 2024 20:16
Recursive values in Elm

Recursive Values

In a functional language, writing recursive functions is common, but it is also possible to write recursive values. Here is a simple example of a recursive value:

ones = 1 :: ones

This is an infinite loop. We just keep growing the ones list to infinity. So #873 logged folks running into this and made it an error. This was especially nice for cases like x = x + 1 where folks were expecting Elm to allow mutation.

port module Spelling exposing (..)
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import String
main =
import Dict exposing (Dict)
import Html exposing (..)
type Rank = King | Queen | Bishop | Knight | Rook | Pawn
type Color = Black | White
type alias Piece =
{ rank : Rank