Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
import Color exposing (Color)
import Graphics.Collage exposing (collage, circle, move, filled)
import Graphics.Element exposing (Element, show)
import Signal exposing (Signal)
import Time
type alias Wave =
{ center : { x : Float, y : Float }
, radius : Float
, color : Color
import Signal exposing (Address, Mailbox, Signal, forwardTo)
import Html exposing (Html, div, ul, li)
import List
update : ID -> (state -> state) -> ContainerState state -> ContainerState state
update id f list =
case list of
[] -> []
(id', x) :: xs ->
if id == id'
type alias Component state action view
= { initial : (state, action)
, view : Address action -> state -> view
, address : Address action
, history : Signal (List (state, action))
}
makeComponent
: state
@TheSeamau5
TheSeamau5 / Components.elm
Last active August 29, 2015 14:21
UI Components in Elm
import Html exposing (Html, button, text)
import Html.Attributes exposing (style)
import Html.Events exposing (..)
import Signal exposing (Signal, Mailbox, Address, mailbox, send)
import Task exposing (Task, andThen, succeed, spawn, ThreadID)
import Graphics.Element exposing (show)
@TheSeamau5
TheSeamau5 / OutlineWebAudioAPI.elm
Created May 7, 2015 17:34
Outline for Web Audio API in Elm
----------------------------
-- Basic Audio Operations --
----------------------------
getAudio : String -> Task Http.Error Audio
play : Audio -> Task error ()
stop : Audio -> Task error ()
module Lazy.List where
import Trampoline exposing (Trampoline(..), trampoline)
import Array exposing (Array)
import List
type LazyListView a
= Nil
| Cons a (LazyList a)
@TheSeamau5
TheSeamau5 / shrinking.elm
Last active August 29, 2015 14:20
Shrinking
property : String -> (a -> Bool) -> Arbitrary a -> Property
property name predicate arbitrary n seed =
let
-- failingTestCase' : Seed -> Int -> Trampoline (Result (a, Seed, Int) Int)
failingTestCase' seed accum =
if accum >= n
then
Done (Ok n)
else
let
@TheSeamau5
TheSeamau5 / killThread.js
Created April 26, 2015 02:27
Kill thread in Elm
/*
kill : ThreadID -> Task x ()
*/
function kill(id){
return asyncFunction(function(callback){
window.clearTimeout(id);
callback(succeed(Utils.Tuple0));
});
};
@TheSeamau5
TheSeamau5 / OptionalTasks.elm
Created April 22, 2015 20:28
Perform a sequence of optional tasks in Elm
optional : List (Task error value) -> Task error (List value)
optional list = case list of
[] -> succeed []
task :: tasks -> task
`andThen` (\value -> Task.map ((::) value) (optional tasks))
`onError` (\_ -> optional tasks)
@TheSeamau5
TheSeamau5 / ParallelTask.elm
Created April 22, 2015 20:21
Run tasks in Parallel in Elm
parallel : Address a -> List (Task error a) -> Task error (List ThreadID)
parallel address tasks =
let
sendToAddress task = spawn (task `andThen` send address)
in
sequence (List.map sendToAddress tasks)