Skip to content

Instantly share code, notes, and snippets.

View MaxMonteil's full-sized avatar
🏠
Working from home

MaxMonteil

🏠
Working from home
View GitHub Profile
@MaxMonteil
MaxMonteil / jsonPatch.ts
Created August 23, 2025 12:14
TS typed JSON Patch RFC 6902
/**
* Type definitions for JSON Patch, based on RFC 6902:
* https://datatracker.ietf.org/doc/html/rfc6902
*
* This file defines the TypeScript types for JSON Patch operations
* (`add`, `remove`, `replace`, `move`, `copy`, `test`) and JSON Patch
* documents. These types are intended to ensure type safety when
* constructing or working with JSON Patch structures.
*
* @see RFC 6902 (JSON Patch): https://datatracker.ietf.org/doc/html/rfc6902
<template>
<h1>List items</h1>
<ul>
<li v-for="item in items" :key="item.id">
{{ item.name }}
</li>
</ul>
<button @click="addItem">Add item</button>
</template>
@MaxMonteil
MaxMonteil / NetworkObserver.ts
Last active October 11, 2024 16:30
A more reliable check for network availability in the browser
const NetworkStatus = {
ONLINE: 'online',
OFFLINE: 'offline',
PENDING: 'pending',
} as const
type NetworkStatusTypeOnline = 'online'
type NetworkStatusTypeOffline = 'offline'
type NetworkStatusTypePending = 'pending'
type NetworkStatusType =
@MaxMonteil
MaxMonteil / multiStoreIdb.ts
Created July 5, 2023 06:34
IndexedDB with multiple stores
import { openDB, IDBPDatabase } from 'idb'
export interface PersistenceFacade<T> {
exists(id: string): Promise<boolean>
save(key: string, value: T): Promise<void>
bulkSave?: (data: { key: string; val: T }[]) => Promise<void>
getByID(id: string): Promise<T | null>
getAll(): Promise<T[]>
getAllWithQuery(constraints: any): Promise<T[]>
deleteByID(id: string): Promise<void>
@MaxMonteil
MaxMonteil / IdbWrapper.js
Created June 20, 2020 16:18
A wrapper around idb for creating multiple stores whenever
import { openDB } from 'idb'
export class IdbWrapper {
static _freshStart = true
static _checking = false
static _dbCheck = null
static _version = 1
static _stores = new Set()
"syllabus": [
{
"id": courseId + moduleName,
"name": "Front End",
"description": "An introduction to the web",
"lessons": [ // classes in the db
{
"id": "lesgh893", // id of the class
"courseId": "fpiu314", // string
"sectionId": courseId + moduleName,
@MaxMonteil
MaxMonteil / Vue Projects directory structure.md
Created March 13, 2020 10:14
An excerpt from the docs of my current project about managing the directory structure.

A Directory Structure for Vue Projects

The project tries to follow a directory structure that mirrors the components structure of the design system/component library. The library divides components into 2 groups:

  • Atomic Components (icons, buttons, inputs)
  • UI Components (forms, cards, timers, etc.)

The codebase adds a further distinction between these 2 groups which are represented by the folders in src/:

  • Components
@MaxMonteil
MaxMonteil / pairwise.py
Created April 2, 2019 18:20
Given an array arr, find element pairs whose sum equal the second argument arg and return the sum of their indices.
def pairwise(arr, arg):
size = range(len(arr))
s = 0
for i in size:
for j in size:
if arr[i] + arr[j] == arg:
arr[i] = 0
arr[j] = 0
s = s + i + j
return s
@MaxMonteil
MaxMonteil / palindrome.py
Created April 2, 2019 14:25
Say whether a given string is a palindrome or not
def palindrome(string):
alphanum = "abcdefghijklmnopqrstuvwxyz0123456789"
clean = "".join([c for c in string.lower() if c in alphanum])
return clean == clean[::-1]
def uniteUnique(*lss):
values = []
for element in lss:
values.extend(element)
unique = []
for value in values:
if value not in unique:
unique.append(value)