Skip to content

Instantly share code, notes, and snippets.

View jean-leonco's full-sized avatar

Jean Leonço jean-leonco

View GitHub Profile
// History
import { createBrowserHistory } from 'history';
const history = createBrowserHistory();
export default history;
// App
import React from 'react';
import { Router } from 'react-router-dom';
@jean-leonco
jean-leonco / GraphQLCache.md
Last active January 14, 2021 12:35
[WIP] GraphQL cache using Redis

When resolver returns node

The key will be the relay globalID and store all db item data. When the node is recovered, the viewerCanSee will filter this.

  • postGlobalID
  • postGlobalID
  • commentGlobalID

Format

@jean-leonco
jean-leonco / environment.js
Created March 21, 2021 18:48
Simple Relay environment with auth header
// Reference: https://relay.dev/docs/guides/network-layer
import { Environment, Network, RecordSource, Store } from 'relay-runtime';
// Function to get the authentication token
export const getToken = () => {
return localStorage.getItem('authentication_token');
};
// Define a function that fetches the results of an operation (query/mutation/etc)
@jean-leonco
jean-leonco / .flake8
Created October 10, 2022 01:14
Basic python setup
[flake8]
max-line-length = 88
extend-exclude = .venv
extend-ignore =
E203, # whitespace before ':' (conflicts with Black)
E231, # Bad trailing comma (conflicts with Black)
E501, # line too long (conflicts with Black)
W503, # line break before binary operator (conflicts with Black)
@jean-leonco
jean-leonco / user.ts
Created May 15, 2023 16:28
Mongo DataSource + Zod + DataLoader
import { AsyncLocalStorage } from 'async_hooks'
import DataLoader from 'dataloader'
import { ObjectId } from 'mongodb'
import { z } from 'zod'
import {
Connection,
ConnectionArgs,
connectionArgsSchema,
@jean-leonco
jean-leonco / _index.tsx
Last active May 11, 2024 20:32
Remix Simple Authentication
import { redirect, type LoaderFunctionArgs } from '@remix-run/node'
import { Form, useLoaderData } from '@remix-run/react'
import { sessionCookie } from '../session.server'
export async function loader({ request }: LoaderFunctionArgs) {
const cookieHeader = request.headers.get('Cookie')
const cookie = await sessionCookie.parse(cookieHeader)
if (!cookie) {
return redirect('/login')
}