Skip to content

Instantly share code, notes, and snippets.

View markusand's full-sized avatar

Marc Vilella markusand

View GitHub Profile
@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 February 19, 2025 17:42
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.
@markusand
markusand / proxy.py
Created November 4, 2022 01:49
HTTP Proxy to redirect GET requests to POST
import os
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib import parse
from requests import post
port = os.environ['PROXY_PORT']
url = os.environ['FORWARD_URL']
token = os.environ['TOKEN']
@markusand
markusand / Brewfile
Last active January 24, 2025 04:45
macOS auto setup
tap "homebrew/bundle"
# BASIC SOFTWARE -->
brew "mas"
# mas "Slack", id: 803453959
mas "The Unarchiver", id: 425424353
mas "Spark", id: 1176895641
mas "Dropover", id: 1355679052
mas "Bitwarden", id: 1352778147
cask "rectangle"
@markusand
markusand / logger.js
Created January 15, 2022 18:33
Express logger module with Winston + Morgan
import winston from 'winston';
import morgan from 'morgan';
import json from 'morgan-json';
/* WINSTON */
const filterLevel = level => winston.format(info => info.level === level ? info : undefined)();
const logger = winston.createLogger({
levels: { error: 0, warn: 1, info: 2, debug: 3, http: 4 },
transports: [
@markusand
markusand / markdown.md
Last active June 10, 2022 19:27
Andorra Recerca + Innovació Toolbox - https://bit.ly/2YLNQU1

Seminari markdown

header

💡 Què és?

Markdown és un llenguatge de marcat lleuger per donar format simple a textos.

  • Estàndard (més o menys)
  • Simple