Skip to content

Instantly share code, notes, and snippets.

View markusand's full-sized avatar

Marc Vilella markusand

View GitHub Profile
@markusand
markusand / .gitignore
Created November 20, 2025 10:07
Global .gitignore for common system files, language artifacts, environment files, logs, and editor/tooling junk across all projects.
# macOS
.DS_Store
# Environments
.env
.env.*
!.env.*.sample
# Logs
logs/
@markusand
markusand / udataclasses.py
Last active November 20, 2025 16:08
A simple implementation for a dataclass decorator in micropython
"""A simple implementation for a dataclass decorator in micropython"""
# pylint: disable=line-too-long
from typing import Callable, Type, TypeVar, Any, Tuple
from builtins import repr as brepr
T = TypeVar("T")
@markusand
markusand / typed-storage.ts
Created August 26, 2025 07:36
Type-safe wrapper for localStorage supporting primitives, Date, arrays, and nested objects. Includes set, get, remove, clear and a Vue 3 ref that auto-syncs with storage.
export type Storable =
| string
| number
| boolean
| null
| Date
| Storable[]
| undefined
| { [key: string]: Storable };
@markusand
markusand / TerrainControl.ts
Last active March 9, 2025 10:38
Terrain control for mapbox-gl-js
import type { Map, IControl } from 'mapbox-gl';
import useTerrain, { type ExtrusionOptions } from './terrain';
import type { Prettify } from '/@/types/utilities';
export type TerrainControlOptions = Prettify<{
init?: boolean,
pitch?: number;
} & ExtrusionOptions>;
export default class TerrainControl implements IControl {
@markusand
markusand / autoparser.py
Last active January 31, 2025 16:53
Autoparse NMEA messages
from typing import List, Type, TypeVar
T = TypeVar("T", bound="Autoparser")
class Autoparser:
"""Automatic parse into parseable classes."""
def __repr__(self):
exclude = (classmethod,)
attrs = [
@markusand
markusand / units.py
Last active September 17, 2025 20:16
A simple unit converter system with Measure value object
"""Unit conversion"""
from dataclasses import dataclass
from functools import total_ordering
from enum import Enum
from typing import Callable, NamedTuple
class UnitDesc(NamedTuple):
"""Unit description"""
scale: float
@markusand
markusand / use.format.ts
Created January 27, 2025 17:36
[Vue] Format numbers depending on locale
export type Unit = 'acre' | 'bit' | 'byte' | 'celsius' | 'centimeter' | 'day' | 'degree' | 'fahrenheit' | 'fluid-ounce' | 'foot' | 'gallon' | 'gigabit' | 'gigabyte' | 'gram' | 'hectare' | 'hour' | 'inch' | 'kilobit' | 'kilobyte' | 'kilogram' | 'kilometer' | 'liter' | 'megabit' | 'megabyte' | 'meter' | 'microsecond' | 'mile' | 'mile-scandinavian' | 'milliliter' | 'millimeter' | 'millisecond' | 'minute' | 'month' | 'nanosecond' | 'ounce' | 'percent' | 'petabyte' | 'pound' | 'second' | 'stone' | 'terabit' | 'terabyte' | 'week' | 'yard' | 'year';
export type FormatOptions = {
currency?: string;
units?: 'short' | 'narrow' | 'long';
sign?: boolean;
integers?: number;
decimals?: number;
round?: 'ceil' | 'floor' | 'expand' | 'trunc';
notation?: 'standard' | 'scientific' | 'engineering' | 'compact';
@markusand
markusand / pyboard.py
Created November 8, 2024 23:12
Lightweight version of pyboard. Includes replacement of module constants declaration for execfile()
"""
Minimal pyboard.py implementation for communicating with MicroPython boards
"""
import os
import time
import re
import serial
import serial.tools.list_ports
@markusand
markusand / use.timeout.ts
Created May 3, 2024 19:10
[React] useTimeout hook
import { useState, useEffect } from 'react';
export type TimeoutOptions = {
initial: number;
auto?: boolean;
interval?: number;
onFinish?: () => void;
};
export const useTimeout = (options?: TimeoutOptions) => {
@markusand
markusand / functional.py
Last active December 28, 2023 01:11
Set of functional programming utilities for working with lists.
""" Functional module """
from typing import List, Dict, Callable, TypeVar, Optional
T = TypeVar('T')
U = TypeVar('U')
def map(predicate: Callable[[T], U], items: List[T]) -> List[U]:
'''
Applies a given function to all items in the list and returns a new list
containing the results.