Skip to content

Instantly share code, notes, and snippets.

@mgold
mgold / .block
Last active December 2, 2016 06:31
Ellipse Interpolation
license: mit
@mgold
mgold / .block
Created July 22, 2016 04:12
Basis Vectors
license: gpl-3.0
module SpinSquare (Model, Action, init, update, view) where
{-| A fork of the eight example in the Elm Architecture tutorial, showing how it would be done with elm-animation. It
turns out to be a lot simpler, both because of the animation itself and because we cheat a little: we don't stop
asking for clock ticks even when we don't need them. This saves a lot of bookkeeping around current vs. elapsed
time, as the animation library assumes you have a constantly running clock shared among all components.
By definition, encapsulated components cannot share a clock, and so as you add more squares, expect things to get
slower. That said, two squares work just fine. This module is a drop-in replacement for the upstream version.
@mgold
mgold / README.md
Last active April 17, 2016 22:04
Brady Campaign vs. the NRA on Senators

This scatterplot shows how the pro-gun NRA and the pro-gun-control Brady Campaign rank U.S. senators. The size of the dot is proportional to the number of senators; hover over to see them. Not surprisingly, there's a strong negative correlation.

Each scatter dot is actually a pie chart, but I am saved from the wrath of the datavis gods by political polarization: there are no Democrats and Republicans that share a stance.

The data were surpringly hard to come by but were sourced from VoteSmart (Brady) and The Washington Post (NRA).

Built with blockbuilder.org.

@mgold
mgold / SuperTimer.elm
Created February 12, 2016 14:40 — forked from shamrin/SuperTimer.elm
Restartable timer
module SuperTimer where
import Html exposing (..)
import Html.Events exposing (onClick)
import Time exposing (Time)
import Signal exposing (Address)
type Action = Tick Time | Toggle Bool | NoOp
type alias Model = { running: Bool, count: Float}
@mgold
mgold / elmpackager.rb
Created March 24, 2016 20:37
A script to help installing elm packages.
require "json"
require "net/http"
require "uri"
def download(name)
puts "Installing " + name
`elm package install #{name} --yes`
end
def prompt(instructions)
@mgold
mgold / proposal.elm
Last active February 12, 2016 01:34
Elm mailbox revamp
-- a distilation of https://github.com/elm-lang/elm-plans/issues/7
{- Mailbox is renamed Dispatcher, although this name is the part I'm least certain about.
The address field is replaced with a dispatch field.
It's minor, but I've found it helpful to put dispatch second, since the signal is easier to explain.
-}
type alias Dispatcher a =
{ signal : Signal a
, dispatch : a -> Message -- the big change
}
@mgold
mgold / README.md
Last active February 2, 2016 15:30
Triangle Centers

Different ways to find the "center" of a triangle. Inspired by Numberphile. Grab and move the vertices of the large triangle.

  • The centroid is found by connecting each angle with the midpoint of the opposite side. All three such lines meet at a single point.

  • The circumcenter is is the intersection of the perpendicular bisectors of each side. Therefore it is equidistant from the three vertices, and is the center of the circle defined by them.

  • The orthocenter is defined by dropping a vertical from each angle down to the opposite side (extending the side if necessary). The vertical does not usually intersect at the midpoint. Once again, all three such lines intersect at one point.

  • The incenter is defined by bisecting each angle with a line continued to the opposite side.

@mgold
mgold / spinner.elm
Created August 27, 2013 02:08
A spinning canvas on which you can paint. Try it: http://share-elm.com/gists/6348912
-- Spinner by Max Goldstein
import Mouse
import Window
import Dict (Dict, empty, toList, insert, findWithDefault)
import Automaton (Automaton, state, run)
import Graphics.Input (button)
-- MODEL
@mgold
mgold / bitmapDraw.elm
Created August 27, 2013 01:54
An infinite grid of black and white pixels in your browser. Try the t, b, w, and c keys after clicking and dragging on this page: http://share-elm.com/gists/6348835/
-- Bitmap Draw by Max Goldstein
-- Change the cursor mode with the keyboard:
-- t Toggle (default)
-- b Black
-- w White
-- c Clear (automatically resets to Toggle afterwards)
import Mouse
import Keyboard