Skip to content

Instantly share code, notes, and snippets.

View airhorns's full-sized avatar
🎯
Workin' on Gadget at https://gadget.dev

Harry Brundage airhorns

🎯
Workin' on Gadget at https://gadget.dev
View GitHub Profile
/** Wrapper class that creates an introspectable promise that can be used to suspend */
export class Suspender<T> {
debug = false;
promise: Promise<T>;
finished = false;
rejected = false;
resolution: T | null = null;
rejectReason: any = null;
id = id++;
declare let window: any;
const _global = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
const NativeWebSocket = _global.WebSocket || _global.MozWebSocket;
import Backoff from "backo2";
import { default as EventEmitterType, EventEmitter, ListenerFn } from "eventemitter3";
import { ExecutionResult } from "graphql/execution/execute";
import { DocumentNode } from "graphql/language/ast";
import { print } from "graphql/language/printer";
import { getOperationAST } from "graphql/utilities/getOperationAST";
@airhorns
airhorns / PromiseModel.ts
Last active July 5, 2020 23:55
mobx-state-tree Promise model
import { cast, flow, IAnyType, Instance, SnapshotOrInstance, types } from "mobx-state-tree";
import { assert } from "../lib/utils";
let counter = 0;
const RejectReasontype = types.maybe(types.frozen<Error>());
/**
* `mobx-state-tree` promise model factory that is observable and plays nice with the atomic middleware. Useful for embedding in the tree to fetch data on demand and reporting it's availability. It's kind of like an Apollo graphql query, but purely just state, more general, and observable.
* __Note__: This is different than normal `Promise`s because this is a factory: it produces one class of promise (a mst model) where instances of the model get configured with arguments to then execute that specific instancce
*/
@airhorns
airhorns / browserless-lighthouse.ts
Created January 8, 2020 20:41
Browserless-token authentication for lighthouse
import https from 'https';
import WebSocket from 'ws';
import log from 'lighthouse-logger';
import queryString from 'query-string';
import LighthouseError from 'lighthouse/lighthouse-core/lib/lh-error';
import ChromeProtocol from 'lighthouse/lighthouse-core/gather/connections/cri';
const CONNECT_TIMEOUT = 10000;
log.setLevel('info');
@airhorns
airhorns / gunicorn_structlog_setup.py
Created September 13, 2019 12:30
Gunicorn structlog integration
import os
import logging.config
import structlog
from .app import app
timestamper = structlog.processors.TimeStamper(fmt="iso")
pre_chain = [
# Add the log level and a timestamp to the event_dict if the log entry is not from structlog.
structlog.stdlib.add_log_level,
export const dataURIMime = (uri: string) => {
return uri.split("")[0].slice(5);
};
export const dataUriToBlob = (uri: string) => {
const data = uri.split(",")[1];
const bytes = atob(data);
const buffer = new ArrayBuffer(bytes.length);
let array = new Uint8Array(buffer);
@airhorns
airhorns / Gemfile.lock
Created February 25, 2019 17:30
Fellow shipit gemfile
GIT
remote: https://github.com/airhorns/shipit-engine.git
revision: 2ecd45860f989828041eeb317947f71d8c40c68d
ref: tail-task-fix
specs:
shipit-engine (0.27.0)
active_model_serializers (~> 0.9.3)
ansi_stream (~> 0.0.6)
attr_encrypted (~> 3.1.0)
autoprefixer-rails (~> 6.4.1)
// // Imported and modified from https://github.com/STRML/react-resizable to not clone elements and to be a bit clearer
// import * as React from "react";
// import { DraggableCore } from "react-draggable";
// type Axis = "both" | "x" | "y" | "none";
// interface State {
// resizing: boolean;
// width: number;
// height: number;
--- recycleNodesInto.js 2018-10-01 13:06:55.000000000 -0400
+++ recycleNodesInto.js-fixed 2018-10-01 13:06:46.000000000 -0400
@@ -15,7 +15,7 @@
*/
function recycleNodesInto(prevData, nextData) {
- if (prevData === nextData || typeof prevData !== 'object' || !prevData || typeof nextData !== 'object' || !nextData) {
+ if (true || prevData === nextData || typeof prevData !== 'object' || !prevData || typeof nextData !== 'object' || !nextData) {
return nextData;
}

Keybase proof

I hereby claim:

  • I am airhorns on github.
  • I am airhorns (https://keybase.io/airhorns) on keybase.
  • I have a public key ASAZpCdV24beL4Nq1fCKJv-VtUv2vxyuWdB3J6AIdjpa7go

To claim this, I am signing this object: