Skip to content

Instantly share code, notes, and snippets.

View bengry's full-sized avatar

Ben Grynhaus bengry

  • wiz-sec
  • Israel
  • 01:27 (UTC +02:00)
View GitHub Profile
@bengry
bengry / StringWithAutocomplete.ts
Created August 31, 2024 20:35
Utility function for class organization when using libraries like Tailwind, which get very verbose very fast
/**
* A utility type around `string` that allows for autocomplete on the string on a specific set of values, yet accepting any string.
*
* @see https://twitter.com/diegohaz/status/1524257274012876801
*/
export type StringWithAutocomplete<S extends string> =
| S
| (string & Record<never, never>);
@bengry
bengry / fakerMiddleware\_internal\buildGqlResolvedFieldPath.ts
Last active August 6, 2024 08:27
faker.js & `graphql-mocks` based consistant graphql mocking
import { GraphQLResolveInfo } from 'graphql';
export function buildGqlResolvedFieldPath(
path: GraphQLResolveInfo['path']
): string {
const fieldPath = path.key;
if (path.prev) {
return `${buildGqlResolvedFieldPath(path.prev)}.${fieldPath}`;
}
@bengry
bengry / reviewable-io-line-numbers.js
Created March 22, 2023 12:26
Reviewable.io - add line numbers
// ==UserScript==
// @name Reviewable.io - add line numbers
// @namespace https://bengr.dev/
// @version 0.1
// @description Add line numbers to reviewable.io
// @author Ben Grynhaus ([email protected])
// @match https://reviewable.io/reviews/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=reviewable.io
// @grant none
// ==/UserScript==
// ==UserScript==
// @name Wolt Cibus Autoselect
// @namespace https://bengr.dev/
// @version 0.1
// @description Automatically choose Cibus payment method in Wolt and turns off the "Use Wolt Credits" Toggle
// @author bengry
// @match https://wolt.com/*/checkout
// @license MIT
// @grant none
// ==/UserScript==
@bengry
bengry / mjml.d.ts
Created January 4, 2022 12:32
TypeScript types for MJML v4.6.x. Might be partial - I typed mostly the only things I used
type TODO = unknown;
/**
* @see https://github.com/mjmlio/mjml/blob/master/packages/mjml-core/src/types/index.js
*/
type ValidTypes = "boolean" | "enum" | "color" | "unit" | "string" | "integer";
type PrimitiveType<T> = T extends boolean
? "boolean"
: T extends string
@bengry
bengry / INetlifyEvent.d.ts
Created October 5, 2021 20:49
Netlify Plugin TypeScript types
import { INetlifyPluginOptions } from "./INetlifyPluginOptions";
export type INetlifyEvent = (options: INetlifyPluginOptions) => void;
import { setupMockDate, MockDateSetup } from 'test-utils';
let mockDate: MockDateSetup;
beforeEach(() => {
mockDate = setupMockDate();
});
afterEach(() => {
mockDate.reset();
import timezonedDate from "timezoned-date";
export interface MockDateSetup {
reset(): void;
set(options: { offset?: number | keyof typeof offsetsByName; isoDate?: string }): void;
}
const originalDate = Date;
export function setupMockDate(): MockDateSetup {
@bengry
bengry / app.module.ts
Created December 26, 2019 07:32
Nest.js request context workaround
import { MiddlewareConsumer, Module, NestModule } from "@nestjs/common";
import { APP_INTERCEPTOR } from "@nestjs/core";
import { RequestContextMiddleware } from "./request-context/request-context.middleware";
import { RequestContextModule } from "./request-context/request-context.module";
@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, "config", "**/!(*.d).{ts,js}")),
WebappUsersModule,
RequestContextModule,
diff --git a/node_modules/workerize-loader/dist/index.js b/node_modules/workerize-loader/dist/index.js
index f318035..7b16cc1 100644
--- a/node_modules/workerize-loader/dist/index.js
+++ b/node_modules/workerize-loader/dist/index.js
@@ -80,7 +80,7 @@ loader.pitch = function (request) {
var entry = compilation.entries[0].resource; // only process entry exports
if (current.resource !== entry) { return; }
- var exports = compilation.__workerizeExports || (compilation.__workerizeExports = {});
+ var exports = CACHE[entry] || (CACHE[entry] = {});