π΅βπ«
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
NewerOlder