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 / NetworkObserver.ts
Last active July 14, 2023 15:48
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)
@MaxMonteil
MaxMonteil / sumAll.py
Created April 1, 2019 09:49
Sum all numbers in a range
def sumAll(r):
return sum([i for i in range(min(r), max(r) + 1)])