Skip to content

Instantly share code, notes, and snippets.

Avatar
🐛

Laurin Quast n1ru4l

🐛
View GitHub Profile
@n1ru4l
n1ru4l / diff.diff
Created Jun 10, 2021
graphql-tools TS Strict diff
View diff.diff
diff --git a/./diff/old/dist/batch-delegate/src/getLoader.d.ts b/./diff/new/dist/batch-delegate/src/getLoader.d.ts
index b00864d6..f8dd9c23 100644
--- a/./diff/old/dist/batch-delegate/src/getLoader.d.ts
+++ b/./diff/new/dist/batch-delegate/src/getLoader.d.ts
@@ -1,3 +1,3 @@
import DataLoader from 'dataloader';
import { BatchDelegateOptions } from './types';
-export declare function getLoader<K = any, V = any, C = K>(options: BatchDelegateOptions): DataLoader<K, V, C>;
+export declare function getLoader<K = any, V = any, C = K>(options: BatchDelegateOptions<any>): DataLoader<K, V, C>;
diff --git a/./diff/old/dist/batch-execute/src/getBatchingExecutor.d.ts b/./diff/new/dist/batch-execute/src/getBatchingExecutor.d.ts
@n1ru4l
n1ru4l / macro.txt
Last active May 21, 2021
dungeon-revealer dsa dice macro
View macro.txt
<Template
id="skillCheck"
var-skill={{"type":"select","label":"Skills","options":[{"label":"Fliegen","value":{"score":0,"attr1":{"name":"Mut","value":16},"attr2":{"name":"Intuition","value":11},"attr3":{"name":"Gewandheit","value":13}}},{"label":"Gaukeleien","value":{"score":10,"attr1":{"name":"Mut","value":16},"attr2":{"name":"Charisma","value":12},"attr3":{"name":"Fingerfertigkeit","value":13}}},{"label":"Klettern","value":{"score":9,"attr1":{"name":"Mut","value":16},"attr2":{"name":"Gewandheit","value":13},"attr3":{"name":"Körperkraft","value":16}}},{"label":"Körperbeherrschung","value":{"score":10,"attr1":{"name":"Gewandheit","value":13},"attr2":{"name":"Gewandheit","value":13},"attr3":{"name":"Konstitution","value":14}}},{"label":"Kraftakt","value":{"score":10,"attr1":{"name":"Konstitution","value":14},"attr2":{"name":"Körperkraft","value":16},"attr3":{"name":"Körperkraft","value":16}}},{"label":"Reiten","value":{"score":10,"attr1":{"name":"Charisma","value":12},"attr2":{"name":"Gewandheit","value":1
@n1ru4l
n1ru4l / graphql-logger.ts
Last active Mar 6, 2021
GraphQL Logger Middleware
View graphql-logger.ts
import { isAsyncIterable } from "@n1ru4l/push-pull-async-iterable-iterator";
type MaybePromise<T> = Promise<T> | T;
const map = <T, O>(map: (input: T) => Promise<O> | O) =>
async function* mapGenerator(asyncIterable: AsyncIterableIterator<T>) {
for await (const value of asyncIterable) {
yield map(value);
}
};
@n1ru4l
n1ru4l / crypto.ts
Created Feb 19, 2021
Create SHA-256 of file in browser (with http fallback)
View crypto.ts
// window.crypto.subtle is undefined on page served via http :(
const crypto: null | SubtleCrypto = window?.crypto?.subtle ?? null;
const i2hex = (i: number): string => {
return ("00" + i.toString(16)).slice(-2);
};
const generateHexFromUint8Array = (arr: Uint8Array) =>
Array.prototype.map.call(arr, i2hex).join("");
@n1ru4l
n1ru4l / ContextPyramidOfDoomPreventer.tsx
Last active Dec 7, 2020
Having a lot of React Contexts?
View ContextPyramidOfDoomPreventer.tsx
import * as React from "react";
export type ComponentWithPropsTuple<TProps = any> = [
(props: TProps) => React.ReactElement,
TProps
];
/**
* This component allows rendering Components in a flat structure.
* Some components rely on a lot of differen context providers.
@n1ru4l
n1ru4l / find-version-range-conflicts.ts
Last active Mar 11, 2021
Find conflicting package.json ranges in mono repository
View find-version-range-conflicts.ts
/**
* This is a simple script for detecting conflicting
* version ranges across packages inside a mono repository.
*/
import fs from "fs";
import glob from "glob"; // yarn add -W -E -E -D glob@7.1.6
import { promisify } from "util";
const globP = promisify(glob);
@n1ru4l
n1ru4l / makePushPullAsyncIterableIterator.ts
Created Dec 2, 2020
Without using Symbol.asyncIterator
View makePushPullAsyncIterableIterator.ts
type Deferred<T> = {
resolve: (value: T) => void;
reject: (value: unknown) => void;
promise: Promise<T>;
};
function createDeferred<T>(): Deferred<T> {
const d = {} as Deferred<T>;
d.promise = new Promise<T>((resolve, reject) => {
@n1ru4l
n1ru4l / AsyncIteratorUtilities.ts
Created Sep 21, 2020
AsyncIteratorUtilities.ts
View AsyncIteratorUtilities.ts
export const map = <T, O>(map: (input: T) => Promise<O> | O) =>
async function* mapGenerator(asyncIterable: AsyncIterableIterator<T>) {
for await (const value of asyncIterable) {
yield map(value);
}
};
export const filter = <T, U extends T>(filter: (input: T) => input is U) =>
async function* filterGenerator(asyncIterable: AsyncIterableIterator<T>) {
@n1ru4l
n1ru4l / graphql-redis-subscriptions+2.1.2.patch
Last active Sep 21, 2020
Correct graphql-subscriptions asyncIterator typings
View graphql-redis-subscriptions+2.1.2.patch
diff --git a/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.d.ts b/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.d.ts
index cc2e21e..870a2b8 100644
--- a/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.d.ts
+++ b/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.d.ts
@@ -13,7 +13,7 @@ export declare class RedisPubSub implements PubSubEngine {
publish<T>(trigger: string, payload: T): Promise<void>;
subscribe(trigger: string, onMessage: Function, options?: Object): Promise<number>;
unsubscribe(subId: number): void;
- asyncIterator<T>(triggers: string | string[], options?: Object): AsyncIterator<T>;
+ asyncIterator<T>(triggers: string | string[], options?: Object): AsyncIterableIterator<T>;
@n1ru4l
n1ru4l / use-async-clipboard-api.ts
Created May 6, 2020
Feature Detect AsyncClipboard API with TypeScript and provide it as a React hook
View use-async-clipboard-api.ts
import * as React from "react";
interface ClipboardItem {
new (input: { [contentType: string]: Blob }): ClipboardItem;
}
type AsyncClipboardWriteFunction = (input: ClipboardItem) => Promise<void>;
declare global {
interface Window {