Skip to content

Instantly share code, notes, and snippets.

View WomB0ComB0's full-sized avatar
πŸ˜΅β€πŸ’«
I need an Advil

Mike Odnis WomB0ComB0

πŸ˜΅β€πŸ’«
I need an Advil
View GitHub Profile
@WomB0ComB0
WomB0ComB0 / convert-to-webp.py
Last active January 4, 2025 10:09
convert images to webp
import os
import subprocess
from pathlib import Path
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
from time import perf_counter
import logging
from typing import List, Set
# Constants
EXTENSIONS: tuple[str, ...] = (".png", ".jpg", ".jpeg")
@WomB0ComB0
WomB0ComB0 / lazy-blur-image-hasher.js
Created November 13, 2024 04:36
bs64 image hasher javascript
"use strict";
const sharp = require("sharp");
const fs = require("fs");
const path = require("path");
sharp.cache(false);
async function generateLazyImage(src) {
const { default: got } = await import("got");
@WomB0ComB0
WomB0ComB0 / lazy-image-wrapper.tsx
Created November 13, 2024 04:42
Lazy image wrapper, React
import React, {
type PropsWithChildren,
cloneElement,
isValidElement,
type DetailedReactHTMLElement,
type ImgHTMLAttributes,
type FC,
Children,
} from "react";
@WomB0ComB0
WomB0ComB0 / my-ts-utils.ts
Created November 13, 2024 05:14
Advanced Typescript utility types
// Prettify - Prettifies a type by removing readonly and optional modifiers
type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
// Head - Gets the first element of an array
type Head<T extends Array<any>> = T extends [infer U, ...infer _Rest] ? U : never
// Tail - Gets the tail of an array
type Tail<T extends any[]> = T extends [infer _U, ...infer Rest] ? Rest : never
@WomB0ComB0
WomB0ComB0 / python.d.ts
Created November 13, 2024 05:33
adding python methods to typescript
/**
* Extends global interfaces to add Python-like functionality
*/
declare global {
interface Number {
/**
* Returns true if the number is within the given range [start, end).
* Similar to Python's `in range()`.
*/
inRange(start: number, end?: number, step?: number): boolean;
@WomB0ComB0
WomB0ComB0 / multi-threading.ts
Created November 15, 2024 18:56
Typescript multi-threading template (will apply opinionated changes soon)
// types.ts
export interface WorkerMessage<T = any> {
id: string;
type: 'TASK' | 'RESULT' | 'ERROR' | 'STATUS';
payload: T;
timestamp: number;
}
export interface WorkerTask {
id: string;
@WomB0ComB0
WomB0ComB0 / multi-threading.py
Created November 15, 2024 18:59
Python multi-threading template (will apply opinionated changes soon)
import threading
import queue
import concurrent.futures
import logging
from typing import List, Callable, Any
from dataclasses import dataclass
from datetime import datetime
import time
# Configure logging
@WomB0ComB0
WomB0ComB0 / multi-threading.go
Created November 15, 2024 19:01
Go multi-threading template (will apply opinionated changes soon)
package concurrency
import (
"context"
"fmt"
"log"
"sync"
"time"
"errors"
)
@WomB0ComB0
WomB0ComB0 / multi-threading.rs
Created November 15, 2024 19:04
Rust multi-threading template (will apply opinionated changes soon)
use std::{
collections::HashMap,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
Arc, Mutex, RwLock,
},
thread,
time::{Duration, Instant},
};
use tokio::{
@WomB0ComB0
WomB0ComB0 / bfs.ts
Created November 17, 2024 01:56
ts-typed BFS
interface Node<T = unknown, Nodes extends Node<any, any>[] = Node<any, any>[]> {
value: T;
neighbors: Nodes;
}
type A = Node<1, [B, C]>
type B = Node<2, [A, D]>
type C = Node<3, [A, B]>
type D = Node<4, [B, C]>