Skip to content

Instantly share code, notes, and snippets.

Avatar
🍻
explicit is better than implicit

Ron Toland mindbat

🍻
explicit is better than implicit
View GitHub Profile
View keybase.md

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 Jan 29, 2017
Elm Day Three: Heads
View elm-day-three-heads.elm
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 Jan 21, 2017
Seven More Languages in Seven Weeks - Elm Day Two Examples
View elm-exmaples-day-two.org

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 Oct 25, 2016
Elm Day Two: Car
View elm-day-two-car.elm
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 Oct 16, 2016
Elm Day 2: Echoing Text
View elm-day-2-echo-text.elm
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 Oct 15, 2016
Elm Day 2: Track Click Position
View elm-day-2-track-click-position.elm
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 Oct 15, 2016
Elm Day 2: Count Mouse Clicks
View elm-day-2-count-mouse-clicks.elm
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 Oct 15, 2016
Elm Day 2: Count Mouse Moves
View elm-day-2-count-mouse-moves.elm
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 Oct 15, 2016
Elm Day 2: Mouse Position
View elm-day-2-mouse-position.elm
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 Dec 21, 2015
Versions of the head, tail, etc functions that are safe to use on empty lists
View safe.hs
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]
You can’t perform that action at this time.