Skip to content

Instantly share code, notes, and snippets.

View ryan-haskell's full-sized avatar

Ryan Haskell ryan-haskell

View GitHub Profile
@ryan-haskell
ryan-haskell / elm-error-json.ts
Created November 17, 2021 04:24
Elm Error Json
/**
* These types were taken from the JSON encoders for the Elm 0.19.1 compiler on 2021/11/16
*
* Here are those resources:
* - https://github.com/elm/compiler/blob/770071accf791e8171440709effe71e78a9ab37c/builder/src/Reporting/Exit/Help.hs
* - https://github.com/elm/compiler/blob/770071accf791e8171440709effe71e78a9ab37c/compiler/src/Reporting/Doc.hs
* - https://github.com/elm/compiler/blob/770071accf791e8171440709effe71e78a9ab37c/compiler/src/Reporting/Error.hs
*/
declare const process: any
@ryan-haskell
ryan-haskell / Api.elm
Created July 12, 2020 05:23
Used in the "Using APIs" section of in the elm-spa guide
-- src/Api.elm
module Api exposing (Data(..), expectJson)
import Http
import Json.Decode as Json
type Data value
= NotAsked
| Loading
@ryan-haskell
ryan-haskell / Carousel.elm
Last active November 26, 2020 23:56
an example of a component built around a data structure.
@ryan-haskell
ryan-haskell / Page.elm
Last active May 21, 2020 16:28
elm-spa – using elm-ui
module Page exposing
( Page, Document, Bundle
, upgrade
, static, sandbox, element, component
)
{-|
@docs Page, Document, Bundle
@ryan-haskell
ryan-haskell / Page.elm
Created March 28, 2020 21:31
elm-spa – using html
module Page exposing
( Page, Document, Bundle
, upgrade
, static, sandbox, element, component
)
{-|
@docs Page, Document, Bundle
@ryan-haskell
ryan-haskell / New.Application.elm
Last active October 11, 2019 16:24
Potential API tweak
module Application exposing (..., init, update, bundle, Initializer, Updater, Bundler)
type Initializer =
Initializer (Context -> ( Model, Cmd Msg, Cmd App.Msg))
type Updater =
Updater (Context -> ( Model, Cmd Msg, Cmd App.Msg))
type Bundler =
@ryan-haskell
ryan-haskell / questionnaire.clj
Created March 12, 2019 21:23
my second clojure program: a terminal-based questionnaire!
(ns questionnaire)
(def questions
{ "What's your name?" :name
"What's your favorite color?" :color
})
(defn bold [text] (str "\033[1m" text "\033[0m"))
(defn prompt [question] (do (print (str (bold question) " ")) (flush) (read-line)))
@ryan-haskell
ryan-haskell / guess.clj
Created February 7, 2019 23:01
My first clojure program!
(ns user)
(defn askForNumber
"Asks for a number within a range, returning nil if input is not a number."
[ low high ]
(do
(print (str "Pick a number from " low " to " high ": "))
(flush)
(let [ num (read-string (read-line))]
(if (number? num) num nil))
@ryan-haskell
ryan-haskell / dottify.js
Created March 18, 2018 19:42
Flatten out a nested JSON object.
// Examples
// To make this functions goal more clear, here are some example inputs with their expected outputs.
/*
const examples = [
{
input: { name: 'Ryan' },
output: { name: 'Ryan' }
},
{
input: { name: { first: 'Ryan', last: 'Haskell-Glatz' } },
@ryan-haskell
ryan-haskell / equals.js
Created March 2, 2018 18:37
Check deep equality in javascript
const equals = (obj1, obj2) => {
const sortKeys = (obj) =>
(obj && typeof obj === 'object')
? Object.keys(obj)
.sort((a, b) => a < b)
.reduce((newObj, key) => {
newObj[key] = sortKeys(obj[key])
return newObj
}, {})
: obj