This file contains hidden or 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 typing import List | |
from starlite import Partial, delete, get, patch, post, put | |
from my_app.models import Resource | |
@get(path="/resources") | |
def list_resources() -> List[Resource]: | |
... |
This file contains hidden or 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 typing import Optional | |
from fastapi import FastAPI | |
app = FastAPI() | |
@app.get("/") | |
def read_root(): | |
return {"Hello": "World"} |
This file contains hidden or 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
#!/bin/bash | |
SPECS_DOWNLOAD_URL="https://url-of-api.com/specs" | |
FILE="$PWD/src/my-api-specs.ts" | |
if [[ -f "$FILE" ]]; then | |
rm "$FILE" | |
fi | |
# use dtsgen to generate the target typescript file | |
dtsgen --url $SPECS_DOWNLOAD_URL >> "$FILE" |
This file contains hidden or 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
function isRecord<T = any>(value: unknown): value is Record<string | symbol, T> { | |
return !!(value && typeof value === 'object'); | |
} | |
function isPromise<T = unknown>(value: unknown): value is Promise<T> { | |
return isRecord(value) && Reflect.has(value, 'then'); | |
} | |
async function recursiveResolve<T>( | |
parsedObject: Record<string, any>, |
This file contains hidden or 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
interface Duck { | |
quack(): string; | |
} | |
function isDuck(value: unknown): value is Duck { | |
return !!( | |
value && | |
typeof value === 'object' && | |
typeof Reflect.get(value, 'quack') === 'function' | |
); |
This file contains hidden or 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
function isDuck(value) { | |
return !!( | |
value && | |
typeof value === 'object' && | |
typeof Reflect.get(value, 'quack') === 'function' | |
); | |
} |
This file contains hidden or 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 typing import Any | |
def is_duck(value: Any) -> bool: | |
try: | |
value.quack() | |
return True | |
except (Attribute, ValueError): | |
return False |
This file contains hidden or 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 itertools import islice | |
from typing import Iterator, Sequence, TypeVar | |
T = TypeVar("T") | |
def chunk(sequence: Sequence[T], size: int) -> Iterator[list[T]]: | |
"""given a sequence, return an iterator of lists of the given size""" | |
return iter(lambda: list(islice(iter(sequence), size)), []) |
This file contains hidden or 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 python:3.9-slim AS install | |
RUN apt-get update \ | |
&& apt-get upgrade -y \ | |
&& apt-get install -y --no-install-recommends curl \ | |
&& apt-get autoremove -y | |
RUN pip install --upgrade pip | |
WORKDIR /app/ | |
# install poetry and keep the get-poetry script so it can be reused later. | |
ENV POETRY_HOME="/opt/poetry" | |
RUN curl https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py > get-poetry.py |
This file contains hidden or 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 { useEffect, useRef } from 'react'; | |
export function useInterval( | |
callback: (clearInterval: () => void) => any, | |
delay: number | null, | |
): () => void { | |
const idRef = useRef<null | number>(null); | |
const clearInterval = () => { | |
if (idRef.current) { |