Skip to content

Instantly share code, notes, and snippets.

@rzane
rzane / maybe.ts
Created March 8, 2019 16:59
The simplest possible `maybe` implementation in TypeScript
type None = null | undefined;
export class Maybe<T> {
private _value: T | undefined;
public constructor(value: T | None) {
this._value = value === null ? undefined : value;
}
public value(): T | undefined {
@rzane
rzane / tsconfig.json
Created February 26, 2019 16:27
Typescript config for a client side app
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
Run options:
include {:focus=>true}
exclude {:compat=>true}
All examples were filtered out; ignoring {:focus=>true}
Running with ActiveRecord 5.2.1
..........................................................................................................................................................................F..............F......F..F...F....FFF.................F............F....F........F.......FF...FF............
Failures:
@rzane
rzane / openapi.yaml
Created January 10, 2019 15:55
Reproduce OpenAPI additionalProperties issue
openapi: 3.0.0
info:
title: MyAPI
description: MY API
version: 0.0.0
servers:
- url: http://localhost:8080/api/
paths:
/example:
get:
@rzane
rzane / openapi.yaml
Created January 10, 2019 15:45
Reproduce OpenAPI anyFromJSON issue
openapi: 3.0.0
info:
title: MyAPI
description: MY API
version: 0.0.0
servers:
- url: http://localhost:8080/api/
paths:
/example:
get:
@rzane
rzane / Backoff.js
Last active May 9, 2018 18:11
Exponential backoff
const create = ({
shouldBackoff,
factor = 5,
maxDelay = 32000,
maxAttempts = 20
}) => {
const backoff = attempt => {
const randomMs = Math.floor(Math.random() * 1000);
const exponential = Math.pow(factor, attempt) + randomMs;
const delay = Math.min(exponential, maxDelay);
@rzane
rzane / index.html
Created March 2, 2018 18:56
Apollo Boost Headers Reproduction
<html>
<head>
<title>Apollo Query Reproduction</title>
<meta charset="UTF-8" />
</head>
<body>
<div id="app">
<h1>These are the headers that get sent along:</h1>
</div>
@rzane
rzane / declare-props.js
Created November 15, 2017 21:13
An interactive script to declare react props
const fs = require('fs');
const path = require('path');
const { CLIEngine } = require('eslint');
const readline = require('readline-sync');
const cli = new CLIEngine({
parser: 'babel-eslint',
useEslintrc: false,
plugins: ['react'],
rules: { 'react/prop-types': ['error', {}] }
@rzane
rzane / Field.js
Created November 14, 2017 15:12
<Field /> component that supports nested values for formik
import React from 'react';
import PropTypes from 'prop-types';
import { set, get } from 'lodash/fp';
/**
* This is a copy-pasta job of Formik's Field component. It's needed in
* order to handle nested values. Future versions of formik will support
* this.
*/
@rzane
rzane / fix_callbacks.rb
Created May 18, 2017 20:03
Fix deprecated ActiveModel::Dirty methods for Active Record 5.1
class After < Struct.new(:text)
def call
text.gsub(Model::FIXES[0], 'saved_change_to_\1?')
.gsub(Model::FIXES[1], '\1_before_last_save')
end
end
class Before < Struct.new(:text)
def call
text.gsub(Model::FIXES[0], 'will_save_change_to_\1?')