Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Haskell-Glatz ryannhg

View GitHub Profile
View elm-error-json.ts
/**
* 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
@ryannhg
ryannhg / Api.elm
Created Jul 12, 2020
Used in the "Using APIs" section of in the elm-spa guide
View Api.elm
-- src/Api.elm
module Api exposing (Data(..), expectJson)
import Http
import Json.Decode as Json
type Data value
= NotAsked
| Loading
@ryannhg
ryannhg / Carousel.elm
Last active Nov 26, 2020
an example of a component built around a data structure.
View Carousel.elm
@ryannhg
ryannhg / Page.elm
Last active May 21, 2020
elm-spa – using elm-ui
View Page.elm
module Page exposing
( Page, Document, Bundle
, upgrade
, static, sandbox, element, component
)
{-|
@docs Page, Document, Bundle
@ryannhg
ryannhg / Page.elm
Created Mar 28, 2020
elm-spa – using html
View Page.elm
module Page exposing
( Page, Document, Bundle
, upgrade
, static, sandbox, element, component
)
{-|
@docs Page, Document, Bundle
@ryannhg
ryannhg / New.Application.elm
Last active Oct 11, 2019
Potential API tweak
View New.Application.elm
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 =
@ryannhg
ryannhg / questionnaire.clj
Created Mar 12, 2019
my second clojure program: a terminal-based questionnaire!
View questionnaire.clj
(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)))
@ryannhg
ryannhg / guess.clj
Created Feb 7, 2019
My first clojure program!
View guess.clj
(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))
@ryannhg
ryannhg / dottify.js
Created Mar 18, 2018
Flatten out a nested JSON object.
View dottify.js
// 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' } },
@ryannhg
ryannhg / equals.js
Created Mar 2, 2018
Check deep equality in javascript
View equals.js
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