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 / reusable-providers.tsx
Created January 10, 2025 00:06
A reusable providers component that almost eliminates the need for context API
'use client';
import type { JSXElementConstructor, ReactNode } from 'react';
type InferProps<T> = T extends JSXElementConstructor<infer P> ? P : never;
type ProviderWithProps<T extends JSXElementConstructor<unknown>> = [
T,
Omit<InferProps<T>, 'children'>
];
@WomB0ComB0
WomB0ComB0 / css-hsl-hex.ts
Last active January 11, 2025 16:24
Grabs the HSL values of CSS variables and adds the HEX version of it, and wraps it in a comment to the right most side of the LOC (line of code)
import * as fs from 'node:fs';
import { $ } from 'bun';
const hslToRgb = (h: number, s: number, l: number): [number, number, number] => {
h /= 360;
s /= 100;
l /= 100;
if (s === 0) {
return [l, l, l].map((v) => Math.round(v * 255)) as [number, number, number];
@WomB0ComB0
WomB0ComB0 / typed-async-return-oriented-programming.ts
Created January 6, 2025 05:52
The Result pattern is a functional programming approach that helps you handle success and failure states explicitly, making your code more predictable and easier to maintain.
type Success<T> = {
readonly success: true;
readonly value: T;
};
type Failure<E> = {
readonly success: false;
readonly error: E;
};
@WomB0ComB0
WomB0ComB0 / own-repository.sh
Created January 5, 2025 15:14
Become the owner of a repository, including the commit history
#!/bin/bash
# Store your new Git credentials
NEW_NAME="<$1>"
NEW_EMAIL="<$2>"
# Color codes for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
@WomB0ComB0
WomB0ComB0 / upgrade-flutter.sh
Created December 23, 2024 03:05
Upgrade dependencies to their latest versions
#!/bin/bash
# Function to extract package versions from flutter pub outdated
get_latest_versions() {
flutter pub outdated | grep -v "Package Name" | grep -v "dependencies:" | grep -v "^$" | while read -r line
do
# Skip the header line with dashes
if [[ $line == *"Current"* ]]; then
continue
fi
@WomB0ComB0
WomB0ComB0 / requirements-from-anaconda.py
Created December 21, 2024 06:12
From ```pip list``` within an Anaconda envmt. write to current ide/envmt.
from collections import defaultdict
try:
book: defaultdict[str, str] = defaultdict(str)
with open("test.txt", "r", encoding="utf-8") as file:
for line in file:
if line.strip():
parts = line.split()
if len(parts) >= 2:
book[parts[0]] = parts[1]
@WomB0ComB0
WomB0ComB0 / clean.ts
Created December 6, 2024 18:53
Utilities for https://github.com/WomB0ComB0/leetcode-solutions, utilizing the LeetCode GraphQL endpoint
import { promises as fs } from 'fs';
import path from 'path';
/**
* Utility class for cleaning and standardizing filenames across programming language directories.
* Handles conversion to kebab-case, roman numeral suffixes, and ensures unique filenames.
*/
class FilenameCleaner {
/** List of programming language directories to process */
private static readonly PROGRAMMING_DIRECTORIES = [
@WomB0ComB0
WomB0ComB0 / extract-types-properties.ts
Created November 30, 2024 23:17
Extract the types and properties from input literal/type/tuple of types
type Decrement<N extends number> = [
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
][N];
type ExtractNthProperty<T, N extends number> =
T extends readonly [infer First, ...infer Rest]
? N extends 0
? First
: ExtractNthProperty<Rest, Decrement<N>>
@WomB0ComB0
WomB0ComB0 / hono-mutation.ts
Created November 27, 2024 16:30
Optimizing API Mutations with React Query and Hono API
import { toast } from "sonner";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { InferRequestType, InferResponseType } from "hono";
import { hono_api } from "@/providers/core/server/react";
import { useRouter } from "next/navigation";
type MutationOptions<TRoute extends keyof typeof hono_api> = {
route: TRoute;
method: keyof (typeof hono_api)[TRoute];
successMessage?: string;
@WomB0ComB0
WomB0ComB0 / advanced-graphs.ts
Created November 26, 2024 21:55
Advanced graphs (Dijkstra, Ford, A*) in TypeScript
/**
* Represents infinity for graph algorithms, using JavaScript's maximum safe integer
*/
const INF = Number.MAX_SAFE_INTEGER;
/**
* Creates a 2D array (matrix) initialized with zeros
* @param {number} x - Number of rows
* @param {number} y - Number of columns
* @returns {number[][]} A 2D array of dimensions x by y filled with zeros