Skip to content

Instantly share code, notes, and snippets.

View AlbericTrancart's full-sized avatar

Albéric Trancart AlbericTrancart

View GitHub Profile
@AlbericTrancart
AlbericTrancart / assert_no_duplicated_queries.py
Created November 10, 2022 11:24
Assert no N+1 performance problem in your Flask unit tests
@contextlib.contextmanager
def assert_no_duplicated_queries(
max_number_of_duplicated_queries: int = 0,
max_number_of_duplications: int = 1,
) -> collections.abc.Generator[None, None, None]:
"""A context manager that verifies that no SQL statement is run twice
during the execution of the code in the context to prevent N+1 issues.
The max_number_of_duplicated_queries param can be set
to progressively fix a code ridded with N+1 issues.
@AlbericTrancart
AlbericTrancart / getAllQueryPages.ts
Last active April 21, 2022 12:36
DynamoDB Toolbox Get All Query Pages Typescript Serverless Lambda
/** Usage **/
// const results = await getAllQueryPages(
// SomeModel.query("MY_PK", {
// index: GSI.GSI1.IndexName,
// })
// );
/** getAllQueryPages.ts **/
import { DocumentClient } from "aws-sdk/lib/dynamodb/document_client";
@AlbericTrancart
AlbericTrancart / gzipMiddleware.ts
Last active April 13, 2022 15:31
Serverless Typescript Lambda Gzip Middleware
import middy from "@middy/core";
import get from "lodash/get";
import set from "lodash/set";
import { gzipSync } from "zlib";
import isString from "lodash/isString";
import { hasProperty } from "@smallable/help-purchase-shared";
export type GzipMiddlewareConfig = Record<string, never>;
type NormalizedResponse = {
@AlbericTrancart
AlbericTrancart / assert_no_duplicated_queries.py
Created February 10, 2022 12:54
Assert no N+1 performance problem in your unit tests
import collections
from contextlib import contextmanager
from django.db import connection
class QueryLogger:
def __init__(self):
self.queries = []
@AlbericTrancart
AlbericTrancart / Accessibility.md
Last active November 5, 2019 10:48
What is an accessible page

Web page accessibility checklist

Images (check: ~ 5 minutes)

  • Meaningful images have text alternatives (alt for <img> , aria-label otherwise)
  • Decorative images are hidden (alt="" for <img>, aria-hidden="true" otherwise)
  • Images required to understand the content point to a description with the aria-describedby attribute
  • Images containing text (memes are a perfect example) have a text alternative
  • If the image has a legend, it is in a <figcaption> tag
  • If the image is a CAPTCHA, there is a non graphical alternative
@AlbericTrancart
AlbericTrancart / stack-css.md
Last active September 25, 2019 19:54
Un processus pour concevoir une architecture CSS

Comment choisir sa stack CSS ?

Étape 1 : choisir une design library ou commencer from scratch

C'est le choix le plus important. Il ne faut pas tordre un système existant qui ne convient pas, cela fera perdre beaucoup de temps en overrides et annulera le gain d'utiliser cette library.

Choix faciles

  • Identité visuelle forte / image de marque ? => from scratch
  • Pas de designer ? => design library