Skip to content

Instantly share code, notes, and snippets.

View mindbat's full-sized avatar
🍻
explicit is better than implicit

Ron Toland mindbat

🍻
explicit is better than implicit
View GitHub Profile

Keybase proof

I hereby claim:

  • I am mindbat on github.
  • I am mindbat (https://keybase.io/mindbat) on keybase.
  • I have a public key ASBaRUcaZn3Q4UeRJEmEJywORliem0tq5njUwVDmu3QThAo

To claim this, I am signing this object:

@mindbat
mindbat / elm-day-three-heads.elm
Last active January 29, 2017 15:09
Elm Day Three: Heads
import Color exposing (..)
import Collage exposing (..)
import Element exposing (Element, image, leftAligned, toHtml)
import Html exposing (Html)
import Keyboard exposing (..)
import Key exposing (..)
import List exposing ((::), all, filter, length)
import Mouse exposing (..)
import Random exposing (Seed, step, initialSeed, int)
import Text exposing (color, fromString, height, monospace)
@mindbat
mindbat / elm-exmaples-day-two.org
Created January 21, 2017 17:13
Seven More Languages in Seven Weeks - Elm Day Two Examples

Updated Elm Examples

The Elm examples given in the book (especially from Day Two, forward) are for an older version of Elm. Elm 0.17 changed a lot of things in the language, including eliminating signals and moving a lot of the libraries around.

I’ve translated the Day Two examples from the book to run on Elm 0.18

Examples

Avoiding Callbacks (p. 103)

Elm 0.17+ avoids callbacks using Subscriptions, not Signals: https://gist.github.com/mindbat/7afc23cad8da000e4b26de55986d4eaf

Maintaining State (p. 104-105)

For all three of these examples, we need to swap signals for subscriptions:

@mindbat
mindbat / elm-day-two-car.elm
Last active October 25, 2016 00:30
Elm Day Two: Car
import Color exposing (..)
import Collage exposing (..)
import Element exposing (..)
carBottom = filled black (rect 160 50)
carTop = filled black (rect 100 60)
tire = filled red (circle 24)
car = collage 300 300
@mindbat
mindbat / elm-day-2-echo-text.elm
Created October 16, 2016 12:07
Elm Day 2: Echoing Text
import Html exposing (Html, text, input, div)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import String
main = App.program { init = init,
view = view, update = update, subscriptions = \_ -> Sub.none }
-- Model
@mindbat
mindbat / elm-day-2-track-click-position.elm
Created October 15, 2016 20:30
Elm Day 2: Track Click Position
import Html exposing (Html, text, div)
import Html.App as App
import Mouse exposing (..)
main = App.program { init = init,
view = view, update = update, subscriptions = subscriptions }
-- Model
type alias Model = { x: Int, y : Int }
@mindbat
mindbat / elm-day-2-count-mouse-clicks.elm
Created October 15, 2016 19:54
Elm Day 2: Count Mouse Clicks
import Html exposing (Html, text, div)
import Html.App as App
import Mouse exposing (..)
main = App.program { init = init,
view = view, update = update, subscriptions = subscriptions }
-- Model
type alias Model = { count: Int }
@mindbat
mindbat / elm-day-2-count-mouse-moves.elm
Created October 15, 2016 19:49
Elm Day 2: Count Mouse Moves
import Html exposing (Html, text, div)
import Html.App as App
import Mouse exposing (..)
main = App.program { init = init,
view = view, update = update, subscriptions = subscriptions }
-- Model
type alias Model = { count: Int }
@mindbat
mindbat / elm-day-2-mouse-position.elm
Created October 15, 2016 19:28
Elm Day 2: Mouse Position
import Html exposing (Html, text, div)
import Html.App as App
import Mouse exposing (..)
main = App.program { init = init,
view = view, update = update, subscriptions = subscriptions }
-- Model
type alias Model = { x: Int, y: Int }
@mindbat
mindbat / safe.hs
Last active December 21, 2015 08:18
Versions of the head, tail, etc functions that are safe to use on empty lists
safeHead :: [a] -> [a]
safeHead x = take 1 x
safeTail :: [a] -> [a]
safeTail x = drop 1 x
safeInit :: [a] -> [a]
safeInit x = take ((length x) - 1) x
safeLast :: [a] -> [a]