Skip to content

Instantly share code, notes, and snippets.

View stipsan's full-sized avatar

Cody Olsen stipsan

View GitHub Profile
@stipsan
stipsan / Viewport-test.jsx
Last active October 17, 2021 22:13
Testing with Jest: Tip #14
import renderer from 'react-test-renderer'
import Viewport from '../Viewport'
it('should render correctly', () => {
const target = {
innerHeight: 600,
innerWidth: 800,
addEventListener: jest.fn(),
removeEventListener: jest.fn()
}
@stipsan
stipsan / Field-test.jsx
Last active August 7, 2018 22:39
Testing with Jest: Tip #15
import renderer from 'react-test-renderer'
import Field from '../Field'
// this import is created by our mock, it is inteded to help with testing and
// don't exist in the real package
import { intl } from 'react-intl'
it('should render correctly', () => {
const component = renderer.create(<Field intl={intl} />)
expect(component.toJSON()).toMatchSnapshot()
@stipsan
stipsan / README.md
Last active February 5, 2018 11:05
fun test

Transform API Blueprints to TypeScript Definitions

How to use

Prerequisites: node v8, docker run is available and npx exists.

  1. In your terminal cd to the folder where your compiled.apib is.
  2. Execute docker run -i bugyik/apib2json < compiled.apib | npx https://gist.github.com/stipsan/77de06507d74442c82916477f2d59722 > api.d.ts. The first time it runs it might take a little time to download the docker image but subsequent runs should be quick.
  3. Load the generated typings 😉 perhaps using /// <reference path="../api.d.ts" />
  4. Then in your resolvers: const {body}: {body: RestEndpoints.GetUserResponse} = await got(endpoint)
  5. As you type body. vscode will autocomplete it for you with whatever that endpoint is offering.
@stipsan
stipsan / cli.js
Last active November 4, 2017 18:09
html-cli with lint-staged support
#!/usr/bin/env node
'use strict';
const path = require('path');
const getStdin = require('get-stdin');
const globby = require('globby');
const entries = require('lodash/entries');
const kebabCase = require('lodash/kebabCase');
const snakeCase = require('lodash/snakeCase');
const meow = require('meow');
@stipsan
stipsan / README.md
Last active November 5, 2017 16:44
Publish to gh pages from circleci with zero config
@stipsan
stipsan / index.jsx
Last active January 28, 2018 19:18
Easy react lifecycle hook debugging
import {Component} from 'react'
import {diff} from 'deep-object-diff'
const flattenObject = function(ob) {
const toReturn = {}
for (const i in ob) {
if (!ob.hasOwnProperty(i)) continue
if (typeof ob[i] == 'object') {
@stipsan
stipsan / README.md
Last active July 31, 2018 11:07 — forked from paulirish/server-timing-demo.js
Demo of server timing values. visualized in chrome devtools.

To test this make sure you got npx installed (if you're on the latest NodeJS LTS version it's already installed): https://www.npmjs.com/package/npx

Then run npx https://gist.github.com/stipsan/3d803d3774d82aea080c50f6f832c0bc and open http://localhost:8082 to test it!

@stipsan
stipsan / masonryWorklet.ts
Created November 22, 2019 12:32
Masonry worklet example
// Plan on making a react/web component that reuses the layout logic from the worklet to lay out and
// reoder a css columns top down layout to a ltr flow
// From https://github.com/GoogleChromeLabs/houdini-samples
registerLayout(
'masonry',
class {
static get inputProperties() {
return ['--padding', '--columns'];
@stipsan
stipsan / import-map.json
Created November 17, 2020 07:50
Minimap
{"imports":{"@podium/browser":"https://unpkg.com/browse/@podium/[email protected]/src/index.js"}}
@stipsan
stipsan / test.js
Created February 3, 2022 22:36
What error is thrown when a fetch is aborted?
// Paste in your DevTools console to inspect the error object thrown by fetch
const controller = new AbortController()
fetch(window.location.href, {signal: controller.signal}).catch((err) => {
console.dir(err)
console.assert(err.name === 'AbortError', `${err.name} === 'AbortError'`)
console.assert(err.code === 20, `${err.code} === 20`)
console.assert(
err.message === 'The user aborted a request.',
`${err.message} === 'The user aborted a request.'`
)