Skip to content

Instantly share code, notes, and snippets.

View jzfgo's full-sized avatar
🤓

Javier Zapata jzfgo

🤓
View GitHub Profile
import { User } from 'payload/dist/auth';
import { Access, AccessArgs, FieldAccess } from 'payload/types';
type CheckerArgs = {
user?: User;
id?: string | number;
};
type Checker = (args: CheckerArgs) => boolean;
const isAdmin: Checker = ({ user }) => user?.role && user?.role === 'admin';
@rmtuckerphx
rmtuckerphx / direnv-win.md
Last active January 12, 2024 18:32
Steps to install direnv on Windows

direnv on Windows

Overview

In JavaScript projects, I used to use dotenv so that I could put local environment variables in a .env file for local development. But dotenv requires you to add code to your project. With direnv, you can put local env vars in a .envrc file and those env vars are loaded automatically in the shell.

Steps to install

For these steps, it is assummed that you have installed Git Bash on Windows. I also use VSCode as my editor.

  1. Create a folder such as c:\tools to put the direnv.exe file and add it to the Windows PATH
@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,
@zarv1k
zarv1k / abstract-unique-validator.ts
Last active April 12, 2024 07:14
Unique Validator Example for NestJS
import { ValidationArguments, ValidatorConstraintInterface } from 'class-validator';
import { Connection, EntitySchema, FindConditions, ObjectType } from 'typeorm';
interface UniqueValidationArguments<E> extends ValidationArguments {
constraints: [
ObjectType<E> | EntitySchema<E> | string,
((validationArguments: ValidationArguments) => FindConditions<E>) | keyof E,
];
}
@loganvolkers
loganvolkers / Byte Formatting for Google Sheets.md
Last active April 16, 2024 10:42
Byte formatting for Google Sheets
@swyxio
swyxio / Gatsby-bootstrap-lifecycle.md
Last active April 1, 2022 11:19
Gatsby bootstrap lifecycle

Sequence of Gatsby's bootstrap lifecycle with links to source code as of v2.0.0

  1. open and validate gatsby-config (get-config-file.js) 1.5 load themes (swyx added this note July 2019)
  2. load plugins (load-plugins/index.js) from the list given in gatsby-config.js
  3. onPreBootstrap: runs onPreBootstrap if it is implemented in any plugins, for example gatsby-plugin-typography. Receives handy [apiCallArgs](https://github.com/gatsbyjs/gatsby/blob/ffd8b2d691c9

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

@wassname
wassname / .eslintrc.js
Last active September 14, 2023 23:57
eslint.recommended (annotated)
/**
* eslint.recommended (annotated)
* ================
* Annotated defaults based on eslint.recommended
*
* @author: wassname
* @license: MIT
* @website https://gist.github.com/wassname/4693303388396c5f074b10865a969b43
* @date 2017-11-13T23:08
* @eslint-version: 4.11.0
#/usr/bin/env bash
# Install some pacakages we'll need to compile the driver below.
sudo dnf install gcc kernel-devel -y
# Create working dir for Broadcom driver files and patches.
mkdir hybrid_wl_f23
# Change to working dir.
cd hybrid_wl_f23
@paulirish
paulirish / bling.js
Last active May 1, 2024 19:56
bling dot js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;