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 / utils.ts
Created July 31, 2024 03:31
Custom Typescript Type Utils
type DeepReadonly<T extends Record<string, unknown>> = {
readonly [K in keyof T]: T[K] extends Record<string, any>
? T[K] extends (...args: Array<unknown>) => unknown
? T[K]
: DeepReadonly<T[K]>
: T[K];
};
type ReadonlyArray<T> = DeepReadonly<Array<T>>;
@WomB0ComB0
WomB0ComB0 / fetch.ts
Created July 10, 2024 19:54
TypeSafe http requests with zod validation
import { z } from "zod";
import { PostSchema } from "@/schema/posts";
import { CommentsSchema } from "@/schema/comments";
export function createAPIClient() {
async function _fetch<T extends z.ZodTypeAny>(
input: RequestInfo,
init: RequestInit,
type: T
): Promise<z.infer<T>> {
@WomB0ComB0
WomB0ComB0 / mysql_db.py
Created July 9, 2024 23:36
Arbitrary MySQL database class in Python
class MySQLDatabase:
def __init__(self, database, user, password, host, port):
self.database = database
self.user = user
self.password = password
self.host = host
self.port = port
def connect(self):
return MySQLDatabase(self.database, self.user, self.password, self.host, self.port)
@WomB0ComB0
WomB0ComB0 / linkedlists.py
Created July 8, 2024 21:17
LikedList methods
class Node: # Creating a node
def __init__(self, item):
self.item = item
self.next = None
class LinkedList: # Creating a linked list
def __init__(self):
self.head = None
def print_list(self):
cur_node = self.head
@WomB0ComB0
WomB0ComB0 / debounce.ts
Created July 1, 2024 02:54
Debounce function in Typescript
/**
* Debounces a function by delaying its execution until a certain amount of time has passed
* since the last time it was invoked. Only the last invocation within the delay period will be executed.
*/
export function debounce(fn: Function, time: number = 300): Function {
let timeoutId: ReturnType<typeof setTimeout>;
return function (this: any, ...args: any[]) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
fn.apply(this, args);
@WomB0ComB0
WomB0ComB0 / db.py
Created June 30, 2024 03:35
db-sqlite3 crud methods within a class (class Database)
from flask import g
import sqlite3
from typing import Dict, List
class Database:
def __init__(self, db_path: str):
self.db_path = db_path
def get_connection(self):
if "conn" not in g: