Skip to content

Instantly share code, notes, and snippets.

View fredcy's full-sized avatar

Fred Yankowski fredcy

View GitHub Profile
Verifying my Blockstack ID is secured with the address 12YXsYfyefSi8PPRSZShNW1NwY3c1LNo8W https://explorer.blockstack.org/address/12YXsYfyefSi8PPRSZShNW1NwY3c1LNo8W
module Michelson exposing (..)
import Json.Decode as Decode
import Json.Decode.Pipeline as Decode
type alias Script =
{ code : Code
, storage : Storage
}
@fredcy
fredcy / FailingElmTest.elm
Last active November 4, 2016 14:08
Example of failing Elm test with no detail
port module Main exposing (..)
import Json.Encode
import Test exposing (Test, describe, test)
import Test.Runner.Node
import Expect
main =
Test.Runner.Node.run emit <|
@fredcy
fredcy / http-send-example.elm
Created November 2, 2016 21:34
Http.send example in Elm 0.17
module Main exposing (main)
import Html
import Html.App
import Http
import Json.Decode as Json exposing ((:=))
import Task exposing (Task)
type alias Model =
@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)]
@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 / 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 / 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 / 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 / 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)