Skip to content

Instantly share code, notes, and snippets.

View zbennett10's full-sized avatar

Zachary Bennett zbennett10

View GitHub Profile
@m-renaud
m-renaud / custom-decoder.elm
Created November 15, 2016 18:11
Custom decoder in elm 0.18
customDecoder decoder toResult =
Json.andThen
(\a ->
case toResult a of
Ok b -> Json.succeed b
Err err -> Json.fail err
)
decoder
@mathiasbynens
mathiasbynens / escape.js
Created June 26, 2019 07:29
Escaping JSON-stringified data for use as a JavaScript string literal
// This object contains a string value that in contains a single quote,
// a double quote, a backtick, and a backslash.
const data = { foo: `a'b"c\`d\\e` };
// Turn the data into its JSON-stringified form.
const json = JSON.stringify(data);
// Now, we want to insert the data into a script body as a JavaScript
// string literal per https://v8.dev/blog/cost-of-javascript-2019#json,
// escaping special characters like `"` in the data.