Skip to content

Instantly share code, notes, and snippets.

View fredcy's full-sized avatar

Fred Yankowski fredcy

View GitHub Profile
import Graphics.Element exposing (..)
main2 =
let
me = you
you = "Jane"
in
show (me, you)
main3 =
@fredcy
fredcy / elm-records.elm
Last active January 25, 2016 19:34
Elm record usage example
import Graphics.Element exposing (show)
type Foo = A { x : Int, y : String }
| B { x : Int, m : Float }
f : Foo -> Foo
f foo =
let
incr v = { v | x = v.x + 1 }
in
@fredcy
fredcy / keybase.md
Created February 2, 2016 02:23
keybase proof

Keybase proof

I hereby claim:

  • I am fredcy on github.
  • I am fredcy (https://keybase.io/fredcy) on keybase.
  • I have a public key ASDaqzdEQzsRRt-VbmDXscGVjQ8suYzQuPbdzfou3dPsYQo

To claim this, I am signing this object:

@fredcy
fredcy / elm-http-string-response.elm
Created March 8, 2016 16:15
Example of elm-http-extra getting HTTP response as a String
module Main (..) where
import Html
import Html.Events
import Http.Extra
import Task
import Effects
import StartApp
@fredcy
fredcy / dotProductExamples.elm
Created March 25, 2016 15:46
Try different ways of implementing dot-product in Elm
module Main where
import Graphics.Element exposing (Element, show)
main : Element
main =
show <| dot (Vec2 3 5) (Vec2 5 6)
@fredcy
fredcy / Main.elm
Last active March 30, 2016 20:32
Elm program that gets user info from Github
module Main (..) where
import Effects exposing (Effects, Never)
import Html exposing (..)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import Http
import Json.Decode as Decode exposing ((:=))
import Json.Decode.Extra exposing ((|:))
import Task
@fredcy
fredcy / maybeMap.elm
Created April 7, 2016 14:28
Apply (a -> Maybe b) function to list returning Nothing if any application results in Nothing, else Just (List b)
import Html exposing (text)
data1 = [ 1, 2, 3, 11 ]
fn1 x = if x < 12 then Just (x + 100) else Nothing
maybeMap : (a -> Maybe b) -> List a -> (Maybe (List b))
maybeMap fn list =
case list of
[] -> Just []
@fredcy
fredcy / convert_snake_case.elm
Last active June 9, 2016 10:59
Convert snake case to camel case in Elm
convert : String -> String
convert snakeStr =
let
repl : Regex.Match -> String
repl match =
case List.head match.submatches of
Just submatch ->
submatch |> Maybe.withDefault "" |> String.toUpper
Nothing ->
Debug.log "error: no submatch" "ERROR"
@fredcy
fredcy / cartesian.elm
Last active November 2, 2019 18:03
Cartesian product of two lists in Elm
import Html exposing (text)
main =
text <| toString <| cartesian ["a", "b", "c"] [1..5]
cartesian : List a -> List b -> List (a,b)
cartesian xs ys =
List.concatMap
( \x -> List.map ( \y -> (x, y) ) ys )
xs
@fredcy
fredcy / groupOverlaps.elm
Created April 27, 2016 19:33
Group overlapping intervals, in Elm
import Html exposing (text)
main =
text <| toString <| group data
type alias Interval = (Int, Int)
data =
[ (1, 2), (3, 5), (4, 10), (5, 8), (5, 12), (13, 15), (14, 20)]