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 / 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 / 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 / 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 / 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 / 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 / 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 / check-unused.ts
Created January 11, 2025 16:05
Check unused dependencies within your project by match casing your package.json and node_module deps
import fs from 'fs';
import path from 'path';
import depcheck from 'depcheck';
import { $ } from 'bun';
import type { PackageJson } from 'type-fest';
// If you're coming from GitHub Gist, you can remove or change this
const rootDir = path.join(__dirname, '..'); // Go up one level to project root
const packageJsonPath = path.join(rootDir, 'package.json');
console.log('Checking:', packageJsonPath);
@WomB0ComB0
WomB0ComB0 / package-cost.ts
Created January 11, 2025 16:18
Calculate dependency cost, returns array of objects which have the name and size (in bytes) of their respective package
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import type { PackageJson } from 'type-fest';
const packageJsonPath = path.join(process.cwd(), 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as PackageJson;
const dependencies = Object.keys(packageJson.dependencies || {});
const devDependencies = Object.keys(packageJson.devDependencies || {});
const allDependencies = [...dependencies, ...devDependencies];
@WomB0ComB0
WomB0ComB0 / zustand-provider.tsx
Created January 19, 2025 16:19
GlobalStoreProvider component that provides the global store to the React component tree. This component initializes the store on first render and maintains a consistent reference to it using useRef to prevent unnecessary re-renders.
'use client';
import { type StoreState, createGlobalStore } from '@/core/store';
import type React from 'react';
import { createContext, useContext, useRef } from 'react';
import { useStore } from 'zustand';
/**
* React context to provide the global store throughout the application. The context
* holds a reference to the store created by createGlobalStore or null if not yet initialized.
@WomB0ComB0
WomB0ComB0 / jotai-provider.tsx
Created January 20, 2025 21:44
A higher-order component that wraps a given component with Jotai's Provider. This enables state management using Jotai atoms throughout the component tree
import { Provider } from 'jotai/react';
import type { ReactNode } from 'react';
/**
* Type definition for a React component that can accept children
* @template P - The props type for the component
*/
type ComponentWithChildren<P = {}> = React.ComponentType<P & { children?: ReactNode }>;
/**