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 / speech-to-text.tsx
Created August 22, 2024 12:50
Typescript, Typesafe Speech to Text
import { Button } from '@/components/ui/button';
/* eslint-disable @typescript-eslint/no-explicit-any */
/// <reference lib="dom" />
import React from 'react';
import { FaMicrophone } from 'react-icons/fa';
import { useIsomorphicLayoutEffect } from 'usehooks-ts';
/*
* Intakes a state setter where the component
* will store the result of speech to text into
@WomB0ComB0
WomB0ComB0 / match-env-vars.ts
Created August 16, 2024 01:34
This TypeScript script compares environment variables from .env files with a predefined set, performing set operations (union, intersection, or difference) specified via command-line arguments. It parses the variables, executes the chosen operation, and outputs the results to a file, providing a flexible tool for analyzing and managing environme…
import { readFileSync, writeFileSync, readdirSync } from "node:fs";
import { join } from "path";
const paste: string = `
<key>=<value>
...
`
const envFiles: string[] = readdirSync(process.cwd()).filter((file) => file.startsWith(".env"));
@WomB0ComB0
WomB0ComB0 / node-package-dependencies-checker.ts
Created August 15, 2024 20:50
Check the difference between n dev/dependencies
import { readFileSync } from 'fs';
import { join } from 'path';
import { z } from 'zod';
const packages = readFileSync(join(__dirname, 'package.json'), 'utf8');
const schema = z.object({
devDependencies: z.record(z.string()),
dependencies: z.record(z.string()),
});
@WomB0ComB0
WomB0ComB0 / count_fles_pattern.py
Created August 11, 2024 01:49
Get the file names within a directory which match specified pattern
import os
import re
import sys
from typing import List
class FileSystem:
def __init__(self, path='.') -> None:
self.path = path
def filter_files(self, files, pattern) -> List[str]:
@WomB0ComB0
WomB0ComB0 / kv-generator.ts
Created August 10, 2024 11:44
Generate kv pairs for O(1) lookup time from text files
import { fileURLToPath } from "node:url"
import { readFileSync, writeFileSync } from "node:fs"
import { dirname } from "node:path"
(() => {
const __dirname = dirname(fileURLToPath(import.meta.url))
console.log(`${__dirname}<path><file_name>.<extension>`)
const robots = readFileSync(`${__dirname}<path><file_name>.<extension>`, "utf-8")
const kv: Map<string, string> = new Map<string, string>()
@WomB0ComB0
WomB0ComB0 / variations.ts
Created August 2, 2024 21:17
Generate all possible alpha characters , on the point of casing (capital lowercase)
import fs from 'fs';
import { fileURLToPath } from 'url';
import path from 'path';
import { Worker, isMainThread, parentPort, workerData } from 'worker_threads';
const __filename: string = fileURLToPath(import.meta.url);
const __dirname: string = path.dirname(__filename);
const filePath = path.join(__dirname, 'server', 'data', 'nsfw-names.txt');
const fileContent = fs.readFileSync(filePath, 'utf8');
@WomB0ComB0
WomB0ComB0 / scraper-filtration.ts
Last active August 2, 2024 17:02
Advanced, general, website scraper
import puppeteer from 'puppeteer-extra';
import { LaunchOptions } from 'puppeteer';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import AdblockerPlugin from 'puppeteer-extra-plugin-adblocker';
interface Row {
text: string;
@WomB0ComB0
WomB0ComB0 / binarysearch_sting.ts
Created August 1, 2024 15:13
Binary search text in Typescript
const binarySearch = (source_text: string, target: string): [number, string] | null => {
const source_text_segments: string[] = (source_text.match(/[^.!?]+[.!?]+/g) || [source_text]).map(s => s.trim());
const target_segment = target.trim();
let result: [number, string] | null = null;
let left: number = 0;
let right: number = source_text_segments.length - 1;
while (left <= right) {
const mid = left + Math.floor((right - left) / 2);
const segment = source_text_segments[mid];
@WomB0ComB0
WomB0ComB0 / scraper.ts
Last active July 31, 2024 16:14
Simple text content web scraper with puppeteer
import puppeteer from "puppeteer";
import axios from "axios";
export const scraper = async (url: Readonly<string>): Promise<string[]> => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(url, {
timeout: 0,
waitUntil: "domcontentloaded"
@WomB0ComB0
WomB0ComB0 / memoize.py
Created July 31, 2024 05:15
Meoize class Python
class Memoize:
def __init__(self, func: Callable) -> None:
self.func = func
self.cache = {}
def __call__(self, *args, **kwargs) -> Any:
if args not in self.cache:
self.cache[args] = self.func(*args, **kwargs)
return self.cache[args]