Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
@TheSeamau5
TheSeamau5 / QuasiFullECS.elm
Last active August 3, 2017 23:09
Quasi-Full expression of Entity Component System in Elm
import Color (Color, rgb)
import Graphics.Collage (..)
import Graphics.Element (Element)
import List ((::), map)
import Signal (Signal, foldp, (<~), sampleOn)
import Keyboard (arrows)
import Time (millisecond, every)
--------------------------
@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 ()
@TheSeamau5
TheSeamau5 / NewRecordEntityComponentSystem.elm
Last active June 12, 2017 03:23
Example under the New Record Entity Component System
import List (map, (::))
import Color (Color, rgb)
import Keyboard (arrows)
import Signal (Signal, (<~), foldp)
import Graphics.Collage (square, circle, move, filled, collage, Form)
import Graphics.Element (Element)
type alias Vector = {
x : Float,
y : Float
@TheSeamau5
TheSeamau5 / CSP.md
Created January 31, 2015 02:35
Investigating CSP for Elm

Communicating Sequential Processes (CSP)

CSP is one of the many ways of reasoning about concurrent systems. It emphasizes on the idea of a channel which enables communication between producers and consumers and where the channel itself is fundamentally decouple from either producers or consumers.

Queues

The easiest way of thinking about a channel is to think about a queue. A queue is very simple, it is a data structure where one may only push data to the end of a queue and may only read data from the front of the queue.

In pseudo-code:

@TheSeamau5
TheSeamau5 / autosuggest.elm
Created May 16, 2016 07:11
Autosuggest with caching in Elm
import Dict exposing (Dict)
import Html exposing (Html, div, text, input, ul, li)
import Html.App as Html
import Html.Events exposing (..)
import Task exposing (Task)
import String
---------------------------
main =
@TheSeamau5
TheSeamau5 / makingElmDynamicSafely.md
Last active February 16, 2017 20:40
Proposal to make Elm more dynamic while maintaining type safety

Making Elm more Dynamic safely

The goal of this piece is to explore ways to give Elm some of the awesome features of dynamic languages while not sacrificing Elm's safety. The following ideas have come from exploring entity component systems/plugin architectures and noticing some of Elm's "limitations" to represent some of these ideas.

*NOTE: I am by no means an expert in type systems, compiler, programming languages, or actually programming in general. These are simply ideas I have been playing around with in recent weeks and wished to share with the Elm community. The hope is not that my ideas be adopted or pushed for or whatever. The goal is simply to improve the Elm language/platform by exploring possibilities to enhance the language in such a way as to not break any of its current guarantees or void any of its current advantages. The following is an exploration on how to make Elm's type system more "dynamic" in the sense that the inputs may be of unknown type while keeping the static nature of the lan

@TheSeamau5
TheSeamau5 / MacrosInProgrammingLanguages.md
Last active December 26, 2016 11:12
Macros in Different Programming Languages

Macros/Metaprogramming in Programming Languages

The following is a list of programming languages and their syntax for doing metaprogramming.

C

Macros in C are just glorified string substitution.

@TheSeamau5
TheSeamau5 / todomvcrewrite.elm
Created July 10, 2015 11:17
Todo MVC Rewrite with field setter syntax
module Todo where
{-| TodoMVC implemented in Elm, using plain HTML and CSS for rendering.
This application is broken up into four distinct parts:
1. Model - a full definition of the application's state
2. Update - a way to step the application state forward
3. View - a way to visualize our application state with HTML
4. Inputs - the signals necessary to manage events
This clean division of concerns is a core part of Elm. You can read more about
this in the Pong tutorial: http://elm-lang.org/blog/Pong.elm
This program is not particularly large, so definitely see the following
import Html exposing (Html, div, text, button)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import Random exposing (Seed, initialSeed, step, float, bool)
-- Start with initial probability
-- For every miss :
-- p = p * 0.9
-- Goal: In point-free style
mapReduce : (a -> b) -> (List b -> c) -> List a -> c
-- Simple
mapReduce mapper reducer list
= reducer (List.map mapper list)
-- Remove the last argument via composition
mapReduce mapper reducer
= reducer << List.map mapper