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
@mindbat
mindbat / pre-commit.lint
Created Jun 28, 2013
Git pre-commit script to run all the modified files through php-lint. Won't let you commit php file with a syntax error.
View pre-commit.lint
#!/bin/sh
#
# Hook script to check the changed files with php lint
# Called by "git commit" with no arguments.
#
# To enable this hook, rename this file to "pre-commit".
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
@mindbat
mindbat / rename_gutenberg.sh
Created Jul 28, 2013
Bash script to rename project gutenberg ebooks to their document titles.
View rename_gutenberg.sh
#!/bin/bash
# Bash script to pull document titles from
# Project Gutenberg ebooks.
# Invoke using command like:
# find ./ -type f -name "*.txt" | xargs -n 1 ./process.sh ~/Documents/
# pull the first line of the file
FIRST_LINE=`head -n 1 $2`
@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 / 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:

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-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 }