This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/49725198/23972 | |
// https://www.typescriptlang.org/play?#code/C4TwDgpgBAShCOBXAlgJwgQWAGQgQwGdgB5AOwgB4AVAGigGkIQCoIAPYCUgExYGsmAewBmUKlAC8UASBFiAfJICwAKCjqoABWQBjPtToBRNjoA2ibpRlzaDJgXnzVGqADIoAb2cuNAbXpQyKR2zAC6ALQA-ABcsAgo6NwU2noGDI5uWniowMh4psm6+rbGZhaUjMx09I5OahoAvv72oaqqQZyowng60ACyXIgAkpwAtp7eucCmELFEqEEA5gDc3jqCo2CC5KTAMVCkiKMARhCoq-VmRfuHJ2cX6rrbc8ALpCuqDW0qoJBQAMKmIrEVD-DZbHbASRxJBoTA4fBEMiUAaHEYQUZ0ADkVz0WKgAB8oDjwdsuMAsXVVOtSEQoAB3ZDAAAWYM2ZN2sUBwNBpMh0K89XUUxmsQARJwiGKaN51Ot2ZDYgBWABMMqFgRp4qepDFn2+NLpjJZ3L0XKBehBbIh5IFsqgItmUAlECl6pcuL4yoALO6NDrtTS9Sovipqds6WdUIJUAB1JnMgByEATZ3NPOtHKhUkFLkd4slwGl9oDzp1wdD4dpUNIgkMqGjcYTACFBCz05beQrbTn7fnnYXixrPT6-XK+eTYirfSWtWWg-qwypDVCozH4yzWyzY8yuMiABKEWPR95UcBO018K0T3Z2jX9l1u+0jqBKmfDm-AcUEZmCRCmbgoFOA4jlOVAoF3dAhxcUsxXLRdvl+aA4FhdAyFMEBkTSSoWHYTgeH4IRRHEKRrGIxQJHtFJiiMExzEsCgyLEap7Ece13A8KB-ECYIcIiGJ7RcFCEggJJqOwtiNRcdxNGyXJ8goOB1lQJJSnoip7GqeQ6EQHgIGEIJRMklwmj4xDzygdDMPIS9r27W8pGEuErKw1FhjGbFPXxIkSXsikqWXCMazrBt1wTFzyFiCKIFsrsbQ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/49725198/23972 | |
export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick< | |
T, | |
Exclude<keyof T, Keys> | |
> & | |
{ | |
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>; | |
}[Keys]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://css-tricks.com/click-outside-detector/ | |
// https://codepen.io/chriscoyier/project/editor/AxPzxn | |
import React, { useEffect, useRef, forwardRef } from 'https://cdn.skypack.dev/react'; | |
const ClickOutsideDetector = forwardRef(function ClickOutsideDetector( | |
{ listen, onClickOutside, ignore, ...props }, | |
ref | |
) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/51865579/23972 | |
function fakeBaseClass<T>(): new () => Pick<T, keyof T> { | |
return class {} as any; | |
} | |
// USAGE: | |
class FooProxy extends fakeBaseClass<Foo>(){ | |
private foo: Foo; // I would make this private as it is not really accessible on what the constructor of FooProxy returns (maybe remove it as I see no use for it) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resolveConfig from "tailwindcss/resolveConfig"; | |
// Update next import to the location of your tailwind config. If you're using CRA | |
// and your `tailwind.config.js` is outside of `src`, you might have to do | |
// Shenanigans™ to import it. (You can use craco and https://stackoverflow.com/a/60353355/23972) | |
import tailwindConfig from "../../tailwind.config"; | |
const THEME = resolveConfig(tailwindConfig).theme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Given list of stings, access nested properties in object. | |
* | |
* @param {Object<string, *>} object | |
* @param {Array<string>} accessors | |
* @returns {*} | |
*/ | |
function nestedGet(object, accessors) { | |
return accessors.reduce((acc, prop) => { | |
return acc?.[prop]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* Lazily-evaluated getters. | |
* | |
* ```js | |
* class Person { | |
* get name() { | |
* lazyProperty(this, 'name', calculateSomeValueForName()) | |
* return this.name | |
* } | |
* } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.serializers import ModelSerializer, SerializerMethodField | |
from .models import Book, Publisher, Author | |
class PublisherModelSerializer(ModelSerializer): | |
""" | |
A ModelSerializer that takes an additional `fields` argument that | |
controls which fields should be displayed. | |
""" | |
def __init__(self, *args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def upper_and_lower(txt): | |
capitalize = 0 | |
final_txt = [] | |
for letter in txt: | |
if capitalize and letter.isalpha(): | |
letter = letter.upper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from typing import Awaitable, Final, List, TYPE_CHECKING, TypedDict | |
from channels.auth import AuthMiddlewareStack | |
from channels.db import database_sync_to_async | |
from django.contrib.auth.models import AnonymousUser | |
from rest_framework.exceptions import AuthenticationFailed | |
from rest_framework_jwt.authentication import JSONWebTokenAuthentication | |
from rest_framework_jwt.blacklist.exceptions import MissingToken |