Skip to content

Instantly share code, notes, and snippets.

View KATT's full-sized avatar
🌴
On vacation

Alex / KATT KATT

🌴
On vacation
View GitHub Profile
type AnyFunction = (...args: any) => any
type FunctionWithOneArg<T extends AnyFunction> = (args: Record<string, any>) => ReturnType<T>
type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
type Arguments<T> = [T] extends [(...args: infer U) => any]
? U
: [T] extends [void] ? [] : [T]
type PartialArg<T> = Partial<Arguments<T>[0]>
import { transformWhereInput } from './transformWhereInput'
test('basic', () => {
expect(
transformWhereInput({
status: 'ACTIVE',
}),
).toEqual({
status: {
$eq: 'ACTIVE',
function deferred<T>() {
let resolve: (value: PromiseLike<T> | T) => void;
let reject: (reason: Error) => void;
let promise = new Promise<T>((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});
return { promise, resolve, reject };
}
/* eslint-disable no-underscore-dangle */
module.exports = ({
processEventEmitter,
logger,
skipRecurringOperationRefetch,
}) =>
class RecurringOperation {
constructor({ operation, expiry = null }) {
if (typeof operation !== 'function') {
@KATT
KATT / retry.ts
Created July 17, 2017 14:05
retry async operation up to N times
/**
* retry async operaration up to N times
*
* usage:
* ```ts
* async fn() {
* const response = await retry(() => fetch('/endpoint/that/might/fail'), 3)
* }
* fn() // will retry fetch up to 3 times
* ```
import { ApolloClient, createNetworkInterface } from 'react-apollo';
let apolloClient = null;
function createClient(headers, userToken) {
const networkInterface = createNetworkInterface({
uri: 'https://api.graph.cool/simple/v1/Groopy',
opts: {
credentials: 'same-origin',
// Pass headers here if your graphql server requires them
@KATT
KATT / KATTCORP
Last active November 9, 2016 13:16
/ )
/ )__/ )_____/ /
( @ . @ ) )
( )
//¨//¨¨//¨//
import React, { PropTypes } from 'react';
function NL2BR({content}) {
const strs = content.split('\n');
const {length} = strs;
if (length === 1) {
return <span>{content}</span>;
}
const obj = {
a: 1,
b: 2,
c: 3,
d: 4,
};
const {
a,
b,
function getFrontMatter(file) {
return new Promise((resolve, reject) => {
readFile(join(__dirname, '../pages', file), (error, content) => {
if (error) return reject(error);
let doc = fm(content.toString())
resolve(doc);
});
})
}