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 / 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 / csslayout.elm
Created January 31, 2015 17:48
Wrapping CSS Layout in Elm
type alias Bounds = {
left : Float,
right : Float,
top : Float,
bottom : Float
}
bounds : Bounds
bounds = Bounds 0 0 0 0
@TheSeamau5
TheSeamau5 / svgdragdrop.elm
Last active January 29, 2020 05:26
Drag and drop example with svg in Elm
import Svg (Svg, circle, svg, g, line, text)
import Svg.Attributes (cx, cy, r, fill, stroke, strokeWidth, x, y, x1, x2, y1, y2, fontSize, style)
import Html
import Html.Attributes as Html
import Signal (Signal, map, foldp)
import DragAndDrop (mouseEvents, MouseEvent(..))
import List
--------------
@TheSeamau5
TheSeamau5 / hoveringGridExample.elm
Created March 6, 2015 01:49
Example of hovering over a grid
import Graphics.Collage (..)
import Graphics.Element (..)
import Graphics.Input (..)
import Color (..)
import Signal (..)
import Text
import List
import Mouse
@TheSeamau5
TheSeamau5 / example.elm
Last active August 29, 2015 14:16
API for testing stateful code in Elm
{-
This is an example of how to test state in Elm.
The idea is that one can model your application as a state machine
with an update function of the type:
update : action -> state -> state
This is very useful in order to test applications
built using the Elm architecture, which looks like this:
@TheSeamau5
TheSeamau5 / RedditHomePage.elm
Last active March 10, 2016 15:14
Getting the Reddit Home Page using Elm Promises
--------------------------
-- CORE LIBRARY IMPORTS --
--------------------------
import Task exposing (Task, succeed, andThen, onError)
import Json.Decode exposing (Decoder, object2, (:=), string, int, list, map)
import Signal exposing (Signal, Mailbox, mailbox, send)
import List
---------------------------------
-- THIRD PARTY LIBRARY IMPORTS --

Record Example

The following is an example of how to:

  • create a nested record type
  • encode this as JSON
  • decode a JSON string to an entity
  • create a random Entity generator
  • test the JSON parsing of the Entity
@TheSeamau5
TheSeamau5 / ReactNativeExample.jsx
Created March 26, 2015 21:56
React Native Example Reddit Client
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require("react-native");
var {
AppRegistry,
@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 / shrinkInt.elm
Created April 10, 2015 23:58
Shrink Strategy for Ints
shrinkInt : Int -> List Int
shrinkInt n =
if n < 0
then
-n :: List.map ((*) -1) (series 0 -n)
else
series 0 n
series : Int -> Int -> List Int