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 / regex-suggestor.py
Created November 24, 2024 23:00
Python script that takes in 1x1 dimensional data to suggest the best regex against the inputted data
from collections import Counter
from typing import Dict, List, Tuple
def analyze_patterns(terms_dict: Dict[str, str]) -> Tuple[Dict[str, int], List[str]]:
"""
Analyzes terms to find common patterns and potential regex optimizations.
Returns frequency of patterns and suggested regex patterns.
"""
# Convert all terms to list and lowercase for consistency
@WomB0ComB0
WomB0ComB0 / simplify-job-tracker-parser.py
Created November 23, 2024 03:18
Python CSV parser for simplify jobs
from typing import List, Dict
from datetime import datetime
import csv
def parse_jobs(file_path: str) -> List[Dict[str, str]]:
jobs = []
with open(file_path, "r", encoding="utf-8-sig") as f: # Changed to utf-8-sig
reader = csv.DictReader(f)
for row in reader:
# Parse the date
@WomB0ComB0
WomB0ComB0 / fetcher.ts
Created November 22, 2024 20:33
Configuration options for enhanced fetching that extends the base Axios request config
import axios, { type AxiosRequestConfig, AxiosError } from 'axios';
/**
* Wraps a promise to return a tuple containing either the resolved value or an error.
* Provides a cleaner way to handle promise rejections without try/catch blocks.
*
* @template T - The type of value that the promise resolves to
* @param {Promise<T>} promise - The promise to handle
* @returns {Promise<[undefined, T] | [Error]>} A promise that resolves to a tuple containing either:
* - [undefined, T] if the promise resolves successfully, where T is the resolved value
@WomB0ComB0
WomB0ComB0 / data-loader.tsx
Created November 22, 2024 16:51
Client-side fetch component to reduce excessive re-writing of the same sequence of code
'use client';
import React, { Suspense } from 'react';
import { ClientError, Loader } from '@/components'
import { fetcher } from "@/lib"
import { useSuspenseQuery } from '@tanstack/react-query';
import { catchError, parseCodePath } from '@/utils';
/**
* A React component that handles data fetching with built-in loading, error handling, and caching.
/**
* Node.js file system module for file operations
*/
import fs from "node:fs";
/**
* Node.js path module for handling file paths
*/
import path from "node:path";
/**
@WomB0ComB0
WomB0ComB0 / build-time-typescript-type-json-parser.ts
Created November 19, 2024 07:16
Build-time Typescript-Type-safe JSON parser
// Base utility types
type Whitespace = '\u{9}' | '\u{A}' | '\u{20}' // tab, newline, space
type TrimLeft<V extends string> = V extends `${Whitespace}${infer R}`
? TrimLeft<R>
: V
type TrimRight<V extends string> = V extends `${infer R}${Whitespace}`
? TrimRight<R>
: V
@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]>
@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 / 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.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