Skip to content

Instantly share code, notes, and snippets.

View sarahbethfederman's full-sized avatar

Sarah Federman sarahbethfederman

View GitHub Profile
@resource11
resource11 / autolink-headers-in-gatsby-mdx-files
Last active January 26, 2020 00:37
gatsby-config.js settings to generate autolinked headers in MDX files
import React from 'react';
import { BLOCKS } from '@contentful/rich-text-types';
import { documentToHtmlString } from './lib';
import BlogPostBlockquoteEmoji, {
contentfulId as BLOCKQUOTE_EMOJI,
} from '../BlogPostBlockquoteEmoji';
import BlogPostCaption, { contentfulId as CAPTION } from '../BlogPostCaption';
import BlogPostColumns, { contentfulId as COLUMNS } from '../BlogPostColumns';
import BlogPostImage from '../BlogPostImage';

Introduction

Many people are confused by the {{mut}} helper because it seems very magical. This gist aims to help you construct a mental model for understanding what is going on when you use it.

History

Prior to the introduction of {{mut}}, form elements were two-way bound by default. That is, given this component:

import Ember from 'ember';
export default Ember.Component.extend({
@odewahn
odewahn / error-handling-with-fetch.md
Last active February 27, 2024 09:56
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@ivanoats
ivanoats / fetch-from-contentful.js
Created June 17, 2016 18:45
fetch-from-contentful.js
#!/usr/bin/env babel-node
require('dotenv').config()
import contentful from 'contentful'
import fs from 'fs-extra-promise'
// Contentful Config
const apiToken = process.env.CONTENTFUL_DELIVERY_API_TOKEN
const spaceId = process.env.CONTENTFUL_SPACE_ID
const client = contentful.createClient({ accessToken: apiToken, space: spaceId })