Skip to content

Instantly share code, notes, and snippets.


James A Rosen jamesarosen

View GitHub Profile
jamesarosen /
Created May 13, 2021
I'm trying to fetch and parse some JSON in Terraform using jq and I just can't figure it out.
# Braintree publish a list of their CIDR blocks and IP addresses at
# The body looks like
# {
# "production": {
# "cidrs": [
# ""
# ]
# "ips": [
# ""
jamesarosen / cloudflare-cache.js
Created Feb 20, 2020
Caching with Cloudflare
View cloudflare-cache.js
function isCacheable(response) {
const vary = response.headers.get('Vary')
return (
response.status >= 200 &&
response.status < 400 &&
response.status !== 206 &&
response.headers.get('Cache-Control') != null &&
vary !== '_' &&
vary !== '*'
jamesarosen / react-state-machines.jsx
Created Dec 12, 2019
Using state machines in hook-based React components
View react-state-machines.jsx
const STATUSES = {
initial: {},
fetching: { showLoadingIndicator: true },
fetched: { showResults: true },
error: { showError: true },
function Foo() {
const [status, setStatus] = useState(STATUSES.initial)
const [results, setResults] = useState(null)
jamesarosen /
Last active Feb 13, 2021
Helper Functions in the Redux Store

I have a function that generates image URLs. This function combines some relatively static global configuration with some dynamic data that changes on every invocation. I say "relatively static" because the configuration is loaded asynchronously during the application boot, but remains fixed after that.

Option One

export default async function imageUrl(imageId, { size = 'normal' }) {
  if (imageId == null) return null
  const constantsResponse = await fetch('/api/constants')
 const imagesRoot = constantsResponse.json().imagesRoot
jamesarosen /
Created Oct 11, 2019
Does resolve .org domains properly?

A friend asked me whether Cloudflare's service was having trouble resolving .org domains. Here are some findings.

From SF:

;; ANSWER SECTION:		3432	IN	A		3432	IN	A		3432	IN	A
jamesarosen /
Last active Aug 27, 2018
Quality Engineering
jamesarosen /
Created Aug 25, 2018

The following code will let an ember addon provide an addon-test-support/ folder whose contents get merged into app/mirage/. It excludes addon-test-support/ from the build if mirage is disabled.

See Better Addon Support on the Ember CLI Mirage feature-request board.

jamesarosen /
Last active May 31, 2018
Ember 2018 Roadmap


I have been working with Ember since the SproutCore days. I have watched a passionate, dedicated team spend the last 7 years continually improving the framweork and its ecosystem. Along the way, many things have changed (almost always for the better), but some things have remained constant.

Many of the things I say below have been said by others before. I particularly recommend reading Matt McManus's Improve the interoperability of the community and the framework and Chris Garrett's Ember as a Component-Service Framework.

View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
clearLog() {
foo: undefined,
View components.fui-truncate.js
import Ember from 'ember'
import hbs from 'htmlbars-inline-precompile'
export default Ember.Component.extend({
suffixLength: 4,
text: null,
prefix: Ember.computed('suffixLength', 'text', function() {
const suffixLength = this.get('suffixLength')
const text = this.get('text') || ''