Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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:
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 / 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 / Dockerfile
Created April 1, 2019 02:27
Tiny debug image
FROM golang:alpine as build
WORKDIR /usr/src/app
RUN apk --no-cache add upx
COPY ./server.go ./
ENV CGO_ENABLED=0
RUN go build -o server server.go
RUN upx --brute server
# ---
@rzane
rzane / github-to-pivotal.rb
Created May 22, 2019 15:57
Migrate GitHub issues to Pivotal Tracker
require 'github_api'
require 'tracker_api'
GITHUB_USER = 'username or organization'
GITHUB_REPO = 'repo'
GITHUB_LOGIN = 'username'
GITHUB_PASSWORD = '***'
PIVOTAL_TOKEN = '***'
PIVOTAL_PROJECT_ID = 'last segment of the pivotal URL'
@rzane
rzane / fileExchange.ts
Created August 1, 2019 23:42
URQL file exchange (which doesn't work at all)
import { print } from "graphql";
import { pipe, map } from "wonka";
import { Exchange, Operation } from "urql";
type FetchExchangeFn = (
operation: Operation,
options: RequestInit
) => RequestInit;
const createFetchExchange = (fn: FetchExchangeFn): Exchange => {
@rzane
rzane / README.md
Last active July 18, 2020 13:14
QueryExtensions

QueryExtensions

First, you'll need to incorporate the extension:

class ApplicationRecord < ActiveRecord::Base
  extend QueryExtensions
end